<?php  
include('Class_Party.php');
 


//**************SAVE RECORD IN THE TABLES*******************START HERE******************************************************
//if($_REQUEST['Save']!='' && $_REQUEST['action']!='Edit' && $fstatus)


if($_REQUEST['Save']!='' && $_REQUEST['action']!='Edit' )
{

	$sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'prefix');
	$sqlqut=DB_query("select * from quotation where site='".$_REQUEST['site']."'",$db);
	if(DB_num_rows($sqlqut)>0)
	{
	$SQLMax=DB_query("select MAX(quotationNo) as QutNo from quotation where site='".$_REQUEST['site']."'",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$MXNo=substr($MaxQut['QutNo'],-2);
	$FinMx=$MXNo+1;
	$FinalCode=$sitename."/"."QUT"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$sitename."/"."QUT"."/".'00001';
	}


	$data['site']=$_REQUEST['site'];
	$data['quotationNo']=$FinalCode;
	$data['enquiryNo']=$_REQUEST['leadid'];
	$data['against']=$_REQUEST['against'];
	$data['type']=$_REQUEST['type'];
	$data['quotationDate']=FormatDateForSQL($_REQUEST['quotationDate']);
	$data['party']=$_REQUEST['party'];
	$data['quotationType']=$_REQUEST['quotationType'];
	$data['quotation_funnel']=$_REQUEST['quotation_funnel'];
	$data['quotation_stage']=$_REQUEST['quotation_stage'];
	$data['contactPerson']=$_REQUEST['ContactPerson'];
	$data['partyContact']=$_REQUEST['partyContact2'];
	$data['validTill']=ConvertSQLDate($_REQUEST['validTill']);
	//$data['salesTax']=$_REQUEST['salesTax'];
	//$data['Excise']=$_REQUEST['Excise'];
	//$data['insurance']=$_REQUEST['insurance'];
	//$data['delivery']=$_REQUEST['delivery'];
	//$data['validity']=$_REQUEST['validity'];
	$data['basicAmount']=$_REQUEST['basicAmount'];
	$data['exciseDuty']=$_REQUEST['EDBillRate'];
	$data['totalDiscountedPrice']=$_REQUEST['totalDiscountedPrice'];
	$data['ECessPercentage']=$_REQUEST['ECessPercentage'];
	$data['ECessValue']=$_REQUEST['ECessValue'];
	$data['SAHCessPercentage']=$_REQUEST['SAHCessPercentage'];
	$data['SAHCessValue']=$_REQUEST['SAHCessValue'];
	$data['taxableAmount']=$_REQUEST['taxableAmount'];
	$data['VatCst']=$_REQUEST['VatCst'];  
	$data['VatCstValue']=$_REQUEST['VatCstValue'];  
	$data['VatCst_hrd']=$_REQUEST['VatCst_hrd'];  
	$data['VatCstValue_hrd']=$_REQUEST['VatCstValu1e1'];
	$data['sales_tax_taxabelamt']=$_REQUEST['total_taxable_amt'];
	$data['sales_tax_hrdamt']=$_REQUEST['total_taxable_hrd'];
	$data['freight']=$_REQUEST['freight'];
	$data['hrdtotalAmt']=$_REQUEST['hrdtotalAmt'];
	$data['grandTotal']=$_REQUEST['grandTotal'];  
	$data['createdBy']=$_SESSION['UserID'];  
	$data['createdDate']=date('Y-m-d');
	$data['billing_address']=$_REQUEST['address1']; 
	$data['billing_city']=$_REQUEST['city']; 
	$data['billing_state']=$_REQUEST['zipcode']; 
	$data['billing_country']=$_REQUEST['country']; 
	$data['shipping_address']=$_REQUEST['Shipping_address']; 
	$data['shipping_city']=$_REQUEST['Shipping_city']; 
	$data['shipping_state']=$_REQUEST['Shipping_zipcode']; 
	$data['shipping_country']=$_REQUEST['Shipping_country']; 
	
	$data['discounttype']=$_REQUEST['PerAmount']; 
	$data['discountper']=$_REQUEST['Discount_amount']; 
	$data['discountamount']=$_REQUEST['discountperc'];
	$data['afterdiscount']=$_REQUEST['afterdiscountprice'];
	
	$data['process_quote_type']='Process';
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	
	$data['quotationSubject']=$_REQUEST['quotationSubject'];
	$data['quotationMailDate']=$_REQUEST['quotationMailDate'];
	$data['quotationSite']=$_REQUEST['quotationSite'];

	
	//echo "<pre>";
	//print_r($data);

	$s->RecordInsert('quotation', $data);
	$masterId=DB_Last_Insert_ID($db,'quotation','id');
	
	
	for($k=0;$k<count($_REQUEST['terms']);$k++)
	{
		$dataterm['parant_id']=$masterId;
		$dataterm['termsid']=$_REQUEST['terms'][$k];
		$dataterm['condid']=$_REQUEST['Terms_Condition'][$k];
		$dataterm['frm_id']=$_REQUEST['frmid'];
		$s->RecordInsert('quotation_terms_cond', $dataterm);
	}
	 
	
	for($cnt=0;$cnt<count($_REQUEST['item_code']);$cnt++)
	{	
		if($_REQUEST['item_code'][$cnt]!=''){
		$dataArr['parentId']=$masterId;
		$dataArr['itemCode']=$_REQUEST['item_code'][$cnt];
		$dataArr['sizeid']=$_REQUEST['size'][$cnt];
		$dataArr['grade']=$_REQUEST['grade'][$cnt];
		$dataArr['quantity']=$_REQUEST['stock_qty'][$cnt];
		$dataArr['price']=$_REQUEST['stock_price'][$cnt];
		$dataArr['PerUnits']=$_REQUEST['stock_perunit'][$cnt];
		$dataArr['totalValue']=$_REQUEST['stock_value'][$cnt];
		$dataArr['discount_type']=$_REQUEST['PerAmo'][$cnt];
		$dataArr['discount_per']=$_REQUEST['Discount'][$cnt];
		$dataArr['after_dis']=$_REQUEST['perc'][$cnt];
		$dataArr['stock_value']=$_REQUEST['value_dis'][$cnt];
		$dataArr['requisitionDate']=date('Y-m-d');
		$dataArr['est_qty_prm_sec']=$_REQUEST['qtytype'][$cnt];
		$dataArr['secondary_qty']=$_REQUEST['secondary_qty'][$cnt];
		//echo "<pre>";
		//print_r($dataArr);
		
		$s->RecordInsert('quotation_details',$dataArr);
		}
	}
	
	//print_r($_REQUEST['addhrdAmt']);
	for($z=0; $z<count($_REQUEST['hrditemid']);$z++)
	{
		if($_REQUEST['addhrdAmt'][$z]!='0')
		$cnt=1;
		else
		$cnt=$_REQUEST['addhrdAmt'][$z];
		
		$hrddata['parant_id']=$masterId;
		$hrddata['hardwarepart']=$_REQUEST['hardwarepart'][$z];
		$hrddata['itemCode']=$_REQUEST['hrditemid'][$z];
		$hrddata['quantity']=$_REQUEST['hrd_qty'][$z];
		$hrddata['price']=$_REQUEST['hrd_price'][$z];
		$hrddata['PerUnits']=$_REQUEST['hrd_perunit'][$z];
		$hrddata['totalValue']=$_REQUEST['hrd_value'][$z];
		$hrddata['discount_type']=$_REQUEST['hrdPerAmo'][$z];
		$hrddata['discount_per']=$_REQUEST['hrdDiscount'][$z];
		$hrddata['after_dis']=$_REQUEST['hrdperc'][$z];
		$hrddata['stock_value']=$_REQUEST['hrdvalue_dis'][$z];
		$hrddata['isChecked']=$cnt;
		
		//echo "<pre>";
		//print_r($hrddata);
		$s->RecordInsert('quotation_hardware_items',$hrddata);
		
	}
	
	
	
	
	//exit;
	if($_REQUEST['against']=='Enquiry')
	{
	$updatelead=DB_query("update crm_leads set Quotes_Status='Y' where leadid='".$_REQUEST['leadid']."'",$db);
	}
	if($_REQUEST['against']=='Estimation 2 Against Bom')
	{
	$updatelead=DB_query("update cstest_estimation_bom set est_status='1' where id='".$_REQUEST['leadid']."'",$db);
	}
	
	$s->pageLocation("index.php?route=CRM/ViewQuotes".$rurl);
}
//**************SAVE RECORD IN THE TABLES*******************END HERE******************************************************
?>


