<?php ob_start();
error_reporting(0);
$PageSecurity = 4;
$PageName = 'MaterialReceiptNote';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
if (isset($_GET['ModifyOrderNumber']) and $_SESSION[UserType]=='SuperAdmin')  {
$title = _('Modify Purchase Order') . ' ' . $_GET['ModifyOrderNumber'];
} 
else 
{
}
if(isset($_GET['issueid'])  && isset($_GET['issueid']) !=''){
$title = _('Update Issue Slip');
}
$dealertype=$s->getField('www_users','id',$_SESSION['UserID'],'Type');

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

				$url_cancel= "index.php?route=Inventory/transation/material_receipt_note_index".$rurl;
				$url_add= "index.php?route=Inventory/transation/material_receipt_note_add".$rurl;
				
				
				
				



?>
<script type="text/javascript" src="js/function-ajax.js" language="javascript">
</script>
<script type="text/javascript">

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

function confirmPost()
{
if(document.getElementById("sitecode").value=='000')
{
alert("Must Select Site Name");
document.getElementById("sitecode").focus();
return false;
}
if(document.getElementById("storecode").value=='000')
{
alert("Must Select Store Name");
document.getElementById("storecode").focus();
return false;
}
if(document.getElementById("receiviedagaist").value=='0')
{
alert("Must Select Received Aganist Type");
document.getElementById("receiviedagaist").focus();
return false;
}
if(document.getElementById("vendor").value=='000')
{
alert("Must Select  Vender");
document.getElementById("vendor").focus();
return false;
}
if(document.getElementById("gatepassno").value=='')
{
alert("Must Enter Gate Entry No");
document.getElementById("gatepassno").focus();
return false;
}
if(document.getElementById("gatepassdate").value=='')
{
alert("Must Enter Gate Entry Date");
document.getElementById("gatepassdate").focus();
return false;
}
if(document.getElementById("entrycheck").value=='1')
{
alert("Duplicate Entry For Gate Entry Pass");
document.getElementById("gatepassno").value='';
document.getElementById("gatepassno").focus();
return false;
}


var col=0;
var cou=document.getElementById("count").value;
for(var i=0;i<cou;i++)
{	
if(document.getElementById("qty_as_per_bill_"+i).value!='')
{
var col=1;
}	
}
if(col==0)
{
alert("please Fill All details of item");
return false;
}
	
if(document.getElementById("total_item_amount").value=='' || document.getElementById("total_item_amount").value=='0.00')
{
alert("Total amount should not be blank");
document.getElementById("total_item_amount").focus();
return false;
}



if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
{
alert("Grand Total amount should not be blank");
document.getElementById("GrandTotal").focus();
return false;
}		

}

function confirmPost1()
{
var max_price=document.getElementById("max_price").value;
var grand_price=document.getElementById("GrandTotal").value;
if(parseFloat(grand_price) > parseFloat(max_price)){
$alertmasg="Grandtotal not more than Maximum Direct Purchase Allowed Amount - "+max_price;
alert($alertmasg);
return false;
}

if(document.getElementById("sitecode").value=='000')
{
alert("Must Select Site Name");
document.getElementById("sitecode").focus();
return false;
}
if(document.getElementById("storecode").value=='000')
{
alert("Must Select Store Name");
document.getElementById("storecode").focus();
return false;
}
if(document.getElementById("receiviedagaist").value=='0')
{
alert("Must Select Received Aganist Type");
document.getElementById("receiviedagaist").focus();
return false;
}
if(document.getElementById("vendor").value=='000')
{
alert("Must Select  Vender");
document.getElementById("vendor").focus();
return false;
}
if(document.getElementById("gatepassno").value=='')
{
alert("Must Enter Gate Entry No");
document.getElementById("gatepassno").focus();
return false;
}
if(document.getElementById("gatepassdate").value=='')
{
alert("Must Enter Gate Entry Date");
document.getElementById("gatepassdate").focus();
return false;
}
if(document.getElementById("entrycheck").value=='1')
{
alert("Duplicate Entry For Gate Entry Pass");
document.getElementById("gatepassno").value='';
document.getElementById("gatepassno").focus();
return false;
}

var col=0;
var cou=document.getElementById("count").value;
for(var i=0;i<cou;i++)
{	
if(document.getElementById("qty_as_per_bill_"+i).value!='')
{
var col=1;
}	
}
if(col==0)
{
alert("please Fill All details of item");
return false;
}

if(document.getElementById("total_item_amount").value=='' || document.getElementById("total_item_amount").value=='0.00')
{
alert("Total amount should not be blank");
document.getElementById("total_item_amount").focus();
return false;
}	

if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
{
alert("Grand Total amount should not be blank");
document.getElementById("GrandTotal").focus();
return false;
}	
}
function caltaxamout(i)
{
var excise=parseFloat(document.getElementById("exciseDuty_"+i).value);
if(excise!=0)
{
var basic_amount=document.getElementById("exciseValue_"+i).value;
var ecessamt=document.getElementById("ECessValue_"+i).value;
var sahamt=document.getElementById("SAHCessValue_"+i).value;
var totaltax=parseFloat(basic_amount)+parseFloat(ecessamt)+parseFloat(sahamt);	
document.getElementById('taxableamount_'+i).value=totaltax.toFixed(2);	
}
else
{
document.getElementById('taxableamount_'+i).value=0;		
}	
}

