<?php
error_reporting(0);

?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<link rel="stylesheet" href="calendar-15/calendar-15/fonts/icomoon/style.css">

<link rel="stylesheet" href="calendar-15/calendar-15/css/rome.css">
<link rel="stylesheet" href="calendar-15/calendar-15/css/style.css">
<!-- <script src = "ajax/loadoutreport1.js"></script>
<script src = "ajax/loadoutreport2.js"></script>
<script src = "ajax/loadoutreport3.js"></script> -->
<script src="js/quotationreport.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:5px;
        padding-right:5px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      text-align:center;
      padding:8px;
     border:1px solid rgba(24, 7, 173); 
      background-color:#FFFFE0;
      color:black;
    }
    th
    {
      background-color:rgba(24, 7, 173);
      text-align:center;
      padding:8px;
     border-bottom:1px solid #FFFFE0; 
     color:#FFFFE0;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
.reportModal
{
  height:800px;
}
.searchfeilds input
{
height:30px;
}
.daterow
{
  margin-top:10px;
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
  function printDiv() 
{

  var divToPrint=document.getElementById('printdiv');

  var newWin=window.open('','Print-Window');

  newWin.document.open();

  newWin.document.write('<html><head><link rel="stylesheet" href="tablestyle/tablereport.css"></head><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
  newWin.document.close();
}
  $(function () {

// INITIALIZE DATEPICKER PLUGIN
$('.datepicker').datepicker({
    clearBtn: true,
    format: "dd/mm/yyyy"
});


// FOR DEMO PURPOSE
$('#reservationDate').on('change', function () {
    var pickedDate = $('input').val();
    $('#pickedDate').html(pickedDate);
});
});

</script>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    <div ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>Sales Report</h3>
<br>

<!-- search collaspe -->

<!-- date -->
<form action="fullreport.php" method="post">
<div class="row daterow" style="overflow:auto">  
                <div class="col-sm-1"></div>
                
           <div class="col-sm-2">
                <input type="text" class="form-control" id="input_from" name="fromdate" autocomplete="off" placeholder="Start Date"></div>
                <div class="col-sm-2">
                            
                <input type="text" class="form-control" id="input_to" name="todate" autocomplete="off" placeholder="To Date">
              </div>
			  
			  <div class="col-sm-2">
                            
               <input type="text" class="form-control" value="00:00:00" name="timefrom" placeholder="Start Date">
              </div>
			  
			  <div class="col-sm-2">
                            
               <input type="text" class="form-control" value="23:59:59" name="timeto" placeholder="To Date">
              </div>
			       
              <div class="col-sm-1"><button class="btn btn-info" type="submit"><i class="fas fa-calendar-check" style="font-size:23px;"></i></button></div> 
              <div class="col-sm-1"><button type="button" class="btn btn-primary" onClick="printDiv()">Download</button></div>       
            </div>
            </form>
           

 



    <br>
    
    <div class="container" id="printdiv">
  <div class="row">
    <div class="col-md-12">
   <table >
             <thead>
               <?php 
			   $fromdate=$_POST['fromdate'];
			   $todate=$_POST['todate'];
			  $time_from = !empty($_POST['timefrom']) ? $_POST['timefrom'] : '00:00:00';
$time_to   = !empty($_POST['timeto'])   ? $_POST['timeto']   : '23:59:59';
               $proedit=mysqli_query($connect,"select * from partydetail order by id desc");
               while($proshowedi = mysqli_fetch_array($proedit))
               {
                 $party=  $proshowedi['party'];
               }
               //echo $time_from;
               ?>
               <tr align="center"><th colspan="20"><?php echo $party ?></th></tr>
               <tr align="center"><th colspan="20">Sales Report</th></tr>
               <tr>
                 <th>S.no</th>
				 <th>BILL.No</th>
				 <th>DATE</th>
				 <th>TIME</th>
                 <th>VEHICLE.NO</th>
                 <th>CUSTOMER</th>
                 <th>MATERIAL</th>
                 
<th>UNIT</th>


<th>RATE</th>
<th>GST</th>

<th>UNIT RATE</th>
<th>BEFORE TAX</th>
<th>SGST</th>
<th>CGST</th>
<!--<th>ROUND OFF</th>-->

<th>TOTAL AMOUNT</th>
<th>PAYMENT</th>
<!--<th>BILL TYPE</th>-->
<th>SITE</th>

<th>BATA</th>


                
                 
               </tr>
             </thead>
             <tbody>
             <?php
			// $sql_qry=mysqli_query($connect,"Select sec.*,cm.name,pm.tax from second_transaction as sec inner join customerdetails as cm on sec.customer=cm.code inner join productdetail as pm on pm.productcode=sec.product where sec.status!='deleted' and sec.date between '$fromdate' and '$todate' and cm.status=''");
			$sql_qry=mysqli_query($connect,"SELECT 
    sec.*, 
    cm.name, 
    pm.tax 
FROM second_transaction AS sec 
INNER JOIN customerdetails AS cm 
    ON sec.customer = cm.code 
INNER JOIN productdetail AS pm 
    ON pm.productcode = sec.product 
WHERE 
    sec.status != 'deleted' 
    AND cm.status = '' 
   
    AND CONCAT(sec.date, ' ', sec.time) >= '$fromdate $time_from' 
    AND CONCAT(sec.date, ' ', sec.time) <= '$todate $time_to'
ORDER BY 
    CAST(SUBSTRING_INDEX(sec.salescode, '/', -1) AS UNSIGNED) ASC");
		
			
			 
			 $sno=0;
			 $unit=0;
			 $bfrtax=0;
			 $tamount=0;
			 $bata=0;
			 while($row_result=mysqli_fetch_array($sql_qry))
			 {
			 $price=$row_result['price'];
			 $gst=$row_result['tax'];
			 $inclu = $price * 100 /( 100 + $gst);
			 $gstamount=$price-$inclu;
			 $qty=$row_result['netqty'];
			 $sub = $inclu * $qty;
			 $tax = (0.01*$gst*$sub);
			 
			 $date=date_create($row_result['date']);

			 ?>
             <tr>
             <td><?php echo ++$sno;?></td>
			  <td><?php echo $row_result['salescode'];?></td>
			 <td><?php echo date_format($date,"d/m/Y");?></td>
			 <td><?php echo $row_result['time'];?></td>
			 
             <td><?php echo $row_result['vehicleno'];?></td>
             <td><?php echo $row_result['name'];?></td>
             <td><?php echo $row_result['productname'];?></td>
            
             <td><?php echo $row_result['netqty'];?></td>
             <td align="right"><?php echo number_format($inclu,2,'.','');?></td>
             <td align="right"><?php echo number_format($gstamount,2,'.','');?></td>
             <td><?php echo number_format($row_result['price'],2,'.','');?></td>
              <td align="right"><?php echo number_format($sub,2,'.','');?></td>
             <td align="right"><?php echo number_format(($tax/2),2,'.','');?></td>
             <td align="right"><?php echo number_format(($tax/2),2,'.','');?></td>
             
              <td><?php echo number_format($row_result['totalamount'],2,'.','');?></td>
             <td><?php echo $row_result['modeof'];?></td>
             
             <td><?php echo $row_result['delivery'];?></td>
             
             <td>0.00</td>
             </tr>
             <?php
			  $unit+=$row_result['netqty'];
			 $bfrtax+=$sub;
			 $tamount+=$row_result['totalamount'];
			 
			 }
			 ?>
             <tr>
             <td>&nbsp;</td>
            <td>&nbsp;</td>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
			  <td>&nbsp;</td>
             <td>&nbsp;</td>
          
             <td><?php echo number_format($unit,2,'.','');?></td>
             <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
              <td align="right"><?php echo number_format($bfrtax,2,'.','');?></td>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
            
              <td>0.00</td>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
             
             <td><?php echo number_format($bata,2,'.','');?></td>
             </tr>

             </tbody>
           </table>
           </div></div>
           <div>&nbsp;</div>
           
           <div class="row">
    <div class="col-md-6">
           <table>
           <tr>
           <th>Product</th>
           <th>No.OF.LOADS</th>
           <th>TOTAL UNITS</th>
           <th>TOTAL VALUE</th>
           </tr>
           <?php
		   $sql_product=mysqli_query($connect,"select productname,count(product) as pcount,sum(netqty) as qty,sum(totalamount) as tamount from second_transaction where status=''     AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to'group by product");
		   $tload=0;
		   $tqty=0;
		   $tamount=0;
		   while($row_product=mysqli_fetch_array($sql_product))
			 {
		   ?>
           <tr>
           <td><?php echo $row_product['productname'];?></td>
		   <td align="right"><?php echo number_format($row_product['pcount'],2,'.','');?></td>
           <td align="right"><?php echo number_format($row_product['qty'],2,'.','');?></td>
           <td align="right"><?php echo number_format($row_product['tamount'],2,'.','');?></td>
          
           </tr>
           <?php
		   $tload+=$row_product['pcount'];
		   $tqty+=$row_product['qty'];
		   $tamount+=$row_product['tamount'];
		   }
		   ?>
           <tr>
           <td><strong>TOTAL</strong></td>
		   <td align="right"><strong><?php echo number_format($tload,2,'.','');?></strong></td>
           <td align="right"><strong><?php echo number_format($tqty,2,'.','');?></strong></td>
           <td align="right"><strong><?php echo number_format($tamount,2,'.','');?></strong></td>
          
           </tr>
           </table>
           
</div>


<div class="col-md-6">
           <table>
           <tr>
           <th>PARTICULAR</th>
           <th>AMOUNT</th>
           
           </tr>
           <?php
		   $sql_category=mysqli_query($connect,"select modeof,sum(totalamount) as tamount from second_transaction where status='' and    CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' group by modeof");
		   
		   $t2amount=0;
		   while($row_category=mysqli_fetch_array($sql_category))
			 {
		   ?>
           <tr>
          
		   <td ><?php echo $row_category['modeof'];?></td>
           
           <td align="right"><?php echo number_format($row_category['tamount'],2,'.','');?></td>
          
           </tr>
           <?php
		  
		   $t2amount+=$row_category['tamount'];
		   }
		   ?>
           <tr>
           <td><strong>TOTAL</strong></td>
		   <td align="right"><strong><?php echo number_format($t2amount,2,'.','');?></strong></td>
          
          
           </tr>
           </table>
           
</div>

</div></div>

</div>
</div>


<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script src="calendar-15/calendar-15/js/rome.js"></script>

<script src="calendar-15/calendar-15/js/main.js"></script>
 <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">

<script >
var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()

</script>
</body>
</html>