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


$query="SELECT id,order_no,trans_date,cash,cheque,chequenumber,card,cardnumber,paid,salesperson,notes  FROM ".$prefix2."order_payment WHERE money_receipt_no=$mrno";
//echo $query;exit;
$result=mysqli_query($linkid,$query);
$getdata=mysqli_fetch_row($result);

$orderid=$getdata[1];
$personid=$getdata[9];

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


//$query="SELECT * FROM ".$prefix."accounts_journal WHERE id=$vid";
$query="SELECT order_no,reference,ord_date,contact_email,deliver_to,delivery_date,total,a.payment_terms,b.debtor_no,b.debtor_ref AS phone,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=$orderid";
//echo $query;exit;
$resultType=mysqli_query($linkid,$query);
$orderData=mysqli_fetch_array($resultType);
$debtor=$orderData['debtor_no'];

$salesperson=$orderData['payment_terms'];
$query="SELECT  DISTINCT  terms FROM ".$prefix."sales_orders AS a,".$prefix."payment_terms AS b WHERE a.payment_terms=b.terms_indicator AND a.payment_terms=$salesperson";
$resultType=mysqli_query($linkid,$query);
$salesData=mysqli_fetch_array($resultType);
$salesman=$salesData['terms'];

$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);


////to get sales person///////////////////////////////
$query="SELECT salesman_name FROM ".$prefix."salesman WHERE salesman_code=$personid";
//echo $query;exit;
$result=mysqli_query($linkid,$query);
$getPerson=mysqli_fetch_row($result);
$salesname=$getPerson[0];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>&nbsp;&nbsp;&nbsp;MONERY RECEIPT</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>
<!--<p  style="vertical-align:top; font-weight:bold" align="left">ORDER CONFIRMATION</p>-->
<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><?php echo "Premium-MR-".$mrno;?></strong>&nbsp;&nbsp;&nbsp;</td>
               <td width="65%" style="padding-left:80px;"> <strong>Date :</strong> <?php echo $deliverydate;?></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['phone'];?></td>
              </tr>
               <tr>
                <td colspan="3">&nbsp;</td>
              </tr>
              <tr>
                <td><strong>Sales Person</strong></td>
                <td>:</td>
                <td><?php echo $salesname;?></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="6" cellspacing="6">
              <tr>
                <th align="left"><strong>Description </strong></th>
                <th align="right"><strong>Amount(Tk.)</strong></th>
              </tr>
              <tr>
                <td align="left" valign="top">Received with thanks as part/full payment against
				<p>Profit Center Day Collection  SSC01</p>
				<p>Profit Center Customer  :SSC01</p>
				<p>Order/Bill No :RETAIL</p>
				</td>
                <td align="right" valign="top"><?php echo number_format($getdata[8],2);?></td>
              </tr>
			   <tr>
                <td align="left" valign="top">Mode of Payment  : <?php 
				if($getdata[3]!="") 
				echo "CASH: ".$getdata[3].", ";
				if($getdata[4]!="")
				echo "CHEQUE: ".$getdata[4]."#".$getdata[5].", ";
				if($getdata[6]!="")
				echo "CARD: ".$getdata[6]."#".$getdata[7]."# ".strtoupper($salesname);
				//echo "Salesman:".strtoupper($salesname);
				?> </td>
                <td align="right" valign="top"></td>
              </tr>
			   <tr>
                <td align="left" valign="top">Notes : <?php echo $getdata[10];?> </td>
                <td align="right" valign="top"></td>
              </tr>
			             
              <tr>
                <td align="right"><b>Total</b></td>
                <td align="right"><strong><?php echo number_format($getdata[8],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 =$getdata[8];
			 $test = convertNumber($num);
			 echo ucwords($test)." Only";?>
          </td>
        </tr>
        <tr>
          <td colspan="2" valign="top"><table width="100%" border="0">
              <tr>
                <td colspan="2" valign="top">
                  <strong>Terms & Conditions</strong> :  This receipt is valid subject to realization of the cheque/DD/Payorder.</td>
              </tr>
              <tr>
                <td colspan="2"><table width="100%" border="0">
                    <tr>                      
                      <td align="right"><br>
                        ....................................................<br>
                        <strong>Approved by: </strong></td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>