<?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');
}
else
{
	$title = _('Modify Material Receipt Note');
}
?>
<link rel="stylesheet" href="css/jquery.ui.all.css">
<script src="js/jquery-1.5.1.js"></script>
<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.widget.js"></script>
<script src="ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/dynamicRow.js"></script>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>-->
<script src="js/edit_tax_calculation.js"></script>
<script src="js/modify_add_mrn.js"></script>
  <!--  To display calender ---->
<script type="text/javascript">
function FiendPurchasenumber(str)
{
	var a= document.getElementById('hidden_site').value;
	var vendor=document.getElementById("vendor").value;
	if(a !='' )
	{location.replace("AddMRN.php?type=<?php echo $_GET['type']; ?>"+"&orderno="+str+"&sitecode="+a+"&vendor="+vendor);}
	else
	{location.replace("AddMRN.php?type=<?php echo $_GET['type']; ?>"+"&orderno="+str);}
}
function calculate_short(id)
{
	var x = parseInt(document.getElementById('reciveqty_'+id).value);
	var poqty = parseInt(document.getElementById('poqty_'+id).value);
	var rate = 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 = parseInt(poqty)- parseInt(x);
				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;
	if(disc_type=='Amount')
	{
		var total_rate=parseInt(qty) * parseInt(itemrate);
		document.getElementById("discount_amount_"+str).value=parseInt(disc);
		document.getElementById("val_after_disc_"+str).value=parseInt(total_rate) - parseInt(disc);
	}
	else if(disc_type=='PercentAmt')
	{
		var total_rate=parseInt(qty) * parseInt(itemrate);
		var disc_val=parseInt(total_rate)*parseInt(disc)/100;
		document.getElementById("discount_amount_"+str).value=parseInt(disc);
		document.getElementById("val_after_disc_"+str).value=parseInt(total_rate) - parseInt(disc_val);
	}
}
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=425,width=640,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=1; 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 calculate_TotalTaxAmount()
{
 	var  itemamount = 0;
 	var  count= document.getElementById('rowcount').value;
 	for(var i=1; i<count; i++)
	{
 		var totalrate = document.getElementById('taxamount_'+i).value;
 			if(!isNaN(totalrate) && totalrate!='' ){
				itemamount  =parseFloat(itemamount)+  parseFloat(totalrate);
  			}
 	}
  	document.getElementById('tax_chargeamount').value = itemamount.toFixed(2);
  }
function cal_surcharges(id)
{
	   
	   document.getElementById("hidden_percent_inclusivecharge").value=id;
}
 
function cal_surcharges1()
{
   var surcharge=document.getElementById("hidden_percent_inclusivecharge").value;
    
 	 if(surcharge=='SUR'){  
 	 document.getElementById('tax_suroct_value').value=(parseFloat(document.getElementById('tax_chargeamount').value) *  parseFloat(document.getElementById('percent_inclusive').value))/100;
	 }
	 if(surcharge=='OCT'){
		 
	  $totals=parseInt(document.getElementById('itemamount').value)+parseInt(document.getElementById('tax_chargeamount').value);
	 document.getElementById('tax_suroct_value').value=($totals *  parseInt(document.getElementById('percent_inclusive').value))/100;
		 }
} 
function Completetotal()
{
	var itemamount = document.getElementById('itemamount').value;
	var tax_chargeamount = document.getElementById('tax_chargeamount').value;
 	var tax_suroct_value = document.getElementById('tax_suroct_value').value;
	var chargeamount = document.getElementById('chargeamount').value;
	document.getElementById('grandtotal').value=parseInt(itemamount)+parseInt(tax_chargeamount)+parseInt(tax_suroct_value)+parseInt(chargeamount);
}
function CountTotalQty()
{
	var  qty = 0;
	var  count= document.getElementById('rowcount').value;
   	var i;
 	for(i=1; i<count; i++)
	{
 		var totalqty = document.getElementById('reciveqty_'+i).value;
 			if(!isNaN(totalqty) && totalqty!='' ){
				qty  =parseInt(qty)+  parseInt(totalqty);
  			}
 	}
  	document.getElementById('totalqty').value = qty;
 }
/*function check_po()
{
	var type=document.getElementById("type").value;
	if(type!='PO'){
	var rowcount=document.getElementById("rowcount").value;
	//alert(rowcount);
	for(var i=1;i<rowcount;i++)
	{
		poqty=document.getElementById("poqty_"+i).value;
		reciveqty=document.getElementById("reciveqty_"+i).value;
		//alert(poqty);
		//alert(reciveqty);
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
	}
	}
}*/
function PurchaseOrderNumber_1()
{
	var receiviedagaist=document.getElementById("receiviedagaist").value;
	location.replace("AddMRN.php?type="+receiviedagaist);
}
function tax_calcutate(str,j)
 {  
	var divid="divTaxAmount"+j;
   	if (str=="")
	{
		document.getElementById(divid).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(divid).innerHTML=xmlhttp.responseText;
		}
	}
 	xmlhttp.open("GET","CountTaxAmount.php?Taxid="+str+"&id="+j,true);
	xmlhttp.send();
 }
 function tax_rate(str)
{
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,true);
xmlhttp.send();
}
function cal_Excise_Duty(str)
{
	var excise_rate=document.getElementById("rate_"+str).value;
	var basic_value=document.getElementById("itemamount").value;	
	var excise_value=basic_value*(excise_rate/100);
	document.getElementById("caption_value_"+str).value=excise_value.toFixed(2);
	
}
function cal_Edu_Cess(str)
{
	var excise_rate=document.getElementById("rate_"+str).value;
	var str2=str-1;
	var excise_val=document.getElementById("caption_value_"+str2).value;
	var educess_value=excise_val*(excise_rate/100);
	document.getElementById("caption_value_"+str).value=educess_value.toFixed(2);	
}
function cal_SHE_Cess(str)
{
	var excise_rate=document.getElementById("rate_"+str).value;
	var str2=str-2;
	var excise_val=document.getElementById("caption_value_"+str2).value;
	var educess_value=excise_val*(excise_rate/100);
	document.getElementById("caption_value_"+str).value=educess_value.toFixed(2);	
}
function calc_taxable_amount()
{
	var tot_taxable=0;
	var basic_value=document.getElementById("itemamount").value;	
	var count=document.getElementById("count_tax").value;
	for(var i=1;i<count;i++)
	{
		var value=document.getElementById("caption_value_"+i).value;
		tot_taxable=parseFloat(tot_taxable)+parseFloat(value);
	}
	var final_taxable=parseFloat(tot_taxable)+parseFloat(basic_value);
	document.getElementById("taxable_amt").value=final_taxable.toFixed(2);
}
function calc_tax_amount()
{
	var taxable=document.getElementById("taxable_amt").value;
	var taxval=document.getElementById("taxvalue").value;
	var final=taxable*(taxval/100);
	document.getElementById("tax_chargeamount").value=final.toFixed(2);
}
function cal_suroct(str)
{
	var total_tax=document.getElementById("tax_chargeamount").value;
	var final_sur=total_tax*(str/100);
	document.getElementById("tax_suroct_value").value=final_sur.toFixed(2);
}
</script>
<?php
if($_REQUEST['action']=='del')
{
	$del_sql="Update addmrnqty SET delete_status='0' WHERE issue_id='".$_REQUEST['mrnid']."' AND itemcode='".$_REQUEST['itemcode']."'"; 
	header("Location: view_MRN.php?Type=".$_REQUEST['Type']."&ModfingOnly=1&mrnid=".$_REQUEST['mrnid']);
	$del_res=DB_query($del_sql,$db);}
