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

//*******************SERVER SIDE VALIDATION*************AMIT SINGH***************27-10-2012*******************************

if($_REQUEST['Save']!='' && $_REQUEST['action']=='Edit')
{
	$fstatus=true;
	if($_REQUEST['site']=='0')
	{
	$msgErr[]="Please Select The Branch";
	$fstatus=false;
	}
	if($_REQUEST['quotationNo']=='')
	{
	$msgErr[]="Please Enter The Quotation No";
	$fstatus=false;
	}
	if($_REQUEST['quotationDate']=='')
	{
	$msgErr[]="Please Enter The Quotation Date";
	$fstatus=false;
	}
	if($_REQUEST['party']=='0')
	{
	$msgErr[]="Please Select The Party ";
	$fstatus=false;
	}
	if($_REQUEST['quotationType']=='0')
	{
	$msgErr[]="Please Select The Quotation Type ";
	$fstatus=false;
	}
	/*if($_REQUEST['enquiryNo']=='')
	{
	$msgErr[]="Please Enter The Enquiry No ";
	$fstatus=false;
	}*/
	if($_REQUEST['validTill']=='')
	{
	$msgErr[]="Please Enter The Valid Date ";
	$fstatus=false;
	}
	if($_REQUEST['basicAmount']=='')
	{
	$msgErr[]="Please Enter The Basic Amount   ";
	$fstatus=false;
	}
	if($_REQUEST['totalDiscountedPrice']=='')
	{
	$msgErr[]="Please Enter The Total Discount Price   ";
	$fstatus=false;
	}
	if($_REQUEST['taxableAmount']=='')
	{
	$msgErr[]="Please Enter The Taxable Amount ";
	$fstatus=false;
	}
	if($_REQUEST['grandTotal']=='')
	{
	$msgErr[]="Please Enter The Grand Total ";
	$fstatus=false;
	}
}

//*******************SERVER SIDE VALIDATION*************AMIT SINGH***************27-10-2012*******************************



//*******************DELETE ITEMS*************AMIT SINGH***************START HERE******************************************


if($_REQUEST['act']=='delitem' && $_REQUEST['id']!='')
{
	$condition="id='".$_REQUEST['id']."'";
	$s->DeleteRecord('quotation_details',  $condition);
	echo "<script>location.href='index.php?route=CRM/CRM_Dir_Quotes_Edit&action=Edit&QID=".$_REQUEST['QID']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

//*******************DELETE ITEMS*************AMIT SINGH***************END HERE******************************************



//*******************FETCH DATA FROM PARANT TABLE*************AMIT SINGH***************START HERE************************


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'];
	$hrdtotalAmt=$result1['hrdtotalAmt'];
	$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']; 
	$ContactPerson=$result1['contactPerson'];
	$OrderType=$result1['order_type'];
	$our_ref_no=$result1['our_ref_no'];
	$subject=$result1['subject'];
	$billing_address=$result1['billing_address'];
	$billing_city=$result1['billing_city'];
	$billing_state=$result1['billing_state'];
	$billing_country=$result1['billing_country'];
	$shipping_address=$result1['shipping_address'];
	$shipping_city=$result1['shipping_city'];
	$shipping_state=$result1['shipping_state'];
	$shipping_country=$result1['shipping_country'];
	$delivery=$result1['delivery'];
	$validity=$result1['validity'];
	$basicAmount=$result1['basicAmount'];
	$totalDiscountedPrice=$result1['totalDiscountedPrice'];
	$exciseDuty=$result1['exciseDuty'];
}

//*******************FETCH DATA FROM PARANT TABLE*************AMIT SINGH***************END HERE************************



