<!doctype html>
<html class="no-js" lang="en">
<?php
session_start();
?>
<head>
    <?php 
  include '../includes/connection.php';
$voucher=$_GET['voucher'];
  ?>

<script type="text/javascript">
      window.onload = function() { window.print();
        var is_chrome = function () { return Boolean(window.chrome); }
            if(is_chrome) 
            {
            setTimeout(function(){document.location.href = "creditors.php";}, 0); 
            //give them 10 seconds to print, then close
            }
            else
            {
             setTimeout(function(){document.location.href = "creditors.php";}, 0); 
            }
        }
   
 </script>
</head>
<body style="font-family: Sans serif,Courier New, Courier,Lucida Sans Typewriter, Lucida Typewriter, monospace; font-stretch: expanded; display: inline-block;">
        <div class="row" style="margin: 20px;" >
        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
        </div>
        <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="margin-top:16px;">
       
        <div class="row" style=" font-size: 20px; ">
        <?php include('myheader.php'); ?>
          <div>
          <?php
          
   


 $paye=mysqli_fetch_array(mysqli_query($con,"SELECT * from purchase_payments where voucher_no='$voucher' && branch_id='$branch'"));
                  $puid=$paye['purchase_id'];
                  $ampaid=$paye['amount_paid'];
                  $sqlxy = "SELECT id, (select product_name from products where id=purchases.product_id)as product_name, quantity, unit_price, (select symbol from units where UnitID=(select Units from products where id=purchases.product_id))as units,(select total_price from purchase_totals where id=purchases.purchase_id)as tprice,(select name from suppliers where supplier_id=purchases.supplier) as supplier,(select name from users where id=purchases.AddedBy) as user  from purchases where purchase_id='$puid' ";
              
$sup=mysqli_fetch_array(mysqli_query($conn, $sqlxy));

          ?>
        <br>
        <br>
        <strong>Payment For Goods Supplied</strong>
        <br>
        
        Voucher No:  <?php echo $voucher; ?><br>
        
        
   </div>
    </div>
    <div>
        <br>
        Date:  <?php echo date('d/m/Y')?>
        
   </div>
        <hr style="margin: 0; border-style: dashed;">
        <div>
        <br>
        <table width="100%" style="border-style: dotted; border: 2px;">
          <thead style="text-align: left;">
            <th width="40%">ITEM</th>
            <th width="20%">QTY</th>
           
            <th width="20%">PRICE</th>
            <th width="20%">AMOUNT</th>
          </thead>
        <div>
          
        </div>
        </table>
        
   </div>
   <hr style="margin: 0; border-style: dashed;">
   <div>
   <br>
         <table width="100%" style="border-style: dotted; border: 2px;">
          <tbody>
          <?php
        $result2 = mysqli_query($conn, $sqlxy);
          while($row = mysqli_fetch_assoc($result2)) {
            ?>
            <tr>
              <td width="40%"><?php echo $row['product_name'];?></td>
              <td width="20%"><?php echo $row['quantity']." ".$row['units'];?></td>
              <td width="20%"><strong><?php echo number_format($row['unit_price']);?></td>
              <td width="20%"><?php echo number_format($row['unit_price']*$row['quantity']);?></td>
            </tr>
            <?php
           
          }
          $ptp=mysqli_fetch_array(mysqli_query($con,"SELECT * from purchase_totals where id='$puid'"));
   $balre= (int)$ptp['total_price']-(int)$ptp['paid'];
          ?>
            
          </tbody>
        </table>
        </div>
        <hr style="margin: 0; border-style: dashed;">
        <div>
        
         <table width="100%" style="border-style: dotted; border: 2px;">
          <thead style="text-align: left; font-stretch: expanded;  ">
            <th colspan="4" width="80%" style=" transform: scale(1,2); font-size: 16px;"><h5>Total</h5></th>
            <th style=" transform: scale(1,2); font-size: 16px;"><?php echo number_format($ptp['total_price']);?></th>
          </thead>

            <thead style="text-align: left; font-stretch: expanded;">
            <th colspan="4" width="80%" style=" transform: scale(1,2); font-size: 16px;">Amount Paid</th>
            <th style=" transform: scale(1,2); font-size: 16px;"><?php echo number_format($ptp['paid']);?></th> 
          </thead>
             <thead style="text-align: left; font-stretch: expanded;">
            <th colspan="4" width="80%" style=" transform: scale(1,1.5); font-size: 16px;"><br>Balance</th>
            <th style=" transform: scale(1,1.5); font-size: 16px;"><br><?php echo number_format($balre);?></th>

          </thead>
         
        </table>
        </div>
        <hr style="margin: 5px; border-style: dashed;">
        
        <div>
          <p align="center">Paid BY: <?php echo $sup['user'];?></p>
          
        </div>
        <div>
          <p align="center">POS Software Powered By:<br> <?php $dev_select=mysqli_fetch_array(mysqli_query($con,"select * from Developer")); echo $dev_select['developer_name']; ?> <br><?php echo $dev_select['tel'];?></p>
        </div>
   </div>
 </div>
        
        
        
        
</body>
<?php

?>
</html>