<link rel="stylesheet" type="text/css" href="css/professional/table_frize.css">
<?php
if(isset($_REQUEST['Update']))
{
	$data['po_date']=FormatDateForSQL($_REQUEST['po_date']);	
	$data['delivery_place']=$_REQUEST['delivery_place'];
	$data['mod_of_transport']=$_REQUEST['mod_of_transport'];
	$deli_date = str_replace('/', '-', $_REQUEST['delivery_date']);
	$data['delivery_date']=date('Y-m-d', strtotime($deli_date));
	$valid_date = str_replace('/', '-', $_REQUEST['valid_till']);
	$data['valid_till']=date('Y-m-d', strtotime($valid_date));
	$data['delivery_time']=$_REQUEST['delivery_time'];
	$data['payment_terms']=$_REQUEST['PaymentTerm'];
	$data['payment_mod']=$_REQUEST['payment_mod'];
	$data['remarks']=$_REQUEST['remarks']; 
	$data['modified_by']=$_SESSION['UserID'];
	$data['modified_date']=date('Y-m-d');
	//$data['po_category']=$_REQUEST['po_category'];

	$con = "id = '".$_REQUEST['id']."'";
	$s->RecordEdit('purchorders',$data,$con);
	
	
	//INSERT INTO PARANT TABLE
	
	//echo "<pre>";print_r($_REQUEST['mst_itemid']); die;	
		
		$s->pageLocation("index.php?route=POModule/view_purchase_order".$rurl);
}

?>
<script type="text/javascript" language="javascript">
$.noConflict();
$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=profile_popup]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var site=document.getElementById("site").value;
		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#PickedItems").dialog({
				title:'Item List',
				modal: true,
				resizable: false,
				width:900,
				height:400,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		GetitemListForDirectPO(site);
		});
	});


function closediolgebox(exval,id)
{
	if(id=='')
	{
		document.getElementById("exciseValue").value=exval;
	}
	else
	{
		document.getElementById("exciseValue_"+id).value=exval;
	}
	$('#div_id').dialog("close");
}


function calculateExcisejq(id,val)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("div_id").innerHTML=xmlhttp.responseText;
	}
	}
	var id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		var basicamt=document.getElementById("basic").value;
	}
	else
	{
		var basicamt=document.getElementById("basic_"+i).value;
	}
	xmlhttp.open("GET","GetCalExcisejqe.php?ids="+id+"&vls="+val+"&bamt="+basicamt,true);
	xmlhttp.send();
}



function calecessjq(id,val)
{
	$("#div_idEcess").dialog({
	modal: true,
	resizable: false,
	width:300,
	height:150,
	closeText: 'fechar',
	draggable: true,
	show: 'fade',
	hide: 'fade',
	dialogClass: 'main-dialog-class',
	buttons: {
		//Save: function()
//		{
//		$("#myform").closest("form").submit();
//		},
		//Exit: function()
//		{
//			$(this).dialog("close");
//		}
	}
	});
	$(".ui-dialog-titlebar").hide();
	calculateEcessjq(id,val)
}


function calculateEcessjq(id,val)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("div_idEcess").innerHTML=xmlhttp.responseText;
	}
	}
	var id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","GetCalEcessjqe.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}


function closediolgeboxEcess(exval,id)
{
	if(id=='')
	{
		document.getElementById("ECessValue").value=exval;
	}
	else
	{
		document.getElementById("ECessValue_"+id).value=exval;
	}
	$('#div_idEcess').dialog("close");
}

function calSheecessjq(id,val)
{
	$("#div_idEcess").dialog({
	modal: true,
	resizable: false,
	width:300,
	height:150,
	closeText: 'fechar',
	draggable: true,
	show: 'fade',
	hide: 'fade',
	dialogClass: 'main-dialog-class',
	buttons: {
		//Save: function()
//		{
//		$("#myform").closest("form").submit();
//		},
		//Exit: function()
//		{
//			$(this).dialog("close");
//		}
	}
	});
	$(".ui-dialog-titlebar").hide();
	calculateSHEcessjq(id,val)
}


function calculateSHEcessjq(id,val)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("div_idEcess").innerHTML=xmlhttp.responseText;
	}
	}
	var id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","GetCalSHEcessjqe.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}


function closediolgeboxSHEcess(exval,id)
{
	if(id=='')
	{
		document.getElementById("SAHCessValue").value=exval;
	}
	else
	{
		document.getElementById("SAHCessValue_"+id).value=exval;
	}
	$('#div_idEcess').dialog("close");
}

function GetitemListForDirectPO(str)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("PickedItems").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","direct_po_items1.php?site="+str,true);
	xmlhttp.send();
}


function VendorAddressContactpeson(str)
{
	//alert(po_id);
	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("CPerson").innerHTML=data[0];
		//document.getElementById("billing_Address").value=data[1];
		//document.getElementById("billing_city").value=data[2];
		//document.getElementById("billing_state").value=data[3];
		//document.getElementById("billing_state1").value=data[4];
		//document.getElementById("billing_country").value=data[5];
		//document.getElementById("billing_country1").value=data[6];
	}
	}
	xmlhttp.open("GET","GetVenAddressContact.php?VID="+str,true);
	xmlhttp.send();
}
function VendorAddressContactpeson1(str)
{
	//alert(po_id);
	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("CPerson").innerHTML=data[0];
		document.getElementById("billing_Address").value=data[1];
		document.getElementById("billing_Address1").value=data[7];
		document.getElementById("billing_Address2").value=data[8];
		document.getElementById("billing_city").value=data[2];
		document.getElementById("billing_state").value=data[3];
		document.getElementById("billing_state1").value=data[4];
		document.getElementById("billing_country").value=data[5];
		document.getElementById("billing_country1").value=data[6];
		document.getElementById("zipcode").value=data[9];
	}
	}
	xmlhttp.open("GET","GetVenAddressContact1.php?VID="+str,true);
	xmlhttp.send();
}

function GetMobileNo(id)
{
	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("mobile_no").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","GetContactNo.php?contactId="+id,true);
	xmlhttp.send();
}


function checkExcisable(str,id)
{
	id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
	if(str=='NonExcisable')
	{
		document.getElementById("exciseDuty").disabled=true;
		document.getElementById("exciseValue").disabled=true;
		document.getElementById("cess_ID1").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("cess_ID2").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxable_amt").disabled=true;
		
		
		document.getElementById("exciseDuty").value='0';
		document.getElementById("exciseValue").value='';
		document.getElementById("cess_ID1").value='';
		document.getElementById("ECessValue").value='';
		document.getElementById("cess_ID2").value='';
		document.getElementById("SAHCessValue").value='';
		document.getElementById("taxable_amt").value='';
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty").disabled=false;
		document.getElementById("exciseValue").disabled=false;
		document.getElementById("cess_ID1").disabled=false;
		document.getElementById("ECessValue").disabled=false;
		document.getElementById("cess_ID2").disabled=false;
		document.getElementById("SAHCessValue").disabled=false;
		document.getElementById("taxable_amt").disabled=false;
	}
	else
	{
		document.getElementById("exciseDuty").disabled=true;
		document.getElementById("exciseValue").disabled=true;
		document.getElementById("cess_ID1").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("cess_ID2").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxable_amt").disabled=true;
		
		
		document.getElementById("exciseDuty").value='0';
		document.getElementById("exciseValue").value='';
		document.getElementById("cess_ID1").value='';
		document.getElementById("ECessValue").value='';
		document.getElementById("cess_ID2").value='';
		document.getElementById("SAHCessValue").value='';
		document.getElementById("taxable_amt").value='';
	}
	document.getElementById("hid_billing_type").value=str;
	}
	else
	{
	if(str=='NonExcisable')
	{
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("cess_ID1_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("cess_ID2_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		
		
		document.getElementById("exciseDuty_"+i).value='0';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cess_ID1_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cess_ID2_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("cess_ID1_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("cess_ID2_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxable_amt_"+i).disabled=false;	
	}
	else
	{
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("cess_ID1_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("cess_ID2_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		
		
		document.getElementById("exciseDuty_"+i).value='0';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cess_ID1_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cess_ID2_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
	}
	document.getElementById("hid_billing_type_"+i).value=str;
	}
	
}

function CustomDutyType(val,id)
{
	id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		if(document.getElementById("cuntomDuty_Flag").value=='2')
		{
			document.getElementById("Custon_Duty").disabled=true; 
			document.getElementById("CustomDutyAmt").disabled=true; 
		}
		else
		{
			document.getElementById("Custon_Duty").disabled=false; 
			document.getElementById("CustomDutyAmt").disabled=false; 
		}
	}
	else
	{
		if(document.getElementById("cuntomDuty_Flag_"+i).value=='2')
		{
			document.getElementById("Custon_Duty_"+i).disabled=true; 
			document.getElementById("CustomDutyAmt_"+i).disabled=true; 
		}
		else
		{
			document.getElementById("Custon_Duty_"+i).disabled=false; 
			document.getElementById("CustomDutyAmt_"+i).disabled=false; 
		}
	}
	
}



function checkCustomtype(id)
{
	id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		if(document.getElementById("cuntomDuty_Flag").value=='')
		{
			alert("please Select The Custom Duty Flag First !");
			return false;
		}
	}
	else
	{
		if(document.getElementById("cuntomDuty_Flag_"+i).value=='')
		{
			alert("please Select The Custom Duty Flag First !");
			return false;
		}
	}
}


