{!! Theme::section('community.pannel.payments.user-payments-menu',['subpage'=>'ecommerce']) !!}

<div class="box">
    <div class="box-title" style="font-size:16px; font-weight:normal;">
		User Ecommerce Payments		
    </div>
   
    <div class="box-content">
		<div class="">
			@if(count($orders)>0)
            	<table class="table table-bordered users-payments-dashboard-tbl">
                    <thead>
                        <tr>							   
							<th style="width: 25%">Product Details</th>
							<th style="width: 25%">Transaction Details</th> 
							<th style="width: 25%">Seller</th> 
							<th style="width: 25%">Buyer</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($orders as $order)
                            <tr>															
                                <td> 
									<?php
										$businessName="";
										$businessUrl="";
										
										$storeOwner="";
										
										if($order->to_user_id){
											$user=$community->present()->findByIdUsername($order->to_user_id);
											if($user){
												$businessName=$user->fullname;
												$businessUrl=$user->present()->url();
											}
										}										
									?>	
                                    </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=$community->present()->getBusinessPage($dtls->community_business_id);
													}else{
														$business=$community->present()->getBusinessPage($dtls->community_id);
													}
													
													if($business){
														$productUrl=URL::route('store', ['slug' => $business->slug])."/product/".$product->id;
														
														$businessName="Store: ". $business->title;
														$storeOwner="Store owner: ". $business->user->fullname;
														
														$businessUrl=URL::route('store', ['slug' => $business->slug]);
													}else{
														$productUrl=\URL::route('productbuy',['id'=>$product->id]);
													}	
												?>
												
												<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 />
													@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)
														<br />
														<?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
                                                <br />
                                                {{$dtls->product->product_name}} </a>
                                                <br />
                                                <?php $pr++;?>
                                            @endif
                                            <br />
                                        @endforeach
                                    @endif							
                                </td>								
								
								<td>
									<b>Transaction Id:</b> {{$order->transaction_id}} <br />
                                   
                                    <b>Date:</b>
                                    {{date("d F Y",strtotime($order->created_at))}}<br />
                                
                                    <b>Amount:</b>
                                    <?php
                                        if($order->currency=="INR"){  
                                            $currencyIcon="<i class='fa fa-inr'></i>"; 
                                        }
                                        else{
                                            $currencyIcon="<i class='fa fa-dollar'></i>"; 
                                        }
                                    ?>	
                                    
                                    {!! $currencyIcon !!} {{number_format($order->amount, 2, '.', ',')}} <br /><br />                                                   
									
									@if($dtls->product->product_type==1)
										<p><strong>Payment transactions:</strong></p>
																		
										<?php
											$transactions=$community->present()->getBusinessProductsOrders($dtls->product->id,$order->id);
										?>
										
										<div>
											@if(!empty($transactions))
												<table class="table">
													<tr>
														<th>Amount</td>
														<th>Date</td>
														<th>Status and Transaction Id</td>
													</tr>													
													
													@foreach($transactions as $trans)	
														<tr>
															<td>{!! $currencyIcon !!} {{number_format($trans->amount, 2, '.', ',')}}</td>
															<td>{{date("d F Y",strtotime($trans->created_at))}} </td>
															<td>
																<strong>Status:</strong> Completed <br>
																<strong>Transaction Id:</strong> {{$trans->transaction_id}}
															</td>
														</tr>															
													@endforeach	
													
													<tr>
															<td>{!! $currencyIcon !!} {{number_format($order->amount, 2, '.', ',')}}</td>
															<td>{{date("d F Y",strtotime($order->created_at))}} </td>
															<td>
																<strong>Status:</strong> Completed <br>
																<strong>Transaction Id:</strong> {{$order->transaction_id}}
															</td>
														</tr>
												</table>	
											@endif
										</div>										
									@endif
								</td>
								
								<td>
                                   <p> @if($businessName) <a href="{{$businessUrl}}">{{$businessName}}</a> @endif</p>
								   
								   @if($storeOwner) {{$storeOwner}} @endif
                                </td>
								
								<td>
                                    @if($order->user)
                                        <a href="{{$order->user->present()->url()}}">
                                            <img data-original="{{$order->user->present()->getAvatar(50)}}" class="lazy"/>
                                            <br />
                                            {{$order->user->fullname}}
                                        </a>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
                {!! $orders->appends(request()->except('page'))->render() !!}
            @else
                <br />No downloads found.
            @endif 
            <br />
            <br />   
		</div>
	</div>
	<br>
</div>  

