<?php
error_reporting(0);
include "config.php";
$customer=$_GET['customer'];
		
		  $fromdate=$_GET['fromdate'];
		  $todate=$_GET['todate'];
		  
		  $fdate=date_create($fromdate);
		  $tdate=date_create($todate);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>

<body onload="window.print()">

<h3 align="center"><u>Customer&nbsp;Report</u></h3>

<table  class="table table-striped table-bordered " cellspacing="0" width="100%">
<tr>
<td><strong>Customer Name</strong></td>
<td><strong><?php echo $customer;?></strong></td>
<td><strong>From Date</strong></td>
<td><strong><?php echo  date_format($fdate,"d-m-Y");?></strong></td>
<td><strong>To Date</strong></td>
<td><strong><?php echo  date_format($tdate,"d-m-Y");?></strong></td>
</tr>

</table>

 <?php
		  $query=mysqli_query($connect,"select * from second_transaction where status='' and customer='$customer' and date between '$fromdate' and '$todate' group by productname");
		  while($row_product=mysqli_fetch_array($query))
		  {
		  $product=$row_product['product'];
  ?>
  
  
 
  <u><h3 align="center"><?php echo $row_product['productname'];?></h3></u>
  <div>&nbsp;</div>
  <table  class="table table-striped table-bordered " cellspacing="0" width="100%">
             <thead>
                 <th>Sno</th>
                 <th>Ticket</th>
                 <th>Invoice</th>
                 <th>TripNo</th>
                 <th>Customer</th>
                 <th>Product</th>
                 
                 <th>VehicleNo</th>
                <!-- <th>Chakka</th>-->
                 <th>Delivery</th>
                 
                 
                 <th>Date</th>
                 <th>Time</th>
                 <!--<th>EmptyWeight</th>
                 <th>LoadWeight</th>
                 <th>NetWeight</th>-->
                 <th>Capacity</th>
                 <th>NetQty</th>
                
                 <th>Price</th>
                 
                 <th>Totalamount</th>
               
                
                 <th>Mode</th>
                 <th>Remarks</th>
                 <th>User</th>
              
             </thead>
             <?php
			 
			 $sql_query="select sh.salescode,sh.ticket,sh.chakka,sh.vehicleno,sh.customer,sh.delivery,sh.productname,sh.price,sh.priceori,sh.date,sh.time,sh.emptyweight,sh.loadweight,sh.netweight,sh.netqty,sh.netqtyori,sh.cft,sh.totalamount,sh.modeof,sh.remark,sh.editby,cm.name,tik.tripno from second_transaction as sh inner join customerdetails as cm on cm.code=sh.customer inner join ticket as tik on tik.ticket=sh.ticket where tik.status='' and cm.status='' and sh.status=''  and sh.customer='$customer' and sh.date between '$fromdate' and '$todate' and sh.product='$product' order by sh.date,sh.id";
			 			$query_result=mysqli_query($connect, $sql_query) or die("brandgriddata.php: get brand Data step 1".$sql_query);
			$sno=0;
			$ntqty=0;
			$ntamount=0;
			while($row_query=mysqli_fetch_array($query_result))
{
			 ?>
             <tbody >
<tr>
<td><?php echo ++$sno;?></td>
<td><?php echo $row_query['ticket'];?></td>

<td><?php echo $row_query['salescode'];?></td>
<td><?php echo $row_query['tripno'];?></td>
<td><?php echo $row_query['name'];?></td>
<td><?php echo $row_query['productname'];?></td>
<td><?php echo $row_query['vehicleno'];?></td>
<!--<td><?php echo $row_query['chakka'];?></td>-->
<td><?php echo $row_query['delivery'];?></td>
<td><?php echo $row_query['date'];?></td>
<td><?php echo $row_query['time'];?></td>
<!--<td><?php echo $row_query['emptyweight'];?></td>
<td><?php echo $row_query['loadweight'];?></td>
<td><?php echo $row_query['netweight'];?></td>-->
<td><?php echo $row_query['cft'];?></td>
<td align="right"><?php echo number_format($row_query['netqty'],2,'.','');?></td>

<td><?php echo number_format($row_query['price'],2,'.','');?></td>

<td align="right"><?php echo number_format($row_query['totalamount'],2,'.','');?></td>
<td><?php echo $row_query['modeof'];?></td>
<td><?php echo $row_query['remark'];?></td>
<td><?php echo $row_query['editby'];?></td>

</tr>
             </tbody>
             <?php
			 $ntqty+=$row_query['netqty'];
			$ntamount+=$row_query['totalamount'];
			 }
			 ?>
             <tr>
             <td colspan="11" align="right"><strong>Total&nbsp;Qty</strong></td>
             <td align="right"><strong><?php echo number_format($ntqty,2,'.','');?></strong></td>
             <td align="right"><strong>Total&nbsp;Amount</strong></td>
             <td align="right"><strong><?php echo number_format($ntamount,2,'.','');?></strong></td>
             </tr>
           </table>
  
  <?php
  }
  ?>
  
  <div>&nbsp;</div>
  
  <table  class="table table-striped table-bordered " cellspacing="0" width="100%">
              <thead>
                 <th align="center">Sno</th>
                 <th align="center">Product</th>
                 <th align="center">UOM</th>
                 <th align="center">Qty</th>
                  <th align="center">Amount</th>
                 </thead>
           <?php
            $query_sum=mysqli_query($connect,"select product,productname,sum(netqty) as netqty,sum(totalamount) as total from second_transaction where status='' and customer='$customer' and date between '$fromdate' and '$todate' group by productname");
			$sno2=0;
			$sumamt=0;
		  while($row_sum=mysqli_fetch_array($query_sum))
		  {
		  //echo "select * from productdetail where productcode='".$row_sum['product']."' and status<>'Deleted'";
		  $qry=mysqli_query($connect,"select * from productdetail where productcode='".$row_sum['product']."' and status<>'Deleted'");
		  $rw=mysqli_fetch_array($qry,MYSQLI_ASSOC);
           ?>
           <tbody>
           <tr>
           <td align="center"><?php echo ++$sno2;?></td>
           <td align="center"><?php echo $row_sum['productname'];?></td>
          <td align="center"><?php echo $rw['unit'];?></td>
           <td align="right"><?php echo number_format($row_sum['netqty'],2,'.','');?></td>
           <td align="right"><?php echo number_format($row_sum['total'],2,'.','');?></td>
           </tr>
           </tbody>
           <?php
		   $sumamt+=$row_sum['total'];
		   }
		   ?>
           <tr>
           <td align="right" colspan="4"><b>Net&nbsp;Amount</b></td>
           <td align="right"><strong><?php echo number_format($sumamt,2,'.','');?></strong></td>
           </tr>
           </table>

</body>
</html>
