<?php ob_start();
$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');
}

								$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;
				
				
				
				//********************************************************************//
					
					function get($site,$store,$date1,$item,$closqty,$closerate,$closevalue)
					{
					global $db;
					  $check_current_opening="Select * from stock_summary where date='".$date1."'
					 and site='".$site."' and store='".$store."'
					  and item='".$item."'";
					 
					
					$check_current_op_result=DB_query($check_current_opening,$db);
					if(DB_num_rows($check_current_op_result)=='0')
					{
					$closing_qty=$closqty;		
					$closing_value=$closevalue;
					$closing_rate=$closerate;	
					}
					else
					{
						$check_current_op_row=DB_fetch_array($check_current_op_result);
						$id=$check_current_op_row['id'];
						$opening_qty=$closqty;
						$opening_value=$closevalue;    
						$opening_rate=round($opening_value/$opening_qty);
						$closing_qty=$opening_qty+$check_current_op_row['inwards_qty']-$check_current_op_row['outwards_qty'];
					$closing_value=$opening_value+$check_current_op_row['inwards_value']-$check_current_op_row['outwards_value'];
						$closing_rate= round($closing_value/$closing_qty);
					
						$update_summary="Update  stock_summary set 
													opening_qty='".$opening_qty."',    
													opening_rate='".round($opening_rate,2)."',    
													opening_value='".$opening_value."', 								   
													closing_qty='".$closing_qty."',    
													closing_rate='".$closing_rate."',    
													closing_value='".$closing_value."' where id=$id ";
						$result2=DB_query($update_summary,$db);
						
						
					}
					          

                               $date2= strtotime(date("Y-m-d", strtotime($date1)) . " +1 day");
                                 $date11= date("Y-m-d",$date2);
							 		 
							    if($date11<=date('Y-m-d'))
							   {
							  
 								get($site,$store,$date11,$item,$closing_qty,$closing_rate,$closing_value);
								}		


								}	
					//**********************************************************************************//





?>
<script type="text/javascript" src="../../js/function-ajax.js" language="javascript">
</script>
<script type="text/javascript">
	function FiendPurchasenumber(str)
	{
	var a= document.getElementById('sitecode').value;
	var vendor=document.getElementById("vendor").value;
	var storecode=document.getElementById("storecode").value;
	var receipt=document.getElementById("receiviedagaist").value;
	location.replace("index.php?route=Inventory/transation/material_receipt_note_add"+"&orderno="+str+"&sitecode="+a+"&vendor="+vendor+"&storecode="+storecode+"&receipt="+receipt+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>");
	}
	function againstPR(str)
	{
	var a= document.getElementById('sitecode').value;
	var vendor=document.getElementById("vendor").value;
	var storecode=document.getElementById("storecode").value;
	var receipt=document.getElementById("receiviedagaist").value;
	location.replace("index.php?route=Inventory/transation/material_receipt_note_add"+"&pr="+str+"&sitecode="+a+"&vendor="+vendor+"&storecode="+storecode+"&receipt="+receipt+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>");
	}

	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;
	}
	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;
	}
	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 item_total_rate=parseFloat(document.getElementById('item_total_rate_'+i).value);
								var total=taxamt;
								var vatamount=(total*vatcst_per)/100;
								document.getElementById('vatcstamount_'+i).value=vatamount.toFixed(2);	
									
								}	
								else
								{
								document.getElementById('vatcstamount_'+i).value=0;	
								}
									
									
								}


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

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


					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['lrno']=$_REQUEST['lrno'];
						$_SESSION['lrdate']=$_REQUEST['lrdate'];
						$_SESSION['total_weight']=$_REQUEST['total_weight'];
						$_SESSION['RemarksIfAny']=$_REQUEST['RemarksIfAny'];
						$_SESSION['DocumentType']=$_REQUEST['DocumentType'];
					}


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

