<?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;
 $amount = 0;
 $sql = "select title_id from sale where s_id = '".$s_id."'";
 $statement = $connect->prepare($sql);
                      $statement->execute(); 
                      $title_id = $statement->fetchColumn();
$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'];
 }
 $sql =$connect->query("select FORMAT(sum(d.qty*d.rate - d.qty*d.dis_rate - d.rate * d.dis_pr / 100 * d.qty)   + sum(d.qty*d.rate - d.qty*d.dis_rate - d.rate * d.dis_pr / 100 * d.qty)  * gst_pr / 100 -m.discount + m.freight,2) as amount from sale_detail d,sale m where m.s_id=d.s_id and d.s_id='".$s_id."'");
 $amount = $sql->fetchColumn();


  $statement = $connect->prepare("select m.s_id,m.inv_no,DATE_FORMAT(m.dated,'%d-%m-%Y') as dated,m.cur_stamp,m.description,m.gd_no,m.discount,m.discount_dsc,m.freight_dsc,m.cust_name,m.contact,m.freight,m.gst_pr,m.pre_balance,a.acc_name,c.phone,o.user_name from sale m,user_detail o,
    accounts a,customers c 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>Under Taking Print</title>
     <style>
        * {
          padding: 0;
          margin: 20px 20px 20px 20px;
          font-family: Book Antiqua;
          font-weight: normal;

        }
    #rpt_header {
     width:100%;
    margin:0 auto;
    
    text-align:left;
    margin-top: 20px;
    
    }

    .content , p {
    page-break-inside: avoid;
  }

  .title {
    
    font-size: 25px;
    font-family:Book Antiqua;
    text-align: center;
    padding-left: 40px;
  }
   

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

    footer {
  
}
.auth {
  text-align: center;
  font-size: 20px;
  top:90px ;
  right: 270px;
  position: fixed;
  font-family: Tahoma;
}
.taking {
  text-align: center;
  font-size: 15px;
  top:150px ;
  right: 300px;
  position: fixed;
  font-family: Book Antiqua;
  font-weight: bold;
  border-bottom: 2px solid black;
}
thead td{
width: 25%;
font-weight: bold;
}

tbody td{

font-weight: normal;
}

@media print {
  footer {
    position: fixed;
    bottom: 40px;
    right: 20px;
    width: 30%;
  }


}
.signtable {
  margin-top: 40px;
  text-align: center;
}
.topline {
  border-top: 1px solid black;
  
}
.address {
  font-size: 11px;
  font-weight: bold;
  font-family: arial;

}
.cust {
  font-weight: bold;
}
.undertaking {
  text-decoration: underline;
  font-size: 18px;
  text-align: center;
  font-weight: bold;
}
  </style>

  </head>
  <body onload="window.print();">
    <div class="content">
      
    
 <table width="100%" class="page_header">
  <tr><td width="100%" class="undertaking">Undertaking</td></tr>
 </table>
  <?php 
  foreach($result as $row)
 {

 
  $discount = $row['discount'];
  $freight = $row['freight'];
  $s_id = $row['s_id'];
  $cur_stamp = $row['cur_stamp'];
  $gd_no = $row['gd_no'];
  $dated= $row['dated'];
  $inv_no = $row['inv_no'];
  
  $name = $row['acc_name'];
  
 
}
  ?> 

  <p class="detail">
    To: &nbsp;<?php echo '<span class="cust">'.$name.'</span>';?>
    <br />
    <br />
    Dear Customer,
    <br />
    <br />
    <br />

    We, The New Bearing Centre hereby state that we are the Comercial Importer of the supplies made to you, with following details:
  </p>

  <table width="100%" >
    <thead>
    <tr>
      <td>
        G.D #
      </td>
      <td>
        Invoice No.
      </td>
      <td>
        Date
      </td>
      <td>
        Amount
      </td>
    </tr>
    </thead>
    <tbody>
       <tr>
      <td>
        <?php echo $gd_no;?>
      </td>
      <td>
        <?php echo $inv_no;?>
      </td>
      <td>
        <?php echo $dated;?>
      </td>
      <td>
        <?php echo $amount;?>
      </td>
    </tr>
    </tbody>
    
  </table>

  <p class="detail">
    We further state that we have paid income tax under section 148 of the income tax ordinance 2001, at the time of import. Further we confirm that no addition to the value of such goods has been made by us.<br />
    <br />
    We undertake that because of claiming exemption for non-deduction of withholding tax under section 153 of the income tax ordinance 2001. if you suffer any loss/penalty imposed by the income tax department, we will compensate the same.



  </p>

  <p class="detail">
    For <br />
    <br />
    The New Bearing Center
  </p>

<footer>
  <p class="address"></p>  
      
    
</footer>



</body>
</html>