<?php include "layouts/menu.php"; ?>
		<script type="text/javascript">
	  $(function() {
   $("#datepicker").datepicker({ dateFormat: 'dd-mm-yy' });
  });
</script>
<script type="text/javascript">
function zp(n){
return n<10?("0"+n):n;
}
function insertDate(t,format){
var now=new Date();
var DD=zp(now.getDate());
var MM=zp(now.getMonth()+1);
var YYYY=now.getFullYear();
format=format.replace(/DD/,DD);
format=format.replace(/MM/,MM);
format=format.replace(/YYYY/,YYYY);
t.value=format;
}
</script>
    <script>
  $(function() {
   $("#datepicker1").datepicker({ dateFormat: 'dd-mm-yy' });
  });
  </script>
   <script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'my div', 'height=400,width=600');
        mywindow.document.write('<html><head><title>INFOSSEL SOFT SOLUTIONS</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write(' <h1 style="color:green;text-align:center;" >INFOSSEL SOFT SOLUTIONS</h1><body >');
        mywindow.document.write(data);
        mywindow.document.write('<h3 style="text-align:right;">Signed by</h3><h3 style="color:blue;text-align:right;">For INFOSSEL SOFT SOLUTIONS</h3></body></html>');

        mywindow.print();
        mywindow.close();

        return true;
    }

</script>
    <script>
  $(function() {
   $("#datepicker2").datepicker({ dateFormat: 'dd-mm-yy' });
  });
  </script>
      <script>
  $(function() {
   $("#datepicker8").datepicker({ dateFormat: 'dd-mm-yy' });
  });
  </script>
    <script>
  $(function() {
   $("#datepicker9").datepicker({ dateFormat: 'dd-mm-yy' });
  });
  </script>
   <script type="text/javascript">
function CollapseForm()
{
// Two places to customize:

// Specify the id of the form.
var IDofForm = "form1";

// Specify the id of the div containing the form.
var IDofDivWithForm = "demo";

// This line submits the form. (If Ajax processed, call Ajax function, instead.)
document.getElementById(IDofForm).submit();

// This line collapses the form.
document.getElementById(IDofDivWithForm).style.display = "none";
}
</script>
     
<?php include "layouts/menu1.php"; ?>
            <!-- Right side column. Contains the navbar and content of the page -->
           <div class="right_col" role="main">
                <!-- Content Header (Page header) -->
              <section class="content-header">
                    <div class="col-lg-6">  	
   
 
  </br></br>
