<?php 
$PageName = 'Vendor Quotation'; 

//unset($_SESSION['TermsValues']);
//**************************SAVE THE DATA***************START HERE**********30-04-2013********AMITSINGH***************

if($_REQUEST['submit'])
{
	//exit('test');
	//echo "<pre>"; print_r($_REQUEST); echo "</pre>";
            /*$attachfile=$_FILES['attachFile']['name'];
            if($attachfile!='')
            {
            	$maxid=DB_query("select Max(id) from venderquotations",$db);
            	$maxiddata=DB_fetch_array($maxid);
            	$maxnumber=$maxiddata['Max(id)']+1;
            	$new_name=$attachfile.'_Quo'.$maxnumber; 
            	$path="doc/".$new_name; 
            
    	        if(move_uploaded_file($_FILES['attachFile']['tmp_name'],$path))
        	    {
          		  $data['attachedfile']=trim($new_name);
            	}
            
	        }*/
	          $FinempCode1=rand(0,9999);
	    	if($_FILES['attachFile']['name']!='')
	   		 {
        	$name=$_FILES['attachFile']['name'];
			$tmp_name=$_FILES['attachFile']['tmp_name'];
			$name_brk=explode('.',$name);
			$type=$name_brk[1];
			$new_name=$FinempCode1.'.'.$type;
			$path="uploaded_docs/".$new_name;
			$file_copy=copy($tmp_name,$path);		
		}

		$data['attachedfile']        =$new_name;
        $prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."' and module_id='".$_REQUEST['modid']."' ",$db);
	    $prefix_row=DB_fetch_array($prefix_sql);
	  //$prefixf=explode("/",$prefix_row['prefix_code']);
	    $prefix1=$prefix_row['prefix_code'];
	    $financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
	    $sql="Select quotation_no from venderquotations where Site='".$_REQUEST['Site']."' 
	    and INSTR(`quotation_no`, '$financial') > 0 order by id desc limit 0,1";

	$result=DB_query($sql,$db);
	$myrow=DB_fetch_array($result);
	//echo DB_num_rows($result);
	//echo $myrow['quotation_no'];

	if(DB_num_rows($result)>0)
	{
	//$Reqno=$myrow['Reqno'];
	//$req_part1=substr($Reqno,-4);
	$ExplBill=explode("/",$myrow['quotation_no']);
	$maxval = $ExplBill[3];
	//echo $req_part1;
	$req_final=$maxval+1;
	//echo "<br>".$req_final;
	}
	else
	{
	$req_final="1";
	}
	
	$string=$_REQUEST['Site']."/".$financial."/".$prefix1."/";

	  $final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);//USED FOR AUTO CODE GENERATION
	//exit();
	if($_REQUEST['dutytype'])
	$cnt='Y';
	else
	$cnt='N';	
    $data['mapid']=$_REQUEST['mapid'];
	$data['Site']=$_REQUEST['Site'];
	$data['Quotation_Date']=FormatDateFORSQL($_REQUEST['Quotation_Date']);
	$data['quotation_no']=$final_string;
	$data['mst_supplierno']=$_REQUEST['mst_supplierno'];
	$data['indent_prno']=$_REQUEST['indent_prno'];	
	$data['party_Quo_no']=DB_escape_string($_REQUEST['party_Quo_no']);
	$data['party_Quo_date']=FormatDateFORSQL($_REQUEST['party_Quo_date']);
	$data['Remarks']=$_REQUEST['Remarks'];
	$data['basic_amt']=$_REQUEST['basic_amt'];
	$data['pkg_per']=$_REQUEST['pkg_per'];
	$data['pkg_charges']=$_REQUEST['pkg_charges'];
	$data['vatcst']=$_REQUEST['vatcst'];
	$data['taxvalue']=$_REQUEST['taxvalue'];
	$data['surcharge_per']=$_REQUEST['surcharge_per'];
	$data['surcharge_amt']=$_REQUEST['surcharge_amt'];
	$data['Freight']=$_REQUEST['Freight'];
	$data['add_charges']=$_REQUEST['add_charges'];
	$data['pluMin']=$_REQUEST['pluMin'];
	$data['roundOff']=$_REQUEST['roundVal'];
	$data['excise_id']=$_REQUEST['excise'];
	$data['excise_amt']=$_REQUEST['excise_duty_val'];
	$data['ecess_id']=$_REQUEST['ecess'];
	$data['ecess_amt']=$_REQUEST['ecess_val'];
	$data['s_ecess_id']=$_REQUEST['shecess'];
	$data['s_ecess_amt']=$_REQUEST['shecess_val'];
	$data['insurance']=$_REQUEST['insurance'];
	$data['non_insurance']    =$_REQUEST['insr_amt']; 
	$data['total_grand_amt']   =$_REQUEST['total_po_amt'];  
    $data['dis_per']           =$_REQUEST['discount_percent'];  
    $data['discounted_amt']    =$_REQUEST['discount_amt'];  
    $data['discount_amt']      =$_REQUEST['discounted_amt'];  
	$data['total_amt']=$_REQUEST['total_amt'];
	$data['total_taxable_amt']=$_REQUEST['tot_tax_amt'];
	$data['entry_tax']=$_REQUEST['entry_tax_amt'];
	$data['other_charges']=$_REQUEST['miscellaneous'];
	$data['grand_total']=$_REQUEST['GrandTotal'];
	$data['duty_type']=$cnt;
	$data['created_date']=date('Y-m-d');
    $data['createdBy']=trim($_SESSION['UserID']);
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['terms_condition']=$_REQUEST['VenderQutation_TermCondition'];
	
	$s->RecordInsert('venderquotations',$data);			//INSERT INTO PARANT TABLE
	$last_id=DB_Last_Insert_ID($db,'venderquotations','id');// GET LAST INSERT ID
	
        //echo "<pre>";
	//print_r($data);
	//exit;
	for($i=0;$i<$_REQUEST['hiditemcount'];$i++)
	{
		//$dataArr['i']=$i;
		$dataArr['parant_id']=$last_id;
		$dataArr['indentPr_no']=$_REQUEST['mapid'];
		$dataArr['mst_itemid']=$_REQUEST['itemID'][$i];
		$dataArr['Quantity']=$_REQUEST['qty'][$i];
		$dataArr['Rate']=$_REQUEST['rate'][$i];
		$dataArr['totalPrice']=$_REQUEST['price'][$i];
		$dataArr['DiscountType']=$_REQUEST['DiscountType1'][$i];
		$dataArr['Discount']=$_REQUEST['Discount1'][$i];
		$dataArr['currency']=$_REQUEST['currency'][$i];
		$dataArr['discounted_amount']=$_REQUEST['discounted_amount'][$i];
		$dataArr['NetRate']=$_REQUEST['NetRate'][$i];		
		$dataArr['basic_Amt']=$_REQUEST['basic_Amt1'][$i];
		$dataArr['Excise_type']=$_REQUEST['Excise_type'][$i];
		$dataArr['Excise_Duty']=$_REQUEST['Excise_Duty'][$i];
		$dataArr['ExcisePercentage']=$_REQUEST['ExcisePercentage'][$i];
		$dataArr['ExciseValue']=$_REQUEST['exciseValue'][$i];
		$dataArr['Cess_ID']=$_REQUEST['Cess_ID'][$i];
		$dataArr['ECessPercentage']=$_REQUEST['ECessPercentage'][$i];
		$dataArr['ECessValue']=$_REQUEST['ECessValue'][$i];
		$dataArr['SHECess_ID']=$_REQUEST['SHECess_ID'][$i];
		$dataArr['SAHCessPercentage']=$_REQUEST['SAHCessPercentage'][$i];
		$dataArr['SAHCessValue']=$_REQUEST['SAHCessValue'][$i];
		$dataArr['taxable_amt']=$_REQUEST['taxable_amt'][$i];
		$dataArr['freightItem']=$_REQUEST['freightItem'][$i];
		$dataArr['inputVat']=$_REQUEST['inputVat'][$i];
		$dataArr['pkg_amt']=$_REQUEST['pkg_Amt'][$i];
		$dataArr['sur_per']=$_REQUEST['surchargeper'][$i];
		$dataArr['sur_amt']=$_REQUEST['surchargeamt'][$i];

		$dataArr['size']=$_REQUEST['sizesp'][$i];
        $dataArr['mst_unitid']=$_REQUEST['mstunit_id'][$i];
		$dataArr['grade']=$_REQUEST['gradesp'][$i];

		$dataArr['taxvalue']=$_REQUEST['taxvalue1'][$i];
		$dataArr['TotalAmount']=$_REQUEST['TotalAmount'][$i];//print_r($dataArr);exit;
		$dataArr['brand_id']=$_REQUEST['brand'][$i];
		//echo "<pre>"; print_r($dataArr); echo "</pre>";
		$s->RecordInsert('vendorquotationdetails',$dataArr);//INSERT INTO CHIELD TABLE
		
	}
	//exit('jk');
                    // Updating Quotation Status
            $noQuoQry="select id from venderquotations where mapid='".$_REQUEST['mapid']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
            $noQuoQryExec = DB_query($noQuoQry, $db);
              $numRows=DB_num_rows($noQuoQryExec);
              $norVendors=$_REQUEST['noVendor'];
             if($numRows==$norVendors){
                 $datastatus['quotaion_status']=1;
			$condA="id='".$_REQUEST['mapid']."'";
			$s->RecordEdit('indentpr_mapping',$datastatus,$condA);//CHANGE STATUS
             }
 else {
     $datastatus['quotaion_status']=2;
			$condA="id='".$_REQUEST['mapid']."'";
			$s->RecordEdit('indentpr_mapping',$datastatus,$condA);//CHANGE STATUS
 }

	$s->pageLocation("index.php?route=POModule/DispVendor_Quotes".$rurl);
	
	unset($_SESSION['TermsValues']);
}