//*******************UPADET RECORDS*************AMIT SINGH***************START HERE************************************

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

	$data['site']=$_REQUEST['site'];
	$data['quotationNo']=$_REQUEST['quotationNo'];
	$data['quotationDate']=FormatDateForSQL($_REQUEST['quotationDate']);
	$data['party']=$_REQUEST['party'];
	$data['quotationType']=$_REQUEST['quotationType'];
	$data['quotation_subject']=$_REQUEST['quotation_subject'];
	$data['quotation_funnel']=$_REQUEST['quotation_funnel'];
	$data['quotation_stage']=$_REQUEST['quotation_stage'];
	$data['enquiryNo']=$_REQUEST['leadid'];
	$data['source']=$_REQUEST['source1'];
	$data['contactPerson']=$_REQUEST['ContactPerson'];
	$data['partyContact']=$_REQUEST['partyContact2'];
	$data['validTill']=ConvertSQLDate($_REQUEST['validTill']);
	$data['pack_forward']=$_REQUEST['pack_forward'];
	$data['freight']=$_REQUEST['freight'];
	$data['payTerms']=$_REQUEST['payTerms'];
	$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['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['roundOff']=$_REQUEST['roundOff'];  
	$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['process_quote_type']='Direct';
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	
	$cond1="id='".$_REQUEST['QID']."'";
	$s->RecordEdit('quotation', $data, $cond1);// UPDATE ON PARANT TABLE

	for($i=0;$i<count($_REQUEST['row_id']);$i++)
	{	
	$data_array['quantity']=$_REQUEST['Qty'][$i];   
	$data_array['price']=$_REQUEST['price'][$i];
	$data_array['totalValue']=$_REQUEST['stock_qty'][$i];  
	$data_array['mrp_unit']=$_REQUEST['mrp_per'][$i];
	$data_array['ass_price']=$_REQUEST['ass_price'][$i];
	$data_array['total_ass_price']=$_REQUEST['total_ass_price'][$i]; 
	$data_array['EDRate']=$_REQUEST['EDRate'][$i];
	$data_array['EDAmt']=$_REQUEST['EDAmt'][$i];
	
	$cond2="id='".$_REQUEST['row_id'][$i]."'";
	$s->RecordEdit('quotation_details', $data_array, $cond2);// UPDATE ON OLD ITEM
	}
	
	for($j=0;$j<count($_REQUEST['item_code1']);$j++)
{
	if($_REQUEST['item_code1'][$j]!='')
	{
		$data_arr['parentId']=$_REQUEST['QID'];
		$data_arr['itemCode']=$_REQUEST['item_code1'][$j];
		$data_arr['quantity']=$_REQUEST['Qty1'][$j];
		$data_arr['price']=$_REQUEST['price1'][$j];
		$data_arr['PerUnits']=1;
		$data_arr['totalValue']=$_REQUEST['stock_qty1'][$j];
		$data_arr['EDRate']=$_REQUEST['EDRate1'][$j];
		$data_arr['EDAmt']=$_REQUEST['EDAmt1'][$j];
		$data_arr['mrp_unit']=$_REQUEST['mrp_per1'][$j];
	   	$data_arr['ass_price']=$_REQUEST['ass_price1'][$j];
	    $data_arr['total_ass_price']=$_REQUEST['total_ass_price1'][$j];
		$rowinsert= $s->RecordInsert('quotation_details', $data_arr);// INSERT NEW ITEM
	}
}
	
	
	$_SESSION['success_msg']="UPDATED Successfully";
	$s->pageLocation("index.php?route=CRM/ViewQuotes".$rurl);
}

//*******************UPADET RECORDS*************AMIT SINGH***************END HERE************************************