</div>

  <div class="pull-right box-tools">

   <form id="form1" name="form1" class="form-horizontal" method="post" action="" enctype="multipart/form-data">
   
  
                                        <button class="btn btn-danger btn-sm refresh-btn" data-toggle="tooltip" title="Reload"  ><i class="fa fa-refresh"></i></button>
                                        <button class="btn btn-danger btn-sm" data-widget='collapse' data-toggle="tooltip" title="Collapse" ><i class="fa fa-minus"></i></button>
                                        <button class="btn btn-danger btn-sm" data-widget='remove' data-toggle="tooltip" title="Remove" ><i class="fa fa-times"></i></button>
                                    </div>

                </section>
				
                 
                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12"> 
                            <div class="box">
                               <!-- /.box-header -->
                                <div class="box-body table-responsive">
                                  
									 <div class="alert alert-info">MONTHLY LOG REPORT</div>
    <form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
 <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Car</label>
    <div class="col-sm-4">
      <select type="text" class="form-control" id="inputPassword3" name="car" value="" placeholder="">
	  <option>Select</option>
	  <?php $qry=mysqli_query($conn, "select * from veh");
	  while($row2=mysqli_fetch_array($qry))
						{ ?>
						<option><?php echo $row2['debit'];?></option> <?php } ?></select> 
    </div>
  </div>	   
	<div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">From</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="datepicker" name="fdate" value="<?php echo date('01-m-Y'); ?>" placeholder="DD/MM/YYYY" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">To</label>
    <div class="col-sm-4">
    <input type="text" class="form-control" id="datepicker" name="tdate" value="<?php echo date('t-m-Y'); ?>" placeholder="DD/MM/YYYY" onfocus="insertDate(this,'DD-MM-YYYY')">
    </div>
  </div>
			<div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default" name="s129">Total</button>
    </div>
  </div></div>
    <?php
								if(isset($_POST['s129']))
								{
									extract($_POST);
									
									 ?>
					</br>				 
<input type="button" value="Print" onclick="PrintElem('#mydiv')"  style="margin:20px;">
					<div id="mydiv">

<h4><b>Car Report <?php echo $fdate; ?> To <?php echo $tdate; ?></b></h4>
									<table   border="1"  ><font size="2">
						<tr>
						<th>CONTENT</th>
						<th>VALUE </th>
						<th> </th>
						<th>NEXTxxxSERVICE </th>
						<th>DATE </th>
						
						
						
					</tr>
									
									<?php  $exp = 0; $class5 = 0;
									$ffdate = $fdate;
									$e=0;  $s=0;  $r=0;  $t=0; $d=0; $t1 = 0; $deb = 0;
									$open = 0;
									$close = 0;
									
										$vehh = $car;
								while (strtotime($fdate) <= strtotime($tdate)) 
								{
									   $paydate = $fdate;
						$qry=mysqli_query($conn, "select * from vehc where mfin='$mfin' &&  date='$paydate' && veh='$vehh'");
									while($row=mysqli_fetch_array($qry))
						{ $t1++;
						 if($t1==1){
						 $open = $row['open'];
						 }
						 $close = $row['close'];
						 
									}
									$qry7=mysqli_query($conn, "select * from att where mfin='$mfin' &&  date='$paydate' && car='$vehh'");
									while($row7=mysqli_fetch_array($qry7))
						{ 
						 $class5 = $class5 + $row7['class'];
						 
									}
									
									$fdate = date ("d-m-Y", strtotime("+1 day", strtotime($fdate))); 
									}
$qry9=mysqli_query($conn, "select * from veh where mfin='$mfin' &&  debit='$vehh'");
									while($row9=mysqli_fetch_array($qry9))
						{  $oil = $row9['oil'];
					$wheel = $row9['wheel'];
					$water = $row9['water'];
					$bat = $row9['bat'];
						}
						?></p>
				
					<tr>
					 <?php
					$total = 0;
					$total = $close - $open; ?>
					<td>VEHICLE</td>
						<td><?php echo $vehh;?></td>
						<td></td>
						<td>OIL SERVICE</td>
						
						<td><?php echo $oil;?></td>
											</tr>
											
					<tr>
					
					<td>TOTAL KM</td>
						<td><?php echo $total;?></td>
						<td></td>
						<td>WHEEL SERVICE</td>
						
						<td><?php echo $wheel;?></td>
											</tr>
											<tr>
					
					<td>CLASSES </td>
						<td><?php echo $class5;?></td>
						<td></td>
						<td>WATER SERVICE</td>
						
						<td><?php echo $water;?></td>
											</tr>
											<tr>
					 <?php
					$avg = $total / $class5; ?>
					<td>Class Mileage</td>
						<td><?php echo round($avg,2);?></td>
						<td></td>
					<td>BATTERY SERVICE</td>
						
						<td><?php echo $bat;?></td>
											</tr>
				</table>
						<h3>Current Km - <?php echo $close; ?> </h3>
					 <?php
					 
									 ?>
									 <table border="1" >
					 
                                        <thead>
                                            <tr>
												<th>Date</th>
												<th>Debit</th>
												
												<th>Cat</th>
												<th>Details</th>
												
                                            </tr>
                                        </thead>
										<?php
$fdate = $ffdate;
										while (strtotime($fdate) <= strtotime($tdate)) 
								{ 
							 $paydate = $fdate;
							$qry22=mysqli_query($conn, "select * from vdebit where mfin='$mfin' &&  date='$paydate' && car='$vehh'");
					while($row2=mysqli_fetch_array($qry22))
						{
					?>
                                        <tbody>
                                           <tr>
                                               <td><?php echo $row2['date'];?></td>
						<td><?php echo $row2['debit']; ?></td><td><?php echo $row2['cat']; ?></td>
						<td><?php echo $row2['details']; ?></td>
						
                                            </tr>
                                          </tbody>
                                        <?php

								} 
								$fdate = date ("d-m-Y", strtotime("+1 day", strtotime($fdate))); 
								}
				
					?>
					                    
                                    </table>		
                <?php
									}
					
				
					?>
					</font>	</form> </DIV>
                                  	
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>

                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->


        <!-- jQuery 2.0.2 -->
       <?php include "layouts/footer.php"; ?>

    </body>
</html>