//**************************SAVE THE DATA***************END HERE**********06-12-2013********PRIYANKA PANWAR***************





//**************************FETCH THE DATA***************START HERE**********06-12-2013********PRIYANKA PANWAR***************


$INDENTqRY="SELECT * FROM indentpr_mapping where id='".$_REQUEST['mapid']."' and (quotaion_status=0 || quotaion_status=2) and CompanyId='".$_SESSION['ACGCompanyId']."'";
$SQLVendorList=DB_query($INDENTqRY,$db);
$vendorList=DB_fetch_array($SQLVendorList);

	$site=$vendorList['site'];
        $VenList=$vendorList['mapped_vendor'];
	$prNo=$vendorList['indentPrno'];


$vendorArray=explode(',', $VenList);
  $noofVendors=count($vendorArray);   
$quotQry="SELECT * FROM venderquotations where mapid='".$_REQUEST['mapid']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
$quotQryExec=DB_query($quotQry,$db);
while($quotQryDta=DB_fetch_array($quotQryExec))
{
 $vendorID[]=$quotQryDta['mst_supplierno'];
}
//print_r($vendorArray);
if($vendorID!=''){
    
   
    $result=array_diff($vendorArray,$vendorID);
//print_r($result);
$VENDORsTR=implode(',', $result);
}
//**************************FETCH THE DATA***************END HERE**********30-04-2013********AMITSINGH***************
?>


<!---**************************JAVASCRIPT FILES***************START HERE**********30-04-2013********AMITSINGH*************-->

<script type="text/javascript" src="POModule/po_calculation.js"></script>
<script language="javascript" type="text/javascript">

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


function GetVendorWiseIndentNo(vendorId)
{
	
        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("indent_prno").innerHTML=xmlhttp.responseText;
	}
	}
	
	var prno=document.getElementById("prno").value;
      
	xmlhttp.open("GET","GetVendorWiseIndentNo.php?vendorId="+vendorId+"&Prno="+prno,true);
	xmlhttp.send();
}


function GetPrDetails(indentId)
{
	//alert(indentId);
        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("ShowAllData").innerHTML=xmlhttp.responseText;
	}
	}
	var mapid=document.getElementById("mapid").value;
	var vendorid=document.getElementById("mst_supplierno").value;
	xmlhttp.open("GET","GetIndentNoPrDetails.php?IndentId="+indentId+"&vendorId="+vendorid+"&mapid="+mapid,true);
	xmlhttp.send();
}




function check_approveqty(str,j)
{
	var req_qty=document.getElementById("req_qty_"+j).value;
	if(str>req_qty)
	{
		alert("Quantity to approve cannot be greater than requsition quantity");
		document.getElementById("app_qty_"+j).value='';
		document.getElementById("app_qty_"+j).focus();
	}
}



function calcPackaging(str)
{
	if(str!='')
	{
		var tota_amt=document.getElementById("total_item_amount").value;
		var pckgng_val=(str/100)*tota_amt;
		document.getElementById("pkg_charges1").value=pckgng_val.toFixed(2);
	}
}
function calcRounded(str)
{
	var gtotal=document.getElementById('orig_grand_tot').value;
	var gtotal_brk=gtotal.split('.');
	if(str=='+')
	{var final=parseInt(gtotal_brk[0])+1;}
	else if(str=='-')
	{var final=parseInt(gtotal_brk[0]);}
	else if(str=='')
	{var final=gtotal;}
	document.getElementById('GrandTotal').value=final;
}
function calculateExciseDuty(i)
{
	var basic=document.getElementById("basic_"+i).value;
	var ExcisePercentage=document.getElementById("ExcisePercentage_"+i).value;
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("exciseValue_"+i).value=exciseVal.toFixed(2);
}
function hid_billing_typecheck(i,str){

	if(str=='')
	{
		alert("Select Tax Type");
	}

}



function checkExcisable(str,ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }
	if(str=='NonExcisable')
	{
/*		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("cessID1_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("cessID2_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;			
		document.getElementById("exciseDuty_"+i).value='0';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cessID1_"+i).value=''; 
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cessID2_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';*/
		/*document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("cessID1_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("cessID2_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxableAmt_"+i).disabled=true;
		//document.getElementById("freightItem_"+i).disabled=false;
		document.getElementById("inputVat_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		
		document.getElementById("surchargeper_"+i).disabled=false;		
		document.getElementById("surchargeamt_"+i).disabled=false;*/
		
		
		document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cessID1_"+i).value='0';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cessID2_"+i).value='0';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxableAmt_"+i).value='';			
		document.getElementById("inputVat_"+i).value='0';

		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("surchargeper_"+i).value='';		
		document.getElementById("surchargeamt_"+i).value='';

	}
	else if(str=='Excisable')
	{
		/*document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("cessID1_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("cessID2_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		//document.getElementById("inputVat_"+i).disabled=true;*/
		/*document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("cessID1_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("cessID2_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxableAmt_"+i).disabled=false;
		//document.getElementById("freightItem_"+i).disabled=true;
		document.getElementById("inputVat_"+i).disabled=true;
		document.getElementById("taxvalue_"+i).disabled=true;

		document.getElementById("surchargeper_"+i).disabled=true;		
		document.getElementById("surchargeamt_"+i).disabled=true;*/


		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("surchargeper_"+i).value='';		
		document.getElementById("surchargeamt_"+i).value='';
		document.getElementById("inputVat_"+i).value='0';
		
	}
	else
	{
		/*document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("cessID1_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("cessID2_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxableAmt_"+i).disabled=false;
		document.getElementById("freightItem_"+i).disabled=false;
		document.getElementById("inputVat_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;		
		document.getElementById("exciseDuty_"+i).value='0';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cessID1_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cessID2_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxableAmt_"+i).value='';*/
		/*document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("cessID1_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("cessID2_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxableAmt_"+i).disabled=false;
		//document.getElementById("freightItem_"+i).disabled=false;
		document.getElementById("inputVat_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;

		document.getElementById("surchargeper_"+i).disabled=false;		
		document.getElementById("surchargeamt_"+i).disabled=false;*/
		
		document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cessID1_"+i).value='0';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cessID2_"+i).value='0';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxableAmt_"+i).value='';
		document.getElementById("inputVat_"+i).value='0';

		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("surchargeper_"+i).value='';		
		document.getElementById("surchargeamt_"+i).value='';

	}
	document.getElementById("hidBillingType_"+i).value=str;
	cal_totalamount();
}