if(isset($_POST['save']))
{


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

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

	$sql1 = "select PO_Orderno from purchorders where orderno = '".$_POST['select']."' ";
	$result = DB_query($sql1, $db);
	$myrow = DB_fetch_array($result);
	$PO_Orderno = $myrow['PO_Orderno'];		
		$data['MRNNo'] = $strBothFinal; 
		$data['totalqty'] = $_REQUEST['totalqty']; 
 		$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["PO_WO_MTO"] = $_REQUEST['Purchase_Order'];  
 		$data['OrderDate'] = date("Y-m-d");//$_REQUEST['orderdate']; 
		$data['ReceivedFrom'] = $_REQUEST['vendor'];
		$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['sur_oct_amt'] = $_REQUEST['sur_oct_amt'];
		$data['tot_freight'] = $_REQUEST['tot_freight'];
		$data['add_charges'] = $_REQUEST['add_charges'];
		$data['grandtotal'] = $_REQUEST['grandtotal'];
		$data['round_off'] = $_REQUEST['round_off'];
	    $insertsql=$s->insertRecord('addmrn', $data);
 	   $insertResult = DB_query($insertsql,$db,$ErrMsg);
	   $Lastreq_id=DB_Last_Insert_ID($db,'addmrn',$ErrMsg);
 	   if($insertResult==true)
	   { 		
		$countval= count($_REQUEST['itemcode']);
		$total_basic_amount=0;
		$total_tax_amount=0;	
		$coldata1=0;
		$numdata1=0;
 		for($i=0;$i<$countval;$i++)
		{
 				if($_REQUEST['qty_as_per_bill'][$i]!='')
				{				
				$product_description = htmlspecialchars($_REQUEST['desc'][$i], ENT_QUOTES);
				$item_code = htmlspecialchars($_REQUEST['itemcode'][$i], ENT_QUOTES);
				$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['itemcode']= $item_code;
				$data_arr['description']= $product_description;
				$data_arr['Make']= $_POST['make'][$i];
				$data_arr['Color']= $_REQUEST['color'][$i];
				$data_arr['Gread']= $_REQUEST['gread'][$i];
				$data_arr['size']= $_REQUEST['size'][$i];
				$data_arr['gsm']= $_REQUEST['gsm'][$i];
				$data_arr['UOM']= $_REQUEST['uom'][$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['disc_type']= $_REQUEST['disc_type'][$i];
				$data_arr['discount']= $_REQUEST['discount'][$i];
				$data_arr['discount_amount']= $_REQUEST['discount_amount'][$i];
				$data_arr['val_after_disc']= $_REQUEST['val_after_disc'][$i];
				$data_arr['sp_disc_perc']= $_REQUEST['sp_disc_perc'][$i];
				$data_arr['sp_disc_amt']= $_REQUEST['sp_disc_amt'][$i]; 
				$data_arr['specialdis_type']=$_REQUEST['Perspc'][$i]; 				                 
				$data_arr['basic']= $_REQUEST['basic'][$i];  
				$data_arr['billing_type']= $_REQUEST['billing_type'][$i];  
				$data_arr['excise_duty']= $_REQUEST['excise_duty'][$i];  
				$data_arr['excise_perc']= $_REQUEST['excise_perc'][$i];  
				$data_arr['excise_val']= $_REQUEST['excise_val'][$i];  
				$data_arr['e_cess_perc']= $_REQUEST['e_cess_perc'][$i];  
				$data_arr['e_cess_val']= $_REQUEST['e_cess_val'][$i];  
				$data_arr['sah_perc']= $_REQUEST['sah_perc'][$i];  
				$data_arr['sah_val']= $_REQUEST['sah_val'][$i];				
				$data_arr['total_amt_with_tax']= $_REQUEST['total'][$i];
				$data_arr['remarks']= $_REQUEST['remarks'][$i];
				$data_arr['mat_value']= $_REQUEST['mat_value'][$i];			
				
				
				if($_REQUEST['short_accessid'][$i]!=0)
					{
					$pending_status=1;
					$data_arr['status']= "N";
					}
					else
					{
					 $data_arr['status']= "Y";
					}
				
				if($_REQUEST['hidden_addqty']!='')
				$data_arr['parent_id']= $_REQUEST['hidden_addqty'];
				$data_arr['rejectqty']= $_REQUEST['rejectqty'][$i];
				$data_arr['order_no']= $_REQUEST['orderno'];
				$data_arr['item_total_rate']= $_REQUEST['item_total_rate'][$i];
				$data_arr['taxamount_rate']=$_REQUEST['taxableamount'][$i];				
		        $total_basic_amount+=$data_arr['item_total_rate'];
				$total_tax_amount+=$data_arr['taxamount_rate'];	
					
					
					
								
				$insert_mrm=$s->insertRecord('addmrnqty', $data_arr);
				$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm,$db,$ErrMsg);
		/******************** insert update_mrn_qty Po QTY   **************************************/	
					
						if($_REQUEST['receiviedagaist']=='PO')
				       {
					  
					if($_REQUEST['reciveqty'][$i]>=$_REQUEST['pending_qty'][$i])
					{
						//echo "Update purchorderdetails set status='received' where 
						//orderno='".$_REQUEST['Purchase_Order']."' and mst_itemid='".$_REQUEST['mst_itemid'][$i]."'";
						
						
						$updatePO=DB_query("Update purchorderdetails set status='received' where 
						orderno='".$_REQUEST['Purchase_Order']."' and mst_itemid='".$_REQUEST['mst_itemid'][$i]."'",$db);					
					}
				}
					
				
					/**********************************************************************/
				
				
				}
					
					
							
		    }
	
      
			
			if($_REQUEST['receiviedagaist']=='PO')
			{
				$get_num_rows=DB_query("Select * from purchorderdetails where orderno='".$_REQUEST['Purchase_Order']."'",$db);
				$num_rows=DB_num_rows($get_num_rows);				
				$check_item_stat=DB_query("Select * from purchorderdetails where orderno='".$_REQUEST['Purchase_Order']."'
				 and status='received'",$db);
				$received_num_rows=DB_num_rows($check_item_stat);
				
				if($num_rows==$received_num_rows)
				{
					$updatePOStat=DB_query("Update purchorders set Po_recive_status='Receive' where 
					orderno='".$_REQUEST['Purchase_Order']."'",$db);
				}
			}
			
		
			 
		$_SESSION['success_msg']="Saved Successfully";
	echo "<script>location='index.php?route=Inventory/transation/material_receipt_note_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	    
	}
	}
	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']);
}
?>
<form action="" method="post">
<h2 align="center"><strong>Material Receipt Note</strong></h2>
<br />

<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>Mrn 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>MRN 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>Site <font color="#FF0000">*</font></strong></th>
    <td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td><?php
	if($_SESSION['AssignedSites']!='0')
	  {
	     $ss="Select loccode,locationname from locations where company='".$_SESSION['ACGCompanyId']."' and loccode in (".$_SESSION['AssignedSites'].")";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		 $ss="Select loccode,locationname from locations where company='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }
	?>
     <select name="sitecode" onchange="getreqitemdata(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['loccode'];?>"<?php echo ($sitecode==$site_row['loccode']?'selected':'')?>><?php echo $site_row['loccode'];?></option>
      <?php } ?>
    </select></td>
	  <td><div id="txtsite">
	    <?php
	
	$site_sql="Select locationname from locations where loccode ='".$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['locationname'];?>" 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="storedata">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select id, StoreCode, StoreName from storetype order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="storecode" name="storecode"  style="width:100%" onfocus="check_po()"   >
		<option value="000">Select</option> 
		<?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['StoreName']; ?></option>
		<?php }
		?>
		</select>		</td>
        <!--<td><div id="txtid"><input type="text" name="storename" id="storename" size="20" readonly="true" value="<?php echo $storename; ?>"></div></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="PO"<?php if($_REQUEST['receiviedagaist']=="PO") {?> selected="selected"<?php } ?>>PO</option>
    <option value="Without PO" <?php if($_REQUEST['receiviedagaist']=="Without PO") {?> selected="selected"<?php } ?>>Without PO</option> 	
    </select>    </td>
    <th scope="row"><strong>Recevied From  <font color="#FF0000">*</font></strong></th>
    <td colspan="2">
    	<!--+document.getElementById('sitecode').value-->
<select name="vendor" id="vendor"  style="width:100%"  onchange="ShowDiv(this.value,'hid_POrder','disp_porder.php?receipt='+document.getElementById('receiviedagaist').value+'&site='+document.getElementById('sitecode').value)" >
			<!--<select name="vendor" id="vendor"  style="width:100%"  onchange="ShowDiv(this.value,'hid_POrder','disp_porder.php?site='+document.getElementById('sitecode').value)" >-->
			<option value="000" >---Select1---</option>
			<?php
			$sql="select id  ,vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			$p='';
			if($vendor==$myrow['id'])
			$p="selected";
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo  str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
			</select></td>    
</tr>
<tr>
    <th scope="row"><strong>PO</strong></th>
    <td colspan="2">
	<div id='hid_POrder'>
	<?php
 //$sql="select orderno, PO_Orderno from purchorders Where Po_recive_status='Pending'";
	//$result = DB_query($sql,$db);
	
if($_REQUEST['receipt']=="PO")
{
	?>
	<select name="Purchase_Order" id="Purchase_Order" onchange="FiendPurchasenumber(this.value)"  style="width:100%" >
      <?php 	



$sql=DB_query("select * from purchorders where orderno='".$_REQUEST['orderno']."'",$db);
while ($rsdesig=DB_fetch_array($sql)){
		
	?>
      <option value="<?php  echo $rsdesig['orderno'];?>" <?php echo ($PurchaseOrder==$rsdesig['orderno']?'selected':'')?>><?php echo $rsdesig['PO_Orderno'];?></option>
      <?php }?>
    </select>
	<?php }  ?>
	</div> </td>
    <th><strong>Order Date </strong></th>
    <td colspan="2"><?php
	   if($_REQUEST['receipt']=='PO')
	   { 
	   $date_sql="Select orddate from purchorders where orderno='".$_REQUEST['orderno']."' ";
	   $date_res=DB_query($date_sql,$db);
	   $date_row=DB_fetch_array($date_res);
	   $Order_Date=$date_row['orddate'];
	   ?>
	    <input type="text" name="orderdate" id="orderdate" value="<?php echo ConvertSQLDate($Order_Date); ?>" readonly="true" style="width:100%" >
		<?php }else{
	    ?>
	   <input type="text" name="orderdate" id="orderdate" value="<?php if(isset($_SESSION['orderdate'])) echo $orderdate; else echo date('d/m/Y'); ?>" readonly="true" class="datepicker" style="width:100%" ></td>
	   <?php } ?>
  </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)"; /></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'";}
