<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<!--reference to main.css removed-->
<?php
include('../include/session.php');
?>

<?php
$purchase_id=$_GET['purchase_id'];

$table_name = $_SESSION['db_prefix']."_purchase";
$purchase_query = "SELECT *  FROM $table_name WHERE  purchase_id = '".$purchase_id."' ";
$purchase_result = mySQL_query($purchase_query);
$b0 = mysql_result($purchase_result, 0, "purchase_date");
$b2 = mysql_result($purchase_result, 0, "supplier_id");
$b5 = mysql_result($purchase_result, 0, "purchase_order");
$b6 = mysql_result($purchase_result, 0, "ordered_by");
$b7 = mysql_result($purchase_result, 0, "authorised_by");
$b10 = mysql_result($purchase_result, 0, "company");

  $date = strtotime($b0);
$orderno = $b5;
   $table_name = $_SESSION['db_prefix']."_purchase_lines";
   $line_query = "SELECT *  FROM $table_name WHERE  purchase_id = '".$purchase_id."' AND store_item_id>0";
   $line_result = mySQL_query($line_query);
   $line_num = mysql_num_rows($line_result);
   
   $table_name = $_SESSION['db_prefix']."_purchase_lines";
   $line2_query = "SELECT *  FROM $table_name WHERE  purchase_id = '".$purchase_id."' AND store_item_id=0";
   $line2_result = mySQL_query($line2_query);
   $line2_num = mysql_num_rows($line2_result);
   
  
$table_name2 = $_SESSION['db_prefix']."_suppliers";
$customer_query = "SELECT * FROM $table_name2 WHERE supplier_id ='".$b2."' ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);  

$a15 = mysql_result($customer_result, 0, "account_name");
$a7 = mysql_result($customer_result, 0, "post_address");
$a9 = mysql_result($customer_result, 0, "post_place");
$a10 = mysql_result($customer_result, 0, "phys_address");
$a11 = mysql_result($customer_result, 0, "phys_place");
$a13 = mysql_result($customer_result, 0, "VAT_no");


?>
<title>Purchase order <?php echo $b5 .' for '. $a15 ?></title>


<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/print.css" />

</head>

<body  onload="window.print(); window.close();" >

<div style="width:800px;">
<?php 
if ($b10=='Manase') {include('../include/print_header.php');}
if ($b10=='M-works') {include('../include/m_print_header.php');}
?>
<br>
<br>
<br>
<div style="width:650px; margin-left:50px; ">
<font font-family:Arial, Helvetica, sans-serif; size="+3"><b>Purchase order</b></font>
<br>
Suppliers copy
<br>
<br>

    <table width="620" id="tableprint_no_border" >
            <tr>
              <td align="left" valign="top">Order no:</td>
              <td align="left" valign="top"><?php echo $b5; ?></td>
              <td align="right" valign="top">Date:&nbsp;&nbsp;</td>
              <td align="left" valign="top"><?php echo date("d-m-Y",  $date); ?></td>
            </tr>
            <tr>
              <td width="86" align="left" valign="top">&nbsp;</td>
              <td width="183" align="left" valign="top">&nbsp;</td>
              <td width="146" align="left" valign="top">&nbsp;</td>
              <td width="185" align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">To:</td>
              <td colspan="3" align="left" valign="top"><?php echo $a15?></td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top"><?php echo $a7?></td>
              <td colspan="2" align="left" valign="top"><?php echo $a10?></td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top"><?php echo $a9?></td>
              <td colspan="2" align="left" valign="top"><?php echo $a11?></td>
            </tr>
            <tr>
              <td align="left" valign="top">VAT no:<?php echo $a13 ?></td>
              <td align="left" valign="top">&nbsp;</td>
              <td colspan="2" align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">Ordered by:</td>
              <td align="left" valign="top"><?php echo $b6 ?></td>
              <td align="left" valign="top">Authorised by:</td>
              <td align="left" valign="top"><?php echo $b7 ?></td>
            </tr>
            <tr>
              <td colspan="4" align="left" valign="top">&nbsp;</td>
            </tr>
          </table>
        <br>
