<link rel="stylesheet" type="text/css" href="css/professional/table_frize.css">
<?php 	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
?>
<div id="PickedItems" style="display:none"></div>
<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" href="/css/jquery.ui.all.css">
<script src="js1/jquery.ui.widget.js"></script>
<script src="js1/jquery.ui.tabs.js"></script>
<script type="text/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("sitecode").value;
		
		if(document.getElementById("showw").value=='')
			{
			alert("Must Select Duty Type First");
			return false;
			}
		else
		{	
		//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 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","ajax_pick_items.php?site="+str,true);
	xmlhttp.send();
}



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('count1').value;
	//alert(edit_cnt);
	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;
	}
	
	//alert(counter);
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
	
	if(document.getElementById("row_id_"+ctr).checked==true)
	{
		if(document.getElementById('itemid').value=='')
		{
			if(edit_cnt=='')
			{
				var counter=0;
			}
			for(var j=0; j<counter; j++)
			{
				if(document.getElementById('itemid1_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
			}
			if(dup=='empty')
			{	
				var data=addRow('dataTable');
				
				document.getElementById('itemid').value = id;
				document.getElementById('itemcode').value = code;
				document.getElementById('itemname').value = shade;
				document.getElementById('total_stock').value = stock;
				document.getElementById('itemdesc').value = desc;	
				//document.getElementById('price').value = netrate;
				//document.getElementById('mrpper').value = mrprate;
				
			}
		}
		else
		{
			for(var i=counter; i<=itemcount; i++)
			{	
				if(edit_cnt=='')
				{
					var counter=0;
				}
				for(var j=0; j<counter; j++)
				{
					if(document.getElementById('itemid1_'+j).value==id)
					{
						alert("Duplicate Value"); 
						document.getElementById("row_id_"+ctr).checked=false;
						var dup = "dup";
						break;
					}
				}
				if(document.getElementById('itemid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				if(document.getElementById('itemid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				if(dup=='empty')
				{				
					if(document.getElementById('itemid_'+i).value=='')
					{	var data= addRow('dataTable');
						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;
						break;
					}
					else
					{
						continue;
					}
				}
			}
		}
	}


function addRow(tableID) 
{
   
  
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newCount=parseInt(rowCount);
	var newcell = row.insertCell(i);
	if(i==0)
	newcell.className='headerpartcol1';	
	else if(i==1)
	newcell.className='headerpartcol2';
	else if(i==2)
	newcell.className='headerpartcol3';
	else if(i==3)
	newcell.className='headerpartcol4';
	else if(i==4)
	newcell.className='headerpartcol5';
	else if(i==5)
	newcell.className='headerpartcol6';
	else
	newcell.className='colls1';
	
	//newcell.style.background='#e7e7e7';
	
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	
	switch(newcell.childNodes[0].type) 
	{
	
	case "text":	
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	//newcell.childNodes[0].name = newcell.childNodes[0].name;
	var t=newcell.childNodes[0].name;
	var ns=t.split("[");
	newcell.childNodes[0].name=ns[0]+'['+newCount+']';
	break;
	
	
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	var t=newcell.childNodes[0].name;
	var ns=t.split("[");
	newcell.childNodes[0].name=ns[0]+'['+newCount+']';
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	var t=newcell.childNodes[0].name;
	var ns=t.split("[");
	newcell.childNodes[0].name=ns[0]+'['+newCount+']';
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	var t=newcell.childNodes[0].name;
	var ns=t.split("[");
	newcell.childNodes[0].name=ns[0]+'['+newCount+']';
	break;
	case "select-one":	
	
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	var t=newcell.childNodes[0].name;
	var ns=t.split("[");
	newcell.childNodes[0].name=ns[0]+'['+newCount+']';
	
	break;	
	}
		//document.getElementById("stock_perunit_"+newCount).value=1;
	}
	
	
}
}
</script>
<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
</script>
<script type="text/javascript">
function calgrandtotalImp(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var totalPrice=document.getElementById("totalPrice").value;
		document.getElementById("TotalSpecial").value=totalPrice;
	}
	else
	{
		var totalPrice=document.getElementById("totalPrice_"+i).value;
		document.getElementById("TotalSpecial_"+i).value=totalPrice;
		
	}	
}
function cal_grandtotalImp(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var totalPrice=document.getElementById("totalPrice").value;
      if(document.getElementById("ex_amount").value!='')
		var TotalSpecial=document.getElementById("ex_amount").value;
      else
       var TotalSpecial=0;
		var grand_tot1 =parseFloat(totalPrice)+parseFloat(TotalSpecial);
		var grand_tot = grand_tot1.toFixed(2);
		
		document.getElementById("TotalSpecial").value=grand_tot;
	}
	else
	{
		var totalPrice=document.getElementById("totalPrice_"+i).value;
       if(document.getElementById("ex_amount_"+i).value!='')
		var TotalSpecial=document.getElementById("ex_amount").value;
      else
       var TotalSpecial=0;
	
		var grand_tot1 =parseFloat(totalPrice)+parseFloat(TotalSpecial);
		var grand_tot = grand_tot1.toFixed(2);
		document.getElementById("TotalSpecial_"+i).value=grand_tot;
		
	}	
}


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("totalPrice").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("totalPrice_"+i).value=Total.toFixed(2);
	}
} 

