<?php extract($_POST);
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Sales Order');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['Cancel']!='')
{
	unset($_REQUEST);
}

if($_REQUEST['Save'])
{
$fstatus=true;
  if($_REQUEST['branch ']=='000')
  {
  	  $msgErr[]="Please Select Branch Name"	;
      $fstatus=false;
  }
  if($_REQUEST['orderNo1']=='')
  {
  	  $msgErr[]="Please Enter Order no"	;
      $fstatus=false;
  }	
	 
   if($_REQUEST['orderType']=='000')
  {
  	  $msgErr[]="Please Select Order Type"	;
      $fstatus=false;
  }
   if($_REQUEST['orderReceived']=='000')
  {
  	  $msgErr[]="Please Select Order Received"	;
      $fstatus=false;
  }
   if($_REQUEST['client']=='000')
  {
  	  $msgErr[]="Please Select Party Name"	;
      $fstatus=false;
  }
  if($_REQUEST['quoteNumber']=='0')
  {
  	  $msgErr[]="Please Select Order No";
      $fstatus=false;
  }
  for($K=0;$K<$_REQUEST['countItems'];$K++)
  {
  	if($_REQUEST['ItemCode'][$k]=='0')
  {
  	  $msgErr[]="Please Enter Item Code".$k;
      $fstatus=false;
  }
  if($_REQUEST['Quantity'][$k]=='0')
  {
  	  $msgErr[]="Please Enter Quantity".$k;
      $fstatus=false;
  }
  if($_REQUEST['Rate'][$k]=='0')
  {
  	  $msgErr[]="Please Enter Rate".$k;
      $fstatus=false;
  }
  if($_REQUEST['Discount'][$k]=='0')
  {
  	  $msgErr[]="Please Enter Discount".$k;
      $fstatus=false;
  }
	
  }
  
  
}
  

