<?php ob_start();
error_reporting(0);
$PageSecurity = 4;
$PageName = 'MaterialReceiptNote';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
$CompanyId =$_SESSION['ACGCompanyId'];

	 $sql_query1 = "SELECT * FROM mrn_comercial_flag where company_id=".$CompanyId;
			$sqlQuery1 =DB_query($sql_query1,$db);
			$rowNew=DB_fetch_array($sqlQuery1);
			 $mrnFlag=$rowNew['mrn_flag'];
	if (isset($_GET['ModifyOrderNumber']) and $_SESSION[UserType]=='SuperAdmin')  {
	$title = _('Modify Purchase Order') . ' ' . $_GET['ModifyOrderNumber'];
	} 
	else 
	{
	}
	if(isset($_GET['issueid'])  && isset($_GET['issueid']) !=''){
	$title = _('Update Issue Slip');
	}

								$Prefix_code = "CLD9/PO";
								$Prefix_date = date("y");
								$Prefix_date++;
								$CurrentFinancialYear = date("y")."-".$Prefix_date;
								$Ordernumber = $_GET['orderno'];
								
								$SQL ="select supplierno from purchorders where orderno='".$Ordernumber."'";
								$result = DB_query($SQL,$db);
								$supp_result = DB_fetch_array($result);
								$suppno = $supp_result['supplierno'];
								
								$ORDER_SQL = "SELECT PO_Orderno FROM purchorders WHERE orderno='".$_GET['orderno']."' ";
								$ORDER_RES = DB_query($ORDER_SQL, $db);
								$ORDER_ROW = DB_fetch_array($ORDER_RES);
								$PO_Orderno = $ORDER_ROW['PO_Orderno'];
								$time = date('G:ia');
								$date = date($_SESSION['DefaultDateFormat']);

					if (empty($_GET['identifier'])) {$identifier=date('U');	} 
					else {$identifier=$_GET['identifier'];}

					$url_cancel= "index.php?route=Inventory/transation/material_receipt_note_exo_index".$rurl;
					$url_add= "index.php?route=Inventory/transation/material_receipt_note_add_exo".$rurl;	
?>

<script type="text/javascript" src="../../js/function-ajax.js" language="javascript">
</script>
<script type="text/javascript">
function DiscountAmount(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo_"+i).value;
		var discount = document.getElementById("Discount_"+i).value;
		var totalPrice = document.getElementById("itemamount_"+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 = 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);
	var count =document.getElementById("count").value;
var tot_cvd1=0;
for(var i=0; i<count;i++){
	if(subTotal==''){subTotal=0;}
	tot_cvd=parseFloat(tot_cvd)+parseFloat(subTotal);
}
//alert(tot_cvd);
document.getElementById("cvd_total").value = tot_cvd.toFixed(2);
		
}

/*function calTotalQty(val,id)
{
var qtyBill = document.getElementById("qty_as_per_bill_"+id).value;
if(qtyBill==''){qtyBill=0;}
	if(parseInt(val)>parseInt(qtyBill))
	{
	var diff = parseFloat(val)-parseFloat(qtyBill);
	}
	else
	{
	var diff =  parseFloat(qtyBill)-parseFloat(val);
	}
	document.getElementById("short_accessid_"+id).value=diff.toFixed(2);
	
	var totalamt=0;
	var countcharges = document.getElementById("count").value;
	for(var i=0;i<countcharges;i++)
	{
	var rec1 = document.getElementById("reciveqty_"+i).value;
	if(rec1==''){rec1=0;}
		var totalamt=parseFloat(totalamt)+parseFloat(rec1);
	}
	document.getElementById("short1").value=totalamt.toFixed(2);
}*/

/*function calTotalQty1(val,id)
{
var qtyBill = document.getElementById("reciveqty_"+id).value;
if(qtyBill==''){qtyBill=0;}
	if(parseInt(val)>parseInt(qtyBill))
	{
	var diff = parseFloat(val)-parseFloat(qtyBill);
	}
	else
	{
	var diff =  parseFloat(qtyBill)-parseFloat(val);
	}
	document.getElementById("short_accessid_"+id).value=diff.toFixed(2);
var totalamt=0;
	var countcharges = document.getElementById("count").value;
	for(var i=0;i<countcharges;i++)
	{
	var qtyBill1 = document.getElementById("qty_as_per_bill_"+i).value;
	if(qtyBill1==''){qtyBill1=0;}
		var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
	}
	document.getElementById("short").value=totalamt.toFixed(2);
	
	var poqty=parseInt(document.getElementById("pending_"+id).value);
	var tolerance = document.getElementById("tolerances_"+id).value;
	if(tolerance==''){tolerance=0;}
	if(poqty==''){poqty=0;}
	str1=parseInt(val);
	if(str1==''){str1=0;}
	if(tolerance=='')
	{
		if(parseInt(poqty)<parseInt(str1))
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		document.getElementById("qty_as_per_bill_"+id).value='';
		return false;
		}
	}
	else
	{
	var p1 = (tolerance*poqty)/100;
	var p2 = parseFloat(poqty)+parseFloat(p1);
		if(parseInt(p2)<parseInt(str1))
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		document.getElementById("qty_as_per_bill_"+id).value='';
		return false;
		}
	}	
}
*/
 function DiscountAmount1(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo1_"+i).value;
		var rate = document.getElementById("itemrate1_"+i).value;
		var discount = document.getElementById("Discount1_"+i).value;
		var quantity = document.getElementById("reciveqty1_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount1_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc1_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate1_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic1_"+i).value=subTotal.toFixed(2);
		var totAmount3 = document.getElementById("total_item_amount3").value;
		if(totAmount3=="")
		{
		document.getElementById("total_item_amount3").value = subTotal.toFixed(2);
		}
		else
		{
		var sum = parseFloat(totAmount3)+parseFloat(subTotal);
		document.getElementById("total_item_amount3").value = sum.toFixed(2);
		}
		
		
}