?>
<div id="reqId" <?php echo $display;?>>
<table width="100%">
<tr>
 <th width="35px">PR No. </th>
    <td id="pr_no">
	<?php 
	$sql3="Select requisitionno, Reqno from materialrequisitions where sitecode='".$sitecode."'";
	  $result3=DB_query($sql3,$db);
	  ?>
	  <select name='req_no' style='width:150px' id='req_id' onchange='againstPR(this.value)'>
	  <option value=''>Select</option><?php 
	  while($row3=DB_fetch_array($result3))
	  {?>
	  	<option value='<?php echo $row3['requisitionno'];?>' <?php if($req_no==$row3['requisitionno']) echo "selected";?>><?php echo $row3['Reqno'];?></option><?php
	  }?>
	  </select>
    </td>
  </tr>
</table>
</div>



	<?php if($_REQUEST['receipt']=='PO' )
	{
		$disabled="disabled";
	}
else
	{
		$disabled='';
	}
		?>
		
		
	 <p align="left"><input type="submit"  name="item_popup" value="Add Items" id="item_popup"  onclick="open_items();"  <?php echo $disabled; ?> /></p>
	 

 
<?php 
if($_REQUEST['receipt']=='PO')
{


				$CR=1;
				  $Vendor_Quot_No=$s->GetFieldValue('purchorders',"orderno ='".$_GET['orderno']."'",'mst_vendor_quotesid');
				  
 				?>
<fieldset><legend><strong>ITEM DETAILS</strong></legend>
<div style="overflow:auto; width:790px ; height:170px"  >
  <table width="100%" border="1" cellspacing="1" cellpadding="2">
    <tr>
      <th scope="col"><strong>S. NO.</strong></th>
      <th scope="col"><strong>ITEM CODE </strong></th>
      <th scope="col"><strong>DESCRIPTION</strong></th>
      <th scope="col"><strong>MAKE</strong></th>
      <th scope="col"><strong>GRADE</strong></th>
      <th scope="col"><strong>COLOR</strong></th>
      <th scope="col"><strong>UOM</strong></th>
      <th scope="col"><strong>PO QTY </strong></th>
      <th scope="col"><strong>Pending QTY </strong></th>
      <th scope="col"><strong>QTY AS PER BILL </strong></th>
      <th scope="col"><strong>QTY RECEIVED</strong></th>
      <th scope="col"><strong>SHORT QUANTITY </strong></th>
      <th scope="col"><strong>RATE</strong></th>
      <th scope="col"><strong>TOTAL ITEM PRICE</strong></th>
      <th scope="col"><strong>DISCOUNT TYPE</strong></th>
      <th scope="col"><strong>DISCOUNT %</strong></th>
      <th scope="col"><strong>DISCOUNT AMT.</strong></th>
      <th scope="col"><strong>SUB TOTAL</strong></th>
      <th scope="col"><strong>SPL. DISC. Amt</strong></th>
      <th scope="col"><strong>SPL. DISC. %</strong></th>
      <th scope="col"><strong>SPL. DISC. AMT.</strong></th>
      <th scope="col"><strong>BASIC AMT.</strong></th>
      <th scope="col"><strong>EXCISE FLAG</strong></th>
      <th scope="col"><strong>EXCISE</strong></th>
      <th scope="col"><strong>E-CESS</strong></th>
      <th scope="col"><strong>SAH-CESS</strong></th>
      <th scope="col"><strong>Excise Amount</strong></th>
      <th scope="col"><strong>Total Amount</strong></th>
      <!-- <th scope="col"><strong>TAX TYPE </strong></th>
    <th scope="col"><strong>TAX RATE </strong></th>
    <th scope="col"><strong>TAX VALUE </strong></th>
    <th scope="col"><strong>VALUE WITH TAX </strong></th>-->
      <th scope="col"><strong>REMARKS</strong></th>
    </tr>
    <?php		
 $i=0;
//echo "select * from purchorderdetails where orderno='".$_GET['orderno']."'";
$ql_purch_details=DB_query("select * from purchorderdetails where orderno='".$_GET['orderno']."' and  status='Pending'",$db);

while($purchdetails_row=DB_fetch_array($ql_purch_details)){


$vend=DB_query("select * from  venderquotations where id='".$Vendor_Quot_No."'",$db); 
$venddata=DB_fetch_array($vend);	

//echo $Vendor_Quot_No;

 $vat_cst_per=$venddata['vat_cst_per'];
 $Taxsql="SELECT id,tax_code, taxrate FROM service_tax_master where id='".$venddata['vat_cst_per']."'";
				$Taxresult=DB_query($Taxsql,$db); 
				$Taxmyrow=DB_fetch_array($Taxresult);
				
?>
    <input type="hidden"  name="vatper" size="10" id="vatper" value="<?php echo $Taxmyrow['taxrate'];?>" />
    <?php
 $sql="SELECT * FROM vendorquotationdetails WHERE quotation_no='". $Vendor_Quot_No."' and mst_productid='".$purchdetails_row['mst_itemid']."'";


$Itemrow=DB_fetch_array($result=DB_query($sql,$db));



$aks=DB_query("SELECT * FROM purchorders_ammd where against_po_id='".$_GET['orderno']."' order by revision_no desc limit 1",$db);
if(DB_num_rows($aks)>0)
{
$aks1=DB_fetch_array($aks);
$XYZ=DB_query("select * from purchorderdetails_ammd where orderno='".$aks1['orderno']."' and mst_itemid='".$purchdetails_row['mst_itemid']."'",$db);
$XYZ1=DB_fetch_array($XYZ);
	
	 $tq=$XYZ1['rate'];
	
}
else {

$tq=$Itemrow['rate'];
}
$discount_type=$Itemrow['discount_type'];
$discount=$Itemrow['discount'];
$discount_amount=$Itemrow['discount_amount'];
$sub_total=$Itemrow['sub_total'];
$specialdiscounttype=$Itemrow['specialdis_type'];
$specialdiscount=$Itemrow['specialdiscount'];
$specialdiscount_amount=$Itemrow['specialdiscount_amount'];
$basic_amt=$Itemrow['basic_amt'];
$tax_type=$Itemrow['tax_type'];
$Excise_Duty=$Itemrow['Excise_Duty'];
$ExcisePercentage=$Itemrow['ExcisePercentage'];
$Excise_Duty_value=$Itemrow['Excise_Duty_value'];
$Edu_Cess_perc=$Itemrow['Edu_Cess_perc'];
$Edu_Cess=$Itemrow['Edu_Cess'];
$SHE_Cess_perc=$Itemrow['SHE_Cess_perc'];
$SHE_Cess=$Itemrow['SHE_Cess'];
$taxable_amt=$Itemrow['taxable_amt'];
$taxable_amt=$Itemrow['taxable_amt'];
$total_amount=$Itemrow['total_amount'];
$ExcisePercentage=$Itemrow['ExcisePercentage'];
$Edu_Cess_perc=$Itemrow['Edu_Cess_perc'];
$SHE_Cess_perc=$Itemrow['SHE_Cess_perc'];
$Excise_Duty=$Itemrow['Excise_Duty'];
$freight=$Itemrow['fright'];

	$sql_query_update=DB_fetch_array(DB_query("SELECT * FROM update_mrn_qty where order_no='".$_GET['orderno']."' and itemcode='".$Itemrow['prod_id']."' and status='0'", $db));
	$make=DB_query("SELECT * FROM requisitionorderdetails where requsitionno='".$Itemrow['requisition_no']."'", $db);
	$make_row=DB_fetch_array($make);
	
	$shortqty=DB_query("select close_qty from purchorderdetails where 
	orderno='".$_GET['orderno']."' and mst_itemid='".$Itemrow['mst_productid']."'",$db);
	$short_qty=DB_fetch_array($shortqty);
	if($short_qty['close_qty']=='') $closeqty1=0; else $closeqty1=$short_qty['close_qty'];
	  $check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	  where order_no='".$_GET['orderno']."' and mst_itemid='".$Itemrow['mst_productid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']+$closeqty1);
	}
	else{$pending_qty=$purchdetails_row['quatity']-$closeqty1;}	
	
	  
	  //$s->getField('addmrnqty','issue_id',$qtydata,'reciveqty');
	?>
    <?php //if($sql_query_update['status']=='0')  
	//{
		?>
    <tr id="txt_order">
      <td><?php echo $i+1;?></td>
      <input type="hidden"  name="Excise_Duty[]" size="10" id="Excise_Duty_<?php echo $i; ?>" value="<?php echo $Excise_Duty;?>" />
      <input type="hidden"  name="ExcisePercentage[]"     size="10" id="ExcisePercentage_<?php echo $i; ?>" value="<?php echo $ExcisePercentage;?>" />
      <input type="hidden"  name="Edu_Cess_perc[]" size="10" id="Edu_Cess_perc_<?php echo $i; ?>" value="<?php echo $Edu_Cess_perc;?>" />
      <input type="hidden"  name="SHE_Cess_perc[]" size="10" id="SHE_Cess_perc_<?php echo $i; ?>" value="<?php echo $SHE_Cess_perc;?>" />
      <td><input type="hidden"   name="qcreqd[]" size="10" value="<?php echo $numrow;?>" />
          <input type="hidden"   name="hidden_addqty[]" size="10" value="<?php echo $Itemrow['id'];?>" />
          <input type="hidden" value="" id="user_shipping[<?php echo $i;?>]" name="user_shipping[<?php echo $i;?>]3" />
          <?php echo $Itemrow['prod_id'];?>
          <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15" onblur="PO_order(this.value)" value="<?php echo $Itemrow['prod_id'] ?>" />
          <input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]" size="15" value="<?php echo $Itemrow['mst_productid'] ?>" />
          <input type="hidden" name="orderno"  id="orderno" onblur="PO_order(this.value)"  value="<?php echo $_REQUEST['orderno'];?>" /></td>
      <td><?php echo $Itemrow['prod_dec'] ?>
          <input type="hidden" name="desc[]"   id="desc[]" size="25" value="<?php echo $Itemrow['prod_dec'] ?>"/></td>
      <td><?php
	  echo $make1_name1=$s->getField('product_manufacture','id',$make_row['make'],'manufacturer');
	    ?>
          <input name="make[]" id="make[]" type="hidden" value="<?php echo $make1_name1 ?>" /></td>
      <td><?php $gradename=$s->getField('product_grade','id',$make_row['grade'],'grade');
          echo $gradename ?>
          <input name="gread[]" id="gread[]" type="hidden" value="<?php echo $gradename ?>" /></td>
      <td><?php $colorname=$s->getField('product_color','id',$make_row['color'],'color');
           echo $colorname ?>
          <input name="color[]" id="color[]" type="hidden" value="<?php echo $colorname ?>" /></td>
      <td><?php $unitname=$s->getField('unitsofmeasure','unitid',$Itemrow['uom'],'unitname');
         echo $unitname;?>
          <input name="uom[]" id="uom[]" type="hidden" value="<?php echo $Itemrow['uom'] ?>" /></td>
      <td><?php   echo $poqty=$purchdetails_row['quatity']; ?>
          <input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
      <td><?php   echo $pending_qty;?>
          <input type="hidden" name="pending_qty[]" id="pendingqty_<?php echo $i;?>" value="<?php echo $pending_qty;?>" />
      </td>
      <td><input name="qty_as_per_bill[]2" type="text" id="qty_as_per_bill_<?php echo $i;?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
	  <?php $tolerance=$s->getField('item_master','id',$Itemrow['mst_productid'],'tolerance');  ?>
	  <input type="hidden" name="tolerance[]" id="tolerance_<?php echo $i;?>" value="<?php echo $tolerance;?>" />
	  </td>
      <td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i;?>"  size="8"  onkeyup="check_bill_qty(this.value,<?php echo $i;?>)"  /></td>
      <td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i;?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
      <td><?php echo $tq;?>
          <input name="itemrate[]" type="hidden" id="itemrate_<?php echo $i;?>" value="<?php echo  $Itemrow['rate'];?>"  size="8"/></td>
      <td><input name="item_total_rate[]" type="text" id="item_total_rate_<?php echo $i; ?>" value="" size="8" onfocus="calc_total_price(<?php echo $i;?>)"/></td>
      <td><select style="width:80px;" name="disc_type[]" id="PerAmo_<?php echo $i;?>">
        <option value="Amount" <?php echo ($discount_type=='Amount')?'selected':''?>>Amount</option>
        <option value="PercentAmt"<?php echo ($discount_type=='PercentAmt')?'selected':''?>>Percent Amt</option>
      </select></td>
      <td><input type="text" style="width:40px" name="discount[]" id="discount_<?php echo $i;?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" value="<?php echo $discount;?>" /></td>
      <td><input type="text" style="width:35px" name="discount_amount[]" id="perc_<?php echo $i;?>"  readonly="true" onfocus="Check(this.value,<?php echo $i;?>)" value="<?php echo $discount_amount;  ?>"/></td>
      <td><input type="text"  id="NetRate_<?php echo $i;?>" name="val_after_disc[]" style="width:70px;" readonly value=""/></td>
      <td><select style="width:100%;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
        <option value="Amount" <?php echo ($_POST['Perspc']=='Amount'|| $specialdiscounttype=='Amount')?'selected':''?>>Amount</option>
        <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt' || $specialdiscounttype=='PercentAmt')?'selected':''?>>Percent Amt</option>
      </select></td>
      <td><input type="text" name="sp_disc_perc[]" id="special_discount_<?php echo $i;?>" size="10" style="width:35px;" onblur="DiscountAmountdpc(this.value,<?php echo $i;?>)" value="<?php echo $specialdiscount;?>" /></td>
      <td><input type="text"  name="sp_disc_amt[]" id="Specialperc_<?php echo $i;?>"  style="width:70px;" onfocus="check1(this.value,<?php echo $i;?>)" value="<?php echo $specialdiscount_amount;?>"/></td>
      <td><input type="text" style="width:70px" id="basic_<?php echo $i;?>" readonly value=""/></td>
      <td><input type="text" style="width:70px" id="billing_type[]" name="billing_type[]" readonly value="<?php echo $tax_type;?>"/></td>
      <td><select name="excise_duty[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;" onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
        <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase' and id=".$Excise_Duty."",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
        <option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
        <?php 	
			}
    	    ?>
      </select>
	  <?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++;
			 } 
			 ?>
          <input type="text" name="excise_perc[]" id="ExcisePercentage_<?php echo $i;?>" value="<?php echo $ExcisePercentage;?>" size="5" onblur="calcExcise(this.value,<?php echo $i;?>)" />
        <input type="text" name="excise_val[]" id="exciseValue_<?php echo $i;?>" value="" size="10"  onfocus="calculateExciseDuty(<?php echo $_REQUEST['data']; ?>)"/></td>
       <td><input name="e_cess_perc[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly onfocus="caldata(<?php echo $i;?>)"  /><input name="e_cess_val[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $Edu_Cess;?>"  style="width:70px;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>
	  <td><input name="sah_perc[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/><input name="sah_val[]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $SHE_Cess;?>"  style="width:65px;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
          
		  <td><input name="taxableamount[]" type="text" id="taxableamount_<?php echo $i?>" value="" size="12"  onfocus="caltaxamout(<?php echo $i;?>)" /></td>
          
          <td><input name="total[]" type="text" id="total_<?php echo $i?>" value="" size="12" readonly="true" onfocus="value_after_discount(<?php echo $i ?>);"/></td>
         
    
          <td><input type="text" name="remarks[]" id="remarks[]" value=""/></td>  
		  
         </tr>
    <?php $i++;} 
	//} ?>
    <input type="hidden" name="countval" value="<?php echo $i; ?>"  id="count"/>
  </table>
