<?php





require_once 'pdf.php';


 


 include('db_con.php');


 $html = '';


 


 $p_id = $_GET['id'];


 $tot_qty = 0;


 $tot_amt = 0;


 $discount = 0;


 $gst_amt = 0;





 





  $heading1 = "Purchase Return Invoice";


  $heading2 = "---------";


  $heading3 = "---------";


        














  $statement = $connect->prepare("select m.pr_id,m.inv_no,0 as chal_no,0 as bilty_no,m.due_day,DATE_FORMAT(m.due_date,'%d-%m-%Y')as due_date,DATE_FORMAT(m.dated,'%d-%m-%Y')as dated ,DATE_FORMAT(m.cur_stamp,'%d-%m-%Y  %h:%i %p') as cur_stamp,m.description,m.discount,m.freight,m.freight_dsc,m.discount_dsc,m.gst_pr,v.name,v.phone,q.sv_name,


    d.item_no,CONCAT(i.item_name,' ',t.type_name,' ',c.color_name,' ',b.brand_name) as item_name,u.uom_name,d.ctn,d.qty,d.rate,d.dis_pr,d.dis_rate from pr_detail d,pr m,item_uom u,


    vendors v, sub_vendors q, items  i,item_type t,item_color c,item_brand b where m.pr_id=d.pr_id and d.item_no=i.item_id and i.uom=u.uom_id and c.color_id=i.color_id and t.type_id=i.type_id and i.brand_id=b.brand_id and v.v_id=m.v_id and m.sv_id=q.sv_id and


    m.pr_id= :p_id


    


  ");


 $statement->execute(


  array(  


   ':p_id'       =>  $p_id


  )


 );


 $result = $statement->fetchAll();





 


  foreach($result as $row)


 {








 





 $html .=' <style>


 * {


 font-family : Helvetica;


}


    @page { margin:160px 20px; }


    #header { position: fixed; left: 0px; top: -160px; right: 0px; height: 160px; text-align: center;background-color: #fff; }


    #footer { position: fixed; left: 0px; bottom: -160px; right: 0px; height: 300px; background-color: #fff; }


    #content {margin:0;}


    .rightside{text-align:right;}


    #footer .page:after { content: "page " counter(page) " of " counter(pages);}


    


    #table_header th {


    border-top:1px solid black;


    border-bottom:1px solid black;


  }


  .small-font {


  font-size:12px;


  font-weight:normal;


  font-family:Helvetica;


}


.font-bold {


  font-size:13px;


  font-weight:normal;


  font-family:Helvetica;


}


.signtable {


  text-align:center;





}





.topline {


  border-top:0.1px solid black;


}


.brline


{


  border-top:0.1px solid black;


}





 h5, h6{


  margin: 0;


  padding: 0;


}





#main-header {


  font-size:12px;





}


  </style>











  <div id="header">


    <div id="heading">


    <br />


  <h5>'.$heading1.'</h5>


  <h6>'.$heading2.'</h6>


  <h6>'.$heading3.'</h6>


  </div>


  


  <table id="main-header" width="100%">


  <tr>


  <td width="15%">GRN : '.$row['pr_id'].'</td><td width = "50%">Inv No. : '.$row["inv_no"].'</td><td width="15%">Date :</td><td width = "20%">'.$row["dated"].'</td>


  </tr>





  <tr>


  <td width="15%">M/S :</td><td width = "50%">'.$row["name"].'</td><td width="15%">Credit Days :</td><td width = "20%">'.$row["due_day"].'</td>


  </tr>


  <tr>


  <td width="15%">Phone No. :</td><td width = "50%">'.$row["phone"].'</td><td width="15%">Due Date :</td><td width = "20%">'.$row["due_date"].'</td>


  </tr>





  <tr>


  <td width="15%">Sub :</td><td width = "50%">'.$row["sv_name"].'</td><td width="15%">Bilty No. :</td><td width = "20%">'.$row["bilty_no"].'</td>


  </tr>





  


  </table>


  <table width="100%" id="table_header">





  <tr>


  <th width="5%" class="font-bold">Sr</th>


  


  <th width="46%" class="font-bold">Item Name</th>


  <th width="7%" class="font-bold">UOM</th>


  


  <th width="5%" class="rightside font-bold">Ctn</th>


  <th width="7%" class="rightside font-bold">Qty</th>


  


  <th width="10%"class="rightside font-bold">Rate</th>


  <th width="10%"class="rightside font-bold">Discount</th>


  <th width="10%" class="rightside font-bold">Amount</th>


 











  </tr>





  </table>





  </div>





  