function calculateTotalPrice(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		Quantity=document.getElementById("Quantity").value;
		Rate= document.getElementById("Rate").value;
		if(Quantity==''){Quantity=0;}
		if(Rate==''){Rate=0;}
		var Total=Quantity*Rate;
		document.getElementById("totalValue").value=Total.toFixed(2);
	}
	else
	{
		Quantity=document.getElementById("Quantity_"+i).value;
		Rate= document.getElementById("Rate_"+i).value;
		if(Quantity==''){Quantity=0;}
		if(Rate==''){Rate=0;}
		var Total=Quantity*Rate;
		document.getElementById("totalValue_"+i).value=Total.toFixed(2);
	}
}


function DiscountAmount(DA,id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var discount_percent = document.getElementById("PerAmo").value;
		var rate = document.getElementById("Rate").value;
		var discount = document.getElementById("Discount").value;
		var quantity = document.getElementById("Quantity").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("Discount").value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc").value=percent.toFixed(2);
		document.getElementById("NetRate").value=subTotal.toFixed(2);
		document.getElementById("basic").value=subTotal.toFixed(2);
	}
	else
	{
		var discount_percent = document.getElementById("PerAmo_"+i).value;
		var rate = document.getElementById("Rate_"+i).value;
		var discount = document.getElementById("Discount_"+i).value;
		var quantity = document.getElementById("Quantity_"+i).value;
		var totalPrice = 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("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);
	}
}



function Check(Ta,id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var totalnetrate=parseFloat(document.getElementById("totalValue").value);
		var discount = parseFloat(document.getElementById("Discount").value);
		var discount1=parseFloat(document.getElementById("perc").value);
		if(totalnetrate<discount)	
		{
		alert("Discount Amount Not Greater then Total Price");
		document.getElementById("Discount").value='';
		document.getElementById("perc").value='';
		document.getElementById("NetRate").value='';
		document.getElementById("basic").value='';		
		document.getElementById("Discount").focus();
		}	
		else if(totalnetrate<discount1)	
		{
		alert("Discount Amount Not Greater then Total Price");
		document.getElementById("Discount").value='';
		document.getElementById("perc").value='';
		document.getElementById("NetRate").value='';
		document.getElementById("basic").value='';		
		document.getElementById("Discount").focus();
		}	
	}
	else
	{
		var totalnetrate=parseFloat(document.getElementById("totalValue_"+i).value);
		var discount = parseFloat(document.getElementById("Discount_"+i).value);
		var discount1=parseFloat(document.getElementById("perc_"+i).value);
		if(totalnetrate<discount)	
		{
		alert("Discount Amount Not Greater then Total Price");
		document.getElementById("Discount_"+i).value='';
		document.getElementById("perc_"+i).value='';
		document.getElementById("NetRate_"+i).value='';	
		document.getElementById("basic_"+i).value='';		
		document.getElementById("Discount_"+i).focus();
		}	
		else if(totalnetrate<discount1)	
		{
		alert("Discount Amount Not Greater then Total Price");
		document.getElementById("Discount_"+i).value='';
		document.getElementById("perc_"+i).value='';
		document.getElementById("NetRate_"+i).value='';	
		document.getElementById("basic_"+i).value='';		
		document.getElementById("Discount_"+i).focus();
		}
	}
}


function checkexiseflag(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		if(document.getElementById("hid_billing_type").value=='')
		{
		alert("Select Tax Type");
		document.getElementById("hid_billing_type").focus();
		}	
	}
	else
	{
		if(document.getElementById("hid_billing_type_"+i).value=='')
		{
		alert("Select Tax Type");
		document.getElementById("hid_billing_type_"+i).focus();
		}	

	}
}


function calculateTaxable(id)
{
	id1=id.split("_");
	i=id1[2];
	if(i==undefined)
	{
		var exciseValue=document.getElementById("exciseValue").value;
		var ECessValue=document.getElementById("ECessValue").value;
		var SAHCessValue=document.getElementById("SAHCessValue").value;
		
		if(exciseValue==''){exciseValue=0;}
		if(ECessValue==''){ECessValue=0;}
		if(SAHCessValue==''){SAHCessValue=0;}
		var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
		document.getElementById("taxable_amt").value=TOTAL.toFixed(2);
	}
	else
	{
		var exciseValue=document.getElementById("exciseValue_"+i).value;
		var ECessValue=document.getElementById("ECessValue_"+i).value;
		var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
		
		if(exciseValue==''){exciseValue=0;}
		if(ECessValue==''){ECessValue=0;}
		if(SAHCessValue==''){SAHCessValue=0;}
		var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
		document.getElementById("taxable_amt_"+i).value=TOTAL.toFixed(2);

	}
}




function cal_grandtotal(id)
{

	var id1=id.split("_");
	var i=id1[1];
     
		var type_of_bill=document.getElementById("hid_billingtype_"+i).value;
		var basic=document.getElementById("basic_"+i).value;
		var Totaltaxable=document.getElementById("taxable_amt_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		if(document.getElementById("hid_billingtype_"+i).value=='NonExcisable')
		{
		var grand_tot1=parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
		}	
		else if(document.getElementById("hid_billingtype_"+i).value=='IncludeTax'){
		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_"+i).value=grand_tot;
		
}






function cal_grandtotalImp(id)
{
	id1=id.split("_");
	//alert(id1);
	if(i==undefined)
	{
		//var type_of_bill=document.getElementById("cuntomDuty_Flag").value;
		var basic=document.getElementById("basic").value;
		var Totaltaxable=0;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		
			var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
			var grand_tot=grand_tot1.toFixed(2);
		
		document.getElementById("TotalSpecial").value=grand_tot;
	}
	else
	{
		//var type_of_bill=document.getElementById("cuntomDuty_Flag_"+i).value;
		//alert(type_of_bill);
		var basic=document.getElementById("basic_"+i).value;
		//alert(basic);
		var Totaltaxable=0;
		//alert(Totaltaxable);
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
		var grand_tot=grand_tot1.toFixed(2);
		
		document.getElementById("TotalSpecial_"+i).value=grand_tot;
	}	
}




function showhideorddive(str)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText.split("__");
		document.getElementById("divordertype").innerHTML=data[0];
		document.getElementById("basicamtdetails").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","ajax_order_type.php?OrderType="+str,true);
	xmlhttp.send();
}




function CalculateCustomDuty(id,val)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText.split("__");
		var k=data[0];
		if(data[0]=='')
		{
			document.getElementById("CustomDutyAmt").value=data[1];
		}
		else
		{
			document.getElementById("CustomDutyAmt_"+k).value=data[1];
		}
	}
	}
	var id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		var basicamt=document.getElementById("basic").value;
	}
	else
	{
		var basicamt=document.getElementById("basic_"+i).value;
	}
	xmlhttp.open("GET","ajax_get_cutom_duty.php?ids="+id+"&vls="+val+"&bamt="+basicamt,true);
	xmlhttp.send();
}



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



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



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

</script>

<div id="PickedItems" style="display:none">
</div>

<div id="div_id" style="display:none"></div>

<div id="div_idEcess" style="display:none"></div>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Purchase Order Approval</h1>	
<form action="" method="post">

