@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="/tasks/repairs/{!! $task->id !!}" target="_self">Back</a>
			</div>
		</div>

		<div class="row" align='bottom'>
			<!-- Task problem-->
			<div class="col-xs-7">
				<div class="bs-callout bs-callout-danger"  style="margin-bottom: 5px;">
					<h4> <i class="fa fa-wrench"></i> {!! $task->title !!}</h4>
					<p>
						<div class="wrapper">{!! $task->formatedProblem !!}</div>
					</p>
				</div>
				<!--Staff members-->
				<hr style="margin: 20px 0;" />
				<h4 style="margin-bottom: 20px;"><i class="fa fa-users"></i> Staff Members Involved in this Repair</h4>
				<div class='row'>

					@foreach($task->involved_users() as $user)
						<div class='col-xs-4 col-sm-3' style="margin-bottom:20px" >
							<div class="text-center">
								<img style="width: 45px;" src="{!! $user->profile_photo_url !!}">
							</div>
							<div class="text-center">
								<div><strong>{!! $user->name !!}</strong></div>
								<small class="text-muted">{!! $user->role !!}</small>
							</div>
						</div>
					@endforeach


				</div>

				@if($task->comments()->count() > 0)
					<div class="bs-callout bs-callout-info">
						<h4>Comments</h4>
						@foreach($task->comments as $comment)
							<p>{{ $comment->comment }} <small>by <strong>{{ $comment->creator ? $comment->creator->name : 'Unknown User' }}</strong> on {{ date("d/m/Y H:i", strtotime($comment->created_at)) }}</small></p>
						@endforeach
					</div>
				@endif
				{{-- If cancelled --}}
				@if($task->status_id == '8')
					<div class="alert alert-danger ng-binding media">
						<i class="fa fa-exclamation-triangle"></i> Cancellation reason: {!! $task->cancelled_reason !!}
					</div>
				@endif

				@if($task->completed_template_items()->count() > 0)
					<div class="bs-callout bs-callout-info">
						<h4>Template</h4>
						<ul>
							@foreach($task->completed_template_items as $item)
								<li>{!! $item->name !!} <span class="glyphicon glyphicon-ok-circle text-success"></span></li>
							@endforeach
						</ul>
					</div>
				@endif

			</div>
			<div class="col-xs-5">
				{{-- Summary Box --}}
				<div class="panel panel-default">
					<div class="panel-heading">
						<h4 class="panel-title"><i class="fa fa-ticket"></i> Summary</h4>
					</div>
					<table class="table">
						<tbody>
							<tr><th>Booked in Date:</th>   <th style="text-align:right"> {!! date_format( new DateTime($task->created_at), 'd/m/Y')  !!}</th></tr>
							<tr><th>Job Number:</th>   <th style="text-align:right"> {!! $task->id !!} </th></tr>
							<tr><th>Labour:</th>   <th style="text-align:right"> &pound;{!! $task->labour !!} </th></tr>
							@if($task->attended_time)
								<tr><th>Attended Time:</th> <th style="text-align:right"> {!! $task->present()->attendedTime !!} </th></tr>
							@endif
							@if($task->unattended_time)
								<tr><th>Unattended Time:</th> <th style="text-align:right"> {!! $task->present()->unattendedTime !!} </th></tr>
							@endif
						</tbody>
					</table>
				</div>

				{{-- Getting the icon for all the devices classes --}}
				<?php $deviceIcon = ['laptop' => 'fa fa-laptop', 'pc' => 'fa-desktop', 'mac' => 'fa-apple', 'tablet' => 'fa-tablet', 'hdd' => 'fa-hdd-o'] ?>
				@foreach($task->devices as $device)
					<div class="panel panel-default">
						<div class="panel-heading">
							<h4 class="panel-title"><i class="fa {!! $deviceIcon[$device->type] !!}"></i> {!! $device->name !!}</h4>
						</div>

							<table class="table">
								<col width="30%" />
								<col width="70%" />
								<tr>
									<th>PSU:</th>
									<td class='text-right'>{!! $device->psu ? 'Yes' : 'No' !!}</td>
								</tr>
								<tr>
									<th>Case:</th>
									<td class='text-right'>{!! $device->case ? 'Yes' : 'No' !!}</td>
								</tr>
								@if( $device->other_items)
									<tr>
										<th>Other Items:</th>
										<td class='text-right'>{!! $device->other_items !!}</td>
									</tr>
								@endif
								<tr>
									<th>Visual Inspection:</th>
									<td class='text-right'>{!! $device->visual_inspection !!}</td>
								</tr>
								@if($device->ram_model !== null || $device->ram_size || $device->ram_speed)
								<tr>
									<th valign="top">RAM:</th>
									<td>
										<table width="100%">
											<col width="50%" />
											<col width="50%" />
											<tr>
												<td colspan='2' class='text-right'>
													{!! $device->present()->ramStatusMessage !!}
												</td>
											</tr>
											<tr><td>&nbsp;</td></tr>
											@if( $device->ram_model !== null)
												<tr><td>Model:</td><td>{!! $device->ram_model !!}</td></tr>
											@endif
											@if( $device->ram_size)
												<tr><td>Size:</td><td>{!! $device->present()->ramSize !!}</td></tr>
											@endif
											@if( $device->ram_speed !== null)
												<tr><td>Speed:</td><td>{!! $device->present()->ramSpeed !!}</td></tr>
											@endif
										</table>
									</td>
								</tr>
								@endif
								@if( $device->hdd_model !== null || $device->hdd_size !== null || $device->status !== null )
								<tr>
									<th valign="top">HDD:</th>
									<td>
										<table width="100%">
											<col width="50%" />
											<col width="50%" />
											<tr><td colspan='2' class='text-right'>{!! $device->present()->hddStatusMessage() !!}</td></tr>
											<tr><td>&nbsp;</td></tr>
											@if($device->hdd_model !== null)
												<tr><td>Model:</td><td>{!! $device->hdd_model !!}</td></tr>
											@endif
											@if( $device->hdd_size !== null )
												<tr><td>Size:</td><td>{!! $device->present()->hddSize !!}</td></tr>
											@endif
										</table>
									</td>
								</tr>
								@endif
								@if( $device->antivirus !== null || $device->has_antivirus !== null || $device->num_viruses !==null || $device->is_secure )
								<tr>
									<th valign="top">Antivirus:</th>
									<td>
										<table width="100%">
											<col width="50%" />
											<col width="50%" />
											<tr><td colspan='2' class='text-right'>{!! $device->present()->antivirusStatusMessage() !!}</td></tr>
											<tr><td>&nbsp;</td></tr>
											@if( $device->has_antivirus !== null)
												<tr><td>Has Antivirus:</td><td>{!! $device->present()->hasAntivirus !!}</td></tr>
											@endif
											@if( $device->antivirus !== null && $device->has_antivirus)
												<tr><td>Program:</td><td>{!! $device->present()->antivirusProgram !!}</td></tr>
											@endif
											@if( $device->antivirus_expiration_date !== null && $device->has_antivirus)
												<tr><td>Expiration Date:</td><td>{!! $device->present()->antivirusExpirationDate !!}</td></tr>
											@endif
											@if( $device->num_viruses )
												<tr><td>Viruses Found:</td><td>{!! $device->present()->numViruses !!}</td></tr>
											@endif
											@if( $device->is_secure !==null)
												<tr><td>Device Secure:</td><td>{!! $device->present()->isSecure !!}</td></tr>
											@endif
										</table>
									</td>
								</tr>
								@endif
							</table>
						@if($device->revisionHistory()->count() > 0)
							<table class="table" style="background-color: #F5F5F5; font-size: 90%;">
								<tbody>
									<tr><th>CHANGES:</th></tr>
									@foreach($device->revisionHistory as $history )

										@if($history->fieldName() != 'updated_by' && $history->fieldName() != 'Recommended RAM Size' && $history->oldValue() !== null && $history->oldValue() != '')
											<tr>
												<td>
													{!! $device->present()->printChange($history) !!}
												</td>
											</tr>
											<?php $any = true; ?>
										@endif
									@endforeach
									@if( ! isset($any))
										<tr>
											<td>
												No chages made
											</td>
										</tr>
									@endif
								</tbody>
							</table>
						@endif

					</div>
				@endforeach
				{{-- Parts needed --}}
				@if($task->parts()->count() > 0)
				<div class="panel panel-default">
					<div class="panel-heading">
						<h4 class="panel-title"><i class="fa fa-fw fa-paperclip"></i> Parts</h4>
					</div>
					<table class="table">
						<tbody>
							<tr><th>Name:</th>   <th style="text-align:right">Price</th></tr>
							@foreach($task->parts as $part)
								<tr><td>{!! $part->stock->name !!}</td>  <td align='right'>&pound;{!! $part->price !!}</td></tr>
							@endforeach
							<tr><th>Total:</th>   <th style="text-align:right">&pound;{!! $task->parts()->sum('price') !!}</th></tr>
						</tbody>
					</table>
				</div>
				@endif

			</div>

		</div>
@stop