function calvatamount(i)
{
var vatcst_per=document.getElementById('vatper').value;
if(vatcst_per!=0)
{
var taxamt=parseFloat(document.getElementById('taxableamount_'+i).value);
var total=taxamt;
var vatamount=(total*vatcst_per)/100;
document.getElementById('vatcstamount_'+i).value=vatamount.toFixed(2);	
}	
else
{
document.getElementById('vatcstamount_'+i).value=0;	
}
}
function calculate_short(id)
{
	var x = parseInt(document.getElementById('reciveqty_'+id).value);
	var poqty = parseInt(document.getElementById('qty_as_per_bill_'+id).value);	
	var rate = parseInt(document.getElementById('itemrate_'+id).value);
 	if(x != '')
	{
		if(poqty < x)
		{	
		alert("Received Quantity can not be greater than PO Quantity");
		return false;
		}
		else if(poqty >= x)
		{
 		document.getElementById('short_accessid_'+id).value = (parseFloat(poqty)- parseFloat(x)).toFixed(2);
		return true;
		}
	  }
	else
	{
	document.getElementById('short_accessid_'+id).value = 0;
	return true;
	}
}
function calculate_discount(str)
{
	var qty=document.getElementById("reciveqty_"+str).value;
	var itemrate=document.getElementById("itemrate_"+str).value;
	var disc_type=document.getElementById("disc_type_"+str).value;
	var disc=document.getElementById("discount_"+str).value;
	//alert(disc);
	if(disc==''){disc=0;}
	if(disc_type=='Amount')
	{
		var total_rate=parseFloat(qty) * parseFloat(itemrate);
		document.getElementById("val_after_disc_"+str).value=(parseFloat(total_rate) - parseFloat(disc)).toFixed(2);
		document.getElementById("discount_amount_"+str).value=(parseFloat(disc)).toFixed(2);
	}
	else if(disc_type=='PercentAmt')
	{
		var total_rate=parseFloat(qty) * parseFloat(itemrate);
		var disc_val=parseFloat(total_rate)*parseFloat(disc)/100;
		document.getElementById("val_after_disc_"+str).value=(parseFloat(total_rate) - parseFloat(disc_val)).toFixed(2);
		document.getElementById("discount_amount_"+str).value=(parseFloat(disc_val)).toFixed(2);
	}
}
function calc_taxval(str,j)
{
	var val_after_disc = document.getElementById("val_after_disc_"+j).value;
	if(val_after_disc != ''){
	var taxvalue=(parseInt(str)*parseInt(val_after_disc))/100;
	}
	document.getElementById("taxamount_"+j).value=parseInt(taxvalue);
	
}
function calc_amount_with_tax(str)
{
	var totalrate = document.getElementById("val_after_disc_"+str).value;
	var taxamount = document.getElementById("taxamount_"+str).value;
if(totalrate != '' && taxamount != '')
{
	var total_amt_with_tax = parseInt(totalrate) + parseInt(taxamount);
	document.getElementById("total_amt_with_tax_"+str).value = parseInt(total_amt_with_tax);
}
}
function openPopupProfile(i)
{
  	window.open("Search_item_MRN.php?rowcount="+i,"profiles_popup_window","height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function ChargeAmount1(CA,ID)
 {
	if (CA=="")
	{
		document.getElementById("PerActual"+ID).innerHTML="";
		return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("PerActual"+ID).innerHTML=xmlhttp.responseText;
		}
	}
 	xmlhttp.open("GET","Charges_Details.php?CA="+CA+"&ID="+ID,true);
	xmlhttp.send();
 }
function calculate_BasicAmount()
{
 	var  itemamount = 0;
 	var  count= document.getElementById('rowcount').value;
 	
	for(var i=0; i<count; i++)
	{
 		var totalrate = document.getElementById('val_after_disc_'+i).value;
			if(!isNaN(totalrate) && totalrate!='' ){
				itemamount  =parseFloat(itemamount)+  parseFloat(totalrate);
  			}
			else if(totalrate=='')
			{ totalrate=0;}
 	}
 	document.getElementById('itemamount').value = itemamount;
 }
 
function value_after_discount(i)
{
	
	var basic = parseFloat(document.getElementById('basic_'+i).value);
	//alert(item_total_rate);
	if(document.getElementById('taxableamount_'+i).value=='')
	{
	var taxableamt = 0;	
	}
	else
	{
	var taxableamt = parseFloat(document.getElementById('taxableamount_'+i).value);
	}
	//alert(taxableamt);
 	var val_after_disc = parseFloat(basic+taxableamt);
 	//alert(val_after_disc);
	document.getElementById('total_'+i).value=val_after_disc.toFixed(2);	
	
	
}
function CountTotalQty()
{
	var  qty = 0;
	var  count= document.getElementById('rowcount').value;
   	var i;
 	for(i=0; i<count; i++)
	{
 		var totalqty = document.getElementById('reciveqty_'+i).value;
 			if(!isNaN(totalqty) && totalqty!='' ){
				qty  =parseFloat(qty)+  parseFloat(totalqty);
  			}
 	}
  	document.getElementById('totalqty').value = qty;
 }
 
 function check_po_qty(i)
 {
        poqty=parseFloat(document.getElementById("pending_qty_"+i).value);
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		if(reciveqty!='' && poqty!='')
		{
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
		}
 
 
 
 }
 
 
  function check_po_qty1(i)
  {
        poqty=parseFloat(document.getElementById("pending_qty_"+i).value);
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		if(reciveqty!='' && poqty!='')
		{
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
		}
  if(document.getElementById("convfac_"+i).value!='')
   var k=parseFloat(document.getElementById("convfac_"+i).value); 
 else
 var k=0;
 var amt=reciveqty/k;
 document.getElementById("scecondarqty_"+i).value=amt.toFixed(2);
 }
 
 function check_po_qty2(i)
  {
       
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		
  if(document.getElementById("convfac_"+i).value!='')
   var k=parseFloat(document.getElementById("convfac_"+i).value); 
 else
 var k=0;
 var amt=reciveqty/k;
 document.getElementById("scecondarqty_"+i).value=amt.toFixed(2);
 }
 
 
 
 
function check_po1()
{
	var rowcount=document.getElementById("rowcount").value;
	for(var i=0;i<rowcount;i++)
	{
		poqty=parseFloat(document.getElementById("poqty_"+i).value);
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		if(reciveqty!='' && poqty!='')
		{
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
		}
		
	}
}
 
function check_bill_qty(str,id)
{
  
	var poqty=parseInt(document.getElementById("pendingqty_"+id).value);
	var tolerance = document.getElementById("tolerance_"+id).value;
	if(tolerance==''){tolerance=0;}
	str1=parseInt(str);
	if(poqty!='')
	{
	var qty=(poqty*tolerance)/100;
	var poqty1=parseInt(poqty)+parseInt(qty);
	//var poqty2=poqty-qty;	
	if(str1>poqty1)
	{
		var altmsg = "Quantity As Per Bill Cannot Be Greater Than "+tolerance+" % more of PO Quantity";
		alert(altmsg);
		document.getElementById("qty_as_per_bill_"+id).value='';
		document.getElementById("reciveqty_"+id).value='';
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
	}
	}
}

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

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


}
}

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