<!--GENERAL DETAILS-->
<?php
if($_REQUEST['action'] == 'edit')
{
$show_query = "select * from purchorders where id = '".$_REQUEST['id']."'";
$show_query_res = DB_query($show_query,$db) or die(DB_error());
$show_query_result = DB_fetch_array($show_query_res);

	$query_edit = "select * from purchorders where id='".$_REQUEST['id']."'";
	$query_edit_res = DB_query($query_edit,$db) or die(DB_error());
	$query_edit_result = DB_fetch_array($query_edit_res);
	$flag=0;
	$view_flag = 0;
	if($query_edit_result['indentPRno'] != "")
	{
		$flag = 1;
	}
	if($_REQUEST['modify'] == 'viewonly')
	{
		$view_flag = 1;
	}
	
	$ordertype=array("IO"=>"Import Order","DO"=>"Domestic Order");
	$poordertype=array("AT"=>"Asset","MT"=>"Material","SV"=>"Service");
	
?>
<h3>General Details</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td width="13%" align="right"><strong>Branch:</strong></td>
	<td width="35%"><?php 
	$ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')";
	$site_sql=DB_query($ss1,$db);?>
	<select name="site" id="site" onchange="VendorAddressContactpeson1(this.value,'<?php echo $_REQUEST['id'];?>')" ><!-- onchange="generate_reqno(this.value)"-->
	
	<?php 
		while($site_row=DB_fetch_array($site_sql))
		{
			if($flag=='1' || $view_flag == 1)
			{
				$p = "";
				if($query_edit_result['site'] == $site_row['loccode'])
				{
					$p="selected";
				}
			}
	?>
	<option value="<?php echo $site_row['loccode'];?>"<?php echo $p; ?>><?php echo $site_row['locationname'];?></option>
	<?php } ?>
	</select></td>
	<td width="13%" align="right"><strong>PO No.:</strong></td>
	<td><input type="text" value="<?php echo $query_edit_result['purchase_ordNo']; ?>" disabled="disabled"/></td>
</tr>
</tr>
<tr class="row1">
	<td align="right"><strong>Vendor Name:</strong></td>
	<td><?php 
	$SQLV="Select id,vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."' 
	and id='".$query_edit_result['vendorId']."'";
	$VDetails1=DB_query($SQLV,$db);?>
	<select name="vendor_id" id="vendor_id" >
		<?php 
		while($VDetails=DB_fetch_array($VDetails1))
		{
			if($flag=='1' || $view_flag == 1)
			{
				$p = "";
				if($query_edit_result['vendorId'] == $VDetails['id'])
				{
					$p="selected";
				}
			}
	?>
	<option value="<?php echo $VDetails['id'];?>" <?php echo $p; ?>><?php echo $VDetails['vendor_name'];?></option>
	<?php } ?>
	</select></td>
	<td align="right"><strong>PO Date:</strong></td>
	<td><input type="text" name="po_date" id="po_date" value="<?php  echo date("d/m/Y", strtotime( $query_edit_result['po_date']));?>" class="datepicker" <?php if($view_flag == 1){?> readonly="true" <?php } ?> /></td>
</tr>

<tr class="row1">
	<td align="right"><strong>Contact Person:</strong></td>
	<td id="CPerson">
		<select name="contact_person" id="contact_person">		
	<?php 
	$sqlConPerSon=DB_query("select * from contact_information_master where master_code='".$query_edit_result['vendorId']."' and master_prefix='S' and id='".$query_edit_result['contact_person']."'",$db);
	while($ConPerDetails=DB_fetch_array($sqlConPerSon))
	{	
		if($flag=='1' || $view_flag == 1 )
			{
				$p = "";
				if($query_edit_result['contact_person'] == $ConPerDetails['id'])
				{
					$p="selected";
				}
			}
	?>
	<option value="<?php echo $ConPerDetails['id']; ?>" <?php echo $p; ?>><?php echo $ConPerDetails['person']; ?></option>
	<?php 
	}
	?>	
	</select></td>
	<td align="right"><strong>Mobile No.:</strong></td>
	<td><input type="text" name="mobile_no" id="mobile_no" value="<?php echo $query_edit_result['mobileNo'];?>" readonly="readonly" ></td>
</tr>
<tr class="row1">
	<td align="right"><strong>Purchase Order Type:</strong></td>
	<td><?php $t=$query_edit_result['purchase_ord_Type'];	?>
	<input type="text" name="" value="<?php echo $ordertype[$t]; ?>" readonly="readonly" /></td>
	<td align="right"><strong>PO category:</strong></td>
	<td><?php $t1=$query_edit_result['po_category'];	
	?>
	<select name="po_category">
	<option value="0">Select</option>
	<?php
	foreach($poordertype as $key=>$value1)
	{ 
	$tt='';
	if($poordertype[$t1]==$value1)
	$tt="selected";
	?>
	<option value="<?php echo $key; ?>" <?php echo $tt; ?>><?php echo  $value1; ?></option>
	<?php } ?>
	</select>
		</td>
</tr>
	
<tr class="row1">	
	<td align="right"><strong>Quotation No.:</strong></td>
	<?php 
		$query_quoto = "select * from venderquotations where id='".$query_edit_result['quotationId']."'";
		$quoto_res = DB_query($query_quoto,$db) or die(DB_error());
		$quoto_result = DB_fetch_assoc($quoto_res);
	?>
	<td><input type="text" name="quote_No" id="quote_No" value="<?php echo $quoto_result['quotation_no'];?>" readonly="true" disabled="disabled"/></td>
	<td align="right"><strong>Quotation Date:</strong></td>
	<td colspan="3"><input type="text" name="quote_date" id="quote_date"  value="<?php echo date("d/m/Y", strtotime( $query_edit_result['qutation_date']));?>"  readonly="true" /></td>
</tr>
</table>
<!--GENERAL DETAILS-->

<!--ADDRESS DETAILS-->

<h3>Address Details (Ckeck If Billing &amp; Shipping Address Are Same <?php if($view_flag != 1){?><input type="checkbox" name="shipping_data" id="shipping_data" onclick="ship_data()"    ><?php } ?>)</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td width="13%" align="right"><strong>Billing Address:</strong></td>
	<td width="35%">
	<input type="text" name="billing_Address" id="billing_Address" value="<?php echo $query_edit_result['biiling_Address'];?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	<td width="13%" align="right"><strong>Shipping Address:</strong></td>
	<td id="CODE">
	<input type="text" id="Shipping_address" name="sippiling_Address" value="<?php echo $query_edit_result['sippiling_Address']; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	</tr>
	<tr class="row1">
	<td><strong></strong></td>
	<td>
	<input type="text" name="billing_Address1" id="billing_Address1" value="<?php echo $query_edit_result['biiling_Address1'];?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	<td><strong></strong></td>
	<td id="CODE">
	<input type="text" id="Shipping_address1" name="sippiling_Address1" value="<?php echo $query_edit_result['sippiling_Address1']; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	</tr>
	<tr class="row1">
	<td><strong></strong></td>
	<td >
	<input type="text" name="billing_Address2" id="billing_Address2" value="<?php echo $query_edit_result['biiling_Address2'];?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	<td align="right"><strong>Shipping Address:</strong></td>
	<td id="CODE">
	<input type="text" id="Shipping_address2" name="sippiling_Address2" value="<?php echo $query_edit_result['sippiling_Address2']; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	</tr>
	<tr class="row1">
	<td align="right"><strong>Billing City:</strong></td>
	<td><select name="billing_city" id="billing_city" onchange="GetSatateCountry(this.value)">
			<option value="">Select</option>
			  <?php 
				  $city_sql=DB_query("select * from city_master",$db);
				  while($city_row=DB_fetch_array($city_sql))
				  { 
				  		$p = "";
						if($query_edit_result['biiling_City'] == $city_row['id'])
							$p = "selected";			  
			  ?>
			  <option value="<?php echo $city_row['id'];?>" <?php echo $p; ?>><?php echo $city_row['city'];?></option>
			  <?php } ?>
	</select>	</td>
	<td align="right"><strong>Shipping City:</strong></td>
	<td>
	<select name="shipping_city" id="shipping_city" onchange="GetSatateCountry1(this.value)">
			<option value="">Select</option>
			  <?php 
			  $city_sql=DB_query("select * from city_master",$db);
			  while($city_row=DB_fetch_array($city_sql))
			  { 
			  	$p = "";
				if($query_edit_result['sippiling_City'] == $city_row['id'])
					$p = "selected";	
			  ?>
			  <option value="<?php echo $city_row['id'];?>" <?php echo $p; ?>><?php echo $city_row['city'];?></option>
			  <?php 
			  } 
			  ?>
	</select></td>
	</tr>
	<tr class="row1">
	<td align="right"><strong>Billing State:</strong></td>
	<td>
		<input type="hidden" name="billing_state" id="billing_state" value="<?php echo $query_edit_result['biiling_State']; ?>" />
		<?php $STname=$s->GetFieldValue('state_master',"id='".$query_edit_result['biiling_State']."'",'state'); ?>
		<input type="text" name="billing_state1" id="billing_state1" value="<?php echo $STname; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/>	</td>
	<td align="right"><strong>Shipping State:</strong></td>
	<td>
		<input type="hidden" name="shipping_state" id="shipping_state" value="<?php echo $query_edit_result['sippiling_State']; ?>" />
		<?php $STname=$s->GetFieldValue('state_master',"id='".$query_edit_result['sippiling_State']."'",'state'); ?>
		<input type="text" name="shipping_state1" id="shipping_state1" value="<?php echo $STname; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?> />	</td>
	</tr>
	<tr class="row1">
	<td align="right"><strong>Billing Country:</strong></td>
	<td>
		<input type="hidden" name="billing_country" id="billing_country" value="<?php echo $query_edit_result['biiling_Country']; ?>" />
		<?php $Conname=$s->GetFieldValue('country_master',"id='".$query_edit_result['biiling_Country']."'",'country'); ?>
		<input type="text" name="billing_country1" id="billing_country1" value="<?php echo $Conname; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/>	 </td>
	<td align="right"><strong>Shipping Country:</strong></td>
	<td><input type="hidden" name="shipping_country" id="shipping_country" value="<?php echo $query_edit_result['sippiling_Country']; ?>" />
					 <?php $Conname=$s->GetFieldValue('country_master',"id='".$query_edit_result['sippiling_Country']."'",'country'); ?>
					 <input type="text" name="shipping_country1" id="shipping_country1" value="<?php echo $Conname; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/>	</td>
	</tr>
	<tr class="row1">
	<td align="right"><strong>Billing Postal Code:</strong></td>
	<td >
	<input type="text" name="biiling_PostalCode" id="zipcode" value="<?php echo $query_edit_result['biiling_PostalCode']; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	<td align="right"><strong>Shipping Postal Code:</strong></td>
	<td><input type="text" name="sippiling_PostalCode" id="Shipping_zipcode" value="<?php echo $query_edit_result['sippiling_PostalCode'];?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
</tr>
</table>

<!--ADDRESS DETAILS-->

<!--OTHER DETAILS-->


<h3>Other Details:</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td width="13%" align="right"><strong>Delivery Date:</strong></td>
	<td width="35%"><input type="text" name="delivery_date" id="delivery_date" value="<?php echo date("d/m/Y", strtotime( $query_edit_result['delivery_date']));?>" class="datepicker"  onchange="checkvalidate()"   <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
	<td width="13%" align="right"><strong>Valid Till:</strong></td>
	<td><input type="text"  class="datepicker" name="valid_till" id="valid_till" value="<?php echo date("d/m/Y", strtotime( $query_edit_result['valid_till']));?>"  onchange="checktilldate()"  <?php if($view_flag == 1){?> readonly="true" <?php } ?> /></td>
</tr>

<tr class="row1">
	<td align="right"><strong>Payment Terms:</strong></td>
	<td><select name="PaymentTerm" id="PaymentTerm">
		<option value="000">Select Payment Terms</option>
		<?php 
		$sql="select * from paymentterms";
		$result=DB_query($sql, $db);
		while($myrow = DB_fetch_array($result))
		{ 
		$p='';
		if($query_edit_result['payment_terms']==$myrow['termsindicator'])
		$p="selected";
		?>
		<option value="<?php echo $myrow['termsindicator'];?>"<?php echo $p; ?>><?php echo $myrow['terms'];?></option>
		<?php } ?>
			      </select></td>
	<td align="right"><strong>Payment Mode:</strong></td>
	<td><select name="payment_mod" id="payment_mod">
			      <option value="000">Select Payment Mode</option>
			      <?php 
					$sql='SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($query_edit_result['payment_mod'] == $myrow['paymentid'])
							$p="selected";
						?>
			      <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
			      <?php 	} ?>
			      </select></td>