<!----------------------INCLUDES AJAX FILES-----------------START HERE--------------------------------AS------------------->
<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 totalBasic2=0;
	if(document.getElementById("hiditemcount").value!='')
	{
	var cnt=parseFloat(document.getElementById("hiditemcount").value);
	}
	else
	{
		cnt=0
	}
	
	if(document.getElementById("count1").value!='')
	{
	var cnt1=parseFloat(document.getElementById("count1").value);
	}
	else
	{
		cnt1=0;
	}
	
	
	var fincount=cnt+cnt1;
	
	
	//alert(fincount);
	//if(document.getElementById("value_dis").value!='')
//	{
//	var totalBasic4=document.getElementById("value_dis").value;
//	}
//	else
//	{
//	var totalBasic4=0;
//	}
	
	for(var i=0;i<fincount;i++)
	{
	if(document.getElementById("itemid1_"+i).value!=''){
	if(document.getElementById("value_dis_"+i).value!='')
	{	
	var totalBasic1=document.getElementById("value_dis_"+i).value;
	}
	else
	{
	var totalBasic1=0;
	}
	var totalBasic=parseFloat(totalBasic)+parseFloat(totalBasic1);
	}
	}
	//var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic4);	
	var totalBasic3=parseFloat(totalBasic);	
	document.getElementById("basicAmount").value=totalBasic3;
}