function DiscountAmount3(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo2_"+i).value;
		var rate = document.getElementById("itemrate2_"+i).value;
		var discount = document.getElementById("Discount2_"+i).value;
		var quantity = document.getElementById("reciveqty2_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount2_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc2_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate2_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic2_"+i).value=subTotal.toFixed(2);
		//var totAmount3 = document.getElementById("GrandTotal1").value;
		//if(totAmount3=="")
		//{
		//document.getElementById("GrandTotal1").value = subTotal.toFixed(2);
		//}
		//else
		//{
		//var sum = parseFloat(totAmount3)+parseFloat(subTotal);
		//document.getElementById("GrandTotal1").value = sum.toFixed(2);
		//}
		
		
}
function DiscountAmount4(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo3_"+i).value;
		var rate = document.getElementById("itemrate3_"+i).value;
		var discount = document.getElementById("Discount3_"+i).value;
		var quantity = document.getElementById("reciveqty3_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount3_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc3_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate3_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic3_"+i).value=subTotal.toFixed(2);
}
	function FiendPurchasenumber(str)
	{
	var a= document.getElementById('sitecode').value;
	var vendor=document.getElementById("vendor").value;
	var storecode=document.getElementById("storecode").value;
	var receipt=document.getElementById("receiviedagaist").value;
	location.replace("index.php?route=Inventory/transation/material_receipt_note_add_exo"+"&orderno="+str+"&sitecode="+a+"&vendor="+vendor+"&storecode="+storecode+"&receipt="+receipt+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>");
	}
	function againstPR(str)
	{
	var a= document.getElementById('sitecode').value;
	var vendor=document.getElementById("vendor").value;
	var storecode=document.getElementById("storecode").value;
	var receipt=document.getElementById("receiviedagaist").value;
	location.replace("index.php?route=Inventory/transation/material_receipt_note_add_exo"+"&pr="+str+"&sitecode="+a+"&vendor="+vendor+"&storecode="+storecode+"&receipt="+receipt+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>");
	}

	

function confirmPost()
{
	if(document.getElementById("sitecode").value=='000')
	{
	alert("Must Select Site Name");
	document.getElementById("sitecode").focus();
	return false;
	}
	if(document.getElementById("storecode").value=='000')
	{
	alert("Must Select Store Name");
	document.getElementById("storecode").focus();
	return false;
	}
	if(document.getElementById("receiviedagaist").value=='0')
	{
	alert("Must Select Received Aganist Type");
	document.getElementById("receiviedagaist").focus();
	return false;
	}
	if(document.getElementById("mst_supplierno").value=='000')
	{
	alert("Must Select  Vender");
	document.getElementById("mst_supplierno").focus();
	return false;
	}
	if(document.getElementById("DocumentType").value=='')
	{
	alert("Must Select  Document Type");
	document.getElementById("DocumentType").focus();
	return false;
	}
	if(document.getElementById("billno").value=='')
	{
	alert("Must Select  Document No");
	document.getElementById("billno").focus();
	return false;
	}
	if(document.getElementById("MRNVoucherDate").value=='')
	{
	alert("Must Select  Document Date");
	document.getElementById("MRNVoucherDate").focus();
	return false;
	}
	if(document.getElementById("gatepassno").value=='')
	{
	alert("Must Enter Gate Entry No");
	document.getElementById("gatepassno").focus();
	return false;
	}
	if(document.getElementById("gatepassdate").value=='')
	{
	alert("Must Enter Gate Entry Date");
	document.getElementById("gatepassdate").focus();
	return false;
	}
	if(document.getElementById("entrycheck").value=='1')
	{
	alert("Duplicate Entry For Gate Entry Pass");
	document.getElementById("gatepassno").value='';
	document.getElementById("gatepassno").focus();
	return false;
	}
	
	
	var col=0;
	var cou=document.getElementById("count").value;
	for(var i=0;i<cou;i++)
	{	
	if(document.getElementById("qty_as_per_bill_"+i).value!='')
	{
	var col=1;
	}	
	}
	//if(col==0)
	//{
	//alert("please Fill All details of item");
	//return false;
	//}
	
	if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
	{
	alert("Grand Total amount should not be blank");
	document.getElementById("GrandTotal").focus();
	return false;
	}		
	
}

function confirmPost1()
{
	var max_price=document.getElementById("max_price").value;
	var grand_price=document.getElementById("GrandTotal").value;
	if(parseFloat(grand_price) > parseFloat(max_price)){
	$alertmasg="Grandtotal not more than Maximum Direct Purchase Allowed Amount - "+max_price;
	alert($alertmasg);
	return false;
	}
	
	if(document.getElementById("sitecode").value=='000')
	{
	alert("Must Select Site Name");
	document.getElementById("sitecode").focus();
	return false;
	}
	if(document.getElementById("storecode").value=='000')
	{
	alert("Must Select Store Name");
	document.getElementById("storecode").focus();
	return false;
	}
	if(document.getElementById("receiviedagaist").value=='0')
	{
	alert("Must Select Received Aganist Type");
	document.getElementById("receiviedagaist").focus();
	return false;
	}
	if(document.getElementById("vendor").value=='000')
	{
	alert("Must Select  Vender");
	document.getElementById("vendor").focus();
	return false;
	}
	if(document.getElementById("gatepassno").value=='')
	{
	alert("Must Enter Gate Entry No");
	document.getElementById("gatepassno").focus();
	return false;
	}
	if(document.getElementById("gatepassdate").value=='')
	{
	alert("Must Enter Gate Entry Date");
	document.getElementById("gatepassdate").focus();
	return false;
	}
	if(document.getElementById("entrycheck").value=='1')
	{
	alert("Duplicate Entry For Gate Entry Pass");
	document.getElementById("gatepassno").value='';
	document.getElementById("gatepassno").focus();
	return false;
	}
	
	var col=0;
	var cou=document.getElementById("count").value;
	for(var i=0;i<cou;i++)
	{	
	if(document.getElementById("qty_as_per_bill_"+i).value!='')
	{
	var col=1;
	}	
	}
	if(col==0)
	{
	alert("please Fill All details of item");
	return false;
	}
	
	if(document.getElementById("total_item_amount").value=='' || document.getElementById("total_item_amount").value=='0.00')
	{
	alert("Total amount should not be blank");
	document.getElementById("total_item_amount").focus();
	return false;
	}	
	
	if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
	{
	alert("Grand Total amount should not be blank");
	document.getElementById("GrandTotal").focus();
	return false;
	}		
	

}



				function caltaxamout(i)
				{
					
				var excise=parseFloat(document.getElementById("exciseDuty_"+i).value);
				
				if(excise!=0)
				{
				var basic_amount=document.getElementById("exciseValue_"+i).value;
				var ecessamt=document.getElementById("ECessValue_"+i).value;
				var sahamt=document.getElementById("SAHCessValue_"+i).value;
				var totaltax=parseFloat(basic_amount)+parseFloat(ecessamt)+parseFloat(sahamt);	
				document.getElementById('taxableamount_'+i).value=totaltax.toFixed(2);	
				}
				else
				{
				document.getElementById('taxableamount_'+i).value=0;		
				}	
					
				}

       function caltaxamout1(i)
				{
					
				var excise=parseFloat(document.getElementById("exciseDuty_"+i).value);
				
				if(excise!=0)
				{
				var basic_amount=document.getElementById("exciseValue_"+i).value;
				var ecessamt=document.getElementById("ECessValue_"+i).value;
				var sahamt=document.getElementById("SAHCessValue_"+i).value;
				var totaltax=parseFloat(basic_amount)+parseFloat(ecessamt)+parseFloat(sahamt);	
				document.getElementById('taxableamount_'+i).value=totaltax.toFixed(2);	
				}
				else
				{
				document.getElementById('taxableamount_'+i).value=0;		
				}	
					
				}
								function calvatamount(i)
								{
								
								var vatcst_per=document.getElementById('vatper').value;
								
								if(vatcst_per!=0)
								{
								var taxamt=parseFloat(document.getElementById('taxableamount_'+i).value);
								//var item_total_rate=parseFloat(document.getElementById('item_total_rate_'+i).value);
								var total=taxamt;
								var vatamount=(total*vatcst_per)/100;
								document.getElementById('vatcstamount_'+i).value=vatamount.toFixed(2);	
									
								}	
								else
								{
								document.getElementById('vatcstamount_'+i).value=0;	
								}
									
									
								}


function calculate_short(id)
{
	var x = parseInt(document.getElementById('reciveqty_'+id).value);

	var poqty = parseInt(document.getElementById('qty_as_per_bill_'+id).value);
	
	var rate = parseInt(document.getElementById('itemrate_'+id).value);
 	if(x != '')
	{
		if(poqty < x)
		{	
			alert("Received Quantity can not be greater than PO Quantity");
			return false;
		}
		else if(poqty >= x)
		{
 				document.getElementById('short_accessid_'+id).value = (parseFloat(poqty)- parseFloat(x)).toFixed(2);
				return true;
		}
	  }
	else
	{
		document.getElementById('short_accessid_'+id).value = 0;
			return true;
	}
}

function calculate_poshort(id)
	{
	var qty_per_bill=parseInt(document.getElementById("qty_as_per_bill_"+id).value);
	var reciveqty=parseInt(document.getElementById("reciveqty_"+id).value);	
	if(document.getElementById("reciveqty_"+id).value=='')
	{
	var reciveqty=0;	
	}
	else
	{
	var reciveqty=parseInt(document.getElementById("reciveqty_"+id).value);	
	}
	if(qty_per_bill>reciveqty)
	{
	var short_accessid=qty_per_bill-reciveqty;
	}
	else
	{
	var short_accessid=reciveqty-qty_per_bill;
	}
	if(short_accessid<0){short_accessid=0;}
	document.getElementById("short_accessid_"+id).value=short_accessid;
}

function calculate_poshort1(id)
	{
	var qty_per_bill=parseInt(document.getElementById("qty_as_per_bill1_"+id).value);
	var reciveqty=parseInt(document.getElementById("reciveqty1_"+id).value);	
	if(document.getElementById("reciveqty1_"+id).value=='')
	{
	var reciveqty=0;	
	}
	else
	{
	var reciveqty=parseInt(document.getElementById("reciveqty1_"+id).value);	
	}
	var short_accessid=qty_per_bill-reciveqty;
	if(short_accessid<0){short_accessid=0;}
	document.getElementById("short_accessid1_"+id).value=short_accessid;
}

function calculate_poshort2(id)
	{
	var qty_per_bill2=parseInt(document.getElementById("qty_as_per_bill2_"+id).value);
	var reciveqty2=parseInt(document.getElementById("reciveqty2_"+id).value);	
	if(document.getElementById("reciveqty2_"+id).value=='')
	{
	var reciveqty2=0;	
	}
	else
	{
	var reciveqty2=parseInt(document.getElementById("reciveqty2_"+id).value);	
	}
	var short_accessid2=qty_per_bill2-reciveqty2;
	if(short_accessid2<0){short_accessid2=0;}
	document.getElementById("short_accessid2_"+id).value=short_accessid2;
}

function calculate_poshort3(id)
	{
	var qty_per_bill2=parseInt(document.getElementById("qty_as_per_bill3_"+id).value);
	var reciveqty2=parseInt(document.getElementById("reciveqty3_"+id).value);	
	if(document.getElementById("reciveqty3_"+id).value=='')
	{
	var reciveqty2=0;	
	}
	else
	{
	var reciveqty2=parseInt(document.getElementById("reciveqty3_"+id).value);	
	}
	if(qty_per_bill>reciveqty)
	{
	var short_accessid2=qty_per_bill-reciveqty;
	}
	else
	{
	var short_accessid2=reciveqty-qty_per_bill;
	}
	if(short_accessid2<0){short_accessid2=0;}
	document.getElementById("short_accessid3_"+id).value=short_accessid2;
}


function calculate_discount(str)
{
	var qty=document.getElementById("reciveqty_"+str).value;
	var itemrate=document.getElementById("itemrate_"+str).value;
	var disc_type=document.getElementById("disc_type_"+str).value;
	var disc=document.getElementById("discount_"+str).value;
	//alert(disc);
	if(disc==''){disc=0;}
	if(disc_type=='Amount')
	{
		var total_rate=parseFloat(qty) * parseFloat(itemrate);
		document.getElementById("val_after_disc_"+str).value=(parseFloat(total_rate) - parseFloat(disc)).toFixed(2);
		document.getElementById("discount_amount_"+str).value=(parseFloat(disc)).toFixed(2);
	}
	else if(disc_type=='PercentAmt')
	{
		var total_rate=parseFloat(qty) * parseFloat(itemrate);
		var disc_val=parseFloat(total_rate)*parseFloat(disc)/100;
		document.getElementById("val_after_disc_"+str).value=(parseFloat(total_rate) - parseFloat(disc_val)).toFixed(2);
		document.getElementById("discount_amount_"+str).value=(parseFloat(disc_val)).toFixed(2);
	}
}
function calc_taxval(str,j)
{
	var val_after_disc = document.getElementById("val_after_disc_"+j).value;
	if(val_after_disc != ''){
	var taxvalue=(parseInt(str)*parseInt(val_after_disc))/100;
	}
	document.getElementById("taxamount_"+j).value=parseInt(taxvalue);
	
}

function calcNewAmount(id,val)
{
	if(val==''){val=0;}
	var id_brk=id.split('_');
	var i=id_brk[2];
	var ammtValue = document.getElementById("NetRate_"+i).value;
	if(ammtValue==''){ammtValue=0;}
	var newAmount=parseInt(val)*parseInt(ammtValue);
	document.getElementById("basic_"+i).value=parseInt(newAmount);
}

function calc_amount_with_tax(str)
{
	var totalrate = document.getElementById("val_after_disc_"+str).value;
	var taxamount = document.getElementById("taxamount_"+str).value;
if(totalrate != '' && taxamount != '')
{
	var total_amt_with_tax = parseInt(totalrate) + parseInt(taxamount);
	document.getElementById("total_amt_with_tax_"+str).value = parseInt(total_amt_with_tax);
}
}
function openPopupProfile(i)
{
  	window.open("Search_item_MRN.php?rowcount="+i,"profiles_popup_window","height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function ChargeAmount1(CA,ID)
 {
	if (CA=="")
	{
		document.getElementById("PerActual"+ID).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("PerActual"+ID).innerHTML=xmlhttp.responseText;
		}
	}
 	xmlhttp.open("GET","Charges_Details.php?CA="+CA+"&ID="+ID,true);
	xmlhttp.send();
 }
function calculate_BasicAmount()
{
 	var  itemamount = 0;
 	var  count= document.getElementById('rowcount').value;
 	
	for(var i=0; i<count; i++)
	{
 		var totalrate = document.getElementById('val_after_disc_'+i).value;
			if(!isNaN(totalrate) && totalrate!='' ){
				itemamount  =parseFloat(itemamount)+  parseFloat(totalrate);
  			}
			else if(totalrate=='')
			{ totalrate=0;}
 	}
 	document.getElementById('itemamount').value = itemamount;
 }
 
function value_after_discount(i)
{
	
	var basic = parseFloat(document.getElementById('basic_'+i).value);
	//alert(item_total_rate);
	if(document.getElementById('taxableamount_'+i).value=='')
	{
	var taxableamt = 0;	
	}
	else
	{
	var taxableamt = parseFloat(document.getElementById('taxableamount_'+i).value);
	}
	//alert(taxableamt);
 	var val_after_disc = parseFloat(basic+taxableamt);
 	//alert(val_after_disc);
	document.getElementById('total_'+i).value=val_after_disc.toFixed(2);	
	
	
}

function value_after_discount1(i)
{
	
	var basic = parseFloat(document.getElementById('basic_'+i).value);
	//alert(item_total_rate);
	if(document.getElementById('taxableamount_'+i).value=='')
	{
	var taxableamt = 0;	
	}
	else
	{
	var taxableamt = parseFloat(document.getElementById('taxableamount_'+i).value);
	}
	//alert(taxableamt);
 	var val_after_disc = parseFloat(basic+taxableamt);
 	//alert(val_after_disc);
	document.getElementById('total_'+i).value=val_after_disc.toFixed(2);	
	
	
}


function CountTotalQty()
{
	var  qty = 0;
	var  count= document.getElementById('rowcount').value;
   	var i;
 	for(i=0; i<count; i++)
	{
 		var totalqty = document.getElementById('reciveqty_'+i).value;
 			if(!isNaN(totalqty) && totalqty!='' ){
				qty  =parseFloat(qty)+  parseFloat(totalqty);
  			}
 	}
  	document.getElementById('totalqty').value = qty;
 }
  function check_po_qty1(i)
  {
        poqty=parseFloat(document.getElementById("pending_qty_"+i).value);
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		if(reciveqty!='' && poqty!='')
		{
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
		}
  if(document.getElementById("convfac_"+i).value!='')
   var k=parseFloat(document.getElementById("convfac_"+i).value); 
 else
 var k=0;
 var amt=reciveqty/k;
 document.getElementById("scecondarqty_"+i).value=amt.toFixed(2);
 }
 
 function check_po_qty2(i)
  {
       
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		
  if(document.getElementById("convfac_"+i).value!='')
   var k=parseFloat(document.getElementById("convfac_"+i).value); 
 else
 var k=0;
 var amt=reciveqty/k;
 document.getElementById("scecondarqty_"+i).value=amt.toFixed(2);
 }
 
 
 function grnDisabled()
 {
 	if(document.getElementById("GrnType").value=="domestic")
	{
	document.getElementById("importPo1").style.display='none';
	document.getElementById("importPo2").style.display='none';
	document.getElementById("importPo3").style.display='none';
	document.getElementById("importPo4").style.display='none';
	document.getElementById("charges1").style.display='none';
	document.getElementById("charges2").style.display='none';
	document.getElementById("charges3").style.display='none';
	document.getElementById("charges4").style.display='none';
	}
	else
	{
	if(document.getElementById("DutyType").value=="Itemwise")
	{
	document.getElementById("importPo2").style.display="none";
	document.getElementById("importPo1").style.display="block";
	document.getElementById("importPo3").style.display='none';
	document.getElementById("charges1").style.display='block';
	document.getElementById("charges2").style.display='none';
	document.getElementById("charges3").style.display='none';
	document.getElementById("charges4").style.display='none';
	}
	}
 }
 function grnDisabled1(str)
 {
	var po_id=document.getElementById("Purchase_Order").value;
	var GrnType=document.getElementById("GrnType").value;
	if (str==''){
  		document.getElementById("target_id").innerHTML="";
 	 	return;
  	}
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
   	if(xmlhttp.readyState==4 && xmlhttp.status==200){
		var data=xmlhttp.responseText;
		//alert(data);
    	document.getElementById("target_id").innerHTML=xmlhttp.responseText;
   }
 }
xmlhttp.open("GET","ajax_po_items.php?po="+po_id+"&type="+str+"&GrnType="+GrnType,true);
xmlhttp.send();
 }
 function ajax_cur_rate(str,id)
 {
 	var basicAmt = document.getElementById("NetRate_"+id).value;
	var oldid=document.getElementById("itemCurrency_"+id).value;
	if (str==''){
  		document.getElementById("conv_rate_"+id).value="";
 	 	return;
  	}
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
   	if(xmlhttp.readyState==4 && xmlhttp.status==200){
		var data=xmlhttp.responseText.split("__");
		if(data[0]=="")
		{
		alert('Conversion Rate is Empty');
			document.getElementById("conv_curr_"+id).focus();
		return false;
		}
		else
		{
    	document.getElementById("conv_rate_"+id).value=data[0];
		}
		document.getElementById("basic_"+id).value=data[1];
   }
 }
xmlhttp.open("GET","ajax_get_rate.php?oldCur="+oldid+"&newCur="+str+"&basicAmount="+basicAmt,true);
xmlhttp.send();
 }
 
 function ajax_cur_rate_tot(str)
 {
 	var basicAmt = document.getElementById("total_item_amount").value;
	var oldid=document.getElementById("oldCurrency").value;
	if (str=='')
	{
  		document.getElementById("tot_conv_rate").value="";
 	 	return;
  	}

	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
  	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
   	if(xmlhttp.readyState==4 && xmlhttp.status==200){
		var data=xmlhttp.responseText.split("__");
		if(data[0]=="")
		{
		alert('Conversion Rate is Empty');
			document.getElementById("tot_conv_rate").focus();
		return false;
		}
		else
		{
    	document.getElementById("tot_conv_rate").value=data[0];
		}
		document.getElementById("tot_conv_amt").value=data[1];
   }
 }
xmlhttp.open("GET","ajax_get_rate.php?oldCur="+oldid+"&newCur="+str+"&basicAmount="+basicAmt,true);
xmlhttp.send();
 }

 function getOrderDate(str)
 {
		if (str=='')
		{
	  		document.getElementById("orderdate").value="";
			document.getElementById("typeGrn").innerHTML="";
	 	 	return;
	  	}
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	  		xmlhttp=new XMLHttpRequest();
	  	}else{// code for IE6, IE5
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  	}
		    xmlhttp.onreadystatechange=function(){
	    	if(xmlhttp.readyState==4 && xmlhttp.status==200){
			var data=xmlhttp.responseText.split("__");
	    	document.getElementById("orderdate").value=data[0];
			document.getElementById("typeGrn").innerHTML=data[1];
			document.getElementById("itemTable").innerHTML=data[2];
	   }
	 }
	xmlhttp.open("GET","ajax_order_date.php?po="+str,true);
	xmlhttp.send();
 }
 
 function getItemLists(str)
 {
	if (str==''){
  		alert('Select PO');
 	 	return;
  	}
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}else{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function(){
   	if(xmlhttp.readyState==4 && xmlhttp.status==200){
	//alert(xmlhttp.responseText);
		document.getElementById("itemTable").innerHTML=xmlhttp.responseText;
   }
 }
xmlhttp.open("GET","ajax_item_lists.php?po="+str,true);
xmlhttp.send();
 }
 