</tr>
<tr class="row1">
<td align="right"><strong>Remarks:</strong></td>
<td colspan="3"><textarea  name="remarks" id="remarks" <?php if($view_flag == 1){?> readonly="true" <?php } ?>><?php echo $query_edit_result['remarks'];?></textarea></td>
</tr>
</table>

<!--OTHER DETAILS-->
  <h3>Items Details:</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3"> 
  <tr class="row1">
    <td colspan="6" style="padding:0px;">
	<div style="width:100%; margin:auto;">
	 <div class="frisetable22">
	<div class="bodywidth2">	
      <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#333333 1px solid;">
        <tr class="row1">
          <td class="headerl_1">S. No.</td>
          <td class="headerl_2"></td>
          <td class="headerl_3">Part Code</td>
          <td class="headerl_4">Part Name</td>
		  <td class='col'></td>
          <td class='col'>Qty</td>
          <td class='col'>Rate</td>
		  <?php if($query_edit_result['purchase_ord_Type']=='IO') { ?> 
		  <td class='col'>Currency</td>
		  
		  <?php } ?>
          <td class='col'>Total Price</td>
          <td class='col'>Discount Type</td>
          <td class='col' style="width:60px;">Discount Amt</td>
		  <td class='col' style="width:60px;">Unit Wise Discount</td>
          <td class='col'>Discounted Amount</td>
          <td class='col'>Sub Total</td>
          <td class='col'>Basic Amount</td>
		 <?php if($query_edit_result['purchase_ord_Type']=='IO') { ?> 
            <td class="col">Total<br />Amt.</td>
		  <?php } else { ?>
		 <td class='col'>Excise flag</td>
         <td class='col'>Excise</td>
		<td class='col'>Excise Value</td>
       <td class='col'>E-Cess</td>
		<td class='col'>E-Cess Value</td>
		<td class='col'>SAH-E Cess</td>
		<td class='col'>SAH-E Value</td>
		<td class='col' >Excise Amt.</td>
		<td class='col' style="white-space:nowrap;">Total Amt.</td>
		  <?php } ?>          
        </tr>
        <tbody id="dataTable">
          <?php 
		$i=0;
		$item_detail_query = "select * from purchorderdetails where parantId='".$_REQUEST['id']."'";
		$item_detail_res = DB_query($item_detail_query,$db) or die(DB_error());
		while($item_detail_result = DB_fetch_array($item_detail_res))
		{
		
		  if($item_detail_result['Excise_type']=='NonExcisable' || $item_detail_result['Excise_type']=='NonExcisable')
		   {
		   $disable='disabled';
		   }
		   else
		   {
		   $disable='';
		   }
		   
			$mst_item_id = $item_detail_result['mst_itemid'];
			$mst_item_query = "select * from item_master where id='".$mst_item_id."'";
			$mst_item_res = DB_query($mst_item_query,$db) or die(DB_error());
			$mst_item_result = DB_fetch_array($mst_item_res);
			//echo $mst_item_result['StockID'];
			//echo $mst_item_result['item_name'];
			//echo $mst_item_result['mst_unitid'];
		?>
          <tr bgcolor="#fff">
            <td class="headercol1"><input name="checkbox"  type='checkbox' id="delitem[]"  readonly="true" /></td>
            <td class="headercol2"><input type='hidden' name='mst_itemid[<?php echo $i; ?>]' id='itemid_<?php echo $i; ?>' value="<?php echo $mst_item_id; ?>"/></td>
            <td class="headercol3"><input type='text' name='itemcode[<?php echo $i; ?>]' id='itemcode_<?php echo $i; ?>' value="<?php echo $mst_item_result['StockID']; ?>" readonly='true' /></td>
            <td class="headercol4"><input type='text' name='itemcode[<?php echo $i; ?>]' id='itemname_<?php echo $i; ?>' value="<?php echo $mst_item_result['item_name']; ?>" readonly='true' /></td>
			<td class="col1"><input type="hidden" name="status[<?php echo $i; ?>]" value="<?php echo $item_detail_result['status']; ?>" /></td>
            <td class="col1"><input  type='text' name='Quantity[<?php echo $i; ?>]' id='Quantity_<?php echo $i; ?>' value="<?php echo $item_detail_result['Quantity'];?>" readonly="true" /></td>
            <td class="col1"><input  type='text' name='Rate[<?php echo $i; ?>]' id='Rate_<?php echo $i; ?>' value="<?php echo $item_detail_result['Rate'];?>" onkeyup='calculateTotalPrice(this.id)' readonly="true" /></td>
			 <?php if($query_edit_result['purchase_ord_Type']=='IO') { ?> 
			 <td class="col1"><select name="currency[<?php echo $i; ?>]" >
	<option value="0">Select</option>
	<?php 
	$sql_currency=DB_query("select * from currency_master where  CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row_currency=DB_fetch_array($sql_currency))
	{
	$p1='';
	if($item_detail_result['currnecy']==$row_currency['id'])
	$p1="selected='selected'";
	?>
	<option value="<?php echo $row_currency['id']; ?>" <?php echo $p1; ?>><?php echo $row_currency['abbreviation']; ?></option>
	<?php } ?>
	</select></td>	
			 <?php }
			  ?>
            <td class="col1"><input type='text' name='totalPrice[<?php echo $i; ?>]' id='totalValue_<?php echo $i; ?>' value="<?php echo $item_detail_result['totalPrice'];?>" readonly='true'/></td>
            <td class="col1"><select name='DiscountType[<?php echo $i; ?>]' id='PerAmo_<?php echo $i; ?>'>
              <option value='Amount' <?php if($item_detail_result['DiscountType'] == "Amount"){ echo "selected"; } ?> >Amount</option>
              <option value='PercentAmt' <?php if($item_detail_result['DiscountType'] == "PercentAmt"){ echo "selected"; } ?> >Percent Amt</option>
            </select></td>
            <td class="col1"><input type='text' name='Discount[<?php echo $i; ?>]' id='Discount_<?php echo $i; ?>' value="<?php echo $item_detail_result['Discount'];?>" onblur='DiscountAmount(this.value,this.id)' onkeyup='DiscountAmount(this.value,this.id)' <?php if($view_flag == 1){?> readonly="true" <?php } ?> />
            </td>
		<td class="col1"><input type='text' name='unitdiscount[<?php echo $i; ?>]' id='unitdiscount_<?php echo $i; ?>' value="<?php echo $item_detail_result['unitwisedis'];?>" onblur='calcdisamt(this.value,this.id)'
		onkeyup='calcdisamt(this.value,this.id)' <?php if($view_flag == 1){?> readonly="true" <?php } ?> />
            </td>				
            <td class="col1"><input type='text' name='discounted_amount[<?php echo $i; ?>]' id='perc_<?php echo $i; ?>'  value="<?php echo $item_detail_result['discounted_amount'];?>" readonly='true' onfocus='Check(this.value,this.id)' />
            </td>
            <td class="col1"><input type='text'  id='NetRate_<?php echo $i; ?>' name='NetRate[<?php echo $i; ?>]' value="<?php echo $item_detail_result['NetRate']; ?>" readonly /></td>
            <td class="col1"><input type='text' id='basic_<?php echo $i; ?>' name='basic_Amt[<?php echo $i; ?>]' value="<?php echo $item_detail_result['basic_Amt'];?>"readonly /></td>
		<?php if($query_edit_result['purchase_ord_Type']=='IO') { ?> 	
             <td class="col1"><input type="text" id="TotalSpecial_<?php echo $i; ?>" name="TotalAmount[<?php echo $i; ?>]" onfocus="cal_grandtotalImp(this.id);" value="<?php echo $item_detail_result['TotalAmount']; ?>" <?php if($view_flag == 1){?> readonly="true" <?php } ?> /></td>
		<?php } else { ?>
		<td class="col1"><select name='Excise_type[<?php echo $i; ?>]' id='hid_billingtype_<?php echo $i; ?>'  onchange='checkExcisable(this.value,this.id)'>
					<option value=''>Select</option>
					<option value='NonExcisable' <?php if($item_detail_result['Excise_type']=='NonExcisable') { ?> selected="selected" <?php } ?>  >NonExcisable</option>
					<option value='Excisable' <?php if($item_detail_result['Excise_type']=='Excisable') { ?> selected="selected" <?php } ?>>Excisable</option>
					<option value='IncludeTax' <?php if($item_detail_result['Excise_type']=='IncludeTax') { ?> selected="selected" <?php } ?>>IncludeTax</option>
					</select></td>
					<td class="col1"><select name='Excise_Duty[<?php echo $i; ?>]' id='exciseDuty_<?php echo $i; ?>' onchange='claculateExcise(this.id,this.value)' onfocus='checkexiseflag(this.id)' <?php echo $disable; ?> >
					<option value=''>Select</option>
					<?php
					$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
					while($excise_row=DB_fetch_array($excise_sql))
					{
					$g='';
					if($item_detail_result['Excise_Duty']==$excise_row['id'])
					{$g='selected';}
					?>
					<option value="<?php echo $excise_row['id']; ?>" <?php echo $g; ?> ><?php echo $excise_row['caption']; ?></option>
					<?php } ?>
					</select><input name='ExcisePercentage[<?php echo $i; ?>]' id='ExcisePercentage_<?php echo $i; ?>' type='hidden' readonly <?php echo $disable; ?> />
					</td>
					<td class="col1"><input name='exciseValue[<?php echo $i; ?>]' id='exciseValue_<?php echo $i; ?>' type='text' onfocus='calculateExciseDuty(this.id)' readonly='true' value="<?php echo $item_detail_result['exciseValue']; ?>" <?php echo $disable; ?> /></td>
					<?php 
					$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
					$k=1;
					while($cessRow=DB_fetch_array($cessSql))
					{
					$caption[$k]=$cessRow['caption']; 
					$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
					while($rate_row=DB_fetch_array($rate_sql))
					{
					$rate[$k]=$rate_row['def_rate'];
					}
					$k++;
					} 	
					
					$cessLedgerSql1=DB_query("Select * from excise_tax where ledgertype='cess' LIMIT 0,1",$db);	 
					$cessLedgerSql2=DB_query("Select * from excise_tax where ledgertype='cess' LIMIT 1,1",$db);	 	 
					?>
					<td class="col1"><select name='Cess_ID[<?php echo $i; ?>]' id='cess_ID1_<?php echo $i; ?>' onchange='calEcessonchange(this.id,this.value)' <?php echo $disable; ?>>
					<option value=''>Select</option>
					<?php	
					while($cessLedger1=DB_fetch_array($cessLedgerSql1)){
					$t1='';
					if($cessLedger1['id']==$item_detail_result['Cess_ID'])
					$t1='selected';
					?>
					<option value="<?php echo $cessLedger1['id']; ?>" <?php echo $t1; ?>><?php echo $cessLedger1['caption']; ?></option>
					<?php } ?>
					</select>
					<input name='ECessPercentage[<?php echo $i; ?>]' id='ECessPercentage_<?php echo $i; ?>' type='hidden' value='<?php echo $rate[1]; ?>' readonly /></td>
					<td class="col1"><input name='ECessValue[<?php echo $i; ?>]' id='ECessValue_<?php echo $i; ?>' type='text' onfocus='calculateECess(this.id)' value="<?php echo $item_detail_result['ECessValue']; ?>" readonly <?php echo $disable; ?> /></td>
					<td class="col1"><select name='SHECess_ID[<?php echo $i; ?>]' id='cess_ID2_<?php echo $i; ?>' onchange='calSHEcessonchange(this.id,this.value)' <?php echo $disable; ?>>
					<option value=''>Select</option>
					<?php 	
					while($cessLedger2=DB_fetch_array($cessLedgerSql2)){
					$t2='';
					if($cessLedger2['id']==$item_detail_result['SHECess_ID'])
					$t2='selected';
					?>
					<option value="<?php echo $cessLedger2['id']; ?>" <?php echo $t2; ?> ><?php echo $cessLedger2['caption']; ?></option>
					<?php } ?>
					</select>
					<input name='SAHCessPercentage[<?php echo $i; ?>]' id='SAHCessPercentage_<?php echo $i; ?>' type='hidden' value='<?php echo $rate[2]; ?>' readonly <?php echo $disable; ?>/></td>
					<td class="col1"><input name='SAHCessValue[<?php echo $i; ?>]' id='SAHCessValue_<?php echo $i; ?>' type='text' value="<?php echo $item_detail_result['SAHCessValue']; ?>" readonly onfocus='calculateSAHCess(this.id)' <?php echo $disable; ?> /></td>
					<td class="col1"><input type='text' name='taxable_amt[<?php echo $i; ?>]' id='taxable_amt_<?php echo $i; ?>' onfocus='calculateTaxable(this.id)' value="<?php echo $item_detail_result['taxable_amt']; ?>" readonly <?php echo $disable; ?>/></td>
					<td class="col1"><input type='text' id='TotalSpecial_<?php echo $i; ?>' name='TotalAmount[<?php echo $i; ?>]' style='width:100px;' readonly onfocus='cal_grandtotal(this.id);'  value="<?php echo $item_detail_result['TotalAmount']; ?>"  /></td>
		
		<?php } ?>	
          </tr>
          <?php $i++; } ?>
        </tbody>
      </table>
	  </div>
	  </div>
    </div>
	</td>
  </tr>
  </table>
  <input type="hidden" name="Input" id="hiditemcount"  value="<?php echo $i; ?>" />
  <input type="hidden" name="Input" id="edit_cnt"  value="<?php echo $i; ?>" />
 <table border="0" width="100%" cellpadding="3" cellspacing="0">
      <tr>
        <td width="66%"></td>
        <td valign="top"><div id="basicamtdetails">
		 <?php if($query_edit_result['purchase_ord_Type']=='IO') { ?> 
          <table width="100%" border="0" cellspacing="0" cellpadding="3">
            <tr class="row1">
              <td width="40%" align="right"><strong>Basic Amount:</strong></td>
              <td><input name='basic_amt' id='total_item_amount' value="<?php echo $query_edit_result['total_amount']; ?>" readonly onfocus='cal_totalamount()' /></td>
            </tr>
           
            <tr class="row1">
              <td align="right"><strong>Insurance charges:</strong></td>
              <td><input type="text" name="insurancecharges" id="insurancecharges" value="<?php echo $query_edit_result['insurancecharges'];?>"   onblur="calsuroctamtipm(this.value)"  readonly="true"/>
                      <input name="insurancecharges_amt" type="text"  value="<?php echo $query_edit_result['insurancecharges_amt'];?>" onkeyup="reversecalsuroctamt(this.value);" id="insurancecharges_amt" <?php if($view_flag == 1){?> readonly="true" <?php } ?>/></td>
            </tr>
            <tr class="row1">
              <td align="right"><strong>Overseas Freight:</strong></td>
              <td><input type="text" name="overseasfrieght" id="overseasfrieght" value="<?php echo $query_edit_result['overseasfrieght'];?>" onblur="caloverfreight(this.value)"  readonly="true" />
                      <input name="overseasfrieght_amt" type="text" value="<?php echo $query_edit_result['overseasfrieght_amt'];?>" onkeyup="reversecaloverfreight(this.value);" id="overseasfrieght_amt"  readonly="true" /></td>
            </tr>
            <tr class="row1">
              <td align="right"><strong>Local Freight:</strong></td>
              <td><input type="text" name="localfreight" id="localfreight" value="<?php echo $query_edit_result['localfreight'];?>" onblur="callocalfreight(this.value)" readonly="true" />
                <input name="localfreight_amt" type="text"  value="<?php echo $query_edit_result['localfreight_amt'];?>" onkeyup="reversecallocalfreight(this.value);" id="localfreight_amt" readonly="true" /></td>
            </tr>
            <tr class="row1">
              <td align="right"><strong>Clearing &amp; Forwarding:</strong></td>
              <td><input type="text" name="clearingforwarding" id="clearingforwarding" value="<?php echo $query_edit_result['clearingforwarding'];?>" onblur="calclearingforwarding(this.value)" readonly="true" />
                      <input name="calclearingforwarding_amt" type="text" value="<?php echo $query_edit_result['calclearingforwarding_amt'];?>" onkeyup="reversecalclearingforwarding(this.value);" id="calclearingforwarding_amt"  readonly="true"/></td>
            </tr>
            <tr class="row1">
              <td align="right"><strong>Detetion Charges:</strong> </td>
              <td><input type="text" name="detetioncharges" id="detetioncharges" value="<?php echo $query_edit_result['detetioncharges'];?>" onblur="caldetetioncharges(this.value)"  readonly="true" />
                    <input name="detetioncharges_amt" type="text" value="<?php echo $query_edit_result['detetioncharges_amt'];?>" onkeyup="reversecaldetetioncharges(this.value);"   id="detetioncharges_amt"  readonly="true" /></td>
            </tr>
            <tr class="row1">
              <td align="right"><strong>Other charges:</strong></td>
              <td><input type="text" name="othercharges" id="othercharges"  value="<?php echo $query_edit_result['othercharges'];?>"  readonly="true" /></td>
            </tr>
            <tr class="row1">
              <td align="right"><strong>Grand Total:</strong></td>
              <td><input type="text" name="GrandTotal" value="<?php echo $query_edit_result['GrandTotal'];?>" id="GrandTotal" onfocus="cal_grandamountimp()"   readonly="true" /></td>
            </tr>
          </table> <?php } else { ?>
		  
		<table width='100%' border='0' cellspacing='0' cellpadding='3'>
		<tr class='row1'>
		<td width="40%" align="right"><strong>Basic Amount:</strong></td>
		<td><input type='text'  name='basic_amt' id='total_item_amount' value="<?php echo $query_edit_result['total_amount'];?>" readonly onfocus='cal_totalamount()' /></td>
		</tr>
		<tr class='row1'>
        <td align="right"><strong>Pkg Charges:</strong></td>
        <td><input type='text' name='pkg_per' id='pkg_perc' value="<?php echo $query_edit_result['pkg_per'];?>" style='width:30%; float:left; margin-right:2px;' onkeyup='calcPackaging(this.value)' /><input name='pkg_charges' id='pkg_charges1' value="<?php echo $query_edit_result['pkg_charges'];?>" style='width:67%; float:left;' type='text'/></td>
        </tr>
        <tr class='row1'>
        <td align="right"><strong>Vat/Cst(discription):</strong></td>
		<?php 
		$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
		$Taxresult=DB_query($Taxsql,$db);
		?>
        <td><select id='taxname' name='vatcst' onchange='tax_rate1(this.value)'>
	    <option value='0'>---Select---</option>
		<?php
		while($Taxmyrow=DB_fetch_array($Taxresult)){
			$p = "";
			if($query_edit_result['vatcst'] == $Taxmyrow['salestax_id'])
				$p = "selected";
		?>
        <option  value="<?php echo $Taxmyrow['salestax_id']; ?>" <?php echo $p; ?> ><?php echo $Taxmyrow['tax_code'].'---'.$Taxmyrow['taxrate'].'%' ;?></option>
        <?php 
		}
		?>
        </select></td>
        </tr>
        <tr class='row1'>
        <td align="right"><strong>Tax Value:</strong></td>
        <td><div id='taxval'><input type='text' name='taxvalue' id='taxvalue' value="<?php echo $query_edit_result['vatcstvalue'];?>" readonly='true'/>
        </div></td>
        </tr>
     	<tr class='row1'>
        <td align="right"><strong>Surcharge Amount:</strong></td>
        <td><input type='text' name='surcharge_per' id='sur_oct_per' value="<?php echo $query_edit_result['surcharge_per'];?>" style='width:30%; float:left; margin-right:2px;' onchange='calsuroctamt(this.value)'/><input name='surcharge_amt' type='text' id='sur_oct_amt' value="<?php echo $query_edit_result['surcharge_amt'];?>" style='width:67%; float:left;' /></td>
        </tr>
        <tr class='row1'>
        <td align="right"><strong>Freight:</strong></td>
        <td><input type='text' name='Freight' id='TotalCharge' value="<?php echo $query_edit_result['Freight'];?>"/></td>
        </tr>
        <tr class='row1'>      
		<td align="right"><strong>Additional Charges:</strong></td>
        <td><input name='add_charges' id='additionalCharges' type='text' value="<?php echo $query_edit_result['add_charges'];?>" /></td>
        </tr>
				
        <tr class='row1'>
		<td align="right"><strong>Grand Total:</strong></td>
        <td><input type='text' name='GrandTotal' id='GrandTotal' onfocus='cal_grandamount()' value="<?php echo $query_edit_result['GrandTotal'];?>" /><input type='hidden'  id='orig_grand_tot' /></td>
        </tr>
        <tr class="row1">
        <td align="right"><strong>Round Off:</strong></td>
		<td><select name='round_off' id='round_off' style='height:20px' onchange='calcRounded(this.value)'>
				  <option value=''>None</option>
				  <option value='+'>+</option>
				  <option value='-'>-</option>
				  </select></td>
    	</tr>
		</table>
		  <?php } ?>
        </div></td>
      </tr>
    </table>
  <?php if(!isset($_REQUEST['modify'])) { ?>
  
  <p align="center"><input name="Update" type="submit" value="Generate Direct Order" class="search"  onclick="return validate();"/></p>
  <?php } ?>

</form>
 
 </div>
 </div>
 
<script language="JavaScript">


function checkvalidate()
{
	
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del=document.getElementById("delivery_date").value;	
if(del<datedat)
{
alert("Delivery  Date Not less then current  Date");
//document.getElementById("delivery_date").value='';
document.getElementById("delivery_date").focus;	
return false;	
}


}
function checktilldate()
{
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}	
var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del1=document.getElementById("valid_till").value;	
if(del1<datedat)
{
alert("Valid Till Date Not less then current  Date");
//document.getElementById("valid_till").value='';
document.getElementById("valid_till").focus;	
return false;	
}	
	
	
}	
	
	
	
	
function validate()
{//
//var curr_date2='';	
//var curr_month2='';
//var d = new Date();
////alert(d.format("m/dd/yy"));
//var curr_date = d.getDate();
//var curr_month1 = d.getMonth();
//var curr_year = d.getFullYear();
//var curr_month=curr_month1+1;
//var t=curr_month;
//var d=curr_date;

//if(t!=10 || t!=11 ||t!=12 )
//{
// curr_month2="0" + curr_month;	
//}
//else
//{
// curr_month2=curr_month;	
//}
//if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
//{
// curr_date2="0" + curr_date;		
//}
//else
//{
// curr_date2=curr_date;		
//}
//
//
//var datedat=(curr_date2 + "/" + curr_month2 
//+ "/" + curr_year);
//
//if(document.getElementById("delivery_place1").value=='')
//{
//alert("Must Enter Delivery Place");
//document.getElementById("delivery_place1").focus();
//return false;	
//}
//if(document.getElementById("delivery_date").value=='')
//{
//alert("Must Enter Delivery Date");
//document.getElementById("delivery_date").focus();
//return false;	
//}
//if(document.getElementById("delivery_date").value!='')
//{
//
//var del=document.getElementById("delivery_date").value;	
//}
//if(del<datedat)
//{
//alert("Delivery  Date Not less then current  Date");
//document.getElementById("delivery_date").focus();	
//return false;	
//}
//if(document.getElementById("delivery_time").value=='')
//{
//alert("Must Enter Delivery Time");
//document.getElementById("delivery_time").focus();
//return false;	
//}
//if(document.getElementById("contact_person").value=='')
//{
//alert("Must Enter Contact Person Name");
//document.getElementById("contact_person").focus();
//return false;	
//}
//var del1=document.getElementById("valid_till").value;	
//if(del1<datedat)
//{
//alert("Valid Till Date Not less then current  Date");
////document.getElementById("valid_till").value='';
//document.getElementById("valid_till").focus;	
//return false;	
//}	
//return true;		
}	
	
