<?php
 
 include('db_con.php');

//require_once 'pdf.php';
 $html = '';
 
 $fdate = $_GET['fdate'];
 $tdate = $_GET['tdate'];
 $inv_type = $_GET['inv_type'];
 
 $gst = 'OFF';
 if($inv_type == 'GST'){$gst ='ON'; $inv_type ='';}

  $sql = "select  concat(t.type_name , ' ' , i.item_name) description, sum(d.qty) qty from sale_detail d, sale m, items i, item_type t  where m.s_id=d.s_id and t.type_id = i.type_id and i.item_id = d.item_no and m.inv_type LIKE '%".$inv_type."' and m.gst LIKE '%".$gst."%' and m.dated between '".$fdate."' and '".$tdate."' group by i.item_id order by i.item_name asc ";
  
 $statement = $connect->query($sql);
  
 
 $result = $statement->fetchAll();


 
  ?>
<!DOCTYPE html>
<html>
<head>
  <title>Sales Detail</title>
  <style>
    * {
      font-family: calibri;
      padding: 3px;
      line-height: 12px;
     
    }
    @media print {
  @page { margin: 0;size:landscape; }
  body { margin: 1cm; }
}
  .rightside {text-align: right;}
  table td{   
    border-bottom: 1px solid gray;
    font-size: 12px;
  }
  .head_row {
    font-weight: bold;
  }
  thead td {
    font-weight: bold;
     border-bottom: 2px solid gray;
      border-top: 2px solid gray;
       background-color :  #f3f3f3;
  }
.total {
  font-weight: bold;
}
  </style>

</head>
<body>
  <h3><?php if($gst =='ON'){$inv_type = 'GST';} echo $inv_type;?> Sales Detail</h3>
<table width="100%">

<tr>
<td><b>From : </b><?php echo $fdate;?></td><td><b>To :</b> <?php echo $tdate;?></td>
</tr>

</table>
  <table width="100%">
  <thead>
  <tr class="head_row">
  
  <td width="5%">Sr</td>
<td width="35%" >Description</td>
<td width="10%" class="rightside">Qty</td>

  </tr>
  </thead>
  <tbody>
<?php
$tot_amount = 0;
$tot_discount = 0;
$tot_freight = 0;
$count = 0;
$tot_qty = 0;
$tot_inv_amount = 0;
foreach($result as $row)
 {
 
  $count++;
  
  $qty = $row["qty"];
  $tot_qty = $tot_qty + $qty;
 
echo ' 
  <tr>
  <td>'.$count.'</td> 
  
  <td>'.$row["description"].'</td>
  <td class="rightside">'.number_format($qty,0).'</td>
  
  </tr>
  ';
   
   
   
  }
  echo 
  '
    <tr class="total">
  <td colspan="2" class="rightside">Total:</td>

  <td class="rightside">'.number_format($tot_qty,0).'</td>
  
  </tr>';
  
  ?>
  </tbody>
</table>

</body>
</html>