function validation()
{
if(document.getElementById('Site').value=='0')
{alert('Please Select a branch');
document.getElementById('Site').focus();
return false;
}
if(document.getElementById('dealer').value=='')
{alert('Please Select a Delear');
document.getElementById('dealer').focus();
return false;
}
	
if(document.getElementById("TelephonicDate").value=='')
{
alert('Please enter the memo date');
document.getElementById('TelephonicDate').focus();
return false;
}

if(document.getElementById('po_no').value==''){
alert('PO No cannot be empty');
document.getElementById('po_no').focus();
return false;
}
	
if(document.getElementById('Client').value=='0'){
alert('Please choose a client');
document.getElementById('Client').focus();
return false;}
	
if(document.getElementById('Sale_Key_Exec').value=='0'){
alert('Please choose a Sales Executive');
document.getElementById('Sale_Key_Exec').focus();
return false;}


if(document.getElementById('PODate').value==''){
alert('Please enter PO Date');
document.getElementById('PODate').focus();
return false;
}

if(document.getElementById('cat').value=='0'){
alert('Please choose a category');
document.getElementById('cat').focus();
return false;}		
		
if(document.getElementById('basicAmount').value==''){
alert('Basic Amount cannot be empty');
document.getElementById('basicAmount').focus();
return false;
}
	
if(document.getElementById('taxableAmount').value==''){
alert('Taxable AMount cannot be empty');
document.getElementById('taxableAmount').focus();
return false;
}

if(document.getElementById('grandTotal').value==''){
alert('Grand Total cannot be empty');
document.getElementById('grandTotal').focus();
return false;
}
return true;
}	

function getContactName(str)
{
	
if(str.length==0)
{
	document.getElementById("ContactName").innerHTML="";
	return;
	
}
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	  	
		document.getElementById("ContactName").innerHTML=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","getContact.php?Client="+str,true);
xmlhttp.send();	
	
	
} 
function getPhoneNo(str)
{
	
if(str.length==0)
{
	document.getElementById("PhoneNo").innerHTML="";
	return;
	
}
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	  	
		document.getElementById("PhoneNo").innerHTML=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","getPhone.php?Contact="+str,true);
xmlhttp.send();	
	
	
} 


/****************************************************/

function getdata1(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("ItemListDiv").innerHTML=data[0];
	//document.getElementById("subcategory1").innerHTML=data[0];
	}
	}
	xmlhttp.open("GET","ajax_item_list_ajax.php?site="+str,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	

function getdata2(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("ItemListDiv").innerHTML=data[0];
	//document.getElementById("subcategory1").innerHTML=data[0];
	}
	}
	xmlhttp.open("GET","ajax_item_list_ajax.php?q="+str,true);
	xmlhttp.send();
	
}








/******************************************************/








function openPopupProfile2()
{
	window.open("TelephonicItems.php?modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>");
}
function calculateTotalAmt(val,id)
{
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			var qty=document.getElementById("qty_"+i).value;
			var tot_amt=qty*val;
			document.getElementById("totalamt_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			var qty=document.getElementById("qty").value;
			var tot_amt=qty*val;
			document.getElementById("totalamt").value=tot_amt.toFixed(2);
		}
}

function calassprice(val,id)
{
	
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price").value=tot_amt.toFixed(2);
		}
}