?>
<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;
	if(cnt==''){cnt=0;}
	var edit_cnt=document.getElementById("edit_cnt").value;
	var new_count=parseInt(edit_cnt)+parseInt(cnt); 
	for(var i=0;i<new_count;i++)
	{
	 	var totalBasic1=document.getElementById("totalamt_"+i).value;
		//alert(totalBasic1);
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
		//alert(totalBasic);
		//alert("1st = "+first_row);
	  document.getElementById("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
}



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("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 calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}*/

function calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	if(document.getElementById("taxableAmount").value!='')
	var assembly=document.getElementById("hardamt").value;
	else
	var assembly=0;
	
	var taxableAmount1=parseFloat(taxableAmount)+parseFloat(assembly);
	var vat_cst=taxableAmount1*(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("directTelephonicItemsedit.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 //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%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Direct Quote Offer To Customer</h3></td>
 </tr>
<?php


if(count($msgErr>0))
{
?>
<tr><td colspan="4">
<?php
for($k=0;$k<count($msgErr);$k++) 
{
echo "<div class='error'>".$msgErr[$k]."</div>";
}
?>	
</td></tr>	
<?php	
} 
?>	
<tr class="row1">
    <td class="tabledata1" >Branch<label><font color="#FF0000">*</font></label></td>
    <td>
    <select name="site"   id="site" onChange="ShowDiv(this.value,'CODE','codeGenerator.php?quotesite=crmquotes');" 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="<?php echo $quotationNo;?>" 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 if(isset($quotationDate)){echo $quotationDate;}?>" style="width:150px;" class="datepicker" /></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">Client Name<font color="#FF0000">*</font></td>
    <td>
    	<?php
		
	 // echo "Select vender_client,AccountsID,AccountName,ledgertype from accountledger where ledgertype in('leads','client')";
		?>
	<select name="party" style="width:150px;"  onChange="getaddress(this.value);" >
      <option value="000">Select</option>
	   <?php  //echo $ClassParty->PartList($party);?>
	   
	   <?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 class="tabledata1" >Type of Quotation<font color="#FF0000">*</font></td>
    <td><select name="quotationType" style="width:150px;">
      <option value="M"<?php echo($quotationType=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo($quotationType=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo($quotationType=='R'?'selected':'')?>>Retail</option>
    </select></td>
    </tr>
<tr class="row1">
    <td class="tabledata1" >Quote Stage</td>
    <td><input type="text" style="width:150px;"  name="quotation_stage" value="<?php  echo $quotation_stage;?>"/></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"/></td>
	
	 </tr>
<tr class="row1">
  	 <td class="tabledata1" >Contact Person</td>
    <td><select style="width:150px;" name="ContactPerson" onchange="getPhoneNo(this.value)">
                   
					<option value="0">--Select--</option>
					<?php 
					  $SQL="Select * from contact_information_master ";
											
					$Res=DB_query($SQL,$db);
					while($Row=DB_fetch_array($Res))
					{
					?>
					<option value="<?php echo $Row['id']?>" <?php echo($ContactPerson==$Row['id']?'selected':'')?>><?php echo $Row['person']?></option>
					<?php  } ?>
					
					</select></td>
   	<td class="tabledata1" >Mobile No.</td>
    <td><div id="PhoneNo"><input type="text" name="partyContact2" id="PhoneNo1" style="width:150px;" value="<?php if(isset($partyContact)){echo $partyContact;} else { echo $_REQUEST['partyContact'];}?>" /></div></td>
 
    </tr>
<tr class="row1">
  <td class="tabledata1" >Quote Type</td>
                <td><select name="order_type" id="order_type" style="width:150px;"   >
                   <option value="Consolidate"<?php echo($OrderType=='TBI'?'selected':''); ?>>TBI </option>	
                <option value="MRP_Item"<?php echo($OrderType=='MRP_Item'?'selected':''); ?>>MRP Item Wise </option>	
                </select></td>
				<td class="tabledata1" >Our Ref No.</td>
	<td><input type="text" name="our_ref_no" id="our_ref_no" value="<?php echo $our_ref_no; ?>" style="width:150px;" /></td>
  </tr>
<tr class="row1">
  	<td class="tabledata1" >Subject</td>
	<td colspan="3"><textarea name="subject" style="width:627px;"><?php echo $subject; ?></textarea></td>
  </tr>
<tr class="row1">
    <td colspan="6"><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>

<?php 
 if($_REQUEST['action']=='Edit')
 {
     $getlead=DB_query( "select * from crm_accounts where mst_leadid='".$enquiryNo."'  ",$db);
	 while($row_lead=DB_fetch_array($getlead))
	 {
		$leadcode=$row_lead['leadcode'];
		$company_name=$row_lead['company_name'];
		$address1=$row_lead['address1'];
		$groupid=$row_lead['groupid'];
		$city=$row_lead['city'];
		$zipcode=$row_lead['zipcode'];
		$country=$row_lead['country'];
		$Shipping_address=$row_lead['Shipping_address'];
		$Shipping_zipcode=$row_lead['Shipping_zipcode'];
		$Shipping_city=$row_lead['Shipping_city'];
		$Shipping_country=$row_lead['Shipping_country'];

  	 }
 }
?>

<tr class="row1">
    <td class="tabledata1" >Billing Address</td>
    <td>
    <input type="text" name="address1" style="width:150px;" id="address1"   value="<?php  echo $billing_address;?>"/></td>
    <td class="tabledata1" >Shipping Address</th>
    <td id="CODE"><input type="text" name="Shipping_address" style="width:150px;" id="shipping_address1"   value="<?php  echo $shipping_address;?>"/></td>
  </tr>
<tr class="row1">
    <td class="tabledata1" >Billing city</td>
    <td><input name="city" type="text" id="city"  style="width:150px;" value="<?php  echo $billing_city;?>"/></td>
    <td class="tabledata1" >shipping City</td>
    <td><input name="Shipping_city" type="text" id="ship_city"  style="width:150px;" value="<?php  echo $shipping_city?>"/></td>
  </tr>
<tr class="row1">
    <td class="tabledata1" >Billing State</td>
    <td>
    <input type="text" name="zipcode" style="width:150px;" id="state"  value="<?php  echo $billing_state?>" /></td>
    <td class="tabledata1" >Shipping State</td>
    <td><input type="text" name="Shipping_zipcode" id="ship_state" style="width:150px;"  value="<?php  echo $shipping_state?>" /></td>
    </tr>
<tr class="row1">
    <td class="tabledata1" >Billing Country</td>
    <td><input name="country" type="text" id="country"  style="width:150px;" value="<?php  echo $billing_country;?>"/></td>
    <td class="tabledata1" >Shipping Country</td>
    <td><input name="Shipping_country" type="text" id="ship_country"  style="width:150px;" value="<?php  echo $shipping_country;?>"/></td>
    </tr>
<tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Item Details</h3></td>
  </tr>
<tr class="row1">
    <td colspan="6"><p 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" />&nbsp;
<input type="button" onclick="deleteRow('dataTable')" value="Delete" class="search" />
</p></td>
  </tr>
</table>
 
<div id="showdata">
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border:#666666 solid 1px;">
              <tr class="row1">
                <td width="42" class="tabledata">S.No</td>
				<td class="tabledata" width="5"></td>
				<td class="tabledata" width="80">Item Code</td>
				<td width="150" class="tabledata">Item Name. </td>
				<td width="90" class="tabledata" style="text-align:center;">Size</td>
              <td colspan="2" class="tabledata" style="text-align:center;" width="120">Quantity</td>
                <td class="tabledata">Price</td>
                <td class="tabledata">Total Amt</td>
                <?php if($OrderType!='TBI' && $OrderType!='' ) {  ?>
                 <th class="tabledata" align="center">MRP /Unit</th>
                <th class="tabledata" align="center">Ass Price</th>
                <th class="tabledata" align="center">Total Ass Value</th>
                <?php }?>
                <td class="tabledata">Excise Duty Rate</td>
                <td class="tabledata">ED Amt</td>
              </tr>
		<!-------------Add ITEMS IN THE ITEM LIST AT TIME OF EDIT----------------------->
<?php 
 $i=0;
 //echo "Select * from quotation_details where parentId='".$_REQUEST['QID']."'";
  $ItemSQL=DB_query("Select * from quotation_details where parentId='".$_REQUEST['QID']."'",$db);
  while($item_row1=DB_fetch_array($ItemSQL))
  {
 
	//echo "select * from item_master where id='".$item_row1[ItemCode]."'";
	 $itemquery=DB_query("select * from item_master where id='".$item_row1['itemCode']."'" , $db);
	$item_row=DB_fetch_array($itemquery);
	 //echo "select StockID,item_name,unit, make ,grade, color from item_master where StockID='".$itemlist[$i]."'" ;
	
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
		
		
		
	
	
	?>
	
	<tr bgcolor="<?php //echo $bg;?>"  class="row1">
	<td class="tabledata"><a href="index.php?route=CRM/CRM_Dir_Quotes_Edit&action=Edit&QID=<?php echo $_REQUEST['QID'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delitem&id=<?php echo $item_row1['id'];?>"><img src="images/delete.gif" /></a>
	<?php //echo $i+1;?></td>
	<td class="tabledata"><input type="hidden" name="row_id[<?php echo $i; ?>]" id="row_id" value="<?php echo $item_row1['id']?>" /></td>	
	<td  class="tabledata">
	<input type="hidden" name="itemid[<?php echo $i; ?>]" value="<?php echo $item_row['id'];?>" />
	<input type="hidden" name="item_code[<?php echo $i;?>]" id="item_code_<?php echo $i;?>" value="<?php echo $item_row['StockID'];?>" readonly  size="6">	
	<?php echo $item_row['StockID'];?>
				
   <input type="hidden" value="<?php echo $item_row['StockID'];?>" tabindex=""  readonly="" id="washing_profile" name="itemcode[]"   />
   <input type="hidden" name="salesdetailid[<?php echo $i;?>]" value="<?php echo $item_row1['id'];?>"  />
   <input type="hidden" name="itemid[<?php echo $i;?>]" value="<?php echo $item_row['id'];?>" />
	</td>	
   <td class="tabledata">
				<?php echo $item_row['item_name'];?>
            </td>
   <td class="tabledata" ><select  name="size[]" id="" style="width:100%;">
   						<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 if($item_row1['sizeid']==$sizeid['id']) { ?>
					 selected="selected" <?php  } ?>><?php echo $sizeid['size']; ?></option>
					<?php } ?></select></td>
   
   <td class="tabledata" ><input type="text" style="width:50px;" name="Qty[<?php echo $i;?>]" id="qty_<?php echo $i;?>" value="<?php echo $item_row1['quantity']?>"/></td>
   <td class="tabledata" width="50"><select name="unit[]" id="" style="width:100%;" >
	                      <option value="0">Select</option>
						  <?php  $unit=DB_query("select * from  unitsofmeasure 
						   where unitid ='".$item_row['mst_unitid']."' or unitid='".$item_row['conv_unit']."'",$db);
						   while($unit_row=DB_fetch_array($unit))
						   {
						   ?>
						   <option value="<?php echo $unit_row['unitid']; ?>" <?php if($item_row1['unit']==$unit_row['unitid']) { ?>
					 selected="selected" <?php  } ?>><?php echo $unit_row['unitname']; ?></option>
						   <?php } ?>
                          </select></td>
   <td class="tabledata" ><input type="text" name="price[<?php echo $i;?>]" id="price_<?php echo $i;?>" value="<?php echo $item_row1['price']?>" size="6" onkeyup="calculateTotalAmt(this.value,this.id)" /></td>
   
   <td class="tabledata" ><input type="text" name="stock_qty[<?php echo $i;?>]" id="totalamt_<?php echo $i;?>" style="width:70px;" value="<?php echo $item_row1['totalValue']?>" readonly="true"  />
   
   <?php $item_row1['EDRate']; ?>
   </td>
     <?php if($OrderType!='TBI' && $OrderType!='') {  ?>
   <td class="tabledata"><input type="text" name="mrp_per[<?php echo $i;?>]" value="<?php echo $item_row1['mrp_unit']; ?>" id="mrpper_<?php echo $i;?>"  size="9" onkeyup="calassprice(this.value,this.id)" /></td>
<td class="tabledata"><input type="text" name="ass_price[<?php echo $i;?>]" value="<?php echo $item_row1['ass_price']; ?>" id="ass_price_<?php echo $i;?>" readonly="readonly"  size="9"/></td>
<td class="tabledata"><input type="text" name="total_ass_price[<?php echo $i;?>]" value="<?php echo $item_row1['total_ass_price']; ?>" id="totalassamt_<?php echo $i;?>" readonly="true" size="25" onfocus="calass_amount(this.id)" /></td>

  
   
  
   <td class="tabledata" >
   <select name="EDRate[<?php echo $i;?>]" id="exciserate_<?php echo $i?>" style="width:107px;" 
   onchange="calculateExcise1(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 ($item_row1['EDRate']==$ServiceRow['id']?'selected':''); ?>><?php echo $ServiceRow['caption']?></option>
			<?php	
			}
    		
    		?>
    		</select>
   
   <?php //echo $s->GetFieldValue('excise_tax',"id=".$item_row1['EDRate']."",'caption');?>
   
   </td>
   <td class="tabledata" >
   <div id='hid_ED_div_<?php echo $i?>'>  
   <input size="10" type="text" name="EDAmt[<?php echo $i?>]" id="excisevalue_<?php echo $i ?>" value="<?php echo $item_row1['EDAmt']?>" >
   
   </div>
   </td>
    <?php } else {?>
    	 <td class="tabledata" >
   <select name="EDRate[<?php echo $i;?>]" id="exciserate_<?php echo $i?>" style="width:107px;" 
   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 ($item_row1['EDRate']==$ServiceRow['id']?'selected':''); ?>><?php echo $ServiceRow['caption']?></option>
			<?php	
			}
    		
    		?>
    		</select>
   
   <?php //echo $s->GetFieldValue('excise_tax',"id=".$item_row1['EDRate']."",'caption');?>
   
   </td>
    <td class="tabledata" >
   <div id='hid_ED_div_<?php echo $i?>'>  
   <input size="10" type="text" name="EDAmt[<?php echo $i?>]" id="excisevalue_<?php echo $i ?>" value="<?php echo $item_row1['EDAmt']?>" >
   
   </div>
   </td>
    	<?php } ?> 
  </tr>
  <?php  $i++;
   }  ?>	
  <input type="hidden" name="" value="<?php echo $i;?>" id="edit_cnt" /> 
  <?php 
  {
  ?>
<!------Add Extra Items--------->	
<tbody id="dataTable">
<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" /></td>
<td class="tabledata"><input type="hidden" name="item_code1[]" id="itemid" /></td>	
<td class="tabledata"><input type="text" name="" value="" id="itemcode" style="width:100%;"/></td>
<td class="tabledata" style="white-space:nowrap"><input type="text" name="" value="" id="itemname" style="width:100%;" /></td>
<td class="tabledata"><select  name="size[]" id="size1" style="width:100%;"  >
						<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="Qty1[]" value="" id="qty" style="width:50px;"/></td>
<td class="tabledata"><select name="unit[]" id="unit" style="width:100%;" >
	                      <option value="0">Select</option>
						  <?php  $unit=DB_query("select * from  unitsofmeasure",$db);
						   while($unit_row=DB_fetch_array($unit))
						   {
						   ?>
						   <option value="<?php echo $unit_row['unitid']; ?>"><?php echo $unit_row['unitname']; ?></option>
						   <?php } ?>
                          </select></td>
<td class="tabledata"><input type="text" name="price1[]" value="" id="price" onkeyup="calculateTotalAmt(this.value,this.id)" size="6"/></td>
<td class="tabledata"><input type="text" name="stock_qty1[]" value="" id="totalamt" readonly="true" size="9"/></td>
 <?php if($OrderType!='TBI' && $OrderType!='') {  ?>
 	<td class="tabledata"><input type="text" name="mrp_per1[]" value="" id="mrpper"  size="9" onkeyup="calassprice(this.value,this.id)" /></td>
<td class="tabledata"><input type="text" name="ass_price1[]" value="" id="ass_price" readonly="readonly"  size="9"/></td>
<td class="tabledata"><input type="text" name="total_ass_price1[]" value="" id="totalassamt" readonly="true" size="25" onfocus="calass_amount(this.id)" /></td>

<td class="tabledata"><select name="EDRate1[]" id="exciserate" style="width:107px" 
		onchange="calculateExcise1(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 class="tabledata"><input type="text" name="EDAmt1[]" value="" id="excisevalue" size="10"/></td>
    <input type="hidden" name="ApprovalStatus1[]" value="Pending">
 <?php } else {?>
 	
 	
<td class="tabledata"><select name="EDRate1[]" id="exciserate" style="width:107px" 
		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 class="tabledata"><input type="text" name="EDAmt1[]" value="" id="excisevalue" size="10"/></td>
   <input type="hidden" name="ApprovalStatus1[]" value="Pending">
   <?php } ?>	
  </tr>
		  </tbody>
<?php } ?>
  
 <!------Add Extra Items--------->	 
  
</table>
 </div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="row1">
    <td align="left" valign="top"><p align="left"><h3 style="color:#003399;">Assembly Item Details</h3></p></td>
  </tr>
  <tr class="row1">
    <td align="left" valign="top"><p align="left" style="padding-top:5px; padding-bottom:5px; padding-left:2px;"><input type="button" onClick="addRow1('dataTable1')" value="Add More" class="search" />&nbsp;
<input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_hardwareitems()" class="search" />
<input type="button" class="search"  onclick="deleteRowOrder1('dataTable1')" value="Delete" /></p></td>
  </tr>
</table>

<div style="overflow: auto; width:956px;">
<table id='deleterrw' width='100%' border='1' cellpadding='3' cellspacing='0'>

<tr class='row1'>
<td width="40" class='tabledata' style="width:40px;">Sr. No.</td>
<td class='tabledata' width="5">&nbsp;</td>
<td class='tabledata' width="80">Item Code</td>
<td width="150" class='tabledata'>Item Name</td>
<td colspan="2" class='tabledata' width="120">Quantity</td>
<td class='tabledata'>Price</td>
<td class='tabledata'>Value</td>
<td class='tabledata'>Action</td>
</tr>
<tbody id='dataTable1'>
<?php 
$t=1;
//echo "select * from quotation_hardware_items where quote_type='Direct' and parant_id='".$_REQUEST['QID']."'";
$sql_hrd=DB_query("select * from quotation_hardware_items where quote_type='Direct' and parant_id='".$_REQUEST['QID']."'",$db);
while($row1=DB_fetch_array($sql_hrd))
{
$unitid=$s->getField('item_master','id',$row1['itemCode'],'mst_unitid');


?>

<tr>
<td class="tabledata"><input name="delitem1[]" type="checkbox" value="" /></td>
<td class="tabledata"><input type="hidden" name="hardwareid[]" id="hardwareid_<?php echo $t; ?>" value="<?php echo $row1['itemCode']; ?>" /></td>
<td class="tabledata"><input type="text" style="width:100%;" name="hardwarecode[]" id="hardwarecode_<?php echo $t; ?>" value="<?php echo $s->getField('item_master','id',$row1['itemCode'],'StockID'); ?>"  /></td>
<td class="tabledata"><input type="text" style="width:100%;" name="hardwarename[]" id="hardwarename_<?php echo $t; ?>" value="<?php echo $s->getField('item_master','id',$row1['itemCode'],'item_name'); ?>"  /></td>
<td width="70" class="tabledata"><input type="text" name="hrdqty[]" id="hrdqty_<?php echo $t; ?>" style="width:100%;" value="<?php echo $row1['quantity']; ?>" /></td>
<td width="50" class="tabledata"><select name="hardwareunit[]" id="hardwareunit_<?php echo $t; ?>"  style="width:100%;"  >
	                      <option value="0">Select</option>
						  <?php  $unit=DB_query("select * from  unitsofmeasure",$db);
						   while($unit_row=DB_fetch_array($unit))
						   {
						   ?>
						   <option value="<?php echo $unit_row['unitid']; ?>"<?php if($unitid==$unit_row['unitid']) {?> selected="selected" <?php } ?> ><?php echo $unit_row['unitname']; ?></option>
						   <?php } ?>
              </select></td>
<td class="tabledata"><input type="text" name="hrdprice[]" id="hrdprice_<?php echo $t; ?>" onkeyup="calculateTotalhrdAmt(this.value,this.id)" value="<?php echo $row1['price']; ?>" /></td>

<td class="tabledata"><input type="text" name="hrdvalue[]" id="hrdvalue_<?php echo $t; ?>" value="<?php echo $row1['totalValue']; ?>" /></td>
<td class="tabledata"><input type="checkbox" name="ass_action[]" id="action_<?php echo $t; ?>" onclick="additems(this.id)" value="1" <?php if($row1['isChecked']==1) { ?> checked="checked" <?php } ?> /></td>
</tr>
<?php $t++; } ?>
</tbody>
</table>
 </div>

<input type="text" name="hiditemcount1" id="hiditemcount1" value="" />
 <input type="text" name="" value="<?php echo $t; ?>" id="edit_cnt1" />
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td valign="top" width="47%">
	<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 width="53%" 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()" value="<?php echo $basicAmount; ?>" 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)" <?php if($OrderType!='Consolidate' && $OrderType!='' ) {  ?> disabled <?php } ?> >
          <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($exciseDuty==$ServiceRow['id']?'selected':''); ?>><?php echo $ServiceRow['caption']?></option>
          <?php	
			}
    		
    		?>
        </select>
		  <input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $totalDiscountedPrice; ?>"  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:150px;">
          <input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:150px" />
          <input name="ECessValue" id="ECessValue" type="text" value="<?php echo $ECessValue; ?>"  readonly onFocus="calculateECess()" style="width:150px;"/></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:150px;">
          <input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>" style="width:150px;" readonly/>
          <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" style="width:150px;" value="<?php echo $taxableAmount; ?>" onFocus="calculateTaxable()"/></td>
		</tr>
		<tr class="row1">
		
		<td class="tabledata1">Assembly Amount<label><font color="#FF0000">*</font></label></td>
		<td><input name="hardamt" id="hardamt" type="text" style="width:150px;" value="<?php echo $hrdtotalAmt; ?>" /></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="Input" id="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" value="<?php echo $grandTotal; ?>"  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);
	}
	
	
	/*if(document.getElementById("edit_cnt").value!='')
	{
	var totalelement=parseInt(document.getElementById("edit_cnt").value;
	for(var k=0;k<=totalelement;k++)
	{
	if(document.getElementById("excisevalue_"+k))
	{
	var totalExcise1=document.getElementById("excisevalue_"+k).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 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?type=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 addRow1(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount1").value=='')
	r =rowCount+1;
	else
	{
	var t=document.getElementById("edit_cnt1").value;
	var t1=document.getElementById("hiditemcount1").value;
	r=parseInt(t1)+parseInt(t)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount1").value=r;
	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;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
}

function deleteRowOrder1(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--;
					}
					
				}
	var t=document.getElementById("edit_cnt1").value;
	if(document.getElementById("hiditemcount1").value!='')
	var t1=document.getElementById("hiditemcount1").value;
	else
	var t1=0;
	r=parseInt(t1)+parseInt(t)-1;
		document.getElementById("hiditemcount1").value=r;		
		}
		catch(e) 
		{
			alert(e);
		}}


function open_hardwareitems()
{
window.open("directhardwareitems_edit.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");


}

function calculateTotalhrdAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	
	if(id_brk.length>1)
	{
	var qty=document.getElementById("hrdqty_"+i).value;
	var tot_amt=qty*val;
	document.getElementById("hrdvalue_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("hrdqty").value;
	var tot_amt=qty*val;
	document.getElementById("hrdvalue").value=tot_amt.toFixed(2);
	}
}

function additems(str)
{
if(document.getElementById(str).checked==true)
{
var str1;
var s=str.split("_");
			if(s[1]==undefined)
			{
			if(document.getElementById("hrdvalue").value!='')
			 str1=document.getElementById("hrdvalue").value;
			else  str1=0;
            }
			else
			{
			if(document.getElementById("hrdvalue_"+s[1]).value!='')
			str1=document.getElementById("hrdvalue_"+s[1]).value;
			else
			str1=0;
			}
if(document.getElementById("hardamt").value!='')
var amt=document.getElementById("hardamt").value;
else
var amt=0;

var amount=parseFloat(amt)+parseFloat(str1);

document.getElementById("hardamt").value=amount.toFixed(2);
}
else
{

var str1;
var s=str.split("_");
			if(s[1]==undefined)
			{
			if(document.getElementById("hrdvalue").value!='')
			 str1=document.getElementById("hrdvalue").value;
			else  str1=0;
            }
			else
			{
			if(document.getElementById("hrdvalue_"+s[1]).value!='')
			str1=document.getElementById("hrdvalue_"+s[1]).value;
			else
			str1=0;
			}
if(document.getElementById("hardamt").value!='')
var amt=document.getElementById("hardamt").value;
else
var amt=0;

var amount=parseFloat(amt)-parseFloat(str1);

document.getElementById("hardamt").value=amount.toFixed(2);


}
}


</script>