function showdata(str)
{
if (str=='')
  {
  document.getElementById("divdata").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("divdata").style.display='block';
    document.getElementById("divdata").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","geteditdatapo.php?site="+str,true);
xmlhttp.send();
}	








function ship_data()
{

	if(document.getElementById("shipping_data").checked==true)
	{
		document.getElementById('Shipping_address').value = document.getElementById('billing_Address').value;
		document.getElementById('shipping_city').value = document.getElementById('billing_city').value;
		document.getElementById('shipping_state').value = document.getElementById('billing_state').value;
		document.getElementById('shipping_country').value = document.getElementById('billing_country').value;
		document.getElementById('shipping_state1').value = document.getElementById('billing_state1').value;
		document.getElementById('shipping_country1').value = document.getElementById('billing_country1').value;
		document.getElementById('Shipping_zipcode').value = document.getElementById('zipcode').value;
		
	}else{
		document.getElementById('Shipping_address').value = '';
		document.getElementById('shipping_state').value = '';
		document.getElementById('shipping_city').value = '';
		document.getElementById('shipping_country').value = '';
		document.getElementById('shipping_state1').value = '';
		document.getElementById('shipping_country1').value = '';
		document.getElementById('Shipping_zipcode').value='';
	}
}





function cal_totalamount()
{
	//alert("shailesh");
	//var firstrow=document.getElementById("TotalSpecial").value;
	//if(firstrow==''){firstrow=0;}
	var total=0;
	var t=document.getElementById("hiditemcount").value;
	//alert(t);
	for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("TotalSpecial_"+i).value);
		//alert(amt);
		total=parseFloat(total)+amt;	
	}	
	var fintotal=parseFloat(total);
	document.getElementById("total_item_amount").value=fintotal.toFixed(2);	
	
	
