<div class="container community-invoice-container">
	 {!! Theme::section('user.purchase.menu',['page'=>'']) !!}	
	 
	 <div class="invoice-outer-box">
		<div class="card card-body invoice-wrapper box-shadow" id="invoice-wrapper">
					@if(Session::has('invoice_pay_message'))
						@php
							$invoicePayMsg = Session::get('invoice_pay_message');
							$invoicePayType = Session::get('invoice_pay_message_type', 'success');
							$alertClass = ($invoicePayType === 'danger') ? 'alert-danger' : 'alert-success';
						@endphp
						<div class="alert {{ $alertClass }} alert-dismissable" id="invoicePayAlert" role="alert">
							<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
							{!! $invoicePayMsg !!}
						</div>
					@endif

				<div class="row">
					<div class="col-sm-12">
						<span class="pull-left">
							<p><b>{{ trans('invoices.view.invoice') }}</b>
								<i class="sl-icon-refresh text-danger cursor-pointer hidden" data-toggle="tooltip" id="invoice-recurring-icon" title="{{ trans('invoices.view.recurring-invoice') }}"></i>
							</p>
							
							<span>
								<h5>#{{$invoice->invoice_number}}</h5>
							</span>
						</span>						
						
						<span class="pull-right text-align-right">							
							<!--<span class="js-invoice-statuses " id="invoice-status-draft">
								<h1 class="text-uppercase text-default muted">Draft</h1>
							</span>-->
							
							
							@if(\Auth::user()->id==$invoice->from_user_id and $invoice->has_sent==0)								
								<a class="btn red-color-button" href="{{URL::route('community-invoice-edit',['slug'=>0,'id'=>$invoice->id])}}" style="margin-right:15px;">{{ trans('invoices.view.click-to-edit') }}</a>

								<a class="btn black-color-button delete-action-confirm-custom" data-msg="{{ trans('invoices.view.send-confirm', ['email' => $invoice->email_addresss]) }}" style="width:60px" data-url="{{URL::route('community-invoice-send',['slug'=>0,'id'=>$invoice->id])}}">
									{{ trans('invoices.view.send') }}
								</a>
							@endif

							@if($invoice->has_sent==1)
								@if($invoice->status==0)
									<span class="js-invoice-statuses" id="invoice-status-due">
										<h3 class="text-uppercase text-warning">{{ trans('invoices.view.due') }}</h3>
										@if($invoice->status==0 and \Auth::user()->id==$invoice->to_user_id)
											<span class="btn red-color-button invoice-proceed-pay-btn">{{ trans('invoices.view.proceed-to-pay', ['amount' => '$'.number_format($invoice->total_amount, 2, '.', ',')]) }}</span>
										@endif
									</span>
								@else 
									<span class="js-invoice-statuses" id="invoice-status-paid">
										<h3 class="text-uppercase text-success">{{ trans('invoices.view.paid') }}</h3>								
									</span>
								@endif
							@endif
							
							<!--<span class="js-invoice-statuses hidden" id="invoice-status-overdue">
								<h1 class="text-uppercase text-danger">Overdue</h1>
							</span>-->
							
							<!--<span class="js-invoice-statuses hidden" id="invoice-status-paid">
								<h1 class="text-uppercase text-success">Paid</h1>
							</span>-->
						</span>
					</div>
				</div>	
				<hr>
				
				<div class="row">					
					<div class="col-sm-12">						
						<div class="pull-left">
							<address>
								
								@if($invoice->company_logo)
									<img src="{{\Image::url($invoice->company_logo)}}" class="invoice-company-logo-view" style="margin-bottom:20px;"/>
								@endif

								@if($invoice->from_user)
									<?php
										$user=$invoice->from_user;
									?>
									   <!--<div class="invoice-user-dtls-box">	
										   <a href="{{$user->present()->url()}}" data-ajaxify="true">																							  
												<p class="invoice-user-dtls" style="color:#20aee3 !important;">{{$user->fullname}}</p>
										   </a>
									   </div>--> 	   
								@endif
								
								@if($invoice->address)
									<div class="invoice-address-box">	
										{!! nl2br($invoice->address) !!}
									</div>	
								@endif
							</address>
						</div>
						
						<div class="pull-right text-right">
							<address>
								<p class="invoice-to-heading">{{ trans('invoices.view.invoice-to') }}</p>
								
								@if($invoice->to_user)
									<?php
										$user=$invoice->to_user;
									?>
									   <div class="invoice-user-dtls-box" style="text-align:right; margin">	
										   <a href="{{$user->present()->url()}}" data-ajaxify="true">
												<!--<img src="{{$user->present()->getAvatar(100)}}" class="invoice-user-img"/>-->
												<p class="to-invoice-user-dtls" style="color:#20aee3 !important;">{{$invoice->name}}</p>
												<p>{{$invoice->email_addresss}}</p>
										   </a>
									   </div>
								@else
									<div class="invoice-user-dtls-box" style="text-align:right; margin">  
										<p class="to-invoice-user-dtls" style="color:#20aee3 !important;">{{$invoice->name}}</p>
										<p>{{$invoice->email_addresss}}</p>	
									</div>
								@endif		

								@if($invoice->customer_address)
									<div class="invoice-address-box">	
										{!! nl2br($invoice->customer_address) !!}
									</div>
								@endif								
							</address>
						</div>
					</div>

					<div class="col-sm-12" id="invoice-dates-wrapper">						
						<div class="pull-left invoice-dates">
							<table>
								<tbody>
									<tr>
										<td class="x-date-lang" id="fx-invoice-date-lang"><strong>{{ trans('invoices.view.invoice-date') }}</strong></td>
										<td class="x-date"> <span>{{date("M j, Y",strtotime($invoice->invoice_date))}}</span></td>
									</tr>
									<tr>
										<td class="x-date-due-lang"><strong>{{ trans('invoices.view.due-date') }}</strong></td>
										<td class="x-date-due"> <span>{{date("M j, Y",strtotime($invoice->due_date))}}</span></td>
									</tr>
								</tbody>
							</table>
						</div>
						
						<div class="pull-right invoice-dues">
							<table>
								<tbody>
									@if($invoice->status==0)
										<tr>
											<td class="x-payments-lang" id="fx-payments-date-lang" style="font-size:22px !important; font-weight:bold; color:#000;">{{ trans('invoices.view.due') }}</td>						
											<td class="x-payments"> <span class="p-l-20" style="font-size:22px; font-weight:bold; color:#000;">${{number_format($invoice->total_amount, 2, '.', ',')}}</span></td>
										</tr>
									@else
										<tr>
											<td class="x-payments-lang" id="fx-payments-date-lang">{{ trans('invoices.view.payments') }}</td>						
											<td class="x-payments"> <span class="p-l-20">${{number_format($invoice->total_amount, 2, '.', ',')}}</span></td>
										</tr>
									@endif
									<!--<tr>
										<td class="x-balance-due-lang">Balance Due </td>
										<td class="x-balance-due"> 
											<span class="x-due-amount-label">
												<label class="label label-rounded label-success" id="billing-details-amount-due">$0.00</label>
											</span>
										
											<span class="x-due-amount-plain hidden">$0.00</span>
										</td>
									</tr>-->
								</tbody>
							</table>
						</div>
					</div>
		
					<div class="col-sm-12">
						<div class="table-responsive m-t-40 invoice-table-wrapper  clear-both">
							<table class="table table-hover invoice-table invoice-table-items">
								<thead>
									<tr>
										<th class="text-left x-description bill_col_description">{{ trans('invoices.view.invoice-items') }}</th>
										
										<th class="text-left x-quantity bill_col_quantity">{{ trans('invoices.view.qty') }}</th>
										
										<th class="text-left x-unit bill_col_unit">{{ trans('invoices.view.price') }}</th>
										
										<th class="text-left x-rate bill_col_rate">{{ trans('invoices.view.description') }}</th>
										
										<th class="text-right x-total bill_col_total" id="bill_col_total">{{ trans('invoices.view.total') }}</th>
									</tr>
								</thead>
								
								<tbody id="billing-items-container">
									@foreach($invoice->items as $item)
										<tr>
											<td>{!! $item->item_name !!}</td>
											<td>{!! $item->quantity !!}</td>
											<td>${!! number_format($item->price, 2, '.', ',') !!}</td>
											<td>{!! nl2br($item->item_description) !!}</td>
											<td class="text-right">${{number_format($item->sub_total, 2, '.', ',')}}</td>
										</tr>	
									@endforeach							
								</tbody>
							</table>
						</div>
					</div>

					<div class="col-sm-12" id="bill-totals-wrapper">				
						<div class="pull-right m-t-30 text-right">
							<table class="invoice-total-table">

								<tbody id="billing-table-section-subtotal">
									<tr>
										<td>{{ trans('invoices.view.subtotal') }}</td>
										<td id="billing-subtotal-figure">
											<span>${{number_format($invoice->sub_total_amount, 2, '.', ',')}}</span>
										</td>
									</tr>
								</tbody>
								
								@if($invoice->tax_percentage)								
									<!--<tbody id="billing-table-section-tax">
										<tr>
											<td>Applicable Tax</td>
											<td id="billing-subtotal-figure">
												<span>${{$invoice->tax_amount}} ({{number_format($invoice->tax_percentage, 2, '.', ',')}}%)</span>
											</td>
										</tr>
									</tbody>-->
								@endif	
								
								@if($invoice->tax1_percentage and $invoice->tax1_amount!="0.00" and $invoice->tax1_amount!="" and $invoice->tax1_amount!=0)								
									<tbody id="billing-table-section-tax">
										<tr>
											<td>{!! $invoice->tax1_name !!} : </td>
											<td id="billing-subtotal-figure">
												<span>${{$invoice->tax1_amount}} ({{number_format($invoice->tax1_percentage, 2, '.', ',')}}%)</span>
											</td>
										</tr>
									</tbody>
								@endif
								
								@if($invoice->tax2_percentage and $invoice->tax2_amount!="0.00" and $invoice->tax2_amount!="" and $invoice->tax2_amount!=0)								
									<tbody id="billing-table-section-tax">
										<tr>
											<td>{!! $invoice->tax2_name !!} : </td>
											<td id="billing-subtotal-figure">
												<span>${{$invoice->tax2_amount}} ({{number_format($invoice->tax2_percentage, 2, '.', ',')}}%)</span>
											</td>
										</tr>
									</tbody>
								@endif
								
								@if($invoice->tax3_percentage and $invoice->tax3_amount!="0.00" and $invoice->tax3_amount!="" and $invoice->tax3_amount!=0)								
									<tbody id="billing-table-section-tax">
										<tr>
											<td>{!! $invoice->tax3_name !!} : </td>
											<td id="billing-subtotal-figure">
												<span>${{$invoice->tax3_amount}} ({{number_format($invoice->tax3_percentage, 2, '.', ',')}}%)</span>
											</td>
										</tr>
									</tbody>
								@endif

								<tbody id="invoice-table-section-total">																		
									<tr class="text-themecontrast" id="billing-sums-total-container">
										<td class="billing-sums-total">{{ trans('invoices.view.total') }}</td>
										<td id="billing-sums-total">
											<span>${{number_format($invoice->total_amount, 2, '.', ',')}}</span>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
						
						<div style="clear:both"></div>
						
						@if($invoice->status==0 and \Auth::user()->id==$invoice->to_user_id)
							<div class="invoice-pay-now-box" style="padding-right: 0px; text-align:right;">
								<span class="btn red-color-button invoice-proceed-pay-btn" style="border-radius:4px; width:200px;">{{ trans('invoices.view.proceed-to-payment') }} {{--${{number_format($invoice->total_amount, 2, '.', ',')}}--}}</span>
							</div>
						@endif
					</div>
			
					@if($invoice->terms)
						<div class="col-sm-12" style="clear:both">							
							<div class="text-left">
								<p class="invoice-terms-heading">{{ trans('invoices.view.invoice-terms') }}</p>
								<div class="invoice-terms-texts"><p>{!! $invoice->terms !!}</p></div>
							</div>
						</div>	
				    @endif

					@if($invoice->message)
						<div class="col-sm-12" style="clear:both">							
							<div class="text-left">
								<p class="invoice-terms-heading">{{ trans('invoices.view.message-to-customer') }}</p>
								<div class="invoice-terms-texts"><p>{!! $invoice->message !!}</p></div>
							</div>
						</div>	
				    @endif

					@if($invoice->status==1 and $invoice->transaction_id)
						<div class="invoice-pay-now-box">
							 <p><strong>{{ trans('invoices.view.payment-transaction-id') }}</strong> - {!! $invoice->transaction_id !!}</p> 
							 <p><strong>{{ trans('invoices.view.payment-date') }}</strong> - {{date("M j, Y",strtotime($invoice->payment_date))}}</p> 
						</div>
					@endif	
					
					@if($invoice->status==0 and \Auth::user()->id==$invoice->to_user_id)
						<div class="invoice-pay-now-box">	
							{!! Theme::section('invoices.payment-form',[
								'invoice'=>$invoice,
								'organizationDetails'=>$organizationDetails,
								'cards'=>$cards ?? null,
								'default_card'=>$default_card ?? null,
								'community_id_for_cards'=>$community_id_for_cards ?? 0,
							]) !!}
						</div>	
					@endif
			  </div>	 
		</div>	
	</div>
</div>	
