<?php  
include('Class_Party.php');
if($_REQUEST['Save']!='' && $_REQUEST['action']!='Edit')
{
	$startYr = explode('-', $_SESSION['financialYrStart']);
	$endYr = explode('-', $_SESSION['financialYrEnd']);
	$startYr[0];
	$endYr[0];
	 $financial=substr($startYr[0],-2)."-".substr($endYr[0],-2); 
	date_default_timezone_set('Asia/Kolkata');
	$sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'prefix');
	
	 if($_SESSION['dealerid'])
	 {
	 	$prefSql="select prefix_code from prefix_tbl where prefix_name = 'Quotes Management'";
		$resultPrfx = DB_query($prefSql,$db);
		$Prefxrow=DB_Fetch_array($resultPrfx);
		$prefixcode=$Prefxrow['prefix_code'];
		
		 $sql="select quotationNo from quotation where site = '".$_REQUEST['site']."' and dealerid='".$_SESSION['dealerid']."' and CompanyId='".$_SESSION['ACGCompanyId']."' and INSTR(`quotationNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
		$result = DB_query($sql,$db);
		$numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['quotationNo']);
			 $maxval = $ExplBill[3]; 
		}
		else
		{$maxval=0;}
	 }
	else
	 {
	 	$prefSql="select prefix_code from prefix_tbl where prefix_name = 'Quotes Management'";
		$resultPrfx = DB_query($prefSql,$db);
		$Prefxrow=DB_Fetch_array($resultPrfx);
		$prefixcode=$Prefxrow['prefix_code'];
		
		
		$sql="select quotationNo from quotation where site = '".$_REQUEST['site']."' and dealerid='".$_SESSION['dealerid']."' and CompanyId='".$_SESSION['ACGCompanyId']."' and INSTR(`quotationNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
		$result = DB_query($sql,$db);
		$numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['quotationNo']);
			 $maxval = $ExplBill[3]; 
		}
		else
		{$maxval=0;}
	 }
	
	
		$strChar=$_REQUEST['site']."/".$prefixcode."/".$financial."/";
		$strFinal = $maxval+1;
		 $strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT);


	$data['site']=$_REQUEST['site'];
	$data['quotationNo']=$strBothFinal;
	$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['pack_forward']=$_REQUEST['pack_forward'];
	$data['delivery']=$_REQUEST['delivery'];
	$data['validity']=$_REQUEST['validity'];
	$data['basicAmount']=$_REQUEST['basicAmount'];
	$data['totalDiscountedPrice']=$_REQUEST['totalDiscountedPrice'];
	$data['exciseDuty']=$_REQUEST['EDBillRate'];
	$data['exciseValue']=$_REQUEST['exciseValue'];
	$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['freightValue']=$_REQUEST['freightValue'];  
	$data['packagingCharges']=$_REQUEST['packagingCharges'];  
	$data['additionalCharges']=$_REQUEST['additionalCharges'];
	$data['order_type']=$_REQUEST['order_type'];
	$data['our_ref_no']=$_REQUEST['our_ref_no'];
	$data['subject']=$_REQUEST['subject'];
	$data['grandTotal']=$_REQUEST['grandTotal'];  
	$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['process_quote_type']='Direct';
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['created_by']=$_SESSION['UserID'];
	$data['created_date']=date('Y-m-d');
	$data['dealerid']=trim($_SESSION['dealerid']);
	$s->RecordInsert('quotation', $data);
	
	
	$masterId=DB_Last_Insert_ID($db,'quotation','id');
	if($masterId!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['item_code']);$cnt++)
	{	
	if($_REQUEST['item_code'][$cnt]!='')
	{
	$data_array['parentId']=$masterId;  
	$data_array['itemCode']=$_REQUEST['item_code'][$cnt];  
	$data_array['quantity']=$_REQUEST['Qty'][$cnt];   
	$data_array['price']=$_REQUEST['price'][$cnt];
	$data_array['totalValue']=$_REQUEST['stock_value'][$cnt];  
	$data_array['EDRate']=$_REQUEST['EDRate'][$cnt];
	$data_array['EDAmt']=$_REQUEST['EDAmt'][$cnt];
	$data_array['requisitionDate']=date('Y-m-d');
	$s->RecordInsert('quotation_details', $data_array);
	}
	}
	}
	$_SESSION['success_msg']="Inserted Successfully";
	$s->pageLocation("index.php?route=CRM/ViewQuotes".$rurl);
}