var hdcnt=document.getElementById("hiditemcount").value;
	var flag=0;
	var flag1=0;
	if(document.getElementById("cuntomDuty_Flag").value==1)
	{
		flag=1;
	}
	if(hdcnt!='')
	{
		for(var j=0;j<hdcnt;j++)
		{
			if(document.getElementById("cuntomDuty_Flag_"+j).value==1)
			{
				flag1=1;
			}
		}
	}	
	if(flag==1 || flag1==1)
	{
		//document.getElementById("CustomDuty").disabled=true;
	}
	else
	{
		document.getElementById("CustomDuty").disabled=false;
	}

}




function cal_totalamountwithduty()
{
	var hdcnt=document.getElementById("hiditemcount").value;
	var chka=document.getElementById("CustomDuty").value;
	if(chka==0)
	{
		var total=0;
		amtone=parseFloat(document.getElementById("CustomDutyAmt").value);
		for(var j=1;j<=hdcnt;j++)
		{
			if(document.getElementById("CustomDutyAmt_"+j).value!='')
			{
				var amt=parseFloat(document.getElementById("CustomDutyAmt_"+j).value);
				total=parseFloat(total)+amt;	
			}
			else
			{
				total=0;
			}
		}
		total=total+amtone;
		document.getElementById("custondutyval").value=total.toFixed(2);		
	}
	else
	{
		var basic=document.getElementById("total_item_amount").value;
		var rate=document.getElementById("rateval").value;
		if(basic==''){basic=0;}
		var calexc=(basic*rate)/100;
		document.getElementById("custondutyval").value=calexc.toFixed(2);	
		
	}
}