</div>
</fieldset>
<br>
<?php } 
if($_REQUEST['type']=='Direct')
{
?>
<fieldset><legend><strong>ITEM DETAILS</strong></legend>
 <div style="width:790px ;"  >
      
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
		
		<div style="overflow:auto; width:790px;">
	<table width="100%" border="1" cellspacing="1" cellpadding="2">
        <tr>
		
          <th scope="col"><strong>S. NO. </strong></th>
          <th scope="col"><strong>ITEM CODE </strong></th>
          <th scope="col"><strong>DESCRIPTION</strong></th>
          <th scope="col"><strong>MAKE</strong></th>
          <th scope="col"><strong>GRADE</strong></th>
          <th scope="col"><strong>COLOR</strong></th>
          <th scope="col"><strong>UOM</strong></th>
          <!-- <th scope="col"><strong>QTY </strong></th>-->
          <th scope="col"><strong>QTY AS PER BILL </strong></th>
          <th scope="col"><strong>QTY RECEIVED</strong></th>
          <th scope="col"><strong>SHORT QUANTITY </strong></th>
          <th scope="col"><strong>RATE</strong></th>
          <th scope="col"><strong>TOTAL ITEM PRICE</strong></th>      
          
          <th scope="col"><strong>DISCOUNT TYPE</strong></th>
	   <th scope="col"><strong>DISCOUNT %</strong></th>
	 <th scope="col"><strong>DISCOUNT AMT.</strong></th> 
	  <th scope="col"><strong>SUB TOTAL</strong></th> 
	    <th scope="col"><strong>SPL. DISC. Type</strong></th> 
	   <th scope="col"><strong>SPL. DISC. %</strong></th> 
	   <th scope="col"><strong>SPL. DISC. AMT.</strong></th>  
	   <th scope="col"><strong>BASIC AMT.</strong></th> 
	    <th scope="col"><strong>EXCISE FLAG</strong></th> 
	   <th scope="col"><strong>EXCISE</strong></th> 
	    <th scope="col"><strong>E-CESS</strong></th>
	    <th scope="col"><strong>SAH-CESS</strong></th>
          
          
          
          
          <th scope="col"><strong>EXCISE AMOUNT</strong></th>
      
          <th scope="col"><strong>REMARKS</strong></th>
        </tr>
		</table></div></td></tr>
		
		
		
		
		
		
		
		
		
		
      
		
	
    <tr>
	<td>
	<div style="overflow:auto; height:130px; width:790px;">
		<table width="100%" border="1" cellspacing="0" cellpadding="4">
        <?php		
 $i=0;

if($_SESSION['manvi_new']!='')
{
	

 $itemlist=array();
//print_r($_SESSION['ACGRequisition-ItemList']);
$itemlist=explode('#',$_SESSION['manvi_new']);
//print_r($itemlist);
?>
        <?php 
	for($i=0;$i<count($itemlist);$i++)
	{
//	echo "select * from item_master where StockID='".$itemlist[$i]."'";

	 $itemquery=DB_query("select * from item_master where StockID='".$itemlist[$i]."'" , $db);
	 //echo "select StockID,item_name,unit, make ,grade, color from item_master where StockID='".$itemlist[$i]."'" ;
	while($item_row=DB_fetch_array($itemquery))
	{
		/*if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";*/	
	?>
	
		<tr>
		<tr id="txt_order">
          <td><?php echo $i+1;?></td>
          <td><input type="hidden"   name="qcreqd[]" size="10" value="<?php echo $numrow;?>" />
              <input type="hidden"   name="hidden_addqty[]" size="10" value="<?php echo $item_row['id'];?>" />
              <input type="hidden" value="" id="user_shipping[<?php echo $i;?>]" name="user_shipping[<?php echo $i;?>]" />
              <?php echo $item_row['StockID'];?>
              <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15" onblur="PO_order(this.value)" value="<?php echo $item_row['StockID'] ?>" />
              <input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]" size="15" value="<?php echo $item_row['id'] ?>" />
              <input type="hidden" name="orderno"  id="orderno" onblur="PO_order(this.value)"  value="" /></td>
          <td><?php echo $item_row['item_name'] ?>
              <input type="hidden" name="desc[]"   id="desc[]" size="25" value="<?php echo $item_row['item_name'] ?>"/></td>
          <td><?php 
$makename=$s->getField('product_manufacture','id',$item_row['make'],'manufacturer');
echo $makename; ?>
              <input name="make[]" id="make[]" type="hidden" value="<?php echo $item_row['make'] ?>" /></td>
          <td><?php 
$gradename=$s->getField('product_grade','id',$item_row['grade'],'grade');
echo $gradename ?>
              <input name="gread[]" id="gread[]" type="hidden" value="<?php echo $item_row['grade'] ?>" /></td>
          <td><?php 
$colorname=$s->getField('product_color','id',$Itemrow['color'],'color');
echo $colorname ?>
              <input name="color[]" id="color[]" type="hidden" value="<?php echo $item_row['color'] ?>" /></td>
          <td><?php 
$unitname=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitname;?>
              <input name="uom[]" id="uom[]" type="hidden" value="<?php echo $item_row['unit'] ?>" /></td>
          <!-- <td><input name="poqty[]" type="text" id="poqty_<?php echo $i; ?>" value="" size="10"/></td>-->
          <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i?>" value="" size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/></td>
          <td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i?>"    size="8"  value="<?php echo $_REQUEST['reciveqty'][$i];?>"/></td>
          <td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
          <td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i?>" value=""  size="8"/></td>
          <td><input name="item_total_rate[]" type="text" id="item_total_rate_<?php echo $i?>" value="" size="8" onfocus="calc_total_price(<?php echo $i;?>)"/></td>
          
          
          
          
           <td><select style="width:80px;" name="disc_type[]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount">Amount</option>
            <option value="PercentAmt">Percent Amt</option></select></td>
	  <td><input type="text" style="width:40px" name="discount[]" id="Discount_<?php echo $i;?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" value="<?php echo $discount;?>" /></td>
	  <td><input type="text" style="width:35px" name="discount_amount[]" id="perc_<?php echo $i;?>"  readonly="true" onfocus="Check(this.value,<?php echo $i;?>)" value="<?php echo $discount_amount;?>"/></td>
	  <td><input type="text"  id="NetRate_<?php echo $i;?>" name="val_after_disc[]" style="width:70px;" readonly value="<?php echo $sub_total;?>"/></td>
	  <td><select style="width:100%;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['Perspc']=='Amount'|| $specialdiscounttype=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt' || $specialdiscounttype=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
	  <td><input type="text" name="sp_disc_perc[]" id="special_discount_<?php echo $i;?>" size="10" style="width:35px;" onblur="DiscountAmountdpc(this.value,<?php echo $i;?>)" value="<?php echo $specialdiscount;?>" /></td>
	  <td><input type="text"  name="sp_disc_amt[]" id="Specialperc_<?php echo $i;?>"  style="width:70px;" onfocus="check1(this.value,<?php echo $i;?>)" value="<?php echo $specialdiscount_amount;?>"/></td>
	  <td><input type="text" style="width:70px" id="basic_<?php echo $i;?>" name="basic[]" readonly value="<?php echo $basic_amt?>"/></td>
	  <td><select name="billing_type[]" style="width:85px" id="billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,<?php echo $i; ?>)">
	<option value="">Select</option>
	<option value="NonExcisable">NonExcisable</option>
	<option value="Excisable">Excisable</option>
	<option value="IncludeTax">IncludeTax</option>
</select></td>
	  <td><select name="excise_duty[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;" onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
	  	<option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select><div id="exciseId_<?php echo $i; ?>"></div></td>
  	      <?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
	  <td><input name="e_cess_perc[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly onfocus="caldata(<?php echo $i;?>)"  /><input name="e_cess_val[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $Edu_Cess;?>"  style="width:70px;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>
	  <td><input name="sah_perc[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/><input name="sah_val[]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $SHE_Cess;?>"  style="width:65px;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
          
          <td><input name="taxableamount[]" type="text" id="taxableamount_<?php echo $i?>" value="" size="12"  onfocus="caltaxamout(<?php echo $i;?>)" /></td>
          
          <td><input name="total[]" type="text" id="total_<?php echo $i?>" value="" size="12" readonly="true" onfocus="value_after_discount(<?php echo $i ?>);"/></td>
          <!--<td><input name="item_total_rate[]" type="text" id="item_total_rate_<?php echo $i; ?>" value="" size="8" onfocus="calc_total_price(<?php echo $i;?>)"/></td>
      <td><input name="discount_amount[]" type="text" id="discount_amount_<?php echo $i;?>" value="<?php echo ($_REQUEST['discount_amount'][$i]+$_REQUEST['specialdiscount_amount'][$i]); ?>" size="12" readonly="true" /></td>
      <td><input name="val_after_disc[]" type="text" id="val_after_disc_<?php echo $i;?>" value="<?php echo $_REQUEST['val_after_disc'][$i];?>" size="12" readonly="true" onfocus="value_after_discount(<?php echo $i ?>);"/></td>
      -->
          <td><input type="text" name="remarks[]" id="remarks[]" value=""/></td>
        </tr>
        <?php } }  ?>
     
		</table></div></td></tr>
        <input type="hidden" name="countval2" value="<?php echo $i; ?>" id="count"/>
	</table>
    </div>
</fieldset>
   
  <?php }}
