<?php ob_start();
$PageSecurity = 4;
$PageName = 'MaterialReceiptNote';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');

if($_REQUEST['action']=='delete')
{
DB_query("update log_addmrnqty set del_status=1 where grn_id='".$_REQUEST['mrnid']."' and id='".$_REQUEST['dirid']."'",$db);

}
if($_REQUEST['action']=='undo')
{
DB_query("update log_addmrnqty set del_status=0 where grn_id='".$_REQUEST['mrnid']."' ",$db);

}

if(isset($_GET['issueid'])  && isset($_GET['issueid']) !='')
{
	$title = _('Update Issue Slip');
}
else
{
	$title = _('Modify Material Receipt Note');
}
	$url_cancel= "index.php?route=Inventory/transaction/goods_receipt_note_index".$rurl;
	$url_add= "index.php?route=Inventory/transaction/material_receipt_note_edit".$rurl;
if($_REQUEST['action']=='del')
{
	$del_sql="Update log_addmrnqty SET delete_status='0' WHERE grn_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);
}
	
//**************************************** Update Mrn Data     *****************************************//
if($_REQUEST['delete']=="delete"){
	$countval1= $_REQUEST['countrow'];
	for($j=0;$j<$countval1;$j++)
	{
		if($_REQUEST['disboxid'][$j]==1){
			$qry_box="delete from log_addmrnbox where id='".$_REQUEST['box_id'][$j]."' and dispatch=0";			
			DB_query($qry_box,$db);
		}
	}
}

if($_REQUEST['Update'])
	{    //echo "<pre>"; print_r($_REQUEST); die;
	    $updatemrn_sql="UPDATE log_add_mrn SET 
		site='".$_POST['site']."',
		store='".$_POST['storecode']."',
		ptype='".$_POST['ptype']."',
		vendor='".$_POST['vendor']."',";
		if($_POST['ptype']!=3){
		$updatemrn_sql.="po_order='".$_POST['po_order']."',";
		}
		$updatemrn_sql.="vendor_address='".$_POST['vendor_address']."',
		document_type='".$_POST['document_type']."',
		document_no='".$_POST['document_no']."',
		doc_date='".FormatDateForSQL1($_POST['doc_date'])."',
		gate_entry_no='".$_POST['gate_entry_no']."',
		gate_entry_date='".FormatDateForSQL1($_POST['gate_entry_date'])."',
		boe_no='".$_POST['boe_no']."',
		receive_time='".$_POST['receive_time']."',
		package_srno='".$_POST['package_srno']."',
		pod_receive_date='".FormatDateForSQL1($_POST['pod_receive_date'])."',
		pod_head_over_date='".FormatDateForSQL1($_POST['pod_head_over_date'])."',
		POD_done='".$_POST['POD_done']."',
		POD_date='".FormatDateForSQL1($_POST['POD_date'])."',
		remarks='".$_POST['remarks']."',
		total_amt='".$_POST['total_item_amount']."',
		pkg_per='".$_POST['pkg_perc']."',  
		pkg_amt ='".$_POST['pkg_charges']."',
		excise_id = '".$_REQUEST['EDBillRate']."',
		excise_amt = '".$_REQUEST['totalDiscountedPrice']."',
		ecess_per = '".$_REQUEST['ECessPercentage']."',
		ecess_amt = '".$_REQUEST['ECessValue1']."',
		sah_per = '".$_REQUEST['SAHCessPercentage']."',
		sah_amt = '".$_REQUEST['SAHCessValue1']."',
		total_excise_amt = '".$_REQUEST['total_excise_amount']."',		
		vat_cst='".$_POST['vat_cst']."',  
		vat_cst_amt ='".$_POST['taxvalue']."', 
		sur_per='".$_POST['sur_oct_per']."',  
		sur_amt='".$_POST['sur_oct_amt']."',  
		freight='".$_POST['tot_freight']."',
		loading='".$_POST['loading']."',  
		additional_charge='".$_POST['add_charges']."',  
		grand_total ='".$_POST['grandtotal']."',
		modified_by='".$_SESSION['UserID']."',
		modified_date='".date('Y-m-d')."'
		WHERE id='".$_REQUEST['mrnid']."'";
		$updatemrn_res=DB_query($updatemrn_sql,$db);

		$del=DB_query("delete from log_addmrnqty where grn_id='".$_REQUEST['mrnid']."'",$db);
		if(isset($_REQUEST['pppt']) && $_REQUEST['pppt']==3){
			$countval= count($_REQUEST['mst_itemid1']);
			for($i=0;$i<$countval;$i++)
			{
				if($_REQUEST['reciveqty1'][$i]!='')
				{	  
					$data_arr['grn_id']= $_REQUEST['mrnid'];
					$data_arr['mst_itemid']= $_POST['mst_itemid1'][$i];
					$data_arr['reciveqty']= $_REQUEST['reciveqty1'][$i];
					$data_arr['reciveqty1']= $_REQUEST['reciveqty1'][$i];
					$data_arr['rate']= $_POST['rate1'][$i];
					$data_arr['total_price']= $_REQUEST['total_price1'][$i];	
					
					$insert_mrm=$s->insertRecord('log_addmrnqty', $data_arr);
					$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm,$db,$ErrMsg);
				}
			}
		}else{
			$countval= count($_REQUEST['mst_itemid']);
			for($i=0;$i<$countval;$i++)
			{
				if($_REQUEST['reciveqty'][$i]!='')
				{	  
					$data_arr['grn_id']= $_REQUEST['mrnid'];
					$data_arr['mst_itemid']= $_POST['mst_itemid'][$i];
					$data_arr['reciveqty']= $_REQUEST['reciveqty'][$i];
					$data_arr['reciveqty1']= $_REQUEST['reciveqty'][$i];
					$data_arr['rate']= $_POST['itemrate'][$i];
					$data_arr['total_price']= $_REQUEST['item_total_rate'][$i];	

					$insert_mrm=$s->insertRecord('log_addmrnqty', $data_arr);
					$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm,$db,$ErrMsg);
				}
			}
		}	
		
		$countval1= $_REQUEST['countrow'];
		for($j=0;$j<$countval1;$j++)
		{
			if($_REQUEST['package_no'][$j]!='')
			{	
				$updatemrn_sqlb="UPDATE log_addmrnbox SET			
				package_no='".$_REQUEST['package_no'][$j]."',
				no_of_package='".$_REQUEST['no_of_package'][$j]."',
				content='".$_REQUEST['content'][$j]."',				
				layout='".$_REQUEST['layout'][$j]."',
				itemid='".$_REQUEST['itemid'][$j]."'
				WHERE grn_id='".$_REQUEST['mrnid']."' AND id='".$_REQUEST['box_id'][$j]."'";	
											
				$updatemrn_resb=DB_query($updatemrn_sqlb,$db);
		   }
		}
		if($_REQUEST['countrow1']>0 && $_REQUEST['countrow1']!=''){
			$countval2=$countval1+$_REQUEST['countrow1'];
			for($j=$countval1;$j<$countval2;$j++)
			{
				if($_REQUEST['package_no'][$j]!='')
				{				
					$data_arr1['grn_id']= $_REQUEST['mrnid'];
					$data_arr1['package_no']= $_POST['package_no'][$j];
					$data_arr1['no_of_package']= $_REQUEST['no_of_package'][$j];
					$data_arr1['content']= $_POST['content'][$j];				
					$data_arr1['layout']= $_REQUEST['layout'][$j];
					$data_arr1['store'] = $_REQUEST['storecode'];	

					$insert_mrm1=$s->insertRecord('log_addmrnbox', $data_arr1);
					$ErrMsg1 = _('An error occurred Record for Boxes Not Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm1,$db,$ErrMsg);	
			   }
			}
		}
		
		$countvalO = count($_REQUEST['vehicle_no']);
		for($ii=0;$ii<$countvalO;$ii++)
		{
			
			if($ii<$_REQUEST['rcheck']){
				if($_REQUEST['vehicle_no'][$ii]!='')
				{
					$updatemrn_sqlo="UPDATE log_add_mrn_details SET			
					vehicle_no='".$_REQUEST['vehicle_no'][$ii]."',
					lr_no='".$_REQUEST['lr_no'][$ii]."',
					lr_date='".FormatDateForSQL1($_REQUEST['lr_date'][$ii])."',				
					way_bill_no='".$_REQUEST['way_bill_no'][$ii]."',
					way_bill_amt='".$_REQUEST['way_bill_amt'][$ii]."'
					WHERE grn_id='".$_REQUEST['mrnid']."' AND id='".$_REQUEST['oitem'][$ii]."'";	
												
					$updatemrn_reso=DB_query($updatemrn_sqlo,$db);
				}
			}else{
				if($_REQUEST['vehicle_no'][$ii]!='')
				{				
					$data_arrO['grn_id']= $_REQUEST['mrnid'];
					$data_arrO['vehicle_no']= $_POST['vehicle_no'][$ii];
					$data_arrO['lr_no']= $_REQUEST['lr_no'][$ii];
					$data_arrO['lr_date']= FormatDateForSQL1($_POST['lr_date'][$ii]);				
					$data_arrO['way_bill_no']= $_REQUEST['way_bill_no'][$ii];	
					$data_arrO['way_bill_amt']= $_REQUEST['way_bill_amt'][$ii];
											
					$insert_mrmO=$s->insertRecord('log_add_mrn_details', $data_arrO);
					$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrmO,$db,$ErrMsg);	
			   }
			} 
		}
		
		$_SESSION['success_msg']="Update Successfully";
		echo "<script>location='index.php?route=LOG/transaction/goods_receipt_note_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
	 

