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


$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,b.notes,order_type FROM ".$prefix."sales_orders AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no AND a.trans_type='32'  AND  a.order_no=$orderno";
///echo $query;exit;
$resultType=mysqli_query($linkid,$query);
$orderData=mysqli_fetch_array($resultType);
$debtor=$orderData['debtor_no'];
$salesperson=$orderData['payment_terms'];

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

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

$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 id FROM ".$prefix."sales_order_details AS a,".$prefix."stock_master AS b WHERE a.stk_code=b.stock_id  AND a.trans_type='32' AND a.order_no=$orderno";
$result=mysqli_query($linkid,$query);
$getCount=mysqli_num_rows($result);

if($getCount > 10){
$query="SELECT stk_code,unit_price,quantity,discount_percent AS discount,long_description FROM ".$prefix."sales_order_details AS a,".$prefix."stock_master AS b WHERE a.stk_code=b.stock_id AND a.trans_type='32' AND a.order_no=$orderno LIMIT 0,10";
//echo $query;exit;
$resultOrder=mysqli_query($linkid,$query);
$resultDiscount=mysqli_query($linkid,$query);
$getDiscount=mysqli_fetch_row($resultDiscount);


$query="SELECT stk_code,unit_price,quantity,discount_percent AS discount,long_description FROM ".$prefix."sales_order_details AS a,".$prefix."stock_master AS b WHERE a.stk_code=b.stock_id AND a.trans_type='32'  AND a.order_no=$orderno LIMIT 10,50";
//echo $query;exit;
$resultOrder2=mysqli_query($linkid,$query);
$resultDiscount2=mysqli_query($linkid,$query);
$getDiscount2=mysqli_fetch_row($resultDiscount2);
}

elseif($getCount <= 10){
$query="SELECT stk_code,unit_price,quantity,discount_percent AS discount,long_description FROM ".$prefix."sales_order_details AS a,".$prefix."stock_master AS b WHERE a.stk_code=b.stock_id AND a.trans_type='32' AND a.order_no=$orderno LIMIT 0,10";
//echo $query;exit;
$resultOrder=mysqli_query($linkid,$query);
$resultDiscount=mysqli_query($linkid,$query);
$getDiscount=mysqli_fetch_row($resultDiscount);
}