function checkexiseflag(ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }

	if(document.getElementById("hidBillingType_"+i).value==''){
		alert("Must Select Tax Type");
	} else {
	    if(!isNumber(ids)){
	    	idNamePrefix=idsArr[0];
			switch(idNamePrefix) {
			    case 'cessID1':
			        if(document.getElementById("exciseDuty_"+i).value==''){
			        	alert('Please excise duty first');
			        }
			        break;
			    case 'cessID2':
			        if(document.getElementById("exciseDuty_"+i).value==''){
			        	alert('Please excise duty first');
			        }
			        break;
			    case 'inputVat':
			        if(document.getElementById("hidBillingType_"+i).value=='' || document.getElementById("hidBillingType_"+i).value=='Excisable'){
			        	alert('Please select correct excise flag');
			        }
			        break;
			    case 'exciseDuty':
			        if(document.getElementById("hidBillingType_"+i).value=='NonExcisable'){
			        	alert('Please select correct excise flag');
			        }
			        break;
			} 
	    }
	}	
	
} 



function calculateECess(i)
{
	
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessPercentage=document.getElementById("ECessPercentage_"+i).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue_"+i).value=total.toFixed(2);
}
function calculateSAHCess(i)
{
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage_"+i).value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue_"+i).value=total.toFixed(2);
}

function claculateExcise(id,val)
{
	var id1=id.split("_");
	var i=id1[1];
	var basicamt=document.getElementById("basic_"+i).value;
	var pkgamt=document.getElementById("pkgamt_"+i).value;
	if(basicamt=='') basicamt=0;
	if(pkgamt=='') pkgamt=0;
	var totalabasic=parseFloat(basicamt)+parseFloat(pkgamt);
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data=xmlhttp.responseText.split("__");
			//console.log(xmlhttp.responseText);
			var k=data[0];
			document.getElementById("exciseValue_"+k).value=data[1];
				var id1="cessID1_"+i;
	             var val1=document.getElementById(id1).value;
	             calEcessonchange(id1,val1);

		}
	
	}
	xmlhttp.open("GET","ajax_getexcisevalue.php?ids="+id+"&vls="+val+"&bamt="+totalabasic,true);
	xmlhttp.send();
	
}



function calEcessonchange(id,val)
{
	//alert(id);
	var id1=id.split("_");
	var i=id1[1];
	var ecessval=document.getElementById("exciseValue_"+i).value;
		
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText.split("__");
		
		var k=data[0];
		document.getElementById("ECessValue_"+k).value=data[1];
		       var id1="cessID2_"+i;
	             var val1=document.getElementById(id1).value;
	             calSHEcessonchange(id1,val1);
	}
	}

	xmlhttp.open("GET","ajax_ecesscalculation1.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}


function calSHEcessonchange(id,val)
{
	
	var id1=id.split("_");
	var i=id1[1];
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText.split("__");
		var k=data[0];
		document.getElementById("SAHCessValue_"+k).value=data[1];
		calculateTaxable(i);
	}
	}
	
	var ecessval=document.getElementById("exciseValue_"+i).value;
	xmlhttp.open("GET","ajax_ecesscalculation1.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}


function calculateTotalPrice(i)
{
	Quantity=document.getElementById("Quantity_"+i).value;
	Rate= document.getElementById("Rate_"+i).value;
	if(Quantity==''){Quantity=0;}
	if(Rate==''){Rate=0;}
	var Total=Quantity*Rate;
	document.getElementById("totalValue_"+i).value=Total.toFixed(2);
}


function calculateTaxable(ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessValue=document.getElementById("ECessValue_"+i).value;
	var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
	
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxableAmt_"+i).value=TOTAL.toFixed(2);
	var taxrate=document.getElementById("inputVat_"+i).value;
	tax_rate2(taxrate,i);
	//cal_grandtotal(i);
}




function calc_tax_amount()
{
	var taxable=document.getElementById("taxable_amt").value;
	var taxval=document.getElementById("taxvalue").value;
	var final=taxable*(taxval/100);
	document.getElementById("tot_tax_amount").value=final.toFixed(2);
}

function get_charge(str)
{
	document.getElementById("hidden_suroct").value=str
}

function cal_suroct(i,str)
{
	
	var total_tax=document.getElementById("taxvalue_"+i).value;
	var final_sur=total_tax*(str/100);
	document.getElementById("sur_oct_amt_"+i).value=final_sur.toFixed(2);
}

function calsuroctamt(str)
{
var amt=parseFloat(document.getElementById("taxvalue").value);
var	suroctper=parseFloat(document.getElementById("sur_oct_per").value);
var amount=(amt*suroctper)/100;
document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}

function tax_rate1(str)
{
	
	var taxableAmount=document.getElementById("total_item_amount").value;
	var taxableAmount1=document.getElementById("pkg_charges1").value;
	if(taxableAmount1==''){taxableAmount1=0;}
	var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
	if (str.length==0)
	{
	document.getElementById("taxval").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("taxval").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_tax_valdata.php?taxid="+str+"&amt="+taxableAmount2,true);
	xmlhttp.send();
}

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


function calc_totaltax()
	{
	var total_tax=0;
	var cnt=document.getElementById("count").value
	for(var j=1;j<cnt;j++)
	{
		var taxamt=document.getElementById("totaltaxamount_"+j).value;
		total_tax=parseFloat(total_tax)+parseFloat(taxamt);
	}
	document.getElementById("total_tax").value=total_tax.toFixed(2);
}



function cal_totalcharge()
	{
	var total=0;
	var count=document.getElementById("countcharges").value;
	for(var i=1; i<count;i++)
	{
		var actualamt=document.getElementById("actual_"+i).value;
		if(actualamt!='')
		{
		total=parseFloat(total)+parseFloat(actualamt);
		}
	}
	document.getElementById("TotalCharge").value=total.toFixed(2);
}




function cal_totalamount()
{
	var sumOfArea=0;
	var sumOfArea1=0;
	var sumOfArea2=0;
    var sumOfArea3=0;
    var sumOfArea4=0;
    var sumOfArea5=0;
    var sumOfAreapkg=0;
    var sumOfAreasurcharge=0;

    $('#tableDataProduction').find('input[type="text"][class="basic"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea= sumOfArea + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea= sumOfArea;	
    }
    });

    $('#tableDataProduction').find('input[type="text"][class="pkgamt"]').each(function(){
    if($(this).val()!='')
    {
    sumOfAreapkg= sumOfAreapkg + parseFloat($(this).val());   
    }
    else
    {
    sumOfAreapkg= sumOfAreapkg;	
    }
    });

    $('#tableDataProduction').find('input[type="text"][class="excise"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea1= sumOfArea1 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea1= sumOfArea1;	
    }
    });

     $('#tableDataProduction').find('input[type="text"][class="ecess"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea2= sumOfArea2 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea2= sumOfArea2;	
    }
    });

     $('#tableDataProduction').find('input[type="text"][class="shecess"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea3= sumOfArea3 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea3= sumOfArea3;	
    }
    }); 

     $('#tableDataProduction').find('input[type="text"][class="freight"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea4= sumOfArea4 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea4= sumOfArea4;	
    }
    }); 

     $('#tableDataProduction').find('input[type="text"][class="vat"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea5= sumOfArea5 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea5= sumOfArea5;	
    }
    }); 

    $('#tableDataProduction').find('input[type="text"][class="surcharge"]').each(function(){
    if($(this).val()!='')
    {
    sumOfAreasurcharge= sumOfAreasurcharge + parseFloat($(this).val());   
    }
    else
    {
    sumOfAreasurcharge= sumOfAreasurcharge;	
    }
    }); 

	$tot_basic=sumOfArea.toFixed(2);
	document.getElementById("excise_duty_val").value=sumOfArea1.toFixed(2);
	document.getElementById("ecess_val").value=sumOfArea2.toFixed(2);
	document.getElementById("shecess_val").value=sumOfArea3.toFixed(2);
	document.getElementById("taxvalue").value=sumOfArea5.toFixed(2);
	document.getElementById("TotalCharge").value=sumOfArea4.toFixed(2);
	document.getElementById("pkg_charges1").value=sumOfAreapkg.toFixed(2);
    document.getElementById("sur_oct_amt").value=sumOfAreasurcharge.toFixed(2);
    document.getElementById("total_item_amount").value=$tot_basic; 


	cal_total_grand();
}


