<?php

 date_default_timezone_set('Asia/Karachi');
 include('db_con.php');
 
 
 $s_id = $_GET['id'];
 
 $tot_qty = 0;
 $tot_amt = 0;
 $tot_lqty = 0;
 $discount =0;
 $freight = 0;
 $title_id = 1;
$statement = $connect->prepare("select * from titles where  id= :title_id
    
  ");
 $statement->execute(
  array(  
   ':title_id'       =>  $title_id
  )
 );
 $result = $statement->fetchAll();
 
  foreach($result as $row)
 {
  $heading1 = $row['heading1'];
  $heading2 = $row['heading2'];
  $heading3 = $row['heading3'];
  $stn = $row['heading4'];
  $ntn = $row['heading5'];
 }
 

  $statement = $connect->prepare("select m.s_id,m.inv_no,m.s_id chal_no,m.po_no,0 bilty_no,m.po_no,m.due_day,DATE_FORMAT(m.due_dated,'%d-%m-%Y') as due_dated,DATE_FORMAT(m.dated,'%d-%m-%Y') as dated,m.gst_pr,'' notes,m.fst_pr, m.cur_stamp,m.hs_code, m.description,m.inv_type,m.discount,m.discount_dsc, m.freight_dsc,m.cust_name,m.contact, a.ntn, a.stn, m.freight,m.gst_pr,m.pre_balance,a.acc_name,a.address, a.phone,o.user_name from sale m,user_detail o,
    accounts a where o.user_id=m.user_id and a.acc_no=m.cust_id and
    m.s_id= :s_id LIMIT 1
    
  ");
 $statement->execute(
  array(  
   ':s_id'       =>  $s_id
  )
 );
 $result = $statement->fetchAll();

 
  ?>
  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>GST Print</title>
     <style>
        * {
          padding: 0;
          margin: 0;
          font-family: arial;
        
        }

       
        .bordered {
          border-bottom: 1px solid black;
          padding: 5px;
        }
    #rpt_header {
     width:100%;
    margin:0 auto;
    display:inline-block;
    text-align:left;
    }


.doc_type {
  float: right;
}
.address {
  width: 100%;
  text-align: left;
  line-height: 15px;
  
  font-family: arial;
  font-size: 12px;
}

    .rightside {
      text-align: right;
    }

    #data_table  {

    }
    thead td {
      font-weight: bold;
      font-size: 15px;
      border-bottom: 2px solid black;
      border-top: 2px solid black;
      background-color:#aed6f1;
      padding: 5px;
      font-family: arial;    
    }

    tbody td {
      font-size: 14px;
      font-weight: bold;

    }

    footer {
  
}


.topline {
  border-top: 1px solid black;
  
}
h3 {
  text-align: center;
}
.hline {
  border-bottom: 1px solid black;
}
.description {
  color:red;
}
.notes {
  border-top:1px solid black;

}
.notes p {

}

  </style>

  </head>
  <body onload="window.print();">
    <div class="content">
      <div id="rpt_header">
          
       <table width="100%">
       <tr>
        <td width="12%">
          <img style="float: left;width:80px;height:80px" src="images/1.png">
     
    </td>
    <td width="78%">
      <h2><?php echo $heading1;?></h2>
      <p class="address"><?php echo $heading2;?></p>  
      <p class="address"><?php echo $heading3;?></p>
      <p class="address"><?php echo $ntn;?></p> 
      <p class="address"><?php echo $stn;?></p>    
    </td>
    <td width="10%">  <img style="float: right;width:80px;height:80px" src="images/2.png"></td>
    </tr>
  </table>

      </div>
    <div class="hline"></div>
   
      <br />
      <h3>SALES TAX INVOICE</h3>
    <br/>
 <table width="100%" class="page_header">
  <?php 
  foreach($result as $row)
 {
  $gst_pr = $row["gst_pr"];
  $notes = $row["notes"];
  $stn = $row["stn"];
  $ntn = $row["ntn"];
  $fst_pr = $row["fst_pr"];
 echo '
 
  
  <tr><td width="15%"><b>M/s :</b></td>
  <td width = "35%">'.$row["acc_name"].'</td>
  <td width="15%" class="rightside"><b>Date :</b></td><td width = "35%" class="rightside">'.$row["dated"].'</td>
  </tr>
  <tr><td width="15%"><b>Address: </b></td>
  <td width = "35%">'.$row["address"].'</td>
  <td width="15%" class="rightside"><b>Invoice # :</b></td><td width = "35%" class="rightside">'.$row["inv_no"].'</td>
  </tr>
  <tr><td width="15%"><b>STN :</b></td>
  <td width = "35%">'.$row["stn"].'</td>
  <td width="15%" class="rightside"><b>PO # :</b></td><td width = "35%" class="rightside">'.$row["po_no"].'</td>
  </tr>
  <tr><td width="15%"><b>NTN :</b></td>
  <td width = "35%">'.$row["ntn"].'</td>
  <td width="15%" class="rightside"><b>DC # :</b></td><td width = "35%" class="rightside">'.$row["s_id"].'</td>
  </tr>
   <tr><td width="15%"><b>Desc :</b></td>
  <td width = "35%">'.$row["description"].'</td>
  <td width="15%" class="rightside"><b>HS Code :</b></td><td width = "35%" class="rightside">'.$row["hs_code"].'</td>
  </tr>
  ';
}
  ?> 
  </table>
  <br />
  <table width="100%" id="data_table">
  <thead>

  <tr>
  
  
  <td width="5%" class="font-bold">#</td>
  <td width="69%"class="font-bold">Description</td>
  <td width="8%" class="font-bold rightside">UOM</td>