?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>&nbsp;&nbsp;&nbsp;Quotation</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="80%" align="left"><table width="100%" border="0" align="left">
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
			  <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="2">
				
				To,<br/>
				<?php echo $orderData['name'];?><br/>
				<?php echo $orderData['address'];?><br/>
				<?php echo $orderData['phone'];?><br/>
				Order reference:No: MSCORP-<?php echo $orderData['reference'];?><br/>
				Sales Person:<?php echo $salesman;?> <br/>
				
				<br>
				<br>
				<p><strong>Subject: Price Quotation</strong></p>
				<p>Dear Sir,<p>
				<p>We are pleased to submit the following quotation in response of your recent inquiry by the instruction of the Top Management.</p>
				</td>
              </tr>
			  
		    </table></td>
          <td width="40%" align="right">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2" width="100%" valign="top" style="height:100%;min-height:280px; margin-bottom:6px position:relative;">
		  <table width="100%" cellpadding="6" cellspacing="6" border="1">
              <tr style=padding:8px;background-color:#54ccae>
                <th width="5%" align="center">SL.</th>
                <th width="37%" align="left"><strong>Description Of Item</strong></th>
				<th width="12%" align="center"><strong>Rate</strong></th>
				<th width="12%" align="center"><strong>Qty.</strong></th>
				<?php if($getDiscount[3] > 0){?>
				<th width="6%" align="center"><strong>Disc.</strong></th>
				<?php
				}
				?>				
                <th width="15%" align="right"><strong>Payable Amount(Tk.)</strong></th>
              </tr>
			  <?php

			  if($resultOrder)

			  { $i=0;

			  while($mydata=mysqli_fetch_assoc($resultOrder))
			  {		  
			  $i+=1;
			   $netorder=$mydata['unit_price'] * $mydata['quantity'];
			   $discount= $netorder * $mydata['discount'];
			   $totalOrder=$netorder-$discount;		   
				
			  ?>
              <tr style="line-height:10px;">
                <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 align="center" valign="top" ><?php echo $mydata['unit_price'];?></td>
                <td align="center" valign="top" ><?php echo $mydata['quantity'];?></td>
				<?php if($getDiscount[3] > 0){?>
				<td align="center" valign="top" ><?php echo $mydata['discount']*100;?>%</td>
				<?php
				}
				?>	
			    <td align="right"  valign="top"><?php echo number_format($totalOrder,2);?></td>
              </tr>
              <?php

			  }

			  }

			  ?>
			  <?php if($getCount < 10){?>
              <tr>
                <?php if($getDiscount[3] > 0) {?>
				<td align="right" colspan="5"><b>Total Amount</b></td>
				 <?php
				 }else{
				 ?>
				<td align="right" colspan="4"><b>Grand Total</b></td>
				<?php 
				}
				?>
                <td align="right"><strong><?php echo number_format($orderData['total'],2);?></strong></td>
              </tr>
              <tr>
			    <?php if($getDiscount[3] > 0){?>
                <td align="right" colspan="5"><b>Total Amount</b></td>
				<?php 
				}else{
				?>
				<td align="right" colspan="4"><b>Grand Amount</b></td>
				<?php 
				}
				?>
                <td align="right"><strong><?php echo number_format($orderData['total'],2);?></strong></td>
              </tr>
			  <?php
			  }
			  ?>
            </table></td>
        </tr>
     <?php if($getCount < 10){?>	 
	    <tr>
          <td colspan="2" align="left"><b>In Words :</b>
            <?php  $num =$orderData['total'];
			 $test = convertNumber($num);
			 echo ucwords($test)." Only";?>
          </td>
        </tr>
		<?php }?>
        <tr>
          <td colspan="2" valign="top"><table width="100%" border="0">
             
              <tr>
                <td colspan="2" valign="top">
                  <strong>Terms & Conditions</strong> : 
				 <ul> 
<li>Price: The above price has been quoted in Excluded  VAT </li>
<li>Validity: 30 days.		</li>
<li>Mode of Payment: Cash/Cheque / Credit Card. 	</li>
<li>Delivery Period: 15 Working days after receiving of formal Work Order.</li>
 In case of any interruption in normal activities due to unforeseen incident,
the company reserve the right to change the delivery schedule with prior intimation to the customer.</li>
<li>Delivery Location: Customer point / site (has to mention as per clients required address).</li>
<li>Terms of Payment: 100% along with the order, rest of the amount paid before delivery of goods.
If paid cheque, subject to realization of the cheque</li>
<li>One year for any manufacturing defect	</li>
</ul>
Looking forward for receiving the approval and formal work order. <br/><br/>
Sincerely,
		

				  
				  </td>
              </tr>
			  <?php if($getCount < 10){?>
              <tr>
                <td colspan="2" valign="top"><table width="100%" border="0">
                    <tr>
                      <td><br>
                        ....................................................<br>
                        <strong>Prepared by</strong></td>
                      <td align="center"></td>
                      <td align="center"></td>
                    </tr>
                  </table></td>
              </tr>
			  <?php }?>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