function calTotalQty1(val,id)
{
var qtyRec = document.getElementById("reciveqty_"+id).value;
if(qtyRec==''){qtyRec=0;}
	
	var diff =  parseFloat(qtyRec)-parseFloat(val);
	document.getElementById("short_accessid_"+id).value=diff.toFixed(2);
var totalamt=0;
	var countcharges = document.getElementById("count").value;
	for(var i=0;i<countcharges;i++)
	{
	var qtyBill1 = document.getElementById("qty_as_per_bill_"+i).value;
	if(qtyBill1==''){qtyBill1=0;}
		var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
	}
	document.getElementById("short").value=totalamt.toFixed(2);
	
	var poqty=parseInt(document.getElementById("pending_"+id).value);
	var tolerance = document.getElementById("tolerances_"+id).value;
	if(tolerance==''){tolerance=0;}
	if(poqty==''){poqty=0;}
	str1=parseInt(val);
	if(str1==''){str1=0;}
	if(tolerance=='')
	{
		if(parseInt(poqty)<parseInt(str1))
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		document.getElementById("qty_as_per_bill_"+id).value='';
		return false;
		}
	}
	else
	{
	var p1 = (tolerance*poqty)/100;
	var p2 = parseFloat(poqty)+parseFloat(p1);
		if(parseInt(p2)<parseInt(str1))
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		document.getElementById("qty_as_per_bill_"+id).value='';
		return false;
		}
	}	
}
 
 function calTotalQty(val,id)
{
var qtyBill = document.getElementById("qty_as_per_bill_"+id).value;
if(qtyBill==''){qtyBill=0;}
	var diff = parseFloat(val)-parseFloat(qtyBill);
	document.getElementById("short_accessid_"+id).value=diff.toFixed(2);
	
	
	var totalamt=0;
	var countcharges = document.getElementById("count").value;
	for(var i=0;i<countcharges;i++)
	{
	var rec1 = document.getElementById("reciveqty_"+i).value;
	if(rec1==''){rec1=0;}
		var totalamt=parseFloat(totalamt)+parseFloat(rec1);
	}
	document.getElementById("short1").value=totalamt.toFixed(2);
}
 
function check_po1()
{
	var rowcount=document.getElementById("rowcount").value;
	for(var i=0;i<rowcount;i++)
	{
		poqty=parseFloat(document.getElementById("poqty_"+i).value);
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		if(reciveqty!='' && poqty!='')
		{
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
		}
		
	}
}
 
function check_bill_qty(str,id)
{
	var poqty=parseInt(document.getElementById("pending_"+id).value);
	var tolerance = document.getElementById("tolerances_"+id).value;
	if(tolerance==''){tolerance=0;}
	if(poqty==''){poqty=0;}
	str1=parseInt(str);
	if(str1==''){str1=0;}
	if(tolerance==0)
	{
		if(poqty<str1)
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
		}
	}
	else
	{
	var p1 = (tolerance*poqty)/100;
	var p2 = parseFloat(poqty)+parseFloat(p1);
		if(p2<str1)
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
		}
	}	
}

function chekdata(str)
{
var qty=parseFloat(document.getElementById("reciveqty_"+str).value);

if(document.getElementById("pendingqty_"+str).value!='')
{
var qty1=parseFloat(document.getElementById("pendingqty_"+str).value);
var qty2=qty1-qty;
document.getElementById("pendingqty_"+str).value=qty2;


}
}

function calc_total_price(str)
{
   
	var item_total_rate=0;
	var reciveqty = document.getElementById("reciveqty_"+str).value;
	var itemrate=document.getElementById("itemrate_"+str).value;
		
	if(reciveqty!='' && itemrate!='')
	{
		document.getElementById("item_total_rate_"+str).value=(parseFloat(reciveqty)*parseFloat(itemrate)).toFixed(2);
	}
}

function getreqitemdataNew(str)
{
var xmlhttp;
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("storedata").innerHTML=data[1];
	document.getElementById("transporters").innerHTML=data[2];
	document.getElementById("mst_supplierno").innerHTML=data[3];
    }
  }
  xmlhttp.open("GET","getsitenamedata.php?site="+str,true);
xmlhttp.send();
}
</script>
<?php 
					if($_REQUEST['reset']!='')
					{
					unset($_REQUEST['sitecode']);unset($_REQUEST['sitename']);unset($_REQUEST['hidden_site']);
					unset($_REQUEST['vendor']);	unset($_REQUEST['PO']);	unset($_REQUEST['credit_days']);
					unset($_REQUEST['MRNdate']);unset($_REQUEST['matrialreceipt']);	unset($_REQUEST['storecode']);
					unset($_REQUEST['storename']);unset($_REQUEST['rmrs_no']);unset($_REQUEST['orderdate']);
					unset($_REQUEST['billno']);	unset($_REQUEST['MRNVoucherDate']);	unset($_REQUEST['gatepassno']);
					unset($_REQUEST['inwardate_save']);	unset($_REQUEST['transport']);unset($_REQUEST['vehicalno']);
					unset($_REQUEST['timein']);unset($_REQUEST['timeout']);	unset($_REQUEST['lrno']);
					unset($_REQUEST['lrdate']);	unset($_REQUEST['total_weight']);unset($_REQUEST['RemarksIfAny']);
					unset($_REQUEST['DocumentType']);unset($_REQUEST['receiviedagaist']);unset($_REQUEST['receipt']);
					unset($_SESSION['manvi_new']);unset($_SESSION['receiviedagaist']);unset($_SESSION['sitecode']);
					unset($_SESSION['sitename']);unset($_SESSION['hidden_site']);unset($_SESSION['vendor']);
					unset($_SESSION['PO']);unset($_SESSION['credit_days']);	unset($_SESSION['MRNdate']);
					unset($_SESSION['matrialreceipt']);unset($_SESSION['storecode']);unset($_SESSION['storename']);
					unset($_SESSION['rmrs_no']);unset($_SESSION['orderdate']);unset($_SESSION['billno']);
					unset($_SESSION['MRNVoucherDate']);unset($_SESSION['gatepassno']);unset($_SESSION['inwardate_save']);
					unset($_SESSION['transport']);unset($_SESSION['vehicalno']);unset($_SESSION['timein']);
					unset($_SESSION['timeout']);unset($_SESSION['lrno']);unset($_SESSION['lrdate']);
					unset($_SESSION['total_weight']);unset($_SESSION['RemarksIfAny']);unset($_SESSION['DocumentType']);
					unset($_SESSION['entrycheck']);unset($_REQUEST['receipt']);
					}


					if($_REQUEST['item_popup']!='')
					{
						$_SESSION['receiviedagaist']=$_REQUEST['receiviedagaist'];
						$_SESSION['sitecode']=$_REQUEST['sitecode'];
						$_SESSION['sitename']=$_REQUEST['sitename'];
						$_SESSION['hidden_site']=$_REQUEST['hidden_site'];
						$_SESSION['vendor']=$_REQUEST['vendor'];
						$_SESSION['PO']=$_REQUEST['PO'];
						$_SESSION['credit_days']=$_REQUEST['credit_days'];
						$_SESSION['MRNdate']=$_REQUEST['MRNdate'];
						$_SESSION['matrialreceipt']=$_REQUEST['matrialreceipt'];
						$_SESSION['storecode']=$_REQUEST['storecode'];
						$_SESSION['storename']=$_REQUEST['storename'];
						$_SESSION['rmrs_no']=$_REQUEST['rmrs_no'];
						$_SESSION['orderdate']=$_REQUEST['orderdate'];
						$_SESSION['billno']=$_REQUEST['billno'];
						$_SESSION['MRNVoucherDate']=$_REQUEST['MRNVoucherDate'];
						$_SESSION['gatepassno']=$_REQUEST['gatepassno'];
						$_SESSION['inwardate_save']=$_REQUEST['inwardate_save'];
						$_SESSION['transport']=$_REQUEST['transport'];
						$_SESSION['vehicalno']=$_REQUEST['vehicalno'];
						$_SESSION['timein']=$_REQUEST['timein'];
						$_SESSION['timeout']=$_REQUEST['timeout'];
						$_SESSION['entrycheck']=$_REQUEST['entrycheck'];
						$_SESSION['lrno']=$_REQUEST['lrno'];
						$_SESSION['lrdate']=$_REQUEST['lrdate'];
						$_SESSION['total_weight']=$_REQUEST['total_weight'];
						$_SESSION['RemarksIfAny']=$_REQUEST['RemarksIfAny'];
						$_SESSION['DocumentType']=$_REQUEST['DocumentType'];
					}


			if($_REQUEST['orderno']!='' || $_REQUEST['pr']!='')
			{
				 $sitecode=$_SESSION['sitecode'];$sitename=$_SESSION['sitename'];
				 $entrycheck=$_SESSION['entrycheck'];
				$hidden_site=$_SESSION['hidden_site'];$vendor=$_SESSION['vendor'];
				$PO=$_SESSION['PO'];$req_no=$_REQUEST['pr'];$credit_days=$_SESSION['credit_days'];
				$MRNdate=$_SESSION['MRNdate'];$matrialreceipt=$_SESSION['matrialreceipt'];
				$storecode=$_SESSION['storecode'];$storename=$_SESSION['storename'];
				$rmrs_no=$_SESSION['rmrs_no'];$orderdate=$_SESSION['orderdate'];
				$billno=$_SESSION['billno'];$MRNVoucherDate=$_SESSION['MRNVoucherDate'];
				$gatepassno=$_SESSION['gatepassno'];$inwardate_save=$_SESSION['inwardate_save'];
				$transport=$_SESSION['transport'];$vehicalno=$_SESSION['vehicalno'];
				$timein=$_SESSION['timein'];$timeout=$_SESSION['timeout'];			
				$lrno=$_SESSION['lrno'];$lrdate=$_SESSION['lrdate'];
				$total_weight=$_SESSION['total_weight'];$RemarksIfAny=$_SESSION['RemarksIfAny'];
				$DocumentType=$_SESSION['DocumentType'];$sitecode=$_REQUEST['sitecode'];
				$sitename=$_REQUEST['sitename'];$hidden_site=$_REQUEST['hidden_site'];
				$vendor=$_REQUEST['vendor'];$_REQUEST['receiviedagaist']=$_REQUEST['receipt'];
				$PO=$_REQUEST['PO'];$credit_days=$_REQUEST['credit_days'];
				$MRNdate=date('d/m/Y');$matrialreceipt=$_REQUEST['received_on_basis'];
				$PurchaseOrder=$_REQUEST['Purchase_Order'];$storecode=$_REQUEST['storecode'];
				$storename=$_REQUEST['storename'];$rmrs_no=$_REQUEST['rmrs_no'];
				$orderdate=date('d/m/Y');$billno=$_REQUEST['billno'];$MRNVoucherDate=date('d/m/Y');
				$gatepassno=$_REQUEST['gatepassno'];$inwardate_save=date('d/m/Y');$transport=$_REQUEST['transport'];
				$vehicalno=$_REQUEST['vehicalno'];$timein=$_REQUEST['timein'];$timeout=$_REQUEST['timeout'];
				$lrno=$_REQUEST['lrno'];$lrdate=date('d/m/Y');$total_weight=$_REQUEST['total_weight'];
				$RemarksIfAny=$_REQUEST['RemarksIfAny'];$DocumentType=$_REQUEST['DocumentType'];
			}

		if($_REQUEST['type']!='')
		{
			$sitecode=$_SESSION['sitecode'];$sitename=$_SESSION['sitename'];
			 $entrycheck=$_SESSION['entrycheck'];
			$_REQUEST['receiviedagaist']=$_SESSION['receiviedagaist'];$hidden_site=$_SESSION['hidden_site'];
			$vendor=$_SESSION['vendor'];$PO=$_SESSION['PO'];$credit_days=$_SESSION['credit_days'];
			$MRNdate=$_SESSION['MRNdate'];$matrialreceipt=$_SESSION['matrialreceipt'];
			$storecode=$_SESSION['storecode'];$storename=$_SESSION['storename'];
			$rmrs_no=$_SESSION['rmrs_no'];$orderdate=$_SESSION['orderdate'];
			$billno=$_SESSION['billno'];$MRNVoucherDate=$_SESSION['MRNVoucherDate'];
			$gatepassno=$_SESSION['gatepassno'];$inwardate_save=$_SESSION['inwardate_save'];
			$transport=$_SESSION['transport'];$vehicalno=$_SESSION['vehicalno'];
			$timein=$_SESSION['timein'];$timeout=$_SESSION['timeout'];$lrno=$_SESSION['lrno'];
			$lrdate=$_SESSION['lrdate'];$total_weight=$_SESSION['total_weight'];$RemarksIfAny=$_SESSION['RemarksIfAny'];
			$DocumentType=$_SESSION['DocumentType'];
		
		}
		
		
if($_REQUEST['daction']=='del')
{
  $delsql = "update purchorderdetails set item_row_status='0' where podetailitem='".$_REQUEST['id']."'";
  $delete_result = DB_query($delsql,$db);
    if(!$delete_result)
  {
    die("error".DB_error_msg($db));
   }
 }
$date = date($_SESSION['DefaultDateFormat']);

