<!-- $o=Account::class -->
<div>
	<label>Invoices Due</label>
	@if(($x=$o->invoices()
		->active()
		->orderBy('due_at')
		->with(['items.taxes','payments','account'])
		->get()
		->filter(function($item) use ($pid) { return $item->due > 0 || $item->payments->search(function($item) use ($pid) { return $item->id == $pid; }) !== FALSE; }))->count())
		<table class="table table-hover">
			<thead>
			<tr>
				<th>ID</th>
				<th>Date Issue</th>
				<th>Date Due</th>
				<th>Total</th>
				<th>Due</th>
				<th class="text-right">Apply</th>
			</tr>
			</thead>

			<tbody>
			@foreach ($x as $io)
				<tr>
					<td><a href="{{ url('u/invoice',[$io->id]) }}">{{ $io->sid }}</a></td>
					<td>{{ $io->created_at->format('Y-m-d') }}</td>
					<td>{{ $io->due_at->format('Y-m-d') }}</td>
					<td>{{ number_format($io->total,2) }}</td>
					<td>{{ number_format($io->due,2) }}</td>
					<td class="text-right">
						<x-leenooks::form.text class="text-right" id="invoices_{{$io->id}}" name="invoices[{{ $io->id }}]" icon="fa-dollar-sign" old="invoices.{{$io->id}}" :value="number_format(($x=$io->payment_items->filter(fn($item)=>$item->payment_id == $pid)) ? $x->sum('amount') : 0,2)"/>
					</td>
				</tr>
			@endforeach
			</tbody>
		</table>
	@else
		<p>No invoices due.</p>
	@endif
</div>