<!-- $o=Account::class -->
<!-- Show past 12 months invoices -->
<div class="card card-success">
	<div class="card-header p-2">
		<h3 class="card-title">Past Invoices</h3>
	</div>

	<div class="card-body p-2">
		@if(($list=$o->invoiceSummaryPast()->where('invoices.created_at','>=',\Carbon\Carbon::now()->subYears(2)->startOfYear())->get())->count())
			<table class="table table-sm table-striped" id="invoices_past_{{ $o->id }}">
				<thead>
				<tr>
					<th>Account</th>
					<th>#</th>
					<th>Issued</th>
					<th>Paid</th>
					<th class="text-right">Total</th>
				</tr>
				</thead>

				<tbody>
				@foreach ($list as $oo)
					<tr>
						<td>{{ $oo->account->name }}</td>
						<td><a href="{{ url('u/invoice',$oo->id) }}">{{ $oo->lid }}</a></td>
						<td>{{ $oo->created_at->format('Y-m-d') }}</td>
						<td>{{ $oo->_paid_at?->format('Y-m-d') }}</td>
						<td class="text-right">${{ number_format($oo->_total,2) }}</td>
					</tr>
				@endforeach
				</tbody>
			</table>

		@else
			<p>No invoices to list</p>
		@endif
	</div>
</div>

@pa(datatables,rowgroup|conditionalpaging)

@section('page-scripts')
	<script type="text/javascript">
		@if($list->count())
			$(document).ready(function() {
				$('#invoices_past_{{ $o->id }}').DataTable({
					conditionalPaging: true,
					order: [[2,'desc'],[0,'asc']],
					rowGroup: {
						dataSrc: 0,
					},
					columnDefs: [
						{
							targets: [0],
							visible: false,
						}
					],
				});
			});
		@endif
	</script>
@append