//**************************Modify Section*******************************************************
if(isset($_REQUEST['mrnid']))
{
	    $condition="id='".$_REQUEST['mrnid']."'";
		$GetData=$s->GetRecord('log_add_mrn', $condition);
		$GetResultData= DB_query($GetData,$db);
		$GetRowData=DB_fetch_array($GetResultData);
				
		$grn_no=$GetRowData['grn_no'];
		$grn_date=$GetRowData['grn_date'];
		$site=$GetRowData['site'];
		$store=$GetRowData['store'];
		$ptype=$GetRowData['ptype'];
		$po_order=$GetRowData['po_order'];
	    $vendor=$GetRowData['vendor'];
		$vendor_address=$GetRowData['vendor_address'];
		$document_type=$GetRowData['document_type'];
		$document_no=$GetRowData['document_no'];
		$doc_date=$GetRowData['doc_date'];
		$vendor_invoice_no=$GetRowData['vendor_invoice_no'];
		$vendor_invoice_val=$GetRowData['vendor_invoice_val'];
		$vendor_invoice_date=$GetRowData['vendor_invoice_date'];
		$gate_entry_no=$GetRowData['gate_entry_no'];
		$gate_entry_date=$GetRowData['gate_entry_date'];
		$boe_no=$GetRowData['boe_no'];
		$receive_time=$GetRowData['receive_time'];
		$package_srno=$GetRowData['package_srno'];
		$pod_receive_date=$GetRowData['pod_receive_date'];
		$pod_head_over_date=$GetRowData['pod_head_over_date'];
		$POD_done=$GetRowData['POD_done'];
		$POD_date=$GetRowData['POD_date'];
		$remarks=$GetRowData['remarks'];
}
?>
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:fixed;
left:280px;
top:200px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<script>
$(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
</script>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form action="" method="post">
<h1 align="center"><strong>Goods  Receipt Note</strong></h1>
<input name="usertype" id="usertype" type="hidden" value="<?php echo $dealertype; ?>" />
 
<h3 >GENERAL DETAILS</h3>
<table width="100%"  border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata1">Location</td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td><?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
     <select name="site" onchange="getreqitemdata(this.value)" id="site" style="width:70px"    >
      <option value="0">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($site==$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 ='".$site."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($site))
	{
	?>
	    <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>
	<td  class="tabledata1">Warehouse</td>
    <td id="storedata">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select id, StoreCode, StoreName from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in ('".$_SESSION['AssignedBranch']."') order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="storecode" name="storecode"  style="width:100%">
		<option value="0">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($store==$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>
    <td class="tabledata1">GRN No.</td>
    <td><input type="text" value="<?php echo $grn_no;?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
  	<td  class="tabledata1">GRN Date </td>
    <td><input type="text" value="<?php echo ConvertSQLDate($grn_date);?>" style="width:150px;" name="grn_date" readonly="true" class="datepicker"></td>
	<td  class="tabledata1">Purchase Type</td>
    <td>
		<select name="ptype" id="ptype"	style="width:150px;" onchange="changetype()">
			<option value="0" <?php if($ptype==0){echo "selected";}?>>---Select---</option>
			<option value="1" <?php if($ptype==1){echo "selected";}?>>LOCAL</option>
			<option value="2" <?php if($ptype==2){echo "selected";}?>>IMPORT</option>
			<option value="3" <?php if($ptype==3){echo "selected";}?>>FOC</option>
		</select>	</td>
    <td class="tabledata1">Supplier Name</td>
    <td ><select name="vendor" id="vendor"  style="width:150px;" onchange="getaddress(this.value)">
		<option value="0" >---Select---</option>
			<?php
			$sql="select id, vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			?>
			 <option  value="<?php echo $myrow['id']; ?>" <?php if($vendor==$myrow['id']){echo "selected";}?>><?php echo  str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
		</select></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">Supplier Address</td>
	<td id="supaddress"><textarea name="vendor_address" id="vendor_address"><?php echo $vendor_address;?></textarea></td>
	<td  class="tabledata1">Purchase Order</td>
	<td id="porder">
		<?php if($ptype==3){?>
		<input type="text" style="width:150px;" name="po_order" id="po_order" value="">
		<?php }else{ ?>
		<select name="po_order" id="po_order" style="width:150px;" onchange="getitemlist(this.value)">
			<option value="0" >---Select---</option>
			<?php $sql1="select id, pr_no from log_po where vender_id='".$vendor."' AND ptype='".$ptype."'";
			$result1 = DB_query($sql1, $db);
			while($myrow1 = DB_fetch_array($result1))
			{?> 
				<option value="<?php echo $myrow1['id'];?>" <?php if($po_order==$myrow1['id']){echo "selected";}?>><?php echo $myrow1['pr_no'];?></option>
			<?php } ?>
		</select>
		<?php } ?>	</td>
    <td class="tabledata1">Document Type</td>
    <td>
		<select name="document_type" id="document_type" style="width:150px;">
			<option value="0" <?php if($document_type==0){echo "selected";}?>>Select</option>
			<option value="Challan" <?php if($document_type=="Challan"){echo "selected";}?>>Challan</option>
			<option value="Bill" <?php if($document_type=="Bill"){echo "selected";}?>>Bill</option>
			<option value="Invoice" <?php if($document_type=="Invoice"){echo "selected";}?>>Invoice</option>
		</select>	</td>
</tr>
<tr class="row1">
	<td class="tabledata1">Invoice No</td>
    <td><input name="document_no" type="text" id="document_no" style="width:150px;" value="<?php echo $document_no;?>" /></td>
	<td class="tabledata1">Invoice Date</td>
    <td><input name="doc_date" type="text" id="doc_date" style="width:150px;" value="<?php echo ConvertSQLDate($doc_date);?>" class="datepicker" readonly="true" /></td>
    <td class="tabledata1">Vendor Invoice No.</td>
    <td><input name="vendor_invoice_no" type="text" id="vendor_invoice_no" style="width:150px;" value="<?php echo $vendor_invoice_no;?>" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Vendor Invoice Value</td>
    <td><input name="vendor_invoice_val" type="text" id="vendor_invoice_val" style="width:150px;" value="<?php echo $vendor_invoice_val;?>" /></td>
	<td class="tabledata1">Vendor Invoice Date</td>
    <td><input name="vendor_invoice_date" type="text" id="vendor_invoice_date" style="width:150px;" value="<?php echo ConvertSQLDate($vendor_invoice_date);?>" class="datepicker" readonly="true" /></td>
    <td class="tabledata1">Gate Entry No.</td>
    <td><input type="text" name="gate_entry_no"  style="width:150px;" id="gate_entry_no"  value="<?php echo $gate_entry_no;?>" />    </td>
</tr>
<tr class="row1">
	<td class="tabledata1">Gate Entry Date</td>
    <td><input type="text" name="gate_entry_date" id="gate_entry_date" style="width:150px;" class="datepicker" readonly="true" value="<?php echo ConvertSQLDate($gate_entry_date);?>" /></td>
    <td class="tabledata1">BOE No.</td>
    <td><input name="boe_no" type="text" id="boe_no" style="width:150px;"  value="<?php echo $boe_no;?>"/></td>
    <td class="tabledata1">Receiving Time</td>
    <td><input type="text" name="receive_time" id="receive_time" value="<?php echo $receive_time;?>" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1">No. of Package</td>
    <td><input type="text" name="package_srno" id="package_srno"  style="width:150px;" value="<?php echo $package_srno;?>"/></td>
	<td class="tabledata1">POD Received Date</td>
    <td><input name="pod_receive_date" type="text" id="pod_receive_date" style="width:150px;" value="<?php echo ConvertSQLDate($pod_receive_date);?>" class="datepicker" readonly="true"/></td>
	<td class="tabledata1">POD Hand Over Date to Finance Team</td>
    <td><input name="pod_head_over_date" type="text" id="pod_head_over_date" style="width:150px;" value="<?php echo ConvertSQLDate($pod_head_over_date);?>" class="datepicker" readonly="true"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1">POD Done</td>
    <td>
		<select name="POD_done" id="POD_done" style="width:150px;">
			<option value="0" <?php if($POD_done==0){echo "selected";}?>>Select</option>
			<option value="N" <?php if($POD_done=="N"){echo "selected";}?>>NO</option>
			<option value="Y" <?php if($POD_done=="Y"){echo "selected";}?>>YES</option>
		</select>	</td>
	<td class="tabledata1">POD Date</td>
    <td><input name="POD_date" type="text" id="POD_date" style="width:150px;" value="<?php echo ConvertSQLDate($POD_date);?>" class="datepicker" readonly="true"/></td>
	<td class="tabledata1">&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr class="row1">
    <td  class="tabledata1">Remarks If Any</td>
    <td colspan="5"><input name="remarks" type="text" id="remarks" value="<?php echo $remarks;?>" style="width:630px;height:50px;" /></td>
</tr>
<tr class="row1">
	<td colspan="6"><h3>OTHER DETAILS</h3></td>
</tr>
<tr class="row1">
	<td colspan="6">
		<div style="width:auto; overflow:auto; border:#006699 solid 2px;">
        <p align="left" style="padding-top:5px; padding-bottom:5px;">
          <input type="button" onclick="addRow('dataTableO')" value="Add Rows" class="search" />
          &nbsp;&nbsp;
          <input type="button" class="search"   onclick="deleteRowOrderO('dataTableO')" value="Delete" />
        </p>
       
        <div style="width:auto; overflow:auto;">
          <div id="showdata">
            <table width="100%" border="1" cellspacing="0" cellpadding="3">
              <tr>
                <td class="tabledata"></td>
				<td class="tabledata">Vehicle No.</td>
                <td class="tabledata">LR No.</td>
                <td class="tabledata">LR Date</td>
                <td class="tabledata">Way Bill No.</td>
                <td class="tabledata">Way Bill Amount</td>
              </tr>
			  <?php
			  	$i=0;
			  	$ItemSQL2=DB_query("Select * from log_add_mrn_details where grn_id='".$_REQUEST['mrnid']."'",$db);
		  		while($item_row2=DB_fetch_array($ItemSQL2))
		  		{
			  	?>			  		
			  <tr>
                  <td><?php echo $i+1;?><input name="oitem[]" type="hidden" value="<?php echo $item_row2['id'];?>" /></td>
				 <td><input type="text" name="vehicle_no[]" id="vehicle_no1" value="<?php echo $item_row2['vehicle_no'];?>" /></td>
                  <td><input type="text" name="lr_no[]" id="lr_no1" size="40" value="<?php echo $item_row2['lr_no'];?>" /></td>
                  <td><input type="text" name="lr_date[]" id="lr_date1" size="20" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php echo ConvertSQLDate($item_row2['lr_date']);?>" readonly="true"/></td>
                  <td><input type="text" name="way_bill_no[]" id="way_bill_no1" size="20" value="<?php echo $item_row2['way_bill_no'];?>"/></td>
                  <td><input type="text" name="way_bill_amt[]" id="way_bill_amt1" size="20" value="<?php echo $item_row2['way_bill_amt'];?>" /></td>
               </tr>
			   <?php $i++;} ?>
			   <input type="hidden" name="rcheck" id="rcheck" value="<?php echo $i;?>" />
              <tbody id="dataTableO">
                <tr>
                  <td><input name="delitem[]" type="checkbox" value="" /></td>
				 <td><input type="text" name="vehicle_no[]" id="vehicle_no" /></td>
                  <td><input type="text" name="lr_no[]" id="lr_no" size="40" /></td>
                  <td><input type="text" name="lr_date[]" id="lr_date" size="20" onClick="javascript:NewCal(this.id,'ddmmyyyy')" /></td>
                  <td><input type="text" name="way_bill_no[]" id="way_bill_no" size="20" /></td>
                  <td><input type="text" name="way_bill_amt[]" id="way_bill_amt" size="20" /></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
		<input type="hidden" name="hiditemcountO" id="hiditemcountO" value="" />
        <input type="hidden" name="" value="" id="edit_cntO" />
		<div class="cl"></div>
      </div>	</td>
</tr>
<tr class="row1">
	<td colspan="6">&nbsp;</td>
</tr>
<tr class="row1">
	<td colspan="6"><h3>ITEM DETAILS</h3></td>
</tr>
<tr class="row1">
	<td style="text-align:left; <?php if($ptype!=3){?>display:none;<?php }else{?>display:block;<?php } ?>" colspan="6" id="bfoc">
		<!--<input type="button" onClick="open_items()" value="Add Item" accesskey="A" class="search" />&nbsp;-->
		<input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" />&nbsp;	</td>			 
</tr>
<tr class="row1">
	<td  colspan="6">
	<div id="foc" <?php if($ptype!=3){?>style="display:none"<?php }else{?>style="display:block;"<?php } ?>>		
		<?php /*?><div style="overflow:auto; width:950px; margin-left:auto; margin-right:auto; height:auto">
    	<div id="itemdata">
      	<table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
          	<td class="tabledata1" style="width:40px;"><strong>Select</strong></td>
			<td class="tabledata1" style="width:20px;"><strong></strong></td>
			<td class="tabledata1"><strong>ITEM CODE </strong></td>
			<td class="tabledata1"><strong>DESCRIPTION</strong></td>
			<td class="tabledata1"><strong>UOM</strong></td>         
			<td class="tabledata1"><strong>QTY RECEIVED</strong></td>
			<td class="tabledata1"><strong>RATE</strong></td>
			<td class="tabledata1"><strong>TOTAL PRICE</strong></td> 
        </tr>
        <tbody id="dataTable">
          <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" id="delitem" /></td>
            <td><input  type="hidden"   readonly=""  id="itemdataid"  name="mst_itemid[]" /></td>
            <td><input type="text" value="" tabindex=""   id="itemcode" name="itemcode[]"size="20"
			 onkeyup="opendatas(this.value,this.id)"/>
            </td>
            <td><input type="text" name="item_name[]"  id="descriptions" size="25"  value=""/></td>
            <td><input type="text" name="uom[]" id="uom" value="" readonly /> </td>
	 		<td><input  type="text" name="reciveqty[]"  id="poqty" size="30"   value=""   /></td>
		  <td><input  type="text" name="itemrate[]"  id="porate" size="30"  value="" onkeyup="calamt1(this.id,this.value)" /></td>
            <td><input  type="text" name="item_total_rate[]"  id="itemtotalrate" size="30"   value="" readonly  /></td>
          </tr>
        </tbody>
      	</table>
    </div>
  </div><div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" /><?php */?>
		<div style="overflow:auto; width:945px; height:auto">
          <div id="div">
            <table width="100%" border="1" cellpadding="3" cellspacing="0">
              <tr>
                <th><strong>S. No.</strong></th>
                <th></th>
                <th><strong>Item Code</strong></th>
                <th><strong>Item Name</strong></th>
                <th><strong>UOM</strong></th>
                <th><strong>Qty</strong></th>
                <th><strong>Rate</strong></th>
                <th><strong>Total AMT</strong></th>
              </tr>
              <?php 
 $i=0;
$sql_edit=DB_query("Select * from log_addmrnqty where grn_id='".$_REQUEST['mrnid']."' and del_status=0 ",$db);
while($record_edit=DB_fetch_array($sql_edit))
{

if($i%2==0)
{$bg="#CCCCCC";}
else
$bg="#C8BECB";
	?>
              <td><a href="index.php?route=LOG/transaction/material_receipt_note_edit&action=Edit&id=<?php echo $_REQUEST['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delitem&delid=<?php echo $record_edit['id'];?>"><img src="images/delete.gif" /></a> </td>
          <td><input  type="hidden"   readonly=""  id="mst_itemid[]"  name="mst_itemid1[]"  value="<?php echo $record_edit['mst_itemid']; ?>" />          </td>
                <td><?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'StockID'); ?> </td>
                <td><?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'item_name'); ?> </td>
                <td><?php $unit= $s->getField('item_master','id',$record_edit['mst_itemid'],'mst_unitid'); ?>
              <?php echo $s->getField('unitsofmeasure','unitid',$unit,'unitname');  ?> </td>
                <td><input  type="text" name="reciveqty1[]"  id="poqty1_<?php echo $i; ?>" size="30"   value="<?php  echo $record_edit['reciveqty'];	?>"  /></td>
                <td><input  type="text" name="rate1[]"  id="porate1_<?php echo $i; ?>" size="30"  value="<?php  echo $record_edit['rate'];?>"  onkeyup="calamt3(this.id,this.value)"  />          </td>
                <td><input  type="text" name="total_price1[]"  id="itemtotalrate1_<?php echo $i; ?>" size="30"   value="<?php  echo $record_edit['total_price'];	?>" readonly  />          </td>
              </tr>
              <?php $i++; } ?>
              <tbody id="dataTable">
                <tr bgcolor="#FFFFFF">
                  <td><input name="delitem[]2" type="checkbox" value="<?php echo $item_row['id'];?>" id="delitem" /></td>
                  <td><input  type="hidden"   readonly=""  id="itemdataid"  name="mst_itemid1[]" /></td>
                  <td><input type="text" value="" tabindex=""   id="itemcode" name="itemcode[]"size="20"
			 onkeyup="opendatas(this.value,this.id)"/>                  </td>
                  <td><input type="text" name="desc[]"  id="descriptions" size="25"  value=""/></td>
                  <td><input type="text" name="uom[]" id="uom" value="" readonly />                  </td>
                  <td><input  type="text" name="reciveqty1[]"  id="poqty" size="30"   value=""   /></td>
                  <td><input  type="text" name="rate1[]"  id="porate" size="30"  value="" onkeyup="calamt2(this.id,this.value)" /></td>
                  <td><input  type="text" name="total_price1[]"  id="itemtotalrate" size="30"   value="" readonly  /></td>
                </tr>
              </tbody>
            </table>
          </div>
		  </div>
		  <input type="hidden" name="pppt" value="<?php echo $ptype; ?>" />
		<input type="hidden" name="" value="<?php echo $i;?>" id="ee_cnt" /> 
  <input type="hidden" name="" value="" id="edit_cnt" /> 
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
	</div>	
	<div id="nfoc" <?php if($ptype==3){?>style="display:none"<?php }else{?>style="display:block"<?php } ?>>
		<div style="overflow:auto; width:945px; height:auto">
 	<div id="itemdata">
 	<table width="100%" border="1" cellpadding="3" cellspacing="0">
         <tr class="row1">
			<td class="tabledata"><strong>S. NO. </strong></td>
			<td class="tabledata"><strong></strong></td>
			<td class="tabledata"><strong>ITEM CODE </strong></td>
			<td class="tabledata"><strong>DESCRIPTION</strong></td>  
			<td class="tabledata"><strong>UOM</strong></td>
			<td class="tabledata"><strong>PO QTY</strong></td>
			<td class="tabledata"><strong>PENDING QTY</strong></td>
			<td class="tabledata"><strong>RECEIVED QTY</strong></td>
			<td class="tabledata"><strong>RATE</strong></td>
			<td class="tabledata"><strong>TOTAL AMT</strong></td>
		</tr>
        <?php 
 		$i=0;
		$sql_edit=DB_query("Select * from log_po_details where parent_id='".$po_order."' and del_status=0",$db);
		while($record_edit=DB_fetch_array($sql_edit))
		{
			if($i%2==0)
				{$bg="#CCCCCC";}
			else
				$bg="#C8BECB";
		?>
		<tr>
			<td><?php echo ++$i; ?></td>
			<td>
				<input  type="hidden"   readonly=""  id="itemdataid1_<?php echo $i; ?>"  name="mst_itemid[<?php echo $i-1; ?>]"  value="<?php echo $record_edit['mst_itemid']; ?>" />			</td>
			<td>
				<?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'StockID'); ?>			</td>
			<td>
				<?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'item_name'); ?>			</td>
			<td>
				<?php $unit= $s->getField('item_master','id',$record_edit['mst_itemid'],'mst_unitid'); ?>
				<?php echo $s->getField('unitsofmeasure','unitid',$unit,'unitname');  ?>			</td>
			<td>
			<?php 
			$sql5 = DB_query("select * from log_addmrnqty where grn_id='".$_REQUEST['mrnid']."' AND mst_itemid='".$record_edit['mst_itemid']."'", $db);
			$record5=DB_fetch_array($sql5); 
			
			$sql6 = DB_query("select SUM(reciveqty) AS recv from log_addmrnqty where grn_id IN (select id from log_add_mrn where po_order=".$po_order.") AND mst_itemid='".$record_edit['mst_itemid']."'", $db);
			$record6=DB_fetch_array($sql6); 
			
			$sql4 = DB_query("select * from log_po_details where parent_id='".$po_order."' AND mst_itemid='".$record_edit['mst_itemid']."'", $db);
			$record4=DB_fetch_array($sql4); ?>
				<input  type="text" name="pqty[<?php echo $i-1; ?>]"  id="pqty_<?php echo $i; ?>" size="20" value="<?php echo $record4['qty'];?>" readonly="true"  /></td>
			<td>
				<input  type="text" name="peqty[<?php echo $i-1; ?>]"  id="peqty_<?php echo $i; ?>" size="20" value="<?php echo ($record4['qty']+$record5['reciveqty']-$record6['recv']);?>" readonly="true"  /></td>
			<td>
				<input  type="text" name="reciveqty[<?php echo $i-1; ?>]"  id="poqty_<?php echo $i; ?>" size="20" value="<?php echo $record5['reciveqty'];?>" onblur="checkqty(this.value,<?php echo $i;?>)"  /></td>
			<td>
				<input  type="text" name="itemrate[<?php echo $i-1; ?>]"  id="porate_<?php echo $i; ?>" size="20"  value="<?php echo $record5['rate'];?>" onkeyup="calamt(this.id,this.value)"  />			</td>
			<td>
				<input  type="text" name="item_total_rate[<?php echo $i-1; ?>]"  id="itemtotalrate_<?php echo $i; ?>" size="20" value="<?php echo $record5['total_price'];?>" readonly />			</td>
		</tr>
		<?php } ?>
	</table>
    </div>
  	</div>
  	<input type="hidden" name="" value="<?php echo $i;?>" id="ee_cnt" /> 
  	<input type="hidden" name="" value="<?php echo $i;?>" id="edit_cnt" /> 
  	<input type="hidden" name="hiditemcount" id="hiditemcountnf" value="<?php echo $i;?>" />
	</div>	</td>
