@use(App\Models\Service)
<!-- Show client movements -->
<div class="card card-dark">
	<div class="card-header p-2">
		<h3 class="card-title">Service Movements</h3>
	</div>

	<div class="card-body p-2">
		@if(($x=Service::movements($user))->count())
			<table class="table table-sm table-striped table-hover" id="service_movements">
				<thead>
				<tr>
					<th>ID</th>
					<th>Account</th>
					<th>Name</th>
					<th>Status</th>
					<th>Product</th>
				</tr>
				</thead>

				<tbody>
				@foreach ($x as $o)
					<tr>
						<td><a href="{{ url('u/service',$o->id) }}">{{ $o->sid }}</a></td>
						<td>{{ $o->account->name }}</td>
						<td>{{ $o->name_short }}</td>
						<td>
							{{ $o->status }}
							@switch($o->status)
								@case ('ORDER-SENT')
									<br>(#{{ $o->order_info_reference }})
									@break;
								@case ('PROVISION-PLANNED')
									<br>({{ ($xx=$o->start_at) ? $xx->format('Y-m-d') : 'No Date' }})
									@break;
								@case ('CANCEL-PENDING')
									<br>({{ ($xx=$o->stop_at) ? $xx->format('Y-m-d') : 'No Date' }})
									@break;
							@endswitch
						</td>
						<td>{{ $o->product->name }}</td>
					</tr>
				@endforeach
				</tbody>

				<tfoot>
				<tr>
					<th>Count {{ $x->count() }}</th>
					<th colspan="4">&nbsp;</th>
				</tr>
				</tfoot>
			</table>
		@else
			<p>No Service Movements</p>
		@endif
	</div>
</div>

@pa(datatables,rowgroup|conditionalpaging)

@section('page-scripts')
	<script type="text/javascript">
		$(document).ready(function() {
			$('#service_movements').DataTable({
				conditionalPaging: true,
				order: [3, 'asc'],
				rowGroup: {
					dataSrc: 1,
					startRender: function ( rows, group ) {
						return group+': '+rows.count()+' Services';
					},
				},
				orderFixed: [1, 'asc']
			});
		});
	</script>
@append