<br>
Please supply us with the following:<br>
<br>
<table width="620" id="tableprint" >
      <tr>
              <td height="20" align="left" valign="top">Item</td>
              <td width="51" align="center" valign="top">Quantity</td>
              <td width="106" align="center" valign="top">Unit Price </td>
              <td width="112" align="center" valign="top">Total</td>
      </tr>
            <?php
        $i=0;
        $sub_tot=0;
        $a6_total=0;
         while ($i<$line_num){
           $a0 = mysql_result($line_result, $i, "purchase_line_id");
           $a1 = mysql_result($line_result, $i, "store_item_id");
           $table_name = $_SESSION['db_prefix']."_store_items";
            $item_query = "SELECT item_name, subCategory, unit FROM $table_name WHERE store_item_id = '".$a1."' ";
            $item_result = mySQL_query($item_query);
            $a1a = mysql_result($item_result, 0, "item_name");
            $a3a = mysql_result($item_result, 0, "unit");
            $a4 = mysql_result($item_result, 0, "subCategory");
           $a2 = mysql_result($line_result, $i, "quantity");
           $a3 = mysql_result($line_result, $i, "price");
          $a5=$a2*$a3;
          $a6_total=$a6_total+$a5;
           
         ?>
            <tr>
              <td valign="top"><?php echo $a1a ?></td>
              <td valign="top"><?php echo $a2 ?></td>
              <td align="right" valign="top"><div align="right"><?php echo number_format($a3, 2, '.', ',') ?></div></td>
              <td align="right" valign="top"><div align="right"><?php echo number_format($a5, 2, '.', ',')?></div></td>
            </tr>
            <?php 
         // $a6_total=$a6_total+$a6;
        $i++;
         }
         ?>
            <?php
        $i=0;
        $sub_tot=0;
        $b6_total=0;
         while ($i<$line2_num){
           $b0 = mysql_result($line2_result, $i, "purchase_line_id");
           $b1 = mysql_result($line2_result, $i, "item_name");
           $b2 = mysql_result($line2_result, $i, "quantity");
           $b3 = mysql_result($line2_result, $i, "price");
           $b4 = mysql_result($line2_result, $i, "order_no");
          $b5=$b2*$b3;
          $b6_total=$b6_total+$b5;
           
         ?>
            <tr>
              <td valign="top"><?php echo $b1 ?></td>
              <td valign="top"><?php echo $b2 ?></td>
              <td align="right" valign="top"><div align="right"><?php echo number_format($b3, 2, '.', ',') ?></div></td>
              <td align="right" valign="top"><div align="right"><?php echo number_format($b5, 2, '.', ',')?></div></td>
            </tr>
            <?php 
         // $a6_total=$a6_total+$a6;
        $i++;
         }
         ?>
    </table>
          <br>
<br>
<?php 
$all_total = $a6_total + $b6_total;
?>
          
    <table width="620" id="tableprint">
  <tr>
    <td width="496" align="right">All total:</td>
    <td width="112" align="right"><?php echo number_format($all_total, 2, '.', ',') ?>&nbsp;</td>
  </tr>
</table>
</div>

<div style="width:800px; page-break-before:always;">
<?php 
if ($b10=='Manase') {include('../include/print_header.php');}
if ($b10=='M-works') {include('../include/m_print_header.php');}
?> 