/*function check_po()
{
	
	var sitecode=document.getElementById("sitecode").value;
	var storecode=document.getElementById("storecode").value;
	var vendor=document.getElementById("vendor").value; 
	var billno=document.getElementById("billno").value;
	
	if(sitecode=='000')
	{
		alert("Please Select Sitecode");
		return false; 
	}
	if(document.getElementById("receiviedagaist").value!="Without PO")
	{
	if(vendor=='000')
	{
		alert("Please Select Vendor");
		 return false;
	}
	}
	if(storecode=='000')
	{
		alert("Please Select Sitecode");
		 return false;
	}
	if(billno=='')
	{
		alert("Please Challan Or Bill");
		 return false;
	}
	return true;
}*/
</script>
<?php 
					if($_REQUEST['reset']!='')
					{
					unset($_REQUEST['sitecode']);unset($_REQUEST['sitename']);unset($_REQUEST['hidden_site']);
					unset($_REQUEST['vendor']);	unset($_REQUEST['PO']);	unset($_REQUEST['credit_days']);
					unset($_REQUEST['MRNdate']);unset($_REQUEST['matrialreceipt']);	unset($_REQUEST['storecode']);
					unset($_REQUEST['storename']);unset($_REQUEST['rmrs_no']);unset($_REQUEST['orderdate']);
					unset($_REQUEST['billno']);	unset($_REQUEST['MRNVoucherDate']);	unset($_REQUEST['gatepassno']);
					unset($_REQUEST['inwardate_save']);	unset($_REQUEST['transport']);unset($_REQUEST['vehicalno']);
					unset($_REQUEST['timein']);unset($_REQUEST['timeout']);	unset($_REQUEST['lrno']);
					unset($_REQUEST['lrdate']);	unset($_REQUEST['total_weight']);unset($_REQUEST['RemarksIfAny']);
					unset($_REQUEST['DocumentType']);unset($_REQUEST['receiviedagaist']);unset($_REQUEST['receipt']);
					unset($_SESSION['manvi_new']);unset($_SESSION['receiviedagaist']);unset($_SESSION['sitecode']);
					unset($_SESSION['sitename']);unset($_SESSION['hidden_site']);unset($_SESSION['vendor']);
					unset($_SESSION['PO']);unset($_SESSION['credit_days']);	unset($_SESSION['MRNdate']);
					unset($_SESSION['matrialreceipt']);unset($_SESSION['storecode']);unset($_SESSION['storename']);
					unset($_SESSION['rmrs_no']);unset($_SESSION['orderdate']);unset($_SESSION['billno']);
					unset($_SESSION['MRNVoucherDate']);unset($_SESSION['gatepassno']);unset($_SESSION['inwardate_save']);
					unset($_SESSION['transport']);unset($_SESSION['vehicalno']);unset($_SESSION['timein']);
					unset($_SESSION['timeout']);unset($_SESSION['lrno']);unset($_SESSION['lrdate']);
					unset($_SESSION['total_weight']);unset($_SESSION['RemarksIfAny']);unset($_SESSION['DocumentType']);
					unset($_SESSION['entrycheck']);unset($_REQUEST['receipt']);
					unset($_SESSION['dealertype']);
					}


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


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

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

