
<?php $__env->startSection('title'); ?> Cost Of Truck Inefficiency <?php $__env->stopSection(); ?>
<?php $__env->startSection('body'); ?>

<div class="row">
	<div class="form-group col-md-3">
		<label class="control-label">From</label>
		<input type="text" class="form-control fromDate" name="fromDate">
	</div>
	<div class="form-group col-md-3">
		<label class="control-label">To</label>
		<input type="text" class="form-control toDate" name="toDate">
	</div>
</div>
<div class="row">
	<div class="form-group col-md-3">
		<label>Delivery Type</label>
		<select class="form-control type chosen-select" multiple name="type">
			<option value="GT">GT</option>
			<option value="MT">MT</option>
			<option value="GT-MT">GT-MT</option>
			<option value="Other">Other</option>
		</select>
		<label><input type="checkbox" class="filter" value="type"> Select All</label>
	</div>
	<div class="form-group col-md-3">
		<label class="control-label">Max Volume Efficiency (%)</label>
		<input type="text" class="form-control max" value="88" name="max">
	</div>
	<div class="form-group col-md-3">
		<button class="btn btn-primary generate" style="margin-top: 25px;">Generate</button>
		<button class="btn btn-primary export pull-right" style="margin-top: 25px;">Export</button>
	</div>
</div>

<div class="row">
	<div class="col-md-10">
		<div class="table-responsive">
			<table class="table table-condensed table-bordered section1">
				<tbody>
					<tr>
						<th style="width: 600px !important;">Trips</th><td class="trips">0</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Trips removed due to maximum utilization</th><td class="utilized_trips">0</td>
					</tr>

					<tr><td colspan="2" style="padding: 15px;"></td></tr>

					<tr>
						<th style="width: 600px !important;">(V%) Average Volume Utilization - based on trips in which space utilization is poor</th><td class="v_average_percent">0%</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">'V' categorized trips</th><td class="volume_count">0</td>
					</tr>

					<tr>
						<th style="width: 600px !important;">(W%) Average Weight Utilization - based on trips in which weight utilization is poor</th><td class="w_average_percent">0%</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">'W' categorized trips</th><td class="weight_count">0</td>
					</tr>


					<tr><td colspan="2" style="padding: 15px;"></td></tr>



					<tr>
						<th style="width: 600px !important;">Average volume per trip</th><td class="average_volume_per_trip">0 CBM</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Average weight per trip</th><td class="average_weight_per_trip">0 Kg</td>
					</tr>
					




					<tr><td colspan="2" style="padding: 15px;"></td></tr>

					<tr>
						<th style="width: 600px !important;">Total carrying volume available for 'V' category</th><td class="available_total_volume">0 CBM</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Total carrying weight available for 'W' category</th><td class="available_total_weight">0 Kg</td>
					</tr>
					

					<tr><td colspan="2" style="padding: 15px;"></td></tr>

					<tr>
						<th style="width: 600px !important;">Number of trips addded due to volume utilization inefficiency</th><td class="volume_loss_trips">0</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Number of trips addded due to weight utilization inefficiency</th><td class="weight_loss_trips">0</td>
					</tr>

					<tr><td colspan="2" style="padding: 15px;"></td></tr>

					<tr>
						<th style="width: 600px !important;">Average delivery cost per trip</th><td class="average_delivery_cost">Rs 0.00</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Cost of volume inefficiency</th><td class="v_inefficiency_cost">Rs 0.00</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Cost of weight inefficiency</th><td class="w_inefficiency_cost">Rs 0.00</td>
					</tr>
					<tr>
						<th style="width: 600px !important;">Total cost of inefficiency</th><td class="total_inefficiency_cost">Rs 0.00</td>
					</tr>

				</tbody>
			</table>
		</div>
	</div>
</div>


