<?php
if(basename($_SERVER['PHP_SELF']) == 'milerepo.php') 
  $nv=" class='current'";
$custo=$conde='';
include'connection.php';
$dato=$datos=$Date;
$p=0;

// Open a single record
if(isset($_POST['slip']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$pago=$_POST['pago'];
			$invo=$_POST['invo'];
			$dte=$_POST['dte'];
			$p=$_POST['p'];

include'slipo.php';
		}

include'header.php';


if(isset($_POST['back']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$p=$_POST['p'];
		}

if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
				$p=1;
		}

            if($p==1)
        $conde="AND `Pdate` BETWEEN '$dato' AND '$datos'";
	

        if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
?>

<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
        Vehicles
          </h2>
                 </div>
     
         <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">

	   <li class="list-group-item">
              <a href="locate.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Allocate Vehicles
                </p>
              </a></li> 
                  
			  <li class="list-group-item">
              <a href="ment.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Repair & Services
                </p>
              </a></li>

    <li class="list-group-item">
	  <a href="mainsto.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;List of Vehicles
                </p>
              </a></li>
                       
            </ul><br><br>

			<li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="createa.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Customers
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="dispatch.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Vehicle Trip
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="addinco.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Add Vehicle Income
                </p>
              </a></li>	
        
                <?php
              if($_SESSION['Cpo']){
                  ?>
			  <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
              <a href="purcha.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Purchase Orders
                </p>
              </a></li>
              <?php
              }
              if($_SESSION['Cpi']){
                  ?>
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="profo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Proforma
                </p>
              </a></li>	
              <?php
              }
              ?>
              
            <li class="list-group-item active" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="payslip.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Payment Vouchers
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="conterepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Container Dispatch
                </p>
              </a></li>	
              
            <li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="ddlist.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Mileage Deduction
                </p>
              </a></li>		
  </div>
       
        <div class="col-lg-10"><div class="row">
            <div class="col-lg-6"><div class="col-lg-1"> </div>
           
         <form action="milpay.php" method="post"> 
           <div class="col-lg-3 hidden-print"> <button class="btn btn-warning btn-block" type="submit" style='font-size:12px;'> Mileage Payment </button></div></form>
           
            <form action="miler.php" method="post"><div class="col-lg-3">
       <button class="btn  btn-success btn-block" type="submit" style='font-size:12px;'> Create New Voucher </button></div></form>
           
         <form action="tmile.php" method="post"> 
           <div class="col-lg-3 hidden-print"> <button class="btn btn-info btn-block" type="submit" style='font-size:12px;'> Trip Report </button> </div></form>
           <div class="col-lg-2"> </div>
           </div>

        <form action="" method="post" class="form-horizontal ">                 
     <div class="col-lg-6 hidden-print" style="padding-right:50px;"> 
        <div class="col-lg-1"> </div><div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" id="from" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" id="to" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                     
                       
                       <div class="col-lg-3"><?php echo"<input type='hidden' name='pg' value='$pg'>"; ?>
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div></form>               
            </div>
               <?php
               if($p)
		$do=mysqli_query($conn, "SELECT SUM(`Amount`/`Rate`) AS `Mile`, COUNT(distinct(`Plate`)) AS `Veh`, `Trip`, `Pdate`, `Done`, `Printed`, `Type`, `Rate`, `Invoice` FROM `repair` WHERE (`Trip`!='0' AND `Status`='0' AND `Garage`='ROAD TOLL' AND `Printed`='1' $conde) OR (`Trip`!='0' AND `Status`='0' AND `Garage`='MILEAGE' AND `Printed`='1' $conde) OR (`Trip`!='0' AND `Status`='0' AND `Garage`='OTHER EXPENSE' AND `Printed`='1' $conde) OR (`Trip`!='0' AND `Status`='0' AND `Garage`='GPS SERVICES' AND `Printed`='1' $conde) GROUP BY `Invoice` ORDER BY `Date` ASC");
		        else
		$do=mysqli_query($conn, "SELECT SUM(`Amount`/`Rate`) AS `Mile`, COUNT(distinct(`Plate`)) AS `Veh`, `Trip`, `Pdate`, `Done`, `Printed`, `Type`, `Rate`, `Invoice` FROM `repair` WHERE (`Trip`!='0' AND `Status`='0' AND `Garage`='ROAD TOLL' AND `Printed`='1') OR (`Trip`!='0' AND `Status`='0' AND `Garage`='MILEAGE' AND `Printed`='1') OR (`Trip`!='0' AND `Status`='0' AND `Garage`='OTHER EXPENSE' AND `Printed`='1') OR (`Trip`!='0' AND `Status`='0' AND `Garage`='GPS SERVICES' AND `Printed`='1') GROUP BY `Invoice` ORDER BY `Number` DESC LIMIT 15");
				if($fo=mysqli_num_rows($do)){
				?>
                 
            <div class="divFooter"><center><u><b> MILEAGE RECORD <?php echo $mpri ?></b></u></center></div>
             <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <span class="pull-right hidden-print">&nbsp;&nbsp;
		<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'>
			 <i class="lnr lnr-printer"></i></a></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
                <form action='' method='post'>

				<table class="table table-striped table-hover">     
                        <thead><tr role="row">
    <th width="1%" style='padding:1px; text-align:center; width:5px;'> Voucher&nbsp;No </th>
					 <th width='8%'><div align='center'> Date </th>
		<th style='padding:1px;'><div align='center'> User </th>
			<th style='padding:1px;'><div align='center'> Destination </th>
    <th style='padding:1px;'><div align='center'> Vehicles </th>
	<th width="14%" style='padding:1px;'><div align='center'> Amount </th>
	<th width="10%" style='padding:1px;'><div align='center'> Rate </th>
	<th width="14%" style='padding:1px;'><div align='center'> Value </th>
			<th width='1%' style='padding:1px;'><div align='center'>#</th></tr>
                    </thead>
                                        <tbody>
					<?php
			$i=1;		            	$tto=$tv=$ta=0;
	while($ro=mysqli_fetch_assoc($do)){
				$trip=$ro['Trip'];
				$dte=$ro['Pdate'];
				$pla=$ro['Done'];
				$pr=$ro['Printed'];
				$mile=$ro['Mile'];
				$rate=$ro['Rate'];
				$typ=$ro['Type'];
				$veh=$ro['Veh'];
				$invo=$ro['Invoice']; 
			    
			 	// ****************** Trip customer ********************** 
	   	$doil=mysqli_query($conn, "SELECT `Destination`, `Final`, `Location` FROM `trips` WHERE `Number`='$trip' ORDER BY `Number` ASC");
			$roil=mysqli_fetch_assoc($doil);
				$des=$roil['Destination'];
				$fni=$roil['Final'];
				$loc=$roil['Location'];
			    $deso="$des/$loc - $fni";
			    $to=$mile*$rate;
				
						$milo=number_format($mile, 2);
						$rateo=number_format($rate, 2);
						$too=number_format($to, 2);
						
			    if($typ==1)
					$stl="padding:1px; font-size:13px; color:blue;";
			    else
					$stl="padding:1px; font-size:13px;";
				
		if($pa OR $typ==1)
	$mode="disabled readonly";
		else
	$mode="data-placement='top' data-toggle='modal' data-target='#modalcut$i'";


	print("<tr><form action='' method='post'>
	<td class='text-center' style='width:5px; $stl $clr'> $invo </td>
	<td style='$stl $clr'><div align='center'> $dte </td>
	<td style='$stl $clr'> $pla </td><td style='$stl $clr'> $deso
	  <input type='hidden' name='p' value='$p'>
	  <input type='hidden' name='dte' value='$dte'>
	  <input type='hidden' name='invo' value='$invo'>
	  <input type='hidden' name='dato' value='$dato'>
	  <input type='hidden' name='datos' value='$datos'>
	  <input type='hidden' name='pago' value='milerepo.php'>
	  <input type='hidden' name='nuo$i' value='$nuo'> </td>
	<td style='$stl $clr'><div align='center'> $veh </td>
	<td style='$stl $clr'><div align='right'> $milo </td>
	<td style='$stl $clr'><div align='right'> $rateo </td>
	<td style='$stl $clr'><div align='right'> $too &nbsp; </td>
	<td style='$stl $clr'><div align='center'><button type='submit' class='btn btn-xs btn-success hidden-print' style='height:18px; width:25px; padding:0px; margin:0px; margin-right:2px;' name='slip'> &nbsp;<i class='lnr lnr-download'></i>&nbsp; </button>
	</td></form></tr>");
	            $i++;                     
	   $tto+=$mile;                  $tv+=$veh;                $ta+=$to;
			}
			$tto=number_format($tto, 2);
			$tv=number_format($tv);
			$ta=number_format($ta, 2);
		?>
						
        </tbody><tr><th colspan='4'><div align='center' Total Amount </th>
            <th><div align='center'><?php echo $tv ?></div></th>
            <th><div align='right'><?php echo $tto ?></div></th>
                <th><div align='right'> -- </div></th>
                <th><div align='right'><?php echo $ta ?></div></th>
                    <th><div align='center'>--</div></th></tr><thead>
                        
                        
                        
                        
                    </thead>
                  </table><br>

				</form>
				  

								</div></div>
								<span class="pull-right hidden-print">
			 <a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'>
			 <i class="lnr lnr-printer"></i></a></span><br><br><br>  

			<?php
				}
				else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b> 0 </b></span>
            <div class='widget-container fluid-height clearfix'>
            <div class='widget-content padded clearfix'>
			<br><br><br><br><br><br>
	<div style='text-align:center; font-size:24px; color:#ff9999'>Report not available on selected date </div><br><br><br><br><br><br>";
					}
			
					?>
                                      
                
              </div>
            </div></div>
                  </div>
   <?php
   include'footer.php';
   ?>