if($_REQUEST['Save']!='' and $fstatus)
{
	$sql1="Insert into salesorder set
					branch='".$_REQUEST['branch1']."', 
					orderNo='".$_REQUEST['orderNo1']."',      
					orderDate='".FormatDateForSQL($_REQUEST['orderDate1'])."',  
					PORefNo='".$_REQUEST['PORefNo1']."',  
					customerPODate='".FormatDateForSQL($_REQUEST['customerPODate1'])."',  
					ammendmentDate='".FormatDateForSQL($_REQUEST['ammendmentDate1'])."',  
					orderReceived='".$_REQUEST['orderReceived1']."',  
					orderType='".$_REQUEST['orderType1']."',  
					client='".$_REQUEST['client1']."',  
					salesMan='".$_REQUEST['salesMan1']."',  
					quoteNo='".$_REQUEST['quoteNo1']."',  
					validTill='".FormatDateForSQL($_REQUEST['validTill1'])."',  
					PPC='".$_REQUEST['PPC1']."',     
					freightStatus='".$_REQUEST['freightStatus']."',  
					paymentAgainst='".$_REQUEST['paymentAgainst']."',  
					dispatchTo='".$_REQUEST['dispatchTo']."',  
					basicAmount='".$_REQUEST['basicAmount']."',  
					totalDiscountedPrice='".$_REQUEST['totalDiscountedPrice']."',  
					exciseDuty='".$_REQUEST['exciseDuty']."',  
					exciseValue='".$_REQUEST['exciseValue']."',  
					ECessPercentage='".$_REQUEST['ECessPercentage']."',  
					ECessValue='".$_REQUEST['ECessValue']."',  
					SAHCessPercentage='".$_REQUEST['SAHCessPercentage']."',  
					SAHCessValue='".$_REQUEST['SAHCessValue']."',  
					taxableAmount='".$_REQUEST['taxableAmount']."',  
					VatCst='".$_REQUEST['VatCst']."',  
					VatCstValue='".$_REQUEST['VatCstValue']."', 
					freightValue='".$_REQUEST['freightValue']."',  
					packagingCharges='".$_REQUEST['packagingCharges']."',  
					additionalCharges='".$_REQUEST['additionalCharges']."',  
					roundOff='".$_REQUEST['roundOff']."',  
					grandTotal='".$_REQUEST['grandTotal']."',  
					createdBy='".$_SESSION['UserID']."',  
					createdDate='".date('Y-m-d')."' ,
					CompanyId='".$_SESSION['ACGCompanyId']."' ";
					
	$result1=DB_query($sql1,$db);
	

	$masterId=DB_Last_Insert_ID($db,'salesorder','id');
	if(isset($masterId))
	{
		for($K=0;$K<$_REQUEST['countItems'];$K++)
		{
			$sql2="Insert into salesorder_details set 
							masterId='".$masterId."',  
							
							ItemCode='".$_REQUEST['ItemCode'][$K]."',   
							
							BillingDesc='".$_REQUEST['BillingDesc'][$K]."',
							unit='".$_REQUEST['unit'][$K]."',        
							Quantity='".$_REQUEST['Quantity'][$K]."',      
							Rate='".$_REQUEST['Rate'][$K]."',  
							pricePer='".$_REQUEST['pricePer'][$K]."',
 							Amount='".$_REQUEST['Amount'][$K]."',
 							DiscountType='".$_REQUEST['DiscountType'][$K]."',  
 							Discount='".$_REQUEST['Discount'][$K]."',  
 							valAfterDisc='".$_REQUEST['valAfterDisc'][$K]."',  
 							reqDate='".$_REQUEST['reqDate'][$K]."'  ";
			$result2=DB_query($sql2,$db);
			//echo "<pre>";
			//print_r($sql2);
		}
	}
echo "<script>location.href='index.php?route=SalesOrderList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg( _('Sales Order inserted successfully'),'success');

}
?>
<script language="javascript" type="text/javascript">
function item_window()
{
	window.open("SelectSalesItems.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
	
}
function calculate_totAmount(k)
{
	var qty=document.getElementById("Quantity_"+k).value;
	var Rate=document.getElementById("Rate_"+k).value;
	var rateperthousand=Rate/1000;
	var total=parseFloat(qty)*parseFloat(rateperthousand);
	document.getElementById("Amount_"+k).value=total.toFixed(2);
}
function calculateTotalQty()
{
	var count=document.getElementById("countItems").value;
	var totqty=0;
	for(var str=0;str<count;str++)
	{
		var qty=document.getElementById("Quantity_"+str).value;
		totqty=parseInt(totqty)+parseInt(qty);
	}
	document.getElementById("totalQuantity").value=totqty;
}
function calculateBasicAmt()
{
	var count1=document.getElementById("countItems").value;
	var totamount=0;
	
	for(var st=0;st<count1;st++)
	{
		var amount=document.getElementById("Amount_"+st).value;
		totamount=parseInt(totamount)+parseInt(amount);
	}
	document.getElementById("basicAmount").value=totamount.toFixed(2);
}
function getOrderNo(str)
{
if (str.length==0)
  {
  document.getElementById("orderid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("orderid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","SalesOrderNo.php?q="+str,true);
xmlhttp.send();
}










function getQuotation(str)
{
	var branch=document.getElementById("branch").value;
	if (str.length==0)
  {
  document.getElementById("quoteId").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("quoteId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","SalesOrderNo.php?client="+str+"&branch="+branch,true);
xmlhttp.send();
}










function calculateExcise()
{
	var ordervalue=document.getElementById("basicAmount").value;
	var Epercent=document.getElementById("excisePerc").value;
	var value=ordervalue*(Epercent/100);
	document.getElementById("exciseValue").value=value.toFixed(2);
}

function calculateCCess()
{
	var excise=document.getElementById("exciseValue").value;
	var Cpercent=document.getElementById("C_CessPerc").value;
	var value=excise*(Cpercent/100);
	document.getElementById("C_CessValue").value=value.toFixed(2);
}

function calculateHCess()
{
	var excise=document.getElementById("exciseValue").value;
	var Hpercent=document.getElementById("H_CessPerc").value;
	var value=excise*(Hpercent/100);
	document.getElementById("H_CessValue").value=value.toFixed(2);
}
function calculateTaxable()
{
	var basic=document.getElementById("basicAmount").value;
	var excise=document.getElementById("exciseValue").value;
	var CCess=document.getElementById("C_CessValue").value;
	var HCess=document.getElementById("H_CessValue").value;
	var tottaxable=parseFloat(basic)+parseFloat(excise)+parseFloat(CCess)+parseFloat(HCess);
	document.getElementById("taxableAmount").value=tottaxable.toFixed(2);
}
function GetTaxValue(str)
{
	if (str.length==0)
  {
  document.getElementById("rateId").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("rateId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_val.php?q="+str,true);
xmlhttp.send();
}
function calculateTotalTaxAmt()
{
	var taxRate=document.getElementById("taxRate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var tax=taxableAmount*(taxRate/100);
	document.getElementById("totalTaxAmount").value=tax.toFixed(2);
}
function calculateSurcharge()
{
	var surchargePerc=document.getElementById("surchargePerc").value;
	var totalTaxAmount=document.getElementById("totalTaxAmount").value;
	var surcharge=totalTaxAmount*(surchargePerc/100);
	document.getElementById("surchargeValue").value=surcharge.toFixed(2);
}
function calculateGrandTotal()
{
	var taxableAmount=document.getElementById("taxableAmount").value;
	var totalTaxAmount=document.getElementById("totalTaxAmount").value;
	var freight=document.getElementById("freight").value;
	var surchargeValue=document.getElementById("surchargeValue").value;
	var Grand=parseFloat(taxableAmount)+parseFloat(totalTaxAmount)+parseFloat(freight)+parseFloat(surchargeValue);
	document.getElementById("grandTotal").value=Grand.toFixed(2);
	
}
function calculateECess()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}
function calculateSAHCess()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}
function calculateTaxable()
{
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}
function calculateGrand()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	var d=document.getElementById("value2").value;
	var e=document.getElementById("value1").value;
	var f=document.getElementById("value4").value;
	
	
	if(b==''){b=0;}
	if(c==''){c=0;}
	if(d==''){d=0;}
	if(e==''){e=0;}
	if(f==''){f=0;}
	
	var GRAND=parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	
}
</script>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php if(count($msgErr)>0){?>
   <tr>
   <td colspan="4"><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo "<div class='error'>".$msgErr[$i].'</div>';
   }
    ?></td>
   </tr>
   <?php } ?>
 <tr>
		  	<td align="center" height="30" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><?php echo $title;?></div></td>
    </tr>
	<tr><td><h3 align="center"><font color="#FF0000">*Please fill up the header information before selecting the products</font></h3></td></tr>
    <tr>
        <td>
        <table width="85%" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#ffffff" style="border:1px solid #ccc;">
        <tr>
            <td><div align="center">
                <table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
                  <tr>
                    <th width="21%" align="left">Branch</th>
                    <td width="28%"><select name="branch" id="branch" style="width:100%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            $site_sql=DB_query("Select prefix, loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="24%" align="left">Order No.</th>
                    <td width="27%"><div id="orderid"><input type="text" name="orderNo" id="orderNo" value="<?php echo $_REQUEST['orderNo'];?>" size="6"  style="width:100%;">
                    </div></td>
                  </tr>
                  <tr>
                    <th align="left">Order Date</th>
                    <td><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_REQUEST['orderDate']))echo $_REQUEST['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:100%;"/></td>
                    <th align="left">Customer PO Ref. No.</th>
                    <td><input type="text" name="PORefNo" id="PORefNo" style="width:100%;" value="<?php echo $_REQUEST['PORefNo'];?>" /></td>
                  </tr>
                  <tr>
                    <th align="left">Customer PO Date</th>
                    <td><input type="text" name="customerPODate" id="customerPODate" value="<?php if(isset($_REQUEST['customerPODate']))echo $_REQUEST['customerPODate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:100%;"/></td>
                    <th align="left">Ammendment Date</th>
                    <td><input type="text" name="ammendmentDate" id="ammendmentDate" value="<?php if(isset($_REQUEST['ammendmentDate']))echo $_REQUEST['ammendmentDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:100%;"/></td>
                  </tr>
                  <tr>
                    <th align="left">Order Received</th>
                    <td><select name="orderReceived" id="orderReceived" style="width:100%;">
                      <option value="000">---Select---</option>
                      <option value="MO" <?php echo($_REQUEST['orderReceived']=='MO'?'selected':'')?>>Material Order</option>
                      <option value="EO" <?php echo($_REQUEST['orderReceived']=='EO'?'selected':'')?>>Export Order</option>
                      <option value="RO" <?php echo($_REQUEST['orderReceived']=='RO'?'selected':'')?>>Retail Order</option>
                      <option value="SO" <?php echo($_REQUEST['orderReceived']=='SO'?'selected':'')?>>Service Order</option>
                      <option value="CO" <?php echo($_REQUEST['orderReceived']=='CO'?'selected':'')?>>CT3 Order</option>
                      </select></td>
                    <th align="left">Order Type</th>
                    <td><select name="orderType" id="orderType" style="width:100%">
                      <option value="000">---Select---</option>
                      <option value="P" <?php echo($_REQUEST['orderType']=='P'?'selected':'')?>>Process Order</option>
                      <option value="O" <?php echo($_REQUEST['orderType']=='O'?'selected':'')?>>Open Order</option>
                      <option value="PS" <?php echo($_REQUEST['orderType']=='PS'?'selected':'')?>>Process Order Schedule</option>
                      <option value="OS" <?php echo($_REQUEST['orderType']=='OS'?'selected':'')?>>Open Order Schedule</option>
                    </select></td>
                  </tr>
                  <tr>
                    <th align="left">Party Name </th>
                    <td><select name="client" id="client" style="width:100%;" onchange="getQuotation(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
                    $c_sql=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') 
		and Zone in(".$_SESSION['AssignedSites'].") order by c_name",$db);
                    while($c_row=DB_fetch_array($c_sql)){
                    ?>
                      <option value="<?php echo $c_row['client_code'];?>"<?php echo ($_REQUEST['client']==$c_row['client_code']?'selected':'')?>><?php echo $c_row['c_name'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">Salesman</th>
                    <td><select name="salesMan" id="salesMan" style="width:100%;">
                      <option value="000">---Select---</option>
                      <?php 
                    $sales_sql=DB_query("select id,sales_name from salesman_master",$db);
                    while($sales_row=DB_fetch_array($sales_sql)){
                    ?>
                      <option value="<?php echo $sales_row['id'];?>"<?php echo ($_REQUEST['salesMan']==$sales_row['id']?'selected':'')?>><?php echo $sales_row['sales_name'];?></option>
                      <?php } ?>
                      </select></td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
    <td valign="top">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td colspan="4" id="quoteId">
     
        <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
            <table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr>
                  <th width="21%" align="left" nowrap="nowrap">Against Quotation</th>
                  <td nowrap="nowrap" width="28%">
                <select name="quoteNumber" style="width:100%;">
                      <option value="0">Select</option>
                      <?php 
                 
                 $enq_sql=DB_query("Select id,quotationNo from quotation where party='".$_REQUEST['client']."' and site='".$_REQUEST['branch']."'",$db);
                while($enq_row=DB_fetch_array($enq_sql))
                {?>
                      <option value="<?php echo $enq_row['id'];?>"<?php echo($_REQUEST['quoteNumber']==$enq_row['id']?'selected':'')?>><?php echo $enq_row['quotationNo'];?></option>	
                      <?php 	
                }
                ?>
                      </select></td>
                       <th width="24%" rowspan="3" align="left" nowrap="nowrap">Address</th>
                       <td width="27%"><input name="partyaddress1" type="text" value="<?php echo $_REQUEST['partyaddress1'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
                <tr>
                  <th align="left">Valid Till</th>
                  <td><input name="validTill" type="text" value="<?php if(isset($_REQUEST['validTill'])){echo $_REQUEST['validTill'];} else {echo date('d/m/Y');}?>" size="12" class="datepicker"  style="width:100%;"/></td>
                  <td><input name="partyaddress2" type="text" value="<?php echo $_REQUEST['partyaddress2'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
             <tr>
               <th width="21%" align="left" nowrap="nowrap">Send to PPC</th>
               <td nowrap="nowrap" width="28%">
                 <select name="PPC" style="width:100%;" onchange="showEnqDetails(this.value)">
                  <option value="Yes"<?php echo($_REQUEST['PPC']=='Yes'?'selected':'')?>>Yes</option>
                   <option value="No"<?php echo($_REQUEST['PPC']=='No'?'selected':'')?>>No</option>
                   </select></td>
               <td><input name="partyaddress3" type="text" value="<?php echo $_REQUEST['partyaddress3'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
         </table>
         </div>
        </td>
        </tr>
    </table>
    
    </td>
    </tr>
    </table>
    </td>
    </tr>
      </table>
      <p align="center"><input type="submit" name="Proceed" value="Proceed" /></p>
      </form>
        </td>
    </tr>
	<tr>
	<td>&nbsp;</td>
	</tr>
	<form action="" method="post">	
	<tr>
	
	<td height="8">

	<input type="hidden" name="branch1" id="" value="<?php echo $_REQUEST['branch'];?>" />
	<input type="hidden" name="orderDate1" id="" value="<?php echo $_REQUEST['orderDate'];?>" />
	<input type="hidden" name="orderNo1" id="" value="<?php echo $_REQUEST['orderNo'];?>" />
	<input type="hidden" name="PORefNo1" id="" value="<?php echo $_REQUEST['PORefNo'];?>" />
	<input type="hidden" name="customerPODate1" id="" value="<?php echo $_REQUEST['customerPODate'];?>" />
	<input type="hidden" name="ammendmentDate1" id="" value="<?php echo $_REQUEST['ammendmentDate'];?>" />
	<input type="hidden" name="orderReceived1" id="" value="<?php echo $_REQUEST['orderReceived'];?>" />
	<input type="hidden" name="orderType1" id="" value="<?php echo $_REQUEST['orderType'];?>" />
	<input type="hidden" name="client1" id="" value="<?php echo $_REQUEST['client'];?>" />
	<input type="hidden" name="salesMan1" id="" value="<?php echo $_REQUEST['salesMan'];?>" />
	<input type="hidden" name="quoteNo1" id="" value="<?php echo $_REQUEST['quoteNumber'];?>" />
	<input type="hidden" name="validTill1" id="" value="<?php echo $_REQUEST['validTill'];?>" />
	<input type="hidden" name="PPC1" id="" value="<?php echo $_REQUEST['PPC'];?>" />
	</td>
    </tr>
	<tr><!-- c6c6c6 -->
			<td valign="top" bgcolor="#c6c6c6"><div align="center"><div style="overflow: auto; width: 800px; height: 150px">
			<table width="100%" border="0" cellspacing="2" cellpadding="2">
              <tr>
                <th align="center">S.No</th>
				<th align="center">Item Code </th>
                <th align="center">Item Name </th>
				 <th align="center">Unit</th>
				<th align="center">Billing Description </th>
                <th align="center">Quantity</th>
                <th align="center">Price</th>
                <th align="center">Per Unit(s)</th>
                <th align="center">Value</th>
                <th align="center">Discount Type</th>
				<th align="center">Discount</th>
				<th align="center">Discounted Price</th>
				<th align="center">Date Of Requisition</th>
              </tr>
			  <?php
			  if($_REQUEST['Proceed']!='')
			  { 
			  	$details_sql=DB_query("Select * from quotation_details where parentId='".$_REQUEST['quoteNumber']."'",$db);
				$k=0;
				while($details_row=DB_fetch_array($details_sql))
				{
			  		$item_sql=DB_query("Select item_name,unit from item_master where StockID='".$details_row['itemCode']."'",$db);
			  		$item_row=DB_fetch_array($item_sql);
			  ?>
					  <tr bgcolor="#FFFFFF">
					<td><?php echo $k+1;?></td>
					<td><?php echo $details_row['itemCode'];?><input type="hidden" name="ItemCode[<?php echo $k;?>]" id="ItemCode_<?php echo $k;?>" value="<?php echo $details_row['itemCode'];?>" readonly/></td>
					<td><?php echo $item_row['item_name'];?><input type="hidden" name="ItemDesc[<?php echo $k;?>]" id="ItemDesc_<?php echo $k;?>" value="<?php echo $product_row['item_desc'];?>" readonly/></td>
					<td><?php echo $s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
					$item_row['unit'];?><input type="hidden" name="unit[<?php echo $k;?>]" id="unit_<?php echo $k;?>" value="<?php echo $product_row['unit'];?>" readonly/></td>
					<td><input name="BillingDesc[<?php echo $k;?>]" type="text" id="BillingDesc_<?php echo $k;?>" tabindex="1" value="<?php echo $item_row['item_name'];?>" size="30" /></td>
					<td><input type="text" name="Quantity[<?php echo $k;?>]" id="Quantity_<?php echo $k;?>" value="<?php echo $details_row['quantity'];?>"  readonly/></td>
					<td align="right"><input type="text" name="Rate[<?php echo $k;?>]" id="Rate_<?php echo $k;?>" value="<?php echo $details_row['price'];?>"  readonly/></td>
					<td><input type="text" name="pricePer[<?php echo $k;?>]" id="pricePer_<?php echo $k;?>" value="<?php echo $details_row['PerUnits'];?>" readonly/></td>
					<td align="right"><input type="text" name="Amount[<?php echo $k;?>]" id="Amount_<?php echo $k;?>" value="<?php echo $details_row['totalValue'];?>"   readonly/></td><!-- onfocus="calculate_totAmount(<?php echo $k;?>)" -->
					<td><?php 
					if($details_row['discountType']=='A'){echo "Amount";}else{echo "Percentage";}?><input type="hidden" name="DiscountType[<?php echo $k;?>]" id="DiscountType_<?php echo $k;?>" value="<?php echo $details_row['discountType'];?>" readonly/></td>
					<td><input type="text" name="Discount[<?php echo $k;?>]" id="Discount_<?php echo $k;?>" value="<?php echo $details_row['discount'];?>" readonly/></td> 
					<td><input type="text" name="valAfterDisc[<?php echo $k;?>]" id="valAfterDisc_<?php echo $k;?>" value="<?php echo $details_row['valueAfterDisc'];?>" readonly/></td>
					<td><input type="text" name="reqDate[<?php echo $k;?>]" id="reqDate_<?php echo $k;?>" value="<?php echo $details_row['requisitionDate'];?>" readonly /></td>
					</tr>
			  <?php $k++;} } ?>        

            </table></div></div><input type="hidden" name="countItems" id="countItems" value="<?php echo $k;?>" /></td>
    </tr>
	<tr>
	  <td>&nbsp;</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	</tr>
	<tr>
		<td>
			<table width="85%" border="0" cellpadding="0" cellspacing="0" align="center" >
<tr>
<td valign="top" width="40%"><table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
  <tr>
    <th style="text-align:center;" colspan="2">Terms And Conditions</th>
  </tr>
  <tr>
    <th width="42%" scope="row">Freight</th>
    <td width="58%"><select name="freightStatus" id="freightStatus" style="width: 100%">
      <option value="ToPay">To Pay</option>
      <option value="Payed">Payed</option>
      <option value="Nil">Nil</option>
      </select></td>
  </tr>
  <tr>
    <th scope="row">Against Payment</th>
    <td><select name="paymentAgainst" style="width: 100%">
     <option value="Advance">Advance</option>
     <option value="Cash">Cash</option>
     <option value="Credit">Credit</option>
    </select></td>
  </tr>
  <tr>
    <th scope="row">Dispatch To</th>
    <td><input type="text" name="dispatchTo" id="dispatchTo" value="" size=""  style="width:100%;" /></td>  
    </tr>
</table></td>
<td width="40%" valign="top">
<?php 
$Amount_and_tax=DB_query("Select * from quotation where id='".$_REQUEST['quoteNumber']."'",$db);
$myResult=DB_fetch_array($Amount_and_tax);
?>
<table width="95%" border="0" cellspacing="1" cellpadding="0" align="right" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
    		<tr>
    	<th style="text-align:center;" colspan="2">Amount And Taxes</th>
    </tr>
    <tr>
    	  <tr>
    	    <th width="14%">Basic Amount</th>
    	    <td width="31%"><input name="basicAmount" type="text" value="<?php echo $myResult['basicAmount'];?>" size="25" style="width:98%;" onfocus="calculateBasic()" id="basicAmount" readonly /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th nowrap="nowrap">Discounted Price</th>
    	    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $myResult['totalDiscountedPrice']?>" size="25" style="width:98%;"  readonly onfocus="calculateDiscounted()" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Excise</th>
    	    <td nowrap="nowrap">
    	    <select name="exciseDuty" style="width:98%;" onchange="claculateExcise(this.value)">
    	    <?php 
    	    $excise_sql=DB_query("Select id,caption from excise_tax where id='".$myResult['exciseDuty']."' ",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"<?php echo ($_REQUEST['exciseDuty']==$excise_row['id']?'selected':'')?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select><div id="exciseId"><input name="exciseValue" id="exciseValue" type="text" value="<?php echo $myResult['exciseValue'];?>" size="25" style="width:98%;" /></div>
    	   </tr>
    	     
    	     <?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
    	     <tr>
    	    <th>E-Cess</th>
    	    <td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" size="25" style="width:20%;" readonly />
    	    	<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $myResult['ECessValue'];?>" size="25" style="width:75%;" readonly onfocus="calculateECess()"/></td>
    	    </tr>
    	    <tr>
            <th nowrap="nowrap">SAH-E Cess </th>
    	    <td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" size="25" style="width:20%;" readonly/>
    	    	<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $myResult['SAHCessValue'];?>" size="25" style="width:75%;" readonly onfocus="calculateSAHCess()"/></td>
  	    	</tr>
    	  
    	  
   <tr>
   	<th>Taxable Amount</th>
   	<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $myResult['taxableAmount'];?>" size="25" style="width:98%;" onfocus="calculateTaxable()"/></td>
   </tr>
    	  
    	  
    	  
    	  <tr>
    	    <th>VAT/CST</th>
    	    <td nowrap="nowrap">
    	    <select name="VatCst" id="value3" style="width:98%;" onchange="calculateVATCST(this.value)">
    	    <?php 
    	    $salesSql=DB_query("Select * from sales_tax_master where salestax_id='".$myResult['VatCst']."'",$db);
			while($salesRow=DB_fetch_array($salesSql))
			{?>
				<option value="<?php echo $salesRow['salestax_id'];?>"><?php echo $salesRow['tax_code'];?></option>
			<?php 	
			}
    	    ?>
  	      </select>
    	      <div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $myResult['VatCstValue'];?>" size="25" style="width:98%;" readonly /></div></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Freight</th>
    	    <td><input name="freightValue" id="value2" type="text" value="<?php echo $myResult['freightValue'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Pkg Charges</th>
    	    <td><input name="packagingCharges" id="value1" type="text" value="<?php echo $myResult['packagingCharges'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
  	    <tr>
    	    <th>Additional Charges</th>
    	    <td><input name="additionalCharges" id="value4" type="text" value="<?php echo $myResult['additionalCharges'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Round Off</th>
    	    <td><input name="roundOff" type="text" value="<?php echo $myResult['roundOff'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Grand Total</th>
    	    <td><input name="grandTotal" id="grandTotal" type="text" value="<?php echo $myResult['grandTotal'];?>" size="25" style="width:98%;" onfocus="calculateGrand()" /></td>
    	    
  	    </tr>
  	    </table>
</td>
</tr></table>
      </td>
	</tr>
</table>
<br />
<p align="center">
<input type="submit" name="Save" value="Save"  />
<input type="submit" name="Cancel" value="Cancel" />
</p>
</form>
<?php
include('includes/footer.inc');
?>