if(isset($_POST['save']))
{
$prefixtitle='GRN';	
if($_REQUEST['receiviedagaist']=='PO')
{
$prefixcode="GRN";
}
if($_REQUEST['receiviedagaist']=='DirectPOOrder')
{
$prefixcode="DGRN";
}	
	 
    $prefixtype=$s->getField('dbl_prefix_tbl','prefix_name',$prefixtitle,'prefix_code');						
	$SQLMax=DB_query("select MRNNo as QutNo from dbl_addmrn order by id DESC limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$num=DB_num_rows($SQLMax);
	if($num>0)
	{
	$explode=explode("/",$MaxQut['QutNo']);
	$FinMx=$explode[2]+1;
	$FinalCode=$prefixtype."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$prefixtype."/".'00001';
	}			
	
	
		
		$data['MRNNo'] = $FinalCode; 
		$data['MRNDate'] = date('Y-m-d'); 
		$data['Type'] =  $_REQUEST['receiviedagaist'];
		$data['MRNVoucherDate'] = FormatDateForSQL($_REQUEST['MRNVoucherDate']); 
		$data['ReceivedAgainst'] =  $_REQUEST['receiviedagaist'];
		$data['MaterialReceiptOnBasis'] = $_REQUEST['matrialreceipt']; 
		$data['site'] = $_REQUEST['sitecode']; 
		$data['StoreCode'] = $_REQUEST['storecode'];  
		$data['StoreName'] = $_REQUEST['storename'];  
		$data['site_name'] = $_REQUEST['sitename'];  
		$data['workorderno'] = $_REQUEST['work_order_no'];  
		$data['workorderitem'] = $_REQUEST['finished_item'];  
		$data["PO_WO_MTO"] = $_REQUEST['Purchase_Order'];  
 		$data['OrderDate'] = date("Y-m-d");//$_REQUEST['orderdate']; 
		$data['ReceivedFrom'] = $_REQUEST['branch'];
		$data['req_no'] = $_REQUEST['req_no'];
		$data['DocumentType'] = $_REQUEST['DocumentType'];  
		$data['BillNo'] = $_REQUEST['billno']; 
		$data['BillDate'] = date("Y-m-d"); 
		$data['GetPassNo'] = $_REQUEST['gatepassno']; 
		$data['Inwardsdate'] =FormatDateForSQL($_REQUEST['inwardate_save']);     
		$data['Transp_name'] = $_REQUEST['transport'];  
		$data['VehicleNo'] = $_REQUEST['vehicalno']; 
		$data['TimeIn'] = $_REQUEST['timein']; 
		$data['Timeout'] = $_REQUEST['timeout']; 		 
		$data['LRno'] = $_REQUEST['lrno'];  
		$data['RemarksIfAny'] = $_REQUEST['RemarksIfAny'];  	 
		$data['LRdate'] = FormatDateForSQL($_REQUEST['lrdate']); 
		$data['TotalWeight'] = $_REQUEST['total_weight']; 
		$data['form_no'] = $_REQUEST['form_no'];
		$data['form_type'] = $_REQUEST['form_type']; 
		$data['gatepassdate'] = FormatDateForSQL($_REQUEST['gatepassdate']);
		$data['createdby'] =$_SESSION['UserID'];  	 
		$data['order_no'] = $_REQUEST['orderno'];  	 
		$data['mrnstatus'] = "Pending";
		$data['Remarks'] = $_REQUEST['remark'];  
		$data['rmrs_no'] = $_REQUEST['rmrs_no'];		                    
		$data['total_Item_Amount'] = $_REQUEST['total_item_amount'];
		$data['pkg_perc'] = $_REQUEST['pkg_perc'];
		$data['pkg_charges'] = $_REQUEST['pkg_charges'];
		$data['vat_cst'] = $_REQUEST['vat_cst'];
		$data['vat_cst_val'] = $_REQUEST['taxvalue'];
		$data['sur_oct_per'] = $_REQUEST['sur_oct_per'];
		
		$data['excise'] = $_REQUEST['EDBillRate'];
		$data['excise_amt'] = $_REQUEST['totalDiscountedPrice'];
		$data['ecess'] = $_REQUEST['ECessPercentage'];
		$data['ecess_amt'] = $_REQUEST['ECessValue1'];
		$data['sah'] = $_REQUEST['SAHCessPercentage'];
		$data['sah_amt'] = $_REQUEST['SAHCessValue1'];
		$data['total_exciable'] = $_REQUEST['total_excise_amount'];
		
		$data['loading'] = $_REQUEST['loading'];
		$data['sur_oct_amt'] = $_REQUEST['sur_oct_amt'];
		$data['tot_freight'] = $_REQUEST['tot_freight'];
		$data['add_charges'] = $_REQUEST['add_charges'];
		$data['userstype']=$_REQUEST['usertype'];
		$data['grandtotal'] = $_REQUEST['grandtotal'];
		$data['round_off'] = $_REQUEST['round_off'];
		$data['companyID'] = $_SESSION['ACGCompanyId'];
	    $insertsql=$s->insertRecord('dbl_addmrn', $data);
 	   $insertResult = DB_query($insertsql,$db,$ErrMsg);
	   $Lastreq_id=DB_Last_Insert_ID($db,'dbl_addmrn',$ErrMsg);
 	   if($insertResult==true)
	   { 		
		$countval= count($_REQUEST['mst_itemid']);
		$total_basic_amount=0;
		$total_tax_amount=0;	
		$coldata1=0;
		$numdata1=0;
 		for($i=0;$i<$countval;$i++)
		{
 				if($_REQUEST['qty_as_per_bill'][$i]!='')
				{				
				$data_arr['issue_id']= $Lastreq_id;
				$data_arr['issue_qty']= $_POST['issuebalanc'][$i];				
				$data_arr['mst_itemid']= $_POST['mst_itemid'][$i];
				$data_arr['itemprice']= $_POST['itemrate'][$i];
				$data_arr['POQty']= $_REQUEST['poqty'][$i];
				$data_arr['reciveqty']= $_REQUEST['reciveqty'][$i];
				$data_arr['short_accessid']= $_REQUEST['short_accessid'][$i];
				$data_arr['qty_as_per_bill']= $_REQUEST['qty_as_per_bill'][$i];				
				$data_arr['item_total_rate']= $_REQUEST['item_total_rate'][$i];						
										
				$insert_mrm=$s->insertRecord('dbl_addmrnqty', $data_arr);
				$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
				$insertResult = DB_query($insert_mrm,$db,$ErrMsg);
		/******************** insert update_mrn_qty Po QTY   **************************************/	
					
						
				
				}
					
					
							
		    }
		
			 
		$_SESSION['success_msg']="Saved Successfully";
	echo "<script>location='index.php?route=DealerDistrbutions/Inventory/transation/material_receipt_note_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	    
	}
	
	unset($_SESSION['manvi_new']);
	unset($_SESSION['receiviedagaist']);
	unset($_SESSION['receipt']);
	unset($_SESSION['sitecode']);
	unset($_SESSION['sitename']);
	unset($_SESSION['hidden_site']);
	unset($_SESSION['vendor']);
	unset($_SESSION['PO']);
	unset($_SESSION['credit_days']);
	unset($_SESSION['MRNdate']);
	unset($_SESSION['matrialreceipt']);
	unset($_SESSION['storecode']);
	unset($_SESSION['storename']);
	unset($_SESSION['rmrs_no']);
	unset($_SESSION['orderdate']);
	unset($_SESSION['billno']);
	unset($_SESSION['MRNVoucherDate']);
	unset($_SESSION['gatepassno']);
	unset($_SESSION['inwardate_save']);
	unset($_SESSION['transport']);
	unset($_SESSION['vehicalno']);
	unset($_SESSION['timein']);
	unset($_SESSION['timeout']);
	unset($_SESSION['lrno']);
	unset($_SESSION['lrdate']);
	unset($_SESSION['total_weight']);
	unset($_SESSION['RemarksIfAny']);
	unset($_SESSION['DocumentType']);
}

?>
<form action="" method="post">
<h2 align="center"><strong>Material Receipt Note</strong></h2>
<br />
<input name="usertype" id="usertype" type="hidden" value="<?php echo $dealertype; ?>" />
<div style="width:810px; overflow:auto; margin-left:auto; margin-right:auto"> 

<h4 style="text-align:left; margin-left:10px;">GENERAL DETAILS</h4>
<table width="100%"  border="1" cellspacing="0" cellpadding="3">
  <tr>
    <th><strong>GRN No. </strong></th>
    <td colspan="2"><input type="text" value="Will Be Generated On Saving" style="width:100%" name="MRNNo" readonly="true"></td>
    <th><strong>GRN Date </strong></th>
    <td colspan="2"><input type="text"  style="width:100%"   name="MRNdate" value="<?php if(isset($_SESSION['MRNdate']))echo $MRNdate; else echo date('d/m/Y');?>" id="MRNdate" class="datepicker"></td>
  </tr>

  <tr>
    <th><strong>Dealer<font color="#FF0000">*</font></strong></th>
    <td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td>
	<?php 
	if(isset($_SESSION['dealerid']))
	$ss="Select * from dbl_dealer  where company='".$_SESSION['ACGCompanyId']."' and id='".$_SESSION['dealerid']."'";
	else
	$ss="Select * from dbl_dealer  where company='".$_SESSION['ACGCompanyId']."'";
		  $site_sql=DB_query($ss,$db); ?>
     <select name="sitecode" onchange="getreqitemdata1(this.value)" id="sitecode" style="width:70px"    >
     <option value="000">---Select---</option>
     <?php
	 while($site_row=DB_fetch_array($site_sql))
	 {
     ?>
      <option value="<?php echo $site_row['id'];?>"<?php echo ($sitecode==$site_row['id']?'selected':'')?>><?php echo $site_row['dealer_code'];?></option>
      <?php } ?>
    </select></td>
	  <td><div id="txtsite1">
	    <?php
	
	$site_sql="Select dealer_name from dbl_dealer where id ='".$sitecode."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($sitecode))
	{
	?>
	<input name="sitename" type="text" id="sitename"  value="<?php echo $site_row['dealer_name'];?>" size="20" readonly="true">
	<?php } else {?>
	<input name="sitename" type="text" id="sitename"  value="<?php echo $sitename;?>" size="20" readonly="true">
	<?php } ?>
	<input type="hidden" name="hidden_site" id="hidden_site" value="<?php echo $_REQUEST['hidden_site'];?>"/></div></td>
	</tr>
	<tr></tr>
	</table>	</td>
    <th><strong>Store <font color="#FF0000">*</font></strong></th>
    <td id="storedata12">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select * from dbl_dealer_store order by id ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="storecode" name="storecode"  style="width:100%" onfocus="check_po()"   >
		<option value="000">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($storecode==$myrow['id'])
				$p="selected";
		?>
			<option Value="<?php echo $myrow['id']; ?>" <?php echo $p; ?>><?php echo $myrow['dealer_store_name']; ?></option>
		<?php }
		?>
		</select></td>
      </tr>
    </table></td>
  </tr>
  
  
  
  
  
  
  <tr>
  	<th><strong>Recevied Against <font color="#FF0000">*</font></strong></th>
    <td colspan="2">
    <select name="receiviedagaist" id="receiviedagaist"	style="width:100%" onchange="checkdata(this.value)">
    <option value="0">Select</option>
	<option value="DirectPOOrder"<?php if($_REQUEST['receiviedagaist']=="DirectPOOrder") {?> selected="selected"<?php } ?>>DirectPOOrder</option>
        </select>    </td>
    <th scope="row"><strong>Recevied From  <font color="#FF0000">*</font></strong></th>
    <td colspan="2"><select name="branch" id="branch"  style="width:100%"  >
				<option value="000" >---Select1---</option>
			<?php
			$sql="select * from locations where loccode in ('".$_SESSION['AssignedBranch']."')";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			$p='';
			if($branch==$myrow['loccode'])
			$p="selected";
			?>
			 <option  value="<?php echo $myrow['loccode']; ?>"<?php echo $p;?> ><?php echo  $myrow['locationname']; ?></option>
		<?php }
			?>
			</select></td>    
