<!-- $pdo=Product::class -->
<div class="row">
	@if(count($pdo->services))
		<div class="col-7">
			<table class="table table-hover" id="table">
				<thead>
				<tr>
					<th>ID</th>
					<th>Date Start</th>
					<th>Date Stop</th>
					<th>Data Invoiced</th>
					<th>Active</th>
					<th class="text-right"><small>Normalized</small><br>Charge</th>
					<th class="text-right"><small>Normalized</small><br>Cost</th>
					<th>&nbsp;</th>
				</tr>
				</thead>

				<tbody>
				@foreach ($pdo->services as $so)
					<tr>
						<td><a href="{{ url('u/service',[$so->id]) }}">{{ $so->sid }}</a></td>
						<td>{{ $so->start_at ? $so->start_at->format('Y-m-d') : '-' }}</td>
						<td>{{ $so->stop_at ? $so->stop_at->format('Y-m-d') : '-' }}</td>
						<td>{{ $so->invoice_to ? $so->invoice_to->format('Y-m-d') : '-' }}</td>
						<td>{{ $so->active ? 'YES' : 'NO' }}</td>
						<td class="text-right">{{ $a=number_format($so->billing_charge_normalised_taxed,2) }}</td>
						<td class="text-right">{{ $b=number_format($so->billing_cost_normalised_taxed,2) }}</td>
						<td><button class="btn btn-sm @if($a<$b)btn-danger @else btn-success @endif"><small>@if($a<$b)<i class="fas fa-fw fa-exclamation"></i> @else <i class="fas fa-fw fa-check"></i> @endif</small></button></td>
					</tr>
				@endforeach
				</tbody>
			</table>
		</div>

	@else
		<p>No services use this product.</p>
	@endif
</div>

@pa(datatables,select)

@section('page-scripts')
	<script type="text/javascript">
		$(document).ready(function() {
			@if(count($pdo->services))
				$('#table').DataTable({
					paging: true,
					pageLength: 25,
					lengthChange: true,
					searching: true,
					ordering: true,
					info: true,
					autoWidth: false,
					fixedHeader: true,
					order: [[4,'desc'],[0,'asc']],
					columnDefs: [
						{
							targets: [4],
							visible: false,
						}
					],
				});
			@endif
		});
	</script>
@append