function calsuroctamtipm(str)
{
	var amt=parseFloat(document.getElementById("total_item_amount").value); 
	var amount=(amt*str)/100;
	document.getElementById("insurancecharges_amt").value=amount.toFixed(2);	
}

function reversecalsuroctamt(str)
{ 
	var amt=parseFloat(document.getElementById("total_item_amount").value); 
	var amount=(100*str)/amt;
	document.getElementById("insurancecharges").value=amount.toFixed(2);	
}
 
function caloverfreight(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("overseasfrieght_amt").value=amount.toFixed(2);	
}

function reversecaloverfreight(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value);  
var amount=(100*str)/amt;
document.getElementById("overseasfrieght").value=amount.toFixed(2);	
}

function callocalfreight(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("localfreight_amt").value=amount.toFixed(2);	
}

function reversecallocalfreight(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var per=parseFloat(document.getElementById("localfreight").value); 
var amount=(100*str)/amt;
 document.getElementById("localfreight").value=amount.toFixed(2);	
}


function calclearingforwarding(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("calclearingforwarding_amt").value=amount.toFixed(2);	
}

function reversecalclearingforwarding(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var per=parseFloat(document.getElementById("clearingforwarding").value); 
var amount=(100*str)/amt;
 document.getElementById("clearingforwarding").value=amount.toFixed(2);	
}

function caldetetioncharges(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("detetioncharges_amt").value=amount.toFixed(2);	
}

function reversecaldetetioncharges(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var per=parseFloat(document.getElementById("detetioncharges").value); 
var amount=(100*str)/amt;
 document.getElementById("detetioncharges").value=amount.toFixed(2);	
}





function claculateExcisetotal(id,str)
{  
		var b=document.getElementById("total_item_amount").value;	 
	 
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
				var data=xmlhttp.responseText.split("__"); 
			 	document.getElementById("rateval").value=data[0];
				document.getElementById("custondutyval").value=data[1];
    		}
  		}
		xmlhttp.open("GET","ajax_calculate_customduty.php?quotTaxId="+str+"&data="+b,true);
		xmlhttp.send();


}


function calvatcst()
{
	var tota_amt=document.getElementById("total_item_amount").value;
	
	var vatperc=document.getElementById("vat_cst_per").value;
	
	var cal=(tota_amt*vatperc)/100;
	
	document.getElementById("VatcstVal").value=cal.toFixed(2);
	
}