if(isset($_POST['save']))
{
	 $status=true;
	$msg_error=array();
  	
		 	if(empty($_REQUEST['sitename']))
			{
				$msg_error[]="Please Select Site Code ";
				$status=false;
			}
			if($_REQUEST['storecode']=='000')
			{
				$msg_error[]="Please Select Storecode ";
				$status=false;
			}
				if($_REQUEST['vendor']=='000')
				{
					$msg_error[]="Please Select Recevied From";
					$status=false;
				}
				 
				
				if(empty($_REQUEST['billno']))
				{
					$msg_error[]="Please Enter BillNo ";
					$status=false;
				}
  
		  $countcharge = $_POST['countcharges'];
 		 for($P=1;$P<$countcharge;$P++)
		 {
		   if($_POST['Charge_'.$P.'']=='NO' && $_POST[$P]=='')
		   {
				  	$msg_error[]="Please Enter Amount in Charges Details";
					$status=false;
					break;
     		}
 		 }
 	
	$countval=$_POST['countval'];
	
	for($k=1;$k<countval;$k++)
	{
		if($_POST['reciveqty'][$k]>$_POST['poqty'][$k])
		{
				$msg_error[]="Received Quantity Cannot Be Greater Than PO Quantity";
				$status=false;
				break;
		}
	}	
	
	{
	
	
	$pending_status=0;
	$_POST['PRDate']=Date($_SESSION['DefaultDateFormat']);
	$_POST['DatePrinted']=Date($_SESSION['DefaultDateFormat']);
	ConvertSQLDate($_SESSION['MR'.$identifier]->Orig_OrderDate);
 	$_POST['sitecode'];
	//*****************************************************//
       if($_REQUEST['receiviedagaist']=='PO')
	   {
       $prefixcode="MRP";
	   }

if($_REQUEST['receiviedagaist']=='DirectPOOrder')
	   {
	 $prefixcode="DMRP";
}
	if($_REQUEST['receiviedagaist']=='Without PO')
	{

		$prefixcode="MRW";
	}
	
	if($_REQUEST['receiviedagaist']=='Import Purchase')
	{

		$prefixcode="MRIP";
	}
	$qyprefix=DB_query("Select locationname from locations Where loccode ='".$_POST['sitecode']."'",$db);
	$row_prefix=DB_fetch_array($qyprefix);
	
	 $projectprefix=str_split($row_prefix['locationname'],1);
	 $projectprefix1=$projectprefix[0];
	 $siteCode = $_REQUEST['sitecode'];
	  	$Fin1ExpS1=explode("-",$_SESSION['financialYrStart']);
		$_SESSION['YearStart']=substr($Fin1ExpS1[0],2);
		$Fin1ExpE1=explode("-",$_SESSION['financialYrEnd']);
		$_SESSION['YearEnd']=substr($Fin1ExpE1[0],2);
		 $financial=$_SESSION['YearStart']."-".$_SESSION['YearEnd'];
	 $siteCode12=substr($siteCode,0,3);
      $sql="select * from addmrn where site = '".$_REQUEST['sitecode']."'";
      
	  $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
					
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		{
			
			 $strChar = $siteCode12."/".$prefixcode."/".$financial."/";
		}
	  }
	  else
	  {
	  	
		 $strChar = $siteCode12."/".$prefixcode."/".$financial."/";
	  }
	  
	 $strFinal = $maxval+1;
	$strBothFinal = $strChar.str_pad($strFinal,6,"0",STR_PAD_LEFT);
		
	$Billdate = $_POST['Billdate'];
	$expl =explode('/',$Billdate);
	$Billdatesav = $expl['1']."/".$expl['0']."/".$expl['2'];
	$inwarddate = $_POST['inwardate_save'];
	$inwardexplode = explode('/',$inwarddate);
	$inwardate_save = $inwardexplode[1]."/".$inwardexplode[0]."/".$inwardexplode[2];
	$qty=$_REQUEST['itemcode'];
	$qty1=count($qty);

	//$sql1 = "select PO_Orderno from purchorders where orderno = '".$_POST['select']."' ";
	//$result = DB_query($sql1, $db);
	//$myrow = DB_fetch_array($result);
	//$PO_Orderno = $myrow['PO_Orderno'];	

		$data['MRNNo']                 = $strBothFinal; 
 		$data['MRNDate']               = date('Y-m-d'); 
		$data['site']                  = $_REQUEST['sitecode']; 
		$data['site_name']             = $_REQUEST['sitename'];
		$data['StoreCode']             = $_REQUEST['storecode'];
		$data['Type']                  =  $_REQUEST['receiviedagaist'];
		$data['ReceivedFrom']          = $_REQUEST['vendor'];
		$data["PO_WO_MTO"]             = $_REQUEST['Purchase_Order']; 
		$data['ReceivedAgainst']       =  $_REQUEST['receiviedagaist'];
		$data['OrderDate']             = $_REQUEST['orderdate']; 
		$data['DocumentType']          = $_REQUEST['DocumentType'];  
		$data['BillNo']                = $_REQUEST['billno']; 
		$data['MRNVoucherDate']        = FormatDateForSQL($_REQUEST['MRNVoucherDate']); 
		$data['GetPassNo']             = $_REQUEST['gatepassno']; 		
		$data['gatepassdate']          = FormatDateForSQL($_REQUEST['gatepassdate']);
		$data['VehicleNo']             = $_REQUEST['vehicalno'];
		$data['TimeIn']                = $_REQUEST['timein']; 
		$data['Timeout']               = $_REQUEST['timeout'];
		$data['LRno']                  = $_REQUEST['lrno']; 
		$data['LRdate']                = FormatDateForSQL($_REQUEST['lrdate']); 
		$data['form_no']               = $_REQUEST['form_no'];
		$data['Transp_name']           = $_REQUEST['transporters'];  
		$data['grn_type']              = $_REQUEST['GrnType'];
		$data['duty_type']             = $_REQUEST['DutyType'];
		$data['RemarksIfAny']          = $_REQUEST['RemarksIfAny'];
		$data['form_type']             = $_REQUEST['form_type']; 
		$data['createdby']             =$_SESSION['UserID']; 
		$data['createddate']           =date('Y-m-d'); 
		
		$data['total_amount']          = $_REQUEST['total_item_amounts'];
		$data['order_no']              = $_REQUEST['orderno'];  	 
		$data['mrnstatus']             = "Pending";
		$data['Remarks']               = $_REQUEST['remark'];  
		$data['rmrs_no']               = $_REQUEST['rmrs_no'];		                    
		$data['pkg_perc']              = $_REQUEST['pkg_percs'];
		$data['pkg_charges']           = $_REQUEST['pkg_chargess'];
		$data['tot_excise_amt']        = $_REQUEST['tot_excise_amt'];
		$data['tot_ecess_amt']         = $_REQUEST['tot_ecess_amt'];
		$data['tot_sahecess_amt']      = $_REQUEST['tot_sahecess_amt'];
		$data['tot_excise_duty_amt']   = $_REQUEST['tot_excise_duty_amt'];
		$data['tot_taxable_amt']       = $_REQUEST['tot_taxable_amt'];
		$data['vat_cst']               = $_REQUEST['vat_cst'];
		$data['vat_cst_val']           = $_REQUEST['taxvalue'];
		$data['sur_oct_per']           = $_REQUEST['sur_oct_per'];
		$data['loading']               = $_REQUEST['loading'];
		$data['sur_oct_amt']           = $_REQUEST['sur_oct_amt'];
		$data['tot_freight']           = $_REQUEST['tot_freight'];
		$data['add_charges']           = $_REQUEST['add_chargess'];
		$data['grandtotal']            = $_REQUEST['grandtotals'];
		$data['round_off']             = $_REQUEST['round_off'];
		$data['companyID']             = $_SESSION['ACGCompanyId'];
		
		
		$data['total_custom_duty']    = $_REQUEST['custom_dutys'];
		$data['cvd_total']            = $_REQUEST['cvd_totals'];
		$data['custom_ecess']         = $_REQUEST['custom_ecesss1'];
		$data['custom_sec_ecess']     = $_REQUEST['custom_sec_ecesss'];
		$data['loading']              = $_REQUEST['loadings'];
		$data['basic_amount']         = $_REQUEST['basicAmount1'];
		$data['custom_duty']          = $_REQUEST['custom_duty'];
		$data['freight']              = $_REQUEST['tot_freights'];
		$data['sahecess_per']         = $_REQUEST['sahecess_per'];
		$data['e_cess_perc']          = $_REQUEST['e_cess_perc'];
		$data['excise_perc']          = $_REQUEST['excise_perc'];
		$data['cstm_add_per']         = $_REQUEST['cstm_add_per'];
		$data['cstm_ecessec_per']     = $_REQUEST['cstm_ecessec_per'];
		$data['cstm_ecess_per']       = $_REQUEST['cstm_ecess_per'];
		$data['cvd_per']              = $_REQUEST['cvd_per'];
		$data['custom_duty_per']      = $_REQUEST['custom_duty_per'];
		$data['tot_currency']         = $_REQUEST['tot_currency'];
		$data['tot_conv_rate']        = $_REQUEST['tot_conv_rate'];
		$data['tot_conv_amt']         = $_REQUEST['tot_conv_amt'];
		$data['containerNo']          = $_REQUEST['containerNo'];
		$data['totalBillQty']         = $_REQUEST['totalBillQty'];
		$data['totalRecQty']          = $_REQUEST['totalRecQty'];
		$data['bill_status']          = 0;
		
		if($s->getField('grn_config','id','1','grn_flag')==0)
		{
		$data['Approval_status'] =1;
		}
		else
		{
		$data['Approval_status'] =0;
		}
		 
	  	$dataUpadate['mrn_status'] = 1;	
		$conditionUpa="id='". $_REQUEST['Purchase_Order']."'"; 
		$s->RecordEdit('direct_po', $dataUpadate, $conditionUpa);
		
	    $insertsql=$s->insertRecord('addmrn', $data);
 	   $insertResult = DB_query($insertsql,$db,$ErrMsg);
	   $Lastreq_id=DB_Last_Insert_ID($db,'addmrn',$ErrMsg);
 	   if($insertResult==true)
	   {
	    		
		$countval= count($_REQUEST['itemcode']);
		$total_basic_amount=0;
		$total_tax_amount=0;	
		$coldata1=0;
		$numdata1=0;
 		for($i=0;$i<$countval;$i++)
		{
 				
				if($_REQUEST['qty_as_per_bill'][$i]!='')
				{				
				/* import and itemwise */
				$data_arr['issue_id']= $Lastreq_id;
				$data_arr['issue_qty']= $_POST['issuebalanc'][$i];				
				$data_arr['mst_itemid']= $_POST['mst_itemid'][$i];
				$data_arr['itemprice']= $_POST['itemrate'][$i];
				$data_arr['POQty']= $_REQUEST['poqty'][$i];
				$data_arr['batch_no']= $_REQUEST['batch_no'][$i];
				$data_arr['qty_as_per_bill']= $_REQUEST['qty_as_per_bill'][$i];	
				$data_arr['reciveqty']= $_REQUEST['reciveqty'][$i];	
				$data_arr['short_accessid']= $_REQUEST['short_accessid'][$i];
				$data_arr['itemamount']= $_REQUEST['itemamount'][$i];
				$data_arr['DiscountType1']= $_REQUEST['DiscountType1'][$i];
				$data_arr['discount']= $_REQUEST['discount'][$i];
				$data_arr['discounted_amount1']= $_REQUEST['discounted_amount1'][$i];
				$data_arr['NetRate1']= $_REQUEST['NetRate1'][$i];
				$data_arr['conv_curr']= $_REQUEST['conv_curr'][$i];	
				$data_arr['conv_rate']= $_REQUEST['conv_rate'][$i];	
				$data_arr['basic']= $_REQUEST['basic'][$i];  
				$data_arr['itemCurrency']= $_REQUEST['itemCurrency'][$i];
				$data_arr['Excise_type']= $_REQUEST['Excise_type'][$i];
				$data_arr['Excise_Duty1']= $_REQUEST['Excise_Duty1'][$i];		
				$data_arr['duty_amount_1']= $_REQUEST['duty_amount'][$i];
				$data_arr['TotalAmount1']= $_REQUEST['TotalAmount1'][$i];
				$data_arr['discount_1']= $_REQUEST['discount'][$i];
				$data_arr['custom_ecess']= $_REQUEST['custom_ecess1'][$i];
				$data_arr['custom_sec_ecess']= $_REQUEST['custom_sec_ecess1'][$i];	
				$data_arr['adduty']= $_REQUEST['adduty1'][$i];	
				
						
				$data_arr['disc_type']= $_REQUEST['disc_type'][$i];
				
				$data_arr['discount_amount']= $_REQUEST['discount_amount'][$i];
				$data_arr['val_after_disc']= $_REQUEST['val_after_disc'][$i];
				$data_arr['sp_disc_perc']= $_REQUEST['sp_disc_perc'][$i];
				$data_arr['sp_disc_amt']= $_REQUEST['sp_disc_amt'][$i]; 
				$data_arr['specialdis_type']=$_REQUEST['Perspc'][$i]; 				                 
				
				$data_arr['billing_type']= $_REQUEST['billing_type'][$i];  
				$data_arr['excise_duty']= $_REQUEST['excise_duty'][$i];  
				$data_arr['excise_perc']= $_REQUEST['excise_perc'][$i];  
				$data_arr['excise_val']= $_REQUEST['excise_val'][$i];  
				$data_arr['e_cess_perc']= $_REQUEST['e_cess_perc'][$i];  
				$data_arr['e_cess_val']= $_REQUEST['e_cess_val'][$i];  
				$data_arr['sah_perc']= $_REQUEST['sah_perc'][$i];  
				$data_arr['sah_val']= $_REQUEST['sah_val'][$i];				
				$data_arr['total_amt_with_tax']= $_REQUEST['total'][$i];
				$data_arr['remarks']= $_REQUEST['remarks'][$i];
				$data_arr['mat_value']= $_REQUEST['mat_value'][$i];	
				$data_arr['details_id']= $_REQUEST['details_id'][$i];
				$data_arr['pending_qty'] = $_REQUEST['pending_qty'][$i];
					
				if($_REQUEST['short_accessid'][$i]!=0)
					{
					$pending_status=1;
					$data_arr['status']= "N";
					}
					else
					{
					 $data_arr['status']= "Y";
					}
				
				if($_REQUEST['hidden_addqty']!='')
				$data_arr['parent_id']= $_REQUEST['hidden_addqty'];
				$data_arr['rejectqty']= $_REQUEST['rejectqty'][$i];
				$data_arr['order_no']= $_REQUEST['orderno'];
				$data_arr['item_total_rate']= $_REQUEST['item_total_rate'][$i];
				$data_arr['taxamount_rate']=$_REQUEST['taxableamount'][$i];				
		        $total_basic_amount+=$data_arr['item_total_rate'];
				$total_tax_amount+=$data_arr['taxamount_rate'];	
					
				//echo "<pre>";
				//print_r($data_arr);
				
								
				$insert_mrm=$s->insertRecord('addmrnqty', $data_arr);
				$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm,$db,$ErrMsg);
					
					
		/******************** insert update_mrn_qty Po QTY   **************************************/	
				
				
				if($_REQUEST['receiviedagaist']=='DirectPOOrder')
				       {
					  
					if($_REQUEST['reciveqty'][$i]>=$_REQUEST['pending_qty'][$i])
					{
						//echo "Update purchorderdetails set status='received' where 
						//orderno='".$_REQUEST['Purchase_Order']."' and mst_itemid='".$_REQUEST['mst_itemid'][$i]."'";
						
						
						$updatePO=DB_query("Update direct_po_details set status='received' where 
						parent_id='".$_REQUEST['Purchase_Order']."' and mst_itemid='".$_REQUEST['mst_itemid'][$i]."'",$db);					
					}
				}
				
				
				
					
				
					/**********************************************************************/
				
				
				}
					
					
							
  }
	
      
			
			
			if($_REQUEST['receiviedagaist']=='DirectPOOrder')
			{
				$get_num_rows=DB_query("Select * from direct_po_details where parent_id='".$_REQUEST['Purchase_Order']."'",$db);
				$num_rows=DB_num_rows($get_num_rows);				
				$check_item_stat=DB_query("Select * from direct_po_details where parent_id='".$_REQUEST['Purchase_Order']."'
				 and status='received'",$db);
				$received_num_rows=DB_num_rows($check_item_stat);
				
				if($num_rows==$received_num_rows)
				{
					$updatePOStat=DB_query("Update direct_po set recive_status='Receive' where 
					id='".$_REQUEST['Purchase_Order']."'",$db);
				}
			}
			
			
		
			 
		$_SESSION['success_msg']="Saved Successfully";
	echo "<script>location='index.php?route=Inventory/transation/material_receipt_note_exo_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	    
	}
	}
	unset($_SESSION['manvi_new']);
	unset($_SESSION['receiviedagaist']);
	unset($_SESSION['receipt']);
	unset($_SESSION['sitecode']);
	unset($_SESSION['sitename']);
	unset($_SESSION['hidden_site']);
	unset($_SESSION['vendor']);
	unset($_SESSION['PO']);
	unset($_SESSION['credit_days']);
	unset($_SESSION['MRNdate']);
	unset($_SESSION['matrialreceipt']);
	unset($_SESSION['storecode']);
	unset($_SESSION['storename']);
	unset($_SESSION['rmrs_no']);
	unset($_SESSION['orderdate']);
	unset($_SESSION['billno']);
	unset($_SESSION['MRNVoucherDate']);
	unset($_SESSION['gatepassno']);
	unset($_SESSION['inwardate_save']);
	unset($_SESSION['transport']);
	unset($_SESSION['vehicalno']);
	unset($_SESSION['timein']);
	unset($_SESSION['timeout']);
	unset($_SESSION['lrno']);
	unset($_SESSION['lrdate']);
	unset($_SESSION['total_weight']);
	unset($_SESSION['RemarksIfAny']);
	unset($_SESSION['DocumentType']);
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Material Receipt Note</h1>
<form action="" method="post">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 1px solid;">
  <tr>
    <th width="13%" align="left" valign="top"><strong>Site <font color="#FF0000">*</font></strong></th>
    <td width="20%" align="left" valign="top">
	<?php
	  //echo $_SESSION['ACGCompanyId'];
	//echo "---".$_SESSION['AssignedBranch'];
	
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
	<select name="sitecode" onchange="getreqitemdataNew(this.value)" id="sitecode" style="width:100%;">
      <option value="000">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($sitecode==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
      <?php } ?>
    </select></td>
    <th width="13%" align="left" valign="top"><strong>Mrn No. </strong></th>
    <td width="20%" align="left" valign="top"><input type="text" value="Will Be Generated On Saving" style="width:100%;" name="MRNNo" readonly="true"></td>
    <th width="13%" align="left" valign="top">Mrn Date</th>
    <td align="left" valign="top"><input type="text"  style="width:100%;"   name="MRNdate" 
	value="<?php if(isset($_SESSION['MRNdate']))echo $MRNdate; else echo date('d/m/Y');?>" id="MRNdate" class="datepicker"></td>
  </tr>
  <tr>
    <th align="left" valign="top"><strong>Warehouse <font color="#FF0000">*</font></strong></th>
    <td align="left" valign="top" id="storedata"><?php
		$sql_store = "select id, StoreCode, StoreName from storetype order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="storecode" name="storecode"  style="width:100%;" onfocus="check_po()"   >
		<option value="000">--Select--</option> 
		</select>	</td>
    <th align="left" valign="top"><strong>Recevie Against <font color="#FF0000">*</font></strong></th>
    <td align="left" valign="top"><select name="receiviedagaist" id="receiviedagaist"	style="width:100%;" onchange="checkdata(this.value)">
    <option value="0">--Select--</option>
   <!-- <option value="PO"<?php if($_REQUEST['receiviedagaist']=="PO") {?> selected="selected"<?php } ?>>PO</option>-->
	<option value="DirectPOOrder"<?php if($_REQUEST['receiviedagaist']=="DirectPOOrder") {?> selected="selected"<?php } ?>>DirectPOOrder</option>
    <option value="Without PO" <?php if($_REQUEST['receiviedagaist']=="Without PO") {?> selected="selected"<?php } ?>>Without PO</option> 
	<!--<option value="Import Purchase" <?php if($_REQUEST['receiviedagaist']=="Import Purchase") {?> selected="selected"<?php } ?>>Import Purchase</option>--> 	
    </select></td>
    <th align="left" valign="top"><strong>Vendor <font color="#FF0000">*</font></strong></th>
    <td align="left" valign="top"><select name="vendor" id="mst_supplierno"  style="width:100%;" onchange="ShowDiv(this.value,'hid_POrder','disp_porder.php?receipt='+document.getElementById('receiviedagaist').value+'&site='+document.getElementById('sitecode').value)" >
			<option value="000" >---Select---</option>
			<?php
			$sql="select id  ,vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			$p='';
			if($vendor==$myrow['id'])
			$p="selected";
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo  str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
		</select></td>
  </tr>
  <tr>
    <th align="left" valign="top">PO No.</th>
    <td align="left" valign="top"><div id='hid_POrder' style="width:100%;">
	<select name="Purchase_Order" id="Purchase_Order" onchange="getOrderDate(this.value)" style="width:100%;" >
	<option value="">--Select--</option>
      </select>
	</div></td>
    <th align="left" valign="top"><strong>PO Date </strong></th>
    <td align="left" valign="top"><input type="text" name="orderdate" id="orderdate"  readonly="true" style="width:100%;"></td>
    <th align="left" valign="top"><strong>GRN Type</strong></th>
    <td align="left" valign="top"><div id="typeGrn">
	 <select name="GrnType" id="GrnType" style="width:100%;">
      <option value="">--Select--</option>
    </select>
	</div></td>
  </tr>
  <tr>
    <th align="left" valign="top"><strong>Doc Type</strong></th>
    <td align="left" valign="top"><select name="DocumentType" id="DocumentType" style="width:100%;">
      <option value="">--Select--</option>
	  <option value="Challan">Challan</option>
      <option value="Bill">Bill</option>
	  <option value="BOL">Bill Of Lading</option>
    </select></td>
    <th align="left" valign="top"><strong>Doc No. </strong></th>
    <td align="left" valign="top"><input name="billno" type="text" id="billno" style="width:100%;" /></td>
    <th align="left" valign="top"><strong>Doc Date</strong></th>
    <td align="left" valign="top"><input type="text" name="MRNVoucherDate" id="MRNVoucherDate" style="width:100%;" class="datepicker" /></td>
  </tr>
  <tr>
    <th align="left" valign="top"><strong>Container No.</strong></th>
    <td align="left" valign="top"><input type="text" name="containerNo"  style="width:100%;" id="containerNo"/></td>
    <th align="left" valign="top"><strong>Gate Entry No.<font color="#FF0000">*</font></strong></th>
    <td align="left" valign="top"><input type="text" name="gatepassno"  style="width:200px;" id="gatepassno"/></td>
    <th align="left" valign="top"><strong>Gate Entry Date</strong><font color="#FF0000">*</font></strong></th>
    <td align="left" valign="top"><input type="text" name="gatepassdate" id="gatepassdate" style="width:200px;" class="datepicker" /></td>
  </tr>
  <tr>
    <th align="left" valign="top"><strong>Vehicle No.</strong></th>
    <td align="left" valign="top"><input name="vehicalno" type="text" id="vehicalno" style="width:200px;" value="<?php echo $vehicalno; ?>"/></td>
    <th align="left" valign="top"><strong>Transporter</strong></th>
    <td align="left" valign="top"><div id="transpName">
	<select name="transporters" id="transporters"  style="width:100%;">
			<option value="000" >---Select---</option>
		</select>
	</div></td>
    <th align="left" valign="top"><strong>L R No.</strong></th>
    <td align="left" valign="top"><input name="lrno" type="text" id="lrno" style="width:100%;"  value="<?php echo $lrno; ?>"/></td>
  </tr>
  <tr>
    <th align="left" valign="top"><strong>L R Date</strong></th>
    <td align="left" valign="top"><input name="lrdate" type="text" id="lrdate" style="width:100%;" class="datepicker"/></td>
    <th align="left" valign="top"><strong>Form Type</strong></th>
    <td align="left" valign="top"><select name="form_type" id="form_type"  style="width:100%;">
			<option value="000" >---Select---</option>
			<?php
			$sql="select id,form_name from form_type_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			?>
			 <option  value="<?php echo $myrow['id']; ?>"><?php echo  $myrow['form_name']; ?></option>
		<?php } ?>
		</select></td>
    <th align="left" valign="top"><strong>Form No</strong></th>
    <td align="left" valign="top"><input type="text" name="form_no" id="form_no"  style="width:100%;"/></td>
  </tr>
  <tr>
    <th align="left" valign="top"><?php if($mrnFlag=='0'){ ?>
	  <strong>Duty Type</strong><?php } ?></th>
    <td colspan="5" align="left" valign="top"><?php if($mrnFlag=='0'){ ?><select name="DutyType" id="DutyType" style="width:200px;" onchange="grnDisabled1(this.value)">
	<option value="">--Select--</option>
	<option value="Consolidated">Consolidated</option>
	<option value="Itemwise">Itemwise</option>
	</select><?php } ?></td>
    </tr>
  <tr>
    <th align="left" valign="top"><strong>Remarks</strong></th>
    <td colspan="5" align="left" valign="top"><textarea name="RemarksIfAny"  id="RemarksIfAny"  style="width:100%;"><?php echo $RemarksIfAny;?></textarea></td>
    </tr>
</table>
<br />
<?php 

if($_REQUEST['receiviedagaist']=='Without PO')
{$display="style='display:block'";}
else
{$display="style='display:none'";}
?>
<div id="reqId" <?php echo $display;?>>
<!--<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
 <th width="35px">PR No. </th>
    <td id="pr_no">
	<?php 
	$sql3="Select requisitionno, Reqno from materialrequisitions where sitecode='".$sitecode."'";
	  $result3=DB_query($sql3,$db);
	  ?>
	  <select name='req_no' style='width:150px' id='req_id' onchange='againstPR(this.value)'>
	  <option value=''>Select</option><?php 
	  while($row3=DB_fetch_array($result3))
	  {?>
	  	<option value='<?php echo $row3['requisitionno'];?>' <?php if($req_no==$row3['requisitionno']) echo "selected";?>><?php echo $row3['Reqno'];?></option><?php
	  }?>
	  </select>
    </td>
  </tr>
</table>-->
</div>



	<?php if($_REQUEST['receipt']=='PO' || $_REQUEST['receipt']=='DirectPOOrder'  )
	{
		$disabled="disabled";
	}
   else
	{
		$disabled='';
	}
		?>
	 <!--<p align="left">
	   <input type="submit"  name="item_popup" value="Add Items" id="item_popup"  onclick="open_items();"  <?php echo $disabled; ?> />
	 </p>-->
	 <?php if($mrnFlag=='1'){ ?>
	<div id="itemTable" style="width:950px;overflow:auto;">
 	</div>
	<?php } ?> 
	 
	 <div id="target_id"></div> 
  <div align="center">
  <?php if($_REQUEST['type']=='Direct' || $_REQUEST['pr']!=''){ ?>
    <input type="submit" name="save" value="Save" class="search" onclick="return confirmPost1()" />
	<?php }else{ ?>
	<input type="submit" name="save" value="Save" class="search" onclick="return confirmPost()" />
	<?php } ?>
    <input type="reset" name="reset" class="search" value="Reset" /><a href="index.php?route=Inventory/transation/material_receipt_note_exo_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" class="search" value="Cancel" name="Back" /></a>
<?php 
if($_REQUEST['type']=='Direct' || $_REQUEST['pr']!=''){
	$sqlmax="SELECT max_price FROM direct_mrn_config";
	$resultmax=DB_query($sqlmax,$db); 
	$rowmax=DB_fetch_array($resultmax);
?>
<input type="hidden" name="max_price" id="max_price" value="<?php echo $rowmax['max_price'];;?>" />
<?php }?>
  </div>

</form>
<script language="javascript" type="text/javascript">
function claculateExcise(id,str)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		var b=document.getElementById("basic_"+i).value;
	}
	else
	{
		var b=document.getElementById("basic").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)
    		{
			 
					if(id_brk.length>1)
					{
						var data=xmlhttp.responseText.split("__");
						document.getElementById("dutyamount_"+i).value=data[1];
						 
					}
					else
					{
						var data=xmlhttp.responseText.split("__");
						document.getElementById("dutyamount").value=data[1];
					}
    		}
  		}
		xmlhttp.open("GET","calculatecustomduty.php?quotTaxId="+str+"&data="+b,true);
		xmlhttp.send();
		var count =document.getElementById("count").value;
