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

$query="SELECT order_,tran_date FROM ".$prefix."debtor_trans WHERE reference='$refno'";
//echo $query;exit;
$result=mysqli_query($linkid,$query);
$myorder=mysqli_fetch_row($result);
$orderno=$myorder[0];
$dateval=explode("-",$myorder[1]);
$orderdate=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));


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

$dateval=explode("-",$orderData['delivery_date']);
$deliverydate=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));

$query="SELECT b.salesman_name FROM ".$prefix."cust_branch AS a,".$prefix."salesman AS b WHERE a.salesman=b.salesman_code AND a.debtor_no=$debtor";
$resultType=mysqli_query($linkid,$query);
$salesData=mysqli_fetch_array($resultType);
$salesman=$salesData['salesman_name'];

$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=$orderno";
$resultOrder=mysqli_query($linkid,$query);

?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>&nbsp;&nbsp;&nbsp;DELIVERY NOTE</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>
<table width="70%" border="1" align="left" style="border:1px #999 hidden;font-size:11px">
  <tr>
    <td><table width="100%" border="0" align="left">
        <tr>
          <td width="70%" align="left"><table width="100%" border="0" align="left">
              <tr>
                <td colspan="2" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>MS01-<?php echo $refno;?></strong>&nbsp;&nbsp;&nbsp;</td>
                <td width="65%" style="padding-left:80px;"><strong>Date :</strong> <?php echo $orderdate;?></td>
              </tr>
			  <tr>
                <td width="31%">&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td><?php echo $orderData['name'];?></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td><?php echo $orderData['address'];?></td>
              </tr>
              <tr>
                <td colspan="3">&nbsp;</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 $salesman;?></td>
              </tr>      
            </table></td>
          <td width="40%" align="right">&nbsp;</td>
        </tr>
        <tr>
           <td colspan="2" width="100%" valign="top" style="height:438px;min-height:280px; margin-bottom:6px position:relative;">
		  <table width="100%" cellpadding="4">
              <tr>
                <th width="6%" align="center">SL.</strong></th>
                <th width="44%" align="left"><strong>Article &amp; description </strong></th>
				<th width="15%" align="center"><strong>Delivery Date</strong></th>
                <th width="11%" align="center"><strong>Net Price</strong></th>
                <th width="12%" align="center"><strong>Qty.</strong></th>
                <th width="12%" 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" align="center"><?php echo $deliverydate;?></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>
                <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>
              
            </table></td>
        </tr>
       <!-- <tr>
          <td colspan="2" align="left">
		  <div style="min-height:280px;">&nbsp;</div>
		  </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 if($orderData['notes']=="")
					  echo $orderData['deliver_to'];
					  else
					  echo $orderData['notes'];?></td>
                    </tr>
					 <tr>
                      <td>&nbsp;</td>
                      <td><?php echo $orderData['contact_phone'];?></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td colspan="2" valign="top">
                  <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>

