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

//require_once 'pdf.php';
 $html = '';
 
 $fdate = $_GET['fdate'];
 $tdate = $_GET['tdate'];

 


  $sql = "select  m.s_id, m.dated, m.cust_name, a.acc_name, sum(d.qty*d.rate) amount from quotation_detail d, quotation m ,accounts a where m.s_id=d.s_id and m.cust_id = a.acc_no and m.dated between '".$fdate."' and '".$tdate."' group by m.s_id order by m.dated asc";
  
 $statement = $connect->query($sql);
  
 
 $result = $statement->fetchAll();


 
  ?>
<!DOCTYPE html>
<html>
<head>
  <title>Quotation</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>
 
<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="3%">Sr</td>
  <td width="3%">ID</td>
  <td width="10%" >Date</td>
<td width="29%" >To | Customer</td>
<td width="15%" >M/s:</td>
<td width="10%" class="rightside">Amount</td>
<td width="10%" class="rightside">Status</td>
<td width="20%" class="rightside">Remarks</td>

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

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

</body>
</html>