var tot_cvd1=0;
for(var h=0; h<count;h++){
	var discAmt = document.getElementById("basic_"+h).value;
	if(discAmt==''){discAmt=0;}
	tot_cvd1=parseFloat(tot_cvd1)+parseFloat(discAmt);
}
document.getElementById("total_item_amount12").value = tot_cvd1.toFixed(2);
}

function claculateExcise1(i,str)
{

	

	var discounted=document.getElementById("basic_"+i).value;

	if (str.length==0)

  		{

  			document.getElementById("exciseId_"+i).innerHTML="";

  			return;

  		}

		if (window.XMLHttpRequest)

  		{// code for IE7+, Firefox, Chrome, Opera, Safari

  			xmlhttp=new XMLHttpRequest();

  		}

		else

  		{// code for IE6, IE5

  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  		}

		xmlhttp.onreadystatechange=function()

  		{

  			if (xmlhttp.readyState==4 && xmlhttp.status==200)

    		{

    			document.getElementById("exciseId_"+i).innerHTML=xmlhttp.responseText;

    		}

  		}

		xmlhttp.open("GET","calculateExcise_exo.php?mrnTaxId="+str+"&data="+i,true);

		xmlhttp.send();

}
function claculateExcise2(i,str)

{
	var param1 = document.getElementById("total_item_amount4").value;
	var param2 = document.getElementById("pkg_charges4").value;
	
	var discounted=parseFloat(param1)+parseFloat(param2);

	if (str.length==0)

  		{

  			document.getElementById("exciseIdTot").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("exciseIdTot").innerHTML=xmlhttp.responseText;

    		}

  		}

		xmlhttp.open("GET","calculateExcise_exo1.php?mrnTaxId="+str+"&data="+i,true);

		xmlhttp.send();

}

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 calculateExciseDuty1(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 calculateExciseDuty2(i)
{
var param1 = document.getElementById("total_item_amount4").value;
	var param2 = document.getElementById("pkg_charges4").value;
	
	var discounted=parseFloat(param1)+parseFloat(param2);
	var ExcisePercentage=document.getElementById("ExcisePercentageTot").value;
	
	var exciseVal=discounted*(ExcisePercentage/100);
	document.getElementById("exciseValueTot").value=exciseVal.toFixed(2);
}



function checkexiseflag(i)
{
	if(document.getElementById("billing_type_"+i).value=='')
	{
	alert("Select Tax Type");
	document.getElementById("billing_type_"+i).focus();
	}	
}

function checkexiseflag1(i)
{
	if(document.getElementById("billing_type_"+i).value=='')
	{
	alert("Select Tax Type");
	document.getElementById("billing_type_"+i).focus();
	}	
}


function checkExcisable11(str,i)
{
if(str=='2')
	{
	document.getElementById("exciseDuty_"+i).disabled=true;
	document.getElementById("dutyamount_"+i).disabled=true;
	document.getElementById("TotalSpecial_"+i).disabled=true;
	document.getElementById("customecess_"+i).disabled=true;
	document.getElementById("customsececess_"+i).disabled=true;
	document.getElementById("adduty_"+i).disabled=true;
	
	document.getElementById("exciseDuty_"+i).value='';
	document.getElementById("dutyamount_"+i).value='';
	document.getElementById("TotalSpecial_"+i).value='';
	document.getElementById("customecess_"+i).value='';
	document.getElementById("customsececess_"+i).value='';
	document.getElementById("adduty_"+i).value='';
	}
	else
	{
	document.getElementById("exciseDuty_"+i).disabled=false;
	document.getElementById("dutyamount_"+i).disabled=false;
	document.getElementById("TotalSpecial_"+i).disabled=false;
	document.getElementById("customecess_"+i).disabled=false;
	document.getElementById("customsececess_"+i).disabled=false;
	document.getElementById("adduty_"+i).disabled=false;	
	}
}
function checkExcisable(str,i)
{	
	if(str=='NonExcisable')
	{
	document.getElementById("exciseDuty_"+i).disabled=true;
	document.getElementById("ECessPercentage_"+i).disabled=true;
	document.getElementById("ECessValue_"+i).disabled=true;
	document.getElementById("SAHCessPercentage_"+i).disabled=true;
	document.getElementById("SAHCessValue_"+i).disabled=true;
	document.getElementById("taxableamount_"+i).disabled=true;
	}
	else if(str=='Excisable' || str==0)
	{
	document.getElementById("exciseDuty_"+i).disabled=false;
	//document.getElementById("exciseValue_"+i).disabled=false;
	document.getElementById("ECessPercentage_"+i).disabled=false;
	document.getElementById("ECessValue_"+i).disabled=false;		
	document.getElementById("SAHCessPercentage_"+i).disabled=false;	
	document.getElementById("SAHCessValue_"+i).disabled=false;
	document.getElementById("taxableamount_"+i).disabled=false;
	}
	else
	{
	document.getElementById("exciseDuty_"+i).disabled=true;
	//document.getElementById("exciseValue_"+i).disabled=true;
	document.getElementById("ECessPercentage_"+i).disabled=true;
	document.getElementById("ECessValue_"+i).disabled=true;
	document.getElementById("SAHCessPercentage_"+i).disabled=true;
	document.getElementById("SAHCessValue_"+i).disabled=true;
	document.getElementById("taxable_amt_"+i).disabled=true;
	document.getElementById("taxname_"+i).disabled=true;
	document.getElementById("taxvalue_"+i).disabled=true;
	document.getElementById("sur_oct_perc_"+i).disabled=true;
	document.getElementById("sur_oct_amt_"+i).disabled=true;
	document.getElementById("TotalCharge_"+i).disabled=true;
	document.getElementById("packagingCharges_"+i).disabled=true;
	document.getElementById("additionalCharges_"+i).disabled=true;
	document.getElementById("roundOff_"+i).disabled=true;
	document.getElementById("exciseDuty_"+i).value='';
	//document.getElementById("exciseValue_"+i).value='';
	document.getElementById("ECessPercentage_"+i).value='';
	document.getElementById("ECessValue_"+i).value='';
	document.getElementById("SAHCessPercentage_"+i).value='';
	document.getElementById("SAHCessValue_"+i).value='';
	document.getElementById("taxable_amt_"+i).value='';
	document.getElementById("taxname_"+i).value='';
	document.getElementById("taxvalue_"+i).value='';
	document.getElementById("sur_oct_perc_"+i).value='';
	document.getElementById("sur_oct_amt_"+i).value='';
	document.getElementById("TotalCharge_"+i).value='';
	document.getElementById("packagingCharges_"+i).value='';
	document.getElementById("additionalCharges_"+i).value='';
	document.getElementById("roundOff_"+i).value='';
	}
	document.getElementById("hid_billing_type_"+i).value=str;
}

function checkExcisable1(str,i)
{	
	if(str=='NonExcisable')
	{
	document.getElementById("exciseDuty_"+i).disabled=true;
	document.getElementById("ExcisePercentage_"+i).disabled=true;
	document.getElementById("exciseValue_"+i).disabled=true;
	document.getElementById("ECessPercentage_"+i).disabled=true;
	document.getElementById("ECessValue_"+i).disabled=true;
	document.getElementById("SAHCessPercentage_"+i).disabled=true;
	document.getElementById("SAHCessValue_"+i).disabled=true;
	document.getElementById("taxableamount_"+i).disabled=true;
	}
	else if(str=='Excisable' || str==0)
	{
	document.getElementById("exciseDuty_"+i).disabled=false;
	document.getElementById("ExcisePercentage_"+i).disabled=false;
	document.getElementById("exciseValue_"+i).disabled=false;
	document.getElementById("ECessPercentage_"+i).disabled=false;
	document.getElementById("ECessValue_"+i).disabled=false;		
	document.getElementById("SAHCessPercentage_"+i).disabled=false;	
	document.getElementById("SAHCessValue_"+i).disabled=false;
	document.getElementById("taxableamount_"+i).disabled=false;
	}
	else
	{
	document.getElementById("exciseDuty_"+i).disabled=true;
	document.getElementById("ExcisePercentage_"+i).disabled=true;
	document.getElementById("exciseValue_"+i).disabled=true;
	document.getElementById("ECessPercentage_"+i).disabled=true;
	document.getElementById("ECessValue_"+i).disabled=true;
	document.getElementById("SAHCessPercentage_"+i).disabled=true;
	document.getElementById("SAHCessValue_"+i).disabled=true;
	document.getElementById("taxable_amt_"+i).disabled=true;
	//document.getElementById("taxname_"+i).disabled=true;
	//document.getElementById("taxvalue_"+i).disabled=true;
	//document.getElementById("sur_oct_perc_"+i).disabled=true;
	//document.getElementById("sur_oct_amt_"+i).disabled=true;
	//document.getElementById("TotalCharge_"+i).disabled=true;
	//document.getElementById("packagingCharges_"+i).disabled=true;
	//document.getElementById("additionalCharges_"+i).disabled=true;
	//document.getElementById("roundOff_"+i).disabled=true;
	document.getElementById("exciseDuty_"+i).value='';
	document.getElementById("exciseValue_"+i).value='';
	document.getElementById("ECessPercentage_"+i).value='';
	document.getElementById("ECessValue_"+i).value='';
	document.getElementById("SAHCessPercentage_"+i).value='';
	document.getElementById("SAHCessValue_"+i).value='';
	document.getElementById("taxable_amt_"+i).value='';
	document.getElementById("taxname_"+i).value='';
	document.getElementById("taxvalue_"+i).value='';
	document.getElementById("sur_oct_perc_"+i).value='';
	document.getElementById("sur_oct_amt_"+i).value='';
	document.getElementById("TotalCharge_"+i).value='';
	document.getElementById("packagingCharges_"+i).value='';
	document.getElementById("additionalCharges_"+i).value='';
	document.getElementById("roundOff_"+i).value='';
	}
	document.getElementById("hid_billing_type_"+i).value=str;
}



function cal_totalamount_data()
{	
	var total=0;
	var t=document.getElementById("countval").value;

	for(var i=0;i<t;i++)
	{
	var amt=parseFloat(document.getElementById("item_total_rate_"+i).value);
	if(isNaN(amt)){amt=0;}
	total=parseFloat(total)+amt;	
	}	
	document.getElementById("total_item_amount").value=total.toFixed(2);	
}





function cal_totalamount111()
{
	var total=0;
	var t=document.getElementById("count").value;
	for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("total_"+i).value);
		//alert(amt);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
	document.getElementById("total_item_amount").value=total.toFixed(2);	
}