function calass_amount(id)
{
	var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{ 
			
			var qty=document.getElementById("qty_"+i).value;
			var ass_value=document.getElementById("ass_price_"+i).value;
			var tot_amt=ass_value*qty;
			document.getElementById("totalassamt_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var qty=document.getElementById("qty").value;
			var ass_value=document.getElementById("ass_price").value;
			var tot_amt=ass_value*qty;
			
			document.getElementById("totalassamt").value=tot_amt.toFixed(2);
		}
	
}

function calculateEDAmt(i)
{

    
 		
	var EDRate = document.getElementById("EDRate_"+i).value;
	
	if(EDRate=='0')
	{
		
		//var stock_price = document.getElementById("stock_qty_"+i).value;
		//alert(stock_price);
		document.getElementById("EDAmt_"+i).value='0.00';
		
	}
	else{
		
	
	 
 	var stock_price = document.getElementById("stock_qty_"+i).value;
 
	var EDAmt=((parseFloat(EDRate)*parseFloat(stock_price) )/100);
 	 document.getElementById("EDAmt_"+i).value=EDAmt.toFixed(2);
 	}
	 
 
}
function calculateBasic1()
{
	var totalBasic=0;
	var first_row=document.getElementById("TotalSpecial").value;
	if(first_row != 0)
	{
		totalBasic = first_row;
	}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt);
	for(var i=1;i<newcount;i++)
	{
	 	var totalBasic1=document.getElementById("TotalSpecial_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	  document.getElementById("basicAmount1").value=totalBasic;
	    var hdcnt=cnt;

	var flag=0;
	var flag1=0;
	var totaledrate1=0;
	if(document.getElementById("exdrate"))
	{
	if(document.getElementById("exdrate").value!=0)
	{
	flag=1;
	totaledrate1=document.getElementById("ex_amount").value;
	}
	}
	if(hdcnt!='')
	{
		for(var j=1;j<=hdcnt;j++)
		{ 
		    if(document.getElementById("exdrate_"+j))
			{
			if(document.getElementById("exdrate_"+j).value!=0)
			{
				flag1=1;
				var totaledrate=document.getElementById("ex_amount_"+j).value;
	        	var totaledrate1=(parseFloat(totaledrate)+parseFloat(totaledrate1)).toFixed(2);
				
			}
			}
			else
			{
			  var totaledrate=0;
	        	var totaledrate1=(parseFloat(totaledrate)+parseFloat(totaledrate1)).toFixed(2);
			}
		}
	}
	else
	{
	var totaledrate1=parseFloat(totaledrate1).toFixed(2);
	}
	
	

	if(flag==1 || flag1==1)
	{
		document.getElementById("EDRate").disabled=true;
		document.getElementById("totalDiscountedPrice").value=totaledrate1;
	}
	else
	{
		document.getElementById("EDRate").disabled=false;
		document.getElementById("totalDiscountedPrice").value='';
	}
}

function calculateBasic()
{
	var totalBasic=0;
	var first_row=document.getElementById("TotalSpecial").value;
	if(first_row != 0)
	{
		totalBasic = first_row;
	}
	
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt);
	for(var i=1;i<newcount;i++)
	{
	
	 	var totalBasic1=document.getElementById("TotalSpecial_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
		
		
		
	}
		
	  document.getElementById("basicAmount").value=totalBasic;
	  
	  
	
	  
	
}

function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("hiditemcount").value;
       for(var i=0;i<cnt;i++)
      {
 	    var totalDiscounted1=document.getElementById("EDAmt_"+i).value;
 	    
 	    var totalDiscounted=(parseFloat(totalDiscounted)+parseFloat(totalDiscounted1)).toFixed(2);
  	 }
	 if(totalDiscounted1!=='0')
	 {
 	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
	}
	else{
		var total=document.getElementById("basicAmount").value;
		
		var Edrate=document.getElementById("EDRate_"+i).value;
		var discountEdrate=((parseFloat(Edrate)*parseFloat(total) )/100);
		document.getElementById("totalDiscountedPrice").value=discountEdrate.toFixed(2);
	}
}
function calculateECess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue1").value=total.toFixed(2);
}

function calculateECess()
{
	var exciseValue=document.getElementById("basicAmount").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}

function calculateSAHCess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("SAHCessValue1").value=total.toFixed(2);
}


function calculateSAHCess()
{
	var exciseValue=document.getElementById("basicAmount").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}

function calculateTaxable1()
{
	var Basic=document.getElementById("basicAmount1").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	
	var ECessValue=document.getElementById("ECessValue1").value;
	var SAHCessValue=document.getElementById("SAHCessValue1").value;

	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(Basic);
	document.getElementById("taxableAmount1").value=TOTAL.toFixed(2);
}


function calculateTaxable()
{
	var Basic=document.getElementById("basicAmount").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	
	
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(Basic);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}

function calculateVATCST1(str)
{
   // alert(str);
	var basicAmount = document.getElementById("taxableAmount1").value;
	if (str.length==0)
		{
			document.getElementById("rate").innerHTML="";
			return;
		}
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				//alert(xmlhttp.responseText);
				document.getElementById("VATId1").innerHTML=xmlhttp.responseText;
			}
		}
		xmlhttp.open("GET","calculateExcise_one.php?salesId="+str+"&taxable="+basicAmount,true);
		xmlhttp.send();

}

function calculateVATCST(str)
{
	var basicAmount = document.getElementById("basicAmount").value;
	//alert(basicAmount);
	if (str.length==0)
  		{
  			document.getElementById("rate").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
				//alert(xmlhttp.responseText);
    			document.getElementById("VATId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?salesId="+str+"&taxable="+basicAmount,true);
		xmlhttp.send();
}
function calculateGrand1()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount1").value;
	var c=document.getElementById("VatCstValue1").value;
	if(b==''){b=0;}
	if(c==''){c=0;}
	
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal1").value=GRAND.toFixed(2);
}
function calculateGrand()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	if(b==''){b=0;}
	if(c==''){c=0;}
	
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	
}
 </script>