if($_REQUEST['pr']!='')
{?>
<fieldset><legend><strong>ITEM DETAILS</strong></legend>
<div style="overflow:auto; width:790px ; height:170px"  >
  <table width="100%" border="1" cellspacing="1" cellpadding="2">
   <tr>
          <th scope="col"><strong>S. NO. </strong></th>
          <th scope="col"><strong>ITEM CODE </strong></th>
          <th scope="col"><strong>DESCRIPTION</strong></th>
          <th scope="col"><strong>MAKE</strong></th>
          <th scope="col"><strong>GRADE</strong></th>
          <th scope="col"><strong>COLOR</strong></th>
          <th scope="col"><strong>UOM</strong></th>
          <!-- <th scope="col"><strong>QTY </strong></th>-->
          <th scope="col"><strong>QTY AS PER BILL </strong></th>
          <th scope="col"><strong>QTY RECEIVED</strong></th>
          <th scope="col"><strong>SHORT QUANTITY </strong></th>
          <th scope="col"><strong>RATE</strong></th>
          <th scope="col"><strong>TOTAL ITEM PRICE</strong></th>          
          <th scope="col"><strong>DISCOUNT TYPE</strong></th>
	   <th scope="col"><strong>DISCOUNT %</strong></th>
	 <th scope="col"><strong>DISCOUNT AMT.</strong></th> 
	  <th scope="col"><strong>SUB TOTAL</strong></th> 
	   <th scope="col"><strong>SPL. DISC. Type</strong></th> 
	  <th scope="col"><strong>SPL. DISC. %</strong></th> 
	   <th scope="col"><strong>SPL. DISC. AMT.</strong></th>  
	   <th scope="col"><strong>BASIC AMT.</strong></th> 
	    <th scope="col"><strong>EXCISE FLAG</strong></th> 
	   <th scope="col"><strong>EXCISE</strong></th> 
	    <th scope="col"><strong>E-CESS</strong></th>
	    <th scope="col"><strong>SAH-CESS</strong></th>
          <th scope="col"><strong>EXCISE AMOUNT</strong></th>
          <th scope="col"><strong>TOTAL AMOUNT</strong></th>
          <th scope="col"><strong>REMARKS</strong></th>
        </tr>
<?php
	$req_sql="Select * from requisitionorderdetails where requsitionno=".$_REQUEST['pr']."";
	$req_res=DB_query($req_sql,$db);
	$i=0;
	while($req_row=DB_fetch_array($req_res))
	{
		
		if($req_row['mst_itemid']!=''){
		//echo "select * from item_master where id='".$req_row['mst_itemid']."'";
		$itemquery=DB_query("select * from item_master where id='".$req_row['mst_itemid']."'" , $db); }
		else{
		//echo "select * from item_master where StockID='".$req_row['product_id']."'";
		$itemquery=DB_query("select * from item_master where StockID='".$req_row['product_id']."'" , $db);}
		$item_row=DB_fetch_array($itemquery);
	?>
	<tr id="txt_order">
          <td><?php echo $i+1;?></td>
          <td><input type="hidden"   name="qcreqd[]" size="10" value="<?php echo $numrow;?>" />
              <input type="hidden"   name="hidden_addqty[]" size="10" value="<?php echo $item_row['id'];?>" />
              <input type="hidden" value="" id="user_shipping[<?php echo $i;?>]" name="user_shipping[<?php echo $i;?>]" />
              <?php echo $item_row['StockID'];?>
              <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15" onblur="PO_order(this.value)" value="<?php echo $item_row['StockID'] ?>" />
              <input type="hidden" readonly="" id="itemcode[]" name="mst_itemid[]" size="15" value="<?php echo $item_row['id'] ?>" /></td>
          <td><?php echo $item_row['item_name'] ?>
              <input type="hidden" name="desc[]"   id="desc[]" size="25" value="<?php echo $item_row['item_name'] ?>"/></td>
          <td><?php 
$makename=$s->getField('product_manufacture','id',$req_row['make'],'manufacturer');
echo $makename; ?>
              <input name="make[]" id="make[]" type="hidden" value="<?php echo $req_row['make'] ?>" /></td>
          <td><?php 
$gradename=$s->getField('product_grade','id',$req_row['grade'],'grade');
echo $gradename ?>
              <input name="gread[]" id="gread[]" type="hidden" value="<?php echo $req_row['grade'] ?>" /></td>
          <td><?php 
$colorname=$s->getField('product_color','id',$req_row['color'],'color');
echo $colorname ?>
              <input name="color[]" id="color[]" type="hidden" value="<?php echo $req_row['color'] ?>" /></td>
          <td><?php 
$unitname=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitname;?>
              <input name="uom[]" id="uom[]" type="hidden" value="<?php echo $item_row['unit'] ?>" /></td>
          <!-- <td><input name="poqty[]" type="text" id="poqty_<?php echo $i; ?>" value="" size="10"/></td>-->
          <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i?>" value="" size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/></td>
          <td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i?>"    size="8"  value="<?php echo $_REQUEST['reciveqty'][$i];?>"/></td>
          <td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
          <td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i?>" value=""  size="8"/></td>
          <td><input name="item_total_rate[]" type="text" id="item_total_rate_<?php echo $i?>" value="" size="8" onfocus="calc_total_price(<?php echo $i;?>)"/></td>
          
          
          
          
           <td><select style="width:80px;" name="disc_type[]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount" <?php echo ($discount_type=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($discount_type=='PercentAmt')?'selected':''?>>Percent Amt</option></select></td>
	  <td><input type="text" style="width:40px" name="discount[]"  onblur="DiscountAmount(this.value,<?php echo $i;?>)" value="<?php echo $discount;?>" /></td>
	  <td><input type="text" style="width:35px" name="discount_amount[]" id="perc_<?php echo $i;?>"  readonly="true" onfocus="Check(this.value,<?php echo $i;?>)" value="<?php echo $discount_amount;?>"/></td>
	  <td><input type="text"  id="NetRate_<?php echo $i;?>" name="val_after_disc[]" style="width:70px;" readonly value="<?php echo $sub_total;?>"/></td>
	  <td><select style="width:100%;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['Perspc']=='Amount'|| $specialdis_type=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt' || $specialdis_type=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
	  <td><input type="text" name="sp_disc_perc[]" id="special_discount_<?php echo $i;?>" size="10" style="width:35px;" onblur="DiscountAmountdpc(this.value,<?php echo $i;?>)"  value="<?php echo $specialdiscount;?>" /></td>
	  <td><input type="text"  name="sp_disc_amt[]" id="Specialperc_<?php echo $i;?>"  style="width:70px;" onfocus="check1(this.value,<?php echo $i;?>)" value=""/></td>
	  <td><input type="text" style="width:70px" id="basic_<?php echo $i;?>" name="basic[]" readonly value="<?php echo $basic_amt?>"/></td>
	  <td><select name="billing_type[]" style="width:85px" id="billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,<?php echo $i; ?>)">
	<option value="">Select</option>
	<option value="NonExcisable">NonExcisable</option>
	<option value="Excisable">Excisable</option>
	<option value="IncludeTax">IncludeTax</option>
</select></td>
	  <td><select name="excise_duty[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;" onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
	  	<option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select><div id="exciseId_<?php echo $i; ?>"></div></td>
  	      <?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
	  <td><input name="e_cess_perc[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly onfocus="caldata(<?php echo $i;?>)"  /><input name="e_cess_val[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $Edu_Cess;?>"  style="width:70px;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>
	  <td><input name="sah_perc[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/><input name="sah_val[]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $SHE_Cess;?>"  style="width:65px;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
      <td><input name="taxableamount[]" type="text" id="taxableamount_<?php echo $i?>" value="" size="12"  onfocus="caltaxamout(<?php echo $i;?>)" /></td>
      <td><input name="total[]" type="text" id="total_<?php echo $i?>" value="" size="12" readonly="true" onfocus="value_after_discount(<?php echo $i ?>);"/></td>
      <td><input type="text" name="remarks[]" id="remarks[]" value=""/></td>
        </tr>
    <?php $i++;} 
	 ?>
    <input type="hidden" name="countval" value="<?php echo $i; ?>"  id="count"/>
  </table>
</div>
</fieldset>
<br><?php 
}
 ?>
<div align="right">			
			<table width="40%">
			<tr><th>
		      <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>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_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['id']; ?>"<?php echo ($venddata['vat_cst_per']==$Taxmyrow['id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
              </tr>
              <?php  $taxdata=$s->getField('service_tax_master','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>Additional Charges</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>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" 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>
		     </th>
		<td>		</td>
		</tr>
			</table>
</div>
  <div align="center">
  <?php if($_REQUEST['type']=='Direct' || $_REQUEST['pr']!=''){ ?>
    <input type="submit" name="save" value="Save" onclick="return confirmPost1()" />
	<?php }else{ ?>
	<input type="submit" name="save" value="Save" onclick="return confirmPost()" />
	<?php } ?>
    <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>
<?php 
if($_REQUEST['type']=='Direct' || $_REQUEST['pr']!=''){
	$sqlmax="SELECT max_price FROM direct_mrn_config";
	$resultmax=DB_query($sqlmax,$db); 
	$rowmax=DB_fetch_array($resultmax);
?>
<input type="hidden" name="max_price" id="max_price" value="<?php echo $rowmax['max_price'];;?>" />
<?php }?>
	</div>
</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()
{	
	var total=0;
	var t=document.getElementById("count").value;
	for(var i=0;i<t;i++)
	{
	var amt=parseFloat(document.getElementById("total_"+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_amount").value;
	var taxableAmount1=document.getElementById("pkg_charges1").value;
	if(taxableAmount1==''){taxableAmount1=0;}
	var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
	if (str.length==0)
	{
	document.getElementById("taxval").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("taxval").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_tax_val.php?taxid="+str+"&amt="+taxableAmount2,true);
	xmlhttp.send();
}

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

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

function cal_grandamount()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	//var 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()
{
	window.open("MRN_items.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","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 getchangedataname(str)
{
	if(str=='PO')
	{
	if(document.getElementById("hide1").style.display == "block")
	{
	var ele=document.getElementById("hide1");
	ele.style.display = "none";
	}
	document.getElementById("show").style.display = "block";
	}
	if(str=='MPO')
	{
	if(document.getElementById("hide1").style.display == "none")
	{
	var ele=document.getElementById("hide1");
	ele.style.display = "block";
	}
	//	document.getElementById("hide1").style.display = "block";
	document.getElementById("show").style.display = "none";
	}	
	}	
  
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
	{
	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)
	{
	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("gatepassno").innerHtml=xmlhttp.responseText;
	
	}
	}
	xmlhttp.open("GET","gatentypass.php?str="+str,true);
	xmlhttp.send();





}  
  
  
</script>