if($_REQUEST['cancel']!='')
{
	$cancel_sql="UPDATE addmrnqty SET delete_status='1' WHERE issue_id='".$_REQUEST['mrnid']."' AND delete_status='0'";
	$cancel_res=DB_query($cancel_sql,$db);}

if($_REQUEST['Submit'] && $_GET['Type']=='PO')
{
	$updatemrn_sql="UPDATE addmrn SET 
				   DocumentType='".$_POST['DocumentType']."',
				   BillNo='".$_POST['billno']."',
				   MRNVoucherDate='".FormatDateForSQL($_POST['MRNVoucherDate'])."',
				   GetPassNo='".$_POST['gatepassno']."',
				   Inwardsdate='".FormatDateForSQL($_POST['inwardate_save'])."',
				   Transp_name='".$_POST['transport']."',
				   VehicleNo='".$_POST['vehicalno']."',
				   TimeIn='".$_POST['timein']."',
				   Timeout='".$_POST['timeout']."',
				   LRno='".$_POST['lrno']."',
				   LRdate='".FormatDateForSQL($_POST['lrdate'])."',
				   TotalWeight='".$_POST['total_weight']."',
				   RemarksIfAny='".$_POST['RemarksIfAny']."'
	WHERE id='".$_REQUEST['mrnid']."' ";
	//echo "<pre>";
	//print_r($updatemrn_sql);	 exit;			
	$updatemrn_res=DB_query($updatemrn_sql,$db);
	 header("Location:index.php?route=MaterialReceiptNote&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."");}
	 
else if($_REQUEST['Submit'] && ($_GET['Type']=='Direct')) 
{
		for($str=1;$str<$_REQUEST['count_tax'];$str++)
		{	
			$caption_val[$str] = $_REQUEST['caption_value'][$str];
		}
	$updatemrn_sql="UPDATE addmrn SET 
				  MRNVoucherDate='".FormatDateForSQL($_POST['MRNVoucherDate'])."',
				  MRNDate='".FormatDateForSQL($_POST['MRNdate'])."',
				  MaterialReceiptOnBasis='".$_POST['matrialreceipt']."',
				  rmrs_no='".$_POST['rmrs_no']."',
				  OrderFromSite='".$_POST['sitecode']."',
				  StoreCode='".$_POST['storecode']."',
				  StoreName='".$_POST['storename']."',
				  PO_WO_MTO='".$_POST['PO']."',
				  OrderDate='".FormatDateForSQL($_POST['orderdate'])."',
				  ReceivedFrom='".$_POST['vendor']."',
				 DocumentType='".$_POST['DocumentType']."',
				   BillNo='".$_POST['billno']."',
				   MRNVoucherDate='".FormatDateForSQL($_POST['MRNVoucherDate'])."',
				   GetPassNo='".$_POST['gatepassno']."',
				   Inwardsdate='".FormatDateForSQL($_POST['inwardate_save'])."',
				   Transp_name='".$_POST['transport']."',
				   VehicleNo='".$_POST['vehicalno']."',
				   TimeIn='".$_POST['timein']."',
				   Timeout='".$_POST['timeout']."',
				   LRno='".$_POST['lrno']."',
				   LRdate='".FormatDateForSQL($_POST['lrdate'])."',
				   TotalWeight='".$_POST['total_weight']."',
				   RemarksIfAny='".$_POST['RemarksIfAny']."',
				  site_name='".$_POST['sitename']."',
				  totalqty='".$_POST['totalqty']."',
				  total_Item_Amount='".$_POST['itemamount']."',
				  Excise_Duty='".$caption_val[1]."',  
				  Edu_Cess='".$caption_val[2]."',  
				  SHE_Cess='".$caption_val[3]."',  
				  taxable_amt='".$_POST['taxable_amt']."',  
				  taxname='".$_POST['taxname']."',
				  Charge_Amount='".$_POST['chargeamount']."',
				  percent_inclusive='".$_POST['percent_inclusive']."',
				  percent_inclusivecharge='".$_POST['percent_inclusivecharge']."',
				  tax_suroct_value='".$_POST['tax_suroct_value']."',
				  tax_chargeamount='".$_POST['tax_chargeamount']."',
				  grandtotal='".$_POST['grandtotal']."'
		WHERE id='".$_REQUEST['mrnid']."' ";
	//echo "<pre>";
	//print_r($updatemrn_sql);	 exit;			
	$updatemrn_res=DB_query($updatemrn_sql,$db);
for($k=0;$k<$_POST['countcharges'];$k++)
{
		$update_charges="UPDATE mrn_charges SET
								Inclusive ='".$_POST['Charge'][$k]."', 
								As_Per_Actual='".$_POST['AsPerActual'][$k]."',
								charges='".$_POST['actual'][$k]."' 
						WHERE MRN_id='".$_REQUEST['mrnid']."' AND charges_name='".$_POST['description'][$k]."' ";
		//echo "<pre>";
		//print_r($update_charges);
	 	//exit;
		$update_charge_res=DB_query($update_charges,$db);
		
}
//Update addmrnqty table////
$CR=1;
while($CR<$_POST['countval'])
{
echo "<br>".
$get_sql="Select * from addmrnqty where issue_id='".$_REQUEST['mrnid']."' AND id='".$_POST['row_id'][$CR]."'";
$get_res=DB_query($get_sql,$db);
$get_row=DB_fetch_array($get_res); exit;
//echo "<pre>";
//print_r($get_row);
if(DB_num_rows($get_res)!=0)
{
	$item_total_rate=$_POST['itemrate'][$CR]*$_POST['reciveqty'][$CR];
	if($_REQUEST['short_accessid'][$CR]!=0)
				{
					$pending_status=1;
					$status= "N";
				}
				else
				{
				 $status= "Y";
				}
	$update_sql="Update addmrnqty SET 
								  itemprice='".$_POST['itemrate'][$CR]."',
								  itemcode='".$_POST['itemcode'][$CR]."',
								  description='".$_POST['desc'][$CR]."',                         
								  Make='".$_POST['make'][$CR]."',    
								  Color='".$_POST['color'][$CR]."',   
								  Gread='".$_POST['gread'][$CR]."',  
								  UOM='".$_POST['uom'][$CR]."',     
								  qty_as_per_bill='".$_POST['qty_as_per_bill'][$CR]."',   
								  short_accessid='".$_POST['short_accessid'][$CR]."',  
								  reciveqty='".$_POST['reciveqty'][$CR]."',  
								  item_total_rate='".$item_total_rate."',  
								  disc_type='".$_POST['disc_type'][$CR]."', 
								  discount='".$_POST['discount'][$CR]."',
								  discount_amount='".$_POST['discount_amount'][$CR]."',
								  remarks='".$_POST['remarks'][$CR]."', 
								  status='".$status."', 
								  mat_value='".$_POST['mat_value'][$CR]."' WHERE id='".$_POST['row_id'][$CR]."'";
					echo "<pre>";
					print_r($update_sql); 
					$update_res=DB_query($update_sql,$db);
}
else
{
	$item_total_rate=$_POST['itemrate'][$CR]*$_POST['reciveqty'][$CR];
	if($_REQUEST['short_accessid'][$CR]!=0)
				{
				$pending_status=1;
				$status= "N";
				}
				else{
				 $status= "Y";
				}
	$insert_sql="INSERT INTO addmrnqty (id, issue_id,itemprice,itemcode,description,Make,Color,Gread,UOM,Qcrequd ,qty_as_per_bill,short_accessid,reciveqty,taxname,tax_rate,taxamount_rate,item_total_rate,disc_type,discount,val_after_disc,total_amt_with_tax,remarks,status,mat_value)
				VALUES
					  ('',
					   '".$_REQUEST['mrnid']."',
					   '".$_POST['itemrate'][$CR]."',
					   '".$_POST['itemcode'][$CR]."',
					   '".$_POST['desc'][$CR]."',
					   '".$_POST['make'][$CR]."',
					   '".$_POST['color'][$CR]."',
					   '".$_POST['gread'][$CR]."',
					   '".$_POST['uom'][$CR]."',
					   '".$_POST['qcreqd'][$CR]."',
					   '".$_POST['qty_as_per_bill'][$CR]."',
					   '".$_POST['short_accessid'][$CR]."',
					   '".$_POST['reciveqty'][$CR]."',
					   '".$_POST['taxname'][$CR]."',
					   '".$_POST['tax_rate'][$CR]."',
					   '".$_POST['taxamount'][$CR]."',
					   '".$item_total_rate."',
					   '".$_POST['disc_type'][$CR]."',
					   '".$_POST['discount'][$CR]."',
					   '".$_POST['val_after_disc'][$CR]."',
					   '".$_POST['total_amt_with_tax'][$CR]."',
					   '".$_POST['remarks'][$CR]."',
					   '".$status."',
					   '".$_POST['mat_value'][$CR]."')";
					   //echo "<pre>";
					   //print_r($insert_sql);
	$insert_result=DB_query($insert_sql,$db);	
	
	if($stock_row['itemcode']=$_REQUEST['itemcode'][$CR] && $stock_row['site']=$_REQUEST['sitecode'] && $stock_row['store']=$_REQUEST['storecode'])
	{
		$condition1="itemcode='".$_REQUEST['itemcode'][$CR]."' && site='".$_REQUEST['sitecode'][$CR]."' && store='".$_REQUEST['storecode'][$CR]."'"; 
		$current_bal=$stock_row['stockbalance']+$_REQUEST['reciveqty'][$CR];
		//echo $current_bal; exit;
		//print_r($current_bal); exit;
		$balance_arr['site'] = $_REQUEST['sitecode'];
		$balance_arr['store'] = $_REQUEST['storecode'];  
		$balance_arr['itemcode']= $_REQUEST['itemcode'][$CR];
		$balance_arr['stockbalance']=$current_bal;
		$balance_arr['created_by']=$_SESSION['UserID'];
		$update1=$s->EditRecord(stock_maintenance, $balance_arr, $condition1);
		$row1=DB_query($update1,$db);
					
					if(!$row1)
					{
	  					 die('Error'.DB_error());
					}
		}
	else{
	$balance_arr['site'] = $_REQUEST['sitecode'];
	$balance_arr['store'] = $_REQUEST['storecode'];  
	$balance_arr['itemcode']= $_REQUEST['itemcode'][$CR];
	$balance_arr['stockbalance']= $_REQUEST['reciveqty'][$CR];
	
	$balance_arr['created_by']=$_SESSION['UserID'];  
	
	$insert_stock_maintenance=$s->insertRecord('stock_maintenance', $balance_arr);
	$row1=DB_query($insert_stock_maintenance,$db);
	if(!$row1)			
	{
	   die('Error'.DB_error());
	}
	}
}
$CR++;
}
/////////This is to delete the Item row from the table addmrnqty on clicking update button(Which has been deleted from the front end in the case of DIRECT and the similar ones)///////
$delete_mrn="Delete from addmrnqty where issue_id='".$_REQUEST['mrnid']."' AND delete_status='0'";
$delete_res=DB_query($delete_mrn,$db);

}
//**************************Modify Section*******************************************************
if(isset($_REQUEST['mrnid']))
{
	    $condition="id='".$_REQUEST['mrnid']."'";
		$GetData=$s->GetRecord('addmrn', $condition);
		$GetResultData= DB_query($GetData,$db);
		$GetRowData=DB_fetch_array($GetResultData);
		//echo "<pre>";
		//print_r($GetRowData);
		$MRNNo=$GetRowData['MRNNo'];
		$MRNDate= ($GetRowData['MRNDate']);
		$sitecode=$GetRowData['OrderFromSite'];
		$OrderFromSite=$GetRowData['OrderFromSite'];
		$MRNVoucherDate=($GetRowData['MRNVoucherDate']);
	 	$ReceivedFrom=$GetRowData['ReceivedFrom'];
		$MaterialReceiptOnBasis=$GetRowData['MaterialReceiptOnBasis'];
		$receiviedagaist=$GetRowData['receiviedagaist'];
		$rmrs_no=$GetRowData['rmrs_no'];
		$Type=$GetRowData['Type'];
		$site_name=$GetRowData['site_name'];
	    $OrderFromSite=$GetRowData['OrderFromSite'];
		$PO=$GetRowData['PO_WO_MTO'];
		$BillNo=$GetRowData['BillNo'];
		$Inwardsdate=$GetRowData['Inwardsdate'];
		$DocumentType=$GetRowData['DocumentType'];
		$GetPassNo=$GetRowData['GetPassNo'];
		$Transp_name=$GetRowData['Transp_name'];
		$VehicleNo=$GetRowData['VehicleNo'];
		$TimeIn=$GetRowData['TimeIn'];
		$Timeout=$GetRowData['Timeout'];
		$LRno=$GetRowData['LRno'];
		$LRdate=$GetRowData['LRdate'];
		$TotalWeight=$GetRowData['TotalWeight'];
		$RemarksIfAny=$GetRowData['RemarksIfAny'];
		$OrderDate=$GetRowData['OrderDate'];
	    $StoreCode=$GetRowData['StoreCode'];
		$StoreName=$GetRowData['StoreName'];
		$totalqty=$GetRowData['totalqty'];
		$_REQUEST['chargeamount']=$GetRowData['Charge_Amount'];
		$_REQUEST['tax_chargeamount']=$GetRowData['tax_chargeamount'];
		$_REQUEST['tax_suroct_value']=$GetRowData['tax_suroct_value'];
		$_REQUEST['grandtotal']=$GetRowData['grandtotal'];
		$_REQUEST['percent_inclusive']=$GetRowData['percent_inclusive'];
		$_REQUEST['percent_inclusivecharge']=$GetRowData['percent_inclusivecharge'];
		$_REQUEST['itemamount']=$GetRowData['total_Item_Amount'];
		$_REQUEST['taxable_amt']=$GetRowData['taxable_amt'];
		$_REQUEST['taxname']=$GetRowData['taxname'];
		$_REQUEST['itemamount']=$GetRowData['total_Item_Amount'];
		 
		 if($percent_inclusivecharge=='SUR')
		 {
		  $tax_suroct_value	=($tax_chargeamount*$percent_inclusive)/100;
		 }
		 else{
		  $tax_suroct_value	=(($tax_chargeamount+$total_Item_Amount)*$percent_inclusive)/100;
 		 }
		$Remarks=$GetRowData['Remarks'];	}
?>
<form action="" method="post">
<table width="100%"border="0" cellpadding="2" cellspacing="1">
<?php if($_REQUEST['r'])
	{
	   ?>
	     <tr>
		 <td colspan="2" style="color:#FF0000; font-weight:bold">Record Updated Successfully ! </td>
		 </tr>
	   <?php 
	} ?>
<tr>
<td>
<fieldset><legend><strong>GENERAL DETAILS</strong></legend><table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
<?php 
if(isset($msg_error))
{
?>
  <tr>
  		<td colspan="5">
		<table width="50%" border="0"  style="color:#FF0000;font-weight:bold" align="left">
	  <tr>
 		<?php for($i=0;$i<count($msg_error);$i++)
		{	
		  if($i%2==0)	
		  echo "</tr><tr>";
 	    	echo "<td>".$msg_error[$i]."</td>" ;
		}?>
		</table>		</td>
  </tr>
 <?php } 	 ?>
  <tr>
    <th width="15%"><strong>Mrn No. </strong></th>
    <td colspan="2"><?php echo $MRNNo;?></td>
    <th width="25%"><strong>MRN Date </strong></th>
    <td width="24%" colspan="2"><input type="text" name="MRNdate" value="<?php echo ConvertSQLDate($MRNDate);?>" id="MRNdate" class="datepicker"></td>
  </tr>
  <tr>
    <th><strong>Received Against</strong></th>
    <td colspan="2"><?php echo $Type;?>
	<input type="hidden" name="receiviedagaist" id="receiviedagaist" value="<?php echo $Type;?>" />
	<input id="hidden_form_site" type="hidden" value="<?php echo $_REQUEST['sitecode'];?>" />
    <input id="hidden_form_type" type="hidden" value="<?php echo $_GET['type'];?>" />
    <input type="hidden" name="receive_type" id="receive_type" value="<?php echo $_GET['type'];?>" />	</td>
    <th><strong>Material Received On Basis </strong></th>
    <td colspan="2"><select name="matrialreceipt" id="matrialreceipt" style="width:70px">
	<option value="000">---Select---</option>	
	<?php 
	if($Type=='PO')
	{ ?>
 		<option value="Credit"<?php echo($MaterialReceiptOnBasis=='Credit'?'selected':'')?>>Credit</option>
		<option value="Cash"<?php echo($MaterialReceiptOnBasis=='Cash'?'selected':'')?>>Cash</option>
		<option value="Debitable"<?php echo($MaterialReceiptOnBasis=='Debitable'?'selected':'')?>>Debitable</option>
		<option value="Debitable"<?php echo($MaterialReceiptOnBasis=='rental'?'selected':'')?>>Debitable</option>
		<option value="Hiring"<?php echo($MaterialReceiptOnBasis=='Hiring'?'selected':'')?>>Hiring</option>
	<?php }
	else
	{?>
 	<option value="Credit"<?php echo($MaterialReceiptOnBasis=='Credit'?'selected':'')?>>Credit</option>
	<option value="Cash"<?php echo($MaterialReceiptOnBasis=='Cash'?'selected':'')?>>Cash</option>
<?php } ?>	
	</select></td>
  </tr>
  <tr>
    <th><strong>Site Code - Name </strong></th>
    <td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td><select name="sitecode" onchange="showsitename111(this.value)" id="sitecode" style="width:70px">
      <option value="000">---Select---</option>
      <?php 
	$sql = 'SELECT loccode, locationname FROM locations';
	$resultStkLocs = DB_query($sql,$db);
	  while ($myrow=DB_fetch_array($resultStkLocs))
	  {
 		?>
      <option value="<?php echo $myrow['loccode']; ?>" <?php echo ($OrderFromSite==$myrow['loccode']?'selected':'')?>><?php echo $myrow['loccode'];?></option>
      <?php  }	?>
    </select></td>
	<td><div id="txtsite">
	<?php
	$site_sql="Select locationname from locations where loccode ='".$_REQUEST['sitecode']."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($_REQUEST['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 $site_name;?>" size="20" readonly="true">
	<?php } ?>
	<input type="hidden" name="hidden_site" id="hidden_site" value="<?php echo $_REQUEST['hidden_site'];?>"/></div></td>
	</tr>
	</table>
	</td>
    <th><strong>Store Code - Name </strong></th>
    <td>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select distinct StoreCode, StoreName from storetype order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select name="storecode" onChange="changestorename(this.value)" style="width:50px">
		<option value="000">---Select---</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($StoreCode==$myrow['StoreCode'])
				$p="selected";
		?>
			<option Value="<?php echo $myrow['StoreCode']; ?>" <?php echo $p; ?>><?php echo $myrow['StoreCode']; ?></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 scope="row"><strong>Recevied From </strong></th>
    <td colspan="2"><?php 
		 if($Type=='Direct' || $Type=='PO')
		 {
		 	$sql="select vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			?>
			<select name="vendor" id="vendor" onchange="get_order(this.value)">
			<option value="000">---Select---</option>
			<?php
			while($myrow = DB_fetch_array($result))
			{ 
			$p1='';
			if( strtolower(trim($ReceivedFrom))== strtolower(trim($myrow['vendor_code'])))
			$p1="selected";
			?>
			 <option value="<?php echo $myrow['vendor_code']; ?>"  <?php echo $p1;?> ><?php echo $myrow['vendor_name']; ?></option>
		<?php }
			?>
			</select>
			<?php 
		 }
		 else
		 if($Type=='ACM')
		 {
		 	$SQL = "Select client_code,c_name from clientmaster";
		 	$result = DB_query($SQL,$db);
		 ?>
		<select name="vendor">
		<?php 
		while($myrow = DB_fetch_array($result))
		{
		  ?>
		 <option value="<?php echo $myrow['client_code']; ?>" ><?php echo $myrow['c_name']; ?></option>
		 <?php } ?>
		</select>
		<?php }  else if($Type=='APCM') {
			$SQL = "Select pc_code,pc_name from pcopening";
			$result = DB_query($SQL,$db);
		 ?>
		<select name="vendor"> 
		<?php 
		while($myrow = DB_fetch_array($result))
		{
		  ?>
		 <option value="<?php echo $myrow['pc_code']; ?>"><?php echo $myrow['pc_name']; ?></option>
		 <?php } ?>
		</select>
		<?php  } else if($Type=='AMSR')  {

			$SQL = "select loccode, locationname From locations";
			$result = DB_query($SQL,$db);
		?>		
		<select name="vendor" tabindex="5">
		<?php 
		while($myrow = DB_fetch_array($result))
		{
		  ?>
		 <option value="<?php echo $myrow['loccode']; ?>" ><?php echo $myrow['locationname']; ?></option>
		 <?php } ?>
		</select>
		
		<?php } else { ?>
		<select name="vendor" tabindex="5">
		 <option value="<?php echo $supplierno; ?>"><?php echo $supplier_name; ?></option>
		</select>
	  <?php } ?></td>
    <th><strong>R.M.R.S. No. </strong></th>
    <td colspan="2"><input name="rmrs_no" type="text" value="<?php  echo $rmrs_no;?>" /></td>
  </tr>
  <tr>
    <th scope="row"><strong>PO/Challan/WO/ Ref.No.</strong></th>
    <td colspan="2">
	<?php
if($Type=='PO')
{
 	$sql="select orderno, PO_Orderno from purchorders Where sitecode='".$OrderFromSite."'";
	$result = DB_query($sql,$db);
?>
<div id="order"><select name="PO" id="PurchaseOrder" onchange="FiendPurchasenumber(this.value)"  style="width:210px">
<option value="000">---Select---</option>
<?php
 while($myrow=DB_Fetch_array($result))
 {
?>
<option value="<?php echo $myrow['orderno']; ?>"<?php echo ($PO==$myrow['orderno']?'selected':'')?>><?php echo $myrow['PO_Orderno']; ?> </option>
<?php }?> 
</select></div>
<?php }
 else if($Type=='Direct') { ?>
<input type="text"  id="PO" name="PO"  size="15" value="<?php echo $PO; ?>"/>
<?php } else if($Type=='APCM') {?>
<input type="text"  id="PO" name="PO"  size="15" value="<?php echo $PO; ?>"/>
<?php } else if($Type=='ACM') {?>
<input type="text"  id="PO" name="PO"  size="15" value="<?php echo $PO; ?>"/>
<?php } else if($Type=='AMSR') {?>
<input type="text"   id="PO" name="PO" size="15" value="<?php echo $PO; ?>"/>
<?php } else if($Type=='AWO') {?>
<input type="text"  id="PO" name="PO"  size="15" value="<?php echo $PO; ?>"/>
<?php } else{?>
<select name="">
<option value="000">---Select---</option>
</select>
<?php } ?>	</td>
    <th><strong>Order Date </strong></th>
    <td colspan="2">
	   <input type="text" name="orderdate" id="orderdate" value="<?php echo ConvertSQLDate($OrderDate); ?>" tabindex="13"></td>
  </tr>
</table></fieldset></td>
</tr>
<tr>
<td align="center" height="237"><table width="100%" border="1" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <td width="10%"><strong>Document Type </strong></td>
    <td width="11%"><p>
      <input name="DocumentType" type="radio" value="Challan" <?php echo($DocumentType=='Challan'?'checked':''); ?> />
      <strong>Chalaan</strong></p>
      <p>
      <input name="DocumentType" type="radio" value="Bill" <?php echo($DocumentType=='Bill'?'checked':''); ?>/>
        <strong> Bill</strong></p></td>
    <td width="11%"><strong>No.
      </strong>
      <input name="billno" type="text" id="billno" size="12"  value="<?php  echo $BillNo; ?>" /></td>
    <td width="15%"><strong>Voucher Date</strong>      
      <input type="text" name="MRNVoucherDate"size="12" class="datepicker"  onblur="valdate();"  value="<?php echo ConvertSQLDate($MRNVoucherDate); ?>" tabindex="6"/></td>
    <td width="7%"><strong>Inwards Gate Pass</strong></td>
    <td width="16%"><strong> No. </strong>
      <input type="text" name="gatepassno"size="15" id="gatepassno"  value="<?php echo $GetPassNo;?>" /></td>
    <td width="30%"><strong>Date</strong>
      <input type="text" name="inwardate_save"size="15" id="inwardate_save"  value="<?php echo ConvertSQLDate($Inwardsdate); ?>" class="datepicker"  /></td>
  </tr>
  <tr>
    <td><strong>Transporter Name </strong></td>
    <td><?php  
		$sql_trans = 'select vendor_code, vendor_name from suppliers Where vendor_type="Transporter"';
		$resulttransp = DB_query($sql_trans,$db);
		  ?>
		<select name="transport">
		 <?php 
		 while ($myrow=DB_fetch_array($resulttransp))
		 {?>
		 	<option selected Value="<?php echo $myrow['vendor_code'];?>"<?php echo ($Transp_name==$myrow['vendor_code']?'selected':'')?>><?php echo $myrow['vendor_name'];?></option>
		 <?php }
		?>
		</select></td>
    <td><strong>Vehicle No. </strong></td>
    <td><input name="vehicalno" type="text" id="vehicalno" size="12"  value="<?php echo $VehicleNo; ?>"/></td>
    <td><strong>Time</strong></td>
    <td><p><strong>In </strong></p>
      <p><strong>Out</strong></p></td>
    <td><p>
      <input name="timein" type="text" id="timein" size="12" value="<?php echo $TimeIn; ?>" />
    </p>
      <p>
        <input name="timeout" type="text" id="timeout" size="12" value="<?php echo $Timeout; ?>" onblur="Comparetime();" />
</p></td>
  </tr>
  <tr>
    <td><strong>L R No. </strong></td>
    <td><input name="lrno" type="text" id="lrno" size="12"  value="<?php echo $LRno; ?>"/></td>
    <td><strong>L R Date </strong></td>
    <td><input name="lrdate" type="text" id="lrdate" size="12" value="<?php echo ConvertSQLDate($LRdate); ?>"  onblur="LRdate();" class="datepicker"/></td>
    <td><strong>Total Weight </strong></td>
    <td><input type="text" name="total_weight" id="total_weight"  value="<?php echo $TotalWeight; ?>"/></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="44"><strong>Remarks If Any </strong></td>
    <td colspan="6"><input name="RemarksIfAny" type="text" id="RemarksIfAny" value="<?php echo $RemarksIfAny;?>" size="140">
	</td>
  </tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>
<?php if($Type =='PO')
{
				$CR=1;
				
	if($_GET['ModfingOnly']=='1' && $_GET['mrnid']!='')
	{
		$item_sql ="select * from addmrnqty where issue_id='".$_GET['mrnid']."' ";
		$item_result=DB_query($item_sql, $db);
	}
	else
	{		
		$update_sql ="select * from purchorderdetails WHERE orderno='".$_REQUEST['orderno']."' ";
		$updateSqlresult=DB_query($update_sql, $db);
	}
 				?>

<fieldset><legend><strong>ITEM DETAILS</strong></legend><div style="overflow:auto; width:800px ; height:160px"  >
<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 width="23%"><strong>ITEM NAME</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>DESCRIPTION</strong></th>
    <th width="10%"><strong>ITEM NO.</strong></th>
    <th width="13%"><strong>FLEXO/OFFSET</strong></th>
    <th width="10%"><strong>OD</strong></th>
	<th width="10%"><strong>WIDTH</strong></th>
    <th width="7%"><strong>LENGTH</strong></th>	
    <th width="10%"><strong>SERIAL NO. </strong></th>
    <th width="7%"><strong>ORIGINAL/LOCAL</strong></th>
    <th width="7%"><strong>TYPE </strong></th>
    <th width="7%"><strong>SHADE</strong></th>
    <th width="7%"><strong>RUNNING METER/ROLL</strong></th>
    <th width="7%"><strong>VOLUME</strong></th>
    <th width="7%"><strong>TEETH</strong></th>
    <th width="7%"><strong>BCM</strong></th>
    <th width="7%"><strong>UPS</strong></th>
    <th width="7%"><strong>QUALITY</strong></th>
    <th scope="col"><strong>PO QTY </strong></th>
    <th scope="col"><strong>QTY AS PER BILL </strong></th>
    <th scope="col"><strong>QTY ACCEPTED </strong></th>
    <th scope="col"><strong>SHORT QUANTITY </strong></th>
    <th scope="col"><strong>RATE</strong></th>
    <th scope="col"><strong>DISCOUNT TYPE </strong></th>
    <th scope="col"><strong>DISCOUNT</strong></th>
	<th scope="col"><strong>DISCOUNT AMOUNT</strong></th>
    <th scope="col"><strong>VALUE AFTER DISCOUNT </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=1;
				  while($Itemrow=DB_fetch_array($item_result))
				  {
				   	$reciveqty = $_REQUEST['reciveqty'][$i];
					$rejectqty=$_REQUEST['rejectqty'][$i];
					$short_accessid=$_REQUEST['short_accessid'][$i];
					$uom=$_REQUEST['uom'][$i];
					$poqty=$_REQUEST['poqty'][$i];
					$totalrate=$_REQUEST['totalrate'][$i];
					$taxname=$_REQUEST['taxname'][$i];
					$taxamount=$_REQUEST['taxamount'][$i];
					//echo "<pre>";
					//print_r($Itemrow);
					$record=DB_query("select * from item_master where StockID='".$Itemrow['itemcode']."'",$db);
					$record_row=DB_fetch_array($record)
	?>
<tr id="txt_order">
<td><?php echo $i;?></td>
<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" name="user_shipping[<?php echo $i;?>]">
	<?php echo $Itemrow['itemcode'];?><input type="hidden" tabindex=""  readonly="" id="washing_profile" name="itemcode[]"size="15" onblur="PO_order(this.value)" value="<?php echo $Itemrow['itemcode'] ?>" />
	<input type="hidden" name="orderno"  id="orderno" onblur="PO_order(this.value)"  value="<?php echo $_REQUEST['orderno'];?>" /></td>
<td><?php echo $record_row['item_name']; ?></td>
<td><?php echo $Itemrow['Make'] ?><input name="make[]" id="make[]" type="hidden" value="<?php echo $Itemrow['make'] ?>" /></td>
<td><?php echo $Itemrow['Gread'] ?><input name="gread[]" id="gread[]" type="hidden" value="<?php echo $Itemrow['grade'] ?>"></td>
<td><?php echo $Itemrow['Color'] ?><input name="color[]" id="color[]" type="hidden" value="<?php echo $Itemrow['color'] ?>" ></td>
<td><?php echo $Itemrow['UOM'];?><input name="uom[]" id="uom[]" type="hidden" value="<?php echo $Itemrow['uom'] ?>"></td>
<td><?php echo $record_row['item_desc']; ?>
<input type="hidden" name="desc[]"   id="desc" size="25" value="<?php echo $record_row['item_desc']; ?>"/></td>
<td><?php echo $record_row['item_no']; ?></td>
<td><?php echo $record_row['flexo_offset']; ?></td>
<td><?php echo $record_row['od']; ?></td>
<td><?php echo $record_row['width']; ?></td>
<td><?php echo $record_row['length']; ?></td>
<td><?php echo $record_row['serial_no']; ?></td>
<td><?php echo $record_row['orig_local']; ?></td>
<td><?php echo $record_row['type_name']; ?></td>
<td><?php echo $record_row['shade']; ?></td>
<td><?php echo $record_row['running_roll']; ?></td>
<td><?php echo $record_row['volume']; ?></td>
<td><?php echo $record_row['teeth']; ?></td>
<td><?php echo $record_row['bcm']; ?></td>
<td><?php echo $record_row['ups']; ?></td>
<td><?php echo $record_row['quality']; ?></td>
<td><?php echo $Itemrow['POQty'];?><input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $Itemrow['quatity'];?>" size="10"/></td>
<td><?php echo $Itemrow['POQty'];?><input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $Itemrow['quatity'];?>" size="10"/></td>
<td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i; ?>" size="5" onblur="calculate_short(<?php echo $i ?>)" value="<?php echo $Itemrow['reciveqty'];?>" readonly="true"/></td>
<td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i; ?>" value="<?php echo $Itemrow['short_accessid'];?>" size="5" onfocus="calculate_poshort(<?php echo $i ?>);" readonly="true"/></td>
<td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i; ?>" value="<?php echo  $Itemrow['itemprice'];?>" size="5" readonly="true"/></td>
<td>
<select name="disc_type[]" id="disc_type_<?php echo $i;?>">
<option value="Amount" <?php echo ($Itemrow['disc_type']=='Amount')?'selected':''?>>Amount</option>
<option value="PercentAmt" <?php echo ($Itemrow['disc_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
</select></td>
<td><input name="discount[]" type="text" id="discount_<?php echo $i;?>" value="<?php echo $Itemrow['discount'];?>" size="5" onblur="calculate_discount(<?php echo $i;?>);" readonly="true"/></td>
<td><input name="discount_amount[]" type="text" id="discount_amount_<?php echo $i;?>" value="<?php echo $Itemrow['discount_amount']; ?>" size="8" /></td>
<td><input name="val_after_disc[]" type="text" id="val_after_disc_<?php echo $i;?>" value="<?php echo $Itemrow['val_after_disc'];?>" size="8" readonly="true"/></td>
<td><input type="text" name="remarks[]" id="remarks_<?php echo $i;?>" value="<?php  echo $Itemrow['remarks'];?>" readonly="true"/></td>
</tr>
  <?php $i++;} ?>
<input type="hidden" name="countval" value="<?php echo $i; ?>"  id="rowcount"/>
</table></div>
</fieldset>
<?php  } 
else if($Type=='Direct'/* || $Type=='APCM' || $Type=='ACM'*/)
{?>

<fieldset><legend><strong>ITEM DETAILS</strong></legend><div align="center" style="overflow:auto; width:800px ; height:160px">
<table width="100%" border="1" cellspacing="1" cellpadding="2">
  <tr>
	<th scope="col"><strong>ADD ITEM</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 AS PER BILL </strong></th>
    <th scope="col"><strong>QTY ACCEPTED </strong></th>
	<th scope="col"><strong>SHORT QUANTITY </strong></th>
    <th scope="col"><strong>RATE</strong></th>
    <th scope="col"><strong>DISCOUNT TYPE </strong></th>
    <th scope="col"><strong>DISCOUNT</strong></th>
	<th scope="col"><strong>DISCOUNT AMOUNT</strong></th>
    <th scope="col"><strong>VALUE AFTER DISCOUNT </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>
	<th><strong>ACTION</strong></th>
  </tr>
<?php  
$direct_sql="select * from addmrnqty where issue_id='".$_GET['mrnid']."' AND delete_status='1'";
$direct_res=DB_query($direct_sql,$db);
$j=1;

while($direct_row=DB_fetch_array($direct_res)){
//echo "<pre>";
//print_r($direct_row);
$make_sql=DB_query("select manufacturer from product_manufacture where id='".$direct_row['Make']."'",$db);
$make_row=DB_fetch_array($make_sql);
$grade_sql=DB_query("select grade from product_grade where id='".$direct_row['Gread']."'",$db);
$grade_row=DB_fetch_array($grade_sql);
$color_sql=DB_query("select color from product_color where id='".$direct_row['Color']."'",$db);
$color_row=DB_fetch_array($color_sql);


$_REQUEST['itemcode'][$j]=$direct_row['itemcode'];
$_REQUEST['desc'][$j]=$direct_row['description'];
$_REQUEST['hidmake'][$j]=$make_row['manufacturer'];
$_REQUEST['hidgread'][$j]=$grade_row['grade'];
$_REQUEST['hidcolor'][$j]=$color_row['color'];
$_REQUEST['poqty'][$j]=$direct_row['POQty'];
$_REQUEST['qty_as_per_bill'][$j]=$direct_row['qty_as_per_bill'];
$_REQUEST['reciveqty'][$j]=$direct_row['reciveqty'];
$_REQUEST['short_accessid'][$j]=$direct_row['short_accessid'];
$_REQUEST['itemrate'][$j]=$direct_row['itemprice'];
$_POST['disc_type']=$direct_row['disc_type'];
$_REQUEST['discount'][$j]=$direct_row['discount'];
$_REQUEST['discount_amount'][$j]=$direct_row['discount_amount'];
$_REQUEST['val_after_disc'][$j]=$direct_row['val_after_disc'];
//$_REQUEST['taxname']=$direct_row['taxname'];
//$_REQUEST['tax_rate'][$j]=$direct_row['tax_rate'];
//$_REQUEST['taxamount'][$j]=$direct_row['taxamount_rate'];
//$_REQUEST['total_amt_with_tax'][$j]=$direct_row['total_amt_with_tax'];
$_REQUEST['remarks'][$j]=$direct_row['remarks'];
$_REQUEST['uom'][$j]=$direct_row['UOM'];
?>
<tr>
<td><input type="hidden" name="qcreqd[]"size="10" value="<?php echo $j;?>" />
<input type="hidden" name="row_id[<?php echo $j;?>]" value="<?php echo $direct_row['id'];?>" id="row_id_<?php echo $j;?>" />
<input type="button" name="profile_popup" value="+" id="profile_popup_<?php echo $j;?>"  onclick="openPopupProfile(<?php  echo $j;?>);" /></td>
<td><input type="text" tabindex=""  readonly="" id="washing_profile_<?php echo $j;?>" name="itemcode[<?php echo $j;?>]"size="10" onblur="PO_order(this.value)" value="<?php echo  $_REQUEST['itemcode'][$j]?>"/><input type="hidden" name="orderno[]"  id="orderno_[<?php echo $j;?>]" onblur="PO_order(this.value)"  value="<?php echo $_REQUEST['orderno'];?>" /></td>
<td><input name="desc[<?php echo $j;?>]"  type="text" id="desc_<?php echo $j;?>" value="<?php echo $_REQUEST['desc'][$j]?>" readonly/>	</td> 
<td><input name="make[<?php echo $j;?>]" id="make_<?php echo $j;?>" type="hidden" readonly value="<?php echo $direct_row['Make'];?>"/><input name="hidmake[]" type="text" id="hidmake_<?php echo $j;?>" size="15" readonly value="<?php echo $_REQUEST['hidmake'][$j];?>"/></td>
 <td><input name="gread[<?php echo $j;?>]" id="gread_<?php echo $j;?>" type="hidden" value="<?php echo $direct_row['Gread'];?>"readonly><input name="hidgread[<?php echo $j;?>]" type="text" id="hidgread_<?php echo $j;?>" size="15" readonly value="<?php echo $_REQUEST['hidgread'][$j];?>"></td>
<td><input name="color[<?php echo $j;?>]" id="color_<?php echo $j;?>" type="hidden" value="<?php echo $direct_row['Color'];?>"readonly /><input name="hidcolor[<?php echo $j;?>]" type="text" id="hidcolor_<?php echo $j;?>" size="15" readonly value="<?php echo $_REQUEST['hidcolor'][$j];?>"></td>
<td><input name="uom[<?php echo $j;?>]" type="text" id="uom_<?php echo $j;?>" size="5" readonly value="<?php echo $_REQUEST['uom'][$j];?>"></td>
<td><input name="qty_as_per_bill[<?php echo $j;?>]" type="text" id="qty_as_per_bill_<?php echo $j;?>" value="<?php echo $_REQUEST['qty_as_per_bill'][$j];?>" size="10"/></td>
<td><input name="reciveqty[<?php echo $j;?>]" type="text" id="reciveqty_<?php echo $j; ?>" size="5" onblur="calculate_short(<?php echo $j ?>)" value="<?php echo $_REQUEST['reciveqty'][$j];?>"/></td>
<td><input name="short_accessid[<?php echo $j;?>]" type="text" id="short_accessid_<?php echo $j; ?>" value="<?php echo $_REQUEST['short_accessid'][$j];?>" size="5" onfocus="calculate_poshort(<?php echo $j; ?>);"/></td>
<td><input name="itemrate[<?php echo $j;?>]" type="text" id="itemrate_<?php echo $j; ?>" value="<?php echo  $_REQUEST['itemrate'][$j];?>" size="5"/></td>
<td><select name="disc_type[<?php echo $j;?>]" id="disc_type_<?php echo $j;?>">
<option value="Amount" <?php echo ($_POST['disc_type']=='Amount')?'selected':''?>>Amount</option>
<option value="PercentAmt" <?php echo ($_POST['disc_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
</select></td>
<td><input name="discount[<?php echo $j;?>]" type="text" id="discount_<?php echo $j;?>" value="<?php echo $_REQUEST['discount'][$j];?>" size="5" onblur="calculate_discount(<?php echo $j;?>);"/></td>
<td><input name="discount_amount[]" type="text" id="discount_amount_<?php echo $i;?>" value="<?php echo $_REQUEST['discount_amount'][$j]; ?>" size="8" /></td>
<td><input name="val_after_disc[<?php echo $j;?>]" type="text" id="val_after_disc_<?php echo $j;?>" value="<?php echo $_REQUEST['val_after_disc'][$j];?>" size="8" readonly="true"/></td>
<td><input type="text" name="remarks[<?php echo $j;?>]" id="remarks_<?php echo $j;?>" value="<?php echo $_REQUEST['remarks'][$j];?>"/></td>
<td>
<a href="view_MRN.php?Type=<?php echo $_REQUEST['Type']?>&itemcode=<?php echo $_REQUEST['itemcode'][$j];?>&mrnid=<?php echo $_GET['mrnid'];?>&action=del" onclick="return confirm('Are You Sure You Want To Delete This Item Detail?')"><img src="images/Icon_Delete.gif" width="20" height="20" align="absmiddle" /> </a></td>
</tr>
<?php $j++;}  ?>
<input type="hidden" name="countval" value="<?php echo $j; ?>"  id="rowcount"/>
</table></div></fieldset>
<?php }?>
</td>
</tr>
</table>
<table width="20%" border="0">
<tr>
    <th width="47%"><strong>TOTAL QUANTITY </strong></th>
    <td width="53%" colspan="4">
<input name="totalqty" type="text" id="totalqty" onfocus="CountTotalQty()" size="10" value="<?php echo $totalqty;?>"/>
	</td>
	<td></td>
  </tr>
</table>


<?php ?>
<p align="center"><input type="submit" name="Submit" value="Update" onclick="return check_po()"/>
  <input type="submit" name="cancel" value="Cancel" /></p>
</form>
<?php 
 include('includes/footer.inc');
?>