function cal_totalamount_diectpo()
{
	var total=0;
	var t=document.getElementById("count").value;
	for(var i=0;i<t;i++)
	{
		
			var amt=parseFloat(document.getElementById("item_total_rate_"+i).value);
			if(isNaN(amt)){amt=0;}
			total=parseFloat(total)+amt;
	}	
	document.getElementById("total_item_amount").value=total.toFixed(2);	
}

function cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;
	var taxamt=document.getElementById("taxvalue").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	//var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	if(roundOffVal==''){roundOffVal='-.0';}	
	var test=roundOffVal.split(".");	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
		 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }
	
}

function cal_grandtotal111(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic_"+i).value;	 
		 var Totaltaxable=document.getElementById("dutyamount_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type_"+i).value==2)
		{ 
			var grand_tot1=parseFloat(basic);
			var grand_tot=grand_tot1.toFixed(2);
			
		}  
		else{ 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var cvd = grand_tot1*(12/100);
		var grand_tot=cvd.toFixed(2);
		 } 
		 document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
	
	}
	else
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic").value;	 
		 var Totaltaxable=document.getElementById("dutyamount").value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type").value==2)
		{ 
			var grand_tot1=parseFloat(basic);
			var grand_tot=grand_tot1.toFixed(2);
			
		}  
		else{ 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var grand_tot=grand_tot1.toFixed(2);
		 } 
		 document.getElementById("TotalSpecial").value=grand_tot1 ;	
	
	}
	
var cusduty = document.getElementById("custom_duty").value;
		if(cusduty=="")
		{
		document.getElementById("custom_duty").value = document.getElementById("dutyamount_"+i).value;
		}
		else
		{
		var sum1 = parseFloat(cusduty)+parseFloat(document.getElementById("dutyamount_"+i).value);
		document.getElementById("custom_duty").value = sum1.toFixed(2);
		} 
	
}

function cal_e_cess(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var tot = tot1*(2/100);
	var final_eces=tot.toFixed(2);
	document.getElementById("customecess_"+i).value=final_eces;	
}

function cal_esec_cess(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var tot = tot1*(1/100);
	var final_eces1=tot.toFixed(2);
	 document.getElementById("customsececess_"+i).value=final_eces1;	
}
function cal_add_duty1(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var a = document.getElementById("basic_"+i).value; 
	var b = document.getElementById("dutyamount_"+i).value;
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var d = document.getElementById("customecess_"+i).value; 
	var e = document.getElementById("customsececess_"+i).value; 
	var tot12= parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
	var addPer = document.getElementById("add_percentage").value; 
	var tot1 = tot12*(addPer/100);
	var final_eces2=tot1.toFixed(2);
	 document.getElementById("adduty_"+i).value=final_eces2 ;	
	
}
function cal_cvd_total11(id)
{
var count =document.getElementById("count").value;
var tot_cvd=0;
for(var i=0; i<count;i++){
	var cvd=document.getElementById("TotalSpecial_"+i).value;
	if(cvd==''){cvd=0;}
	tot_cvd=parseFloat(tot_cvd)+parseFloat(cvd);
}

//alert(tot_cvd);

var cvdtot = document.getElementById("cvd_total").value;
		if(cvdtot=="")
		{
		document.getElementById("cvd_total").value = document.getElementById("TotalSpecial_"+i).value;
		}
		else
		{
		var sum2 = parseFloat(cvdtot)+parseFloat(document.getElementById("TotalSpecial_"+i).value);
		document.getElementById("cvd_total").value = sum2.toFixed(2);
		} 
}

function cal_ecess_total(id)
{
var ecestot = document.getElementById("custom_ecess").value;
		if(ecestot=="")
		{
		document.getElementById("custom_ecess").value = document.getElementById("customecess_"+i).value;
		}
		else
		{
		var sum3 = parseFloat(ecestot)+parseFloat(document.getElementById("customecess_"+i).value);
		document.getElementById("custom_ecess").value = sum3.toFixed(2);
		} 
}
function cal_ecess_sec_total(id)
{
var ecesectot = document.getElementById("custom_sec_ecess").value;
		if(ecesectot=="")
		{
		document.getElementById("custom_sec_ecess").value = document.getElementById("customsececess_"+i).value;
		}
		else
		{
		var sum4 = parseFloat(ecesectot)+parseFloat(document.getElementById("customsececess_"+i).value);
		document.getElementById("custom_sec_ecess").value = sum4.toFixed(2);
		} 
}
function cal_addcharg_total(id)
{
var adcharge = document.getElementById("additionalCharges").value;
		if(adcharge=="")
		{
		document.getElementById("additionalCharges").value = document.getElementById("adduty_"+i).value;
		}
		else
		{
		var sum5= parseFloat(adcharge)+parseFloat(document.getElementById("adduty_"+i).value);
		document.getElementById("additionalCharges").value = sum5.toFixed(2);
		} 
}

