<!-- Show client movements -->
<div class="card card-warning card-outline">
	<div class="card-header">
		<h4 class="card-title">Service Movements</h4>

		<div class="card-tools">
			<button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			<button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
		</div>
	</div>

	<div class="card-body">
		@if (($x=$user->client_service_movements())->count())
			<table class="table table-striped table-hover" id="service_movements" style="width: 100%;">
				<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->id }}</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->date_start) ? $xx->format('Y-m-d') : 'No Date' }})
									@break;
								@case ('CANCEL-PENDING')
									<br>({{ ($xx=$o->date_end) ? $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>

@section('page-scripts')
	@css('//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css','jq-dt-css','jquery')
	@js('//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js','jq-dt-js','jquery')
	@css('//cdn.datatables.net/responsive/2.2.1/css/responsive.dataTables.min.css','dt-responsive-css','jq-dt-css')
	@js('//cdn.datatables.net/responsive/2.2.1/js/dataTables.responsive.min.js','dt-responsive-js','jq-dt-js')
	@css('//cdn.datatables.net/rowgroup/1.0.2/css/rowGroup.dataTables.min.css','dt-rowgroup-css','jq-dt-css')
	@js('//cdn.datatables.net/rowgroup/1.0.2/js/dataTables.rowGroup.min.js','dt-rowgroup-js','jq-dt-js')
	@css('/plugin/dataTables/dataTables.bootstrap4.css','dt-bootstrap4-css','jq-dt-css')
	@js('/plugin/dataTables/dataTables.bootstrap4.js','dt-bootstrap4-js','jq-dt-js')

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

			$('#service_movements tbody').on('click','tr', function () {
				$(this).toggleClass('selected');
			});
		});
	</script>
@append