</tr>
<tr>
    <th scope="row"><strong>PO</strong></th>
    <td colspan="2">
	</td>
    <th><strong>Order Date </strong></th>
    <td colspan="2">
	<input type="text" name="orderdate" id="orderdate" value="" readonly="true" class="datepicker" style="width:100%" ></td>
	 </tr> 
  <tr>
    <th scope="row"><strong>Document Type</strong></th>
    <td colspan="2"><select name="DocumentType" id="DocumentType" style="width:100%">
	<option value="Challan">Challan</option>
	<option value="Bill">Bill</option>
	</select></td>
    <th><strong>Document No. </strong></th>
    <td colspan="2"><input name="billno" type="text" id="billno" style="width:100%" value="<?php  echo $billno; ?>" /></td>
  </tr>
  
    <tr>
    <th scope="row"><strong>Challan / Bill Date</strong></th>
    <td colspan="2"><input type="text" name="MRNVoucherDate" style="width:100%" class="datepicker"  onblur="valdate();"  value="<?php if(isset($_SESSION['MRNVoucherDate']))echo $MRNVoucherDate; else echo date('d/m/Y'); ?>"/></td>
    <th><strong>Gate Entry No.<font color="#FF0000">*</font></strong></th>
    <td colspan="2">
	<input type="text" name="gatepassno"  style="width:100%" id="gatepassno"  value="<?php echo $gatepassno; ?>"
	onkeyup="checkgatentyno(this.value)"; />
	<div id="entrycheck1"><input type="hidden" name="entrycheck" id="entrycheck"  value="<?php echo $entrycheck; ?>" /></div>	</td>
  </tr>
    <tr>
    <th>Gate Entry Date<strong><font color="#FF0000">*</font></strong> </th>
    <td colspan="2"><input type="text" name="gatepassdate" id="gatepassdate" style="width:100%" class="datepicker" /></td>
    <th><strong>Vehicle No.</strong></th>
    <td colspan="2"><input name="vehicalno" type="text" id="vehicalno" style="width:100%" value="<?php echo $vehicalno; ?>"/></td>
  </tr>
    <tr>
    <th scope="row"><strong>Receiving Time</strong></th>
    <td colspan="2"><select name="timein" id="timein" style="width:70px">
	<option value="Day" <?php echo $timein=='Day'?'selected':''?>>Day</option>
	<option value="Night" <?php echo $timein=='Night'?'selected':''?>>Night</option>
	</select><input type="text" name="timeout" value="<?php if(isset($_SESSION['timeout'])) echo $timeout; else echo date("h:i:s",time());?>">	</td>
    <th><strong>L R No.</strong></th>
    <td colspan="2"><input name="lrno" type="text" id="lrno" style="width:100%"  value="<?php echo $lrno; ?>"/></td>
  </tr>
    <tr>
    <th scope="row"><strong>L R Date</strong></th>
    <td colspan="2"><input name="lrdate" type="text" id="lrdate" style="width:100%" value="<?php if(isset($_SESSION['lrdate'])) echo $lrdate; else echo date('d/m/Y'); ?>"  onblur="LRdate();" class="datepicker"/></td>
    <th><strong>Form Type</strong></th>
    <td colspan="2"><input type="text" name="form_type" id="form_type"  style="width:100%" /></td>
  </tr>
    <tr>
    <th scope="row"><strong>Form No</strong></th>
    <td colspan="2"><input type="text" name="form_no" id="form_no"  style="width:100%" /></td>
	<th scope="row"><strong>Transporter Name</strong></th>
    <td colspan="2"><input name="transport" type="text" style="width:100%" value="<?php  echo $transport;?>" />	</td>
  </tr>  
    <tr>
    <th scope="row"><strong>Remarks If Any</strong></th>
    <td colspan="5"><textarea name="RemarksIfAny"  id="RemarksIfAny"  style="width:100%"><?php echo $RemarksIfAny;?></textarea></td>
  </tr>