if($_REQUEST['Save']!='' && $_REQUEST['action']=='Edit')
{
	$insert2="update  quotation set 
	quotationDate='".FormatDateForSQL($_REQUEST['quotationDate'])."',
	partyContact='".$_REQUEST['partyContact2']."',
	quotationType='".$_REQUEST['quotationType']."',  
	quotation_stage='".$_REQUEST['quotation_stage']."',  
	validTill='".FormatDateForSQL($_REQUEST['validTill'])."' where id='".$_REQUEST['QID']."' ";
	$query1=DB_query($insert2,$db);
	unset($_SESSION['qutotation_itemcode']);
	unset($_SESSION['itemcode']);	
	$s->pageLocation("index.php?route=CRM/ViewQuotes".$rurl);	
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">

<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 first_row=document.getElementById("totalamt").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	var totalBasic1=document.getElementById("totalamt_"+i).value;
	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	document.getElementById("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
	
	if(document.getElementById("exciserate").value!=0)
	{
	document.getElementById("EDRate").disabled=true;
	}
	for(var i=1;i<newcount;i++)
	{
	if(document.getElementById("exciserate_"+i).value!=0)
	{
	var flag=1;
	break;
	}
	}
	if(flag==1)
	{
	document.getElementById("EDRate").disabled=true;
	}
	
	
	
	
}



function calculateBasic1(str)
{  
	var rowCount = document.getElementById('dataTable').rows.length;
	var obj1=document.getElementById('stockvalue').value;
	var obj=document.getElementById('stockvalue');
	var arr = obj.id.split("_");
	var rowx1=0;
	if (arr[1]==undefined)
	{
	var nm='';
	}
	else
	{
	var nm='_'+arr[1];
	}
	for(var i=1;i<rowCount;i++)
	{  
	rowx1=parseInt(document.getElementById('stockvalue_'+i).value)+parseInt(rowx1) ;
	}
	rowx1=parseInt(rowx1)+parseInt(obj1)
	document.getElementById('basicAmount').value=rowx1;
}


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 calculateDiscounted1(str)
{
	var rowCount = document.getElementById('dataTable').rows.length;
	var obj1=document.getElementById('discountedprice').value;
	var obj=document.getElementById('discountedprice');
	var arr = obj.id.split("_");
	var rowx1=0;
	if (arr[1]==undefined)
	{
	var nm='';
	}
	else
	{
	var nm='_'+arr[1];
	}
	for(var i=1;i<rowCount;i++)
	{  
	rowx1=parseInt(document.getElementById('discountedprice_'+i).value)+parseInt(rowx1) ;
	}
	rowx1=parseInt(rowx1)+parseInt(obj1)
	document.getElementById('totalDiscountedPrice').value=rowx1;
}

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 calculateExcise(str,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	divid="excisevalue_"+i;
	var amount=document.getElementById("totalamt_"+i).value;
	}
	else
	{
	divid="excisevalue";
	var amount=document.getElementById("totalamt").value;
	}
	if(str.length==0)
	{
	document.getElementById(divid).value="";
	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(divid).value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
	xmlhttp.send();	
} 
	
function calassprice(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	var tot_amt=(70*val)/100;
	document.getElementById("ass_price_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var tot_amt=(70*val)/100;
	document.getElementById("ass_price").value=tot_amt.toFixed(2);
	}
}



function calass_amount(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{ 
	var qty=document.getElementById("qty_"+i).value;
	var ass_value=document.getElementById("ass_price_"+i).value;
	var tot_amt=ass_value*qty;
	document.getElementById("totalassamt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("qty").value;
	var ass_value=document.getElementById("ass_price").value;
	var tot_amt=ass_value*qty;
	document.getElementById("totalassamt").value=tot_amt.toFixed(2);
	}
}

function calculateExcise1(str,id)	
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	divid="excisevalue_"+i;
	var amount=document.getElementById("totalassamt_"+i).value;
	}
	else
	{
	divid="excisevalue";
	var amount=document.getElementById("totalassamt").value;
	}
	if(str.length==0)
	{
	document.getElementById(divid).value="";
	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(divid).value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
	xmlhttp.send();	
} 	



function calculateVATCST(str)
{
	if (str.length==0)
	{
	document.getElementById("vat_rate").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)
	{
    
   
	document.getElementById("vat_rate").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId1="+str,true);
	xmlhttp.send();
}



function calculateEditVATCST()
{
	var rate=document.getElementById("vat_rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}



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 Basic=document.getElementById("basicAmount").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(Basic);
	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;
	if(b==''){b=0;}
	if(c==''){c=0;}
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
}



function calculateGrand()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	if(b==''){b=0;}
	if(c==''){c=0;}
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
}

 

function GetLeads(str)
{
	var site=document.getElementById("site").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)
	{
	document.getElementById("hid_Leads").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","CRM_GetLeads.php?str="+str+"&site="+site,true);
	xmlhttp.send();
	
}


function getorder(str)
{
	if(str!='Consolidate')
	document.getElementById("EDRate").setAttribute('disabled',true);
	else
	document.getElementById("EDRate").removeAttribute('disabled');
	if(str.length==0)
	{
	document.getElementById("showdata").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("showdata").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getorderquotesdata.php?id="+str,true);
	xmlhttp.send();
}



function open_items()
{
	if(document.getElementById("order_type").value=='')
	{
	alert("Must Select Order Type First");	
	}
	else
	{	
		window.open("TelephonicItems.php?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");
	}
}


</script>
<?php 
if($_REQUEST['action']=='Edit')
{ 
	$sql1=DB_query("Select * from quotation where id='".$_REQUEST['QID']."'",$db);
	$result1=DB_fetch_array($sql1);
	$site= $result1['site']; 
	$quotationNo=$result1['quotationNo'];  
	$quotationDate=ConvertSqlDate($result1['quotationDate']);  
	$party=$result1['party'];   
	$quotationType=$result1['quotationType'];
	$quotation_subject=$result1['quotation_subject'];
	$quotation_funnel  =$result1['quotation_funnel'];
	$quotation_stage  =$result1['quotation_stage'];
	$order_type  =$result1['order_type'];
	$enquiryNo =$result1['enquiryNo'];
	$source=$result1['source1'];  
	$partyContact=$result1['partyContact'];  
	$validTill=ConvertSQLDate($result1['validTill']);  
	$pack_forward=$result1['pack_forward'];  
	$freight=$result1['freight']; 
	$payTerms=$result1['payTerms'];  
	$salesTax=$result1['salesTax'];  
	$Excise=$result1['Excise'];  
	$insurance=$result1['insurance'];  
	$basicAmount=$result1['basicAmount'];  
	$totalDiscountedPrice=$result1['totalDiscountedPrice'];  
	$exciseDuty=$result1['exciseDuty'];  
	$exciseValue=$result1['exciseValue'];  
	$ECessValue=$result1['ECessValue'];  
	$SAHCessValue=$result1['SAHCessValue'];  
	$taxableAmount=$result1['taxableAmount'];
	$VatCst=$result1['VatCst'];  
	$VatCstValue=$result1['VatCstValue'];  
	$freightValue=$result1['freightValue'];  
	$packagingCharges=$result1['packagingCharges'];  
	$additionalCharges=$result1['additionalCharges'];  
	$roundOff=$result1['roundOff'];  
	$grandTotal=$result1['grandTotal'];  
	$createdBy=$_SESSION['UserID'];  
	$ConvertIntoSales=$result1['ConvertIntoSales'];  
	$SalesOrderNo=$result1['SalesOrderNo'];  
}
?>
<?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">
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
 <tr class="row1">
    <td colspan="6"><h3 style="color:#003399">General Information</h3></td>
  </tr>
  
  
  
  
  
  
  
  
  
  <tr class="row1">
  	<td colspan="4" style="padding:0px;">
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr class="row1">
    <td width="13%" align="left" valign="top"><strong>Branch</strong><font color="#FF0000">*</font></td>
    <td width="20%" align="left" valign="top"><select name="site" style="width:100%;" onchange="javascript:clientselection(this.value);">
   <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 width="13%" align="left" valign="top"><strong>Quotation No.</strong>	</td>
    <td width="20%" align="left" valign="top" id="CODE"><input name="quotationNo" readonly="" type="text" value="Auto Generated" style="width:150px;"/></td>
    <td width="15%" align="left" valign="top"><strong>Date</strong><font color="#FF0000">*</font></td>
    <td align="left" valign="top"><input type="text" name="quotationDate" readonly value="<?php echo date('d/m/Y'); ?>" style="width:150px;" class="datepicker" /></td>
  </tr>
  
  <tr class="row1">
    <td width="13%" align="left" valign="top"><strong>Client</strong><font color="#FF0000">*</font></td>
    <td width="20%" align="left" valign="top">
	<select name="party" id="party" style="width:150px;"  onChange="getaddress(this.value);" >
      <!--<option value="000">Select</option>
	   <?php
	   			//echo  $_SESSION['UserSites'];
			
				
	   /*	$client_sql=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') 
		and Zone in(".$_SESSION['AssignedSites'].")",$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 width="13%" align="left" valign="top"><strong>Consignee</strong></td>
    <td width="20%" align="left" valign="top"><select name="quotationSite" id="quotationSite" style="width:150px">
	</select></td>
    <td width="15%" align="left" valign="top"><strong>Format</strong><label><font color="#FF0000">*</font></label></td>
    <td align="left" valign="top"><select name="format" style="width:150px;">
      <option value="Standard">Standard</option>
    </select></td>
  </tr>
  <tr class="row1">
    <td width="13%" align="left" valign="top"><strong>Contact Person</strong></td>
    <td width="20%" align="left" valign="top"><select style="width:150px;" name="ContactPerson" id="contact" onchange="getPhoneNo(this.value)">
					<option value="0">--Select--</option>
									
					</select></td>
    
    <td width="13%" align="left" valign="top"><strong>Mobile No.</strong></td>
    <td width="20%" align="left" valign="top"><div id="PhoneNo"><input type="text" readonly name="partyContact2" id="PhoneNo1" style="width:150px" value="<?php if(isset($partyContact)){echo $partyContact;} else { echo $_REQUEST['partyContact'];}?>" /></div></td>
    <td width="15%" align="left" valign="top"><strong>Our Ref No.</strong></td>
    <td align="left" valign="top"><input type="text" name="our_ref_no" id="our_ref_no" value="" style="width:150px;" /></td>
  </tr>
  <tr class="row1">
    <td width="13%" align="left" valign="top"><strong>Type of Quotation</strong><font color="#FF0000">*</font></td>
    <td width="20%" align="left" valign="top"><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>
    
    <td width="13%" align="left" valign="top"><strong>Quote Stage</strong></td>
    <td width="20%" align="left" valign="top"><input type="text" style="width:150px;"  name="quotation_stage" value="<?php  echo $quotation_stage;?>"/></td>
    <td width="15%" align="left" valign="top"><strong>Valid Till</strong><label><font color="#FF0000">*</font></label></td>
    <td align="left" valign="top"><input readonly name="validTill" type="text" value="<?php if(isset($validTill)){echo $validTill;} ?>" style="width:150px;" class="datepicker"/></td>
  </tr>
  <tr class="row1">
    <td width="13%" align="left" valign="top"><strong>Quote Type</strong></td>
    <td width="20%" align="left" valign="top"><select name="order_type" id="order_type" style="width:150px;"   onchange="getorder(this.value)">
                           <option value="TBI">TBI</option>	
               <!-- <option value="MRP_Item">MRP Item Wise </option>	-->
                </select></td>
    
    <td width="13%" align="left" valign="top"></td>
    <td width="20%" align="left" valign="top"></td>
    <td colspan="2" align="left" valign="top">&nbsp;</td>
    </tr>
	<tr class="row1">
    <td width="13%" align="left" valign="top"><strong>Subject</strong></td>
    <td colspan="5" align="left" valign="top"><textarea name="quotationSubject" id="quotationSubject" style="width:100%;"></textarea></td>
    </tr>
</table>
	</td>
	</tr>
  
<tr class="row1">
<td colspan="6" class="tabledata1"><h3 style="color:#003399">Account  Billing  &  shipping  Address  Information   <span style="color:#000;">(Check if Same)</span> <input type="checkbox" name="check" id="check"  onclick="showdatashipping()"/></h3></td>
</tr>


 <tr class="row1"><td class="tabledata1" colspan="4" id="addressdata">
 <table width='100%' border='0' cellspacing='1' cellpadding='2'>
  <tr class="row1">
    <td width="15%" class="tabledata1">Billing Address</td>
    <td width="30%">
    <input type='text' name='address1' style='width:150px;' id='address1'   value="" /></td>
    <td width="15%" class="tabledata1">Shipping Address</td>
    <td id='CODE'><input type='text' name='Shipping_address' id='shipping_address1' style='width:150px;'   value=''/></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Billing city</td>
    <td><input name='city' type='text' id='city'  style='width:150px;' value='' /></td>
    <td class="tabledata1" nowrap='nowrap'>shipping City</td>
    <td><input name='Shipping_city' type='text' id='ship_city'  style='width:150px;' value='' /></td>
  </tr>
	
<tr class="row1">
    <td class="tabledata1">Billing State</td>
    <td>
    <input type='text' name='zipcode' id='state' style='width:150px;'  value='' /></td>
    <td class="tabledata1">Shipping State</td>
    <td><input type='text' name='Shipping_zipcode' id='ship_state' style='width:150px;' value='' /></td>
    </tr>	
	<tr class="row1">
    <td class="tabledata1">Billing Country</td>
    <td><input name='country' type='text' id='country'  style='width:150px;' value='' /></td>
    <td class="tabledata1">Shipping Country</td>
    <td><input name='Shipping_country' type='text' id='ship_country'  style='width:150px;' value='' /></td>
    </tr>
</table>
 </td>
    </tr>
<tr class="row1">
<td colspan="6"><h3 style="color:#003399">Item Details</h3></td>
</tr>
<tr class="row1">
<td colspan="4" style="background-color:#e7e7e7"><p align="left" style="padding-top:5px; padding-bottom:5px;">
<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('dataTable')" value="Delete" />




</p></td></tr>
</table>
<div style="overflow: auto; width:100%;">
<div id="showdata">
<table align="center" width="100%;" border="1" cellpadding="3" cellspacing="0">
<tr bgcolor="#CCCCCC">
<td style="text-align:center;" colspan="11"><strong>Item Details</strong></td></tr>
<tr bgcolor="#CCCCCC">
<td><strong>Sr. No.</strong></td>
<td></td>
<td><strong>Item Code</strong></td>
<td><strong>Item Name</strong></td>
<td><strong>Qty</strong></td>
<td><strong>Price</strong></td>
<td><strong>Total Amt</strong></td>
<td><strong>Excise Duty Rate</strong></td>
<td><strong>ED Amt</strong></td>
</tr>
  <tbody id="dataTable">
  	<tr>
<td style="white-space:nowrap;"><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
</td>	
<td><input type="hidden" name="item_code[]" id="itemid" style="width:100%;" /></td>
<td><input type="text" name="" value="" id="itemcode" style="width:100%;" size="16" /></td>
<td style="white-space:nowrap"><input type="text" name="" value="" id="itemname" style="width:100%;"  size="26" /></td>
<td><input type="text" name="Qty[]" value="" id="qty" size="6" style="width:100%;" /></td>
<td><input type="text" name="price[]" value="" id="price" style="width:100%;" onkeyup="calculateTotalAmt(this.value,this.id)" size="6"/></td>
<td><input type="text" name="stock_value[]" style="width:100%;" value="" id="totalamt" readonly="true" size="9"/></td>
<td><select name="EDRate[]" id="exciserate" style="width:107px; width:100%;" 
onchange="calculateExcise(this.value,this.id)">
<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($edit_EDRate==$ServiceRow['id']?'selected':'') ?>><?php echo $ServiceRow['caption'];?></option>
<?php	
}
?>
</select></td>
<td><input type="text" name="EDAmt[]" value="" id="excisevalue" style="width:100%;" size="5"/></td>

</tr>
</tbody>
 </table>
 </div>
 </div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" />
<br>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td valign="top" width="50%">
	<!--<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
		<tr class="row1">
		<td colspan="2" class="tabledata1" style="text-align:center;"><strong>Terms And Conditions</strong></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1" width="19%" scope="row">Pkg &amp; Forwarding</td>
		<td class="tabledata1" width="28%" nowrap="nowrap">
		<select name="pack_forward" id="menu1" style="width:107px;" 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="" style="width:auto;" />
		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Freight</td>
		<td><select name="freight" id="menu2"
		style="width:107px;;" 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="" style="width:auto;" /></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Payment Terms</td>
		<td><select name="payTerms" style="width:107px;">
		<?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 class="row1">
		<td class="tabledata1">Sales Tax</td>
		<td><select name="salesTax" id="menu3" style="width:107px;" 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="" style="width:auto;"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Excise</td>
		<td><select name="Excise" id="" style="width:107px;" 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="" style="width:auto;" /></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1" nowrap="nowrap">Insurance</td>
		<td><select name="insurance" id="menu4" style="width:107px;" 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="" style="width:auto;"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Delivery</td>
		<td colspan="2"><input type="text" name="delivery" id="delivery" style="width:215px;" /></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Validity</td>
		<td colspan="2"><input type="text" name="validity" id="validity" style="width:215px;" /></td>
		</tr>
	</table>	-->
</td>
<td valign="top">
	<table width="90%" border="0" cellspacing="0" cellpadding="3" align="right" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
		<tr class="row1">
		<td colspan="3" class="tabledata1" style="text-align:center;"><strong>Amount And Taxes</strong></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Value Of Goods<label><font color="#FF0000">*</font></label></td>
		<td><input name="basicAmount" type="text"  style="width:150px;" onfocus="calculateBasic()" id="basicAmount"/></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>
		
		<input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:150px;" onfocus="calculateTotalExcise()"/>
		
		
		</td>
		
		</tr>
		<tr class="row1">
		
		<td class="tabledata1">E-Cess</td>
		<td>
		<?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%Edu Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<input type="hidden" name="ECessID" value="<?php echo $RESULT['id']?>" style="width:107px;">
		
		<input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:107px" />
		<input name="ECessValue" id="ECessValue" type="text"   readonly onfocus="calculateECess()" style="width:107px"/></td>
		</tr>
		<tr class="row1">
		
		<td class="tabledata1">SHE Cess </td>
		<?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%SHE Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		
		
		
		<td>
		<input type="hidden" name="SHECessId" value="<?php echo $RESULT['id']?>" style="width:107px;">
		
		<input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>" style="width:107px;" readonly/>
		<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:107px;" 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" style="width:150px;" onfocus="calculateTaxable()"/></td>
		</tr>
		<tr class="row1">
		
		<td class="tabledata1">VAT/CST</td>
		<td>
		<select name="VatCst" id="value3" onchange="calculateVATCST(this.value)" style="width:150px;">
		<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="vat_rate" value="<?php echo $rate;?>" /> 
		
		</td>
		
		</tr>
		<tr class="row1">
		
		<td class="tabledata1"><strong>Grand Total</strong><label><font color="#FF0000">*</font></label></td>
		<td><input name="grandTotal" id="grandTotal" type="text"  style="width:150px;" onfocus="calculateGrand()" readonly="readonly"  /></td>
		
		</tr>
	</table>
</td>
</tr>
</table>
<p align="center"><input type="submit" name="Save" value="Save" class="search"/></p>
</form>
</div>
</div>
<script>
	
function openPopupProfile(i)
{ 
	var site=document.getElementById("site").value;
	window.open("pickcrmquotesitems.php?rowcount="+i+"&site="+site,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}

function calamount(obj)
{
	var rowCount = document.getElementById('dataTable').rows.length;
	var arr = obj.id.split("_");
	if (arr[1]==undefined)
	{
	var nm='';
	var stock_qty=document.getElementById('stockqty').value;	  
	var stock_price=document.getElementById('stockprice').value;	
	var stock_perunit=document.getElementById('stockperunit').value;
	var price=0;
	var amount=0;	
	if(stock_perunit>1)
	{
	price=parseFloat(document.getElementById('stockprice').value)/parseFloat(document.getElementById('stockperunit').value);	
	amount=parseFloat(document.getElementById('stockqty').value)*price; 
	}
	else
	{
	price=parseFloat(document.getElementById('stockprice').value);
	amount=parseFloat(document.getElementById('stockqty').value)*price;    
	}   
	document.getElementById('stockvalue').value=amount;
	}
	else
	{
	var nm='_'+arr[1];
	}
	for(var i=1;i<rowCount;i++)
	{	
	var stock_qty=document.getElementById('stockqty'+nm).value;
	var stock_price=document.getElementById('stockprice'+nm).value;
	var stock_perunit=document.getElementById('stockperunit'+nm).value;
	if(stock_perunit>1)
	{
	var price=parseFloat(document.getElementById('stockprice'+nm).value)/parseFloat(document.getElementById('stockperunit'+nm).value);	
	var amount=parseFloat(document.getElementById('stockqty'+nm).value)*price;
	}
	else
	{
	var price=parseFloat(document.getElementById('stockprice'+nm).value);
	var amount=parseFloat(document.getElementById('stockqty'+nm).value)*price;	
	}
	document.getElementById('stockvalue'+nm).value=amount;
	}
}



function caldiscount(obj)
{
	var rowCount = document.getElementById('dataTable').rows.length;
	var arr = obj.id.split("_");
	if (arr[1]==undefined)
	{
	var nm='';
	var discounttype=document.getElementById('discountType').value;
	var tvalue=parseFloat(document.getElementById('stockvalue').value);
	if(discounttype=='A')
	{
	var amount=tvalue-parseFloat(document.getElementById('discount1').value);	
	}	
	else
	{
	var amount=(tvalue*parseFloat(document.getElementById('discount1').value))/100;	
	}	
	document.getElementById('valueAfterDisc').value=amount.toFixed(2);
	var discountprice=parseFloat(tvalue)-parseFloat(amount);	
	document.getElementById('discountedprice').value=discountprice;	
	}
	else
	{
	var nm='_'+arr[1];
	}
	for(var i=1;i<rowCount;i++)
	{	
	var discounttype=document.getElementById('discountType'+nm).value;
	var tvalue=parseFloat(document.getElementById('stockvalue'+nm).value);
	if(discounttype=='Amount')
	{
	var amount=tvalue-parseFloat(document.getElementById('discount1'+nm).value);	
	}	
	else
	{
	var amount=(tvalue*parseFloat(document.getElementById('discount1'+nm).value))/100;	
	}	
	document.getElementById('valueAfterDisc'+nm).value=amount.toFixed(2);
	var discountprice=parseFloat(tvalue)-parseFloat(amount);	
	document.getElementById('discountedprice'+nm).value=discountprice;	
	}
}



function addRow(tableID) 
{
	if(document)
	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 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+'_'+rowCount;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	}
	}
}



function deleteRowOrder(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 calculateTotalAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	var qty=document.getElementById("qty_"+i).value;
	var tot_amt=qty*val;
	document.getElementById("totalamt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("qty").value;
	var tot_amt=qty*val;
	document.getElementById("totalamt").value=tot_amt.toFixed(2);
	}
}


	
function calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	var first_row=document.getElementById("excisevalue").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise)+parseFloat(first_row);
	}
	else{return false;}
}

	

//function getaddress(str)
//{
//	if (str.length==0)
//	{
//	document.getElementById("addressdata").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("addressdata").innerHTML=xmlhttp.responseText;
//	}
//	}
//	xmlhttp.open("GET","showcrnaddressdetails.php?party="+str,true);
//	xmlhttp.send();	
//}


function getaddress(str)
{
	if (str.length==0)
	{
	document.getElementById("addressdata").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)
	{
	//alert(xmlhttp.responseText);
	var data=xmlhttp.responseText.split("__");
	//alert(data[1]);
	document.getElementById("addressdata").innerHTML=data[0];
	document.getElementById("quotationSite").innerHTML=data[1];	
	document.getElementById("contact").innerHTML=data[2];
	//document.getElementById("contact").innerHTML=data[2];
	}
	}
	xmlhttp.open("GET","direct_showcrnaddressdetails.php?party="+str,true);
	xmlhttp.send();	
}




function showdatashipping()
{
	if(document.getElementById("check").checked==true)	
	{
	document.getElementById("shipping_address1").value=document.getElementById("address1").value;
	document.getElementById("ship_city").value=document.getElementById("city").value;
	document.getElementById("ship_state").value=document.getElementById("state").value;	
	document.getElementById("ship_country").value=document.getElementById("country").value;
	}
	else
	{
	document.getElementById("shipping_address1").value='';
	document.getElementById("ship_city").value='';
	document.getElementById("ship_state").value='';	
	document.getElementById("ship_country").value='';	
	}	
}




function calculateBillExcise(str)
{
	var value=document.getElementById("basicAmount").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?type2=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	
}


function getPhoneNo(str)
{
	if(str.length==0)
	{
	document.getElementById("PhoneNo").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("PhoneNo").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getPhone1.php?Contact="+str,true);
	xmlhttp.send();	
} 

function clientselection(str)
{
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)
		{
			//alert(xmlhttp.responseText);
            document.getElementById("party").innerHTML=xmlhttp.responseText;			
		}
	}
	//var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","ajax_quotation1.php?site="+str,true);
	xmlhttp.send();
}

</script>