	<?php
	include('cocoon_config.php');
	$PageName = 'Vendor Quotation';

	//unset($_SESSION['TermsValues']);
	//**************************SAVE THE DATA***************START HERE**********30-04-2013********AMITSINGH***************
	if ($_REQUEST['action'] == 'Edit' && $_REQUEST['id'] != '') {
		$QuoQry = DB_fetch_array(DB_query("select * from venderquotations where id='" . $_REQUEST['id'] . "'
	  and CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db));
	}

	if ($_REQUEST['submit']) {

		$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;
		$data['party_Quo_no']      = mysqli_real_escape_string($link1, $_REQUEST['party_Quo_no']);
		$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['total_amt']         = $_REQUEST['total_amt'];
		$data['total_taxable_amt'] = $_REQUEST['tot_taxable_amt'];
		$data['entry_tax']         = $_REQUEST['entry_tax_amt'];
		$data['other_charges']     = $_REQUEST['miscellaneous'];
		$data['grand_total']       = $_REQUEST['GrandTotal'];
		$data['total_grand_amt']   = $_REQUEST['total_po_amt'];
		$data['dis_per']           = $_REQUEST['discount_percent'];
		//$data['discounted_amt']    =$_REQUEST['discount_amt'];  
		$data['discount_amt']      = $_REQUEST['discount_amt_tot'];

		$data['modified_date']     = date('Y-m-d');
		$data['modified_by']       = trim($_SESSION['UserID']);
		$data['terms_condition']   = $_REQUEST['VenderQutation_TermCondition'];
		$data['include_gst'] = '1';
		$cond                      = "id='" . $_REQUEST['id'] . "'";
		// echo "<pre>"; print_r($data); echo "</pre>";
		// exit;
		$s->RecordEdit('venderquotations', $data, $cond);			//INSERT INTO PARANT TABLE
		$delVenQuotesDtlsSql = DB_query("delete from vendorquotationdetails where parant_id='" . $_REQUEST['id'] . "'", $db);

		for ($i = 0; $i < $_REQUEST['hiditemcount']; $i++) {
			$dataArr['parant_id']			= $_REQUEST['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['taxvalue']          = $_REQUEST['taxvalue1'][$i];
			$dataArr['TotalAmount']       = $_REQUEST['TotalAmount'][$i]; //print_r($dataArr);exit;
			$dataArr['brand_id'] = $_REQUEST['brand'][$i];
			$dataArr['gst_percent'] = $_REQUEST['inputVat'][$i];
			$dataArr['free_qty'] = $_REQUEST['freeqty'][$i];
			//$cond1  ="id='".$_REQUEST['venderquoto'][$i]."'";
			//echo "<pre>"; print_r($dataArr); echo "</pre>";
			$s->RecordInsert('vendorquotationdetails', $dataArr); //INSERT INTO CHIELD TABLE
			//echo $s->RecordEdit('vendorquotationdetails',$dataArr,$cond1);//INSERT INTO CHIELD TABLE		

		}
		//exit('test');
		$s->pageLocation("index.php?route=POModule/DispVendor_Quotes_gst" . $rurl);
	}

	?>
	<script type="text/javascript" src="POModule/po_calculation_gst_purchase.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("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 = '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("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("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 = '';

			} 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("surchargeper_" + i).disabled = false;
				document.getElementById("surchargeamt_" + 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("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");
			}

		}

		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];
			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("exciseValue_" + k).value = data[1];
					var id1 = "cessID1_" + i;
					var val1 = document.getElementById(id1).value;
					calEcessonchange(id1, val1);
				}
			}

			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);
			xmlhttp.open("GET", "ajax_getexcisevalue.php?ids=" + id + "&vls=" + val + "&bamt=" + totalabasic, true);
			xmlhttp.send();
		}


		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;
			var dis = document.getElementById("discount_amt_tot").value;

			if (totalbasic == '') {
				totalbasic = 0;
			}
			if (dis == '') {
				dis = 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(freight) + parseFloat(vatamt) + parseFloat(insurance) + parseFloat(miss) + parseFloat(pkg) + parseFloat(sur)).toFixed(2);
			total = parseFloat(total) - parseFloat(dis);
			total = parseFloat(total).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 calculate_exice_total() {
			var hid = document.getElementById("hiditemcount").value;

			var amt = 0;
			for (var i = 0; i < hid; i++) {
				if (document.getElementById("exciseValue_" + i).value != '') {
					var exval = document.getElementById("exciseValue_" + i).value;
					var amt = parseFloat(amt) + parseFloat(exval);
				}
			}
			document.getElementById("excise_duty_val").value = amt.toFixed(2);
			calculate_ecess_total();
		}

		function calculate_ecess_total() {
			var hid = document.getElementById("hiditemcount").value;

			var amt = 0;
			for (var i = 0; i < hid; i++) {
				if (document.getElementById("ECessValue_" + i).value != '') {
					var exval = document.getElementById("ECessValue_" + i).value;
					var amt = parseFloat(amt) + parseFloat(exval);
				}

			}
			document.getElementById("ecess_val").value = amt.toFixed(2);

			calculate_shecess_total();
		}


		function calEcessonchange(id, val) {


			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);
				}
			}
			var id1 = id.split("_");
			var i = id1[1];
			var ecessval = document.getElementById("exciseValue_" + i).value;
			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 calculate_shecess_total() {

			var hid = document.getElementById("hiditemcount").value;

			var amt = 0;
			for (var i = 0; i < hid; i++) {
				if (document.getElementById("SAHCessValue_" + i).value != '') {
					var exval = document.getElementById("SAHCessValue_" + i).value;
					var amt = parseFloat(amt) + parseFloat(exval);
				}

			}
			document.getElementById("shecess_val").value = amt.toFixed(2);

			calculate_freight();
		}


		function calculate_freight() {

			var hid = document.getElementById("hiditemcount").value;

			var amt = 0;
			for (var i = 0; i < hid; i++) {
				if (document.getElementById("freightItem_" + i).value != '') {
					var exval = document.getElementById("freightItem_" + i).value;
					var amt = parseFloat(amt) + parseFloat(exval);
				}

			}
			document.getElementById("TotalCharge").value = amt.toFixed(2);

			calculate_vat_total();

		}

		function calculate_vat_total() {

			var hid = document.getElementById("hiditemcount").value;

			var amt = 0;
			for (var i = 0; i < hid; i++) {
				if (document.getElementById("taxvalue_" + i).value != '') {
					var exval = document.getElementById("taxvalue_" + i).value;
					var amt = parseFloat(amt) + parseFloat(exval);
				}

			}
			document.getElementById("taxvalue").value = amt.toFixed(2);

			cal_total_grand();
		}

		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 tax_rate2(str, ids) {
			if (isNumber(ids)) {
				i = ids
			} else {
				var idsArr = ids.split('_');
				var i = idsArr[1];
			}
			//alert(i);
			var bill_type = document.getElementById("hidBillingType_" + i).value;
			var basic = document.getElementById("basic_" + i).value;
			var freight = document.getElementById("freightItem_" + i).value;
			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;
			xmlhttp.open("GET", "get_tax_valdata_item.php?taxid=" + str2 + "&amt=" + taxableAmount2, true);
			xmlhttp.send();
		}

		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 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 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;
			var sumOfArea6 = 0;
			var sumOfArea7 = 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;
				}
			});


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

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

			$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;
			document.getElementById("tot_taxable_amt").value = sumOfArea7.toFixed(2);


			cal_total_grand();
		}


		function cal_grandamount() {
			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("taxvalue"))
				var taxamt = document.getElementById("taxvalue").value;
			if (document.getElementById("pkg_charges1"))
				var packagingCharges = document.getElementById("pkg_charges1").value;
			if (document.getElementById("additionalCharges"))
				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;
			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;
			var pkg = document.getElementById("pkg_charges1").value;
			var freight = document.getElementById("TotalCharge").value;
			var surcharge = document.getElementById("sur_oct_amt").value;
			if (total == '') {
				total = 0;
			}
			if (insurance == '') {
				insurance = 0;
			}
			if (pkg == '') {
				pkg = 0;
			}
			if (freight == '') {
				freight = 0;
			}
			if (surcharge == '') {
				surcharge = 0;
			}
			if (taxamt == '') {
				taxamt = 0;
			}
			if (miscellaneous == '') {
				miscellaneous = 0;
			}
			//alert(insurance);
			var grandtotal = parseFloat(total) + parseFloat(insurance) + parseFloat(miscellaneous) + parseFloat(taxamt) + parseFloat(pkg) + parseFloat(freight) + parseFloat(surcharge);


			//grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge);
			var gradamt = grandtotal.toFixed(2);
			//alert(grandtotal);
			var h = gradamt.split(".");

			if (h[1] == undefined) {
				document.getElementById("pluMin").value = '';
				document.getElementById("roundVal").value = '';
				document.getElementById("GrandTotal").value = gradamt;

			} 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);
				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("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("party_Quo_no").value == '') {
				alert("Please Fill The  Party Quotation No");
				document.getElementById("party_Quo_no").focus();
				return false;
			}

			/*if(document.getElementById("party_date").value == '')
			{
				alert("Please Select Party Date");
				document.getElementById("party_date").focus();
				return false;
			}*/




			/*var count=document.getElementById("hiditemcount").value;
			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("GrandTotal").value == '' || document.getElementById("GrandTotal").value == '0.00') {
				alert("Please Calculate Grand Total First !");
				document.getElementById("GrandTotal").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 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;
			}


		}


		$.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();
		}

		function calcServtax() {
			var rate = document.getElementById("serviceTaxRate").value;

			var totalAmount = document.getElementById("total_item_amount").value;
			if (totalAmount == '') {
				totalAmount = '';
			}
			var finalAmt = parseFloat(rate * totalAmount / 100);
			document.getElementById("serviceTaxValue").value = finalAmt.toFixed(2);

			var totalamt = parseFloat(totalAmount) + parseFloat(finalAmt);
			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 calcServtax_ledger(str) {

			var totalAmount = document.getElementById("total_item_amount").value;
			var tdsRate = document.getElementById("tdsRate").value;
			var tdsEcessRate = document.getElementById("tdsEcessRate").value;
			var tdshEcessValue = document.getElementById("tdshEcessValue").value;
			if (totalAmount == '') {
				totalAmount = 0;
			}
			if (tdsRate == '') {
				tdsRate = 0;
			}
			if (tdsEcessRate == '') {
				tdsEcessRate = 0;
			}
			if (tdshEcessValue == '') {
				tdshEcessValue = 0;
			}
			if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else { // code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

					var data = xmlhttp.responseText.split("_");
					document.getElementById("abtmntRate").value = data[0];
					document.getElementById("abtmntValue1").value = data[1];
					document.getElementById("abtmntValue2").value = data[2];
					document.getElementById("serviceTaxRate").innerHTML = data[3];
					document.getElementById("serviceTaxValue").value = data[4];
					document.getElementById("ecessid").value = data[5];
					document.getElementById("ecessRate").value = data[6];
					document.getElementById("ecessValue").value = data[7];
					document.getElementById("sheid").value = data[8];
					document.getElementById("sheRate").value = data[9];
					document.getElementById("sheValue").value = data[10];
					document.getElementById("totalTax").value = data[11];
					document.getElementById("wctValue").value = data[12];
					document.getElementById("tdsValue").value = data[13];
					document.getElementById("tdsEcessValue").value = data[14];
					document.getElementById("tdshEcessValue").value = data[15];
					document.getElementById("pluMin").value = data[16];
					document.getElementById("roundVal").value = data[17];
					document.getElementById("GrandTotal").value = data[18];



				}
			}

			xmlhttp.open("GET", "ajax_service_map.php?str=" + str + "&basic=" + totalAmount + "&tdsrate=" + tdsRate + "&tdsEcessRate=" + tdsEcessRate + "&tdshEcessValue=" + tdshEcessValue, true);
			xmlhttp.send();

		}

		function calcEcesstax() {
			var rate = document.getElementById("ecessRate").value;

			var totalAmount = document.getElementById("serviceTaxValue").value;
			if (totalAmount == '') {
				totalAmount = '';
			}
			var finalAmt = parseFloat(rate * totalAmount / 100);
			document.getElementById("ecessValue").value = finalAmt.toFixed(2);


			var totalAmountBsic = document.getElementById("total_item_amount").value;
			var totalamt = parseFloat(totalAmount) + parseFloat(totalAmountBsic) + parseFloat(finalAmt);
			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 calcShetax() {
			var rate = document.getElementById("sheRate").value;

			var totalAmount = document.getElementById("serviceTaxValue").value;
			if (totalAmount == '') {
				totalAmount = '';
			}
			var finalAmt = parseFloat(rate * totalAmount / 100);
			document.getElementById("sheValue").value = finalAmt.toFixed(2);


			var totalAmountBsic = document.getElementById("total_item_amount").value;
			var totalEcess = document.getElementById("ecessValue").value;
			var totalamt = parseFloat(totalAmount) + parseFloat(totalAmountBsic) + parseFloat(totalEcess) + parseFloat(finalAmt);
			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';
			}
		}
	</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
	$prdate = $s->GetFieldValue('materialrequisitions', "requisitionno='" . $QuoQry['indent_prno'] . "'", 'prdate');
	?>

	<input type="hidden" name="prno" id="prno" value="<?php echo $prNoStr; ?>" />
	<link rel="stylesheet" href="css/new_mxerp.css">
	<div class="body_contain">
		<div class="tab_div">
			<h1><?php echo $page_title; ?></h1>
			<form method="post" action="" enctype="multipart/form-data">
				<table width="100%" border="0" cellpadding="3" cellspacing="0">
					<tr class="row1">
						<td width="13%" align="right"><strong>Site Name :</strong></td>
						<td width="20%"><?php echo $SiteName = $s->GetFieldValue('locations', "loccode='" . $QuoQry['Site'] . "'", 'locationname'); ?></td>
						<td width="13%" align="right"><strong>Quotation Date / No. :</strong>
							<font color="red">*</font>
						</td>
						<td width="20%"><?php echo ConvertSQLDate($QuoQry['Quotation_Date']) . ' '; ?></td>
						<td width="13%" align="right"><strong>Quotation No. :</strong>
							<font color="red">*</font>
						</td>
						<td><?php echo $QuoQry['quotation_no']; ?></td>
					</tr>
					<tr class="row1">
						<td align="right"><strong>Vendor :</strong>
							<font color="red">*</font>
						</td>
						<td><?php echo $s->GetFieldValue('suppliers', "id='" . $QuoQry['mst_supplierno'] . "'", 'vendor_name') . '<br/>'; ?>
							<input type="hidden" name="mapid" value="<?PHP echo $QuoQry['mst_supplierno']; ?>">
						</td>
						<td align="right"><strong>RFQ No. :</strong>
							<font color="red">*</font>
						</td>
						<td><?php echo $s->GetFieldValue('indentpr_mapping', " id='" . $QuoQry['mapid'] . "' ", 'mapNo'); ?></td>
						<td align="right"><strong>REQ Date :</strong></td>
						<td><input type="text" name="" value="<?php echo ConvertSQLDate($prdate); ?>" readonly /></td>
					</tr>
					<tr class="row1">
						<td align="right"><strong>Party Quotation Number :</strong>
							<font color="red">*</font>
						</td>
						<td><input type="text" name="party_Quo_no" id="party_Quo_no" value="<?php echo $QuoQry['party_Quo_no']; ?>" onkeyup="leftTrim(this)" /></td>
						<td align="right"><strong>Party Quotation Date :</strong>
							<font color="red">*</font>
						</td>
						<td><?php echo ConvertSQLDate($QuoQry['party_Quo_date']); ?></td>
						<td nowrap="nowrap">&nbsp;</td>
						<td nowrap="nowrap">&nbsp;</td>
					</tr>
				</table>
				<br>

				<h3>Item Details</h3>
				<div style="width:100%; overflow:auto; margin:0 auto;" id="ShowAllData">
					<?php
					$vendorType = $s->GetFieldValue('suppliers', "id='" . $QuoQry['mst_supplierno'] . "'", 'vendor_type');
					$loc_state = $s->GetFieldValue("locations", "loccode='" . $QuoQry['Site'] . "'", "state");
					$vendor_state = $s->GetFieldValue("suppliers", "id='" . $QuoQry['mst_supplierno'] . "'", "state");
					$category = $s->GetFieldValue('materialrequisitions', "requisitionno='" . $QuoQry['mapid'] . "'", 'category');
					if ($vendorType == 'Domestic') {
					?>
						<table width="100%" border="1" cellspacing="0" cellpadding="3" style=" border:1px solid #808080;" id="tableDataProduction">
							<tr>
								<th width="3%">S. No.</th>
								<th>Item Name</th>
								<th width="5%">UOM</th>
								<th width="5%">Qty.</th>
								<th width="5%">Free Qty.</th>
								<th width="5%">Brand</th>
								<th width="5%">Quoted Rate</th>
								<th width="5%">Total Price</th>
								<th colspan="2">Discount</th>
								<th width="5%">Basic Amount</th>
								<th width="5%">Pkg Amt.</th>
								<!-- <th width="4%">Excise flag</th>
	<th width="4%">Excise</th>
    <th width="4%">Excise Value</th>
	<th width="4%">E-Cess</th>
	<th width="4%">E-Cess Value</th>
	<th width="4%">SAH-E Cess</th>
	<th width="4%">SAH-E Cess Value</th> -->
								<th width="5%">Taxable<br />Amt.</th>
								<th width="5%">Freight and P&amp;S</th>
								<th width="5%">Input<br />GST</th>
								<th width="5%">Value</th>
								<!-- <th width="4%">Surcharge</th> -->
								<th width="5%">Surcharge Amt</th>
								<th width="5%">Total<br /> Amt.</th>
							</tr>
							<?php $i = 0;
							// echo "select * from vendorquotationdetails where parant_id='".$QuoQry['id']."'";
							$desql = DB_query("select * from vendorquotationdetails where parant_id='" . $QuoQry['id'] . "'", $db);
							while ($rowsql = DB_fetch_array($desql)) {
								$ItemName = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'item_name');
								$UnitId = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'mst_unitid');
								$UnitName = $s->GetFieldValue('unitsofmeasure', "unitid='" . $UnitId . "'", 'unitname');
								$purchase_vat = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'vat_purchase');
								$purchase_cst = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'cst_purchase');
								if ($vendor_state == $loc_state) {
									$vatid = $purchase_vat;
								} else {
									$vatid = $purchase_cst;
								}
								$ItemCode = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'StockID');
								$itemSql = "select id from itemforms where item_code='" . $ItemCode . "'";
								$item_sql = mysqli_query($link1, $itemSql);
								$item_row = mysqli_fetch_array($item_sql);
								$brndSql = "select id,brand_desc from branditems where itemform_id='" . $item_row['id'] . "'";
								$brand_sql = mysqli_query($link1, $brndSql);
							?>
								<tr bgcolor="#fff">
									<td><?php //echo ($i+1).'.'; 
										?><input type="hidden" name="venderquoto[]" value="<?php echo $rowsql['id']; ?>"><input type="button" onclick="javascript:addRow(this,this.id);" id="add_<?php echo $i; ?>" value="+"></td>
									<td><input type="hidden" name="itemID[]" id="itemID_<?php echo $i; ?>" value="<?php echo $rowsql['mst_itemid']; ?>" /><?php echo $ItemName; ?></td>
									<td><?php echo $UnitName; ?></td>
									<td><?php echo $rowsql['Quantity']; ?><input type="hidden" name="qty[]" id="qty_<?php echo $i; ?>" value="<?php echo $rowsql['Quantity']; ?>" onkeypress="javascript:return isNumberKey(this,event)" maxlength="11" onblur="javascript:validate_floating(this.value,this.id)" /></td>
									<td><input type="text" name="freeqty[]" id="freeqty_<?php echo $i; ?>" value="<?php echo $rowsql['free_qty']; ?>" onkeypress="javascript:return isNumberKey(this,event)" maxlength="11" onblur="javascript:validate_floating(this.value,this.id)" /></td>
									<td><select name="brand[]" id="brand_<?php echo $i; ?>" style="width:100%;">
											<option value="">Brand</option><?php while ($brand_row = mysqli_fetch_array($brand_sql)) { ?>
												<option value="<?php echo $brand_row['id']; ?>" <?php if ($brand_row['id'] == $rowsql['brand_id']) {
																									echo 'selected';
																								} ?>><?php echo $brand_row['brand_desc']; ?></option>
											<?php }  ?>
										</select></td>
									<td><input type="text" autocomplete="off" name="rate[]" id="rate_<?php echo $i; ?>" value="<?php echo $rowsql['Rate']; ?>" onkeyup="calcTotAmtInt(this.value,this.id);" onkeypress="return isNumberKey(event)" /></td>
									<td><input type="text" readonly name="price[]" id="price_<?php echo $i; ?>" onkeypress="return isNumberKey(event)" value="<?php echo $rowsql['totalPrice']; ?>" class='basic' /></td>
									<td width="5%"><input type="text" name="Discount1[]" onkeypress="return isNumberKey(event)" value="<?php echo $rowsql['Discount']; ?>" onkeyup="DiscountAmountsInt(this.value,this.id<?php //echo $i; 
																																																							?>)" autocomplete="off" id="Discount_<?php echo $i; ?>" class='dis' /></td>
									<td width="5%"><select name="DiscountType1[]" id="PerAmo_<?php echo $i; ?>" onchange="DiscountAmounts(this.value,this.id<?php //echo $i; 
																																							?>)">
											<option value="Amount" <?php echo ($rowsql['DiscountType'] == 'Amount') ? 'selected' : '' ?>>Amt</option>
											<option value="PercentAmt" <?php echo ($rowsql['DiscountType'] == 'PercentAmt') ? 'selected' : '' ?>>%</option>
										</select></td>
									<td><input type="text" id="basic_<?php echo $i; ?>" name="basic_Amt1[]" value="<?php echo $rowsql['basic_Amt']; ?>" readonly class="basicafterdiscount" /></td>
									<td><input type='text' id='pkgamt_<?php echo $i; ?>' onkeypress="return isNumberKey(event)" name='pkg_Amt[]' onkeyup='pkgamt(this.value,this.id);' value="<?php echo $rowsql['pkg_amt']; ?>" class='pkgamt' /></td>

									<!--<td><select name="Excise_type[<?php //echo $i;
																		?>]" id="hidBillingType_<?php //echo $i;
																								?>" onchange="checkExcisable(this.value,this.id)">
	<option value="">Select</option>
	<option value="NonExcisable" <?php //echo ($rowsql['Excise_type']=='NonExcisable'?'selected':'')
									?>>NonExcisable</option>
	<option value="Excisable" <?php //echo ($rowsql['Excise_type']=='Excisable'?'selected':'')
								?>>Excisable</option>
	<option value="IncludeTax" <?php //echo ($rowsql['Excise_type']=='IncludeTax'?'selected':'')
								?>>IncludeTax</option>
	</select></td>
    <?php //if($rowsql['Excise_type']=='NonExcisable') { $disable="disabled";$vatdisable=''; } 
								//else if($rowsql['Excise_type']=='Excisable') { $vatdisable="disabled"; $vatdisable='disabled';} 
								//else if($rowsql['Excise_type']=='Excisable') { $vatdisable=""; $disable=''; }  
	?>       
 <td><select name="Excise_Duty[<?php //echo $i; 
								?>]" id="exciseDuty_<?php //echo $i; 
													?>" <? php // echo $disable; 
														?> onchange="claculateExcise(this.id,this.value)" onfocus="checkexiseflag(this.id<?php //echo $i; 
																																			?>)">
    	<option value="">Select</option>
		   <?php
								//$excise_sql=DB_query("select * from excise_tax where ledgertype='excisetax' and form_type='Purchase' group by caption"	,$db);     	    
								//$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
								//while($excise_row=DB_fetch_array($excise_sql))
								//{
			?>
		<option value="<?php //echo $excise_row['id']; 
						?>" <?php //echo ($excise_row['id']==$rowsql['Excise_Duty']?'selected':'')
							?>><?php //echo $excise_row['caption']; 
								?></option>
			<?php //} 
			?></select></td>        
 <td><input name="exciseValue[<?php //echo $i; 
								?>]" class='excise' id="exciseValue_<?php //echo $i; 
																	?>" value="<?php //echo $rowsql['ExciseValue']
																				?>" type="text" /></td>        
<?php
								//$cessLedgerSql1=DB_query("Select * from excise_tax where ledgertype='cess' and form_type='Purchase' group by caption  limit 0,1  ",$db);
								//$cessLedgerSql2=DB_query("Select * from excise_tax where ledgertype='scess' and form_type='Purchase' group by caption limit 0,1  ",$db);
?>
 <td><select name="Cess_ID[<?php //echo $i; 
							?>]" id="cessID1_<?php //echo $i; 
												?>" <?php //echo $disable; 
													?> onchange='calEcessonchange(this.id,this.value)'>
<?php //$cessLedger1=DB_fetch_array($cessLedgerSql1)
?>
<option value="<?php //echo $cessLedger1['id'];
				?>" <?php //echo ($cessLedger1['id']==$rowsql['Cess_ID']?'selected':'')
					?>><?php //echo $cessLedger1['caption'];
						?></option></select></td>
 <td><input name="ECessValue[<?php //echo $i; 
								?>]" class='ecess' readonly id="ECessValue_<?php //echo $i; 
																			?>"  type="text" value="<?php //echo $rowsql['ECessValue']; 
																									?>"/></td>        
 <td><select name="SHECess_ID[<?php //echo $i; 
								?>]" id="cessID2_<?php //echo $i; 
													?>" <?php //echo $disable; 
														?> onchange='calSHEcessonchange(this.id,this.value)'>	
	<?php //$cessLedger2=DB_fetch_array($cessLedgerSql2)
	?>
		<option value="<?php //echo $cessLedger2['id'];
						?>" <?php //echo ($cessLedger2['id']==$rowsql['SHECess_ID']?'selected':'')
							?>><?php //echo $cessLedger2['caption'];
								?></option>
	<?php ?>
	</select></td>        
 <td><input name="SAHCessValue[<?php //echo $i; 
								?>]" class='shecess' id="SAHCessValue_<?php //echo $i; 
																		?>" type="text" value="<?php //echo $rowsql['SAHCessValue']; 
																								?>" readonly /></td> -->
									<td><input type="text" name="taxable_amt[<?php //echo $i; 
																				?>]" id="taxableAmt_<?php echo $i; ?>" value="<?php echo $rowsql['taxable_amt']; ?>" readonly class='taxable' /></td>
									<td><input type="text" name="freightItem[<?php //echo $i; 
																				?>]" onkeypress="return isNumberKey(event)" class='freight' id="freightItem_<?php echo $i; ?>" onkeyup="calcfreight(this.value,this.id)" value="<?php echo $rowsql['freightItem']; ?>" /></td>
									<td><input type="text" name="inputVat[<?php //echo $i; 
																			?>]" id="inputVat_<?php echo $i; ?>" readonly value="<?php echo $rowsql['gst_percent']; ?>"></td>
									<td><input type="text" name="taxvalue1[<?php //echo $i; 
																			?>]" id="taxvalue_<?php echo $i; ?>" value="<?php echo $rowsql['taxvalue']; ?>" class='vat' readonly="true" class="taxable" /> </td>
									<!-- <td><input type='text' name='surchargeper[]'  id='surchargeper_<?php //echo $i; 
																										?>' value='<?php //echo $s->getField('sales_tax_master','salestax_id',$rowsql['inputVat'],'surcharge_rate'); 
																													?>' readonly='true'/></td> -->
									<td><input type='text' name='surchargeamt[]' class='surcharge' id='surchargeamt_<?php echo $i; ?>' value='<?php echo $rowsql['sur_amt']; ?>' onkeyup="cal_surchrgeamt(this.value,this.id);" /></td>
									<td><input type="text" id="TotalSpecial_<?php echo $i; ?>" name="TotalAmount[<?php //echo $i;
																													?>]" readonly value="<?php echo $rowsql['TotalAmount']; ?>" /></td>
								</tr>
							<?php $i++;
							} ?>
							<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>" />
						</table>
				</div>
				<br>

				<table width="100%" cellspacing="0" cellpadding="3" border="0">
					<tr>
						<td width="60%" valign="top">
							<table width="100%" cellspacing="0" cellpadding="3" border="0">
								<tr class="row1">
									<td width="18%" align="right"><strong>Terms and Conditions:</strong></td>
									<td><textarea name="VenderQutation_TermCondition" id="VenderQutation_TermCondition" style="height:80px;"><?php echo $QuoQry['terms_condition']; ?></textarea></td>
								</tr>
							</table>
						</td>
						<td valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="3">
								<tr class="row1">
									<td width="40%" align="right"><strong>TOTAL AMOUNT:</strong></td>
									<td><input type="text" name="basic_amt" id="total_item_amount" value="<?php echo $QuoQry['basic_amt']; ?>" onfocus="cal_totalamount()" /></td>
								</tr>
								<tr class="row1">
									<td width="40%" align="right"><strong>Discount:</strong></td>
									<td><input type="text" name="discount_amt_tot" id="discount_amt_tot" value="<?php echo $QuoQry['discount_amt']; ?>" onkeyup="total_dis(this.value)" /></td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Pkg Charges:</strong> </td>
									<td><input name="pkg_charges" readonly id="pkg_charges1" readonly value="<?php echo $QuoQry['pkg_charges']; ?>" type="text" /></td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Taxable Amount:</strong> </td>
									<td><input name="tot_taxable_amt" readonly id="tot_taxable_amt" readonly style="width:94%" type="text" value="<?php echo $QuoQry['total_taxable_amt']; ?>" /></td>
								</tr>
								<!-- <tr class="row1">
        	<td align="right"><strong>Excise Duty:</strong></td>
            <td><input type="text" name="excise_duty_val" id="excise_duty_val" value="<?php  //echo $QuoQry['excise_amt']; 
																						?>" value=""  readonly="true"/></td>
        </tr>
        <tr class="row1">
        	<td align="right"><strong>Ecess:</strong></td>
            <td><input type="text" name="ecess_val" id="ecess_val" value="<?php  //echo $QuoQry['ecess_amt']; 
																			?>"  readonly="true"/></td>
        </tr>
        <tr class="row1">
        	<td align="right"><strong>SHEcess:</strong></td>
            <td><input type="text" name="shecess_val" id="shecess_val" value="<?php  //echo $QuoQry['s_ecess_amt']; 
																				?>"  readonly="true"/></td>
        </tr> -->
								<tr class="row1">
									<td align="right"><strong>Freight And P&amp;S:</strong></td>
									<td><input type="text" name="Freight" id="TotalCharge" value="<?php echo $QuoQry['Freight']; ?>" readonly="true" /></td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>GST Value:</strong></td>
									<td>
										<div id="taxval"><input type="text" name="taxvalue" id="taxvalue" value="<?php echo $QuoQry['taxvalue']; ?>" readonly="true" /></div>
									</td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Surcharge Amount:</strong></td>
									<td><input name="surcharge_amt" readonly type="text" id="sur_oct_amt" value="<?php echo $QuoQry['surcharge_amt']; ?>" /></td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Insurance:</strong></td>
									<td><input name="insurance" id="insurance" type="text" value="<?php echo $QuoQry['insurance']; ?>" onkeyup="cal_insurance()" /></td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Miscellaneous:</strong></td>
									<td><input type="text" value="<?php echo $QuoQry['other_charges']; ?>" name="miscellaneous" id="miscellaneous" onkeyup="cal_insurance()" /></td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Round Off:</strong></td>
									<td><input type="text" name="pluMin" readonly id="pluMin" value="<?php echo $QuoQry['pluMin']; ?>" style="width:49%; float:left; margin-right:2px;" />
										<input type="text" name="roundVal" readonly id="roundVal" value="<?php echo $QuoQry['roundOff']; ?>" style="width:49%; float:left;" />
									</td>
								</tr>
								<tr class="row1">
									<td align="right"><strong>Grand Total:</strong></td>
									<td><input type="text" name="GrandTotal" readonly id="GrandTotal" value="<?php echo $QuoQry['grand_total']; ?>" />
										<input type="hidden" id="orig_grand_tot" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			<?php } else { ?>
				<h3>Item Details</h3>
				<table width="100%" border="1" cellspacing="0" cellpadding="3" style=" border:1px solid #808080;">
					<tr>
						<th width="3%">S. No.</th>
						<th>Item Name</th>
						<th width="10%">UOM</th>
						<th colspan="2"><!--Specification</strong>--></th>
						<th width="10%">Qty.</th>
						<th width="10%">Quoted Rate</th>
						<th width="10%">Amount</th>
						<th colspan="2">Discount</th>
						<th width="10%">Basic Amount</th>
						<th width="10%">Currency</th>
					</tr>
					<?php
						$i = 0;
						$desql = DB_query("select * from vendorquotationdetails where parant_id='" . $QuoQry['id'] . "'", $db);
						while ($rowsql = DB_fetch_array($desql)) {
							$ItemName = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'item_name');
							$UnitId = $s->GetFieldValue('item_master', "id='" . $rowsql['mst_itemid'] . "'", 'mst_unitid');
							$UnitName = $s->GetFieldValue('unitsofmeasure', "unitid='" . $UnitId . "'", 'unitname');
					?>
						<tr>
							<td><?php echo ($i + 1) . '.'; ?> <input type="hidden" name="venderquoto[]" value="<?php echo $rowsql['id']; ?>"></td>
							<td><input type="hidden" name="itemID[]" id="itemID_<?php echo $i; ?>" value="<?php echo $rowsql['mst_itemid']; ?>" />
								<?php echo $ItemName; ?></td>
							<td><?php echo $UnitName; ?></td>
							<td width="1"><!--<select  name="sizesp[]" id="sizesp_<?php echo $i; ?>"  width="50px;"    >
              <option value="0">select</option>
              <?php
							$resultSize = DB_query("select * from size_master", $db);
							while ($rowSize = DB_fetch_array($resultSize)) {
								$size1 = '';
								if ($rowSize['id'] == $rowsql['size'])
									$size1 = "selected";
				?>
              <option value="<?php echo $rowSize['id']; ?>" <?php echo $size1; ?>><?php echo $rowSize['size']; ?></option>
               <?php }
				?></select>--></td>
							<td width="1"><!--<select  name="gradesp[]" id="gradesp_<?php echo $i; ?>"  width="50px;" >
             <option value="0">select</option>
            <?php
							$resultGrade = DB_query("select * from product_grade", $db);
							while ($rowGrade = DB_fetch_array($resultGrade)) {
								$grade1 = '';
								if ($rowGrade['id'] == $rowsql['grade'])
									$grade1 = "selected";

			?>
     <option value="<?php echo $rowGrade['id']; ?>" <?php echo $grade1; ?> ><?php echo $rowGrade['grade']; ?></option>
       <?php }
		?>   
   </select>--></td>
							<td><input type="hidden" name="qty[]" id="qty_<?php echo $i; ?>" value="<?php echo $rowsql['Quantity']; ?>" />
								<?php echo $rowsql['Quantity']; ?></td>
							<td><input type="text" autocomplete="off" name="rate[]" id="rate_<?php echo $i; ?>" onkeyup="calcTotAmt1(this.value,'<?php echo $i; ?>');" value="<?php echo $rowsql['Rate']; ?>" onkeypress="javascript:return isNumberKey(this,event)" maxlength="11" onblur="javascript:validate_floating(this.value,this.id)" /></td>
							<td><input type="text" readonly name="price[]" id="price_<?php echo $i; ?>" value="<?php echo $rowsql['totalPrice']; ?>" /></td>
							<td width="5%"><input type="text" name="Discount1[]" onblur="javascript:validate_floating(this.value,this.id)" maxlength="11" onkeypress="javascript:return isNumberKey(this,event)" onkeyup="DiscountAmounts1(this.value,this.id)" onblur="javascript:validate_floating(this.value,this.id)" maxlength="11" onkeypress="javascript:return isNumberKey(this,event)" autocomplete="off" id="Discount_<?php echo $i; ?>" value="<?php echo $rowsql['Discount']; ?>" />
							</td>
							<td width="5%"><select name="DiscountType1[]" id="PerAmo_<?php echo $i; ?>" onchange="DiscountAmounts1(this.value,this.id)">
									<option value="Amount" <?php echo ($rowsql['DiscountType'] == 'Amount') ? 'selected' : '' ?>>Amt</option>
									<option value="PercentAmt" <?php echo ($rowsql['DiscountType'] == 'PercentAmt') ? 'selected' : '' ?>>%</option>
								</select></td>
							<td><input type="text" id="basic_<?php echo $i; ?>" name="basic_Amt1[]" value="<?php echo $rowsql['basic_Amt']; ?>" readonly /></td>
							<?php $vendorcountry = $s->GetFieldValue('suppliers', "id='" . $QuoQry['mst_supplierno'] . "'", 'country');      ?>
							<td><select name="currency[]" id="currency">
									<?php $curr_sql = DB_query("Select * from currency_master where country='" . $vendorcountry . "'", $db);
									while ($curr_row = DB_fetch_array($curr_sql)) { ?>
										<option value="<?php echo $curr_row['id']; ?>" <?php echo ($rowsql['currency'] == $curr_row['id']) ? 'selected' : '' ?>><?php echo $curr_row['abbreviation']; ?></option>
									<?php } ?>
								</select></td>
						</tr>
					<?php $i++;
						} ?>
				</table>
				<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i;; ?>" />
				<br>
				<table width="100%" cellspacing="0" cellpadding="3">
					<tr>
						<td width="60%" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="3">
								<tr class="row1">
									<td width="18%"><strong>Terms and Conditions :</strong></td>
									<td><textarea name="VenderQutation_TermCondition" id="VenderQutation_TermCondition" style="height:80px;"><?php if (isset($QuoQry['terms_condition'])) {
																																					echo $QuoQry['terms_condition'];
																																				} ?></textarea></td>
								</tr>
							</table>
						</td>
						<td valign="top">
							<table width="100%" border="0" cellspacing="2" cellpadding="2">
								<tr class="row1">
									<td><strong>TOTAL AMOUNT</strong> </td>
									<td><input type="text" name="basic_amt" value="<?php echo $QuoQry['basic_amt'];  ?>" id="total_item_amount" onfocus="cal_totalamount()" /></td>
								</tr>
								<tr class="row1">
									<td><strong>Round Off</strong></td>
									<td><input type="text" name="pluMin" readonly id="pluMin" value="<?php echo $QuoQry['pluMin'];  ?>" />
										<input type="text" name="roundVal" readonly id="roundVal" value="<?php echo $QuoQry['roundOff'];  ?>" />
									</td>
								</tr>
								<tr class="row1">
									<td><strong>Grand Total</strong></td>
									<td><input type="text" name="GrandTotal" readonly id="GrandTotal" onfocus="cal_grandamount()" value="<?php echo $QuoQry['grand_total'];  ?>" />
										<input type="hidden" id="orig_grand_tot" value="<?php echo $QuoQry['grand_total'];  ?>" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			<?php } ?>


			<p align="center"><input type="Submit" name="submit" class="search" onclick="return checkvalid()" value="Save" /></p>

			</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_gst.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);
			document.getElementById("taxableAmt_" + i).value = finalAmt.toFixed(2);

			DiscountAmountsInt(finalAmt, i);
		}

		function pkgamt(val, ids) {
			if (isNumber(ids)) {
				i = ids
			} else {
				var idsArr = ids.split('_');
				var i = idsArr[1];
			}
			//alert(i);
			var rate = "rate_" + i;
			var str = document.getElementById(rate).value;
			var basic = document.getElementById("basic_" + i).value;
			var pkg = parseFloat(val);
			if (basic == '') {
				basic = 0;
			}
			if (pkg == '') {
				pkg = 0;
			}
			var tot = parseFloat(basic) + parseFloat(pkg);
			document.getElementById("taxableAmt_" + i).value = parseFloat(tot);
			document.getElementById("TotalSpecial_" + i).value = parseFloat(tot);

			var str = document.getElementById("inputVat_" + i).value;
			calgstamt(str, i);

		}


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

			var taxable = document.getElementById("taxableAmt_" + i).value;
			var inputVat_perc = document.getElementById("inputVat_" + i).value;
			if (inputVat_perc == '') {
				inputVat_perc = 0;
			}

			var inputgstamt = parseFloat(taxable) * parseFloat(inputVat_perc);
			var tot_input_gst_amt = parseFloat(inputgstamt) / 100;

			document.getElementById("taxvalue_" + i).value = parseFloat(tot_input_gst_amt);
			var tot_basic = parseFloat(taxable) + parseFloat(tot_input_gst_amt);

			document.getElementById("TotalSpecial_" + i).value = parseFloat(tot_basic);
			//alert(str);
			var str = document.getElementById("freightItem_" + i).value;
			calcfreight(str, ids);
		}


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

			var taxable = document.getElementById("taxableAmt_" + i).value;
			var taxamt = document.getElementById("taxvalue_" + i).value;
			var freight = document.getElementById("freightItem_" + i).value;


			if (taxable == '') {
				taxable = 0;
			}
			if (taxamt == '') {
				taxamt = 0;
			}
			if (freight == '') {
				freight = 0;
			}


			var tot_basic = parseFloat(taxable) + parseFloat(taxamt) + parseFloat(freight)

			document.getElementById("TotalSpecial_" + i).value = parseFloat(tot_basic);

			var surcharge = document.getElementById("surchargeamt_" + i).value;


			cal_surchrgeamt(surcharge, ids);
		}

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

			var taxable = document.getElementById("taxableAmt_" + i).value;
			var taxamt = document.getElementById("taxvalue_" + i).value;
			var freight = document.getElementById("freightItem_" + i).value;
			var surcharge = document.getElementById("surchargeamt_" + i).value;


			if (taxable == '') {
				taxable = 0;
			}
			if (taxamt == '') {
				taxamt = 0;
			}
			if (freight == '') {
				freight = 0;
			}
			if (surcharge == '') {
				surcharge = 0;
			}


			var tot_basic = parseFloat(taxable) + parseFloat(taxamt) + parseFloat(freight) + parseFloat(surcharge);

			document.getElementById("TotalSpecial_" + i).value = parseFloat(tot_basic);
			cal_totalamount();
		}

		function DiscountAmountsInt(DA, ids) {
			if (isNumber(ids)) {
				i = ids
			} else {
				var idsArr = ids.split('_');
				var i = idsArr[1];
			}
			var sumOfArea6 = 0;
			var sumOfArea7 = 0;
			//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);
				document.getElementById("taxableAmt_" + 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("taxableAmt_" + i).value = '';
					return false;

				} else {
					var subTotal = parseFloat(totValue) - parseFloat((disct * totValue) / 100);
					document.getElementById("basic_" + i).value = subTotal.toFixed(2);
					document.getElementById("taxableAmt_" + 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);
			$('#tableDataProduction').find('input[type="text"][class="basic"]').each(function() {
				if ($(this).val() != '') {
					sumOfArea6 = sumOfArea6 + parseFloat($(this).val());
				} else {
					sumOfArea6 = sumOfArea6;
				}
			});


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


			var disc = parseFloat(sumOfArea6) - parseFloat(sumOfArea7);
			document.getElementById("discount_amt_tot").value = parseFloat(disc).toFixed(2);


			var pkg = document.getElementById("pkgamt_" + i).value;

			pkgamt(pkg, ids);
			//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+/, "");
		}

		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 (taxamt == '') {
				taxamt = 0;
			}
			if (miscellaneous == '') {
				miscellaneous = 0;
			}
			var grand = parseFloat(total) + parseFloat(insurance) + parseFloat(miscellaneous) + parseFloat(taxamt);
			document.getElementById("GrandTotal").value = grand.toFixed(2);
			cal_roundamt();

		}

		function total_dis(val) {
			var str = val;
			var count_tot_item = document.getElementById("hiditemcount").value;
			var total_basic = document.getElementById("total_item_amount").value;
			if (isNaN(count_tot_item)) {
				count_tot_item = 0;
			}
			for (var i = 0; i < count_tot_item; i++) {
				var basic = document.getElementById("price_" + i).value;

				if (total_basic != 0) {

					var bs = parseFloat(basic) / parseFloat(total_basic);
					var dis = parseFloat(bs) * parseFloat(val);
					if (dis == '') {
						dis = 0;
					}
					if (isNaN(dis)) {
						dis = 0;
					}
					document.getElementById("Discount_" + i).value = parseFloat(dis).toFixed(2);
					var bsafterdiscount = parseFloat(basic) - parseFloat(dis);
					document.getElementById("basic_" + i).value = parseFloat(bsafterdiscount).toFixed(2);
					var pkg = document.getElementById("pkgamt_" + i).value;
					if (pkg == '') {
						pkg = 0;
					}
					document.getElementById("taxableAmt_" + i).value = parseFloat(bsafterdiscount) + parseFloat(pkg);

					var freight = document.getElementById("freightItem_" + i).value;
					if (freight == '') {
						freight = 0;
					}

					var gst_percent = document.getElementById("inputVat_" + i).value;
					var sum_till_freight = parseFloat(bsafterdiscount) + parseFloat(pkg) + parseFloat(freight);


					if (gst_percent == '') {
						gst_percent = 0;
					}
					if (gst_percent != '0') {

						var gst_amt1 = parseFloat(sum_till_freight) * parseFloat(gst_percent);

						var gst_amt = parseFloat(gst_amt1) / 100;
					}
					document.getElementById("taxvalue_" + i).value = parseFloat(gst_amt).toFixed(2);
					var surcharge = document.getElementById("surchargeamt_" + i).value;
					if (surcharge == '') {
						surcharge = 0;
					}

					var line_item_sum = parseFloat(sum_till_freight) + parseFloat(gst_amt) + parseFloat(surcharge);
					document.getElementById("TotalSpecial_" + i).value = parseFloat(line_item_sum).toFixed(2);
				}

			}
			cal_totalamount();

		}
	</script>