<?php
$rurl="&modid=".$modid."&frmid=".$frmid;
if(isset($_POST['Update']))
{
	$select="delete  from quotation_details where status='1' and parentId='".$_REQUEST['id']."'";
	$query=DB_query($select,$db);	
	
  for($cnt=0;$cnt<$_REQUEST['counter'];$cnt++)
		{
	 		    $checkSQL="Select * from quotation_details where parentId='".$_REQUEST['Id']."' and ItemCode='".$_REQUEST['itemCode'][$cnt]."'";
				$checkResult=DB_query($checkSQL,$db);
		if(DB_num_rows($checkResult)>0)
		{				
	 					$insert2="update  quotation_details set
						itemCode='".$_REQUEST['itemCode'][$cnt]."',  
						quantity='".$_REQUEST['quantity'][$cnt]."',   
						price='".$_REQUEST['price'][$cnt]."',
						PerUnits ='".$_REQUEST['PerUnits'][$cnt]."', 
						totalValue='".$_REQUEST['totalValue'][$cnt]."',  
						discountType='".$_REQUEST['discountType'][$cnt]."',  
						discount='".$_REQUEST['discount'][$cnt]."',  
						valueAfterDisc='".$_REQUEST['valueAfterDisc'][$cnt]."',  
						requisitionDate='".$_REQUEST['requisitionDate'][$cnt]."' where id='".$_REQUEST['id'][$cnt]."'";
						$result2=DB_query($insert2,$db);
		}
			else {
					
					   	$insert2="insert into  quotation_details set
										parentId='".$_REQUEST['Id']."',  
										itemCode='".$_REQUEST['itemCode'][$cnt]."',  
										quantity='".$_REQUEST['quantity'][$cnt]."',   
										price='".$_REQUEST['price'][$cnt]."',
										PerUnits ='".$_REQUEST['PerUnits'][$cnt]."', 
										totalValue='".$_REQUEST['totalValue'][$cnt]."',  
										discountType='".$_REQUEST['discountType'][$cnt]."',  
										discount='".$_REQUEST['discount'][$cnt]."', 
										status='0', 
										requisitionDate=now(),
										valueAfterDisc='".$_REQUEST['valueAfterDisc'][$cnt]."'";
										$result2=DB_query($insert2,$db);		
			 }
			
	 $insert2="update  quotation set 
					freight= '".$_REQUEST['freight']."', 
					payTerms='".$_REQUEST['payTerms']."',  
					salesTax='".$_REQUEST['salesTax']."',  
					Excise='".$_REQUEST['Excise']."',  
					insurance='".$_REQUEST['insurance']."',  
					basicAmount='".$_REQUEST['basicAmount']."',  
					totalDiscountedPrice='".$_REQUEST['totalDiscountedPrice']."',  
					exciseDuty='".$_REQUEST['exciseDuty']."',  
					exciseValue='".$_REQUEST['exciseValue']."',  
					ECessValue='".$_REQUEST['ECessValue']."',  
					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']."'  
					where id='".$_REQUEST['Id']."' ";		
					$query1=DB_query($insert2,$db);
		unset($_SESSION['qutotation_itemcode']);
		unset($_SESSION['itemcode']);	
		$s->pageLocation("index.php?route=quotation_list&daction=Updated".$rurl);	
	}
	}
	
	if(isset($_POST['Cancel']))
	{
	$del="update quotation_details set status=0 where parentId='".$_REQUEST['Id']."'"	;
	$query=Db_query($del,$db);	
		unset($_SESSION['qutotation_itemcode']);
		unset($_SESSION['itemcode']);
		echo "<script>location.href='index.php?route=edit_quotation_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&action=edit&Id=".$_REQUEST['Id']."'</script>"; 
	}
	
	if($_REQUEST['act']=='remove' && $_REQUEST['id']!='')
	{
	$del="update quotation_details set status=1 where id='".$_REQUEST['id']."'"	;
	$query=Db_query($del,$db);	
 	echo "<script>location.href='index.php?route=edit_quotation_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&action=edit&Id=".$_REQUEST['Id']."'</script>"; 
	
	
	}
	$sql1=DB_query("Select * from quotation where id='".$_REQUEST['Id']."'",$db);
	$result1=DB_fetch_array($sql1);
	?>
