<?php
require('validate.php');
require('functions.php');
$getpage =$_SERVER['QUERY_STRING']; 
//echo $getpage;
$explode= explode('=',$getpage);
$refno=$explode[1];
//echo $orderno;exit;

$query="SELECT order_ FROM ".$prefix."debtor_trans WHERE reference='$refno'";
$result=mysqli_query($linkid,$query);
$myorder=mysqli_fetch_row($result);


$query="SELECT order_no,reference,ord_date,contact_phone,contact_email,deliver_to,delivery_date,total,b.name,b.address FROM ".$prefix."sales_orders AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no  AND a.order_no=$myorder[0]";
$resultType=mysqli_query($linkid,$query);
$orderData=mysqli_fetch_array($resultType);



$query="SELECT stk_code,unit_price,quantity,long_description FROM ".$prefix."sales_order_details AS a,".$prefix."stock_master AS b WHERE a.stk_code=b.stock_id AND a.order_no=$myorder[0]";
$resultOrder=mysqli_query($linkid,$query);



/*...................................input by user name..........................................*/



?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>DELIVERY NOTE CONFIRMATION</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap framework -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />
<link rel="shortcut icon" href="img/favicon.ico" />
<style type="text/css">

.tableborder { border-collapse: collapse; border : 1px solid #CCC; }

.tableborder td,th { border-left: 1px solid #CCC; }

.tableborder th { border-bottom: 1px solid #CCC; }

.tableborder td:first-child { border-left: none; }

</style>
</head>
<body>
<!--<div>&nbsp;</div>-->
<div>&nbsp;</div>
<table width="85%" border="1" align="center" style="border:1px #999 dotted;font-size:12px">
  <tr>
    <td><table width="98%" border="0" align="center">
        <tr>
          <td colspan="2" align="left"><h4 class="heading">DELIVERY NOTE </h4></td>
        </tr>
        <tr>
          <td width="50%" align="left"><table width="100%" border="0">
              <tr>
                <td colspan="2"><strong>No. : </strong><?php echo $refno;?></td>
                <td width="41%"><strong>Date :</strong> <?php echo $orderData['ord_date'];?></td>
              </tr>
              <tr>
                <td width="50%"><strong>Customer Name</strong> </td>
                <td width="9%">:</td>
                <td><?php echo $orderData['name'];?></td>
              </tr>
              <tr>
                <td><strong>Address</strong></td>
                <td>:</td>
                <td><?php echo $orderData['address'];?></td>
              </tr>
              <tr>
                <td><strong>Contact No</strong> </td>
                <td>:</td>
                <td><?php echo $orderData['contact_phone'];?></td>
              </tr>
              <tr>
                <td><strong>Sales Person</strong></td>
                <td>:</td>
                <td><?php echo $name;?></td>
              </tr>
      
            </table></td>
          <td width="50%" align="right">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2"><table width="100%" class="tableborder">
              <tr>
                <th width="5%" align="center">SL. No</strong></th>
                <th width="40%" align="left"><strong>Article &amp; description </strong></th>
				<th width="10%" align="center"><strong>Delivery Date</strong></th>
                <th width="15%" align="center"><strong>Net Price</strong></th>
                <th width="15%" align="center"><strong>Qty.</strong></th>
                <th width="15%" align="right"><strong>Amount(Tk.)</strong></th>
              </tr>
              <?php

			  if($resultOrder)

			  { $i=0;

			  while($mydata=mysqli_fetch_assoc($resultOrder))

			  {		  

			  $i+=1;
			  $totalOrder= $mydata['unit_price'] * $mydata['quantity'];
			  ?>
              <tr>
                <td align="center" valign="top"><?php echo $i;?></td>
                <td align="left" valign="top" ><?php echo $mydata['stk_code'];?><br>
                  <small><?php echo $mydata['long_description'];?></small></td>
				 <td valign="top"><?php echo $orderData['delivery_date'];?></td> 
                <td align="center" valign="top" ><?php echo $mydata['unit_price'];?></td>
                <td align="center" valign="top" ><?php echo $mydata['quantity'];?></td>
                <td align="right"  valign="top"><?php echo number_format($totalOrder,2);?></td>
              </tr>
              <?php

			  }

			  }

			  ?>
              <tr style="border-top: 1px solid #CCC;">
                <td align="right" colspan="5"><b>TOTAL DELIVERY INCL. VAT</b></td>
                <td align="right"><strong><?php echo number_format($orderData['total'],2);?></strong></td>
              </tr>
              <!--<tr style="border-top: 1px solid #CCC;">
                <td align="right" colspan="5"><b>Payable Amount</b></td>
                <td align="right"><strong><?php echo number_format($orderData['total'],2);?></strong></td>
              </tr>-->
            </table></td>
        </tr>
        <tr>
          <td colspan="2" align="left"><b>Amount In Words :</b>
            <?php  $num =$orderData['total'];

 $test = convertNumber($num);

 echo ucwords($test)." Only";?>
          </td>
        </tr>
        <tr>
          <td colspan="2" valign="top"><table width="100%" border="0">
              <tr>
                <td colspan="2" width="100%"><table width="40%" border="0">
                    <tr>
                      <td><strong>Delivery Place</strong> : </td>
                      <td><?php echo $orderData['deliver_to'];?></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><?php echo $orderData['address'];?></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><?php echo $orderData['contact_phone'];?></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td colspan="2"><br>
                  <strong>Terms & Conditions</strong> : Goods once ordered cannot be changed/cancelled. Order will be valid for 90days from the date of order. Payment has to be made before 01(One) day from the date of delivery.</td>
              </tr>
              <tr>
                <td colspan="2"><table width="100%" border="0">
                    <tr>
                      <td><br>
                        ....................................................<br>
                        <strong>Customer's Signature</strong></td>
                      <td align="center"><br>
                        ....................................................<br>
                        <strong>Prepared by : <b><?php echo $name;?> </b></strong></td>
                      <td align="center"><br>
                        ....................................................<br>
                        <strong>Approved by: </strong></td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
