@extends('templates.sheet-master')

@section('content')
		<div class="options hidden-print">
			<div class="btn-group">
				<span class="btn btn-success" onClick="if (window.self) window.print()">Print</span>

				<a class="btn btn-danger" href="/clients#/customer/{!! $client->id !!}" target="_self">Back</a>
			</div>
		</div>
		<div class="title">
			<i class="fa fa-bar-chart"></i> {!! $client->name !!} Report
			<span class="period">
			@if( $start_date != null &&  $end_date != null )
				(From {!! date_format( new DateTime($start_date), 'd/m/Y')  !!} to {!! date_format( new DateTime($end_date), 'd/m/Y')  !!})
			@else
				(All time)
			@endif
			</span>

		</div>

		<!-- Render the pie charts -->
		<div class="row">
			<div class="col-xs-4">
				<div class="widget widget-classic">
					<div class="widget-content">
						<div class="headline">
							<h4><i class="fa fa-ticket"></i> Number of task per department</h4>
						</div>
						<table class="table table-condensed table-striped">
							<tr>
								<td>Total</td>
								<td><span class="pull-right"> {!! $repairs->count() + $supports->count() + $onsites->count() !!}</span></td>
							</tr>
						</table>
						@if( $repairs->count() + $supports->count() + $onsites->count() > 0 )
							<div client-tasks-stats data-type="count" data-onsite-inf="{!! $onsites->count() !!}" data-support-inf="{!! $supports->count() !!}" data-repair-inf="{!! $repairs->count() !!}"></div>
						@else
							<div class="stats_no_data">No data.</div>
						@endif
					</div>
				</div>
			</div>
			<div class="col-xs-4">
				<div class="widget widget-classic">
					<div class="widget-content">
						<div class="headline">
							<h4><i class="fa fa-money"></i> Amount spent per department</h4>
						</div>
						<table class="table table-condensed table-striped">
							<tr>
								<td>Total</td>
								<td><span class="pull-right"> £{!! $repairs->sum('labour') + $supports->sum('labour') + $onsites->sum('labour') !!}</span></td>
							</tr>
						</table>
						@if( $repairs->sum('labour') + $supports->sum('labour') + $onsites->sum('labour')  > 0)
							<div client-tasks-stats data-type="labour" data-onsite-inf="{!! $onsites->sum('labour') !!}" data-support-inf="{!!  $supports->sum('labour') !!}" data-repair-inf="{!! $repairs->sum('labour') !!}"></div>
						@else
							<div class="stats_no_data">No data.</div>
						@endif
					</div>
				</div>
			</div>
			<div class="col-sm-4 col-xs-4">
				<div class="widget widget-classic">
					<div class="widget-content">
						<div class="headline">
							<h4><i class="fa fa-clock-o"></i> Time of work per department</h4>
						</div>
						<table class="table table-condensed table-striped">
							<tr>
								<td>Total</td>
								<td><span class="pull-right"> {!! $repairs->sum('time_spent') + $supports->sum('time_spent') + $onsites->sum('time_spent') !!} hours</span></td>
							</tr>
						</table>
						@if(  $repairs->sum('time_spent') + $supports->sum('time_spent') + $onsites->sum('time_spent') > 0)
							<div client-tasks-stats data-type="time" data-onsite-inf="{!!  $onsites->sum('time_spent') !!}" data-support-inf="{!! $supports->sum('time_spent') !!}" data-repair-inf="{!! $repairs->sum('time_spent') !!}"></div>
						@else
							<div class="stats_no_data">No data.</div>
						@endif
					</div>
				</div>
			</div>
		</div>


		<!-- List of task realized for this client -->
		<div id='tasks'>

			@if($repairs->count() == 0 && $supports->count() == 0 && $onsites->count() == 00)
				We haven't realize any job for this client
			@else

				<!-- List of support task-->
				@if($supports->count() !=0 )
					<div class='bs-callout bs-callout-danger'>
						<h4><i class="fa fa-laptop"></i> Support Tasks</h4>


							@foreach($supports as $support)
								<table width="100%">
									<tr class="main">
										<th width="20%"><i class="fa fa-calendar"></i> {!! date_format( new DateTime($support->created_at), "j F, Y,   g:i a") !!}</th>
										<th width="70%" valign='top'><i class="fa fa-ticket"></i> {!! $support->title !!}</th>
										<th width='10%' class="text-right"> £{!! $support->labour !!}</th>
									</tr>
									<tr><td colspan='3'>&nbsp;</td></tr>
									<tr class="details">
										<td colspan="3">
											<div class="row">
												<span class="col-xs-3 text-center"><span class="task_property">Technician: </span> <span class="task_inf">{!! $support->user ? $support->user->name : 'No one' !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Duration: </span> <span class="task_inf">{!! $support->time_spent !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Status: </span> <span class="task_inf">{!! $support->status->name !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Finished at: </span> <span class="task_inf">{!! date_format( new DateTime($support->completed_at), "F j, Y, g:i a") !!}</span></span>
											</div>
										</td>
									</tr>
									<tr>
										<td colspan="3">&nbsp;</td>
									</tr>
								</table>
							@endforeach

					</div>
				@endif

				<!-- List of repairs task-->
				@if($repairs->count() !=0 )
					<div class='bs-callout bs-callout-warning'>
						<h4><i class="fa fa-wrench"></i> Repair Tasks</h4>


							@foreach($repairs as $repair)
								<table width="100%">
									<tr class="main">
										<th width="20%"><i class="fa fa-calendar"></i>{!! date_format( new DateTime($repair->created_at), "j F, Y,   g:i a") !!}</th>
										<th width="70%" valign='top'><i class="fa fa-ticket"></i> {!! $repair->title !!}</th>
										<th width='10%' class="text-right"> £{!! $repair->labour !!}</th>
									</tr>
									<tr><td colspan='3'>&nbsp;</td></tr>
									<tr class="details">
										<td colspan="3">
											<div class="row">
												<span class="col-xs-3 text-center"><span class="task_property">Technician: </span> <span class="task_inf">{!! $repair->user ? $repair->user->name : 'No one' !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Duration: </span> <span class="task_inf">{!! $repair->time_spent !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Status: </span> <span class="task_inf">{!! $repair->status->name !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Finished at: </span> <span class="task_inf">{!! date_format( new DateTime($repair->completed_at), "F j, Y, g:i a") !!}</span></span>
											</div>
										</td>
									</tr>
									<tr>
										<td colspan="3">&nbsp;</td>
									</tr>
								</table>
							@endforeach

					</div>
				@endif



				<!-- List of onsite task-->
				@if($onsites->count() !=0 )
					<div class='bs-callout bs-callout-info'>
						<h4><i class="fa fa-truck"></i> Onsite Tasks</h4>
						@foreach($onsites as $onsite)
								<table width="100%">
									<tr class="main">
										<th width="20%"><i class="fa fa-calendar"></i> {!! date_format( new DateTime($onsite->created_at), "j F, Y,   g:i a") !!}</th>
										<th width="70%" valign='top'><i class="fa fa-ticket"></i> {!! $onsite->title !!}</th>
										<th width='10%' class="text-right"> £{!! $onsite->labour !!}</th>
									</tr>
									<tr><td colspan='3'>&nbsp;</td></tr>
									<tr class="details">
										<td colspan="3">
											<div class="row">
												<span class="col-xs-3 text-center"><span class="task_property">Technician: </span> <span class="task_inf">{!! $onsite->user ? $onsite->user->name : 'No one' !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Duration: </span> <span class="task_inf">{!! $onsite->time_spent !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Status: </span> <span class="task_inf">{!! $onsite->status->name !!}</span></span>
												<span class="col-xs-3 text-center"><span class="task_property">Finished at: </span> <span class="task_inf">{!! date_format( new DateTime($onsite->completed_at), "F j, Y, g:i a") !!}</span></span>
											</div>
										</td>
									</tr>
									<tr>
										<td colspan="3">&nbsp;</td>
									</tr>
								</table>
							@endforeach
					</div>
				@endif


			@endif
		</div>

		<!-- Footer -->
		<div class="text-right">
			<strong>Report printed by Computer Assistance on the  {!! date('j \o\f F \o\f Y \a\t g:i a') !!}. <br>Thanks for your confiance.</strong>
		</div>


@stop