<div class="container page-content clearfix">
    <br />
    <div class="box ecommerce-orders-page">
    	<div class="box-title">
        	{!! Theme::section('theme/user.purchase.menu',['page'=>'']) !!}
        </div>
        
        <div class="box-content">
        	<h3 style="font-size:16px;"><span class="brand-colored-texts">{{$product->product_name}}</span> Orders</h3> <br>

			@if(count($orders)>0)
            	<table class="table table-bordered">
                    <thead class="thead-dark">
                        <tr>
							<th style="width: 45%">{{trans('mytransactions.order-details')}}</th>
							<th style="width: 10%">Amount</th>
							<th style="width: 15%">Transaction Details</th>						
                            <th style="width: 15%">{{trans('mytransactions.action')}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($orders as $order)
						
                            <tr>
                                <td class="order-colspan order-colspan-{{$order->id}}" data-id="{{$order->id}}" >                                    
                                    <p class="brand-colored-texts">
									    <b>Product:</b>
                                    
										<?php
											if($order->currency=="INR"){  
												$currencyIcon="<i class='fa fa-inr'></i>"; 
											}
											else{
												$currencyIcon="<i class='fa fa-dollar'></i>"; 
											}
											$dtls='';											
										?>	
                                    </p>
									
									@if($order->details)
                                        <?php 
                                            $pr=1;
                                            $prCount=count($order->details);
                                        ?>			

                                        @foreach($order->details as $dtls)
                                            @if($dtls->product)
                                                <?php 
													$product=$dtls->product;
													
													$productUrl="";
													
													if($dtls->community_business_id!=0){	
														$business=\Auth::user()->present()->getStoreById($dtls->community_business_id);
													}else{														
														$business=\Auth::user()->present()->getStoreById($dtls->community_id);
													}
													
													if($business){
														$productUrl=URL::route('store', ['slug' => $business->slug])."/product/".$product->id;
														
														$businessName=$business->title;
														$businessUrl=URL::route('store', ['slug' => $business->slug]);
													}else{
														$productUrl=\URL::route('productbuy',['id'=>$product->id]);
													}
												?>
												
												@if($prCount>1){{$pr}}) @endif <a href="{{$productUrl}}">
												
												@if($product->product_type!=2)
													@if($product->image1)
														<img data-original="{{Image::url($dtls->product->image1)}}" class="purchase-history-product-img lazy"/>
														<br /></a>
													@endif
												@else
													@if($product->digital_type==1)
														@if($product->digital_video_sample_file)
															<div class="order-video-outer-box">
																 <iframe class="upload-video" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" style="border: none;padding: 0;border-radius: 10px;overflow: hidden" src="{{URL::route('play-video')}}?path={{$product->digital_video_sample_file}}" width="100%" height="330"></iframe>
															</div> 
														@endif 
													@elseif($product->digital_type==2)
														@if($product->digital_image_sample_file)
															 <img data-original="{{Image::url($product->digital_image_sample_file)}}" data-url="{{Image::url($product->digital_image_sample_file)}}" class="order-show-business-product-image lazy" data-id="{{$product->id}}">
														@endif 
													@elseif($product->digital_type==3)
														
														<?php
															$allowed_files  = ['jpg', 'jpeg', 'png', 'gif','pdf', 'txt','mp4', 'mov', 'mpg', 'flv','mp3', 'wav', 'ogg', 'aif','wma','mid'];
															
															$fullPath=getFullPath($product->digital_file_sample_file);
															$extension=strtolower($product->digital_sample_file_extension);
														?>
														
														@if(in_array($extension, $allowed_files))
															<span class="read-sample-file" data-id="{{$product->id}}" style="font-size: 14px;padding: 5px 6px;">Read Sample</span>
														@else
															<a class="download-sample-file" href="{{\URL::route('postproduct-downloadfile')}}?path={{$product->digital_file_sample_file}}" style="font-size: 14px;padding: 5px 6px;">Download Sample</a>
														@endif
													  
														<br /><br />					
														{!! Theme::section('user.products.view-sample-file',['product'=>$product]) !!}
													@endif
												@endif
                                                
                                                {{$dtls->product->product_name}}

												</a>	
                                                <br />
                                                <?php $pr++;?>
                                            @endif
                                            <br />
                                        @endforeach
                                    @endif
									
									<strong>Buyer:</strong>
									@if($order->user)
                                        <p>
											<a href="{{$order->user->present()->url()}}">
												{{$order->user->fullname}}
											</a>
										</p>	
                                    @endif
                                                                         
                                    @if($order->delivery_option==1) 
                                        <b>Pickup</b><br />
                                        <strong>Date:</strong> {{date("M j, Y",strtotime($order->order_date_time))}}<br />
                                        <strong>Time:</strong> {{date("H:i A",strtotime($order->order_date_time))}}<br />
                                        <strong>Cell:</strong> {{$order->mobile}}
                                    @endif
									
									<b>Mailing Address</b>                                       
									<br />
									<!--<b>Delivery Details</b><br />-->
									{{$order->full_name}}<br />
									@if($order->address_1){{$order->address_1}}<br />@endif
									@if($order->city){{$order->city}},@endif {{$order->zip}}<br />
									@if($order->state){{$order->state}},@endif {{$order->country}}<br />
									<strong>Cell:</strong> {{$order->mobile}}                          
												
									
									<br /><br />
									<b>Billing address</b>                                       
									<br />
									
									@if($order->billing_address)
										{{$order->billing_address}}<br />
									@else
										@if($order->city){{$order->city}},@endif {{$order->zip}}<br />
										@if($order->state){{$order->state}},@endif {{$order->country}}<br />
									@endif
                                    
                                    <br /><br />
                                    
									<!--<p>
										<strong>Product Type: </strong>
										
										<span class="brand-colored-texts">
											@if($dtls)
												@if($dtls->product->product_type==0)
													One Time 
												@elseif($dtls->product->product_type==1)
													Subscription 
												@else
													Digital Product
												@endif	
											@endif	
										</span>	
									</p>-->
									
									<?php
											$trCnt='';
											$transactions='';										
											$pendingTrans='';
											$completedCycle='';
									?>
									
									@if($dtls)
										@if($dtls->product->product_type==1)

											Subscription type:
													<strong>
													@if($order->subscription_type==1)
														weekly
													@elseif($order->subscription_type==2)
														bi-weekly
													@elseif($order->subscription_type==3)
														monthly
													@endif </strong><br />
													
											Subscription Cycle: <strong>{{$order->subscription_cycle}}</strong> <br />                            
											Completed Cycle: <strong>{{$order->completed_cycles}}</strong> <br />                              
											Subscribed On: <strong>  {{date("F j, Y",strtotime($order->subscription_date))}}</strong><br />
											Next cycle date: <strong>  {{date("F j, Y",strtotime($order->next_payment_date))}}</strong> 
											<br><br>										
										@endif
										
										<?php											
											if($dtls->product->product_type==1){
												$transactions=\Auth::user()->present()->getProductRecurringTrans($dtls->product->id,$order->id);
												$doneTrCnt=count($transactions);
												
												$trCnt=$order->subscription_cycle;
												$pendingTrans=$trCnt-$order->completed_cycles;
												$completedCycle=$order->completed_cycles;
											}	
										?>
									@endif	
                                </td>
                                
								<input type="hidden" class="order-colspan-cnt order-colspan-cnt-{{$order->id}}" data-id="{{$order->id}}" value="{{$trCnt}}">
								
								@if(!$transactions)								
									<td>
										{!! $currencyIcon !!} {{number_format($order->amount, 2, '.', ',')}} <br />
										<br />
									</td>

									<td>
										<b>Date:</b>
										{{date("M j, Y",strtotime($order->created_at))}}<br />
										
										<b>Transaction Id:</b> {{$order->transaction_id}} <br />
									</td>                                
									
									<td>  
										Completed : One time <br><br>
										
										<a href="{{URL::route('my-sales-status',['id'=>$order->id])}}" style="color:#F00">Update Action</a><br />
									
										@if($order->delivery_option==1) 
											<b>Picked by:</b> <br />
											
											@if($order->picked_by)
												{{$order->picked_by}}<br />	
												<strong>Date:</strong> {{date("d F Y",strtotime($order->picked_date))}}<br />
												<strong>Time:</strong> {{date("H:i A",strtotime($order->picked_date))}}<br />
											@endif 
										@else
											@if($order->courier_by)
												{{$order->courier_by}}<br />	
												<strong>Date:</strong> {{date("d F Y",strtotime($order->courier_date))}}<br />
												<strong>Tracking No:</strong> <br />{{$order->tracking_number}}<br />
											@endif 
										@endif                                    
									</td>
								</tr>	
								@else
									@if(!empty($transactions))	
												
										
											<?php 
												$cntt=count($transactions)+1;
												$newCnt=0;
											?>	
											@foreach($transactions as $trans)
												
													<td>
														{!! $currencyIcon !!} {{number_format($trans->amount, 2, '.', ',')}}
													</td>
													
													<td>
														<strong>Date:</strong> {{date("M j, Y",strtotime($trans->created_at))}} <br>
														<strong>Transaction Id:</strong> {{$trans->transaction_id}}
													</td>	

													<td>
														Completed : <?php echo $cntt-$newCnt?><br><br>
														
														@if($newCnt==0)
															<a href="{{URL::route('my-sales-status',['id'=>$order->id])}}" style="color:#F00">Update Action</a><br />
									
															<br />
															@if($order->delivery_option==1) 
																<b>Picked by:</b> <br />
																
																@if($order->picked_by)
																	{{$order->picked_by}}<br />	
																	<strong>Date:</strong> {{date("d F Y",strtotime($order->picked_date))}}<br />
																	<strong>Time:</strong> {{date("H:i A",strtotime($order->picked_date))}}<br />
																@endif 
															@else
																@if($order->courier_by)
																	{{$order->courier_by}}<br />	
																	<strong>Date:</strong> {{date("d F Y",strtotime($order->courier_date))}}<br />
																	<strong>Tracking No:</strong> <br />{{$order->tracking_number}}<br />
																@endif 
															@endif    	
														@endif
													</td>
												</tr>
												
												<tr>	
												<?php $newCnt++?>	
											@endforeach	
										
										
												<td>
													 {!! $currencyIcon !!} {{number_format($order->amount, 2, '.', ',')}}
												</td>
														
												<td>
													<strong>Date:</strong> {{date("M j, Y",strtotime($order->created_at))}} <br>
													<strong>Transaction Id:</strong> {{$order->transaction_id}}
												</td>	

												<td>
													Completed : 1 <br><br>
													
													@if(count($transactions)<1)
														<a href="{{URL::route('my-sales-status',['id'=>$order->id])}}" style="color:#F00">Update Action</a><br />
										
														<br />
														@if($order->delivery_option==1) 
															<b>Picked by:</b> <br />
															
															@if($order->picked_by)
																{{$order->picked_by}}<br />	
																<strong>Date:</strong> {{date("d F Y",strtotime($order->picked_date))}}<br />
																<strong>Time:</strong> {{date("H:i A",strtotime($order->picked_date))}}<br />
															@endif 
														@else
															@if($order->courier_by)
																{{$order->courier_by}}<br />	
																<strong>Date:</strong> {{date("d F Y",strtotime($order->courier_date))}}<br />
																<strong>Tracking No:</strong> <br />{{$order->tracking_number}}<br />
															@endif 
														@endif
													@endif	
												</td>
											</tr>
											
											<tr>
										
										<?php
											for($cc=0; $cc<$pendingTrans; $cc++){ ?>
												<td></td><td></td><td></td></tr><tr>
										<?php	}	
										?>
									@endif
								@endif			
                            </tr>
                        @endforeach
                    </tbody>
                </table>
                {!! $orders->appends(request()->except('page'))->render() !!}
            @else
                <br />No data found.
            @endif 
            <br />
            <br />
        </div>
        <br>
    </div>
</div>         