function calcCustom(id)
{ 

var totalAmount = document.getElementById("total_item_amount3").value;
		if(totalAmount!="")
		{
		var percentage = document.getElementById("custom_duty_per").value;
		var result = totalAmount*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("custom_duty_new").value=final_result;	
		}
}

function calcCvd(id)
{ 
		var a1 = document.getElementById("total_item_amount3").value;
		var b1 = document.getElementById("custom_duty_new").value;
			
		if(a1!="")
		{
		var percentage = document.getElementById("cvd_per").value;
		var summ = parseFloat(a1)+parseFloat(b1);
		var result = summ*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("cvd_total_new").value=final_result;	
		}
}
function calcCustmexcess(id)
{ 
		var a2 = document.getElementById("custom_duty_new").value;
		var b2 = document.getElementById("cvd_total_new").value;
			
		if(a2!="")
		{
		var percentage2 = document.getElementById("cstm_ecess_per").value;
		var summ2 = parseFloat(a2)+parseFloat(b2);
		var result2 = summ2*(percentage2/100);
		var final_result2=result2.toFixed(2);
		document.getElementById("custom_ecess_new").value=final_result2;	
		}
}
function calcCustmexcessec(id)
{ 
		var a3 = document.getElementById("custom_duty_new").value;
		var b3 = document.getElementById("cvd_total_new").value;
		if(a3!="")
		{
		var percentage3 = document.getElementById("cstm_ecessec_per").value;
		var summ3 = parseFloat(a3)+parseFloat(b3);
		var result3 = summ3*(percentage3/100);
		var final_result3=result3.toFixed(2);
		document.getElementById("custom_sec_ecess_new").value=final_result3;	
		}
}
function calcadduty(id)
{ 
		var a4 = document.getElementById("total_item_amount3").value;
		var b4 = document.getElementById("custom_duty_new").value;
		var c4 = document.getElementById("cvd_total_new").value;
		var d4 = document.getElementById("custom_ecess_new").value;
		var e4 = document.getElementById("custom_sec_ecess_new").value;
		if(a4!="")
		{
		var percentage4 = document.getElementById("cstm_add_per").value;
		var summ4= parseFloat(a4)+parseFloat(b4)+parseFloat(c4)+parseFloat(d4)+parseFloat(e4);
		var result4 = summ4*(percentage4/100);
		var final_result4=result4.toFixed(2);
		document.getElementById("add_charges_new").value=final_result4;	
		}
}


function calcPackaging(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges").value=pckgng_val.toFixed(2);
	}
}

function calcPackaging12(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount12").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges").value=pckgng_val.toFixed(2);
	}
}
function calcPackaging3(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount3").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges3").value=pckgng_val.toFixed(2);
	}
}
function calcPackagingd(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("tot_conv_amt").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges").value=pckgng_val.toFixed(2);
	}
}
function calcPackaging4(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount4").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges4").value=pckgng_val.toFixed(2);
	}
}




 






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 calcExcise(str,i)
{
	var basic=document.getElementById("basic_"+i).value;
	var excise_val=basic*(str/100);
	document.getElementById("exciseValue_"+i).value=excise_val.toFixed(2);
}


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 calculateECess1(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 calculateECess2()
{
	var exciseValue=document.getElementById("exciseValueTot").value;
	var ECessPercentage=document.getElementById("ExcisePercentageTot").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValueTot").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 calculateSAHCess1(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 calculateSAHCess2(i)
{
	var exciseValue=document.getElementById("exciseValueTot").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentageTot").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValueTot").value=total.toFixed(2);
}

function cal_grandtotal(id)
{ 
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{ 
		var basic=document.getElementById("basic_"+i).value;	 
		 var Totaltaxable=document.getElementById("dutyamount_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type_"+i).value==2)
		{ 
			var grand_tot1=parseFloat(basic);
			var grand_tot=grand_tot1.toFixed(2);
			
		}  
		else{ 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var cvdPer = document.getElementById("cvd_percentage").value;
		var cvd = grand_tot1*(cvdPer/100);
		var grand_tot=cvd.toFixed(2);
		 } 
		 document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
	
	}
	else
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic").value;	 
		 var Totaltaxable=document.getElementById("dutyamount").value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type").value==2)
		{ 
			var grand_tot1=parseFloat(basic);
			var grand_tot=grand_tot1.toFixed(2);
			
		}  
		else{ 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var grand_tot=grand_tot1.toFixed(2);
		 } 
		 document.getElementById("TotalSpecial").value=grand_tot1 ;	
	
	}
	

var count =document.getElementById("count").value;
var tot_custom=0;
for(var i=0; i<count;i++){
	var dutyamt=document.getElementById("dutyamount_"+i).value;
	if(dutyamt==''){dutyamt=0;}
	tot_custom=parseFloat(tot_custom)+parseFloat(dutyamt);
}
//alert(tot_custom);
document.getElementById("custom_duty").value = tot_custom.toFixed(2);
}
function cal_e_cess1(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var ecessPer = document.getElementById("ecess_percentage").value;
	var tot = tot1*(ecessPer/100);
	var final_eces=tot.toFixed(2);
	document.getElementById("customecess_"+i).value=final_eces;	
}

function cal_esec_cess1(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var secEcessPer = document.getElementById("secess_percentage").value; 
	var tot = tot1*(secEcessPer/100);
	var final_eces1=tot.toFixed(2);
	 document.getElementById("customsececess_"+i).value=final_eces1;	
}
function cal_add_duty(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var a = document.getElementById("basic_"+i).value; 
	var b = document.getElementById("dutyamount_"+i).value;
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var d = document.getElementById("customecess_"+i).value; 
	var e = document.getElementById("customsececess_"+i).value; 
	var tot12= parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
	var tot1 = tot12*(4/100);
	var final_eces2=tot1.toFixed(2);
	 document.getElementById("adduty_"+i).value=final_eces2 ;	
	
}

function calConvertedAmount(val,id)
{
	var rates = document.getElementById("conv_rate_"+id).value;
	var amt = document.getElementById("NetRate_"+id).value;
	if(rates==''){rates=0;}
	if(amt==''){amt=0;}
	conv_amt=parseFloat(rates)*parseFloat(amt);
	document.getElementById("basic_"+id).value = conv_amt.toFixed(2);
}
function cal_basic_total(id)
{
var count =document.getElementById("count").value;
var tot_basic=0;
for(var i=0; i<count;i++){
	var basic=document.getElementById("basic_"+i).value;
	if(basic==''){basic=0;}
	tot_basic=parseFloat(tot_basic)+parseFloat(basic);
}
//alert(tot_basic);
document.getElementById("total_item_amount").value = tot_basic.toFixed(2);
}

function cal_custom_total(id)
{
var count =document.getElementById("count").value;
var tot_custom=0;
for(var i=0; i<count;i++){
	var dutyamt=document.getElementById("dutyamount_"+i).value;
	if(dutyamt==''){dutyamt=0;}
	tot_custom=parseFloat(tot_custom)+parseFloat(dutyamt);
}
//alert(tot_custom);
document.getElementById("custom_duty").value = tot_custom.toFixed(2);
}

function cal_cvd_total(id)
{

var count =document.getElementById("count").value;
var tot_cvd=0;
for(var i=0; i<count;i++){
	var cvd=document.getElementById("TotalSpecial_"+i).value;
	if(cvd==''){cvd=0;}
	tot_cvd=parseFloat(tot_cvd)+parseFloat(cvd);
}
//alert(tot_cvd);
document.getElementById("cvd_total").value = tot_cvd.toFixed(2);
}

function cal_ecess_total(id)
{
	var count =document.getElementById("count").value;
	var ecestot=0;
	for(var i=0; i<count;i++){
		var eces=document.getElementById("customecess_"+i).value;
		if(eces==''){eces=0;}
		ecestot=parseFloat(ecestot)+parseFloat(eces);
	}
	//alert(ecestot);
	document.getElementById("custom_ecess").value = ecestot.toFixed(2);
}
		
function cal_ecess_sec_total(id)
{
		var count =document.getElementById("count").value;
		var ecesectot=0;
		for(var i=0; i<count;i++){
			var ecess=document.getElementById("customsececess_"+i).value;
			if(ecess==''){ecess=0;}
			ecesectot=parseFloat(ecesectot)+parseFloat(ecess);
		}
		//alert(ecesectot);
		document.getElementById("custom_sec_ecess").value = ecesectot.toFixed(2);
}
function cal_addcharg_total(id)
{
		var count =document.getElementById("count").value;
		var adddutytot=0;
		for(var i=0; i<count;i++){
			var addduty=document.getElementById("adduty_"+i).value;
			if(addduty==''){addduty=0;}
			adddutytot=parseFloat(adddutytot)+parseFloat(addduty);
		}
		//alert(adddutytot);
		document.getElementById("additionalCharges").value = adddutytot.toFixed(2);
}

function calcCustom(id)
{ 

var totalAmount = document.getElementById("total_item_amount3").value;
		if(totalAmount!="")
		{
		var percentage = document.getElementById("custom_duty_per").value;
		var result = totalAmount*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("custom_duty_new").value=final_result;	
		}
}

function calcCustomd(id)
{ 

var totalAmount = document.getElementById("tot_conv_amt").value;
		if(totalAmount!="")
		{
		var percentage = document.getElementById("custom_duty_per").value;
		var result = totalAmount*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("custom_duty_new").value=final_result;	
		}
}

function calctotConvAmt(val)
{ 
	var totalAmount = document.getElementById("total_item_amount3").value;
		if(totalAmount!="")
		{
		var output = parseFloat(val)*parseFloat(totalAmount);
		var final_output=output.toFixed(2);
		document.getElementById("tot_conv_amt").value=final_output;	
		}
}

function calcCvd(id)
{ 
		var a1 = document.getElementById("total_item_amount3").value;
		var b1 = document.getElementById("custom_duty_new").value;
			
		if(a1!="")
		{
		var percentage = document.getElementById("cvd_per").value;
		var summ = parseFloat(a1)+parseFloat(b1);
		var result = summ*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("cvd_total_new").value=final_result;	
		}
}

function calcCvdd(id)
{ 
		var a1 = document.getElementById("tot_conv_amt").value;
		var b1 = document.getElementById("custom_duty_new").value;
			
		if(a1!="")
		{
		var percentage = document.getElementById("cvd_per").value;
		var summ = parseFloat(a1)+parseFloat(b1);
		var result = summ*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("cvd_total_new").value=final_result;	
		}
}
function calcCustmexcess(id)
{ 
		var a2 = document.getElementById("custom_duty_new").value;
		var b2 = document.getElementById("cvd_total_new").value;
			
		if(a2!="")
		{
		var percentage2 = document.getElementById("cstm_ecess_per").value;
		var summ2 = parseFloat(a2)+parseFloat(b2);
		var result2 = summ2*(percentage2/100);
		var final_result2=result2.toFixed(2);
		document.getElementById("custom_ecess_new").value=final_result2;	
		}
}

function calcCustmexcessd(id)
{ 
		var a2 = document.getElementById("custom_duty_new").value;
		var b2 = document.getElementById("cvd_total_new").value;
			
		if(a2!="")
		{
		var percentage2 = document.getElementById("cstm_ecess_per").value;
		var summ2 = parseFloat(a2)+parseFloat(b2);
		var result2 = summ2*(percentage2/100);
		var final_result2=result2.toFixed(2);
		document.getElementById("custom_ecess_new").value=final_result2;	
		}
}
function calcCustmexcessec(id)
{ 
		var a3 = document.getElementById("custom_duty_new").value;
		var b3 = document.getElementById("cvd_total_new").value;
		if(a3!="")
		{
		var percentage3 = document.getElementById("cstm_ecessec_per").value;
		var summ3 = parseFloat(a3)+parseFloat(b3);
		var result3 = summ3*(percentage3/100);
		var final_result3=result3.toFixed(2);
		document.getElementById("custom_sec_ecess_new").value=final_result3;	
		}
}
function calcadduty(id)
{ 
		var a4 = document.getElementById("tot_conv_amt").value;
		var b4 = document.getElementById("custom_duty_new").value;
		var c4 = document.getElementById("cvd_total_new").value;
		var d4 = document.getElementById("custom_ecess_new").value;
		var e4 = document.getElementById("custom_sec_ecess_new").value;
		if(a4!="")
		{
		var percentage4 = document.getElementById("cstm_add_per").value;
		var summ4= parseFloat(a4)+parseFloat(b4)+parseFloat(c4)+parseFloat(d4)+parseFloat(e4);
		var result4 = summ4*(percentage4/100);
		var final_result4=result4.toFixed(2);
		document.getElementById("add_charges_new").value=final_result4;	
		}
}


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 calsuroctamt(str)
{
	var amt=document.getElementById("taxvalue").value;
	var	suroctper=document.getElementById("sur_oct_per").value;
	if(amt==''){amt=0;}
	if(suroctper==''){suroctper=0;}
	var amount=(amt*suroctper)/100;
	document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}

function calsuroctamt1()
{  
	var amt=document.getElementById("taxvalue").value;
	var	suroctper=document.getElementById("sur_oct_per").value;
	if(amt==''){amt=0;}
	if(suroctper==''){suroctper='0';}
	var amount=(amt*suroctper)/100;
	document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}

function cal_grandamount()
{
	var total=document.getElementById("total_item_amount").value;
	//var loading1=document.getElementById("loading1").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	//if(loading1=='') { loading=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 roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	/*if(roundOffVal==''){roundOffVal='-.0';}
	var test=roundOffVal.split(".");
	if(test[0]=='-')
	{
	var dot=".";
	var roundval=dot + test[1];
	document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	}
	else
	{
	var dot=".";
	var roundval=dot + test[1];
	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	}*/
	document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}