function cal_insurance()
{
	var total=document.getElementById("total_item_amount").value;
	var insurance=document.getElementById("insurance").value;
	var miscellaneous=document.getElementById("miscellaneous").value;
	var excise=document.getElementById("excise_duty_val").value;
	var ecess=document.getElementById("ecess_val").value;
	var sheamt=document.getElementById("shecess_val").value;
	var taxamt=document.getElementById("taxvalue").value;
	if(total=='') { total=0;} if(insurance=='') { insurnace=0} if(excise==''){excise=0;} if(ecess==''){ecess=0;} if(sheamt==''){sheamt=0;}
	if(taxamt==''){taxamt=0;}
	if(miscellaneous=='') { miscellaneous=0;}
	var grand=parseFloat(total)+parseFloat(insurance)+parseFloat(miscellaneous)+parseFloat(excise)+parseFloat(ecess)+parseFloat(sheamt)
	          +parseFloat(taxamt);
	document.getElementById("GrandTotal").value=grand.toFixed(2);
    cal_roundamt();

}


function cal_total_grand()
{
	var totalbasic=document.getElementById("total_item_amount").value;
	var exciseamt=document.getElementById("excise_duty_val").value;
	var ecessamt=document.getElementById("ecess_val").value;
	var shessamt=document.getElementById("shecess_val").value;
	var freight=document.getElementById("TotalCharge").value;
	var vatamt=document.getElementById("taxvalue").value;
	var insurance=document.getElementById("insurance").value;
	var miss=document.getElementById("miscellaneous").value;	
	var pkg=document.getElementById("pkg_charges1").value;	
	var sur=document.getElementById("sur_oct_amt").value;	

    if(totalbasic=='') { totalbasic=0;}
    if(exciseamt=='') { exciseamt=0;}
    if(ecessamt=='') { ecessamt=0;}
    if(shessamt=='') { shessamt=0;}
    if(freight=='') { freight=0;}
    if(vatamt=='') { vatamt=0;}
    if(insurance=='') { insurance=0;}
      if(pkg=='') { pkg=0;}
        if(sur=='') { sur=0;}

    if(miss=='') { miss=0;}
   var total=(parseFloat(totalbasic)+parseFloat(exciseamt)+parseFloat(ecessamt)+parseFloat(shessamt)+parseFloat(freight)+parseFloat(vatamt)+parseFloat(insurance)+parseFloat(miss)+parseFloat(pkg)+parseFloat(sur)).toFixed(2);
    

      var grand_total=total.split(".");


       if(grand_total[1]<10)
	{ var first_digit=parseFloat(grand_total[1])*10;}
    else{ var first_digit=grand_total[1];	}
   // echo $first_digit;
 //echo "fd=".$round1[1];exit;
		  if(first_digit>=50)
		  {
		  	//echo $first_digit;
		  var rov=100-parseFloat(first_digit);
		  var tot=parseFloat(grand_total[0])+1;
		  var sign="+";
          var roundval1=rov; 
          var roundval=parseFloat(rov)/100;
		  var grand1=tot;
		  	
		  }
		  else if(first_digit<50){
		    var sign="-";
		    var roundval1=grand_total[1]; 
           var roundval=parseFloat(first_digit)/100;
		  var grand1=grand_total[0];
		}


   document.getElementById("GrandTotal").value=grand1;
   document.getElementById("pluMin").value=sign;
   document.getElementById("roundVal").value=roundval;

  
}
function tax_rate3(str,ids)
{
	//alert(i);
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }
    	getsuperCharge(str,i);
        
	var bill_type=document.getElementById("hidBillingType_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	//var freight=document.getElementById("freightItem_"+i).value;
	var freight=0.00;
	var excise=document.getElementById("taxableAmt_"+i).value;
	var pkg=document.getElementById("pkgamt_"+i).value;
	var suroctper=document.getElementById("surchargeper_"+i).value;
	if(suroctper=='') suroctper=0;
	if(pkg=='') pkg=0;

	if(basic==''){basic=0;}
	if(excise==''){excise=0;}
	if(freight==''){freight=0;}
	if(pkg==''){pkg=0;}

	if(bill_type=="NonExcisable" || bill_type=='')
	{
		var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg);
	}
	else if(bill_type=="IncludeTax")
	{
		var taxableAmount2=parseFloat(basic)+parseFloat(excise)+parseFloat(freight)+parseFloat(pkg);
	}
	else if(bill_type=="Excisable")
	{
		var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg)+parseFloat(excise);
	}


	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var vatamt=xmlhttp.responseText;
		document.getElementById("taxvalue_"+i).value=vatamt;
		var survalue=parseFloat(vatamt)*parseFloat(suroctper)/100;
		document.getElementById("surchargeamt_"+i).value=survalue.toFixed(2);

		cal_grandtotal(i);
	}
	}
	var str2=document.getElementById("inputVat_"+i).value;
	if(str2=='')
		cal_grandtotal(i);	
	else{
		xmlhttp.open("GET","get_tax_valdata_item.php?taxid="+str2+"&amt="+taxableAmount2,true);
		xmlhttp.send();	
	}
	
}

function tax_rate2(str,ids)
{
	//alert(i);
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }
    	
        
	var bill_type=document.getElementById("hidBillingType_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	//var freight=document.getElementById("freightItem_"+i).value;
	var freight=0.00;
	var excise=document.getElementById("taxableAmt_"+i).value;
	var pkg=document.getElementById("pkgamt_"+i).value;
	var suroctper=document.getElementById("surchargeper_"+i).value;
	if(suroctper=='') suroctper=0;
	if(pkg=='') pkg=0;

	if(basic==''){basic=0;}
	if(excise==''){excise=0;}
	if(freight==''){freight=0;}
	if(pkg==''){pkg=0;}

	if(bill_type=="NonExcisable" || bill_type=='')
	{
		var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg);
	}
	else if(bill_type=="IncludeTax")
	{
		var taxableAmount2=parseFloat(basic)+parseFloat(excise)+parseFloat(freight)+parseFloat(pkg);
	}
	else if(bill_type=="Excisable")
	{
		var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg)+parseFloat(excise);
	}


	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var vatamt=xmlhttp.responseText;
		document.getElementById("taxvalue_"+i).value=vatamt;
		var survalue=parseFloat(vatamt)*parseFloat(suroctper)/100;
		document.getElementById("surchargeamt_"+i).value=survalue.toFixed(2);

		cal_grandtotal(i);
	}
	}
	var str2=document.getElementById("inputVat_"+i).value;
	if(str2=='')
		cal_grandtotal(i);	
	else{
		xmlhttp.open("GET","get_tax_valdata_item.php?taxid="+str2+"&amt="+taxableAmount2,true);
		xmlhttp.send();	
	}
	
}

function getsuperCharge(str,i){

	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("surchargeper_"+i).value=xmlhttp.responseText;
		var dfgd=xmlhttp.responseText;
		console.log('fgd '+xmlhttp.responseText);
	}
	}
	xmlhttp.open("GET","getSuperCharge.php?taxid="+str,false);
	xmlhttp.send();	
	//console.log(dfgd);




}

function cal_grandamount()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}


function cal_roundamt()
{
	
	var total=document.getElementById("total_item_amount").value;
	if(document.getElementById("sur_oct_amt"))
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
     if(document.getElementById("TotalCharge"))
	var TotalCharge=document.getElementById("TotalCharge").value;
     if(document.getElementById("packagingCharges"))
	var packagingCharges=document.getElementById("packagingCharges").value;
     if(document.getElementById("additionalCharges"))
	var additionalCharges=document.getElementById("additionalCharges").value;
    if(document.getElementById("taxvalue"))
	var taxamt=document.getElementById("taxvalue").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	
   var h=grandtotal.split(".");
 if(h[1]==undefined)
  {
  	  document.getElementById("pluMin").value='';
	  document.getElementById("roundVal").value='';
	  document.getElementById("GrandTotal").value=grandtotal;
	 
  }

else
{
  if(h[1]<10 && h[1].length==1)
 {
          var first_digit=parseFloat(h[1])*10;	 
		
 }
 else
 {
 var first_digit=h[1];	
 }	

 if(first_digit>=50)
 {
 	  var rov=(100-parseFloat(first_digit))/100;
	   var tot=parseFloat(h[0])+1;
	  
		  document.getElementById("pluMin").value='+';
		  document.getElementById("roundVal").value=rov;
		  document.getElementById("GrandTotal").value=tot;		 
}
	else
	{
	 var rov=parseFloat(first_digit)/100;
	 var tot=parseFloat(h[0]);
	  document.getElementById("pluMin").value='-';
	  document.getElementById("roundVal").value=rov;
	  document.getElementById("GrandTotal").value=tot;
	 
     }

  
}


	
}

