<?php $__env->startSection("content"); ?>

<section class="content">
<?php if(Session::has('message')): ?>
<div class="alert alert-info"><?php echo trans(Session::get('message')); ?></div>
<?php endif; ?>
<div  class="panel panel-default">
	<div class="panel-heading ">
		<div class="panel-btn">
			<a class="btn btn-sm btn-info" href="<?php echo URL::route('facilityrequest.create'); ?>" >
				<span class="glyphicon glyphicon-plus-sign"></span>
				<font size="3">	New Request</font>
			</a>

		<!--	<a class="btn btn-sm btn-warning" data-toggle="modal"data-target="#dispatchPending" >
				<span class="glyphicon glyphicon-plus-sign"></span>
				<font size="3">Pending: <?php echo $count = FacilityRequest::where('request_status_id', '=', '0')->where('hub_id', '=', Auth::user()->hubID)->orWhere('f', '=', Auth::user()->faclityID)->count(); ?></font>
			</a>

			<a class="btn btn-sm btn-default" data-toggle="modal"data-target="#cphlRcvd">
				<span class="glyphicon glyphicon-check-box"></span>
				<font size="3">Received at CPHL:  <?php echo $count = FacilityRequest::where('request_status_id', '=', '3')->where('hub_id', '=', Auth::user()->hubID)->orWhere('f', '=', Auth::user()->faclityID)->count(); ?></font>
			</a>

			<a class="btn btn-sm btn-success" data-toggle="modal"data-target="#hubRcvd">
				<span class="glyphicon glyphicon-plus-sign"></span>
				<font size="3">	Received at Hub:  <?php echo $count = FacilityRequest::where('request_status_id', '=', '0')->where('hub_id', '=', Auth::user()->hubID)->orWhere('f', '=', Auth::user()->faclityID)->count(); ?></font>
			</a>

			<a class="btn btn-sm btn-danger"  data-toggle="modal"data-target="#rejects">
				<span class="glyphicon glyphicon-plus"></span>
				<font size="3">Rejected Requests:  <?php echo $count = FacilityRequest::where('request_status_id', '=', '2')->where('hub_id', '=', Auth::user()->hubID)->orWhere('f', '=', Auth::user()->faclityID)->count(); ?></font>
			</a> 

			<a class="btn btn-sm btn-info"  data-toggle="modal"data-target="#dispatched">
				<span class="glyphicon glyphicon-plus-sign"></span>
				<font size="3">Requests Dispatched:  <?php echo $count = FacilityRequest::where('request_status_id', '=', '5')->where('hub_id', '=', Auth::user()->hubID)->orWhere('f', '=', Auth::user()->faclityID)->count(); ?></font>
			</a>-->
		</div>
	</div>
						<!-- Pending modal -->
							<div class="modal fade" id="dispatchPending" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
							<div class="modal-dialog modal-lg">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										<h4 class="modal-title" id="myModalLabel">Requests Pending Receipt at CPHL</h4>
									</div>
												<div class="modal-body">
													<?php echo $__env->make('FacilityRequest.dispatchPending', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
									</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
										</div>
									</form>
								</div>
							</div>
						</div>

						<!-- Received at Cphl modal -->
						<div class="modal fade" id="cphlRcvd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
							<div class="modal-dialog modal-lg" role="document">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										<h4 class="modal-title" id="myModalLabel">Requests Received at CPHL <small style="color:red">(Pending Dispatch)</small></h4>
									</div>
												<div class="modal-body">
													<?php echo $__env->make('FacilityRequest.cphlRcvd', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
									</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
										</div>
									</form>
								</div>
							</div>
						</div>

						<!-- Received at Hub modal -->
						<div class="modal fade" id="hubRcvd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
							<div class="modal-dialog modal-lg" role="document">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										<h4 class="modal-title" id="myModalLabel">Requests Received at Hub <br><small style="color:red"><i>(Dispatched from CPHL but pending receipt at Hub)</i></small></h4>
									</div>
												<div class="modal-body">
													<?php echo $__env->make('FacilityRequest.hubRcvd', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
									</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
										</div>
									</form>
								</div>
							</div>
						</div>

						<!-- Dispatched Modal -->
						<div class="modal fade" id="dispatched" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
							<div class="modal-dialog modal-lg" role="document">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										<h4 class="modal-title" id="myModalLabel">Dispatched Requests</h4>
									</div>
												<div class="modal-body">
													<?php echo $__env->make('FacilityRequest.dispatched', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
									</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
										</div>
									</form>
								</div>
							</div>
						</div>


	<div  class="panel-body">

		<table class="table table-striped table-hover table-bordered search-table">
			<thead>
				<!-- <th class="text-center">#</th> -->
				<th class="text-center">Order Number</th>
				<!-- <th class="text-center">District</th> -->
				<th class="text-center">Item Requested</th>
				<th class="text-center">Requesting Facility</th>
				<th class="text-center">Reporting Period</th>
				<!-- <th class="text-center">Qty Consumed</th> -->
				<!-- <th class="text-center"># Samples Collected<br> <small>(during reporting period)</small></th> -->
				<th class="text-center">Qty Requested</th>
				<!-- <th class="text-center">IP</th> -->
				<!-- <th class="text-center">Requesting Hub</th> -->
				<th class="text-center">Request Date</th>
				<th class="text-center"> Status</th>
				<!-- <th class="text-center">Received @ CPHL By</th> -->
				<!-- <th class="text-center">Date Received @ CPHL</th> -->
				<th class="text-center">Qty Dispatched</th>
				<th class="text-center">Dispatched By</th>
				<th class="text-center">Dispatch Date</th>
				<!-- <th class="text-center">Date Received <small>@ Hub</small></th> -->
				<th class="text-center">Options</th>
			</tr>
		</thead>
		<tbody>
			<?php $row=1; ?>
			<?php foreach($facilityrequest as $value): ?>

			<tr>
				<!-- <td class="text-center"><?php echo $row; ?></td> -->
				<td class="text-center"><?php echo $value->order_number; ?></td>

					<?php if($value->commodity_id == 0): ?>
					<td class="text-center" style="color:red"><i>no commodity selected</i></td>
					<?php else: ?>
					<td><?php echo $value->commodity->name; ?></td>
					<?php endif; ?>
					<td class="text-center"><?php echo $value->facility->facility; ?></td>
					<td class="text-center"><?php echo $value->start_date; ?> - <?php echo $value->end_date; ?></td>
					<!-- <td class="text-center"><?php echo $value->total_consumption; ?></td> -->
					<!-- <td class="text-center"><?php echo $value->samples_collected; ?></td> -->
					<td class="text-center"><?php echo $value->qty_to_order; ?></td>
					<!-- <td class="text-center"><?php echo $value->requested_by; ?></td> -->
					<td class="text-center"><?php echo $value->created_at; ?></td>

					<td class="text-center">
						<!-- status -->
						<?php if($value->request_status_id == 3): ?>
						<span class='label label-success'>Received at CPHL<br> <small>Pending Dispatch</small></span>
						<?php elseif($value->isRejected()): ?>
						<span class='label label-danger'>Order Rejected At CPHL</span>
						<?php elseif($value->isDispatched()): ?>
						<span class='label label-info'>Dispatched</span>
						<?php elseif($value->isAtHub()): ?>
						<span class='label label-default'>Recieved at Hub</span>
						<?php elseif($value->isInTransit()): ?>
						<span class='label label-default'>Order in Transit to Hub</span>
						<?php elseif($value->isCanceled()): ?>
						<span class='label label-danger'>Order Canceled</span>
						<?php elseif($value->isRejcted): ?>
						<span class 'label-danger'>Order Rejected</span>
						<?php else: ?>
						<span class='label label-warning'>Order Rejected</span>
						<?php endif; ?>
					</td>
					<!-- <td class="text-center"><?php echo $value->received_by; ?></td> -->
					<!-- <td class="text-center"><?php echo $value->cphl_date_received; ?></td> -->
					<td class="text-center"><?php echo $value->qty_dispatched; ?></td>
					<td class="text-center"><?php echo $value->dispatched_by; ?></td>
					<td class="text-center"><?php echo $value->dispatch_date; ?></td>
					<!-- <td class="text-center"><?php echo $value->hub_date_received; ?></td> -->
					<td>

						<?php if($value->isDispatched() && Auth::user()->hubID == $value->hub_id): ?>

						<!--  confrim receipt of requisition-->
						<a class="btn btn-sm btn-info" href="<?php echo URL::route('facilityrequest.hubreceipt', array($value->id)); ?>">
							<span class="glyphicon glyphicon-thumbs-up"></span>
							Confrim Receipt
						</a>

						<?php elseif(Auth::user()->username == $value->requested_by  && $value->isPending()): ?>
						<!-- Delete or edit only what you have initiated -->
						<!-- <button class="btn btn-sm btn-danger delete-item-link" data-toggle="modal" data-target=".confirm-delete-modal"
						data-id="<?php echo URL::route('facilityrequest.delete', array($value->id)); ?>">
						<span class="glyphicon glyphicon-trash"></span>
						<?php echo trans('messages.delete'); ?>

					</button> -->

					<!--  edit requisition-->
					<a class="btn btn-sm btn-info" href="<?php echo URL::route('facilityrequest.edit', array($value->id)); ?>" >
						<span class="glyphicon glyphicon-edit"></span>
						<?php echo trans('messages.edit'); ?>

					</a>
					<a class="btn btn-sm btn-danger" href="<?php echo URL::route('facilityrequest.cancel', array($value->id)); ?>" >
						<span class="glyphicon glyphicon-remove"></span>
						Cancel Order
					</a>
					<?php endif; ?>

				</td>
			</tr>
			<?php $row++; ?>
			<?php endforeach; ?>

		</tbody>
	</table>
	<?php Session::put('SOURCE_URL', URL::full());?>
</div>
</div>
<?php $__env->stopSection(); ?>


<?php echo $__env->make("layout", array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>