<script type="text/javascript">
function showexiceduty(dutytype)
{
	if(dutytype == "item_wise")
	{
		$('#itemwiseshow').show();
		$('#itemwiseshowconsolidate').hide();
	}
	if(dutytype == "consolidate")
	{
		$('#itemwiseshowconsolidate').show();
		$('#itemwiseshow').hide();
	}
	/*if(dutytype=="")
	{
		$('#ExiceDutyDiv').show();
		$('.consolidateshow').show();
	}
	
	if(dutytype == "consolidate")
	{
		//alert("consolidate");
		$('.consolidateshow').hide();
	}*/
		
}
</script>
<?php 
if(isset($_POST['Save']))
{
//print_r($_REQUEST);die;
	$startYr = explode('-', $_SESSION['financialYrStart']);
		$endYr = explode('-', $_SESSION['financialYrEnd']);
		$startYr[0];
		$endYr[0];
		$financial=substr($startYr[0],-2)."-".substr($endYr[0],-2); 
	 
	 
	 if($_SESSION['dealerid'])
	 {
	 	$prefSql="select prefix_code from prefix_tbl where prefix_name = 'Order Management'";
		$resultPrfx = DB_query($prefSql,$db);
		$Prefxrow=DB_Fetch_array($resultPrfx);
		$prefixcode=$Prefxrow['prefix_code'];
		
		 $sql="select orderNo from salesorder where branch = '".$_REQUEST['Site']."' and dealerid='0' and CompanyId='".$_SESSION['ACGCompanyId']."' and INSTR(`orderNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
		 
		$result = DB_query($sql,$db);
		$numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['orderNo']);
			 $maxval = $ExplBill[3]; 
		}
		else
		{$maxval=0;}
	 }
	 else
	 {
	 	$prefSql="select prefix_code from prefix_tbl where prefix_name = 'Order Management'";
		$resultPrfx = DB_query($prefSql,$db);
		$Prefxrow=DB_Fetch_array($resultPrfx);
		$prefixcode=$Prefxrow['prefix_code'];
		
		
		$sql="select orderNo from salesorder where branch = '".$_REQUEST['Site']."' and dealerid='0' and CompanyId='".$_SESSION['ACGCompanyId']."' and INSTR(`orderNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
		$result = DB_query($sql,$db);
		$numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['orderNo']);
			$maxval = $ExplBill[3];
		}
		else
		{$maxval=0;}
	 }
	 

		$strChar=$_REQUEST['Site']."/".$prefixcode."/".$financial."/";
		$strFinal = $maxval+1;
		$strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT); 
	
                                        $sql1="Insert into salesorder set
					branch='".$_REQUEST['sitecode']."', 
					orderDate='".FormatDateForSQL($_REQUEST['TelephonicDate'])."',
					orderNo='".$strBothFinal."', 
					client='".$_REQUEST['Client']."',
					Sale_Key_Exec='".$_REQUEST['Sale_Key_Exec']."',  
			        PORefNo='".$_REQUEST['PONo']."',  
					customerPODate='".FormatDateForSQL($_REQUEST['PODate'])."',  
			        SalesOrderType='Direct',
					DeliveryDate='".FormatDateForSQL($_REQUEST['DelieveryDate'])."',
					RoadPermit='".$_REQUEST['RoadPermit']."',
					Transport='".$_REQUEST['Transport']."',
					freight='".$_REQUEST['freight']."',
					PendingPayment='".$_REQUEST['PendingPayment']."', 
					TelStatus= '".$_REQUEST['Status']."',
					ContactPerson='".$_REQUEST['ContactPerson']."',
					basicAmount='".$_REQUEST['basicAmount']."',
					exciseDuty='".$_REQUEST['EDBillRate']."',
					TotalExciseValue='".$_REQUEST['totalDiscountedPrice']."',
					taxableAmount='".$_REQUEST['taxableAmount']."',
					ECessPercentage='".$_REQUEST['ECessPercentage']."',
					ECessId='".$_REQUEST['ECessID']."',
					ECessValue='".$_REQUEST['ECessValue']."',
					SHECessId='".$_REQUEST['SHECessId']."',
					VatCst='".$_REQUEST['VatCst']."',
					VatCstValue='".$_REQUEST['VatCstValue']."',
 			        SAHCessPercentage='".$_REQUEST['SAHCessPercentage']."',  
					SAHCessValue='".$_REQUEST['SAHCessValue']."',
					order_type='".$_REQUEST['dutytype']."',
					grandTotal='".$_REQUEST['grandTotal']."', 
					createdBy='".$_SESSION['UserID']."',
					CompanyId='".$_SESSION['ACGCompanyId']."',
                                        dealerid='".trim($_SESSION['dealerid'])."'
 				    ,cate='".$_REQUEST['cate']."' ";
					
					$result1=DB_query($sql1,$db);
	 				$SalesId=DB_Last_Insert_ID($db,'salesorder','id');
					if(isset($SalesId))
					{
						for($i=0;$i<count($_REQUEST['itemcode']);$i++)
						{
							if($_REQUEST['itemcode'][$i]!='')
							{
								$data_arr['masterId']=$SalesId;
								$data_arr['mst_itemid']=$_REQUEST['mst_itemid'][$i];
								$data_arr['Quantity']=$_REQUEST['Quantity'][$i];
								$data_arr['Rate']=$_REQUEST['Rate'][$i];
								$data_arr['Amount']=$_REQUEST['totalPrice'][$i];
								$data_arr['EDRate']=$_REQUEST['exdrate'][$i];
								$data_arr['EDAmt']=$_REQUEST['ex_amount'][$i];
								$data_arr['pricePer']=1;
								//$data_arr['mrp_unit']=$_REQUEST['mrp_per'][$i];
								//$data_arr['ass_price']=$_REQUEST['ass_price'][$i];
								$data_arr['total_ass_price']=$_REQUEST['TotalAmount'][$i];
								$data_arr['remarks']=$_REQUEST['remarks'][$i];
								$data_arr['ApprovalStatus']="1";
								$rowinsert= $s->RecordInsert('salesorder_details',$data_arr);
								if(!$rowinsert)
								{
								   die('Error'.DB_error());
								}
							}
						}
					}
					$s->pageLocation("index.php?route=CRM/ViewSalesOrder".$rurl);
					
}