function cal_grandtotal(ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }
	var type_of_bill=document.getElementById("hidBillingType_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	var Totaltaxable=document.getElementById("taxableAmt_"+i).value;
	var freight=document.getElementById("freightItem_"+i).value;
	var vat=document.getElementById("taxvalue_"+i).value;
	var pkg=document.getElementById("pkgamt_"+i).value;
	var suramt=document.getElementById("surchargeamt_"+i).value;

	if(basic==''){basic=0;}
	if(freight==''){freight=0;}
	if(vat==''){vat=0;}
	if(pkg==''){pkg=0;}
	if(suramt==''){suramt=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	if(document.getElementById("hidBillingType_"+i).value=='NonExcisable' || document.getElementById("hidBillingType_"+i).value=='' )
	{
	var grand_tot1=+parseFloat(basic)+parseFloat(freight)+parseFloat(vat)+parseFloat(pkg)+parseFloat(suramt);
	var grand_tot=grand_tot1.toFixed(2);
	}	
	else {
	var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable)+parseFloat(freight)+parseFloat(vat)+parseFloat(pkg)+parseFloat(suramt) ;
	var grand_tot=grand_tot1.toFixed(2);
	}
	
	document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
	cal_totalamount();	
}




function checkstatus(str)
{
	var Charge = document.getElementById("Charge_"+str).value;
	var actual = document.getElementById("actual_"+str).value;
	if(Charge == 'NO' && actual == '')
	{
		alert("Please Enter Some Value Since It Is Not Inclusive");
		return false;
	}
}



var TotalPercent=0;
var TotalAmnt=0;
var finalAmount=0;

function ChargeCalculater(Amt,Amtid)
{
	var AsPerActual=document.getElementById(Amtid).value;
	var ActualType=document.getElementById("AsPerActual_" +Amtid).value;
	if(AsPerActual !='')
	{
		if(ActualType=='PercentAmt')
		{
			var Total= document.getElementById("Total").value;
			var charge= parseFloat(Total) * parseFloat(AsPerActual)/100;
			document.getElementById("actual_"+Amtid).value = charge;
			TotalPercent= parseFloat(TotalPercent) + parseFloat(charge);
		}
		else
		{
			document.getElementById("actual_"+Amtid).value=AsPerActual; 
			TotalAmnt=parseFloat(TotalAmnt) + parseFloat(AsPerActual);
		}
	}
	return true;
}


function ChargeAmount(CA,ID)
{
	if (CA=='NO')
	{
	document.getElementById(ID).disabled=false;
	document.getElementById("actual_"+ID).disabled=false;
	document.getElementById("AsPerActual_"+ID).disabled=false;
	}
	else if (CA!='NO')
	{
	document.getElementById(ID).disabled=true;
	document.getElementById("AsPerActual_"+ID).disabled=true; 
	document.getElementById("actual_"+ID).disabled=true;
	document.getElementById(ID).value='';
	document.getElementById("actual_"+ID).value='';
	}    
}





var Total=0;