&nbsp;
<?php if($getCount > 10){?>
<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="80%" align="left"><table width="100%" border="0" align="left">
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
			  <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="2">
				
				To,<br/>
				<?php echo $orderData['name'];?><br/>
				<?php echo $orderData['address'];?><br/>
				<?php echo $orderData['phone'];?><br/>
				Order reference:No: MSCORP-<?php echo $orderData['reference'];?><br/>
				Sales Person:<?php echo $salesman;?> <br/>
				
				<br>
				<br>
				<p><strong>Subject: Price Quotation</strong></p>
				<p>Dear Sir,<p>
				<p>We are pleased to submit the following quotation in response of your recent inquiry by the instruction of the Top Management.</p>
				</td>
              </tr>
			  
		    </table></td>
          <td width="40%" align="right">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2" width="100%" valign="top" style="height:100%;min-height:280px; margin-bottom:6px position:relative;">
		  <table width="100%" cellpadding="6" cellspacing="6" border="1">
              <tr style=padding:8px;background-color:#54ccae>
                <th width="5%" align="center">SL.</th>
                <th width="37%" align="left"><strong>Description Of Item</strong></th>
				<th width="12%" align="center"><strong>Rate</strong></th>
				<th width="12%" align="center"><strong>Qty.</strong></th>
				<?php if($getDiscount[3] > 0){?>
				<th width="6%" align="center"><strong>Disc.</strong></th>
				<?php
				}
				?>				
                <th width="15%" align="right"><strong>Payable Amount(Tk.)</strong></th>
              </tr>
			  <?php

			  if($resultOrder)

			  { $i=0;

			  while($mydata=mysqli_fetch_assoc($resultOrder))
			  {		  
			  $i+=1;
			   $netorder=$mydata['unit_price'] * $mydata['quantity'];
			   $discount= $netorder * $mydata['discount'];
			   $totalOrder=$netorder-$discount;		   
				
			  ?>
              <tr style="line-height:10px;">
                <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 align="center" valign="top" ><?php echo $mydata['unit_price'];?></td>
                <td align="center" valign="top" ><?php echo $mydata['quantity'];?></td>
				<?php if($getDiscount[3] > 0){?>
				<td align="center" valign="top" ><?php echo $mydata['discount']*100;?>%</td>
				<?php
				}
				?>	
			    <td align="right"  valign="top"><?php echo number_format($totalOrder,2);?></td>
              </tr>
              <?php

			  }

			  }

			  ?>
			  <?php if($getCount < 10){?>
              <tr>
                <?php if($getDiscount[3] > 0) {?>
				<td align="right" colspan="5"><b>Total Amount</b></td>
				 <?php
				 }else{
				 ?>
				<td align="right" colspan="4"><b>Grand Total</b></td>
				<?php 
				}
				?>
                <td align="right"><strong><?php echo number_format($orderData['total'],2);?></strong></td>
              </tr>
              <tr>
			    <?php if($getDiscount[3] > 0){?>
                <td align="right" colspan="5"><b>Total Amount</b></td>
				<?php 
				}else{
				?>
				<td align="right" colspan="4"><b>Grand Amount</b></td>
				<?php 
				}
				?>
                <td align="right"><strong><?php echo number_format($orderData['total'],2);?></strong></td>
              </tr>
			  <?php
			  }
			  ?>
            </table></td>
        </tr>
     <?php if($getCount < 10){?>	 
	    <tr>
          <td colspan="2" align="left"><b>In Words :</b>
            <?php  $num =$orderData['total'];
			 $test = convertNumber($num);
			 echo ucwords($test)." Only";?>
          </td>
        </tr>
		<?php }?>
        <tr>
          <td colspan="2" valign="top"><table width="100%" border="0">
             
              <tr>
                <td colspan="2" valign="top">
                  <strong>Terms & Conditions</strong> : 
				 <ul> 
<li>Price: The above price has been quoted in Excluded  VAT </li>
<li>Validity: 30 days.		</li>
<li>Mode of Payment: Cash/Cheque / Credit Card. 	</li>
<li>Delivery Period: 15 Working days after receiving of formal Work Order.</li>
 In case of any interruption in normal activities due to unforeseen incident,
the company reserve the right to change the delivery schedule with prior intimation to the customer.</li>
<li>Delivery Location: Customer point / site (has to mention as per clients required address).</li>
<li>Terms of Payment: 100% along with the order, rest of the amount paid before delivery of goods.
If paid cheque, subject to realization of the cheque</li>
<li>One year for any manufacturing defect	</li>
</ul>
Looking forward for receiving the approval and formal work order. <br/><br/>
Sincerely,
		

				  
				  </td>
              </tr>
			  <?php if($getCount < 10){?>
              <tr>
                <td colspan="2" valign="top"><table width="100%" border="0">
                    <tr>
                      <td><br>
                        ....................................................<br>
                        <strong>Prepared by</strong></td>
                      <td align="center"></td>
                      <td align="center"></td>
                    </tr>
                  </table></td>
              </tr>
			  <?php }?>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<?php 
}
?>
</body>
</html>