function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("hiditemcount").value;
	for(var i=0;i<=cnt;i++)
	{
	var totalDiscounted1=document.getElementById("valueAfterDisc_"+i).value;
	var totalDiscounted=parseFloat(totalDiscounted)+parseFloat(totalDiscounted1);
	}
	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
}



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 ValueAfterDiscount(i)
{
	var disc=document.getElementById("discount_"+i).value;
	var disctype=document.getElementById("discountType_"+i).value;
	if(disc=='')
	{
	var stockvalue=document.getElementById("stock_value_"+i).value;
	document.getElementById("valueAfterDisc_"+i).value=stockvalue;
	}
	else
	{
	if(disctype=='A')
	{
	var stockvalue=document.getElementById("stock_value_"+i).value;
	var valueafterdisc=parseFloat(stockvalue)-parseFloat(disc);
	document.getElementById("valueAfterDisc_"+i).value=valueafterdisc;
	}
	if(disctype=='P')
	{
	var stockvalue=document.getElementById("stock_value_"+i).value;
	var discpercvalue=(parseFloat(stockvalue)*parseFloat(disc))/100;
	var finalValue=(parseFloat(stockvalue)-parseFloat(discpercvalue)).toFixed(2);
	document.getElementById("valueAfterDisc_"+i).value=finalValue;
	}
	}
}



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)
{
	if (str=='')
	{
	document.getElementById("rate").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("rate").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId="+str,true);
	xmlhttp.send();
}


function calculateVATCST_hrd(str)
{
	if (str=='')
	{
	document.getElementById("rate1").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("rate1").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise_hrd.php?salesId="+str,true);
	xmlhttp.send();
}



function calculateECess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").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("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}



function calculateTaxable()
{
    var afterdiscount=document.getElementById("afterdiscountprice").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(afterdiscount==''){afterdiscount=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(afterdiscount);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}



function calculateGrand()
{
	//var a=document.getElementById("basicAmount").value;
	//var b=document.getElementById("totalDiscountedPrice").value;
	//var c=document.getElementById("ECessValue").value;
	//var d=document.getElementById("SAHCessValue").value;
	//var e=document.getElementById("taxableAmount").value;
	//var f=document.getElementById("VatCstValue").value;
	var g=document.getElementById("freight").value;
	var h=document.getElementById("total_taxable_amt").value;
	var i=document.getElementById("total_taxable_hrd").value;
	//if(a==''){a=0;}
	//if(b==''){b=0;}
	//if(c==''){c=0;}
	//if(d==''){d=0;}
	//if(e==''){e=0;}
	//if(f==''){f=0;}
	if(g==''){g=0;}
	if(h==''){h=0;}
	if(i==''){i=0;}
	//var GRAND=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f)+parseFloat(g);
	var GRAND=parseFloat(g)+parseFloat(h)+parseFloat(i);
	//grandBrk=GRAND.toFixed(2).split('.');
	//grandA=grandBrk[0];
	//grandB=grandBrk[1];
	//alert(grandA);
	//alert(grandB);
	//if(grandB>'50' || grandB=='50')
	//{
		//GRAND11=parseInt(GRAND)+1;
	//}
	//else
	//if(grandB<'50')
	//{
		//GRAND11=parseInt(GRAND);
	//}	
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	//document.getElementById("roundOff").value="."+grandB;
}
 

function GetLeads(str)
{
	var site=document.getElementById("site").value;
	var clientid=document.getElementById("party").value;
	if (str.length==0)
	{
	document.getElementById("hid_Leads").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)
	{
	 var data=xmlhttp.responseText.split("__");
	document.getElementById("hid_Leads").innerHTML=data[0];
	document.getElementById("mobile_check").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","CRM_GetLeads.php?str="+str+"&site="+site+"&client_id="+clientid,true);
	xmlhttp.send();
}


function GetLeadRecord(str)
	{
	var site=document.getElementById("leadid").value;
	if (str.length==0)
	{
	document.getElementById("leadid").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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","CRM_GetLeadsRecord.php?branch="+str,true);
	xmlhttp.send();
	
}
function GetEstimationRecord(str)
{
	var site=document.getElementById("leadid").value;
	if (str==0)
	{
	document.getElementById("leadid").innerHTML="";
	document.getElementById("ITEMSDETAILS").innerHTML="";
	document.getElementById("HARDWAREDETAILS").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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[1];
	document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	
	}
	}
	xmlhttp.open("GET","CRM_GetEstimationRecord.php?estimationid="+str,true);
	xmlhttp.send();
	
}


function GetEstimationRecord2(str)
{
	var site=document.getElementById("leadid").value;
	if (str==0)
	{
	document.getElementById("leadid").innerHTML="";
	document.getElementById("ITEMSDETAILS").innerHTML="";
	document.getElementById("HARDWAREDETAILS").innerHTML="";
	document.getElementById("basicAmount").value='';
	document.getElementById("hrdtotalAmt").value='';
	document.getElementById("afterdiscountprice").value='';
	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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("basicAmount").setAttribute("onfocus","calculateBasic_estimation()");
	
	document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[1];
	document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	document.getElementById("basicAmount").value=data[3];
	document.getElementById("hrdtotalAmt").value=data[4];
	document.getElementById("afterdiscountprice").value=data[3];
	//document.getElementById("typeid").innerHTML=data[0];
	
	
	
	}
	}
	xmlhttp.open("GET","CRM_GetEstimationRecord_against_bom.php?estimationid="+str,true);
	xmlhttp.send();
	
}





function CalculateTotalLeadAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[2];
	
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	if(id_brk.length>2)
	{
	var stock_perunit = document.getElementById("stock_perunit_"+i).value;
	
	
	var stock_price = document.getElementById("stock_price_"+i).value;
	if(document.getElementById("qtyprim_"+i))
	{
	if(document.getElementById("qtyprim_"+i).checked==true)
	var stock_qty = document.getElementById("qtyprim_"+i).value;
	//alert( document.getElementById("qtyprim_"+i).value);
	else
	var stock_qty = document.getElementById("qtysec_"+i).value;
	}
	else
		//alert(document.getElementById("qtysec_"+i).value);
   var stock_qty = document.getElementById("stockqty_"+i).value;
	document.getElementById("stock_value_"+i).value=round((stock_price*stock_qty )/stock_perunit);
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
	}
	else
	{
	var stock_perunit = document.getElementById("stock_perunit").value;
	var stock_price = document.getElementById("stock_price").value;
	var stock_qty = document.getElementById("stockqty").value;
	document.getElementById("stock_value").value=(stock_price*stock_qty )/stock_perunit;
	//document.getElementById("total_stock").value=document.getElementById("stock_qty").value;
	}
	
	
	
	
}


function CalculateTotalLeadAmt1(val,i)
{
	
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	
	var stock_perunit = document.getElementById("stock_perunit1_"+i).value;
	var stock_price = document.getElementById("stock_price1_"+i).value;
	var stock_qty = document.getElementById("stock_qty2_"+i).value;
	document.getElementById("stock_value1_"+i).value=(stock_price*stock_qty )/stock_perunit;
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
}




function CalculateTotalLeadAmt2(val,i)
{
	
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	
	var stock_perunit = document.getElementById("hrdstock_perunit1_"+i).value;
	var stock_price = document.getElementById("hrdstock_price1_"+i).value;
	var stock_qty = document.getElementById("hrdstock_qty2_"+i).value;
	document.getElementById("hrdstock_value1_"+i).value=(stock_price*stock_qty )/stock_perunit;
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
}





function calculateEditVATCST()
{
	//if(document.getElementById("hrdtotalAmt").value!='')
	//{
	//var hrdamt=parseFloat(document.getElementById("hrdtotalAmt").value);
	//}
	//else
	//{
		hrdamt=0;
	//}
	
	var rate=document.getElementById("rate").value;
	if(document.getElementById("taxableAmount").value!='')
	{
	var taxableAmount=parseFloat(document.getElementById("taxableAmount").value);
	}
	else
	{
		taxableAmount=0;
	}
	
	if(rate=='') { rate=0; }
	var fintotal=taxableAmount+hrdamt;
	var vat_cst=fintotal*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}



function calculateEditVATCST_hrd()
{
	if(document.getElementById("hrdtotalAmt").value!='')
	{
	var hrdamt=parseFloat(document.getElementById("hrdtotalAmt").value);
	}
	else
	{
		hrdamt=0;
	}
	
	var rate=document.getElementById("rate1").value;
	
	if(rate=='') { rate=0; }
	
	var fintotal=hrdamt;
	var vat_cst=fintotal*(rate/100);
	document.getElementById("VatCstValue1").value=vat_cst.toFixed(2);
}




function calculateBillExcise(str)
{
	var value=document.getElementById("afterdiscountprice").value;
	if(str.length==0)
	{
	document.getElementById("totalDiscountedPrice").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("totalDiscountedPrice").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	
}


/*function calcValue1(str,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	
	if(id_brk[1]==undefined)
	{
	 if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stockqty").value='';
	   return false;
	   }
	}
	else
	   {	
	  
	   if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+i).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stockqty_"+i).value='';
	   return false;
	   }
	   }
      
}*/



function calcValue(str,i)
{
  
	var stockqty=parseFloat(str);
	var originalstock=parseFloat(document.getElementById("stockqty1_"+i).value);
	var stockvalue=parseFloat(document.getElementById("total_stock1_"+i).value);
	if(stockqty>stockvalue)
	{
		alert("Qty Should be less or equal then Stock Qty");
		document.getElementById("stock_qty2_"+i).value=originalstock;
		return false;
	}
	

	
}



function addtotadhrdamt(i)
{
	var counthrd=document.getElementById("hrdcount1").value;
	var sum=0;
	for(var i=0; i < counthrd; i++)
	{
		if(document.getElementById("addhrdAmt_"+i).checked==true)
		{
			if(document.getElementById("hrdvalue_dis1_"+i).value!='')
			{
			var discamt=parseFloat(document.getElementById("hrdvalue_dis1_"+i).value);
			}
			else
			{
			discamt=0;
			}
			sum=sum+discamt;
		}
		
	}
	
	document.getElementById("hrdtotalAmt").value=sum;
	
}


</script>
<!----------------------INCLUDES AJAX FILES-----------------END HERE--------------------------------AS------------------->



<?php //echo $ConvertIntoSales;?>
	<table border="0">
<tr>
    <td>	
	<?php  if( $ConvertIntoSales=='N'){?>
		<a href="index.php?route=CRM/CRMSalesOrder&QID=<?php  echo $_REQUEST['QID'].$rurl;?>">
	<input type="button" name="Create" value="Convert into Sales Order" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>
	
	<?php } elseif($_REQUEST['action']!='AddNew'){?>
		<a href="index.php?route=CRM/CRMSalesOrder&action=Edit&SID=<?php echo $SalesOrderNo?>&QID=<?php  echo $_REQUEST['QID'].$rurl;?>">
	<input type="button" name="ViewSaleOrder" value="View Sales Order" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>
	
	
	<?php }
	if($_REQUEST['action']=='Edit'){
	?>
	 <a href="CRM/tcpdf/PDFQuotes.php?record=<?php echo $_REQUEST['QID'].$rurl;?>">
	 <input type="button" name=" Export to PDF" value=" Export to PDF" style=" background-image:
	 url(images/PDF.gif)background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px; " />
</a><?php } ?>
	 
</td></tr></table>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Quote Management</h1>
<form action="" method="post"  name="frm1" id="frm1">

<table width="100%" cellpadding="3" cellspacing="0" border="0">
	<tr class="row1">
	<td colspan="4"><strong>General Information</strong></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Branch<label><font color="#FF0000">*</font></label></td>
	<td>
	<select name="site"   id="site" style="width:150px;">
	<option value="0">Select</option>
	<?php 
	$site_sql=DB_query("Select 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($site==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
	<?php 	
	}
	?>
	</select></td>
	<td class="tabledata1">Quotation No.</td>
	<td id="CODE"><input name="quotationNo" type="text" value="Auto Generated" readonly="" style="width:150px;"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Quotation Date <label><font color="#FF0000">*</font></label></td>
	<td><input type="text" name="quotationDate" value="<?php echo date('d/m/Y');?>" style="width:150px;" class="datepicker" id="quotationDate" /></td>
	<td class="tabledata1">Format<label><font color="#FF0000">*</font></label></td>
	<td><select name="format" style="width:150px;">
	<option value="Standard">Standard</option>
	</select></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Account Name<font color="#FF0000">*</font></td>
	<td>
	<select name="party" style="width:150px;"  id="party" onchange="showalldata(this.value);">
	<option value="000">Select</option>
	<?php
	//echo  $_SESSION['UserSites'];
	$client_sql=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  while($client_row=DB_fetch_array($client_sql)){ ?>
	<option value="<?php echo $client_row['id'];?>"<?php echo($party==$client_row['id']?'selected':'')?>>
	<?php  echo $client_row['c_name'];?></option> <?php } ?>
	
	</select>    
	</td>
	<td class="tabledata1">Against<font color="#FF0000">*</font></td>
	<td><select name="against" id="against" style="width:150px;" onChange="GetLeads(this.value);">
			<option value="">Select</option>
			<option value="Enquiry"<?php echo($quotationType=='M'?'selected':'')?>>Lead</option>
			<option value="Estimation"<?php echo($quotationType=='E'?'selected':'')?>>Estimation</option>
			<option value="Estimation 2 Against Bom"<?php echo($quotationType=='E'?'selected':'')?>>Estimation 2 Against Bom</option>
	</select></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Against Enquiry / Estimation
	  <label><font color="#FF0000">*</font></label></td>
	<td><div id='hid_Leads'>
	<?php 
	if($_REQUEST['action']=='Edit')
	$enquery_leadid=$s->GetFieldValue('crm_leads',"leadid='".$result1['enquiryNo']."'",'leadcode');
	else
	$enquery_leadid=$enquiryNo;
	//echo $enquery_leadid;
	?>
	
	
	<input type="text" name="enquiryNo" style="width:150px;" value="<?php  echo $enquery_leadid;?>" /></div></td>
	<td class="tabledata1">Quote Stage</td>
	<td><input type="text" style="width:150px;"  name="quotation_stage" value="<?php  echo $quotation_stage;?>"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Mobile No.</td>
	<td><div id="mobile_check">
	<input type="text" name="partyContact2"   style="width:150px;" value="<?php if(isset($partyContact)){echo $partyContact;} else { echo $_REQUEST['partyContact'];}?>" /></div></td>
	<td class="tabledata1">Valid Till<label><font color="#FF0000">*</font></label></td>
	<td><input name="validTill" type="text" value="<?php if(isset($validTill)){echo $validTill;} ?>" style="width:150px;" class="datepicker" id="validTill" onchange="return selectDate();"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Type</td>
	<td id="typeid"><select name="type" id="type" style="width:150px;">
		<option value="">Select</option>
	</select>
	</td>
	<td class="tabledata1">Type of Quotation<font color="#FF0000">*</font></td>
	<td><select name="quotationType" style="width:150px;">
	<option value="Material"<?php echo($quotationType=='Material'?'selected':'')?>>Material</option>
	<option value="Supply"<?php echo($quotationType=='Supply'?'selected':'')?>>Supply</option>
	<option value="Composite"<?php echo($quotationType=='Composite'?'selected':'')?>>Composite</option>
	</select></td>
	</tr>
	 <tr class="row1">
  	<td class="tabledata1">Quotation Site <label><font color="#FF0000">*</font></label></td>
	<td><input type="text" name="quotationSite" id="quotationSite" style="width:150px" value="<?php if(isset($quotationSite)){echo $quotationSite;} else { echo $_REQUEST['quotationSite'];}?>" /></td>
	<td class="tabledata1">Mail Date</td>
	<td><input type="text" name="quotationMailDate" id="quotationMailDate" style="width:150px" value="<?php if(isset($quotationMailDate)){echo $quotationMailDate;} else { echo $_REQUEST['quotationMailDate'];}?>" class="datepicker" /></td>
  </tr>
  <tr class="row1">
  	<td class="tabledata1">Subject</td>
	<td colspan="3"><textarea name="quotationSubject" id="quotationSubject" style="width:605px;"></textarea></td>
  </tr>
	<tr class="row1">
	<td colspan="4"><strong>Account  Billing  &  shipping  Address  Information</strong><input type="checkbox" name="shipping_data" id="shipping_data" onclick="ship_data()"></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Billing Address</td>
	<td width="25%" >
	<input type="text" name="address1" style="width:150px;" id="address1"  value="<?php  echo $address1;?>"/></td>
	<td class="tabledata1">Shipping Address</td>
	<td width="25%" id="CODE">
	<input type="text" id="Shipping_address" name="Shipping_address" style="width:150px;"   value="<?php echo $Shipping_address?>"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Billing Country</td>
	<td> 
	<select name="country" id="country" onchange="ShowDiv(this.value,'state_id','emp_state.php')" style="width:150px;" />
	<option value="0">--Select--</option>
	<?php
	$country_sql="Select * from country_master";
	$country_res=DB_query($country_sql,$db);
	while($country_row=DB_fetch_array($country_res))
	{
	?>
	<option value="<?php echo $country_row['id']?>"<?php echo ($country== $country_row['id'])?'selected':'';?>><?php echo $country_row['country'];?></option>
	<?php
	}
	?>
	
	</select></td>
	<td class="tabledata1">Shipping Country</td>
	<td>
	<div id="showship"  style="display:block;">
	<select name="Shipping_country" id="country" onchange="ShowDiv(this.value,'state_id','emp_state.php')" style="width:150px;" />
	<option value="0">--Select--</option>
	<?php
	$country_sql="Select * from country_master";
	$country_res=DB_query($country_sql,$db);
	while($country_row=DB_fetch_array($country_res))
	{
	?>
	<option value="<?php echo $country_row['id']?>"<?php echo ($country== $country_row['id'])?'selected':'';?>><?php echo $country_row['country'];?></option>
	<?php
	}
	?>
	
	</select>
	</div>
	<div id="show1ship" style="display:none;">
	<input name="Shipping_country" id="Shipping_country" type="text"  style="width:150px;" value="<?php  echo $Shipping_country?>"/></div></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Billing State</td>
	<td >
	<div id="state_id"><select name="state"  onchange="ShowDiv(this.value,'show_city','emp_city.php')" id="state" style="width:150px;" >
	<option value="o">---Select---</option>
	<?php 
	
	$state_sql=DB_query("select * from state_master where id='".$state."'",$db);
	while($state_row=DB_fetch_array($state_sql))
	{
	?>
	<option value="<?php echo $state_row['id'];?>"<?php echo($state==$state_row['id'])?'selected':'';?>><?php echo $state_row['state'];?></option>
	<?php } ?>
	</select>
	</div>
	</td>
	<td class="tabledata1">Shipping State</td>
	<td >
	<div id="shipbill" style="display:block;">
	<select name="Shipping_state"   id="Shipping_state1" style="width:150px;" >
	<option value="o">---Select---</option>
	<?php 
	
	$state_sql=DB_query("select * from state_master ",$db);
	while($state_row=DB_fetch_array($state_sql))
	{
	?>
	<option value="<?php echo $state_row['id'];?>"<?php echo($state==$state_row['id'])?'selected':'';?>><?php echo $state_row['state'];?></option>
	<?php } ?>
	</select>
	</div>
	<div id="shipbill1" style="display:none;">
	
	<input name="Shipping_state"  id="Shipping_state" type="text" value="<?php //echo $Shipping_state;?>"  style="width:150px;"/>
	</div>
	</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Billing city</td>
	<td ><div id='show_city'>
	<select name="city"  id="city" style="width:150px;" >
	<option value="0">Select</option>
	<?php
	$city_sql=DB_query("select * from city_master where state='".$state."'",$db);
	while($city_row=DB_fetch_array($city_sql))
	{
	?>
	<option value="<?php echo $city_row['id'];?>"<?php echo($city==$city_row['id'])?'selected':'';?>><?php echo $city_row['city'];?></option>
	<?php } ?>
	</select>
	
	</div></td>
	<td class="tabledata1">shipping City</td>
	<td >
	<div id="shipcity" style="display:block;">
	<select name="Shipping_city"  id="city" style="width:150px;" >
	<option value="0">Select</option>
	<?php
	$city_sql=DB_query("select * from city_master",$db);
	while($city_row=DB_fetch_array($city_sql))
	{
	?>
	<option value="<?php echo $city_row['id'];?>"<?php echo($city==$city_row['id'])?'selected':'';?>><?php echo $city_row['city'];?></option>
	<?php } ?>
	</select>
	</div>
	<div id="shipcity1" style="display:none;">
	
	<input name="Shipping_city"  id="Shipping_city" type="text"  style="width:150px;" value="<?php  //echo $Shipping_city?>"/>
	
	</div>
	</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Billing Postal Code</td>
	<td >
	<input type="text" name="zipcode" id="zipcode" style="width:150px;"  value="<?php  echo $zipcode?>" /></td>
	<td class="tabledata1">Shipping Postal Code</td>
	<td><input type="text" name="Shipping_zipcode" id="Shipping_zipcode" style="width:150px;"  value="<?php  echo $Shipping_zipcode?>" /></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1" colspan="4"><strong>Item Details</strong></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1" colspan="4" style="text-align:left;">
	<!--<input type="button" onClick="addRow('dataTable')" value="Add More" class="search" />&nbsp;
	<input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items()" class="search" />-->
	<!--<input type="button" class="search"  onclick="deleteRow('deleterrw')" value="Delete" />-->
	<!--<input type="button" class="search" name="UndoRecords" value="UndoRecords" onclick="undo()" />-->
	</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1" colspan="4">
	<div id="ITEMSDETAILS" style="width:947px; overflow:auto;" >
	<table id="deleterrw" align='center' width='100%;' border='1' cellpadding='3' cellspacing='0'>
	<tr class='row1'>
	<td class='tabledata'>Sr. No.</td>
	<td class='tabledata'>&nbsp;</td>
	<td class='tabledata'>Item Code</td>
	<td class='tabledata'>Item Name</td>
	<td class="tabledata">Size</td>
	<td class='tabledata'>Qty.</td>
	<td class='tabledata'>Price</td>
	<td class='tabledata'>Per Unit</td>
	<td class='tabledata'>Value</td>
	<td class='tabledata'>Discount Type</td>
	<td class='tabledata'>Discount Per</td>
	<td class='tabledata'>Discount Price</td>
	<td class='tabledata'>Value After Discount</td>
	<td class='tabledata'>Total stock Qty</td>
	</tr>
	<tbody id='dataTable'>
	<tr class='row1'>
	<td style='white-space:nowrap;' class='tabledata'><input name='delitem[]' type='checkbox' value='' /></td>
	<td class='tabledata'><input type='hidden' name='item_code[]' id='itemid' value='' /></td>
	<td class='tabledata'><input type='text' name='' id='itemcode' value='' style="width:60px;" /></td>
	<td class='tabledata' style='white-space:nowrap'><input type='text' style="width:90px;" name='item_name[]' id='itemname' value='' /></td>
	<td class="tabledata" style="white-space:nowrap"><select style="width:100px;" name="size[]" id="size">
													<option>--Select--</option>
<?php $SQLSize=DB_query("SELECT * FROM size_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
												while($sizeid=DB_fetch_array($SQLSize)){?>
										<option value="<?php echo $sizeid['id']; ?>"><?php echo $sizeid['size']; ?></option>
												<?php } ?>
												</select></td>
	
	<td class='tabledata'><input type='text' name='stock_qty[]'  id='stockqty' style="width:50px;" onkeyup='calcValue1(this.value,this.id)'  /></td>
	<td class='tabledata'><input type='text' name='stock_price[]'  id='stock_price' style="width:50px;"/></td>
	<td class='tabledata'><input type='text' name='stock_perunit[]' onfocus='filldefaultAmt(this.value,this.id)' id='stock_perunit' style="width:30px;" value='1' /></td>
	<td class='tabledata'><input type='text' name='stock_value[]'  id='stock_value' style="width:60px;" onfocus='CalculateTotalLeadAmt(this.value,this.id)'/></td>
	<td class='tabledata'><select style="width:80px;" name='PerAmo[]' id='PerAmo' >
	<option value='Amount' >Amount</option>
	<option value='PercentAmt'>Percent Amt</option>
	</select></td>
	<td class='tabledata'><input type='text' style="width:50px;" name='Discount[]' id='Discount' onkeyup='DiscountAmount1(this.value,this.id)' /></td>
	<td class='tabledata'><input type='text' style="width:50px;" name='perc[]' id='perc'  readonly='true'  /></td>
	<td class='tabledata'><input type='text' style="width:70px;" name='value_dis[]' id='value_dis'  readonly='true'  /></td>
	<td class='tabledata'><input type='text' name='total_stock[]' id='total_stock' style="width:50px;"   readonly='true' /></td>
	</tr>
	</tbody>
	</table>
	<input type='hidden' name='count1' id='count1' value=''>
	</div>
	
	</td>
	</tr>
</table>

<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" />

<div id="HARDWAREDETAILS">
</div>
<br>
<table width="100%" border="1"  cellpadding="3" cellspacing="0">
	<tr class="row1">
		<td valign="top" width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left">
			<tr class="row1">
				<td class="tabledata1" style="text-align:center;" colspan="2">Terms And Conditions</td>
			</tr>
<?php $i=0; $SQLTerms=DB_query("SELECT * FROM terms_condition where parant_id=0 and frm_id='".$_REQUEST['frmid']."'",$db); 
while($TermsAndCond=DB_fetch_array($SQLTerms)){?>
			<tr class="row1">
				<td class="tabledata1"><?php echo $TermsAndCond['terms_conditions']; ?>
				<input type="hidden" name="terms[]" id="terms" value="<?php echo $TermsAndCond['id']; ?>" />
				</td>
				<td><select name="Terms_Condition[]" id="Terms_Condition" style="width:100%;">
						<option value="">Select</option>
						<?php $SQLCond=DB_query("SELECT * FROM terms_condition where parant_id='".$TermsAndCond['id']."'",$db);
						while($GetCond=DB_fetch_array($SQLCond)){?>
						<option value="<?php echo $GetCond['id']; ?>"><?php echo $GetCond['terms_conditions']; ?></option>
						<?php }?>
				</select></td>
			</tr>
<?php $i++;}?>
		</table>	
		</td>
		<td valign="top" width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="right">
			<tr class="row1">
				<td class="tabledata1" style="text-align:center;" colspan="4">Amount And Taxes</td>
			</tr>
			
			
			
			
			<tr class="row1">
					<td class="tabledata1">Basic Amount<label><font color="#FF0000">*</font></label></td>
					<td colspan="3"><input name="basicAmount" type="text" value="<?php echo $basicAmount;?>" style="width:150px;" onfocus="calculateBasic()" id="basicAmount"   /></td>
				</tr>
			<!--	  <tr class="row1">
					<td class="tabledata1" >Discounted Price<label><font color="#FF0000">*</font></label></td>
					<td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $totalDiscountedPrice;?>" style="width:150px;" onfocus ="calculateDiscounted()"/>
					
					
					</td>
					
				</tr>-->
			<tr class="row1">
			<td>Discount Type</td>
			<td><select  name='PerAmount' id='PerAmount' style="width:150px;" >
            <option value='Amount' >Amount</option>
            <option value='PercentAmt'>Percent Amt</option>
          </select></td>
			<td><input type="text" style="width:35px" name="Discount_amount" id="Discount_amount" 
onkeyup="DiscountAmountvalue(this.value)" value="0" /></td>
			<td>&nbsp;</td>
			</tr>
		  <tr class="row1">
<td>Discount Amt</td><td><input type="text" style="width:150px" name="discountperc" id="discountperc"  readonly="true"  /></td>
			<td>Discounted Amt</td>
			<td><input type="text" style="width:150px" name="afterdiscountprice" id="afterdiscountprice"  readonly="true"  /></td>
		  </tr>	
			
			<tr class="row1">
					<td class="tabledata1">Excise Duty</td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:150px" onchange="calculateBillExcise(this.value)"  >
				<option value="0">--Select--</option>
				<?php
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
				$ServiceRes=DB_query($ServiceSql,$db);
				while($ServiceRow=DB_fetch_array($ServiceRes))
				{
				?>
				<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>							</td>
				    <td>Excise Amt </td>
				    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:150px;" onfocus="calculateTotalExcise()"/>	</td>
			</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 class="row1">
					<td class="tabledata1">E-Cess</td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:150px;" readonly />						</td>
					<td><span class="tabledata1">E-Cess</span> Amt </td>
					<td><input name="ECessValue" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:150px;"readonly onfocus="calculateECess()"/></td>
			</tr>
			<tr class="row1">
					<td class="tabledata1" >SAH-E Cess </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:150px;" readonly/>						</td>
					<td><span class="tabledata1">SAH-E Cess</span> Amt </td>
					<td><input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:150px;" readonly onfocus="calculateSAHCess()"/></td>
			</tr>
			<tr class="row1">
			<td class="tabledata1">Taxable Amount<label><font color="#FF0000">*</font></label></td>
			<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $taxableAmount?>" style="width:150px;" onfocus="calculateTaxable()"/>			</td>
		    <td><span class="tabledata1">HardWare Amt</span></td>
		    <td><input type="text" name="hrdtotalAmt" id="hrdtotalAmt" style="width:150px;"  /></td>
			</tr>
		 
			<tr class="row1">
					<td class="tabledata1">Sales Tax (Taxable Amt) </td>
					<td>
					<select name="VatCst" id="value3" style="width:150px;" onchange="calculateVATCST(this.value)">
				<option value="" >Select</option>
				<?php 
				$salesSql=DB_query("Select * from sales_tax_master",$db);
				while($salesRow=DB_fetch_array($salesSql))
				{?>
				<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
				<?php 	
				}
				?>
				</select>
				<div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:150px;" readonly  onfocus="calculateEditVATCST()" /></div>
				<input type="hidden" name="" id="rate" value="" /></td>
				    <td><span class="tabledata1">Sales Tax (H/w Amt) </span></td>
				    <td><select name="VatCst_hrd" id="value4" style="width:150px;" onchange="calculateVATCST_hrd(this.value)">
				<option value="" >Select</option>
				<?php 
				$salesSql1=DB_query("Select * from sales_tax_master",$db);
				while($salesRow1=DB_fetch_array($salesSql1))
				{?>
				<option value="<?php echo $salesRow1['salestax_id'];?>" <?php echo $VatCst==$salesRow1['salestax_id']?'selected':''?>><?php echo $salesRow1['tax_code'];?></option>
				<?php 	
				}
				?>
				</select>
				<div id="VATId1"><input name="VatCstValu1e1" id="VatCstValue1" type="text" value="<?php echo $VatCstValue?>" style="width:150px;" readonly  onfocus="calculateEditVATCST_hrd()" /></div>
				<input type="hidden" name="" id="rate1" value="" /></td>
			</tr>
				
				<tr class="row1">
					<td class="tabledata1">Total Amt I </td>
					<td ><input type="text" name="total_taxable_amt" id="total_taxable_amt" style="width:150px;" onfocus="calculatetaxable_tax()"  /></td>
					<td class="tabledata1">Total Amt II </td>
					<td ><input type="text" name="total_taxable_hrd" id="total_taxable_hrd" style="width:150px;" onfocus="calculatetaxable_hrd()" /></td>
				</tr>
				
				<tr class="row1">
					<td class="tabledata1">Freight Amt </td>
					<td colspan="3"><input type="text" name="freight" id="freight"  style="width:150px;" /></td>
				</tr>
				
				
		 <!--   	  <tr class="row1">
					<td class="tabledata1">Freight</td>
					<td><input name="freightValue" id="value2" type="text" value="<?php echo $freightValue?>" style="width:150px;" /></td>
					
				</tr>
				  <tr class="row1">
					<td class="tabledata1">Pkg Charges</td>
					<td><input name="packagingCharges" id="value1" type="text" value="<?php echo $packagingCharges;?>" style="width:150px;" /></td>
					
				</tr>
				<tr class="row1">
					<td class="tabledata1">Additional Charges</td>
					<td><input name="additionalCharges" id="value4" type="text" value="<?php  echo $additionalCharges;?>" style="width:150px;" /></td>
					
				</tr>
				  <tr class="row1">
					<td class="tabledata1">Round Off</td>
					<td><input name="roundOff" id="roundOff" type="text" value="<?php echo $roundOff;?>" readonly="true" style="width:150px;" /></td>
					
				</tr>-->
			<tr class="row1">
					<td class="tabledata1">Grand Total<label><font color="#FF0000">*</font></label></td>
					<td colspan="3"><input name="grandTotal" id="grandTotal" type="text"  style="width:150px;" onfocus="calculateGrand()" readonly="readonly" value="<?php echo $grandTotal  ;?>" /></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<p align="center"><input type="submit" name="Save" value="Save" class="search"  onclick="return validate();" /></p>
</form>
</div>
</div>
<script>
function validate()
{
	//alert("hello");
	var testing=document.getElementById("validTill").value;
	var collection = document.getElementById("quotationDate").value;
    
     
       
       var collection1 =   collection.split("/");
             
       var DobDate   = collection1[0];
       var DobMonth = collection1[1];       
       var DobYear   = collection1[2];
   
       var testing1 =   testing.split("/");
              
       var SysDate   = testing1[0];
       var SysMonth = testing1[1];
       var SysYear   = testing1[2];
       
       
    // alert("DobYear="+DobYear+"SysYear ="+SysYear +"DobMonth="+DobMonth+"SysMonth="+SysMonth+"DobDate="+DobDate+"SysDate="+SysDate);
       
       
	   
	   if(document.getElementById("site").value=='0')
	   {
	   alert("Must Select Site First");
	   return false;
	   }
	   if(document.getElementById("quotationDate").value=='')
	   {
	   alert("Must Enter Quotations Date First");
	   return false;
	   }
	   if(document.getElementById("party").value=='000')
	   {
	   alert("Must Select  Account Name First");
	   return false;
	   }
	   if(document.getElementById("leadid").value=='0')
	   {
	   alert("Must Select  Against Enquiry First");
	   return false;
	   }
	   if(document.getElementById("validTill").value=='')
	   {
	   alert("Must Select  Valid Till date First");
	   return false;
	   }
	   if(document.getElementById("quotationSite").value=='')
	   {
	   alert("Must Enter Quotation Site");
	   return false;
	   }
	 
	   if(DobYear > SysYear)
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;      
       }
       else if((DobYear == SysYear) && (DobMonth > SysMonth))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false; 
       }
       
        else if((DobYear == SysYear) && (DobMonth == SysMonth) && (DobDate > SysDate))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;
       }
	   
      
         return true;

}
function selectDate()
{
	//alert("hello");
	var testing=document.getElementById("validTill").value;
	var collection = document.getElementById("quotationDate").value;
    
     
       
       var collection1 =   collection.split("/");
             
       var DobDate   = collection1[0];
       var DobMonth = collection1[1];       
       var DobYear   = collection1[2];
   
       var testing1 =   testing.split("/");
              
       var SysDate   = testing1[0];
       var SysMonth = testing1[1];
       var SysYear   = testing1[2];
       
       
    // alert("DobYear="+DobYear+"SysYear ="+SysYear +"DobMonth="+DobMonth+"SysMonth="+SysMonth+"DobDate="+DobDate+"SysDate="+SysDate);
       
       
	   
	  
	 
	   if(DobYear > SysYear)
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;      
       }
       else if((DobYear == SysYear) && (DobMonth > SysMonth))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false; 
       }
       
        else if((DobYear == SysYear) && (DobMonth == SysMonth) && (DobDate > SysDate))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;
       }
	   
      
         return true;

}