function DiscountAmount(DA,i)
{
	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	
	var rate = document.getElementById("Rate_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var quantity = document.getElementById("Quantity_"+i).value;
	//var totalPrice = quantity*rate;
	var totalPrice = document.getElementById("totalValue_"+i).value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
		var percent = parseFloat(document.getElementById("Discount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("NetRate_"+i).value=subTotal.toFixed(2);
	document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	//return true;
}	




function Check(Ta,i)
{
	var totalnetrate=parseFloat(document.getElementById("totalValue_"+i).value);
	var discount = parseFloat(document.getElementById("Discount_"+i).value);
	var discount1=parseFloat(document.getElementById("perc_"+i).value);
	if(totalnetrate<discount)	
	{
	alert("Discount Amount Not Greater then Total Price");
	document.getElementById("Discount_"+i).value='';
	document.getElementById("perc_"+i).value='';	
	document.getElementById("Discount_"+i).focus();
	}	
	else if(totalnetrate<discount1)	
	{
	alert("Discount Amount Not Greater then Total Price");
	document.getElementById("Discount_"+i).value='';
	document.getElementById("perc_"+i).value='';	
	document.getElementById("Discount_"+i).focus();
	}	
	
}




function check1(Ta1,i)
{
	var total1=parseFloat(document.getElementById("NetRate_"+i).value);	
	var Specialperc=parseFloat(document.getElementById("Specialperc_"+i).value);
	if(total1<Specialperc)	
	{
		alert("Special Discount Amount Not Greater then Sub Total");
		document.getElementById("SpecialDiscount_"+i).value='';
		document.getElementById("Specialperc_"+i).value='';	
		document.getElementById("SpecialDiscount_"+i).focus();	
	}
}

function DiscountAmountspe(DA,i)
{
	var total1=document.getElementById("NetRate_"+i).value;
	var discount1 = document.getElementById("SpecialDiscount_"+i).value;
	var Specialperc=document.getElementById("Specialperc_"+i).value;
	if(discount1=='' && Specialperc=='')
	{
	var total1=document.getElementById("NetRate_"+i).value;
	document.getElementById("basic_"+i).value=total1;
	}
	else
	{
	if(discount1=='' && Specialperc!='')
	{
	var elx=document.getElementById("Specialperc_"+i).value;
	var total1=document.getElementById("NetRate_"+i).value;
	var TotalAmount2 = total1-parseFloat(elx);
	document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
	}
	else
	{
	var percent1 = total1 * parseFloat(discount1)/100;
	var TotalAmount2 = total1-parseFloat(percent1);
	document.getElementById("Specialperc_"+i).value=percent1.toFixed(2);
	document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
	}
	}
}



function DiscountAmountdpc(DA,i)
{
	var discount_percent = document.getElementById("Perspc_"+i).value;
	var totalPrice = document.getElementById("NetRate_"+i).value;
	var discount = document.getElementById("SpecialDiscount_"+i).value;
	if(discount_percent=='PercentAmt' )
	{
	if(discount==''){discount=0;}
	var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
	var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
	var percent = parseFloat(document.getElementById("SpecialDiscount_"+i).value);
	if(isNaN(percent)){percent=0;}
	var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	if(parseFloat(discount)>=100 && discount_percent=='PercentAmt')
	{
	alert("Discount Percentage Should Be Less Then 100");
	document.getElementById("Specialperc_"+i).value='';
	document.getElementById("SpecialDiscount_"+i).value='';
	document.getElementById("basic_"+i).value='';
	document.getElementById("SpecialDiscount_"+i).focus();
	return false;
	}
	else
	{
	document.getElementById("Specialperc_"+i).value=percent.toFixed(2);
	document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	return true;
	}
}

function caldata(i)
{
	if(document.getElementById("exciseDuty_"+i).value=='')
	{
		alert("Please Select Excise Duty");
		document.getElementById("exciseDuty_"+i).focus();
	}	
}

 var TotalAmount=0;
function AmountWithtax(AWT, i ,j)
{
	var NetRate = document.getElementById("NetRate_"+i).value;
	var TaxValue = document.getElementById("taxvalue_"+i).value;
	var TotalAmountWithTax = (parseFloat(NetRate) * parseFloat(TaxValue))/100;
	if(isNaN(TotalAmountWithTax))
	{
		document.getElementById("totaltaxamount_"+i).value=parseFloat(0);
		document.getElementById("TotalAmountWirhTaxAmount_"+i).value = NetRate;
	}
	else
	{
		var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
		var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
		if(isNaN(TotalTaxAmount)){
		var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(0);
	}
	else
	{	
		var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(TotalTaxAmount) + parseFloat(NetRate);
	}
	}	
	TotalAmount=parseFloat(TotalAmount) + parseFloat(TotalCostWithTax);
	return true;
}

function totalGetvalue()
{
	var amount=0; 
	var ob;
	var count = document.getElementById("count").value;
	for(i=1;i<count;i++)
	{
	ob=document.getElementById("TotalAmountWirhTaxAmount_"+i);
	if(ob.value!='')
	{
	amount +=parseFloat(ob.value);
	}
	}
	document.getElementById("Total").value=amount;
}

function openPopUp(i)
{
	window.open("Search_Vendor.php?rowcount="+i,"Search_Vendor_window","height=425,width=400,toolbar=no,menubar=no,dependent=yes,resizable=yes,scrollbars=yes");
}

function Newvendor()
{
	window.redirect("POModule/MR_SelectOSMaterialRequi.php");
}

function valid()
{
	if(document.getElementById("VendorCodeSearch").value == '')
	{
	alert("Please Choose A Vendor Code From The Pop UP");
	document.getElementById("VendorCodeSearch").focus();
	return false;
	}
	return true;
}

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


function checkvalid()
{
	
	if(document.getElementById("mst_supplierno").value == '0')
	{
		alert("Please Select Vendor");
		document.getElementById("mst_supplierno").focus();
		return false;
	}
	if(document.getElementById("party_date").value == '')
	{
		alert("Please Select Party Date");
		document.getElementById("party_date").focus();
		return false;
	}
	if(document.getElementById("party_Quo_no").value == '')
	{
		alert("Please Fill The  Party Quotation No");
		document.getElementById("party_Quo_no").focus();
		return false;
	}
	if(document.getElementById("GrandTotal").value == '')
	{
		
		alert("Please Calculate Grand Total First !");
		document.getElementById("GrandTotal").focus();
		return false;
	}
	//var x=document.getElementById("party_Quo_no").value;
	//alert(x);
	
	
	
	if(document.getElementById("indent_prno").value == '')
	{
		alert("Please Select Indent/PR For Quotation");
		document.getElementById("indent_prno").focus();
		return false;
	}
	
	/*if(document.getElementById("Basis").value == '000')
	{
		alert("Please Select Basis");
		document.getElementById("Basis").focus();
		return false;
	}
	
	if(document.getElementById("PaymentTerm").value == '000')
	{
		alert("Please Select Payment Term");
		document.getElementById("PaymentTerm").focus();
		return false;
	}
	
	if(document.getElementById("PayMode").value == '000')
	{
		alert("Please Select Pay Mode");
		document.getElementById("PayMode").focus();
		return false;
	}*/
	
	
	
	

	
	
	

	/*if(document.getElementById("attachFile").value == '')
	{
		alert("Please Upload An Attachment");
		document.getElementById("attachFile").focus();
		return false;
	}
	
	if(document.getElementById("VenderQutation_TermCondition").value == '')
	{
		alert("Please Add Some Terms And Conditions");
		document.getElementById("VenderQutation_TermCondition").focus();
		return false;
	}*/
	
	
	/*var count=document.getElementById("hiditemcount").value;
	var arrList=[];
	for(var i=0; i<count; i++)
	{
		if(document.getElementById("rate_"+i).value =='')
		{
			alert("Please Enter The Rate First !");
			document.getElementById("rate_"+i).focus();
			return false;
		}
		if(document.getElementById("NetRate_"+i).value =='')
		{
			alert("Please Enter The Sub Total First !");
			document.getElementById("NetRate_"+i).focus();
			return false;
		}
		if(document.getElementById("basic_"+i).value =='')
		{
			alert("Please Enter The Basic Amount First !");
			document.getElementById("basic_"+i).focus();
			return false;
		}
		
		if(document.getElementById("hidBillingType_"+i).value =='')
		{
			alert("Please Select The Excise Flag First !");
			document.getElementById("hidBillingType_"+i).focus();
			return false;
		}
		if(document.getElementById("hidBillingType_"+i).value =='Excisable')
		{
			if(document.getElementById("exciseDuty_"+i).value =='')
			{
				alert("Please Select The Excise First !");
				document.getElementById("exciseDuty_"+i).focus();
				return false;
			}
			
			if(document.getElementById("exciseValue_"+i).value =='')
			{
				alert("Please Fill The Excise Value First !");
				document.getElementById("exciseValue_"+i).focus();
				return false;
			}
			
			if(document.getElementById("ECessValue_"+i).value =='')
			{
				alert("Please Fill The E-Cess Value First !");
				document.getElementById("ECessValue_"+i).focus();
				return false;
			}
			
			if(document.getElementById("SAHCessValue_"+i).value =='')
			{
				alert("Please Fill The SHE-Cess Value First !");
				document.getElementById("SAHCessValue_"+i).focus();
				return false;
			}
			
			
			if(document.getElementById("taxableAmt_"+i).value =='')
			{
				alert("Please Fill The Excise Amount First !");
				document.getElementById("taxableAmt_"+i).focus();
				return false;
			}
			
			if(document.getElementById("TotalSpecial_"+i).value =='')
			{
				alert("Please Fill The Total Amount First !");
				document.getElementById("TotalSpecial_"+i).focus();
				return false;
			}
			if(document.getElementById("itemID_"+i).value !='')
			{
				var itemName=document.getElementById("itemID_"+i).value;
			}
			if(document.getElementById("brand_"+i).value !='')
			{
				var itemName=document.getElementById("brand_"+i).value;
			}
			var newName=itemName+brandName;
			console.log(newName);
			arrList.push(newName);
		
		}
	}*/
	var arrList=[];
	var reteErrId='';
	var childgetids='itemID_';
	$('input[id^='+childgetids+']').each(function(){
		var a=$(this).attr("id");
		var idArr=a.split("_");
		var itemName=document.getElementById("itemID_"+idArr[1]).value;
		var brandName=document.getElementById("brand_"+idArr[1]).value;
		var rateItem=document.getElementById("rate_"+idArr[1]).value;
		var newName=itemName+brandName;
		if(parseInt(rateItem)<0 || rateItem==''){
			reteErrId="rate_"+idArr[1];
			return false;
		}
		console.log(newName);
		arrList.push(newName);
	});
	if(reteErrId!='' || parseInt(reteErrId)<0){
		alert('Enter Rate');
		document.getElementById(reteErrId).focus();
		return false;
	}
	var dupItm=0;
	for (var z = 0; z < arrList.length ; z++) {
      for (var y = z+1; y <arrList.length; y++) {
        if(arrList[z]==arrList[y]){
          dupItm=1;
        }
      }
    }
   /*  if(dupItm=='1'){
    	alert('Duplicate Item');
    	return false;
    } */
	
	//return false;
	
}

//$.noConflict();	
$(document).ready(function(){	
		$('input[name=item_popup]').click(function(){
			$("#div_id").dialog({
			title: 'Terms And Conditions',
            modal: true,
            resizable: false,
            width:300,
            height:300,
            closeText: 'fechar',
            draggable: true,
            show: 'fade',
            hide: 'fade',
            dialogClass: 'main-dialog-class',
				buttons: {
					Save: function()
					{
						assignSession();
						$(this).dialog("close");
					},
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		//CheckVendors(indentid);
		});
		
	
	});

function assignSession()
{
	var termscond=document.getElementById("VenderQutation_TermCondition").value;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","VenderQutation_TermCondition.php?t="+termscond,true);
	xmlhttp.send();
}
</script>
<!---**************************JAVASCRIPT FILES***************END HERE**********30-04-2013********AMITSINGH*************-->
<style>
.main-dialog-class .ui-widget-header{background: url("/Images/your-background.png") repeat-x scroll 34px 42px #a4cf50;font-size:14px;border:0;text-transform:uppercase}
.main-dialog-class .ui-widget-content{background-image:none;background-color:#fff}
</style>
<?php
$reqIDS=$s->GetFieldValue('indentpr_mapping'," id ='".$_REQUEST['mapid']."' " ,'indentPrno');
$getCat="select category from materialrequisitions where requisitionno in($reqIDS)";
$getCatExec = DB_query($getCat, $db);
$catrow = DB_fetch_array($getCatExec);
?>
    <input type="hidden" name="noVendor" value="<?php echo $noofVendors; ?>" />
    <input type="hidden" name="category" id="category" value="<?php echo $catrow['category']; ?>" />
    <input type="hidden" name="items" id="items" value="<?php echo $vendorList['ItemID']; ?>" />
    <input type="hidden" name="qty" id="qty" value="<?php echo $vendorList['mappedQty']; ?>" />
    <input type="hidden" name="prno" id="prno" value="<?php echo $reqIDS; ?>" />
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>vendor Quotation</h1>	
<form method="post" action="" enctype="multipart/form-data">	
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<input type="hidden" name="noVendor" value="<?php echo $noofVendors; ?>" />
<tr class="row1"> 
	<td width="13%" align="right"><strong>Site Name:</strong></td>
	<td width="20%"><?php echo $SiteName=$s->GetFieldValue('locations',"loccode='".$site."'",'locationname');?>
		<input type="hidden" name="Site" id="Site" value="<?php echo $site;?>" style="width:94%;" readonly></td>
	<td width="13%" align="right"><strong>Quotation Date:<font color="red">*</font></strong></td>
	<td width="20%"><input type="text" name="Quotation_Date" id="Quotation_Date" class="datepicker" value="<?php echo date('d/m/Y');?>" style="width:94%;" readonly></td>
	<td width="13%" align="right"><strong>Quotation No.:</strong></td>
	<td><input type="text" name="quotation_no" value="Auto Generate" style="width:94%;" readonly></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Vendor: <font color="red">*</font></strong></td>
	<td><select name="mst_supplierno" id="mst_supplierno" style="width:94%;" onchange="dispalyTax(this.value,'<?php echo $_REQUEST['frmid']; ?>');">
		<option value="0">Select</option>
			<?php
               if($VENDORsTR!='')
               {
               $sql="select id ,vendor_code, vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'  and id in(".$VENDORsTR.") order by vendor_name";
               }
               else
               {
			    $sql="select id ,vendor_code, vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."' and id in(".$vendorList['mapped_vendor'].") order by vendor_name";
               }               
			 $result = DB_query($sql, $db);
			 while($myrow = DB_fetch_array($result))
			 { 
			 $p='';
			 if($vendor==$myrow['id'])
			 $p="selected";
			?>
			<option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }	?></select><input type="hidden" name="mapid" id="mapid" value="<?php echo $vendorList['id']; ?>" /></td>
	<td align="right"><strong>RFQ No.:<font color="red">*</font></strong></td>
    <td><input type="text" readonly name="indent_prno" id="indent_prno" 
        value="<?php echo $s->GetFieldValue('indentpr_mapping'," id='".$_REQUEST['mapid']."' " ,'mapNo'); ?>" style="width:94%;" />
        <input type="hidden" readonly name="indent_prno" id="indent_prno" value="<?php echo $prNo; ?>" /></td>
	<td align="right"><strong>Indent/PR Date:</strong></td>
    <td><input type="text" name="" value="<?php echo ConvertSQLDate($vendorList['createdDate']);?>" style="width:94%;" readonly></td>    
</tr>
<tr class="row1">
	<td align="right"><strong>Party Quotation Number:<font color="red">*</font></strong></td>
	<td><input type="text" name="party_Quo_no" id="party_Quo_no" value="" style="width:94%;" onkeyup="leftTrim(this)" ></td>
	<td align="right"><strong>Party Quotation Date:<font color="red">*</font></strong></td>
    <td><input type="text" name="party_Quo_date" id="party_date" value="" class="datepicker" style="width:94%;" readonly></td>
    <td></td>
    <td> </td>
</tr>
</table>
<div style="width:100%;" id="ShowAllData"></div>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td align="right"><strong>Upload Attachment:</strong> <font style="color:red;">*</font></td>
 <td colspan="6"><input type="file" name="attachFile" id="attachFile" /></td>
 
 </tr>
<tr class="row1">
<td colspan="6" style="text-align:center;"><input type="Submit" name="submit" class="search" onclick="return checkvalid()" value="Save" /></td>
</tr>		
</table>
</form>
</div>
</div>

<script>
function calcTotAmt1(str,i)
{ 
    var totalamt=0;
    var quantity=document.getElementById("qty_"+i).value;
    if(quantity==''){quantity=0;}
    //alert(quantity);
    var finalAmt=parseFloat(str)*parseFloat(quantity);
    //alert(finalAmt);
    document.getElementById("price_"+i).value=finalAmt.toFixed(2);
    document.getElementById("basic_"+i).value=finalAmt.toFixed(2);
    //document.getElementById("TotalSpecial_"+i).value=finalAmt.toFixed(2);
    var countcharges = document.getElementById("hiditemcount").value;
    
			for(var l=0;l<countcharges;l++)
			{
			
			if(document.getElementById("basic_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}
			//alert(totalamt);
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);	
                        
                       document.getElementById("GrandTotal").value=totalamt.toFixed(2);
         //document.getElementById("totalTax").value=totalamt.toFixed(2);
	document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);
var GrandTotAmt = document.getElementById("GrandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
     
	document.getElementById("GrandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("GrandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
 }
 
 
 function DiscountAmounts1(DA,id)
{
    
	//numeric(DA,id);
        id1=id.split("_");
	    i=id1[1];
        
		var totValue = document.getElementById("price_"+i).value;
		var discType = document.getElementById("PerAmo_"+i).value;
		var disct = document.getElementById("Discount_"+i).value;
           if(disct=='') { disct=0;}  
           if(totValue=='') { totValue=0;}    
                if(parseFloat(disct)>parseFloat(totValue))
                    {
                        alert('Discount Cannot Be Greater Than Total Amount');
                        document.getElementById("Discount_"+i).value='';
                        document.getElementById("Discount_"+i).focus();
                        
                       // document.getElementById("basic_"+i).value='';
                        return false;
                    }
                    
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
                        //document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=0;l<countcharges;l++){
			if(document.getElementById("basic_"+l)!=null){
			if(document.getElementById("basic_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}}
			
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
                        //document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=0;l<countcharges;l++)
			{
			if(document.getElementById("basic_"+l)!=null){
			if(document.getElementById("basic_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}}
			
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);		
		}
                
       
    //alert(totalamt);
   

                  
 document.getElementById("GrandTotal").value=totalamt.toFixed(2);         
document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);
var GrandTotAmt = document.getElementById("GrandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
        
	document.getElementById("GrandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("GrandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}
  
  
function dispalyTax(str,frmid)
{
	if(str==0)
	document.getElementById("ShowAllData").innerHTML='';
	else
	{	
    var cat=document.getElementById("category").value;
    var itemID=document.getElementById("items").value;
    var qty=document.getElementById("qty").value;
    var req=document.getElementById("prno").value;
    var site=document.getElementById("Site").value;
    if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{	
	document.getElementById("ShowAllData").innerHTML=xmlhttp.responseText;
	}
	}
	//var site=document.getElementById("Site").value;
	
	//alert("GetVendorWiseTaxation.php?vendorId="+str+"&reqCat="+cat+"&items="+itemID+"&qty="+qty);
	//GetVendorWiseTaxation_itemwise.php?vendorId="+str+"&reqCat="+cat+"&items="+itemID+"&qty="+qty+"&prno="+req+"site="+site
	xmlhttp.open("GET","GetVendorWiseTaxation.php?vendorId="+str+"&reqCat="+cat+"&items="+itemID+"&qty="+qty+"&prno="+req+"&site="+site+"&frmid="+frmid,true);
	xmlhttp.send();
}
}

function showitemwise_details()
{
	
	var str=document.getElementById("mst_supplierno").value;
	var cat=document.getElementById("category").value;
    var itemID=document.getElementById("items").value;
    var qty=document.getElementById("qty").value;
    var req=document.getElementById("prno").value;
    if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{	
	document.getElementById("ShowAllData").innerHTML=xmlhttp.responseText;
	}
	}
	//alert("GetVendorWiseTaxation.php?vendorId="+str+"&reqCat="+cat+"&items="+itemID+"&qty="+qty);
	if(document.getElementById("dutytype").checked==true)
	{
	xmlhttp.open("GET","GetVendorWiseTaxation_itemwise.php?vendorId="+str+"&reqCat="+cat+"&items="+itemID+"&qty="+qty+"&prno="+req,true);
    }
    else
    {
    xmlhttp.open("GET","GetVendorWiseTaxation.php?vendorId="+str+"&reqCat="+cat+"&items="+itemID+"&qty="+qty+"&prno="+req,true);	
    }
	xmlhttp.send();


}
function calcTotAmtInt(str,ids)
{ 
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }

    var totalamt=0;
    var quantity=document.getElementById("qty_"+i).value;
    if(quantity==''){quantity=0;}
    if(str=='') { str=0;}
    //alert(quantity);
    var finalAmt=parseFloat(str)*parseFloat(quantity);
    //alert(finalAmt);
    document.getElementById("price_"+i).value=finalAmt.toFixed(2); 

    DiscountAmountsInt(finalAmt,i); 
 }

function pkgamt(ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }
var rate="rate_"+i;
var str=document.getElementById(rate).value;

calcTotAmtInt(str,i);

}


function DiscountAmountsInt(DA,ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }

	//numeric(DA,id);
      
       // alert(i);
		var totValue = document.getElementById("price_"+i).value;
		var discType = document.getElementById("PerAmo_"+i).value;
		var disct = document.getElementById("Discount_"+i).value;
		if(disct=='')
		{
			disct = 0.00;
			document.getElementById("Discount_"+i).value = '';
		}

			
                
                if(parseFloat(disct)>parseFloat(totValue))
                    {
                        alert('Discount Cannot Be Greater Than Total Amount');
                        document.getElementById("Discount_"+i).value='';
                        document.getElementById("Discount_"+i).focus();
                        
                       // document.getElementById("basic_"+i).value='';
                        return false;
                    }
                    
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
        }
		else
		{
			if(disct>100)
			{
				       alert('Discount % Should be less then 100');
                        document.getElementById("Discount_"+i).value='';
                        document.getElementById("Discount_"+i).focus();
                        
                        document.getElementById("basic_"+i).value='';
                        return false;

			}
			else
			{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	     	}
                       		
		}
		
        
        if(document.getElementById("hidBillingType_"+i).value!='')
        {
          if(document.getElementById("hidBillingType_"+i).value=='Excisable' || document.getElementById("hidBillingType_"+i).value=='IncludeTax')
          {
          	var exciseid="inputVat_"+i;
          	var exciseval=document.getElementById(exciseid).value;
          	tax_rate2(exciseval,i);

          	var exciseid12="exciseDuty_"+i;
          	var exciseval12=document.getElementById(exciseid12).value;
          	claculateExcise(exciseid12,exciseval12);

          }
          if(document.getElementById("hidBillingType_"+i).value=='NonExcisable')
          {
            var exciseid="exciseDuty_"+i;
          	var exciseval=document.getElementById(exciseid).value;
          	claculateExcise(exciseid,exciseval);
          }  
      }
        else
        {
        	document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
        	var val=document.getElementById("inputVat_"+i).value;
        	tax_rate2(val,i);
        }

       
}
function DiscountAmounts(DA,ids)
{
    if(isNumber(ids)){
    	i=ids
    } else {
	    var idsArr=ids.split('_');
	    var i=idsArr[1];     	
    }    
	//numeric(DA,id);
      
        
		var totValue = document.getElementById("price_"+i).value;
		var discType = document.getElementById("PerAmo_"+i).value;
		var disct = document.getElementById("Discount_"+i).value;
                
                if(parseFloat(disct)>parseFloat(totValue))
                    {
                        alert('Discount Cannot Be Greater Than Total Amount');
                        document.getElementById("Discount_"+i).value='';
                        document.getElementById("Discount_"+i).focus();                        
                       // document.getElementById("basic_"+i).value='';
                        document.getElementById("TotalSpecial_"+i).value='';
                        cal_grandtotal(i);
                        return false;
                    }
                    
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
            
		}
		else
		{
			if(disct>100)
			{
				       alert('Discount % Should be less then 100');
                        document.getElementById("Discount_"+i).value='';
                        document.getElementById("Discount_"+i).focus();                        
                        document.getElementById("basic_"+i).value='';
                        document.getElementById("TotalSpecial_"+i).value='';
                        cal_grandtotal(i);
                        return false;

			}
			else
			{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	     	}
            	
		}
                
       if(document.getElementById("hidBillingType_"+i).value!=0)
        {
          if(document.getElementById("hidBillingType_"+i).value=='Excisable' || document.getElementById("hidBillingType_"+i).value=='IncludeTax')
          {
          	var exciseid="inputVat_"+i;
          	var exciseval=document.getElementById(exciseid).value;
          	tax_rate2(exciseid,exciseval);
          }
          if(document.getElementById("hidBillingType_"+i).value=='NonExcisable')
          {
            var exciseid="exciseDuty_"+i;
          	var exciseval=document.getElementById(exciseid).value;
          	claculateExcise(exciseid,exciseval);
          }  
      }
        else
        {
        	document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
        	cal_grandtotal(i);
        }
}

    
 
    
function calcTotAmt(str,i)
{
    var totalamt=0;
    var quantity=document.getElementById("qty_"+i).value;
    if(quantity==''){quantity=0;}
    //alert(quantity);
    var finalAmt=parseFloat(str)*parseFloat(quantity);
    //alert(finalAmt);
    document.getElementById("price_"+i).value=finalAmt.toFixed(2);
    document.getElementById("basic_"+i).value=finalAmt.toFixed(2);
    document.getElementById("TotalSpecial_"+i).value=finalAmt.toFixed(2);
    var countcharges = document.getElementById("hiditemcount").value;
    
			for(var l=0;l<countcharges;l++)
			{
			if(document.getElementById("price_"+l)!=null){
			if(document.getElementById("price_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("price_"+l).value);
			}}
			
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);	
 }

/* function isNumberKey(sender, evt) {
    var txt = sender.value;
    //alert(evt.which);
    var dotcontainer = txt.split('.');
    var charCode = (evt.which) ? evt.which : event.keyCode;
    //alert(event.keyCode);
    if (!(dotcontainer.length == 1 && charCode == 46) && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
} */
function validate_floating(val,id)
{
   var data=id.split("_");
   var val1=parseFloat(val);
 
   if(val=="" || val1==0)
       {   document.getElementById(id).value="";
           document.getElementById(id).focus();
       }else{   
         document.getElementById(id).value=val1.toFixed(2);      
       }   
}

function addRow(obj,id)
{
    var table = document.getElementById('tableDataProduction');
	var rowCount = parseInt(document.getElementById('hiditemcount').value)+1;    
	/*var rowCount = table.rows.length;    
    if(rowCount == 1)
    {
    	count = 1
    }
    else {
    	count = rowCount;
    }*/
    
    var data=id.split('_');
    var thisRow = $(obj).closest( 'tr' )[0];
    var cloneData=$( thisRow ).clone().insertAfter( thisRow );
    cloneData.find('td').each(function(){        
        var el = $(this).find(':first-child');
        //console.log(el);
        var id = el.attr('id') || null;
        if(id) {
	        var idArr=id.split("_");
	        //var k=$(obj).closest('table').find('tr');
	        //k=k.length;
	        var newId=idArr
            el.attr('id', idArr[0]+('_'+rowCount));
            if($('#'+idArr[0]+('_'+rowCount)).attr('type')=='text'){
            	if(idArr[0]=='surchargeper'){

            	} else {
            		el.attr('value', '');
            	}            	
            }
            //cloneData.find('td').eq(2).html("");
            //console.log($('#'+idArr[0]+('_'+rowCount)).attr('type'));
        }
    });
    document.getElementById('hiditemcount').value=rowCount;

    

    

}
function isNumber(n) { return /^-?[\d.]+(?:e-?\d+)?$/.test(n); } 

 function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }

function leftTrim(element)
{
	if(element)
		element.value=element.value.replace(/^\s+/,"");
}

</script>