?>
<div class="body_contain">
<h1><?php echo $title; ?></h1>
<div class="insideclass">
<div >
<div class="demo">
<div id="tabs">
<ul>
<li><a href="#tabs-1">Order Details</a></li>
<li><a href="#tabs-2">More Information</a></li>
</ul>
<div class="body_contain">
<div class="tab_div">
<form action="" method="post"  >
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%">Branch</td>
    <td width="20%"><select style="width:100%;" name="sitecode" id="sitecode"  onchange="showstorecode(this.value)">
<!--          <option value="">Select</option>-->
          <?php
			$SQL="Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
			$Res=DB_query($SQL,$db);
			while($Row=DB_fetch_array($Res))
			{
			?>
           		<option value="<?php echo $Row['loccode']?>" <?php echo($_SESSION['Site']==$Row['loccode'] ? 'selected':'');?> ><?php echo $Row['locationname']?></option>
           <?php  } ?>
         </select></td>
    <td width="13%">SOP No
      <label><font color="#FF0000">*</font></label></td>
    <td width="20%"><div id="orderid"> <input type="text" name="orderNo" id="orderNo" value="<?php  if($_REQUEST['orderNo']=='') echo "Auto Generated"; else $_REQUEST['orderNo'] ;?>" style="width:100%;" readonly=""></div></td>
    <td width="13%">Date
      <label><font color="#FF0000">*</font></label></td>
    <td><input type="text" readonly name="TelephonicDate" id="TelephonicDate" value="<?php if(isset($_SESSION['Telephonic'])){echo $_SESSION['TelephonicDate'];}else {echo date('d/m/Y');}?>" class="datepicker" style="width:100%;"></td>
  </tr>
  <tr class="row1">
    <td>Client</td>
    <td><?php 
	$ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and Site in('".$_SESSION['AssignedBranch']."') order by c_name ASC" ;?>
	  <select style="width:100%;" name="Client" id="Client" onchange="ShowDiv(this.value,'ContactName','getContact.php')">
        <option value="">Select</option>
        <?php 
			$ClientRes=DB_query($ClientSQL,$db);
			while($ClientRow=DB_fetch_array($ClientRes))
			{
		?>
        <option value="<?php echo $ClientRow['id']?>" <?php echo($_SESSION['Client']==$ClientRow['id']?'selected':'')?> ><?php echo $ClientRow['c_name']?></option>
        <?php  } ?>
      </select></td>
    <td>Contact</td>
    <td><?php 
	//$SQL="Select * from contact_information_master where master_code='".$_SESSION['Client']."'";
	$SQL="Select * from contact_information_master where master_code='".$_SESSION['Client']."'";
	?>
	<select style="width:100%;" name="ContactPerson" onchange="getPhoneNo(this.value)">
	<option value="0">Select</option>
	<?php
	
	$Res=DB_query($SQL,$db);
	while($Row=DB_fetch_array($Res))
	{
	?>
	<option value="<?php echo $Row['id']?>" <?php echo($_SESSION['ContactPerson']==$Row['id']?'selected':'')?>><?php echo $Row['person']?></option>
	<?php  } ?>
	</select></td>
    <td>Mobile No.</td>
    <td><div id="PhoneNo">
	<input type="text" style="width:100%;" name="Telephone" id="Telephone" value="<?php echo $_SESSION['Telephone']?>"  >
	</div></td>
  </tr>
  <tr class="row1">
    <td>Address 1</td>
    <td><input type="text"  style="width:100%;" name="Address1"  value="<?php echo $_SESSION['Address1']?>"/></td>
    <td>Address 2</td>
    <td><input type="text" name="Address2" id="Address2" style="width:100%;" value="<?php echo $_SESSION['Address2']?>"  ></td>
    <td>Address 3</td>
    <td><input type="text" name="Address3" id="Address3" style="width:100%;" value="<?php echo $_SESSION['Address3']?>"  ></td>
  </tr>
  <tr class="row1">
    <td>Client P.O. No.
	<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" name="PONo" id="po_no" style="width:100%;"  value="<?php echo $_REQUEST['PONo']?>" /></td>
    <td>P.O. Date<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" readonly name="PODate" id="PODate" style="width:100%;" class="datepicker"  value="<?php echo $_SESSION['PODate']?>"  ></td>
    <td>Delivery Date</td>
    <td><input type="text" readonly name="DelieveryDate" id="DelieveryDate" style="width:100%;" class="datepicker" value="<?php echo $_SESSION['DelieveryDate']?>"   ></td>
  </tr>
  <tr class="row1">
    <td>Transport</td>
    <td><select style="width:100%;" name="Transport">
	<option value="0">Select</option>
	<?php
        if($_SESSION['dealerid'])
        {
	$SQL="Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='".$_SESSION['dealerid']."'";
        }
 else {
     $SQL="Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='0'";
 }
	$Res=DB_query($SQL,$db);
	while($Row=DB_fetch_array($Res))
	{					
	?>
	<option value="<?php echo $Row['id']?>" <?php echo($_SESSION['Transport']==$Row['id']?'selected':'' );?>  ><?php echo $Row['TransportName']?></option>
	<?php  } ?>
	</select></td>
    <td>Road Permit</td>
    <td><input name="RoadPermit" type="text"   style="width:100%;"   value="<?php echo $_SESSION['RoadPermit']?>"  /></td>
    <td>Freight Type</td>
    <td><select style="width:100%;" name="freight">
	<option value="0">Select</option>
	<option value="Paid">Paid</option>
	<option value="topay">To Pay</option>
	<option value="Nill">Nill</option>
	</select></td>
  </tr>
  <tr class="row1">
    <td>Category</td>
    <td><select name="cate" id="cat" style="width:100%;">
	<option value="0">Select</option>
	<option value="Urgent"<?php if($_SESSION['cate']=='Urgent'){ ?> selected="selected" <?php } ?> >Urgent</option>
	<option value="Normal" <?php if($_SESSION['cate']=='Normal'){ ?> selected="selected" <?php } ?> >Normal</option>
	</select></td>
    <td>Sales Key Executive <font color='red'>*</font></td>
    <td><?php 
	
		//echo "select * from www_users where companyid='".$_SESSION['ACGCompanyId']."' and department in('".$Dept_id."')";
		$Sale_key_Exe=DB_query("select * from salesman_master where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
	
	?>
	<select name="Sale_Key_Exec" id="Sale_Key_Exec" style="width:100%;">
	<option value="">Select</option>
	<?php while($Sale_keyRow=DB_fetch_array($Sale_key_Exe))
	{
	?>
	<option value="<?php echo $Sale_keyRow['id'] ?>"  ><?php echo $Sale_keyRow['sales_name']; ?></option>
	<?php } ?>
	</select></td>
    <td>Pending Payments (if any)</td>
    <td><input type="text" style="width:100%;" name="PendingPayment" id="PendingPayment" value="<?php echo $_SESSION['PendingPayment'];?>"></td>
  </tr>
  
</table>
<!-----------------OTHER DETAILS------------------------------------------------------------------------------------>
<table width="100%" border="0" cellspacing="0" cellpadding="3">

<tr class="row1">
	<td class="tabledata1" colspan="6">
	<!--<input type="button" onClick="addRow('dataTable')" value="Add More" class="search" />-->&nbsp;
	<input type="button" name="profile_popup" value="Pick Items" id="profile_popup" class="search" />
	<input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" />
	<select name="dutytype" class="tabledata" style="height:30px;" onchange="getdata(this.value);" id="showw">
		<option value="">Select Duty Type</option>
		<option value="item_wise">Item Wise</option>
		<option value="consolidate">Consolidate</option>
	</select><span style="font-size:12px; font-weight:bold; text-align:center; padding-left:350px;">Items Details</span>
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="6" style="padding:0px;">
		<div id="divordertype" style="width:100%; margin:auto;">
		<div class="frisetable4">
		<div class="bodywidth4">
		<table width="100%" cellpadding="3" cellspacing="0" border="1" >
		<tr bgcolor="#d4d4d4">
			<td class="headerpartl_1">Srl.</td>
			<td class="headerpartl_2"></td>
			<td class="headerpartl_3">Item Code</td>
			<td class="headerpartl_4">Item Name</td>
			<td class="headerpartl_7">Unit</td>
			<td class="headerpartl_5">Description</td>
			<td class="headerpartl_6">Stock Qty.</td>
			<td class="colls">Order Qty</td>
			<td class="colls">Rate</td>
			<td class="colls">Amount</td>
			<td class="consolidateshow colls">Excise Duty Rate</td>
			<td class="consolidateshow colls">ED Amt</td>
			<td class="colls">Total Amt</td>
			<td class="colls">Remarks</td>
		</tr> 
		<tbody id="dataTable">
			<tr bgcolor="#c1c1c1">
					<td class="headerpartcol1"><input type="checkbox" id="delitem[]" /></td>
					<td class="headerpartcol2"><input type="hidden" name="mst_itemid[0]" id="itemid" /></td>
					<td class="headerpartcol3"><input type="text" name="itemcode[0]" id="itemcode" style="width:100%;" readonly="" /></td>
					<td class="headerpartcol4"><input type="text" name="itemname[0]" id="itemname" style="width:100%;" readonly="" /></td>
					<td class="headerpartcol7"><input type="text" name="" id="" style="width:100%;" readonly="" /></td>
					<td class="headerpartcol5"><input type="text" name="itemdesc[0]" id="itemdesc" style="width:100%;" readonly=""></td>
					<td class="headerpartcol6"><input type="text" name="total_stock[0]" id="total_stock" style="width:100%;" readonly="" /></td>
					<td valign="top" class="colls1"><input type="text" name="Quantity[0]" id="Quantity" style="width:80px;"/></td>
					<td valign="top"><input type="text" name="Rate[0]" id="Rate" onKeyUp="calculateTotalPrice(this.id)" style="width:80px;"/></td>
					<td valign="top" class="colls1"><input type="text" name="totalPrice[0]" id="totalPrice" readonly="true" style="width:80px;"/></td>
					<td valign="top" class="consolidateshow colls1"><select name="exdrate[0]" id="exdrate" style="width:107px" onchange="calculateExcise(this.value,this.id)">
							<option value="0">Select</option>
							<?php
								$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
								$ServiceRes=DB_query($ServiceSql,$db);
								while($ServiceRow=DB_fetch_array($ServiceRes))
								{
							?>
							<option value="<?php echo $ServiceRow['id']?>" <?php echo($edit_EDRate==$ServiceRow['id']?"selected":"") ?>><?php echo $ServiceRow['caption'];?></option>
							<?php	
							}
							?>
						</select></td>
					<td valign="top" class="consolidateshow colls1"><input type="text" name="ex_amount[0]" id="ex_amount"/></td>
					<td valign="top" class="colls1"><input type="text" id="TotalSpecial" name="TotalAmount[0]" style="width:150px;" onfocus="cal_grandtotalImp(this.id);" value="0"/></td>
					<td valign="top" class="colls1" height="40"><input type="text" name="ramarks[0]" style="width:100px;" id="remarks"></td>
					
					
					
		</tr> 
		</tbody>  
		</table>
		</div>
		</div>
	  </div>
	</td>
</tr>
	<input type="hidden" name="" id="hiditemcount" />
	<input type="hidden" name="" id="count1" />



<tr class="row1" id="itemwiseshow" style="display:none;">
<td class="tabledata1" colspan="6">
	<table border="0" width="100%" cellpadding="3" cellspacing="0">
		<tr class="row1">
		<td width="50%"></td>
		<td width="50%">
			<table width="100%" border="0" cellspacing="0" cellpadding="3">
			<tr class="row1">
				<td class="tabledata1" colspan="2"><h1 style="border-width: 0 0 0 0px;">Amount And Taxes</h1></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Value Of Goods
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="basicAmount" type="text"  style="width:107px;" onfocus="calculateBasic()" id="basicAmount"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">E-Cess</td>
		<td><?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%Edu Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<input type="hidden" name="ECessID" value="<?php echo $RESULT['id']?>" style="width:107px;">
		<input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:107px" />
		<input name="ECessValue" id="ECessValue" type="text"   readonly onfocus="calculateECess()" style="width:107px"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">SHE Cess </td>
		<?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%SHE Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<td><input type="hidden" name="SHECessId" value="<?php echo $RESULT['id']?>" style="width:107px;">
		<input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>" style="width:107px;" readonly/>
		<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:107px;" readonly onfocus="calculateSAHCess()"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Taxable Amount
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="taxableAmount" id="taxableAmount" type="text" style="width:107px;" onfocus="calculateTaxable()"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">VAT/CST</td>
		<td><select name="VatCst" id="value3" onchange="calculateVATCST(this.value)" style="width:107px;">
		<option value="" >Select</option>
		<?php 
		$salesSql=DB_query("Select * from sales_tax_master",$db);
		while($salesRow=DB_fetch_array($salesSql))
		{?>
		<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
		<?php 	
		}
		?>
		</select>
		<div id="VATId">
		<input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:107px;" readonly  onfocus="calculateEditVATCST()" />
		</div>
		<input type="hidden" name="" id="rate" value="<?php echo $rate;?>" />		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Grand Total</strong>
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="grandTotal" id="grandTotal" type="text"  style="width:107px;" onfocus="calculateGrand()" readonly="readonly"  /></td>
		</tr>
		</table>
	</td>
</tr>
</table></td></tr>



		
<tr class="row1" id="itemwiseshowconsolidate">
<td class="tabledata1" colspan="6">
	<table border="0" width="100%" cellpadding="3" cellspacing="0">
		<tr class="row1">
		<td width="50%"></td>
		<td width="50%">
			<table width="100%" border="0" cellspacing="0" cellpadding="3">
			<tr class="row1">
				<td class="tabledata1" colspan="2"><h1 style="border-width: 0 0 0 0px;">Amount And Taxes</h1></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Value Of Goods
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="basicAmount" type="text"  style="width:107px;" onfocus="calculateBasic1()" id="basicAmount1" readonly='true'/></td>
		</tr>
		<tr class="row1" id="ExiceDutyDiv">
			<td class="tabledata1">Excise Duty</td>
			<td><select name="EDBillRate" id="EDRate" style="width:107px" onchange="calculateBillExcise1(this.value)"  >
			<option value="0">Select</option>
			<?php
			$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
			$ServiceRes=DB_query($ServiceSql,$db);
			while($ServiceRow=DB_fetch_array($ServiceRes))
			{
			?>
			<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
			<?php	
			}
			
			?>
			</select><div id="totalDiscountedPrice1">
			<input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:107px;" onfocus="calculateTotalExcise1()"/>
			</div></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">E-Cess</td>
		<td><?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%Edu Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<input type="hidden" name="ECessID" value="<?php echo $RESULT['id']?>" style="width:107px;">
		<input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:107px" />
		<input name="ECessValue" id="ECessValue1" type="text"   readonly onfocus="calculateECess1()" style="width:107px"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">SHE Cess </td>
		<?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%SHE Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<td><input type="hidden" name="SHECessId" value="<?php echo $RESULT['id']?>" style="width:107px;">
		<input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>" style="width:107px;" readonly/>
		<input name="SAHCessValue" id="SAHCessValue1" type="text" value="<?php echo $SAHCessValue?>" style="width:107px;" readonly onfocus="calculateSAHCess1()"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Taxable Amount
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="taxableAmount" id="taxableAmount1" type="text" style="width:107px;" onfocus="calculateTaxable1()"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">VAT/CST</td>
		<td><select name="VatCst" id="value3" onchange="calculateVATCST1(this.value)" style="width:107px;">
		<option value="" >Select</option>
		<?php 
		$salesSql=DB_query("Select * from sales_tax_master",$db);
		while($salesRow=DB_fetch_array($salesSql))
		{?>
		<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
		<?php 	
		}
		?>
		</select>
		<div id="VATId1">
		<input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:107px;" readonly  onfocus="calculateEditVATCST()" />
		</div>
		<input type="hidden" name="" id="rate" value="<?php echo $rate;?>" />		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Grand Total</strong>
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="grandTotal" id="grandTotal1" type="text"  style="width:107px;" onfocus="calculateGrand1()" readonly="readonly"  /></td>
		</tr>
		</table>
	</td>
</tr>
</table></td></tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td colspan="11">
		<p align="center">
			<!--<input type="submit" name="Save" value="Save" class="search" onclick="return validation();"/>-->
			<input type="submit" name="Save" value="Save" class="search"/>
                    <a href="index.php?route=CRM/ViewSalesOrder&modid=12&frmid=322" onclick="return confirm('Are you sure?');">
                    <input type="button" name="Cancel" value="Cancel" class="search"  />
                    </a>            <!-- Tab 1 Close -->
		</p>
	
	</td>
</tr>
</table>

      <!-- Tab 2 Close -->
          </form>
		  </div>
 </div>
        </div>
      </div>
    </div>
  </div>
  <!-- inside div close -->
</div>
<!-- Main div close -->
<script language="javascript" type="text/javascript">

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

}
	
	
function open_items()
{
if(document.getElementById("order_type").value=='')
{
alert("Must Select Order Type First");	
}
else
{	
var site=document.getElementById("Site").value;
//var store=document.getElementById("store").value;
var date=document.getElementById("TelephonicDate").value;
	window.open("TelephonicItems.php?site="+site+"&date="+date+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");}
}
	
function calculateExcise(str,id)
{
	
	var id_brk=id.split('_');
	var i=id_brk[1];
	//alert(i);
	if(id_brk.length>1)
	{
		divid="ex_amount_"+i;
		var amount=document.getElementById("totalPrice_"+i).value;
	}
	else
	{
		divid="ex_amount";
		var amount=document.getElementById("totalPrice").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		//alert(xmlhttp.responseText);
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","ajax_calculate_excise.php?amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 
	
function calculateExcise1(str,id)	
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalassamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalassamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 	

function calculateBillExcise1(str)
{
	var value=document.getElementById("basicAmount1").value;
	if(str.length==0)
	{
		document.getElementById("totalDiscountedPrice1").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("totalDiscountedPrice1").innerHTML=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
xmlhttp.send();	
}



function calculateBillExcise(str)
{
	var value=document.getElementById("basicAmount").value;
	if(str.length==0)
	{
		document.getElementById("totalDiscountedPrice1").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("totalDiscountedPrice1").innerHTML=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
xmlhttp.send();	
}



function calculateTotalExcise()
{
	
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	var first_row=document.getElementById("excisevalue").value;
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	 	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	 	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise)+parseFloat(first_row);
	}
	else{return false;}
}

function calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}

/*function validate()
{
	if(document.getElementById("Site").value=='0')
	{alert('Please choose a branch before saving'); document.getElementById("Site").focus();  return false;}
	
	if(document.getElementById("orderNo").value=='')
	{alert('SOP No. cannot be empty'); document.getElementById("orderNo").focus(); return false;}
	
	if(document.getElementById("Client").value=='0')
	{alert('Please choose a client before saving'); document.getElementById("Client").focus(); return false;}
	
	if(document.getElementById("PONo").value=='')
	{alert('Client PO No. cannot be empty'); document.getElementById("PONo").focus(); return false;}
		
	return false;
}*/

function getorder(str)
{
	if(str!='Consolidate')
	document.getElementById("EDRate").setAttribute('disabled',true);
	else
	document.getElementById("EDRate").removeAttribute('disabled');
	if(str.length==0)
	{
	document.getElementById("showdata").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("showdata").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","gettelephonicdata.php?id="+str,true);
	xmlhttp.send();
}

function showstore(str)
{

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



}

function showstorecode(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("hid-Godown-div").innerHTML=data[0];
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","lead_storecode.php?site="+str,true);
	xmlhttp.send();
}
function calcValue1(str,id)
{

	var brk=id.split('_');
	if(brk.length==1)
	{
	   if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("qty").value='';
	   return false;
	   }
       
	}
	else
	{
	  if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+brk[1]).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("qty_"+brk[1]).value='';
	   return false;
	   }
		
	}
}

function getdata(str)
{

	
	if(str=="")
	{
	document.getElementById('hid-zone-div').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("divordertype").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","ajax_saleorer.php?arr="+str,true);
	xmlhttp.send();
}



</script>