function DiscountAmount(DA,i)
{
	var discount_percent = document.getElementById("PerAmo1_"+i).value;
	var discount = document.getElementById("Discount1_"+i).value;
	var total = document.getElementById("stock_value1_"+i).value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}	
	
	document.getElementById("perc1_"+i).value=percent.toFixed(2);
	document.getElementById("value_dis1_"+i).value=subTotal.toFixed(2);
	
	
}



function DiscountAmount2(DA,i)
{
	var discount_percent = document.getElementById("hrdPerAmo1_"+i).value;
	var discount = document.getElementById("hrdDiscount1_"+i).value;
	var total = document.getElementById("hrdstock_value1_"+i).value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}	
	var data=calculateBasic_estimation();
	
	document.getElementById("hrdperc1_"+i).value=percent.toFixed(2);
	document.getElementById("hrdvalue_dis1_"+i).value=subTotal.toFixed(2);
	
	
}








function DiscountAmount1(DA,str)
{
  var k=str.split("_");
  
  if(k[1]==undefined)
  {
   
	var discount_percent = document.getElementById("PerAmo").value;
	var discount = document.getElementById("Discount").value;
	var total = document.getElementById("stock_value").value;
	}
	else
	{
	var i=k[1];
	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var total = document.getElementById("stock_value_"+i).value;
	}
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0; var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0; var percent=0;}
	else
	{
	var percent = parseFloat(DA);
	}
	var subTotal = parseFloat(total)-percent;
	
	}	
	if(k[1]==undefined)
	{
	document.getElementById("perc").value=percent.toFixed(2);
	document.getElementById("value_dis").value=subTotal.toFixed(2);
	}
	else
	{
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("value_dis_"+i).value=subTotal.toFixed(2);
	}
	
}
function addRow(tableID) 
{
	if(document)
	if(document.getElementById("count1").value!='')
	{
		var edit_cnt=parseInt(document.getElementById("count1").value);
	}
	else
	{
	edit_cnt=1;
	}
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("stock_perunit_"+newCount).value='1';
	}
	