</table>
<br />
<?php 

if($_REQUEST['receiviedagaist']=='Without PO')
{$display="style='display:block'";}
else
{$display="style='display:none'";}
?>

 <p align="left"><input type="submit"  name="item_popup" value="Add Items" id="item_popup"  onclick="open_items();"  /></p>


<br>

<fieldset><legend><strong>ITEM DETAILS</strong></legend>
 <div id="itemdata">      
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>	
<th><strong>S. NO. </strong></th>
<th><strong>ITEM CODE </strong></th>
<th><strong>DESCRIPTION</strong></th>
<th><strong>UOM</strong></th>         
<th><strong>QTY AS PER BILL </strong></th>
<th><strong>QTY RECEIVED</strong></th>
<th><strong>SHORT QUANTITY </strong></th>
<th><strong>RATE</strong></th>
<th><strong>TOTAL PRICE</strong></th>      
</tr>
<?php
if($_REQUEST['type']=='DirectPOOrder')
{
	
 $i=0;
if($_SESSION['manvi_new']!='')
{
$itemlist=array();
$itemlist=explode('#',$_SESSION['manvi_new']);
?>
        <?php 
	for($i=0;$i<count($itemlist);$i++)
	{
	$itemquery=DB_query("select * from item_master where id='".$itemlist[$i]."'" , $db);
	while($item_row=DB_fetch_array($itemquery))
	{
		
	$unit=$item_row['mst_unitid'];
	
	?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo $item_row['StockID'];?>
<input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]"  value="<?php echo $item_row['id'] ?>" /> </td>
<td><?php echo $item_row['item_name'] ?></td>
<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');echo $unitname; ?></td>
<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i?>" value=""  
onblur="check_bill_qty(this.value,<?php echo $i;?>)"/></td>
<td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i?>"  value="<?php echo $_REQUEST['reciveqty'][$i];?>" 
onkeyup="check_po_qty2(<?php echo $i;?>)" /></td>
<td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" style="width:100px;" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);" /></td>
<td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i?>" value="" style="width:90px;" /></td>
<td><input name="item_total_rate[]" type="text" id="item_total_rate_<?php echo $i?>" value=""  onfocus="calc_total_price(<?php echo $i;?>)" style="width:90px;"/></td></tr>
<?php } }  ?>
<input type="hidden" name="countval2" value="<?php echo $i; ?>" id="count"/>
<?php }} ?>
</table>
</div>
</fieldset>

  <div align="right">			
			<table width="40%">
			<tr><td>
		      <table width="100%" border="1" cellspacing="0" cellpadding="3">
                <tr>
                  <td><strong>TOTAL AMOUNT <font color="#FF0000">*</font></strong> </td>
                  <td >
				 
				  <input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()"/>
				
				  </td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_perc" id="pkg_perc" value="<?php echo $venddata['pkg_per']; ?>" size="5" onkeyup="calcPackaging(this.value)" /><input name="pkg_charges" id="pkg_charges1" type="text" value="" size="28"  
				  onfocus="calcPackaging1()" /></td>
                </tr>
				<tr>
					<td><strong>Excise</strong></td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:100%" onchange="calculateBillExcise(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>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:100%;" onfocus="calculateTotalExcise()"/>
				</td>
				   </tr>
			<?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++;
			} 
			?>
			<tr>
					<td><strong>E-Cess</strong></td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:60px;" readonly />
						<input name="ECessValue1" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:120px;" readonly onfocus="calculateECess1()"/></td>
					</tr>
			<tr >
					<td><strong>SAH-E Cess</strong> </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:60px;" readonly/>
						<input name="SAHCessValue1" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:120px;" readonly onfocus="calculateSAHCess1()"/></td>
					</tr>
					<tr>
					<td><strong>Total Excise Amount</strong></td>
					<td><input type="text" name="total_excise_amount" id="total_item_amount1" style="width:100%" onfocus="showexiseamt()" /></td>
					
					</tr>
                <tr>
                  <td><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="vat_cst" onchange="tax_rate1(this.value)" style="width:100%;">
	          <option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($venddata['vat_cst_per']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
              </tr>
              <?php  $taxdata=$s->getField('sales_tax_master','salestax_id',$venddata['vat_cst_per'],'taxrate'); ?>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="" readonly="true" <?php if($venddata['vat_cst_per']!='') {?> onfocus="tax_rate1(<?php echo $venddata['vat_cst_per']; ?>)" <?php } ?>/>
              </div>

	</td>
                </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per" value="<?php echo $venddata['sur_oct_per']; ?>"  size="10" onfocus="calsuroctamt(this.value)"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:60%;" onfocus="calsuroctamt1()" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:100%;" value="<?php echo $venddata['totalcharge']; ?>"     /></td>
                </tr>
				<tr>
                  <td><strong>Loading /Unloading</strong> </td>
                  <td><input type="text" name="loading" id="loading1" style="width:100%;" value="<?php echo $venddata['loading']; ?>"     /></td>
                </tr>
                <tr>
                  <td><strong>Additional Duties </strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $venddata['add_charges']; ?>" size="25" style="width:100%;" /></td>
                </tr>
				
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12"/><input type="hidden"  id="orig_grand_tot" />&nbsp;<strong>Round Off</strong>&nbsp;<select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded(this.value)">
				  <option value="">None</option>
				  <option value="+">+</option>
				  <option value="-">-</option>
				  </select></td>
                </tr>
			  </table>
    </table>
		     </td></tr>
			</table>
</div>



  <div align="center">
	<input type="submit" name="save" value="Save" onclick="return confirmPost()" />

    <input type="submit" name="reset" value="Reset" /><a href="index.php?route=Inventory/transation/material_receipt_note_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" value="Cancel" name="Back" /></a>
  </div>
	

</form>
<script language="javascript" type="text/javascript">
 function claculateExcise(i,str)
  {
	var discounted=document.getElementById("basic_"+i).value;
	if (str.length==0)
	{
	document.getElementById("exciseId_"+i).innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("exciseId_"+i).innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?mrnTaxId="+str+"&data="+i,true);
	xmlhttp.send();
}


function calculateExciseDuty(i)
{

	var basic=document.getElementById("basic_"+i).value;
	var ExcisePercentage=document.getElementById("ExcisePercentage_"+i).value;
	
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("exciseValue_"+i).value=exciseVal.toFixed(2);
}




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




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


function cal_totalamount_data()
{	

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

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



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

function 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 calcPackaging1()
{
var str=document.getElementById("pkg_perc").value;
	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 DiscountAmount(DA,i)
{


	var discount_percent = document.getElementById("PerAmo_"+i).value;
	
	var discount = DA;
	var totalPrice = document.getElementById("item_total_rate_"+i).value;
	//alert(totalPrice);
	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(DA);
	
	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);
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	//return true;
}



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

function calcExcise(str,i)
{
	var basic=document.getElementById("basic_"+i).value;
	var excise_val=basic*(str/100);
	document.getElementById("exciseValue_"+i).value=excise_val.toFixed(2);
}


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

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

function cal_grandtotal(i)
{
	var type_of_bill=document.getElementById("billing_type_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	var Totaltaxable=document.getElementById("taxableamount_"+i).value;
	if(basic==''){basic=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	//alert(type_of_bill);
	//alert(basic);
	//alert(Totaltaxable);
	if(document.getElementById("billing_type_"+i).value=='NonExcisable')
	{
	var grand_tot1=parseFloat(basic);
	var grand_tot=grand_tot1.toFixed(2);
	}	
	else if(document.getElementById("billing_type_"+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("total_"+i).value=grand_tot ;	
}


function tax_rate1(str)
{
	
	var taxableAmount=document.getElementById("total_item_amount1").value;
	var taxableAmount1=document.getElementById("pkg_charges1").value;
	if(taxableAmount1==''){taxableAmount1=0;}
	var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
	if (str.length==0)
	{
	document.getElementById("taxval").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("taxval").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_tax_valdata.php?taxid="+str+"&amt="+taxableAmount2,true);
	xmlhttp.send();
}

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

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

function cal_grandamount()
{
	var total=document.getElementById("total_item_amount1").value;
	//var loading1=document.getElementById("loading1").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	//if(loading1=='') { loading=0;)
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	//var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	/*if(roundOffVal==''){roundOffVal='-.0';}
	var test=roundOffVal.split(".");
	if(test[0]=='-')
	{
	var dot=".";
	var roundval=dot + test[1];
	document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	}
	else
	{
	var dot=".";
	var roundval=dot + test[1];
	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	}*/
	document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}

function calcRounded(str)
{
	var gtotal=document.getElementById('orig_grand_tot').value;
	var gtotal_brk=gtotal.split('.');
	if(str=='+')
	{var final=parseInt(gtotal_brk[0])+1;}
	else if(str=='-')
	{var final=parseInt(gtotal_brk[0]);}
	else if(str=='')
	{var final=gtotal;}
	document.getElementById('GrandTotal').value=final;
}


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



function checkstatus(str)
{
	var Charge = document.getElementById("Charge_"+str).value;
	var actual = document.getElementById("actual_"+str).value;
	if(Charge == 'NO' && actual == '')
	{
	alert("Please Enter Some Value Since It Is Not Inclusive");
	document.getElementById("str").focus();
	return false;
	}
}
function cal_totalcharge()
{
	var total=0;
	var countcharges = document.getElementById("countcharges").value;
	for(var j=1;j<countcharges;j++)
	{
	var actual=document.getElementById("actual_"+j).value;
	if(actual!=''){
	total=parseFloat(total)+parseFloat(actual); }
	}
	document.getElementById("chargeamount").value=total;
}



function ChargeCalculater(Amt,Amtid)
{
	var AsPerActual=document.getElementById(Amtid).value;
	var ActualType=document.getElementById("AsPerActual_" +Amtid).value;
	if(AsPerActual !='')
	{
	if(ActualType=='PercentAmt')
	{
	var Total= document.getElementById("totalqty").value;
	var charge= parseFloat(Total) * parseFloat(AsPerActual)/100;
	document.getElementById("actual_"+Amtid).value = charge;
	TotalPercent= parseFloat(TotalPercent) + parseFloat(charge);
	}
	else
	{
	document.getElementById("actual_"+Amtid).value=AsPerActual; 
	TotalAmnt=parseFloat(TotalAmnt) + parseFloat(AsPerActual);
	}
	}
	return true;
}
 
  
</script>
<script>
 
  
function checkdata(str)
{
	if(str=="Without PO")
	{
	document.getElementById("reqId").style.display = "block";
	document.getElementById("req_id").disabled=false;
	document.getElementById("vendor").disabled=false;
	document.getElementById("item_popup").disabled=false;
	document.getElementById("Purchase_Order").disabled=true;
	}	
	else if(str=="Import Purchase")
	{
	document.getElementById("reqId").style.display = "none";
	document.getElementById("req_id").disabled="none";
	document.getElementById("vendor").disabled=false;
	document.getElementById("item_popup").disabled=false;
	document.getElementById("Purchase_Order").disabled=true;
	}	
	else
	{
	document.getElementById("reqId").style.display = "none";
	document.getElementById("vendor").disabled=false;
	document.getElementById("item_popup").disabled=true;
	document.getElementById("req_id").disabled=true;
	}
}
  
  
function DiscountAmountdpc(DA,i)
{ 
 
	var discount_percent = document.getElementById("Perspc_"+i).value;
	var totalPrice = document.getElementById("NetRate_"+i).value;
	var discount = document.getElementById("special_discount_"+i).value;
	if(discount_percent=='PercentAmt' )
	{
	if(discount==''){discount=0;}
	var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
	var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
	var percent = parseFloat(document.getElementById("special_discount_"+i).value);
	if(isNaN(percent)){percent=0;}
	var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	 
	if(parseFloat(discount)>=100 && discount_percent=='PercentAmt')
	{
	alert("Discount Percentage Should Be Less Then 100");
	document.getElementById("Specialperc_"+i).value='';
	document.getElementById("special_discount_"+i).value='';
	document.getElementById("basic_"+i).value='';
	document.getElementById("special_discount_"+i).focus();
	return false;
	}
	else
	{
	document.getElementById("Specialperc_"+i).value=percent.toFixed(2);
	document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	return true;
	
	}
}
  
function checkgatentyno(str)
{
 
	if (str.length==0)
	{
	document.getElementById("entrycheck1").innerHTML='';
	alert("Must Enter Gate Entry Pass No");
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("entrycheck1").innerHTML=xmlhttp.responseText;
	
	}
	}
	xmlhttp.open("GET","gatentypass.php?str="+str,true);
	xmlhttp.send();





}  
  
  
function Get_oderdata(str)
{
		
	
if (str=="")
  {
  document.getElementById("dept").innerHTML="";
  return;
  }
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    var data=xmlhttp.responseText.split("__");	
	document.getElementById("oderitem").innerHTML=data[0];
	document.getElementById("jobcarddata").innerHTML=data[1];
    }
  }
  
xmlhttp.open("GET","get_orderdata9.php?salid="+str,true);
xmlhttp.send();	
	
}
  
  
 function calculateBillExcise(str)
{
	var value=document.getElementById("total_item_amount").value;
	if(str.length==0)
	{
	document.getElementById("totalDiscountedPrice").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("totalDiscountedPrice").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	
}

function calculateECess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").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 SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}

function showexiseamt()
{
if(document.getElementById("totalDiscountedPrice").value!='')
var amt1=document.getElementById("totalDiscountedPrice").value;
else
var amt1=0;
if(document.getElementById("ECessValue").value!='')
var amt2=document.getElementById("ECessValue").value;
else
var amt2=0;
if(document.getElementById("SAHCessValue").value!='')
var amt3=document.getElementById("SAHCessValue").value;
else
var amt3=0;
var amount=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);
document.getElementById("total_item_amount1").value=amount.toFixed(2);

}
 
  
  
</script>