';





}


$count = 0;


$amount = 0;


$discount = $row["discount"];


$freight = $row["freight"];


$gst_pr = $row["gst_pr"];


foreach($result as $row)


 {


  $qty = $row["qty"];


  $rate = $row["rate"];


  $dis_rate = $row["dis_rate"];


  $dis_pr = $row["dis_pr"];


  if($dis_rate > 0)


  {


    $dis_item = $qty * $dis_rate; 


    $dis_type = "PP";


    $dis_given = $dis_rate;


  }else{





    $dis_rate = $rate * $dis_pr / 100;


    $dis_item = $qty * $dis_rate;


    $dis_given = $dis_pr;


    $dis_type="%";}





   $count = $count +1;


  


  $amount = $qty * $rate - $dis_item;


  $tot_qty = $tot_qty + $qty;


  $tot_amt = $tot_amt + $amount;


$html .= '


  <div id="content">


  


  <table width="100%">


<tr>


  <td width="5%" class="small-font">'.$count.'</td>


  


<td width="46%" class="small-font">'.$row["item_name"].'</td>


<td width="7%" class="small-font">'.$row["uom_name"].'</td>


<td width="5%" class="rightside small-font">'.$row["ctn"].'</td>


<td width="7%" class="rightside small-font">'.number_format($qty, 2).'</td>


   <td width="10%" class="rightside small-font">'.number_format($rate, 2).'</td>


   <td width="7%" class="rightside small-font">'.number_format($dis_given, 2).'</td>


   <td width="3%" class="rightside small-font">'.$dis_type.'</td>


   <td width="10%" class="rightside small-font">'.number_format($amount, 2).'</td>


  


   


    


   </tr>


   


  </table>








  </div>





  ';


  if($gst_pr > 0)


    {


      $gst_amt = $tot_amt * $gst_pr / 100;


    }


  $net_amt = $tot_amt - $discount + $freight + $gst_amt;


  $html .='








  <div id="footer">


 <div class="brline"></div>





<table width="100%">


<tr>


<td width="60%" class="rightside small-font">Total:</td><td class ="rightside small-font" width="10%">'.number_format($tot_qty, 2).'</td>





<td width="10%"></td>


<td width="10%"></td>


<td width="10%" class="rightside small-font">'.number_format($tot_amt, 2).'</td>





</tr>


</table>


<table width="100%">


<tr>


<td class="rightside small-font" width="70%">GST('.$gst_pr.' %): Amount :</td><td class ="rightside" width="10%"></td>


<td width="10%"></td><td width="10%" class="rightside small-font">'.number_format($gst_amt, 2).'</td>





</tr>


<tr>


<td class="rightside small-font" width="70%">'.$row['discount_dsc'].' :</td><td class ="rightside" width="10%"></td>


<td width="10%"></td><td width="10%" class="rightside small-font">'.number_format($discount, 2).'</td>





</tr>


<tr>


<td class="rightside small-font" width="70%">'.$row['freight_dsc'].' :</td><td class ="rightside" width="10%"></td>


<td width="10%"></td><td width="10%" class="rightside small-font">'.number_format($freight, 2).'</td>





</tr>





<tr>


<td class="rightside small-font" width="90%">Net Amount :</td><td class ="rightside" width="10%"></td>


<td width="10%"></td><td width="10%" class="rightside small-font">'.number_format($net_amt, 2).'</td>





</tr>








</table>


<div class="brline"></div>


<table width="100%">





<tr>


<td class="small-font" width="90%">Printed at : '.$row['cur_stamp'].'</td>








</tr>


</table>


<br />


<br />


<br />


<br />


<table width="100%" class="signtable">


<tr>


<td width="15%"></td><td class="small-font topline" width="20%">Prepared By</td><td width="20%"></td><td width="20%" class="small-font topline">Received By</td><td width="25%"></td>


<td width="20%" class="small-font topline">Checked By</td><td width="25%"></td>


</tr>


</table>








  


  </div>


 


        ';





}








 $pdf = new Pdf();





 $file_name = 'purchase_Invoice_Return_A4.pdf';


 $pdf->setPaper('A4', 'portrait');





 $pdf->loadHtml($html);


 $pdf->render();


 $pdf->stream($file_name, array("Attachment" => false));





?>