</tr>
</table>
<div align="right">			
	
		     <table width="100%" cellpadding="3" cellspacing="0" border="1">
	<tr class="row1">
		<td width="60%">&nbsp;</td>
		<td width="40%">
				<table width="100%" cellpadding="3" cellspacing="0" border="0">
				<tr class="row1">
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" style="width:150px;" <?php if($ptype!=3){?>onfocus="cal_totalamount()"<?php }else{?>onfocus="cal_totalamount1()"<?php } ?> value="<?php echo $GetRowData['total_amt'];?>" readonly="true"/></td>
               </tr>
              <tr class="row1">
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_perc" id="pkg_perc" value="<?php echo $GetRowData['pkg_per'];?>" 
				  style="width:60px" onblur="calcPackaging(this.value)" />
				  <input name="pkg_charges" id="pkg_charges1" type="text" 
				  value="<?php echo $GetRowData['pkg_amt'];?>" style="width:90px;" /></td>
                </tr>
				<tr class="row1">
					<td><strong>Excise</strong></td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:150px;" onchange="calculateBillExcise(this.value)"  >
				<option value="0">--Select--</option>
				<?php
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
				$ServiceRes=DB_query($ServiceSql,$db);
				while($ServiceRow=DB_fetch_array($ServiceRes))
				{
				?>
				<option value="<?php echo $ServiceRow['id']?>" <?php if($ServiceRow['id']==$GetRowData['excise_id']){echo "selected";}?>><?php echo $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:150px;" onfocus="calculateTotalExcise()" value="<?php echo $GetRowData['excise_amt'];?>"/>
				</td>
			    </tr>
			<?php 
			$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			$k=1;
			while($cessRow=DB_fetch_array($cessSql))
			{
			$caption[$k]=$cessRow['caption']; 
			
			$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
			while($rate_row=DB_fetch_array($rate_sql))
			{
			$rate[$k]=$rate_row['def_rate'];
			}
			$k++;
			} 
			?>
			<tr class="row1">
					<td><strong>E-Cess</strong></td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:60px;" readonly />
						<input name="ECessValue1" id="ECessValue" type="text" value="<?php echo $GetRowData['ecess_amt'];?>" style="width:120px;" readonly onfocus="calculateECess1()"/></td>
				</tr>
			<tr class="row1">
					<td><strong>SAH-E Cess</strong> </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:60px;" readonly/>
						<input name="SAHCessValue1" id="SAHCessValue" type="text" value="<?php echo $GetRowData['sah_amt'];?>" style="width:120px;" readonly onfocus="calculateSAHCess1()"/></td>
				</tr>
					<tr class="row1">
					<td><strong>Total Excise Amount</strong></td>
					<td><input type="text" name="total_excise_amount" id="total_item_amount1" style="width:150px;" onfocus="showexiseamt()" value="<?php echo $GetRowData['total_excise_amt'];?>"/></td>
					
					</tr>
                <tr class="row1">
                  <td><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);  	?>
              <td><select id="taxname" name="vat_cst" onchange="tax_rate1(this.value)" style="width:150px;">
	          <option value="0">---Select---</option>
                  <?php    while($Taxmyrow=DB_fetch_array($Taxresult)){			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($GetRowData['vat_cst']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 
              </tr>
              <tr class="row1">
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:150px;" value="<?php echo $GetRowData['vat_cst_amt'];?>" readonly="true"/>
              </div>

	</td>
                  </tr>
                <tr class="row1">
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per"  style="width:60px;" onchange="calsuroctamt(this.value)" value="<?php echo $GetRowData['sur_per'];?>"/>
				  <input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $GetRowData['sur_amt'];?>" style="width:90px;"  onfocus="calsuroctamt1()" /></td>
                </tr>
                <tr class="row1">
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:150px;" value="<?php echo $GetRowData['freight'];?>"/></td>
                </tr>
				 <td><strong>Loading/Unloading</strong> </td>
                  <td><input type="text" name="loading" id="loading1" style="width:150px;" value="<?php echo $GetRowData['loading'];?>"/></td>
                </tr>                
                <tr class="row1">
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $GetRowData['additional_charge'];?>" size="25" style="width:150px;" /></td>
                </tr>
				<!--<tr class="row1">
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;"/></td>
				</tr>-->
				
                <tr class="row1">
				<td><strong>Grand Total</strong></td>
                  <td><input type="text" name="grandtotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12" value="<?php echo $GetRowData['grand_total'];?>"/><input type="hidden"  id="orig_grand_tot" value="<?php echo $GetRowData['grand_total'];?>"/>&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="+" <?php if($GetRowData['round_off']=='+') echo "selected";?>>+</option>
				  <option value="-" <?php if($GetRowData['round_off']=='-') echo "selected";?>>-</option>
				  </select></td>
                </tr>
				</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<div align="left">
				<input type="button" onClick="open_box()" value="Update Boxes Details" class="search" id="upload_boxes" />
		  </div>
			 <div style="display:none;" id="box_block">
			 <hr>
			 <h1 align="center" style="text-align:center;">Update Boxes Details</h1>
			<br />
			<div style="height: auto" id="ItemListDiv">
			<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
			  <tr>
				<td class="tabledata1" colspan="3"><h3 style="color:#000000; font-size:16px;"><strong>Goods Received Note (GRN) Boxes Details</strong></h3></td>
				 <td class="tabledata1">No. of Rows</td>
				 <td class="tabledata1" colspan="2"><input type="text" name="countrow1" id="countrow1" value="" />
				 <input type="button" name="gen_rows" value="Generate Rows" onclick="generaterows()"/></td>
			  </tr>
			  <tr>
				<td class="tabledata">
					<input type="submit" name="delete" value="delete" /><br />
					<input name="disboxid" type="checkbox" id="disboxid" onclick="DisBoxData()"/>
					&nbsp;S. No.
				</td>
				<td class="tabledata">Package No.</td>
				<td class="tabledata">No. of Packages</td>
				<td class="tabledata">Content</td>
				<td class="tabledata">Layout</td>
				<td class="tabledata">Item</td>
			  </tr>
			   <?php  
				$j=0;
				$sqlQtybox = "SELECT * From log_addmrnbox Where grn_id='".$_GET['mrnid']."'";
				$Qty_resultbox = DB_query($sqlQtybox, $db);
				while($row2box=DB_fetch_array($Qty_resultbox))
				{?>
			  <tr>
				<td class="tabledata"><input name="disboxid[<?php echo $j; ?>]" type="checkbox" id="disboxid_<?php echo $j+1; ?>" value="1"  /><?php echo $j+1;?><input type="hidden" name="box_id[<?php echo $j;?>]" id="box_id_<?php echo $j;?>" value="<?php echo $row2box['id'];?>" /></td>
				<td class="tabledata"><input type="text" name="package_no[<?php echo $j;?>]" id="package_no_<?php echo $j;?>" value="<?php echo $row2box['package_no'];?>" /></td>
				<td class="tabledata"><input type="text" name="no_of_package[<?php echo $j;?>]" id="no_of_package_<?php echo $j;?>" value="<?php echo $row2box['no_of_package'];?>" ></td>
				<td class="tabledata"><input type="text" name="content[<?php echo $j;?>]" id="content_<?php echo $j;?>" value="<?php echo $row2box['content'];?>"></td>
				<td class="tabledata">
					<select name="layout[<?php echo $j;?>]" id="layout_<?php echo $j;?>" >
					<option value="0">Select</option>
					<?php 
					$sql1=DB_query("select * from log_floor where CompanyId='".$_SESSION['ACGCompanyId']."' AND store='".$store."'",$db);
					while($sql_floor=DB_fetch_array($sql1))
					{
					?> 
					<option value="<?php echo $sql_floor['id'];?>" <?php if($sql_floor['id']==$row2box['layout']){echo "selected";}?>><?php echo $sql_floor['floor_name']; ?></option>
					<?php } ?>
					</select>
				</td>
				<td class="tabledata">
					<select name="itemid[<?php echo $j;?>]" id="itemid_<?php echo $j;?>" >
					<option value="0">Select</option>
					<?php 
					$sql2=DB_query("select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' AND orig_local='".$store."'",$db);
					while($sql_floor2=DB_fetch_array($sql2))
					{
					?> 
					<option value="<?php echo $sql_floor2['id'];?>" <?php if($sql_floor2['id']==$row2box['itemid']){echo "selected";}?>><?php echo $sql_floor2['item_name']." -- ".$sql_floor2['StockID']; ?></option>
					<?php } ?>
					</select>
				</td>
			  </tr>
			  <?php $j++;} ?>
			  <tbody id="dataTablerows"></tbody>
			</table>
			<input type="hidden" name="countrow" id="countrow" value="<?php echo $j;?>" />
			<br />
			</div>
			</div>
		</td>
	</tr>
</table> 
			 
			
			 
				
			 
  </div>
		
			
		<div align="center">
		<input type="submit" name="Update" value="Update" onclick="return confirmPost()" />
		<input type="submit" name="reset" value="Reset" /><a href="index.php?route=LOG/transaction/goods_receipt_note_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" value="Cancel" name="Back" /></a>
		</div>
</form>
<script language="javascript" type="text/javascript">
 function claculateExcise(i,str)
  {
	var discounted=document.getElementById("basic_"+i).value;
	if (str.length==0)
	{
	document.getElementById("exciseId_"+i).innerHTML="";
	return;
	}

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


function calculateExciseDuty(i)
{

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




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




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



function cal_totalamount()
{
if(document.getElementById("ptype").value==3){
	if(document.getElementById("itemtotalrate").value!='')
	var firstrow=parseFloat(document.getElementById("itemtotalrate").value);
	else
	var firstrow=0;
}
	if(document.getElementById("ptype").value==3){
	var count=document.getElementById("hiditemcount").value;
	}else{
	var count=document.getElementById("hiditemcountnf").value;
	}
	if(count!='')
	{
		var totalprice=0;
		var totalprice1=0;
		for(var i=1;i<=count;i++)
		{
		 if(document.getElementById("itemtotalrate_"+i))
		   {
			  if(document.getElementById("itemtotalrate_"+i).value!='')
			  {
				totalprice=parseFloat(totalprice)+parseFloat(document.getElementById("itemtotalrate_"+i).value);
				}
				
			
				
		   }	
		}
		if(document.getElementById("ptype").value==3){
		var amt=parseFloat(totalprice)+parseFloat(firstrow);
		}else{
		var amt=parseFloat(totalprice);
		}
		document.getElementById("total_item_amount").value=amt.toFixed(2);
	}
	else
	{
	var amt=parseFloat(firstrow);
	document.getElementById("total_item_amount").value=amt.toFixed(2);
	}
	

	
}


function cal_totalamount1()
{
if(document.getElementById("itemtotalrate")){
if(document.getElementById("itemtotalrate").value!='')
var firstrow=parseFloat(document.getElementById("itemtotalrate").value);
else
var firstrow=0;
}

	var eerow = document.getElementById("ee_cnt").value;
	var count=document.getElementById("hiditemcount").value;
	var totalprice=0;
	var totalprice1=0;
	if(eerow>0){
	for(var e=0;e<eerow;e++)
		{
		 if(document.getElementById("itemtotalrate1_"+e))
		   {
			  if(document.getElementById("itemtotalrate1_"+e).value!='')
			  {
				totalprice=parseFloat(totalprice)+parseFloat(document.getElementById("itemtotalrate1_"+e).value);
				}
		   }	
		}
	}
	if(count!='')
	{
		
		for(var i=1;i<=count;i++)
		{
		 if(document.getElementById("itemtotalrate_"+i))
		   {
			  if(document.getElementById("itemtotalrate_"+i).value!='')
			  {
				totalprice=parseFloat(totalprice)+parseFloat(document.getElementById("itemtotalrate_"+i).value);
				}
				
			
				
		   }	
		}
		
		if(document.getElementById("itemtotalrate")){
			var amt=parseFloat(totalprice)+parseFloat(firstrow);
		}else{
			var amt=parseFloat(totalprice);
		}
		document.getElementById("total_item_amount").value=amt.toFixed(2);
	}
	else
	{
	var amt=parseFloat(firstrow);
	document.getElementById("total_item_amount").value=amt.toFixed(2);
	}
	

	
}



function cal_totalamount_data()
{	

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

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



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

function calcPackaging(str)
{

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





function DiscountAmount(DA,i)
{


	var discount_percent = document.getElementById("PerAmo_"+i).value;
	
	var discount = DA;
	var totalPrice = document.getElementById("item_total_rate_"+i).value;
	//alert(totalPrice);
	if(discount_percent=='PercentAmt')
	{
	if(discount==''){discount=0;}
	var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
	var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	var percent =parseFloat(DA);
	
	if(isNaN(percent)){percent=0;}
	var subTotal = totalPrice-parseFloat(percent);
	}
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("NetRate_"+i).value=subTotal.toFixed(2);
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	//return true;
}



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

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


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

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

function cal_grandtotal(i)
{
	var type_of_bill=document.getElementById("billing_type_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	var Totaltaxable=document.getElementById("taxableamount_"+i).value;
	if(basic==''){basic=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	//alert(type_of_bill);
	//alert(basic);
	//alert(Totaltaxable);
	if(document.getElementById("billing_type_"+i).value=='NonExcisable')
	{
	var grand_tot1=parseFloat(basic);
	var grand_tot=grand_tot1.toFixed(2);
	}	
	else if(document.getElementById("billing_type_"+i).value=='IncludeTax')
	{
	var grand_tot1= parseFloat(basic) ;
	var grand_tot=grand_tot1.toFixed(2);
	}
	else
	{
	var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
	var grand_tot=grand_tot1.toFixed(2);
	}
	document.getElementById("total_"+i).value=grand_tot ;	
}


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

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

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

function cal_grandamount()
{
	var total=document.getElementById("total_item_amount").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var totamt=document.getElementById("total_item_amount1").value;
	var taxamt=document.getElementById("taxvalue").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var loading1=document.getElementById("loading1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	

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

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


function open_items()
{
 var type=document.getElementById("storecode").value;
 if(type==0){alert("Please select warehouse first;"); return false;}
 window.open("mrn_items_for_logistic.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 open_box()
//{
// window.open("mrn_boxes_for_logistic.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 open_box()
{
 	if(document.getElementById("box_block").style.display=='none'){
		document.getElementById("box_block").style.display='block';
	}
}



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



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





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

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

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

}

function showsitename158(str)
{

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

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

	
}
 
  
  
</script>
<script type="text/javascript">

function calculate_poshort(id1)
{	
var i=id1.split("_");

if(i[1]==undefined)
{
var qty_per_bill=parseFloat(document.getElementById("qtyasperbill").value);
var reciveqty=parseFloat(document.getElementById("reciveqty").value);	
var short_accessid=qty_per_bill-reciveqty;
document.getElementById("shortaccessid").value=short_accessid;

}
else
{
id=i[1];
var qty_per_bill=parseFloat(document.getElementById("qtyasperbill_"+id).value);
var reciveqty=parseFloat(document.getElementById("reciveqty_"+id).value);	
var short_accessid=qty_per_bill-reciveqty;
document.getElementById("shortaccessid_"+id).value=short_accessid;

}

}

function confirmPost()
{
if(document.getElementById("site").value=='0')
{
alert("Must Select Site Name");
document.getElementById("site").focus();
return false;
}
if(document.getElementById("storecode").value=='0' || document.getElementById("storecode").value=='000')
{
alert("Must Select Warehouse Name");
document.getElementById("storecode").focus();
return false;
}
if(document.getElementById("ptype").value=='0')
{
alert("Must Select Purchase Type");
document.getElementById("ptype").focus();
return false;
}
if(document.getElementById("vendor").value=='0')
{
alert("Must Select  Vender");
document.getElementById("vendor").focus();
return false;
}
if(document.getElementById("document_type").value=='0')
{
alert("Must Enter Document Type");
document.getElementById("document_type").focus();
return false;
}
if(document.getElementById("document_no").value=='')
{
alert("Must Enter Document No");
document.getElementById("document_no").focus();
return false;
}
if(document.getElementById("doc_date").value=='')
{
alert("Must Enter Document Date");
document.getElementById("doc_date").focus();
return false;
}

var cou=document.getElementById("hiditemcount").value;
if(cou=='')
{
if(document.getElementById("reciveqty").value=='')
{
	alert("Please Fill recieve Qty of All item.");
	return false;
}
}else{
for(var i=1;i<=cou;i++)
{	
	if(document.getElementById("reciveqty").value=='')
	{
		alert("Please Fill recieve Qty of All item.");
		return false;
	}
	if(document.getElementById("reciveqty_"+i)){
		if(document.getElementById("reciveqty_"+i).value=='')
		{
			alert("Please Fill recieve Qty of All 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;
}		
return true;
}

function caltaxamout(i)
{
var excise=parseFloat(document.getElementById("exciseDuty_"+i).value);
if(excise!=0)
{
var basic_amount=document.getElementById("exciseValue_"+i).value;
var ecessamt=document.getElementById("ECessValue_"+i).value;
var sahamt=document.getElementById("SAHCessValue_"+i).value;
var totaltax=parseFloat(basic_amount)+parseFloat(ecessamt)+parseFloat(sahamt);	
document.getElementById('taxableamount_'+i).value=totaltax.toFixed(2);	
}
else
{
document.getElementById('taxableamount_'+i).value=0;		
}	
}

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

}
else
{
var id=id1[1];
var poqty1=parseFloat(document.getElementById("qtyasperbill_"+id).value);
	if(parseFloat(str)>poqty1)
	{
		var altmsg = "Quantity As Per bill cannot be greater of  qty as per bill";
		alert(altmsg);
		document.getElementById("qty_as_per_bill_"+id).value='';
		document.getElementById("reciveqty_"+id).value='';
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
	}
}
 
	
}

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

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


}
}

function calc_total_price(str1)
{
   var id=str1.split("_");
   
   if(id[1]==undefined)
   {
    var item_total_rate=0;
	var reciveqty = document.getElementById("reciveqty").value;
	var itemrate=document.getElementById("itemrate").value;
		
	if(reciveqty!='' && itemrate!='')
	{
	document.getElementById("itemtotalrate").value=(parseFloat(reciveqty)*parseFloat(itemrate)).toFixed(2);
	}
   
   }
   else
   {
   var str=id[1];
      var item_total_rate=0;
	var reciveqty = document.getElementById("reciveqty_"+str).value;
	var itemrate=document.getElementById("itemrate_"+str).value;
		
	if(reciveqty!='' && itemrate!='')
	{
		document.getElementById("itemtotalrate_"+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;
}*/



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

function getaddress(str)
{
	if(str==0){
		alert("Please select atleast one supplier.");
		return;
	}
	var pt = document.getElementById("ptype").value;
	var wh = document.getElementById("storecode").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("supaddress").innerHTML=data[0];
	document.getElementById("porder").innerHTML=data[1];
	}
	}
	if(pt==1 || pt==2){
		xmlhttp.open("GET","supaddress.php?sid="+str+"&pt="+pt,true);
	}else{
		xmlhttp.open("GET","supaddress.php?sid="+str,true);
	}
	xmlhttp.send();
}

function generaterows()
{  
	var j=document.getElementById("countrow").value;
	var str=document.getElementById("countrow1").value;
	var store=document.getElementById("storecode").value;
	if(str=='' || str<=0){
		alert("Please enter Number of rows to generate.");
		return;
	}
	if(store=='0'){
		alert("Please select warehouse first.");
		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("dataTablerows").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","generaterows.php?rno="+str+"&store="+store+"&j="+j,true);
	xmlhttp.send();
}
function addRow(tableID) 
{
//alert(tableID);
	if(document)
		//document.getElementById("back").style.display = "none";
    	//document.getElementById("showdata").style.display = "block";
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcountO").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			 // newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
					
					
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
	
function deleteRowOrderO(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcountO").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}
function opendatas(str,id)
{
  var sitecode=document.getElementById("site").value;
  var storecode=document.getElementById("storecode").value;

 if (str.length == 0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	
	
	if(sitecode=='0')
	{
	alert("Must Select Site");
	document.getElementById("sitecode").focus();
	return;
	}
	
	if(storecode=='000')
	{
	alert("Must Select Warehouse");
	document.getElementById("storecode").focus();
	return;
	}

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	//alert(xmlhttp.responseText);
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
    }
  }
  
  xmlhttp.open("GET","log_showpopup.php?site="+str+"&data="+id+"&site1="+storecode,true);
	xmlhttp.send();	
}

function getItemsList1(id,code,shade,netrate,ctr)
{ 
    var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	if(ctr1[1]==undefined)
	{
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	}
	else
	{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	}	
	document.getElementById("lightbox").style.display='none';
	var data= addRow('dataTable')
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}

function calamt(id,str)
{
	var id1=id.split("_");
	var i=id1[1];
	if(id1[1]==undefined)
	{
		if(document.getElementById("poqty").value==''){
			alert("Please fill qty field");
			document.getElementById("poqty").focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty").value);
		document.getElementById("itemtotalrate").value=total.toFixed(2);
	}
	else
	{
	if(document.getElementById("poqty_"+i).value==''){
			alert("Please fill qty field");
			document.getElementById("poqty_"+i).focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty_"+i).value);
		document.getElementById("itemtotalrate_"+i).value=total.toFixed(2);
	}
}

function calamt1(id,str)
{
	var id1=id.split("_");
	var i=id1[1];
	if(id1[1]==undefined)
	{
		if(document.getElementById("poqty").value==''){
			alert("Please fill qty field");
			document.getElementById("poqty").focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty").value);
		document.getElementById("itemtotalrate").value=total.toFixed(2);
	}
	else
	{
	if(document.getElementById("poqty_"+i).value==''){
			alert("Please fill qty field");
			document.getElementById("poqty_"+i).focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty_"+i).value);
		document.getElementById("itemtotalrate_"+i).value=total.toFixed(2);
	}
}

function calamt2(id,str)
{
	var id1=id.split("_");
	var i=id1[1];
	if(id1[1]==undefined)
	{
		if(document.getElementById("poqty").value==''){
			alert("Please fill qty field");
			document.getElementById("poqty").focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty").value);
		document.getElementById("itemtotalrate").value=total.toFixed(2);
	}
	else
	{
	if(document.getElementById("poqty_"+i).value==''){
			alert("Please fill qty field");
			document.getElementById("poqty_"+i).focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty_"+i).value);
		document.getElementById("itemtotalrate_"+i).value=total.toFixed(2);
	}
}

function calamt3(id,str)
{
	var id1=id.split("_");
	var i=id1[1];
	if(id1[1]==undefined)
	{
		if(document.getElementById("poqty1").value==''){
			alert("Please fill qty field");
			document.getElementById("poqty1").focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty1").value);
		document.getElementById("itemtotalrate1").value=total.toFixed(2);
	}
	else
	{
	if(document.getElementById("poqty1_"+i).value==''){
			alert("Please fill qty field");
			document.getElementById("poqty1_"+i).focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty1_"+i).value);
		document.getElementById("itemtotalrate1_"+i).value=total.toFixed(2);
	}
}


function changetype()
{
	var pt=document.getElementById("ptype").value;
	if(pt!=0){
		if(pt==3){
			document.getElementById("nfoc").style.display='none';
			document.getElementById("bfoc").style.display='block';
			document.getElementById("foc").style.display='block';
		}else{
			document.getElementById("bfoc").style.display='none';
			document.getElementById("foc").style.display='none';
			document.getElementById("nfoc").style.display='block';
		}
	}else{
		alert("Please select a type.");
	}
}

function getitemlist(str)
{
	if(str==0){
		alert("Please select a po order.");
		return false;
	}
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		document.getElementById("nfoc").innerHTML=xmlhttp.responseText;
    }
  	}
    xmlhttp.open("GET","log_nfoc.php?po="+str,true);
	xmlhttp.send();	
}

function checkqty(str,ii)
{	
	if(str==''){
		alert("Please enter received quantity.");
		return false;
	}
	if(parseFloat(str)>parseFloat(document.getElementById("peqty_"+ii).value)){
		alert("RECEIVED QTY NOT MORE THAN PENDING QUANTITY.");
		document.getElementById("poqty_"+ii).focus();
		return false;
	}
}
function DisBoxData()
{	
	var t=document.getElementById("countrow").value;
	if(document.getElementById('disboxid').checked==true)
	{	
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('disboxid_'+i).checked=true;	
	}	
	}
	else
	{
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('disboxid_'+i).checked=false;	
	}
	}
}
</script>