<?php extract($_POST);
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Sales Order');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['Cancel']!='')
{
	unset($_SESSION['branch']);
	unset($_SESSION['orderDate']);
	unset($_SESSION['orderNo']);
	unset($_SESSION['orderType']);
	unset($_SESSION['voucherPrefix']);
	unset($_SESSION['voucherDigit']);
	unset($_SESSION['client']);
	unset($_SESSION['Transporter']);
	unset($_SESSION['salesMan']);
	unset($_SESSION['creditDays']);
	unset($_SESSION['expiry']);
	unset($_SESSION['voucherNo']);
	unset($_SESSION['FinalFGArray']);
}
$rurl="&modid=".$modid."&frmid=".$frmid;
if($_REQUEST['Save']!='')
{
	
	
	 $updatesql1="Update salesorder set 
						 
						paymentTerms='".$_REQUEST['paymentTerms']."',   
						deliveryTerms='".$_REQUEST['deliveryTerms']."',              
						otherTerm1='".$_REQUEST['otherTerm1']."',   
						otherTerm2='".$_REQUEST['otherTerm2']."',   
						narration='".$_REQUEST['narration']."',   
						advance='".$_REQUEST['advance']."',   
						totalqty='".$_REQUEST['totalQuantity']."',   
						basicAmount='".$_REQUEST['basicAmount']."',   
						exciseDuty='".$_REQUEST['excisePerc']."',   
						exciseValue='".$_REQUEST['exciseValue']."',   
						ECessPercentage='".$_REQUEST['C_CessPerc']."',   
						ECessValue='".$_REQUEST['C_CessValue']."',   
						SAHCessPercentage='".$_REQUEST['H_CessPerc']."',   
						SAHCessValue='".$_REQUEST['H_CessValue']."',   
						taxableAmount='".$_REQUEST['taxableAmount']."',   
						VatCst='".$_REQUEST['salesTax']."',   
						VatCstValue='".$_REQUEST['taxRate']."',   
						totalTaxAmount='".$_REQUEST['totalTaxAmount']."',   
						freightValue='".$_REQUEST['freight']."',   
						roundOff='".$_REQUEST['roundOff']."',   
						grandTotal='".$_REQUEST['grandTotal']."' where id='".$_REQUEST['EditID']."' ";
	$updateResult1=DB_query($updatesql1,$db);
	//echo "<pre>";
	//print_r($updatesql1); exit;
	for($ST=0;$ST<$_REQUEST['countItems'];$ST++)
	{
	$checkSQL="Select * from salesorder_details where masterId='".$_REQUEST['EditID']."' and ItemCode='".$_REQUEST['ItemCode'][$ST]."'";
	$checkResult=DB_query($checkSQL,$db);
		if(DB_num_rows($checkResult)>0)
		{
			$updateProduct="Update salesorder_details set 
										BillingDesc='".$_REQUEST['BillingDesc'][$ST]."',             
										Quantity='".$_REQUEST['Quantity'][$ST]."',        
										Rate='".$_REQUEST['Rate'][$ST]."',  
										unit = '".$_REQUEST['unit'][$ST]."',         
										Amount='".$_REQUEST['Amount'][$ST]."' 
										where masterId='".$_REQUEST['EditID']."' and ItemCode='".$_REQUEST['ItemCode'][$ST]."'";
			$Productresult1=DB_query($updateProduct,$db);
			//echo "<pre>";
			//print_r($updateProduct);
		}
		else
		{
			$insertProduct="Insert into salesorder_details set 
										masterId='".$_REQUEST['EditID']."',   
										ItemCode='".$_REQUEST['ItemCode'][$ST]."',    
										BillingDesc='".$_REQUEST['BillingDesc'][$ST]."',          
										Quantity='".$_REQUEST['Quantity'][$ST]."',     
										Rate= '".$_REQUEST['Rate'][$ST]."',  
										unit = '".$_REQUEST['unit'][$ST]."',   
										Amount='".$_REQUEST['Amount'][$ST]."'";
			$Productresult2=DB_query($insertProduct,$db);
			//echo "<pre>";
			//print_r($insertProduct);
		}
	}

	unset($_SESSION['branch']);
	unset($_SESSION['orderDate']);
	unset($_SESSION['orderNo']);
	unset($_SESSION['orderType']);
	unset($_SESSION['voucherPrefix']);
	unset($_SESSION['voucherDigit']);
	unset($_SESSION['client']);
	unset($_SESSION['Transporter']);
	unset($_SESSION['salesMan']);
	unset($_SESSION['creditDays']);
	unset($_SESSION['expiry']);
	unset($_SESSION['voucherNo']);
	unset($_SESSION['Items']);
	unset($_SESSION['FinalFGArray']);
$s->pageLocation("index.php?route=SalesOrderList&daction=Updated".$rurl);
}
?>