<td width="5%" class="font-bold rightside">Qty</td>
  <td width="8%" class="rightside font-bold">Rate</td> 
  <td width="15%" class="rightside font-bold">Amount</td> 
    
  
  </tr>
  
</thead>

<tbody>
<?php

$sql = "select d.item_no,CONCAT(t.type_name,' - ', i.item_name) item_name, u.uom_name uom,d.ctn,d.qty,d.rate, d.dis_pr from  items i,item_type t, sale_detail d,item_uom u    where t.type_id=i.type_id and d.item_no=i.item_id and i.uom=u.uom_id and
    d.s_id= :s_id";
$statement = $connect->prepare($sql);
$statement->execute(
  array(  
   ':s_id'       =>  $s_id
  )
 );
$result = $statement->fetchAll();
$count = 0;
foreach($result as $row)
 {

$amount = 0;

$tot_balance = 0;

  $qty = $row["qty"];
  $dis_pr = $row["dis_pr"];
  
  
  $rate = $row["rate"];
   $count = $count +1;
    $dis_rate = $rate * $dis_pr / 100;
    $rate = $rate - $dis_rate;
  
  $amount = $qty * $rate;
  $tot_qty = $tot_qty + $qty;
  $tot_amt = $tot_amt + $amount;
  

  
echo '



<tr>
  
   <td width="5%" class="bordered small-font">'.number_format($count, 0).'</td>
   <td width="50%" class="bordered small-font">'.$row['item_name'].'</td>
<td class=" bordered small-font rightside">'.$row['uom'].'</td>
<td  class="bordered small-font rightside">'.number_format($qty, 0).'</td>
<td  class="bordered small-font rightside ">'.number_format($rate, 0).'</td>
<td  class="bordered small-font rightside ">'.number_format($amount, 0).'</td>

   </tr>
   ';
   
  
  
  

}
$tot_balance =  $tot_amt;

echo '

<tr>
<td colspan="2" class="rightside font-bold" width="55%">Total : </td>
<td  class="total_line rightside small-font"></td>
<td  class="total_line rightside small-font">'.number_format($tot_qty, 0).'</td>
<td class="total_line rightside small-font"></td>
<td class="total_line rightside small-font">'.number_format($tot_amt, 0).'</td>
  
</tr>

';

if($gst_pr > 0)
{
  $gst_amount = $tot_amt * $gst_pr / 100;
  $net_amount = $tot_amt + $gst_amount;
echo '

<tr>
<td colspan="2" class="rightside font-bold" width="55%">GST:'.$gst_pr.'% : </td>
<td  class="total_line rightside small-font"></td>
<td  class="total_line rightside small-font"></td>
<td class="total_line rightside small-font"></td>
<td class="total_line rightside small-font">'.number_format($gst_amount, 0).'</td>
  
</tr>';}
if($fst_pr > 0)
{
  $fst_amount = $tot_amt * $fst_pr / 100;
  $net_amount = $net_amount + $fst_amount;
echo '

<tr>
<td colspan="2" class="rightside font-bold" width="55%">FST:'.$fst_pr.'% : </td>
<td  class="total_line rightside small-font"></td>
<td  class="total_line rightside small-font"></td>
<td class="total_line rightside small-font"></td>
<td class="total_line rightside small-font">'.number_format($fst_amount, 0).'</td>
  
</tr>';}
echo '
<tr>
<td colspan="2" class="rightside font-bold" width="55%">Net Amount: </td>
<td  class="total_line rightside small-font"></td>
<td  class="total_line rightside small-font"></td>
<td class="total_line rightside small-font"></td>
<td class="total_line rightside small-font">'.number_format($net_amount, 0).'</td>
  
</tr>';


?>

</tbody>
</table>

<div class="notes" align="center">
  <br />
  <b>Notes</b>
  <p>We are authorized distributor & dealer of M/S Fast Cables LTD. We have supplied                

  
</p>
<p>electronic goods under HS Code 9405. We are subject to income tax withheld               

</p>
<p>under section 153(1)(a) @ 0.25%                

</p>

</div>
<div align="right">
  <br />
  <br />
  <br />
  <b>Signature______________</b>
</div>
</body>
</html>