<h2 align="center">Edit Quotation</h2>
<form action="" method="post">	
<input type="hidden" name="reqno" id="reqno" value="<?php echo $result1['enquiryNo'];?>" />
<input type="hidden" name="reqno" id="reqno1" value="<?php echo $_REQUEST['modid'];?>" />
<input type="hidden" name="reqno" id="reqno2" value="<?php echo $_REQUEST['frmid'];?>" />
<input type="hidden" name="reqno" id="reqno3" value="<?php echo $_REQUEST['Id'];?>" />
<table width="80%" cellpadding="0" cellspacing="0" border="0" bgcolor="#FFFFFF" style="border:1px solid #CCC;" align="center">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th width="25%" nowrap="nowrap" scope="row"><strong>Branch</strong></th>
    <td width="25%" nowrap="nowrap">
    <select name="site" style="width:98%;" id="site" onchange="getCode(this.value)">
    <?php 
    $site_sql=DB_query("Select loccode, locationname from locations where loccode='".$result1['site']."'",$db);
    while($site_row=DB_fetch_array($site_sql))
	{?>
		<option value="<?php echo $site_row['loccode']?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
	<?php 	
	}
    ?>
    </select></td>
    <th width="25%"><strong>Quotation No.</strong></th>
    <td width="25%" id="CODE"><input name="quotationNo" type="text" value="<?php echo $result1['quotationNo'];?>" size="25"  style="width:98%;"/></td>
   </tr>
  <tr>
    <th scope="row"><strong>Date </strong></th>
    <td nowrap="nowrap"><input type="text" name="quotationDate" value="<?php echo $result1['quotationDate'];?>" style="width:98%;" /></td>
    <th nowrap="nowrap">Format</th>
    <td nowrap="nowrap"><select name="format" style="width:98%;">
      <option value="Standard">Standard</option>
    </select></td>
  </tr>
  <tr>
    <th nowrap="nowrap"><strong>Party Name</strong></th>
    <td nowrap="nowrap">
    <select name="party" style="width:98%;" onchange="enquiryDetails(this.value)">
      <?php 
      $client_sql=DB_query("Select client_code,c_name from clientmaster where client_code='".$result1['party']."'",$db);
	  while($client_row=DB_fetch_array($client_sql))
	  {?>
	  	<option value="<?php echo $client_row['client_code'];?>"<?php echo($_REQUEST['party']==$client_row['client_code']?'selected':'')?>><?php echo $client_row['c_name'];?></option>
	  <?php 	
	  }
      ?>
    </select></td>
    <th scope="row"><strong>Type of Quotation</strong></th>
    <td><select name="quotationType" style="width:98%;">
      <option value="M"<?php echo($result1['quotationType']=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo($result1['quotationType']=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo($result1['quotationType']=='R'?'selected':'')?>>Retail</option>
    </select></td>
    </tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="4"> 
    <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
    <td colspan="2" valign="top"><div id="enquiryId">
    	<table width="100%" cellpadding="2" cellspacing="1" border="0">
        	<tr>
            <th nowrap="nowrap" width="50%"><strong>Against Enquiry</strong></th>
            <td nowrap="nowrap" width="50%">
          
            <select name="enquiryNo" style="width:98%;" onchange="showEnqDetails(this.value)">
              <?php 
             $enq_sql=DB_query("Select id,enquiryNo from enquiry where id='".$result1['enquiryNo']."'",$db);
			while($enq_row=DB_fetch_array($enq_sql))
			{?>
			<option value="<?php echo $enq_row['id'];?>"<?php echo($_REQUEST['enquiryNo']==$enq_row['id']?'selected':'')?>><?php echo $enq_row['enquiryNo'];?></option>	
			<?php 	
			}
            ?>
            </select></td>
   		 </tr>
   		 <?php 
   		 $address_sql=DB_query("Select pre_address1,pre_address2,pre_address3,pre_country,pre_state,pre_city from clientmaster where client_code='".$result1['party']."'",$db);
		 $address_result=DB_fetch_array($address_sql);   		 
   		 $countryName=$s->getField('country_master','id',$address_result['pre_country'],'country');
		 $stateName=$s->getField('state_master','id',$address_result['pre_state'],'state');
		 $cityName=$s->getField('city_master','id',$address_result['pre_city'],'city');
   		 ?>
         <tr>
            <th scope="row" rowspan="3"><strong>Address</strong></th>
            <td><input name="partyaddress1" type="text" value="<?php echo $address_result['pre_address1'];?>" size="25"  style="width:98%;"/></td>
            </tr>
            <tr>
            <td><input name="partyaddress2" type="text" value="<?php echo $address_result['pre_address2'];?>" size="25"  style="width:98%;"/></td>
            </tr>
            <tr>
            <td><input name="partyaddress3" type="text" value="<?php echo $address_result['pre_address3'].",".$cityName.",".$stateName.",".$countryName;?>" size="25"  style="width:98%;"/></td>
            </tr>
     </table></div>
    </td>
    <td valign="top"><div id="enqdetailsId"><table width="100%" border="0" cellspacing="1" cellpadding="1">
  <?php 
		if($result1['source']=='CC'){$source="Cold Call";}
		if($result1['source']=='EC'){$source="Existing Customer";}
		if($result1['source']=='SG'){$source="Self Generated";}
		if($result1['source']=='EMP'){$source="Employee";}
		if($result1['source']=='PTN'){$source="Partner";}
		if($result1['source']=='DM'){$source="Direct Mail";}
		if($result1['source']=='WEB'){$source="Web Site";}
		if($result1['source']=='O'){$source="Other";} ?>
      <tr>
        <th width="50%" scope="row"><strong>Source Through </strong></th>
        <td width="50%">	
        <input name="source" type="text" value="<?php echo $source;?>" size="25"  style="width:98%;"/></td>
      </tr>      
      <tr>
        <th scope="row"><strong>Contact Person</strong></th>
        <td><input type="text" name="partyContact" style="width: 98%" value="<?php echo $result1['partyContact'];?>" /></td>
      </tr>
     <?php 
     $mobile_sql=DB_query("Select phone from contact_information_master where person='".$result1['partyContact']."'",$db);
     $mobile_res=DB_fetch_array($mobile_sql)
     ?>
      <tr>
        <th scope="row"><strong>Mobile No.</strong></th>
        <td><input name="ContactMobile" type="text" value="<?php echo $mobile_res['phone'];?>" size="25" style="width:98%;"/></td>
      </tr>
    </table></div>
    <table border="0" width="100%"><tr><th width="50%">Valid Till</th><td width="50%"><input name="validTill" type="text" value="<?php echo $result1['validTill'];?>" size="12" class="datepicker"  style="width:98%;"/></td></tr></table>	
    </td>
    </tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

	<p align="left"><input type="button" name="item_popup" value="Add Items" id="item_popup"  onclick="open_items();" /></p>

<br/>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Unit</th>
<th>Qty</th>
<th>Price</th>
<th>Per Unit(s)</th>
<th>Value</th>
<th>Discount Type</th>
<th>Discount</th>
<th>Discounted Price</th>
<th>Date Of Requisition</th>
<th>Action</th>
</tr>
<?php 
$details_sql=DB_query("Select * from quotation_details where parentId='".$_REQUEST['Id']."' and status='0'",$db);
	$i=0;
	$_SESSION['qutotation_itemcode']=array();
	while($details_row=DB_fetch_array($details_sql))
	{   $_SESSION['qutotation_itemcode'][]=$details_row['id'];
		$item_sql=DB_query("Select * from item_master where StockID='".$details_row['itemCode']."'",$db);
		$item_row=DB_fetch_array($item_sql);	
	?>	
<tr bgcolor="#FFFFFF">
<td><?php echo $details_row['itemCode']?><input type="hidden" name="itemCode[<?php echo $i;?>]" value="<?php echo $details_row['itemCode']?>" id="itemCode_<?php echo $i;?>" /></td>
<td><?php echo $item_row['item_name']?><input type="hidden" value="<?php echo $details_row['id']; ?>" name="id[<?php echo $i; ?>]" /></td>
<td><?php 
$unitName=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitName?></td>
<td><?php echo $details_row['quantity']?><input type="hidden" name="quantity[<?php echo $i;?>]" value="<?php echo $details_row['quantity']?>" id="quantity_<?php echo $i;?>" /></td>
<td><?php echo $details_row['price']?><input type="hidden" name="price[<?php echo $i;?>]" value="<?php echo $details_row['price']?>" id="price_<?php echo $i;?>" /></td>
<td><?php echo $details_row['PerUnits']?><input type="hidden" name="PerUnits[<?php echo $i;?>]" id="PerUnits_<?php echo $i;?>" value="<?php echo $details_row['pricePer']?>" /></td>
<td><?php echo $details_row['totalValue']?><input type="hidden" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $details_row['totalValue']?>" /></td>
<td>
<select name="discountType[<?php echo $i;?>]" id="discountType_<?php echo $i;?>" style="width: 98%">
<option value="A"<?php echo($details_row['discountType']=='A'?'selected':'')?>>Amount</option>
<option value="P"<?php echo($details_row['discountType']=='P'?'selected':'')?>>Percent</option>
</select>
</td>
<td><input type="text" name="discount[<?php echo $i;?>]" id="discount_<?php echo $i;?>" value="<?php echo $details_row['discount']?>" size="15" onblur="calculateDiscount(this.value,<?php echo $i;?>)" /></td>
<td><input type="text" name="valueAfterDisc[<?php echo $i;?>]" id="valueAfterDisc_<?php echo $i;?>" value="<?php echo $details_row['valueAfterDisc']?>" size="15"/></td>
<td><?php echo $details_row['requisitionDate']?><input type="hidden" name="requisitionDate[<?php echo $i;?>]" id="requisitionDate_<?php echo $i;?>" value="<?php echo $details_row['requisitionDate']?>" size="15"/></td>
<td><a href="index.php?route=edit_quotation_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $result1['id'];?>&act=remove&id=<?php echo $details_row['id']; ?>">Remove</a>
</tr>	<?php $i++; } ?>
<input type="hidden" name="count" id="count" value="<?php echo $i;?>" />

 <?php if($_SESSION['itemcode']!='')
	   {
		$itemcode_list=explode(',',$_SESSION['itemcode']);
	 	for($j=0,$k=$i;$j<count($itemcode_list);$j++,$k++)
		{				
			$yy=explode(",",$itemcode_list[$j]);
			$_SESSION['qutotation_itemcode'][]=$yy[0];
			$item=DB_query("select * from item_master where StockID='".$yy[0]."'",$db);
			$details_row=DB_fetch_array($item);
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $details_row['StockID']?><input type="hidden" name="itemCode[<?php echo $k;?>]" value="<?php echo $details_row['StockID']?>" id="itemCode_<?php echo $k;?>" /></td>
<td><?php echo $item_row['item_name']?><input type="hidden" value="<?php echo $details_row['id']; ?>" name="id[<?php echo $i; ?>]" /></td>
<td><?php 
$unitName=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitName?></td>
<td><?php $quantity1=$s->getField('enquiry_details','itemCode',$details_row['StockID'],'quantity');
echo $quantity1 ?>
<input type="hidden" name="quantity[<?php echo $k;?>]" value="<?php echo $quantity1; ?>" id="quantity_<?php echo $k;?>" /></td>
<td><?php $quantity2=$s->getField('enquiry_details','itemCode',$details_row['StockID'],'price');
echo $quantity2?> 
<input type="hidden" name="price[<?php echo $k;?>]" value="<?php echo $quantity2 ?>" id="price_<?php echo $k;?>" /></td>
<td><?php
	$quantity3=$s->getField('enquiry_details','itemCode',$details_row['StockID'],'pricePer');
echo $quantity3?> 
<input type="hidden" name="PerUnits[<?php echo $k;?>]" id="PerUnits_<?php echo $i;?>" value="<?php echo $quantity3 ?>" /></td>
<td><?php 
$quantity4=$s->getField('enquiry_details','itemCode',$details_row['StockID'],'totalValue');
echo $quantity4?>
<input type="hidden" name="totalValue[<?php echo $k;?>]" id="totalValue_<?php echo $k;?>" value="<?php echo $quantity4?>" /></td>
<td>
<select name="discountType[<?php echo $k;?>]" id="discountType_<?php echo $k;?>" style="width: 98%">
<option value="A"<?php echo($details_row['discountType']=='A'?'selected':'')?>>Amount</option>
<option value="P"<?php echo($details_row['discountType']=='P'?'selected':'')?>>Percent</option>
</select>
</td>
<td><input type="text" name="discount[<?php echo $k;?>]" id="discount_<?php echo $k;?>" value="<?php echo $details_row['discount']?>" size="15" onblur="calculateDiscount(this.value,<?php echo $k;?>)" /></td>
<td><input type="text" name="valueAfterDisc[<?php echo $i;?>]" id="valueAfterDisc_<?php echo $i;?>" value="<?php echo $details_row['valueAfterDisc']?>" size="15"/></td>
<td><?php echo $details_row['requisitionDate']?><input type="hidden" name="requisitionDate[<?php echo $k;?>]" id="requisitionDate_<?php echo $k;?>" value="<?php echo $details_row['requisitionDate']?>" size="15"/></td>
<td>
</tr>
<?php  } } ?>
 <input type="hidden" name="counter" value="<?php echo ($i+$j);?>" id="counter" />
</table>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="50%">
<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="19%" scope="row"><strong>Pkg &amp; Forwarding</strong></th>
      <td width="28%" nowrap="nowrap">
      <select name="pack_forward" id="menu1" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="PFRemarks" id="remarks1" value="" size="23%" style="width:48%;" />
      </td>
      </tr>
      <tr>
    <th width="25%" scope="row"><strong>Freight</strong></th>
    <td width="28%" nowrap="nowrap"><select name="freight" id="menu2" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="freightRemarks" id="remarks2" value="" size="23%" style="width:48%;" /></td>
    </tr>
  <tr>
    <th scope="row"><strong>Payment Terms</strong></th>
    <td><select name="payTerms" style="width: 98%">
      	<?php 
      	$payment_sql=DB_query("Select * from paymentterms",$db);
		while($payment_row=DB_fetch_array($payment_sql))
		{?>
			<option value="<?php echo $payment_row['termsindicator'];?>"><?php echo $payment_row['terms'];?></option>
		<?php 	
		}
      	?>
      </select></td>
    </tr>
    <tr>
    <th scope="row"><strong>Sales Tax</strong></th>
    <td nowrap="nowrap"><select name="salesTax" id="menu3" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="salesRemarks" id="remarks3" value="<?php echo $result1['']; ?>" size="23%"  style="width:48%;"/></td>
  </tr>
  <tr>
    <th>Excise</th>
    <td nowrap="nowrap"><select name="Excise" id="" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="exciseRemarks" id="" value="<?php echo $result1['']; ?>" size="23%" style="width:48%;" /></td>
    </tr>
    <tr>
    <th nowrap="nowrap">Insurance</th>
    <td nowrap="nowrap"><select name="insurance" id="menu4" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="insRemarks" id="remarks4" value="" size="23%"  style="width:48%;"/></td>
    </tr>
</table>	
</td>
<td 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" readonly /></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%;"  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 * from excise_tax where caption like '%excise%' and form_type='Sales'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?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++;
			 } 
    	     ?></td>
    	     <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 $result1['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 $result1['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 $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)">
    	    <option value="">Select</option>
    	    <?php 
    	    $salesSql=DB_query("Select * from sales_tax_master",$db);
			while($salesRow=DB_fetch_array($salesSql))
			{
			$t='';
			if($salesRow['salestax_id']==$result1['VatCst'])
			{
			$t="selected";	
			}	
				?>
				<option value="<?php echo $salesRow['salestax_id'];?>"<?php echo $t; ?>><?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()" readonly="readonly" /></td>
    	    
  	    </tr>
  	    </table>
</td>
</tr></table>
<p align="center"><input type="submit" name="Update" value="Update" /><input type="submit" name="Cancel" value="Cancel" /></p>
	</form>	
<script language="JavaScript" type="text/javascript">
	function enquiryDetails(str)
	{
		var branch=document.getElementById("site").value;
		
		if (str.length==0)
  		{
  			document.getElementById("enquiryId").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("enquiryId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","showEnquiryDetails.php?party="+str+"&branch="+branch,true);
		xmlhttp.send();
	}
	function showEnqDetails(str)
	{
		if (str.length==0)
  		{
  			document.getElementById("enqdetailsId").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("enqdetailsId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","showEnquiryDetails.php?enquiryNo="+str,true);
		xmlhttp.send();
	}
function calculateDiscount(str,a)
{
	var discType=document.getElementById("discountType_"+a).value;
	var value=document.getElementById("totalValue_"+a).value;
	if(str==''){str=0;}
	if(discType=='A') 
	{
		var discount=str;
	}
	else
	if(discType=='P') 
	{
		var discount=value*(str/100);	
	}
	document.getElementById("valueAfterDisc_"+a).value=(parseFloat(value)-parseFloat(discount)).toFixed(2);
}
function calculateBasic()
{   
	var totalBasic=0;
	var cnt=document.getElementById("count").value;
	for(var i=0;i<cnt;i++)
	{
		var totalValue=document.getElementById("totalValue_"+i).value;
		totalBasic=parseFloat(totalBasic)+parseFloat(totalValue);	
	}
	document.getElementById("basicAmount").value=totalBasic.toFixed(2);
}
function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("count").value;
	for(var i=0;i<cnt;i++)
	{
		var totaldisc=document.getElementById("valueAfterDisc_"+i).value;
		totalDiscounted=parseFloat(totalDiscounted)+parseFloat(totaldisc);	
	}
	document.getElementById("totalDiscountedPrice").value=totalDiscounted.toFixed(2);
}
function checkApplicable(str)
{
	for(var i=1; i<6;i++)
	{
		if(document.getElementById("menu"+i).value=='NA')
		{
			document.getElementById("remarks"+i).disabled=true;
			document.getElementById("value"+i).disabled=true;
		}
		else
		if(document.getElementById("menu"+i).value=='AS')
		{
			document.getElementById("remarks"+i).disabled=false;
			document.getElementById("value"+i).disabled=false;
		}
	}
}
function claculateExcise(str)
{
	var discounted=document.getElementById("totalDiscountedPrice").value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId").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("exciseId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?taxId="+str+"&discounted="+discounted,true);
		xmlhttp.send();
}
function calculateVATCST(str)
{
	var taxableAmount=document.getElementById("taxableAmount").value;
	if (str.length==0)
  		{
  			document.getElementById("VATId").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("VATId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?salesId="+str+"&taxable="+taxableAmount,true);
		xmlhttp.send();
}
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);
	
}
function getCode(str)
{
	if (str.length==0)
  {
  document.getElementById("CODE").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("CODE").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","codeGenerator.php?quotesite="+str,true);
xmlhttp.send();
}

function open_items()
{
	
	var reqno=document.getElementById("reqno1").value;
	var reqno1=document.getElementById("reqno1").value;
	var reqno2=document.getElementById("reqno2").value;	
	var reqno3=document.getElementById("reqno3").value;	
	window.open("qutotationitem.php?id="+reqno+"&modid="+reqno1+"&frmid="+reqno2+"&Id="+reqno3+"&action=add","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

</script>