<?php 
$sql1="Select * from salesorder where id='".$_REQUEST['EditID']."'";
$query=DB_query($sql1,$db);
$result1=DB_fetch_array($query);
?>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
		  	<td align="center" height="30" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong><?php echo $title;?></strong></div></td>
    </tr>
	<tr><td></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"><strong>Branch</strong></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 loccode,locationname from locations ",$db);
            while($site_row=DB_fetch_array($site_sql)){
            	$k='';
				if($site_row['loccode']=$result1['branch'])
				{
				$k="Selected";	
				}
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo  $k; ?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="24%" align="left"><strong>Order No.</strong></th>
                    <td width="27%"><div id="orderid"><input type="text" name="orderNo" id="orderNo" value="<?php echo $result1['orderNo'];?>" size="6"  style="width:100%;">
                    </div></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Order Date</strong></th>
                    <td><input type="text" name="orderDate" id="orderDate" value="<?php echo $result1['orderDate']; ?>" class="datepicker" style="width:100%;"/></td>
                    <th align="left"><strong>Customer PO Ref. No.</strong></th>
                    <td><input type="text" name="PORefNo" id="PORefNo" style="width:100%;" value="<?php echo $result1['PORefNo'];?>" /></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Customer PO Date</strong></th>
                    <td><input type="text" name="customerPODate" id="customerPODate" value="<?php echo $result1['customerPODate']; ?>" class="datepicker"  style="width:100%;"/></td>
                    <th align="left"><strong>Ammendment Date</strong></th>
                    <td><input type="text" name="ammendmentDate" id="ammendmentDate" value="<?php echo $result1['ammendmentDate'];?>" class="datepicker" style="width:100%;"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Order Received</strong></th>
                    <td><select name="orderReceived" id="orderReceived" style="width:100%;">
                      <option value="000">---Select---</option>
                      <option value="MO" <?php echo($result1['orderReceived']=='MO'?'selected':'')?>>Material Order</option>
                      <option value="EO" <?php echo($result1['orderReceived']=='EO'?'selected':'')?>>Export Order</option>
                      <option value="RO" <?php echo($result1['orderReceived']=='RO'?'selected':'')?>>Retail Order</option>
                      <option value="SO" <?php echo($result1['orderReceived']=='SO'?'selected':'')?>>Service Order</option>
                      <option value="CO" <?php echo($result1['orderReceived']=='CO'?'selected':'')?>>CT3 Order</option>
                      </select></td>
                    <th align="left"><strong>Order Type</strong></th>
                    <td><select name="orderType" id="orderType" style="width:100%">
                      <option value="000">---Select---</option>
                      <option value="P" <?php echo($result1['orderType']=='P'?'selected':'')?>>Process Order</option>
                      <option value="O" <?php echo($result1['orderType']=='O'?'selected':'')?>>Open Order</option>
                      <option value="PS" <?php echo($result1['orderType']=='PS'?'selected':'')?>>Process Order Schedule</option>
                      <option value="OS" <?php echo($result1['orderType']=='OS'?'selected':'')?>>Open Order Schedule</option>
                    </select></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Party Name </strong></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 id,client_code, c_name from clientmaster",$db);
                    while($c_row=DB_fetch_array($c_sql)){
                    	$tt='';
						if($c_row['client_code']==$result1['client'])
						{
						$tt="selected";	
						}
                    ?>
                      <option value="<?php echo $c_row['client_code'];?>"<?php echo  $tt; ?>><?php echo $c_row['c_name'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left"><strong>Salesman</strong></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)){
                    	$ttt='';
						if($sales_row['id']==$reslult1['salesMan'])
						{
						$ttt="selected";	
						}
                    ?>
                      <option value="<?php echo $sales_row['id'];?>"<?php echo $ttt; ?>><?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"><strong>Against Quotation</strong></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))
                {
                $t1='';
				if($eng_row['id']==$result1['quoteNo'])
				{
				$t1="selected";	
				}	
                	?>
                      <option value="<?php echo $enq_row['id'];?>"<?php echo $t1; ?>><?php echo $enq_row['quotationNo'];?></option>	
                      <?php 	
                }
                ?>
                      </select></td>
                       <th width="24%" rowspan="3" align="left" nowrap="nowrap"><strong>Address</strong></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 $result1['validTill'];?>" 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"><strong>Send to PPC</strong></th>
               <td nowrap="nowrap" width="28%">
                 <select name="PPC" style="width:100%;" onchange="showEnqDetails(this.value)">
                  <option value="Yes"<?php echo( $result1['PPC']=='Yes'?'selected':'')?>>Yes</option>
                   <option value="No"<?php echo( $result1['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>
     
      </form>
        </td>
    </tr>
	<tr>
	<td>&nbsp;</td>
	</tr>
	<form action="" method="post">	
	
    </tr>
	<tr><!-- c6c6c6 -->
			<td valign="top" bgcolor="#c6c6c6"><div align="center"><div style="overflow: auto; width:90% ; height: 150px">
			<table width="100%" border="0" cellspacing="2" cellpadding="2">
              <tr>
                <th align="center"><strong>S.No</strong></th>
				<th align="center"><strong>Item Code </strong></th>
                <th align="center"><strong>Item Name </strong></th>
				 <th align="center"><strong>Unit</strong></th>
				<th align="center"><strong>Billing Description </strong></th>
                <th align="center"><strong>Quantity</strong></th>
                <th align="center"><strong>Price</strong></th>
                <th align="center"><strong>Per Unit(s)</strong></th>
                <th align="center"><strong>Value</strong></th>
                <th align="center"><strong>Discount Type</strong></th>
				<th align="center"><strong>Discount</strong></th>
				<th align="center"><strong>Discounted Price</strong></th>
				<th align="center"><strong>Date Of Requisition</strong></th>
              </tr>
			  <?php		
			  	$details_sql=DB_query("Select * from salesorder_details where masterId='".$result1['id']."'",$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><strong><?php echo $k+1;?></strong></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 type="text" value="<?php echo $item_row['item_name'];?>" size="30" readonly /></td>
					<td><input type="text"  value="<?php echo $details_row['Quantity'];?>" readonly /></td>
					<td align="right"><input type="text"  value="<?php echo $details_row['Rate'];?>" readonly /></td>
					<td><input type="text" name="pricePer[<?php echo $k;?>]" id="pricePer_<?php echo $k;?>" value="<?php echo $details_row['pricePer'];?>" readonly/></td>
					<td align="right"><input type="text" value="<?php echo $details_row['Amount'];?>"   readonly/></td>
					<td><?php 
					if($details_row['DiscountType']=='A'){echo "Amount";}else{echo "Percentage";}?></td>
					<td><input type="text" value="<?php echo $details_row['Discount'];?>"readonly /></td> 
					<td><input type="text" value="<?php echo $details_row['valAfterDisc'];?>" readonly/></td>
					<td><input type="text" value="<?php echo $details_row['reqDate'];?>"  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"><strong>Freight</strong></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"><strong>Against Payment</strong></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"><strong>Dispatch To</strong></th>
    <td><input type="text" name="dispatchTo" id="dispatchTo" value="" size=""  style="width:100%;" /></td>  
    </tr>
</table></td>
<td width="40%" valign="top">

<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 $result1['basicAmount'];?>" size="25" style="width:98%;" onfocus="calculateBasic()" id="basicAmount"  /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th nowrap="nowrap">Discounted Price</th>
    	    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $result1['totalDiscountedPrice']?>" size="25" style="width:98%;"   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 ",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{
				$ex='';
				if($excise_row['id']==$result1['exciseDuty'])
				{
				$ex="selected";	
				}
				?>
				<option value="<?php echo $excise_row['id'];?>"<?php echo $ex; ?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select><div id="exciseId"><input name="exciseValue" id="exciseValue" type="text" value="<?php echo $result1['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%;"  />
    	    	<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $result1['ECessValue'];?>" size="25" style="width:75%;"  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%;" />
    	    	<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $result1['SAHCessValue'];?>" size="25" style="width:75%;"  onfocus="calculateSAHCess()"/></td>
  	    	</tr>
    	  
    	  
   <tr>
   	<th>Taxable Amount</th>
   	<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $result1['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",$db);
			while($salesRow=DB_fetch_array($salesSql))
			{
			$taz='';
			if($salesRow['salestax_id']==$result1['VatCst'])	
			{
			$taz="selected";	
			}
				?>
				<option value="<?php echo $salesRow['salestax_id'];?>"<?php echo $taz; ?>><?php echo $salesRow['tax_code'];?></option>
			<?php 	
			}
    	    ?>
  	      </select>
    	      <div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $result1['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 $result1['freightValue'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Pkg Charges</th>
    	    <td><input name="packagingCharges" id="value1" type="text" value="<?php echo $result1['packagingCharges'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
  	    <tr>
    	    <th>Additional Charges</th>
    	    <td><input name="additionalCharges" id="value4" type="text" value="<?php echo $result1['additionalCharges'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Round Off</th>
    	    <td><input name="roundOff" type="text" value="<?php echo $result1['roundOff'];?>" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Grand Total</th>
    	    <td><input name="grandTotal" id="grandTotal" type="text" value="<?php echo $result1['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>
<script language="javascript" type="text/javascript">
function item_window()
{
	window.open("SelectSalesItems.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&EditID=<?php echo $_REQUEST['EditID'];?>&action=edit","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 total=parseFloat(qty)*parseFloat(Rate);
	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 getCreditDays(str)
{
	if (str.length==0)
  {
  document.getElementById("creditId").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("creditId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ClientCreditDays.php?q="+str,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 calculatePaymentDate()
{
	var startdate=document.getElementById("orderDate").value;
	var days=document.getElementById("creditDays").value;
	
	$breakDate=startdate.split('/');
	
	var date=$breakDate[0];
	var month=$breakDate[1];
	var year=$breakDate[2];
	
	alert(date);
	alert(month);
	alert(year);
	
	 startdate = month+"/"+date+"/"+year;
	alert(startdate);
	
	var d=startdate.getDate(); alert(d);	
}
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>
<?php
include('includes/footer.inc');
?>