function cal_grandamount1()
{
	var total=document.getElementById("total_item_amount12").value;
	var cdis_amt=document.getElementById("pkg_charges").value;
	var insurancecharges_amt=document.getElementById("custom_duty").value;
	var overseasfrieght_amt=document.getElementById("cvd_total").value;
	var localfreight_amt=document.getElementById("custom_ecess").value;
	var calclearingforwarding_amt=document.getElementById("custom_sec_ecess").value;	
	var detetioncharges_amt=document.getElementById("additionalCharges").value;	
	var othercharges=document.getElementById("TotalCharge").value;
	var othercharges1=document.getElementById("loading1").value;	
	if(total==''){total=0;}
	if(cdis_amt==''){cdis_amt=0;}
	if(insurancecharges_amt==''){insurancecharges_amt=0;}
	if(overseasfrieght_amt==''){overseasfrieght_amt=0;}
	if(localfreight_amt==''){localfreight_amt=0;}
	if(calclearingforwarding_amt==''){calclearingforwarding_amt=0;}
	if(detetioncharges_amt==''){detetioncharges_amt=0;}	if(othercharges==''){othercharges=0;}
	if(othercharges1==''){othercharges1=0;}
	 
	grandtotal=parseFloat(total)+parseFloat(cdis_amt)+parseFloat(insurancecharges_amt)+parseFloat(overseasfrieght_amt)+parseFloat(localfreight_amt)+parseFloat(calclearingforwarding_amt)+parseFloat(detetioncharges_amt)+parseFloat(othercharges)+parseFloat(othercharges1);
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
}

function cal_grandamount5()
{

	var total=document.getElementById("tot_conv_amt").value;
	var cdis_amt=document.getElementById("pkg_charges").value;
	var insurancecharges_amt=document.getElementById("custom_duty_new").value;
	var overseasfrieght_amt=document.getElementById("cvd_total_new").value;
	var localfreight_amt=document.getElementById("custom_ecess_new").value;
	var calclearingforwarding_amt=document.getElementById("custom_sec_ecess_new").value;	
	var detetioncharges_amt=document.getElementById("add_charges_new").value;	
	var othercharges=document.getElementById("TotalCharge2").value;	
	var othercharges1=document.getElementById("loading2").value;	
	
	if(total==''){total=0;}
	if(cdis_amt==''){cdis_amt=0;}
	if(insurancecharges_amt==''){insurancecharges_amt=0;}
	if(overseasfrieght_amt==''){overseasfrieght_amt=0;}
	if(localfreight_amt==''){localfreight_amt=0;}
	if(calclearingforwarding_amt==''){calclearingforwarding_amt=0;}
	if(detetioncharges_amt==''){detetioncharges_amt=0;}	if(othercharges==''){othercharges=0;}
	if(othercharges1==''){othercharges1=0;}
	 
	
	grandtotal=parseFloat(total)+parseFloat(cdis_amt)+parseFloat(insurancecharges_amt)+parseFloat(overseasfrieght_amt)+parseFloat(localfreight_amt)+parseFloat(calclearingforwarding_amt)+parseFloat(detetioncharges_amt)+parseFloat(othercharges)+parseFloat(othercharges1);
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
}
function calcRounded(str)
{
	var gtotal=document.getElementById('GrandTotal').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 open_items()
{

 var type=document.getElementById("receiviedagaist").value;
 window.open("MRN_items.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&type="+type,"item_popup_window","height=500,width=800,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}



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");
	document.getElementById("str").focus();
	return false;
	}
}
function cal_totalcharge()
{
	var total=0;
	var countcharges = document.getElementById("countcharges").value;
	for(var j=1;j<countcharges;j++)
	{
	var actual=document.getElementById("actual_"+j).value;
	if(actual!=''){
	total=parseFloat(total)+parseFloat(actual); }
	}
	document.getElementById("chargeamount").value=total;
}



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("totalqty").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;
}
 
  
</script>
<script>
 
  
function checkdata(str)
{
	if(str=="Without PO")
	{
	document.getElementById("reqId").style.display = "block";
	document.getElementById("req_id").disabled=false;
	document.getElementById("vendor").disabled=false;
	document.getElementById("item_popup").disabled=false;
	document.getElementById("Purchase_Order").disabled=true;
	}	
	else if(str=="Import Purchase")
	{
	document.getElementById("reqId").style.display = "none";
	document.getElementById("req_id").disabled="none";
	document.getElementById("vendor").disabled=false;
	document.getElementById("item_popup").disabled=false;
	document.getElementById("Purchase_Order").disabled=true;
	}	
	else
	{
	document.getElementById("reqId").style.display = "none";
	document.getElementById("vendor").disabled=false;
	document.getElementById("item_popup").disabled=true;
	document.getElementById("req_id").disabled=true;
	}
}
  
  
function DiscountAmountdpc(DA,i)
{ 
 
	var discount_percent = document.getElementById("Perspc_"+i).value;
	var totalPrice = document.getElementById("NetRate_"+i).value;
	var discount = document.getElementById("special_discount_"+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("special_discount_"+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("special_discount_"+i).value='';
	document.getElementById("basic_"+i).value='';
	document.getElementById("special_discount_"+i).focus();
	return false;
	}
	else
	{
	document.getElementById("Specialperc_"+i).value=percent.toFixed(2);
	document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	return true;
	
	}
}

function checkgatentyno(str)
{
 
	if (str.length==0)
	{
	document.getElementById("entrycheck1").innerHTML='';
	alert("Must Enter Gate Entry Pass No");
	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("entrycheck1").innerHTML=xmlhttp.responseText;
	
	}
	}
	xmlhttp.open("GET","gatentypass.php?str="+str,true);
	xmlhttp.send();





}  
  
   function DiscountAmount2(DA,id)
{



	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		//document.getElementById("stock_perunit_"+i).value=1;
		var discount_percent = document.getElementById("PerAmo2_"+i).value;	
		var rate = document.getElementById("Rate2_"+i).value;
		var discount = document.getElementById("Discount2_"+i).value;
		var quantity = document.getElementById("Quantity2_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		
		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("Discount2_"+i).value);
			if(isNaN(percent)){percent=0;}
			var subTotal = totalPrice-parseFloat(percent);
		
		}
		document.getElementById("perc2_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate2_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic2_"+i).value=subTotal.toFixed(2);
		
	}
	else
	{
	
	//document.getElementById("stock_perunit").value=1;
	
	var discount_percent = document.getElementById("PerAmo2").value;	


	var rate = document.getElementById("Rate2").value;
	var discount = document.getElementById("Discount2").value;
	var quantity = document.getElementById("Quantity2").value;
	var totalPrice = parseFloat(quantity)*parseFloat(rate);
	
	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("Discount2").value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
	
	}
	document.getElementById("perc2").value=percent.toFixed(2);
	document.getElementById("NetRate2").value=subTotal.toFixed(2);
	document.getElementById("basic2").value=subTotal.toFixed(2);
	
	
	
	}
	
	



	
 
}	

function Get_oderdata(str){
if (str=="")
  {
  document.getElementById("dept").innerHTML="";
  return;
  }
var xmlhttp;
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("oderitem").innerHTML=data[0];
	document.getElementById("jobcarddata").innerHTML=data[1];
    }
  }
  
xmlhttp.open("GET","get_orderdata9.php?salid="+str,true);
xmlhttp.send();	
	
}
function calculateTotalPrice(id)
{
 

var id_brk=id.split('_');

	var i=id_brk[1];
 
	if(id_brk.length>1)
	{	 
		  if(document.getElementById("reciveqty_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty_"+i).focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty_"+i).value;
			Rate= document.getElementById("itemrate_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty").value;
			Rate= document.getElementById("itemrate").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount").value=Total.toFixed(2);		
		   }	
	
	}
}	 

function calculateTotalPrice1(id)
{
 

var id_brk=id.split('_');

	var i=id_brk[1];
 
	if(id_brk.length>1)
	{	 
		  if(document.getElementById("reciveqty1_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty1_"+i).focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty1_"+i).value;
			Rate= document.getElementById("itemrate1_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount1_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty1").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty1").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty1").value;
			Rate= document.getElementById("itemrate1").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount1").value=Total.toFixed(2);		
		   }	
	
	}
}	  
function calculateTotalPrice2(id)
{
 

var id_brk=id.split('_');

	var i=id_brk[1];
 
	if(id_brk.length>1)
	{	 
		  if(document.getElementById("reciveqty2_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty2_"+i).focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty2_"+i).value;
			Rate= document.getElementById("itemrate2_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount2_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty2").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty2").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty2").value;
			Rate= document.getElementById("itemrate2").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount2").value=Total.toFixed(2);		
		   }	
	
	}
}
function calculateTotalPrice3(id)
{

var id_brk=id.split('_');

	var i=id_brk[1];
	if(id_brk.length>1)
	{	
		  if(document.getElementById("reciveqty3_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty3_"+i).focus();	
		  }
		  else
		  {	
			Quantity = document.getElementById("reciveqty3_"+i).value;
			Rate= document.getElementById("itemrate3_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount3_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty3").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty3").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty3").value;
			Rate= document.getElementById("itemrate3").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount3").value=Total.toFixed(2);		
		   }	
	
	}
}	  
function cal_totalamount()
{
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("basic_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;
	}	
document.getElementById("total_item_amount").value=total.toFixed(2);	
}
function cal_totalamount12()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("basic_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("total_item_amount12").value=total.toFixed(2);	
}
function cal_totalamount3()
{
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("basic3_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("total_item_amount4").value=total.toFixed(2);	
}

function calcPackaging2(str)

{

	if(str!='')

	{

		var tota_amt=document.getElementById("total_item_amount").value;

		var pckgng_val=(str/100)*tota_amt;

		document.getElementById("pkg_charges").value=pckgng_val.toFixed(2);

	}
}

function calcexcise2()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("exciseValue_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("tot_excise_amt").value=total.toFixed(2);	
}

function calcecess2()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("ECessValue_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("tot_ecess_amt").value=total.toFixed(2);	
}

function calcsahecess2()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("SAHCessValue_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("tot_sahecess_amt").value=total.toFixed(2);	
}

function calcexciseduty2()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("taxableamount_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("tot_excise_duty_amt").value=total.toFixed(2);	
}

function calcexciseduty3()
{	
var exiceAMt = document.getElementById("exciseValueTot").value;
var ecessAMt = document.getElementById("ECessValueTot").value;
var esahAMt = document.getElementById("SAHCessValueTot").value;
if(isNaN(exiceAMt)){exiceAMt=0;}
if(isNaN(ecessAMt)){ecessAMt=0;}
if(isNaN(esahAMt)){esahAMt=0;}
var total = parseFloat(exiceAMt)+parseFloat(ecessAMt)+parseFloat(esahAMt);
document.getElementById("tot_excise_duty_amt3").value=total.toFixed(2);	
}

function calctaxamt2()
{	
var total=0;
var amt1=document.getElementById("tot_excise_duty_amt").value;
if(isNaN(amt1)){amt1=0;}

var amt2=document.getElementById("total_item_amount").value;
if(isNaN(amt2)){amt2=0;}

var amt3=document.getElementById("pkg_charges").value;
if(isNaN(amt3)){amt3=0;}


total=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);	
		
document.getElementById("tot_taxable_amt").value=total.toFixed(2);	
}

function calctaxamt3()
{	
var total=0;
var amt1=document.getElementById("tot_excise_duty_amt3").value;
if(isNaN(amt1)){amt1=0;}

var amt2=document.getElementById("total_item_amount4").value;
if(isNaN(amt2)){amt2=0;}

var amt3=document.getElementById("pkg_charges4").value;
if(isNaN(amt3)){amt3=0;}


total=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);	
		
document.getElementById("tot_taxable_amt3").value=total.toFixed(2);	
}

function tax_rate2(str)
{
var taxableAmount=document.getElementById("tot_taxable_amt").value;
if(taxableAmount==''){taxableAmount=0;}
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_val.php?taxid="+str+"&amt="+taxableAmount,true);

xmlhttp.send();

}

function tax_rate3(str)
{
var taxableAmount=document.getElementById("tot_taxable_amt3").value;
if(taxableAmount==''){taxableAmount=0;}
if (str.length==0)
  {
  document.getElementById("taxval1").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("taxval3").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","get_tax_val1.php?taxid="+str+"&amt="+taxableAmount,true);

xmlhttp.send();

}
function calsuroctamt2(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 calsuroctamt3(str)

{
	var amt=parseFloat(document.getElementById("taxvalue2").value);

	var	suroctper=parseFloat(document.getElementById("sur_oct_per3").value);

	var amount=(amt*suroctper)/100;

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

}

function cal_grandamounts2()
{
	var totaltax=document.getElementById("tot_taxable_amt").value;
	var taxamt=document.getElementById("taxvalue_").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var loading=document.getElementById("loading").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	

	if(totaltax==''){totaltax=0;}
	if(taxamt==''){taxamt=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(loading==''){loading=0;}
	if(additionalCharges==''){additionalCharges=0;}

	

	var grandtotal=parseFloat(totaltax)+parseFloat(taxamt)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(loading)+parseFloat(additionalCharges);

	document.getElementById("GrandTotals").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tots").value=grandtotal.toFixed(2);	

}

function cal_grandamounts3()
{
	var totaltax=document.getElementById("tot_taxable_amt3").value;
	var taxamt=document.getElementById("taxvalue2").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt3").value;
	var TotalCharge=document.getElementById("TotalCharge1").value;
	var loading=document.getElementById("loading1").value;
	var additionalCharges=document.getElementById("additionalCharges1").value;	

	if(totaltax==''){totaltax=0;}
	if(taxamt==''){taxamt=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(loading==''){loading=0;}
	if(additionalCharges==''){additionalCharges=0;}

	

	var grandtotal=parseFloat(totaltax)+parseFloat(taxamt)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(loading)+parseFloat(additionalCharges);

	document.getElementById("GrandTotals3").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tots3").value=grandtotal.toFixed(2);	

}
function calcRounded2(str)

{

	var gtotal=document.getElementById('orig_grand_tots').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('GrandTotals').value=final;

}
function calcRounded3(str)

{

	var gtotal=document.getElementById('orig_grand_tots3').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('GrandTotals3').value=final;

}
</script>