<!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>GST Purchase Report</title>
 <?php require 'header.php' ?>
</head>

<body onload="window.print()">
<div class="container col-sm-12">
<div id="a">
<h3 align="center">GST Purchase Report </h3>
<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
       
            <tr>
                <th>Invoice No</th>
             
                <th>supplier</th>
               
                
                <th>Product</th>
				<th>Qty</th>
				<th>Rate</th>
				<th>GST%</th>
                <th>Net Amount</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
		require_once("config/configDB.php");
				$tripfromDate=$_GET['fromdate'];
				$triptoDate=$_GET['todate'];
			
				$supplier=$_GET['supplier'];
			
				$product=$_GET['product'];
				
				$sql = "SELECT sh.id,sh.invoice_no, sh.purchase_date, sh.supplier_id,sh.btime btime,  sh.po_num, sh.itemcount, sh.tamount, sh.create_date,sh.id,cm.sname,sd.productID,sd.purchase_prate prate,sd.purchase_gst gst,sd.purchase_eqty qt,sd.purchasenetamt,pm.productname pname FROM purchaseheader as sh LEFT JOIN supplier_master as cm on cm.id = sh.supplier_id inner join purchasedetails as sd on sh.id=sd.purchaseheader_id inner join product_master as pm on pm.id=sd.productID where sh.flag='1' and sh.status='' ";
				
				if($tripfromDate !=''  && $triptoDate !='' && $supplier ==''  && $product=='' ) {
	 	$sql.=" and sh.purchase_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.purchase_date ASC ";

	 }
	 
	 
	 else if($tripfromDate !=''  && $triptoDate !='' && $supplier !=''   && $product=='') {
	  	$sql.=" and sh.supplier_id='".$supplier."'  and sh.purchase_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.purchase_date ASC ";

	 }
	 
	 else if($tripfromDate ==''  && $triptoDate =='' && $supplier !=''   && $product=='')  {
	 	$sql.="  and sh.supplier_id='".$supplier."'   ORDER BY sh.purchase_date ASC ";

	 }
	 
	
	 
	 else if($tripfromDate !=''  && $triptoDate !='' && $supplier ==''   && $product!='' ) {
	 	$sql.=" and sh.purchase_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' and sd.productID='".$product."' ORDER BY sh.purchase_date ASC ";

	 }
	 
	 
	  else if($tripfromDate !=''  && $triptoDate !='' && $supplier !=''   && $product!='' ) {
	 	$sql.=" and sh.purchase_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' and sd.productID='".$product."' and sh.supplier_id='".$supplier."' ORDER BY sh.purchase_date ASC ";

	 }
	 
	
	 
	 else if($tripfromDate ==''  && $triptoDate =='' && $supplier !=''  && $product!='' ) {
	 	$sql.="  and sd.productID='".$product."' and sh.supplier_id='".$supplier."'  ORDER BY sh.purchase_date ASC ";

	 }
	 
	 
	
	 else if($tripfromDate ==''  && $triptoDate =='' && $supplier ==''   && $product!='' ) {
	 	$sql.="  and sd.productID='".$product."'  ORDER BY sh.purchase_date ASC ";

	 }
	 
				?>
        
        <tbody>
            <?php
			$query=mysqli_query($conn, $sql) or die("brandgriddata.php: get brand Data step 1".$sql);
			$total_price=0;
			$total_qty=0;
			while($row=mysqli_fetch_array($query))
{
	$deliver_date=$row["purchase_date"];
$date=date_create($deliver_date);
$purchase_date2=date_format($date,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo $row["invoice_no"];?></td>
           
            <td><?php echo $row["sname"];?></td>
           
           
            <td><?php echo $row["pname"];?></td>
			<td align="right"><?php echo number_format((float)$row["qt"], 2, '.', '');?></td>
			<td><?php echo $row["prate"];?></td>
			<td><?php echo $row["gst"];?></td>
            <td align="right"><?php echo number_format(round($row["purchasenetamt"]), 2, '.', '');?></td>
			</tr>
            <?php
			
			$total_price  += $row["purchasenetamt"];
			$total_qty  += $row["qt"];
}


?>
       <tr>
           
           <td colspan="3" align="right"><strong>Total Qty</strong></td>
            <td align="right"><strong><?php echo number_format((float)$total_qty, 2, '.', '');?></strong></td>
           
			<td  align="right" colspan="2"><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price), 2, '.', '');?></strong></td>
			</tr>              
                    
           
        </tbody>
       
    </table>
    </div>
</div>
 <?php require 'footer.php' ?>

    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>
</body>
</html>