function deleteRow(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
		document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
		}
		catch(e) 
		{
			alert(e);
		}

}	
function ship_data()
{
if(document.getElementById("shipping_data").checked==true)
{
document.getElementById("showship").style.display="none";
document.getElementById("show1ship").style.display="block";
document.getElementById("shipcity").style.display="none";
document.getElementById("shipcity1").style.display="block";
document.getElementById("shipbill").style.display="none";
document.getElementById("shipbill1").style.display="block";

var billing_add=document.getElementById("address1").value;
var e=document.getElementById("country");
var billing_country=e.options[e.selectedIndex].text;
var f=document.getElementById("state");
var state=f.options[f.selectedIndex].text;
var g=document.getElementById("city");
var city=g.options[g.selectedIndex].text;
var zipcode=document.getElementById("zipcode").value;
document.getElementById("Shipping_address").value=billing_add;
document.getElementById("Shipping_country").value=billing_country;
document.getElementById("Shipping_state").value=state;
document.getElementById("Shipping_city").value=city;
document.getElementById("Shipping_zipcode").value=zipcode;
}
else
{
document.getElementById("showship").style.display="block";
document.getElementById("show1ship").style.display="none";
document.getElementById("shipcity").style.display="block";
document.getElementById("shipcity1").style.display="none";
document.getElementById("shipbill").style.display="block";
document.getElementById("shipbill1").style.display="none";
document.getElementById("Shipping_address").value='';
document.getElementById("Shipping_country").value='';
document.getElementById("Shipping_state").value='';
document.getElementById("Shipping_city").value='';
document.getElementById("Shipping_zipcode").value='';
}
}