<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script type="text/javascript">
	$(function(){
		var _token = $('meta[name="_token"]').attr('content');
		var errors = JSON.parse('<?php echo json_encode($errors->toArray()) ?>');
		$('body').highlight({errors: errors.errors});
		$('.chosen-select').chosen({search_contains:true});
		
		$(document).ajaxStart(function () {
	        $('button').data('loading-text', '...');
	        $('button').button('loading');
	    }).ajaxStop(function () {
	        $('button').button('reset');
	    });

	    $('.fromDate').datepicker({
			dateFormat: "yy-mm-dd",
			onSelect: function(){
				$(".toDate").datepicker( "option", "minDate", new Date($('.fromDate').val()) );
			}
		});
		
		$(".toDate").datepicker({
			dateFormat: "yy-mm-dd",
			onSelect: function(){
				$(".fromDate").datepicker( "option", "maxDate", new Date($('.toDate').val()) );
			}
		});

		$(".export").click(function(){
			exportReport();
		});

		$(".generate").click(function(){
			generate();
		});

		function highlightOrThrow(e, callback){
			$.clearHighlights();
			if(e != undefined && typeof(e) == 'object'){
				if(e.hasOwnProperty('errors')){
					$.each(e.errors, function(i, k){
						$('.'+i).highlightElement({msg: k});
					});
				}else if(e.hasOwnProperty('ok') && e.hasOwnProperty('msg') && e.ok == 0){
					$.notify.error({msg: e.msg});
				}else if(e.hasOwnProperty('ok') && e.hasOwnProperty('msg')  && e.ok == 1){
					$.notify.success({msg: e.msg});
					if(callback != undefinded && typeof(callback) == 'function'){
						callback();
					}
				}else{
					callback();
				}
			}else{
				console.log('object expected.');
			}
		}

		function exportReport(){
			var data = {
	            fromDate : $(".fromDate").val(),
	            toDate: $(".toDate").val(),
	            types: $(".type").val(),
	            max: $(".max").val(),
	            filters: $(".filter:checked").map(function(){
					return $(this).val();
				}).get()
	        };
	        
			var dom = '<input type="hidden" name="_token" value="'+ _token +'"/>';
			$.each(data, function(k, v){
				if(v == null){
					v = '';
				}
				if(typeof(v) == "object"){
					$.each(v, function(i, j){
						dom += '<input type="hidden" name="'+ k +'['+ i +']" value="'+ j +'"/>';
					});
				}else{
					dom += '<input type="hidden" name="'+ k +'" value="'+ v +'"/>';
				}
			});
			$('<form action="<?php echo e(url("/report13/export")); ?>" method="post">'+ dom +'</form>').appendTo('body').submit();
			
			$.clearHighlights();
		}

		function generate(){
			var data = {
	            fromDate : $(".fromDate").val(),
	            toDate: $(".toDate").val(),
	            types: $(".type").val(),
	            max: $(".max").val(),
	            filters: $(".filter:checked").map(function(){
					return $(this).val();
				}).get()
	        };

			$.post("<?php echo e(url('/report13/generate')); ?>", {_token: _token, data: data}, function(e){
		        
				highlightOrThrow(e, function(){
					report(e);
				});

			}, 'json');
		}

		function report(e){
			var $section1 = $(".section1");
			if(e != undefined && typeof(e) == "object"){
				$(".trips", $section1).html( Object.keys(e.trips).length );
				$(".utilized_trips", $section1).html( Object.keys(e.utilized_trips).length );

				$(".v_average_percent", $section1).html( (e.v_average_percent).toFixed(2) + "%" );
				$(".w_average_percent", $section1).html( (e.w_average_percent).toFixed(2) + "%" );
				$(".volume_count", $section1).html( e.inefficiency.volume_count );
				$(".weight_count", $section1).html( e.inefficiency.weight_count );

				$(".average_volume_per_trip", $section1).html( (e.average_volume_per_trip).toFixed(2) + " CBM" );
				$(".average_weight_per_trip", $section1).html( (e.average_weight_per_trip).toFixed(2) + " Kg" );

				$(".available_total_volume", $section1).html( (e.available_total_volume).toFixed(2) + " CBM" );
				$(".available_total_weight", $section1).html( (e.available_total_weight).toFixed(2) + " Kg" );

				$(".volume_loss_trips", $section1).html(e.volume_loss_trips);
				$(".weight_loss_trips", $section1).html(e.weight_loss_trips);

				$(".average_delivery_cost", $section1).html("Rs " + (e.average_delivery_cost).toFixed(2) );
				$(".v_inefficiency_cost", $section1).html("Rs " + (e.v_inefficiency_cost).toFixed(2) );
				$(".w_inefficiency_cost", $section1).html("Rs " + (e.w_inefficiency_cost).toFixed(2) );
				$(".total_inefficiency_cost", $section1).html("Rs " + (e.total_inefficiency_cost).toFixed(2) );

			}else{
				$(".trips", $section1).html("0");
				$(".utilized_trips", $section1).html("0");

				$(".v_average_percent", $section1).html("0%");
				$(".w_average_percent", $section1).html("0%");
				$(".volume_count", $section1).html("0");
				$(".weight_count", $section1).html("0");

				$(".average_volume_per_trip", $section1).html("0 CBM");
				$(".average_weight_per_trip", $section1).html("0 Kg");

				$(".available_total_volume", $section1).html("0 CBM");
				$(".available_total_weight", $section1).html("0 Kg");

				$(".volume_loss_trips", $section1).html("0");
				$(".weight_loss_trips", $section1).html("0");

				$(".average_delivery_cost", $section1).html("Rs 0");
				$(".v_inefficiency_cost", $section1).html("Rs 0");
				$(".w_inefficiency_cost", $section1).html("Rs 0");
				$(".total_inefficiency_cost", $section1).html("Rs 0");
			}
		}
	});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>