function calsurchrg()
{
	var amt=parseFloat(document.getElementById("VatcstVal").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 calgrandTotal()
{
	var total=document.getElementById("total_item_amount").value;
	var PkgChrg=document.getElementById("packagingCharges").value;
	var VatAmt=document.getElementById("VatcstVal").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var freight=document.getElementById("TotalCharge").value;
	var additionalCharges=document.getElementById("additionalCharges").value;
		
	if(total==''){total=0;}
	if(PkgChrg==''){PkgChrg=0;}
	if(VatAmt==''){VatAmt=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(freight==''){freight=0;}
	if(additionalCharges==''){additionalCharges=0;}
	grandtotal=parseFloat(total)+parseFloat(PkgChrg)+parseFloat(VatAmt)+parseFloat(sur_oct_amt)+parseFloat(freight)+parseFloat(additionalCharges);
	document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
}


function GetSatateCountry(str)
{
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
 	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		var data=xmlhttp.responseText.split("__");
    	document.getElementById("billing_state").value=data[0];
		document.getElementById("billing_country").value=data[1];
		document.getElementById("billing_state1").value=data[2];
		document.getElementById("billing_country1").value=data[3];
    }
  	}
	xmlhttp.open("GET","SateCountryName.php?CityId="+str,true);
	xmlhttp.send();
}


function GetSatateCountry1(str)
{
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
 	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		var data=xmlhttp.responseText.split("__");
    	document.getElementById("shipping_state").value=data[0];
		document.getElementById("shipping_country").value=data[1];
		document.getElementById("shipping_state1").value=data[2];
		document.getElementById("shipping_country1").value=data[3];
    }
  	}
	xmlhttp.open("GET","SateCountryName.php?CityId="+str,true);
	xmlhttp.send();
}

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


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




function cal_grandamountimp()
{
	
	var total=document.getElementById("total_item_amount").value;
	var cdis_amt=0;
	var insurancecharges_amt=document.getElementById("insurancecharges_amt").value;
	var overseasfrieght_amt=document.getElementById("overseasfrieght_amt").value;
	var localfreight_amt=document.getElementById("localfreight_amt").value;
	var calclearingforwarding_amt=document.getElementById("calclearingforwarding_amt").value;	
	var detetioncharges_amt=document.getElementById("detetioncharges_amt").value;	
	var othercharges=document.getElementById("othercharges").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;}
	 
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(cdis_amt)+parseFloat(insurancecharges_amt)+parseFloat(overseasfrieght_amt)+parseFloat(localfreight_amt)+parseFloat(calclearingforwarding_amt)+parseFloat(detetioncharges_amt)+parseFloat(othercharges);
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	

}

function addRow(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	//alert(rowCount);
	if(document.getElementById("hiditemcount").value=='')
	r =rowCount+1;
	else
	{
	var t=document.getElementById("edit_cnt").value;
	var t1=document.getElementById("hiditemcount").value;
	r=parseInt(t1);
	r1=parseInt(t1)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=r1;
	document.getElementById("edit_cnt").value=r1;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	var newcell = row.insertCell(i);
	if(i==0)
	newcell.className='headerl_1';	
	else if(i==1)
	newcell.className='headerl_2';
	else if(i==2)
	newcell.className='headerl_3';
	else if(i==3)
	newcell.className='headerl_4';
	else
	newcell.className='col1';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+r;
	
		var nt=newcell.childNodes[0].name.split("[");
		if(nt[1]!=undefined)
		{
		var nt1=nt[1].split("]");
		var name=nt[0]+'['+r+']'+'['+nt[2];
		}
		else
		{
		var name=nt[0]+'['+r+']';
		} 
		newcell.childNodes[0].name = name;
	
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+r;
	var nt=newcell.childNodes[0].name.split("[");
		if(nt[1]!=undefined)
		{
		var nt1=nt[1].split("]");
		var name=nt[0]+'['+r+']'+'['+nt[2];
		}
		else
		{
		var name=nt[0]+'['+r+']';
		} 
		newcell.childNodes[0].name = name;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+r;
	var nt=newcell.childNodes[0].name.split("[");
		if(nt[1]!=undefined)
		{
		var nt1=nt[1].split("]");
		var name=nt[0]+'['+r+']'+'['+nt[2];
		}
		else
		{
		var name=nt[0]+'['+r+']';
		} 
		newcell.childNodes[0].name = name;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+r;
	var nt=newcell.childNodes[0].name.split("[");
		if(nt[1]!=undefined)
		{
		var nt1=nt[1].split("]");
		var name=nt[0]+'['+r+']'+'['+nt[2];
		}
		else
		{
		var name=nt[0]+'['+r+']';
		} 
		newcell.childNodes[0].name = name;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+r;
	var nt=newcell.childNodes[0].name.split("[");
		if(nt[1]!=undefined)
		{
		var nt1=nt[1].split("]");
		var name=nt[0]+'['+r+']'+'['+nt[2];
		}
		else
		{
		var name=nt[0]+'['+r+']';
		} 
		newcell.childNodes[0].name = name;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
		//document.getElementById(countid).innerHTML=rowCount;

	}
	

function deleteRow(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
		document.getElementById("hiditemcount").value=parseInt(rowCount);	
		document.getElementById("edit_cnt").value=parseInt(rowCount);			
		}
		catch(e) 
		{
			alert(e);
		}

}


function getItemsList(id,code,shade,desc,netrate,mrprate,stock,ctr)
{
	var dup='empty';
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt=='')
		{var counter=1;} 
	else if(edit_cnt>itemcount)
		{var counter=edit_cnt;
		var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
		
	if(document.getElementById("row_id_"+ctr).checked==true)
	{
		  
			for(var i=counter; i<itemcount; i++)
			{	
					
				for(var j=0; j<itemcount; j++)
			    {
				if(document.getElementById('itemid_'+j))
					{	
				if(document.getElementById('itemid_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
				}
			}	
				if(dup=='empty')
				{	
				var data= addRow('dataTable');
						
					if(document.getElementById('itemid_'+i))
					{				 
					if(document.getElementById('itemid_'+i).value=='')
					{				   		
						document.getElementById('itemid_'+i).value = id;
						document.getElementById('itemcode_'+i).value = code;
						document.getElementById('itemname_'+i).value = shade;
						document.getElementById('total_stock_'+i).value = stock;
						document.getElementById('itemdesc_'+i).value = desc;	
						document.getElementById('price_'+i).value = netrate;
						document.getElementById('mrpper_'+i).value = mrprate;	
					
						break;
					}
					}
					else
					{
						continue;
					}
				}
			}
		
	}
	else
	{
		
		
			for(var i=counter; i<itemcount; i++)
			{
			    if(document.getElementById('itemid_'+i))
				{
				if(document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
				   document.getElementById('itemid_'+i).value = '';
					document.getElementById('itemcode_'+i).value = '';
					document.getElementById('itemname_'+i).value = '';
					document.getElementById('total_stock_'+i).value='';
					document.getElementById('itemdesc_'+i).value = '';	
					document.getElementById('price_'+i).value = '';
					document.getElementById('mrpper_'+i).value = '';
				}
				}
			}
		}
	
	
	}


function calcdisamt(str,id)
{
if(str!='' && str!=0)
{
id1=id.split("_");
	i=id1[1];
	
if(document.getElementById("Quantity_"+i).value!='')
var qty=document.getElementById("Quantity_"+i).value;
else qty=0;
var totalvalue=document.getElementById("totalValue_"+i).value;
var totaldis=parseFloat(qty)/parseFloat(str);
var distype=document.getElementById("PerAmo_"+i).value;
				if(distype=='PercentAmt')
				{
								var totalpercentage=parseFloat(document.getElementById("Discount_"+i).value)*parseFloat(totaldis);
								
								var totaldisountamt1=(parseFloat(totalvalue)*parseFloat(totalpercentage))/100;
								
								var totaldiscountamt=parseFloat(totalvalue)-parseFloat(totaldisountamt1);
								
								document.getElementById("perc_"+i).value=totaldisountamt1.toFixed(2);
								document.getElementById("NetRate_"+i).value=totaldiscountamt.toFixed(2);
								document.getElementById("basic_"+i).value=totaldiscountamt.toFixed(2);
				}
					else
					{
					
							var totalpercentage=parseFloat(document.getElementById("Discount_"+i).value)*parseFloat(totaldis);
							
							var totaldisountamt1=parseFloat(totalpercentage);
							
							var totaldiscountamt=parseFloat(totalvalue)-parseFloat(totaldisountamt1);
							
							document.getElementById("perc_"+i).value=totaldisountamt1.toFixed(2);
							document.getElementById("NetRate_"+i).value=totaldiscountamt.toFixed(2);
							document.getElementById("basic_"+i).value=totaldiscountamt.toFixed(2);
							
					
					
					}



}



}






</script>
<?php } 

?>