function DiscountAmountvalue(DA)
{

var discount_percent = document.getElementById("PerAmount").value;
	var discount = document.getElementById("Discount_amount").value;
	var total = document.getElementById("basicAmount").value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}		
	document.getElementById("discountperc").value=percent.toFixed(2);
	document.getElementById("afterdiscountprice").value=subTotal.toFixed(2);
	
}

function showdata(str)
{
    
    var site=document.getElementById("leadid").value;
	if (str.length==0)
	{	
	}
	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","restrecords.php?id="+str+"&site="+site,true);
	xmlhttp.send();
}

function undo()
{
  var site=document.getElementById("leadid").value;
	
	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","undodata.php?id="+site,true);
	xmlhttp.send();

}


function open_items()
{

var site=document.getElementById("site").value;

var store='';
var date=document.getElementById("quotationDate").value;

window.open("crmquotes.php?site="+site+"&store="+store+"&date="+date+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}



function deactivate(str)
{
	 var confirmText = "Are you sure you want to delete this Item?";
    if(confirm(confirmText))
	{
		var qty=document.getElementById("hrdqty1A_"+str).value;
		var n=qty.split(",");
		var count=n.length;
		for(var j=0;j<count;j++)
		{
			var fin=parseFloat(n[j]);
			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
			var diff=hrdqty-fin;
			document.getElementById("hrdstock_qty2_"+j).value=diff;
			
		}
		//document.getElementById("itemid1_"+str).value='';
		//document.getElementById("active_"+str).style.display='block';
		document.getElementById("itemid1_"+str).value='';
		document.getElementById("deactive_"+str).style.display='none';
		document.getElementById("hide_"+str).style.display='none';
		//alert('Item removed');
		//calqty(str);
		//caltotal(str);
		calculateBasic();
	}
}

function deactivate1(str)
{
	 var confirmText = "Are you sure you want to delete this Item?";
    if(confirm(confirmText))
	{
		//var qty=document.getElementById("hrdqty1A_"+str).value;
		//var n=qty.split(",");
//		var count=n.length;
//		for(var j=0;j<count;j++)
//		{
//			var fin=parseFloat(n[j]);
//			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
//			var diff=hrdqty-fin;
//			document.getElementById("hrdstock_qty2_"+j).value=diff;
//		}
		//document.getElementById("itemid1_"+str).value='';
		//document.getElementById("active_"+str).style.display='block';
		document.getElementById("itemid1_"+str).value='';
		document.getElementById("deactive_"+str).style.display='none';
		document.getElementById("hide_"+str).style.display='none';
		//alert('Item removed');
		//calqty(str);
		//caltotal(str);
		calculateBasic();
	}
}


//function showalldata(str)
//{
//	if (str.length==0)
//	{	
//	}
//	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
//	}
//	}
//	xmlhttp.open("GET","restrecords.php?id="+str+"&site="+site,true);
//	xmlhttp.send();
//
//
//
//
//}

function showalldata(str)
{
	if (str.length==0)
	{	
	}
	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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("address1").value=data[0];
	document.getElementById("country").innerHTML=data[1];
	document.getElementById("state").innerHTML=data[2];
	document.getElementById("city").innerHTML=data[3];
	document.getElementById("zipcode").innerHTML=data[4];
		
	//document.getElementById("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","restrecords_client.php?id="+str,true);
	xmlhttp.send();




}



function showqty2(id)
{
 var k=id.split("_");
var amt=document.getElementById("stockqty_"+k[1]).value;
if(amt=='') { amt=0; } 
var totalamt=document.getElementById("stock_value_"+k[1]).value;
if(totalamt=='') { totalamt=0; } 

var price=parseFloat(totalamt)/parseFloat(amt);
document.getElementById("stock_price_"+k[1]).value=price.toFixed(2);

}
function showqty4(id)
{
 var k=id.split("_");
var amt=document.getElementById("secondary_"+k[1]).value;
if(amt=='') { amt=0; } 
var totalamt=document.getElementById("stock_value_"+k[1]).value;
if(totalamt=='') { totalamt=0; } 

var price=parseFloat(totalamt)/parseFloat(amt);
document.getElementById("stock_price_"+k[1]).value=price.toFixed(2);

}


function showrecordsdata(j)
{
  
   if(document.getElementById("addhrdAmt_"+j).checked==true)
   {
   document.getElementById("addhrdAmt_"+j).value=1;
   }
   else
   {
    document.getElementById("addhrdAmt_"+j).value=0;
   
   }
  
	        var size_array= new Array();
			//var item_array=new Array();
myCheckboxArray = document.frm1.elements["addhrdAmt[]"];
var t=myCheckboxArray.length;
if(t!=undefined)
{
	for(var i=0;i<=t+1;i++)
	{
	   if(document.getElementById("addhrdAmt_"+i))
	   {
		if(document.getElementById("addhrdAmt_"+i).checked==true)
		{
		size_array[i]=document.getElementById("hrdid_"+i).value;
		}
		}
	}
}	
else
{
 if(document.getElementById("addhrdAmt_"+j).checked==true)
		{
        size_array[0]=document.getElementById("hrdid_"+j).value;
        }
}	
	
	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	//document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	
	}
	}
	var leadid=document.getElementById("leadid").value;
	xmlhttp.open("GET","crm_getEstimationrecord_hardware_remove.php?estimationid="+size_array+"&estid="+leadid,true);
	xmlhttp.send();






}


