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

<div>
	<ol class="breadcrumb">
		<li><a href="<?php echo e(URL::route('user.home')); ?>"><?php echo trans('messages.home'); ?></a></li>
		<li class="active">Purchase Requests</li>
	</ol>
</div>


<!-- Style the tab -->
<style>
.tab {
	overflow: hidden;
	border: 1px solid #ccc;
	background-color: #f1f1f1;
}

/* Style the buttons that are used to open the tab content */
.tab button {
	background-color: inherit;
	float: left;
	border: none;
	outline: none;
	cursor: pointer;
	padding: 14px 16px;
	transition: 0.3s;
}

/* Change background color of buttons on hover */
.tab button:hover {
	background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
	background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
	display: none;
	padding: 6px 12px;
	border: 1px solid #ccc;
	border-top: none;
}

.tabcontent {
	animation: fadeEffect 1s; /* Fading effect takes 1 second */
}

/* Go from zero to full opacity */
@keyframes  fadeEffect {
	from {opacity: 0;}
	to {opacity: 1;}
}
</style>

<!-- Tab links -->
<div class="tab">
	<button class="tablinks" onclick="openrequest(event, 'yours')">Total Dispatched This week <br><h3><?php echo $count = dispatch::where('id', '!=', '0')->count(); ?></h3></button>
	<button class="tablinks" onclick="openrequest(event, 'all')">Total Dispatched This month<br><h3></h3></button>
	<button class="tablinks" onclick="openrequest(event, 'stores')">Total Dispatched <br><h3></h3></button>
	<button class="tablinks" onclick="openrequest(event, 'issued')">Issued Request <br><h3></h3></button>
	<button class="tablinks" onclick="openrequest(event, 'rejected')">Rejected <br><h3></h3></button>
	<button>Total Transactions <br><h3><?php echo $count = dispatch::where('id', '!=', '0')->count(); ?></h3></button>
</div>

<!-- Tab content -->
<div id="yours" class="tabcontent">

	<?php if(Session::has('message')): ?>
	<div class="alert alert-info"><?php echo trans(Session::get('message')); ?></div>
	<?php endif; ?>
	<div  class="panel panel-default row" style="width:97%">
		<div class="panel-heading ">
			<span class="glyphicon glyphicon-list"></span>
			Dispatched Items
			<div class="panel-btn">
				<a class="btn btn-sm btn-info" href="<?php echo URL::route('dispatch.create'); ?>" >
					<span class="glyphicon glyphicon-plus-sign"></span>
					<font size="3">	New Dispatch</font>
				</a>
			</div>
		</div>

		<table id='dispatchtable' class="table table-striped table-hover table-bordered search-table" style="font-size: 110%">
			<thead>
				<tr>
					<th class="text-center">#</th>
					<th class="text-center">Hub/Facility</th>
					<th class="text-center">District</th>
					<th class="text-center">Health Region</th>
					<th class="text-center">Item</th>
					<th class="text-center">Quantity</th>
					<th class="text-center">Unit of Measure</th>
					<th class="text-center">Dispatched By</th>
					<th class="text-center">Dispatch Date</th>
					<th class="text-center">Actions</th>
				</tr>
			</thead>

			<tbody>

				<?php $row=1; ?>
				<?php foreach($dispatch as $value): ?>
				<tr>
					<td class="text-center"><?php echo $row; ?></td>
					<td class="text-center"><?php echo $value->folio_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->quantity; ?></td>
					<td>-</td>
					<?php if($value->department == ''): ?>
					<td class="text-center" style="color:red"><i>no dept selected</i></td>
					<?php else: ?>
					<td>-</td>
					<?php endif; ?>
					<td><?php echo $value->incharge_mail; ?></td>
					<td><?php echo $value->approved_by; ?></td>
					<td><?php echo $value->store_approved_by; ?></td>
					<td><?php echo $value->issued_by; ?></td>
					<td class="text-center"><?php echo $value->created_at; ?></td>

					<td>
					<span class='label label-success'>Approved</span>
					</td>
					<td>

						<!-- 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 }}">
							<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('dispatch.edit', array($value->id)); ?>" >
							<span class="glyphicon glyphicon-edit"></span><?php echo trans('messages.edit'); ?></a>

						<!--Print label-->
						<a class="btn btn-sm btn-info" href="<?php echo URL::route('dispatch.edit', array($value->id)); ?>" >
							<span class="glyphicon glyphicon-print"></span> Print Label</a>

						</td>
					</tr>
					<?php $row++; ?>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	</div>
	<script>

		function openrequest(evt, cityName) {
			// Declare all variables
			var i, tabcontent, tablinks;

			// Get all elements with class="tabcontent" and hide them
			tabcontent = document.getElementsByClassName("tabcontent");
			for (i = 0; i < tabcontent.length; i++) {
				tabcontent[i].style.display = "none";
			}

			// Get all elements with class="tablinks" and remove the class "active"
			tablinks = document.getElementsByClassName("tablinks");
			for (i = 0; i < tablinks.length; i++) {
				tablinks[i].className = tablinks[i].className.replace(" active", "");
			}

			// Show the current tab, and add an "active" class to the button that opened the tab
			document.getElementById(cityName).style.display = "block";
			evt.currentTarget.className += " active";

		}

		$(document).ready(function () {
			$('#datatables').DataTable({
				"processing": true,
				"serverSide": true,
				"ajax":{
					"url": "/fetch_records",
					"dataType": "json",
					"type": "POST",
					"data":{ _token: "<?php echo csrf_token(); ?>"}
				},
				"columns": [
				{ "data": "folio_number" },
				{ "data": "commodity_id" },
				{ "data": "quantity" },
				{ "data": "user_id" },
				{ "data": "department" },
				{ "data": "incharge_mail" },
				{ "data": "approved_by" },
				{ "data": "rejected_by" },
				{ "data": "issued_by" },
				{ "data": "request_status_id" }
				]

			});
		});
	</script>
	<?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(); ?>