<div style="width:650px; margin-left:50px; ">
<font font-family:Arial, Helvetica, sans-serif; size="+3"><b>Purchase order</b></font>
<br>
Manase copy<br>
<br>

    <table width="620" id="tableprint_no_border" >
            <tr>
              <td align="left" valign="top">Order no:</td>
              <td align="left" valign="top"><?php echo $orderno; ?></td>
              <td align="right" valign="top">Date:&nbsp;&nbsp;</td>
              <td align="left" valign="top"><?php echo date("d-m-Y",  $date);  ?></td>
            </tr>
            <tr>
              <td width="86" align="left" valign="top">&nbsp;</td>
              <td width="183" align="left" valign="top">&nbsp;</td>
              <td width="146" align="left" valign="top">&nbsp;</td>
              <td width="185" align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">To:</td>
              <td colspan="3" align="left" valign="top"><?php echo $a15;?></td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top"><?php echo $a7;?></td>
              <td colspan="2" align="left" valign="top"><?php echo $a10;?></td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top"><?php echo $a9;?></td>
              <td colspan="2" align="left" valign="top"><?php echo $a11;?></td>
            </tr>
            <tr>
              <td align="left" valign="top">VAT no:<?php echo $a13; ?></td>
              <td align="left" valign="top">&nbsp;</td>
              <td colspan="2" align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">Ordered by:</td>
              <td align="left" valign="top"><?php echo $b6; ?></td>
              <td align="left" valign="top">Authorised by:</td>
              <td align="left" valign="top"><?php echo $b7; ?></td>
            </tr>
            <tr>
              <td colspan="4" align="left" valign="top">&nbsp;</td>
            </tr>
          </table>
        <br>
<br>
Please supply us with the following:<br>
<br>
<table width="620" id="tableprint" >
      <tr>
              <td height="20" align="left" valign="top">Item</td>
              <td width="51" align="center" valign="top">Quantity</td>
              <td width="106" align="center" valign="top">Unit Price </td>
              <td width="112" align="center" valign="top">Total</td>
      </tr>
            <?php
        $i=0;
        $sub_tot=0;
        $a6_total=0;
         while ($i<$line_num){
           $a0 = mysql_result($line_result, $i, "purchase_line_id");
           $a1 = mysql_result($line_result, $i, "store_item_id");
           $table_name = $_SESSION['db_prefix']."_store_items";
            $item_query = "SELECT item_name, subCategory, unit FROM $table_name WHERE store_item_id = '".$a1."' ";
            $item_result = mySQL_query($item_query);
            $a1a = mysql_result($item_result, 0, "item_name");
            $a3a = mysql_result($item_result, 0, "unit");
            $a4 = mysql_result($item_result, 0, "subCategory");
           $a2 = mysql_result($line_result, $i, "quantity");
           $a3 = mysql_result($line_result, $i, "price");
          $a5=$a2*$a3;
          $a6_total=$a6_total+$a5;
           
         ?>
            <tr>
              <td valign="top"><?php echo $a1a; ?></td>
              <td valign="top"><?php echo $a2; ?></td>
              <td align="right" valign="top"><div align="right"><?php echo $a3; ?></div></td>
              <td align="right" valign="top"><div align="right"><?php echo number_format($a5, 2, '.', ',');?></div></td>
            </tr>
            <?php 
         // $a6_total=$a6_total+$a6;
        $i= $i+1;
         }
         ?>
            <?php

        $i=0;
        $sub_tot=0;
        $b6_total=0;
         while ($i<$line2_num){
           $b0 = mysql_result($line2_result, $i, "purchase_line_id");
           $b1 = mysql_result($line2_result, $i, "item_name");
           $b2 = mysql_result($line2_result, $i, "quantity");
           $b3 = mysql_result($line2_result, $i, "price");
           $b4 = mysql_result($line2_result, $i, "order_no");
          $b5=$b2*$b3;
          $b6_total=$b6_total+$b5;
           
         ?>
            <tr>
              <td valign="top"><?php echo $b1 ?></td>
              <td valign="top"><?php echo $b2 ?></td>
              <td align="right" valign="top"><div align="right"><?php echo $b3 ?></div></td>
              <td align="right" valign="top"><div align="right"><?php echo number_format($b5, 2, '.', ',')?></div></td>
            </tr>
            <?php 
         // $a6_total=$a6_total+$a6;
        $i++;
         }
         ?>
    </table>
          <br>
<br>
<?php 
$all_total = $a6_total + $b6_total;
?>
          
    <table width="620" id="tableprint">
  <tr>
    <td width="496" align="right">All total:</td>
    <td width="112" align="right"><?php echo number_format($all_total, 2, '.', ',') ?>&nbsp;</td>
  </tr>
</table>

          

</div> 
</div>

</body>
</html>