function calculateBasic_estimation()
{
	var totalBasic_excise=0;
	var totalBasic2_nonexciseble=0;
	
	var fincount=document.getElementById("hrdcount1").value;
	for(var i=0;i<fincount;i++)
	{
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{
	if(document.getElementById("itemtype_"+i).value=='Y')
	{  
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{	
	var totalBasic1=document.getElementById("hrdvalue_dis1_"+i).value;
	}
	else
	{
	var totalBasic1=0;
	}
	var totalBasic_excise=parseFloat(totalBasic_excise)+parseFloat(totalBasic1);
	}
	else
	{
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{	
	var totalBasic2=document.getElementById("hrdvalue_dis1_"+i).value;
	}
	else
	{
	var totalBasic2=0;
	}
	var totalBasic2_nonexciseble=parseFloat(totalBasic2_nonexciseble)+parseFloat(totalBasic2);
	
	}
	}
	}
	//var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic4);	
	
	document.getElementById("basicAmount").value=totalBasic_excise;
	document.getElementById("hrdtotalAmt").value=totalBasic2_nonexciseble;
}

function calculatetaxable_tax()
{
var salestaxamt=document.getElementById("VatCstValue").value;
var taxableamt=document.getElementById("taxableAmount").value;
	if(salestaxamt==''){salestaxamt=0;}
	if(taxableamt==''){taxableamt=0;}
	
var totalamt=parseFloat(salestaxamt)+parseFloat(taxableamt);	
document.getElementById("total_taxable_amt").value=totalamt.toFixed(2);
}

function calculatetaxable_hrd()
{
var salestaxamt_hrd=document.getElementById("VatCstValue1").value;
var taxableamt_hrd=document.getElementById("hrdtotalAmt").value;
	if(salestaxamt_hrd==''){salestaxamt_hrd=0;}
	if(taxableamt_hrd==''){taxableamt_hrd=0;}
	
var totalamt=parseFloat(salestaxamt_hrd)+parseFloat(taxableamt_hrd);	
document.getElementById("total_taxable_hrd").value=totalamt.toFixed(2);

}




</script>