<?php



require_once 'pdf.php';

 

 include('db_con.php');

 $html = '';

 $fdate = $_GET['fdate'];

 $v_id = $_GET['v_id'];

 $tdate = $_GET['tdate'];

 $pay_status = $_GET['pay_status'];

 $sorted = $_GET['sorted'];









                $statement = $connect->prepare("

        select p.pay_id,p.chq_no,LEFT(v.name, 24) as name,p.chq_date,LEFT(p.chq_bank, 20) as chq_bank,CONCAT(p.description,' - ',pay_status) as description,p.cur_name,p.pay_status,p.amount from

         pay_voucher p,vendors v where v.v_id=p.v_id and p.chq_date between :fdate and :tdate and pay_status = :pay_status 

        order by chq_no");

       $statement->execute(

        array(                  

         ':fdate'       =>  $fdate,

         ':tdate'       =>  $tdate,         

         ':pay_status'     =>  $pay_status

        )

       );



        if($pay_status =='ALL')

               {

                $statement = $connect->prepare("

        select p.pay_id,p.chq_no,LEFT(v.name, 24) as name,p.chq_date,LEFT(p.chq_bank, 20) as chq_bank,CONCAT(p.description,' - ',p.cur_name, ' - ', p.pay_status)

        as description, p.cur_name, p.amount from

         pay_voucher p,vendors v where v.v_id=p.v_id and  p.chq_date between :fdate and :tdate

        order by chq_no");

       $statement->execute(

        array(         

         ':fdate'       =>  $fdate,

         ':tdate'       =>  $tdate         

        

        )

       );

               }            







         



          

        if($sorted == 1)

        {

          $statement = $connect->prepare("

        select p.pay_id,p.chq_no,p.chq_date,LEFT(v.name, 24) as name,LEFT(p.chq_bank, 15) as chq_bank,p.chq_date,CONCAT(p.description,' - ',p.pay_status)

        as description, p.cur_name,p.amount from

         pay_voucher p where v.v_id=p.v_id and p.chq_date between :fdate and :tdate and pay_status = :pay_status 

        order by chq_date");

       $statement->execute(

        array(                  

         ':fdate'       =>  $fdate,

         ':tdate'       =>  $tdate,         

         ':pay_status'     =>  $pay_status

        )

       );



        if($pay_status =='ALL')

               {

                $statement = $connect->prepare("

        select p.pay_id,p.chq_no,p.chq_date,LEFT(a.acc_name, 24) as name,LEFT(p.chq_bank, 20) as chq_bank,p.chq_date,CONCAT(p.description,' - ',p.pay_status)

        as description, p.cur_name,p.amount from

         pay_voucher p where v.v_id=p.v_id and  p.chq_date between :fdate and :tdate

        order by chq_date");

       $statement->execute(

        array(         

         ':fdate'       =>  $fdate,

         ':tdate'       =>  $tdate

         

        

        )

       );

               }

        }





       



              





              

  

 $result = $statement->fetchAll();

 



 $html .=' <style>

    @page { margin:80px 20px; }

    #header { position: fixed; left: 0px; top: -60px; right: 0px; height: 60px; text-align: center; }

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

    #content {margin:0;font-size:14px;}



    .rightside{text-align:right;}

    #footer .page:after { content: counter(page, upper-roman); }

    

    #table_header th {

    border-top:1px solid black;

    border-bottom:1px solid black;

  }

  </style>



  <div id="header">



  

  <table width="100%">

  <tr>

  <td width="40%">Cheques Payable '.$pay_status.'</td><td width="10%"></td>

  <td width="5%" class="rightside">From :</td><td width="12%" class="rightside">'.$fdate.'</td>

  <td width="10%"></td><td width="8%" class="rightside">To :</td><td width="15%" class="rightside">'.$tdate.'</td>

  </tr>

  <tr>

  

  </tr>

  <tr>

  <td width="10%"></td><td width="20%"></td><td width="70%" class="rightside"></td><td width="20%" class="rightside"></td>

  </tr>

  </table>

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



  <tr>

  <th width="5%">pay_id</th>

  <th width="7%">chq_no</th>

  <th width="8%">chq_date</th>

  <th width="25%">To Vendor</th>

  <th width="55%">Description</th>

  

  

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

 







  </tr>



  </table>



  </div>

  

';

foreach($result as $row)

 {

 

  $amount = $row["amount"];

$html .= '

  <div id="content">

  

<table width="100%" cellpadding="0" cellspacing="0">

<tr>

  <td width="5%">'.$row["pay_id"].'</td>

<td width="7%">'.$row["chq_no"].'</td>

<td width="8%">'.$row["chq_date"].'</td>

<td width= "25%">'.$row["name"].'</td>

<td width="55%">'.$row["description"].'</td>





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

  

   

    

   </tr>

   

  </table>





  </div>



  <div id="footer">

  <table width="100%">

  <tr>

  <td width="70%" class="rightside"> </td><td width="30%" class="rightside"></td>

  </tr>

  </table>

    Page <span class="page"></span>

  </div>



        ';



}

$html .='<hr />';

 $pdf = new Pdf();



 $file_name = 'pay_voucher.pdf';

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



 $pdf->loadHtml($html);

 $pdf->render();

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



?>