				<script>
function displayData(str)
{
	var rec=document.getElementById("receiviedagaist").value;
	var sitCode=document.getElementById("sidecode").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)
	{
	document.getElementById("hid_POrder").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","disp_porder1.php?q="+str+"&site="+sitCode,true);
	xmlhttp.send();
}

function dutyTypeDisabled(str)
{
	var grntypes=document.getElementById("GrnType").value;
	var order1=document.getElementById("ordno1").value;
	var order2=document.getElementById("ordno2").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)
	{
	document.getElementById("abc").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","grnDisabledData.php?dutytype="+str+"&grntype="+grntypes+"&ord1="+order1+"&ord2="+order2,true);
	xmlhttp.send();
}

function calTotalQty1(val,id)
{
var totalamt=0;
	var countcharges = document.getElementById("count").value;
	for(var i=0;i<countcharges;i++)
	{
	var qtyBill1 = document.getElementById("qty_as_per_bill_"+i).value;
	if(qtyBill1==''){qtyBill1=0;}
		var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
	}
	document.getElementById("short").value=totalamt.toFixed(2);
}

function calTotalQty(val,id)
{
var qtyBill = document.getElementById("qty_as_per_bill_"+id).value;
if(qtyBill==''){qtyBill=0;}
	if(val>qtyBill)
	{
	var diff = parseFloat(val)-parseFloat(qtyBill);
	}
	else
	{
	var diff =  parseFloat(qtyBill)-parseFloat(val);
	}
	document.getElementById("short_accessid_"+id).value=diff.toFixed(2);
	
	
	var totalamt=0;
	var countcharges = document.getElementById("count").value;
	for(var i=0;i<countcharges;i++)
	{
	var rec1 = document.getElementById("reciveqty_"+i).value;
	if(rec1==''){rec1=0;}
		var totalamt=parseFloat(totalamt)+parseFloat(rec1);
	}
	document.getElementById("short1").value=totalamt.toFixed(2);
}
function check_bill_qtyNew(str,id)
{
	var poqty=parseInt(document.getElementById("pending_"+id).value);
	var tolerance = document.getElementById("tolerances_"+id).value;
	if(tolerance==''){tolerance=0;}
	if(poqty==''){poqty=0;}
	str1=parseInt(str);
	if(str1==''){str1=0;}
	if(tolerance==0)
	{
		if(poqty<str1)
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
		}
	}
	else
	{
	var p1 = (tolerance*poqty)/100;
	var p2 = parseFloat(poqty)+parseFloat(p1);
		if(p2<str1)
		{
		alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
		}
	}	
}
function getOther(int)
{
	if(int=="other")
	{
	document.getElementById("otherReason").style.display="block";
	}
	else
	{
	document.getElementById("otherReason").style.display="none";
	}
}
				</script>
				<?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');
				}
				
				$url_cancel= "index.php?route=Inventory/transation/material_receipt_note_index".$rurl;
				$url_add= "index.php?route=Inventory/transation/material_receipt_note_edit".$rurl;
				$CompanyId =$_SESSION['ACGCompanyId'];
				$sql_query1 = "SELECT * FROM mrn_comercial_flag where company_id=".$CompanyId;
		$sqlQuery1 =DB_query($sql_query1,$db);
		$rowNew=DB_fetch_array($sqlQuery1);
		 $mrnFlag=$rowNew['mrn_flag'];
if(isset($_REQUEST['save']))
{

		$data['BillNo'] = $_REQUEST['billno']; 
		$data['MRNVoucherDate'] = FormatDateForSQL($_REQUEST['MRNVoucherDate']); 
		$data['GetPassNo'] = $_REQUEST['gatepassno']; 
		$data['Transp_name'] = $_REQUEST['transporters'];  
		$data['VehicleNo'] = $_REQUEST['vehicalno'];
		$data['containerNo'] = $_REQUEST['containerNo'];
		$data['LRno'] = $_REQUEST['lrno'];
		$data['LRdate'] = FormatDateForSQL($_REQUEST['lrdate']); 
		$data['form_type'] = $_REQUEST['form_type'];  
		$data['form_no'] = $_REQUEST['form_no'];
		$data['gatepassdate'] = FormatDateForSQL($_REQUEST['gatepassdate']);
		$data['RemarksIfAny'] = $_REQUEST['RemarksIfAny'];
		$data['modified_by'] =$_SESSION['UserID']; 
		$data['modified_date'] =date('Y-m-d'); 
		$data['companyID'] = $_SESSION['ACGCompanyId'];	
		$data['totalBillQty'] = $_REQUEST['totalBillQty'];
		$data['totalRecQty'] = $_REQUEST['totalRecQty'];	
		
		$condition="id='".$_REQUEST['mrnId']."'"; 
		$s->RecordEdit('addmrn', $data, $condition);
		
		$del1=DB_query("delete from addmrnqty where issue_id='".$_REQUEST['mrnId']."'",$db);
		for($i=0;$i<$_REQUEST['countval'];$i++)
		{
				$data_arr1['issue_id']= $_REQUEST['mrnId'];
				$data_arr1['mst_itemid']= $_REQUEST['mst_itemid'][$i];
				$data_arr1['POQty']= $_REQUEST['poqty'][$i];
				$data_arr1['pending_qty']= $_REQUEST['pending_qty'][$i];
				$data_arr1['qty_as_per_bill']= $_REQUEST['qty_as_per_bill'][$i];
				$data_arr1['reciveqty']= $_REQUEST['reciveqty'][$i];
				$data_arr1['short_accessid']= $_REQUEST['short_accessid'][$i];	
						
				
					
				if($_REQUEST['short_accessid'][$i]!=0)
					{
					$pending_status=1;
					$data_arr1['status']= "N";
					}
					else
					{
					 $data_arr1['status']= "Y";
					}
					//echo "<pre>";
					//print_r($data_arr1); 
					
					$insert_mrm=$s->insertRecord('addmrnqty', $data_arr1);
				$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
					$insertResult1 = DB_query($insert_mrm,$db,$ErrMsg);
		}
		
		
		$mosql1=DB_query("SELECT createddate,createdby FROM addmrn where id='".$_REQUEST['mrnId']."'",$db);
    $mo1=DB_fetch_array($mosql1);
	if($_REQUEST['reason']=='other')
	{
		$datain['moduleid']=$_REQUEST['modid']; 
		$datain['frm_id']=$_REQUEST['frmid'];  
		$datain['reason_type']='2'; 
		$datain['reason']=$_REQUEST['otherReason']; 
		$datain['created_by']=$mo1['createdBy']; 
		$datain['created_date']=$mo1['createdDate']; 
		$datain['companyID']=$_SESSION['ACGCompanyId'];  
		$datain['modify_by']=$_SESSION['UserID'];
		$datain['modify_date']=date('Y-m-d');  
		$s->RecordInsert('reason_master', $datain);
		$last_id=DB_Last_Insert_ID($db,'reason_master','id');
	    $datareason['doc_id']=$_REQUEST['SID']; 
		$datareason['reason_id']=$last_id; 
		$datareason['frm_id']=$_REQUEST['frmid']; 
		$datareason['doc_type']='2'; 
		$datareason['doc_date']=$mo1['createdDate']; 
		$datareason['doc_created_by']=$mo1['createdBy']; 
		$datareason['company_id']=$_SESSION['ACGCompanyId'];  
		$datareason['modified_by']=$_SESSION['UserID'];
		$datareason['modified_date']=date('Y-m-d');  
		$s->RecordInsert('log_reason', $datareason);
	}
	else
	{
	   $datareason['doc_id']=$_REQUEST['SID']; 
		$datareason['reason_id']=$_REQUEST['reason']; 
		$datareason['frm_id']=$_REQUEST['frmid']; 
		$datareason['doc_type']='2'; 
		$datareason['doc_date']=$mo1['createdDate']; 
		$datareason['doc_created_by']=$mo1['createdBy']; 
		$datareason['company_id']=$_SESSION['ACGCompanyId'];  
		$datareason['modified_by']=$_SESSION['UserID'];
		$datareason['modified_date']=date('Y-m-d');  
		$s->RecordInsert('log_reason', $datareason);

	}
		$s->pageLocation("index.php?route=Inventory/transation/material_receipt_note_exo_index".$rurl);
		
		
} 

//**************************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['site'];
		$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'];
	    $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'];
		$Form_Type=$GetRowData['form_type'];
		$Form_No=$GetRowData['form_no'];
		$gatepassdate=$GetRowData['gatepassdate'];
		$RemarksIfAny=$GetRowData['RemarksIfAny'];
		$OrderDate=$GetRowData['OrderDate'];
	    $StoreCode=$GetRowData['StoreCode'];
		$StoreName=$GetRowData['StoreName'];
		$totalqty=$GetRowData['totalqty'];
		$orderNo=$GetRowData['order_no'];
		$grntype=$GetRowData['grn_type'];
		$dutyType=$GetRowData['duty_type'];
		$totalAmount=$GetRowData['total_amount'];
		$pkgPerc=$GetRowData['pkg_perc'];
		$pkgCharges=$GetRowData['pkg_charges'];
		$pkgCharges=$GetRowData['pkg_charges'];
		$frieght = $GetRowData['freight'];
		$totalCustom = $GetRowData['total_custom_duty'];
		$custom_sec = $GetRowData['custom_sec_ecess'];
		$cvdTotal = $GetRowData['cvd_total'];
		$grandTotal = $GetRowData['grandtotal'];
		$custEcess = $GetRowData['custom_ecess'];
		$addCharges = $GetRowData['add_charges'];
		$loadingData = $GetRowData['loading'];
		$_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'];	}
?>
<h2 align="center"><strong>Material Receipt Note Edit</strong></h2>
<br />
<div style="width:100%">
<h3><strong>GENERAL DETAILS</strong></h3>
</div>
<form action="" method="post">
<table width="100%" border="1" cellspacing="2" cellpadding="5" align="center">
  <?php 
if(isset($msg_error))
{
?>
  <tr>
    <td colspan=""><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>" ;
		}?>
      </tr>
    </table></td>
  </tr>
  <?php } 	 ?>
  <tr>
  <input type="hidden" name="mrnId" value="<?php echo $GetRowData['id']; ?>" />
    <th width="15%"><strong>Mrn No. </strong></th>
    <td width="30%">
    <input name="mrnNos" type="text" id="mrnNos" style="width:100%" value="<?php if($_REQUEST['mrnNum']!="")
	{ echo $_REQUEST['mrnNum']; } else {echo $MRNNo;} ?>" readonly/></td>
    <th width="31%"><strong>MRN Date </strong></th>
    <td width="24%" colspan="2"><input type="text" name="MRNdate" id="MRNdates" style="width:180px" value="<?php if($_REQUEST['mrnDate']!="")
	{ echo $_REQUEST['mrnDate']; } else {echo ConvertSQLDate($MRNDate);} ?>" readonly/></td>
  </tr>
  <tr>
    <th><strong>Site</strong></th>
    <td><input type="text" size="5" value="<?php
	if($_REQUEST['sitecode']!="") { echo $s->getField('locations','loccode',$_REQUEST['sitecode'],'locationname'); } else{echo $s->getField('locations','loccode',$OrderFromSite,'locationname'); }?>" name="sitecode" id="sitecode" readonly/>      </td>
    <th><strong> Warehouse  </strong>        </th>
    <td>
        <input type="text" value="<?php echo $s->getField('storetype','id',$StoreCode,'StoreName'); ?>" style="width:100%" name="storename" id="storecode" readonly/></td>
  </tr>
  <tr>
    <th><strong>Received Against</strong></th>
    <td ><input name="receiviedagaist" type="text" id="receiviedagaist" style="width:100%" value="<?php if($_REQUEST['receipt']!="")
	{ echo $_REQUEST['receipt']; } else {echo $Type;} ?>" readonly/></td>
    <th scope="row"><strong>Vendor</strong></th>
    <td>
	<input type="text" value="<?php echo str_replace(array("M/s ","M/S"),'',$s->getField('suppliers','id',$ReceivedFrom,'vendor_name'));
	 ?>" style="width:100%" name="vendor" id="vendor" readonly/>
		 </td>
  </tr>
 <tr>
    <th><strong>PO</strong></th>
    <td>
	<input name="Purchase_Order" type="text" style="width:100%" readonly value="<?php echo $s->getField('direct_po','id',$GetRowData['PO_WO_MTO'],'pr_no'); ?>"/> 
	 </td>
    <th><strong>PO Date </strong></th>
    <td><input name="ordDate" type="text" style="width:100%" value="<?php echo  ConvertSQLDate($s->getField('direct_po','id',$GetRowData['PO_WO_MTO'],'pr_date')); ?>" readonly/>    </td>
  </tr>
  <tr>
    <th><strong>GRN Type</strong></th>
    <td>
	<input name="GrnType" type="text" style="width:100%" readonly value="<?php if($grntype=='1') { echo 'Import'; } else { echo 'Domestic'; } ?>"/>
     </td>
    <th><strong>Document No. </strong></th>
    <td><input name="billno" type="text" id="billno" style="width:100%" value="<?php  echo $GetRowData['BillNo']; ?>" /></td>
  </tr>
  <tr>
    <th scope="row"><strong>Challan / Bill Date</strong></th>
    <td><input type="text" name="MRNVoucherDate" style="width:100%" class="datepicker"  value="<?php echo ConvertSQLDate($MRNVoucherDate); ?>"/></td>
    <th><strong>Gate Entry no</strong></th>
    <td><input type="text" name="gatepassno"  style="width:100%" id="gatepassno"  value="<?php echo $GetPassNo;?>" /></td>
  </tr>
  <tr>
    <th scope="row"><strong>Transporter Name</strong></th>
    <td>
	<?php $sql_transporter = "select id,TransportName from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$resultTrans = DB_query($sql_transporter,$db); ?>
		<select id='transporters' name='transporters'  style='width:100%;'>
		<option value='000'>--Select--</option>
		<?php 
		while ($myrowTrans=DB_fetch_array($resultTrans))
		{
		 ?>
		<option Value="<?php echo $myrowTrans['id']; ?>"<?php if($GetRowData['Transp_name']==$myrowTrans['id']) { echo 'selected'; } else { echo '';} ?>><?php echo $myrowTrans['TransportName']?></option>
		<?php } ?>
		</select></td>
    <th><strong>Vehicle No.</strong></th>
    <td><input name="vehicalno" type="text" id="vehicalno"  style="width:100%" value="<?php echo $VehicleNo; ?>"/></td>
  </tr>
  <tr>
    <th scope="row"><strong>Container No.</strong></th>
    <td><input type="text" name="containerNo"  style="width:100%;" value="<?php echo $GetRowData['containerNo']; ?>" id="containerNo"/></td>
    <th><strong>L R No.</strong></th>
    <td><input name="lrno" type="text" id="lrno" style="width:100%" value="<?php echo $GetRowData['LRno']; ?>"/></td>
  </tr>
  <tr>
    <th scope="row"><strong>L R Date</strong></th>
    <td><input name="lrdate" type="text" id="lrdate" style="width:100%" value="<?php echo ConvertSQLDate($LRdate); ?>"  onblur="LRdate();" class="datepicker"/></td>
    <th><strong>Form Type</strong></th>
    <td><select name="form_type" id="form_type"  style="width:100%;">
			<option value="000" >---Select---</option>
			<?php
			$sql="select id,form_name from form_type_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php if($GetRowData['form_type']==$myrow['id']) { echo 'selected'; } else { echo '';} ?>><?php echo  $myrow['form_name']; ?></option>
		<?php } ?>
		</select></td>
  </tr>
  <tr>
    <th height="37" scope="row"><strong>Form No</strong></th>
    <td>
      <input type="text" name="form_no"  style="width:100%" value="<?php echo $GetRowData['form_no']; ?>" id="form_no" /></td>
    <th>Gate Entry Date</th>
    <td><input type="text" name="gatepassdate" id="gatepassdate" value="<?php echo ConvertSQLDate($gatepassdate); ?>" style="width:100%" class="datepicker" /></td>
  </tr>
  <tr>
  <th scope="row"><strong>Remarks If Any</strong></th>
    <td><textarea name="RemarksIfAny"  id="RemarksIfAny"  style="width:200px;"><?php echo $RemarksIfAny;?></textarea></td>
    
    <th scope="row"><strong>Document Type</strong></th>
    <td><select name="DocumentType" id="DocumentType" style="width:100%">
	<option value="">--Select--</option>
      <option value="Challan"<?php if($DocumentType=='Challan') { echo 'selected'; } else { echo ''; } ?>>Challan</option>
      <option value="Bill"<?php if($DocumentType=='Bill') { echo 'selected'; } else { echo ''; } ?>>Bill</option>
	   <option value="Bill"<?php if($DocumentType=='BOL') { echo 'selected'; } else { echo ''; } ?>>Bill Of Leading</option>
    </select></td>
  </tr>
  <tr class="row1">
    
	<th align="left" valign="top"><?php if($mrnFlag=='0'){ ?>
	  <strong>Duty Type</strong><?php } ?></th>
    <td align="left" valign="top"><?php if($mrnFlag=='0'){ ?><select name="DutyType" id="DutyType" style="width:200px;" onchange="grnDisabled1(this.value)">
	<option value="">--Select--</option>
	<option value="Consolidated">Consolidated</option>
	<option value="Itemwise">Itemwise</option>
	</select><?php } ?></td>
	
	<td><strong>Reason</strong>		</td>
		<td>
		<?php
			
		 $mosql=DB_query("SELECT id,reason FROM reason_master where moduleid='".$_REQUEST['modid']."' and frm_id='".$_REQUEST['frmid']."' and reason_type='2' and created_by='".$_SESSION['UserID']."' and CompanyId='".$_SESSION['ACGCompanyId']."' order by created_date DESC",$db);
		$selectreason=DB_query("SELECT reason_id FROM log_reason where doc_id='".$_REQUEST['SID']."' order by id DESC",$db);
		$secarr=DB_fetch_array($selectreason); ?>
		<select name="reason" id="reason" style="width:200px;" onchange="getOther(this.value)">
      <option value="">--Select--</option>
	 <?php while($mo=DB_fetch_array($mosql)){
	 ?>
	  <option value="<?php echo $mo['id']; ?>" <?php echo ($secarr['reason_id']==$mo['id']?'selected':'')?>><?php echo $mo['reason']; ?></option>
	  <?php }?>
	  <option value="other" <?php echo ($secarr['reason_id']=='other'?'selected':'')?>>Other</option>
    </select>
	<textarea name="otherReason" id="otherReason" style="width:100%;<?php if($secarr['reason_id']=='other'){?>display:block;<?php }else{?>display:none;<?php }?>"><?php echo $s->getField('reason_master','id',$secarr['reason_id'],'reason');?></textarea></td>
  </tr>
</table>
<br /><br />
 <?php if($mrnFlag=='1'){ ?>
	<div id="itemTable" style="width:950px;overflow:auto;">
	<table width='100%' border='1' cellspacing='0' cellpadding='3' style='border:1px solid #333333;'>
<tr>
	<td class='tabledata'><strong>Sr.No.</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>QTY AS PER BILL </strong></td>
	<td class='tabledata'><strong>QTY Recieved</strong></td>
	<td class='tabledata'><strong>Short/Excess Quantity</strong></td>
 </tr>
 <?php
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$GetRowData['id']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	 $check_last_mrn="Select qty from direct_po_details 
	where parent_id='".$GetRowData['PO_WO_MTO']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	$check_last_mrn1="Select sum(reciveqty) from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id 
	where addmrn.PO_WO_MTO='".$GetRowData['PO_WO_MTO']."' and addmrnqty.mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
	
	$last_mrn_row1=DB_fetch_array($last_mrn_res1);
	 $last_mrn_row1['sum(reciveqty)'];
	if($last_mrn_row['qty']>=$last_mrn_row1['sum(reciveqty)'])
	{
		$pending_qty=$last_mrn_row['qty']-($last_mrn_row1['sum(reciveqty)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['qty'];
	}	
?>
<tr bgcolor='#c1c1c1'>
	<td><?php echo $i+1; ?></td>
	<td><?php echo $itemcode; ?>
	<input type='hidden' name='convfac[]' id='convfac_<?php echo $i; ?>' value='<?php echo $confac; ?>' />
	<input type='hidden' readonly='' id='mst_itemid_<?php echo $i; ?>' name='mst_itemid[]' size='15' value='<?php echo $row['mst_itemid']; ?>' />
	<input type='hidden' readonly='' id='itemcode_<?php echo $i; ?>' name='itemcode[]' size='15'  value='<?php echo $itemcode; ?>' />
	<input type='hidden' readonly='' id='tolerances_<?php echo $i; ?>' name='tolrancees[]' size='15'  value='<?php echo $tolerance; ?>' />
	<input type='hidden' readonly='' id='pending_<?php echo $i; ?>' name='pending[]' size='15'  value="<?php echo $pending_qty; ?>" /></td>
	<input type='hidden' readonly='' id='mst_itemid_".$i."' name='details_id[]' size='15' value='<?php echo $row['id']; ?>' />
	<td><?php echo $row['mst_itemid']; ?></td>
	<td><?php echo $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname'); ?></td>
	<td><?php echo $poqty=$row['POQty']; ?>
	<input name='poqty[]' type='hidden' id='poqty_<?php echo $i; ?>' value='<?php echo $poqty; ?>' size='10'/></td>
	<td><?php echo $pending_qty; ?>
	<input type='hidden' name='pending_qty[]' id='pending_qty_<?php echo $i; ?>' value='<?php echo $pending_qty; ?>' />	</td>
	<td><input name='qty_as_per_bill[]' type='text' id='qty_as_per_bill_<?php echo $i; ?>'  onkeyup='calTotalQty1(this.value,<?php echo $i; ?>);' size='8' onblur='check_bill_qtyNew(this.value,<?php echo $i; ?>)' value='<?php echo $row['qty_as_per_bill']; ?>'/></td>
	<td><input name='reciveqty[]' type='text' id='reciveqty_<?php echo $i; ?>' onkeyup='calTotalQty(this.value,<?php echo $i; ?>);' value='<?php echo $row['reciveqty']; ?>'  size='8' /></td>
	<td><input name='short_accessid[]' type='text' id='short_accessid_<?php echo $i; ?>' value='<?php echo $row['short_accessid']; ?>' size='8' readonly='true' onfocus='calculate_poshort(<?php echo $i; ?>);'/></td>
</tr>
<?php
 
 $i++; }
 ?>	
<tr bgcolor='#c1c1c1'>
<td colspan='6'>Total Qty </td>
<td><input name='totalBillQty' type='text' value='<?php echo $GetRowData['totalBillQty']; ?>' id='short'  size='8' /></td>
<td colspan='2'><input name='totalRecQty' type='text' value='<?php echo $GetRowData['totalRecQty']; ?>' id='short1'  size='8' /></td>
</tr>
 <input type='hidden' name='countval' value='<?php echo $i; ?>'   id='count'/>
</table>
 	</div>
	<?php } ?> 
	<br/>
	<br/>
	 
<div id="abc">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>
<?php if($grntype=='1' && $dutyType=='Itemwise') { ?>
 <div  style="width:900px;display:block;overflow:auto;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr>
	<th class="tabledata"><strong>Sr.No.</strong></th>
	<th class="tabledata"><strong>Item Code</strong></th>
	<th class="tabledata"><strong>Description</strong></th>
	<th class="tabledata"><strong>UOM</strong></th>
	<th class="tabledata"><strong>PO QTY</strong></th>
	<th class="tabledata"><strong>Pending QTY</strong></th>
	<th class="tabledata"><strong>Batch No.</strong></th>
	<th class="tabledata"><strong>QTY AS PER BILL </strong></th>
	<th class="tabledata"><strong>QTY Recieved</strong></th>
	<th class="tabledata"><strong>Short Quantity</strong></th>
	<th class="tabledata"><strong>Rate</strong></th>
	<th class="tabledata"><strong>Amount</strong></th>
	<th class="tabledata"><strong>Dis. Type</strong></th> 
	<th class="tabledata"><strong>Dis. % <br />or amt</strong>.</th>
	<th class="tabledata"><strong>Final<br  />Dis. Amt.</strong></th>
	<th class="tabledata"><strong>Discounted Amount</strong></th>
	<td class="tabledata"><strong>Currency</strong></td>
	<td class="tabledata" ><strong>Conversion<br /> Curr.</strong></td>
	<td class="tabledata"><strong>Conversion<br /> Rate</strong></td>
	<th class="tabledata"><strong>Basic<br /> Amt.</strong></th>
	<th class="tabledata"><strong>Custom Duty Flag</strong></th>
	<th class="tabledata"><strong>Custom Duty</strong></th>
	<th class="tabledata"><strong>Duty Amount</strong></th>
	<th class="tabledata"><div style="width:47px;"><strong>CVD</strong></div></th>
	<th class="tabledata"><strong>Custom E.Cess</strong></th>
	<th class="tabledata"><strong>Custom SE.Cess</strong></th>
	<th class="tabledata"><strong>Add. Duty</strong></th>
  </tr>
  <input type="hidden" id="cvd_percentage" value="<?php echo $s->getField('custom_duty','type','CVD','def_rate');?>" />
  <input type="hidden" id="ecess_percentage" value="<?php echo $s->getField('custom_duty','type','ECESS','def_rate');?>" />
  <input type="hidden" id="secess_percentage" value="<?php echo $s->getField('custom_duty','type','SHE-CESS','def_rate');?>" />
  <input type="hidden" id="add_percentage" value="<?php echo $s->getField('custom_duty','type','ADC','def_rate');?>" />
  <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrnid']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$tolerance=$s->getField('item_master','id',$row['mst_itemid'],'tolerance');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	where order_no='".$orderNo."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']);
	}
	else
	{
		$pending_qty=$row['qty'];
	}	
	

?>

<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	</td>
	<td><?php echo $itemname ?></td>
	<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
	<td><?php   echo $poqty=$row['POQty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="<?php echo $row['batch_no'];?>" /></td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill2_<?php echo $i; ?>" value="<?php echo $row['qty_as_per_bill'];?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty2_<?php echo $i; ?>"  size="8"  onkeyup="check_po_qty1(<?php echo $i;?>)" value="<?php echo $row['reciveqty']; ?>"  /></td>
	<!--<td><input name="scecondarqty[]" type="text" id="scecondarqty_<?php echo $i; ?>"  size="8"   /></td>-->
	<td><input name="short_accessid[]" type="text" id="short_accessid2_<?php echo $i; ?>" value="<?php echo  $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort2(<?php echo $i ?>);"/></td>
	<td><?php //echo $row['rate'];?>
	<input name="itemrate[]" type="rext" id="itemrate2_<?php echo $i; ?>" readonly="true"  size="8" value="<?php echo  $row['itemprice'];?>"/>
	</td>
	<td>
	<input name="itemamount[]" type="text" id="itemamount2_<?php echo $i; ?>" onfocus="calculateTotalPrice2(this.id)"  size="8" readonly="true" value="<?php echo $row['itemamount'];?>"/>
	</td>
	<td class="tabledata" id ="hideArea1"><select style="width:80px;" name="DiscountType1[]" id="PerAmo2_<?php echo $i; ?>">
            <option value="Amount"<?php echo ($row['DiscountType1']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row['DiscountType1']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td><input type="text" style="width:40px" name="discount[]" id="Discount2_<?php echo $i;?>" onblur="DiscountAmount3(this.value,this.id)" value="<?php echo $row['discount_1'];?>" /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc2_<?php echo $i; ?>"  readonly="true" style="width:100%;" onFocus="Check(this.value)" value="<?php echo $row['discounted_amount1'];?>"/></td> 
		<td class="tabledata" id ="hideArea3"><input type="text"  id="NetRate2_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" value="<?php echo $row['NetRate1'];?>" readonly/></td>
		<td><input name="itemCurrency[]" type="text" id="itemCurrency_<?php echo $i; ?>" value="<?php echo $row['itemCurrency'];?>" size="8" readonly="true"/>
	</td>
	<td class="tabledata"><select style="width:80px;" name="conv_curr[]" id="conv_curr_<?php echo $i; ?>">
			<?php $curr_sql=DB_query("Select * from currency_master",$db);
			while($curr_row=DB_fetch_array($curr_sql))
			{  ?>
            <option value="<?php echo $curr_row['id']; ?>"<?php echo ($row['conv_curr']==$curr_row['id'])?'selected':''?>><?php echo $curr_row['abbreviation']; ?></option>
			<?php } ?>
          </select></td>
		  <td><input name="conv_rate[]" type="text" id="conv_rate_<?php echo $i; ?>" onblur="calcNewAmount(this.id,this.value)" size="8" value="<?php echo $row['conv_rate'];?>"/></td>
		<td class="tabledata"><input type="text" style="width:70px" id="basic_<?php echo $i;?>" name="basic[]" onblur="cal_basic_total(this.id)" value="<?php echo $row['basic'];?>" readonly/></td>
		<td class="tabledata"><select name="Excise_type1[]" style="width:85px" id="hid_billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,this.id)">
	<option value="">Select</option>
	<option value="1"<?php echo ($row['Excise_type1']=='Amount')?'selected':''?>>Yes</option>
	<option value="2"<?php echo ($row['Excise_type1']=='Amount')?'selected':''?>>No</option>
</select></td>
	<td class="tabledata"><select name="Excise_Duty1[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;"    onchange="claculateExcise(this.id,this.value)" onblur="checkexiseflag(this.id)">
    	    <option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from custom_duty where type='custom'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"<?php echo ($row['Excise_Duty1']==$excise_row['id'])?'selected':''?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $j;?>"></div>
      </td>
		  <td class="tabledata"><input type="text"  id="dutyamount_<?php echo $i;?>" readonly="" onfocus="checkduty(this.id)" name="duty_amount[]" style="width:70px;" onblur="cal_custom_total(this.id)" value="<?php echo $row['duty_amount_1'];?>"/></td><?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?> 
		<td class="tabledata">
		<input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalAmount1[]" style="width:70px;" onfocus="cal_grandtotal(this.id);" value="<?php echo $row['TotalAmount1'];?>" onblur="cal_cvd_total(this.id);"/></td>
		<td class="tabledata"><input type="text" id="customecess_<?php echo $i;?>" name="custom_ecess[]" style="width:70px;" onblur="cal_ecess_total(this.id);" value="<?php echo $row['custom_ecess'];?>" onfocus="cal_e_cess1(this.id);" / ></td>
		<td class="tabledata"><input type="text" id="customsececess_<?php echo $i;?>" name="custom_sec_ecess[]" style="width:70px;" onblur="cal_ecess_sec_total(this.id);" value="<?php echo $row['custom_sec_ecess'];?>"  onfocus="cal_esec_cess1(this.id);" / ></td>
		<td class="tabledata"><input type="text" id="adduty_<?php echo $i;?>" name="adduty[]" style="width:70px;" value="<?php echo $row['adduty'];?>" onfocus="cal_add_duty1(this.id);"  onblur="cal_addcharg_total(this.id);"  / ></td>
</tr>
  <?php $i++; }	 ?>
  <input type="text" name="countval" value="<?php echo $i; ?>"  id="count"/>
</table>
 </div>

<div  id="OLDcharges1" align="right">			
			<table width="40%">
			<tr><th>
		      <table width="100%" border="1" cellspacing="0" cellpadding="3">
                <tr>
                  <td><strong>BASIC AMOUNT<font color="#FF0000">*</font></strong> </td>
                  <td >
				 
				  <input type="text" name="total_item_amounts" id="total_item_amount12" style="width:100%;" onfocus="cal_totalamount12()" value="<?php echo $totalAmount; ?>"/>
				
				  </td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_percs" id="pkg_perc" value="<?php echo $pkgPerc; ?>" size="5" onkeyup="calcPackaging12(this.value)" /><input name="pkg_chargess" id="pkg_charges" type="text" size="28"  
				  onfocus="calcPackaging1()" value="<?php echo $pkgCharges; ?>"/></td>
                </tr>
                <tr>
                  <td><strong>Custom Duty</strong> </td>
              <td><input type="text" name="custom_dutys" id="custom_duty" style="width:100%;" value="<?php echo $totalCustom; ?>"/></td>
              </tr>
              <tr>
              	<td><strong>CVD</strong></td>
              <td><div id="taxval">
                  <input type="text" name="cvd_totals" value="<?php echo $cvdTotal; ?>" id="cvd_total" style="width:100%;"/>
              </div>

	</td>
                </tr>
                <tr>
                  <td><strong>Custom E.Cess</strong> </td>
                  <td><input type="text" name="custom_ecesss" value="<?php echo $custEcess; ?>" id="custom_ecess" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Custom SE.Cess</strong> </td>
                  <td><input type="text" name="custom_sec_ecesss" value="<?php echo $custom_sec; ?>" id="custom_sec_ecess" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Additional Duty </strong> </td>
                  <td><input name="add_chargess" id="additionalCharges" value="<?php echo $addCharges; ?>" type="text" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freights" value="<?php echo $frieght; ?>" id="TotalCharge" style="width:100%;"   /></td>
                </tr>
				<tr>
                  <td><strong>Loading /Unloading</strong> </td>
                  <td><input type="text" name="loadings" id="loading1" value="<?php echo $loadingData; ?>" style="width:100%;" /></td>
                </tr>
				<!--<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;"/></td>
				</tr>-->
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotals" id="orig_grand_tot" onfocus="cal_grandamount1()" value="<?php echo $grandTotal; ?>" size="12"/><input type="hidden"  id="orig_grand_tot" />&nbsp;<strong>Round Off</strong>&nbsp;<select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded(this.value)">
				  <option value="">None</option>
				  <option value="+">+</option>
				  <option value="-">-</option>
				  </select></td>
                </tr>
              </table>
		     </th>
		<td>		</td>
		</tr>
			</table>
</div>
<?php } ?>
<?php if($grntype=='1' && $dutyType=='Consolidated') { ?>
 <div id="importPo3" style="width:900px;overflow:auto;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr>
	<td class="tabledata"><strong>Sr.No.</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>Batch No.</strong></td>
	<td class="tabledata"><strong>QTY AS PER BILL </strong></td>
	<td class="tabledata"><strong>QTY Recieved</strong></td>
	<td class="tabledata"><strong>Short Quantity</strong></td>
	<td class="tabledata"><strong>Rate</strong></td>
	<td class="tabledata"><strong>Amount</strong></td>
	<td class="tabledata" id ="hideArea16">Dis. Type</td>  
	<td class="tabledata" id ="hideArea15">Dis. % <br />or amt.</td>
	<td class="tabledata" id ="hideArea14">Final<br  />Dis. Amt.</td>
	<td class="tabledata" id ="hideArea13">Discounted Amount</td>
	<td class="tabledata" id ="hideArea12">Basic<br /> Amt.</td>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrnid']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	where order_no='".$orderNo."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']);
	}
	else
	{
		$pending_qty=$row['qty'];
	}	
	

?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	</td>
	<td><?php echo $itemname ?></td>
	<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
	<td><?php   echo $poqty=$row['POQty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="<?php echo $row['batch_no'];?>" /></td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill2_<?php echo $i; ?>" value="<?php echo $row['qty_as_per_bill'];?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty2_<?php echo $i; ?>"  size="8"  onkeyup="check_po_qty1(<?php echo $i;?>)" value="<?php echo $row['reciveqty']; ?>"  /></td>
	<!--<td><input name="scecondarqty[]" type="text" id="scecondarqty_<?php echo $i; ?>"  size="8"   /></td>-->
	<td><input name="short_accessid[]" type="text" id="short_accessid2_<?php echo $i; ?>" value="<?php echo  $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort2(<?php echo $i ?>);"/></td>
	<td><?php //echo $row['rate'];?>
	<input name="itemrate[]" type="rext" id="itemrate2_<?php echo $i; ?>" readonly="true"  size="8" value="<?php echo  $row['itemprice'];?>"/>
	</td>
	<td>
	<input name="itemamount[]" type="text" id="itemamount2_<?php echo $i; ?>" onfocus="calculateTotalPrice2(this.id)"  size="8" readonly="true" value="<?php echo $row['itemamount'];?>"/>
	</td>
	 <td class="tabledata" id ="hideArea1"><select style="width:80px;" name="DiscountType1[]" id="PerAmo2_<?php echo $i; ?>">
            <option value="Amount"<?php echo ($row['DiscountType1']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row['DiscountType1']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td><input type="text" style="width:40px" name="discount[]" id="Discount2_<?php echo $i;?>" onblur="DiscountAmount3(this.value,this.id)" value="<?php echo $row['discount_1'];?>" /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc2_<?php echo $i; ?>"  readonly="true" style="width:100%;" onFocus="Check(this.value)" value="<?php echo $row['discounted_amount1'];?>"/></td> 
		<td class="tabledata" id ="hideArea3"><input type="text"  id="NetRate2_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" value="<?php echo $row['NetRate1'];?>" readonly/></td>
		<td class="tabledata" id ="hideArea4"><input type="text" style="width:70px" id="basic1_<?php echo $i;?>" value="<?php echo $row['basic'];?>" name="basic[]" readonly/></td>
</tr>
  <?php $i++; }	 ?>
  <input type="hidden" name="countval1" value="<?php echo $i; ?>"  id="count"/>
</table>
 </div>
</td>
</tr>
</table>
<div style="clear:both"></div>
<div align="right" id="charges3">			
			<table width="40%">
			<tr><th>
		      <table width="100%" border="1" cellspacing="0" cellpadding="3">
                <tr>
                  <td><strong>TOTAL AMOUNT <font color="#FF0000">*</font></strong> </td>
                  <td >
				  <input type="text" name="total_item_amounts" id="total_item_amount3" style="width:100%;" onfocus="cal_totalamount2()" value="<?php echo $totalAmount; ?>" />
				  </td>
               </tr>
			   <tr>
                  <td><strong>Currency Conversion<font color="#FF0000">*</font></strong> </td>
                  <td >
				  <select style="width:80px;" name="tot_currency" id="tot_currency">
			<?php $curr_sql=DB_query("Select * from currency_master",$db);
			while($curr_row=DB_fetch_array($curr_sql))
			{  ?>
            <option value="<?php echo $curr_row['id']; ?>"<?php echo ($GetRowData['tot_currency']==$curr_row['id'])?'selected':''?>><?php echo $curr_row['abbreviation']; ?></option>
			<?php } ?>
          </select>
		  <input name="tot_conv_rate" id="tot_conv_rate" type="text" value="<?php echo $GetRowData['tot_conv_rate']; ?>" size="28"  
				  onblur="calctotConvAmt(this.value)" />
				  </td>
               </tr>
			   <tr>
                  <td><strong>Conversion Amount</strong> </td>
                  <td><input type="text" name="tot_conv_amt" id="tot_conv_amt" value="<?php echo $GetRowData['tot_conv_amt']; ?>" size="28" /></td>
                </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_percs" id="pkg_perc" value="<?php echo $GetRowData['pkg_perc']; ?>" size="5" onkeyup="calcPackaging3(this.value)" /><input name="pkg_chargess" id="pkg_charges3" type="text" value="<?php echo $GetRowData['pkg_charges']; ?>" size="28"  
				  onfocus="calcPackaging1()" /></td>
                </tr>
                <tr>
                  <td><strong>Custom Duty</strong> </td>
              <td><select name="custom_duty_per" id="custom_duty_per" style="width: 55%" onchange="calcCustom(this.value)">
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'Custom'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"<?php echo ($GetRowData['custom_duty_per']==$accgroup_row['def_rate'])?'selected':''?>><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
			  <input type="text" name="custom_dutys" value="<?php echo $GetRowData['total_custom_duty']; ?>" id="custom_duty_new" style="width:100%;"/></td>
              </tr>
              <tr>
              	<td><strong>CVD</strong></td>
              <td><select name="cvd_per" id="cvd_per" style="width: 55%" onchange="calcCvd(this.value)">
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'CVD'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"<?php echo ($GetRowData['cvd_per']==$accgroup_row['def_rate'])?'selected':''?>><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
                  <input type="text" name="cvd_totals" id="cvd_total_new" value="<?php echo $GetRowData['cvd_total']; ?>" style="width:100%;"/></td>
                </tr>
                <tr>
                  <td><strong>Custom E.Cess</strong> </td>
                  <td>
				  <select name="cstm_ecess_per" id="cstm_ecess_per" style="width: 55%" onchange="calcCustmexcess(this.value)">
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'ECESS'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"<?php echo ($GetRowData['cstm_ecess_per']==$accgroup_row['def_rate'])?'selected':''?>><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select><input type="text" name="custom_ecess1" value="<?php echo $GetRowData['custom_ecess']; ?>" id="custom_ecess_new" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Custom SE E.Cess</strong> </td>
                  <td><select name="cstm_ecessec_per" id="cstm_ecessec_per" style="width: 55%" onchange="calcCustmexcessec(this.value)">
				<option value="">--Select--></option>  
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'SHE-CESS'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"<?php echo ($GetRowData['cstm_ecessec_per']==$accgroup_row['def_rate'])?'selected':''?>><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
				<input type="text" name="custom_sec_ecesss" value="<?php echo $GetRowData['custom_sec_ecess']; ?>" id="custom_sec_ecess_new" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Additional Duty </strong> </td>
                  <td><select name="cstm_add_per" id="cstm_add_per" style="width: 55%" onchange="calcadduty(this.value)">
				  <option value="">--Select--></option>  
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'ADC'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"<?php echo ($GetRowData['cstm_add_per']==$accgroup_row['def_rate'])?'selected':''?>><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
				  <input name="add_chargess" id="add_charges_new" type="text" value="<?php echo $GetRowData['add_charges']; ?>" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freights" id="TotalCharge2" style="width:100%;" value="<?php echo $GetRowData['freight']; ?>"     /></td>
                </tr>
				<tr>
                  <td><strong>Loading/Unloading</strong> </td>
                  <td><input type="text" name="loadings" id="loading2" style="width:100%;" value="<?php echo $GetRowData['loading']; ?>"/></td>
                </tr>
				<!--<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;"/></td>
				</tr>-->
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotals" id="orig_grand_tot2" value="<?php echo $GetRowData['grandtotal']; ?>" onfocus="cal_grandamount5()"  size="12"/><input type="hidden"  id="orig_grand_tot2" />&nbsp;<strong>Round Off</strong>&nbsp;<select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded(this.value)">
				  <option value="">None</option>
				  <option value="+">+</option>
				  <option value="-">-</option>
				  </select></td>
                </tr>
              </table>
		     </th>
		<td>		</td>
		</tr>
			</table>
</div>
<?php } ?>
<?php if($grntype=='2' && $dutyType=='Consolidated') { ?>
<div id="importPo4" style="width:950px;overflow:auto;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr>
	<td class="tabledata"><strong>Sr.No.</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>Batch No.</strong></td>
	<td class="tabledata"><strong>QTY AS PER BILL </strong></td>
	<td class="tabledata"><strong>QTY Recieved</strong></td>
	<td class="tabledata"><strong>Short Quantity</strong></td>
	<td class="tabledata"><strong>Rate</strong></td>
	<td class="tabledata"><strong>Amount</strong></td>
	<td class="tabledata" id ="hideArea16">Dis. Type</td>  
	<td class="tabledata" id ="hideArea15">Dis. % <br />or amt.</td>
	<td class="tabledata" id ="hideArea14">Final<br  />Dis. Amt.</td>
	<td class="tabledata" id ="hideArea13">Discounted Amount</td>
	<td class="tabledata" id ="hideArea12">Basic<br /> Amt.</td>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrnid']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	where order_no='".$orderNo."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']);
	}
	else
	{
		$pending_qty=$row['qty'];
	}	
	

?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
	
	</td>
	<td><?php echo $itemname ?></td>
	<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
	<!--<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit1,'unitname');
	echo $unitname; ?></td>-->
	
	<td><?php   echo $poqty=$row['POQty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="<?php echo $row['batch_no']; ?>" /></td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill3_<?php echo $i; ?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)" value="<?php echo $row['qty_as_per_bill']; ?>"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty3_<?php echo $i; ?>"  size="8"  onkeyup="check_po_qty1(<?php echo $i;?>)" value="<?php echo $row['reciveqty']; ?>" /></td>
	<td><input name="short_accessid[]" type="text" id="short_accessid3_<?php echo $i; ?>" value="<?php echo $row['short_accessid']; ?>" size="8" readonly="true" onfocus="calculate_poshort3(<?php echo $i ?>);"/></td>
	<td><?php //echo $row['rate'];?>
	<input name="itemrate[]" type="text" id="itemrate3_<?php echo $i; ?>" value="<?php echo $row['itemprice']; ?>"  size="8" readonly="true"/>
	</td>
	<td>
	<input name="itemamount[]" type="text" id="itemamount3_<?php echo $i; ?>" value="<?php echo $row['itemamount']; ?>" onfocus="calculateTotalPrice3(this.id)"  size="8"/>
	</td>
	 <td class="tabledata"><select style="width:80px;" name="DiscountType1[]" id="PerAmo3_<?php echo $i; ?>">
            <option value="Amount" <?php echo ($row['DiscountType1']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row['DiscountType1']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td id ="hideArea2"><input type="text" style="width:40px" name="discount[]" id="Discount3_<?php echo $i;?>" onblur="DiscountAmount4(this.value,this.id)" value="<?php echo $row['discount']; ?>"  /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc3_<?php echo $i; ?>" value="<?php echo $row['discounted_amount1']; ?>" readonly="true" style="width:100%;" /></td>
		<td class="tabledata" id ="hideArea3"><input type="text" value="<?php echo $row['NetRate1']; ?>" id="NetRate3_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" readonly/></td>
		<td class="tabledata" id ="hideArea4"><input type="text" value="<?php echo $row['basic']; ?>" style="width:70px" id="basic3_<?php echo $i;?>" name="basic[]" readonly/></td>
</tr>
  <?php $i++; }	 ?>
  <input type="hidden" name="countval3" value="<?php echo $i; ?>"  id="count"/>
</table>
 </div>
 <div align="right" id="charges4">	
		<table width="40%">
			<tr><th>
			  <table width="100%" border="0" cellspacing="2" cellpadding="2">

                <tr>

                  <td><strong>TOTAL BASIC AMOUNT</strong> </td>

                  <td ><input type="text" name="total_item_amounts" id="total_item_amount4" style="width:100%;" onfocus="cal_totalamount3()" value="<?php echo $GetRowData['total_amount']; ?>" /></td>

               </tr>

              <tr>

                  <td><strong>Pkg Charges</strong> </td>

                  <td><input type="text" name="pkg_percs" id="pkg_perc4" size="5" value="<?php echo $GetRowData['pkg_perc']; ?>" onchange="calcPackaging4(this.value)" /><input name="pkg_chargess" id="pkg_charges4" value="<?php echo $GetRowData['pkg_charges']; ?>" type="text" size="28" /></td>
                </tr>
				<tr>
                  <td><strong>Total Excise Amt</strong> </td>
                  <td><select name="tot_excise_amt11" id="exciseDutyTot" style="width:120px;" onchange="claculateExcise2(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag1(<?php echo $i; ?>)" >
	<option value="">Select</option>
	<?php 
	$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
	while($excise_row=DB_fetch_array($excise_sql))
	{
	$c='';
	if($Excise_Duty==$excise_row['id'])
	$c='selected';
	?>
	<option value="<?php echo $excise_row['id'];?>"<?php echo $c; ?>><?php echo $excise_row['caption'];?></option>
	<?php 	
	}
	?> 
	</select><div id="exciseIdTot">
	<input name="excise_perc" id="ExcisePercentageTot" type="text" value="<?php echo $GetRowData['excise_perc']; ?>"  style="width:35px;;"  /> 
	<input name="tot_excise_amt" id="exciseValueTot" type="text" style="width:70px;" onfocus="calculateExciseDuty2(<?php echo $i; ?>)" value="<?php echo $GetRowData['tot_excise_amt']; ?>" />
	</div></td>
                </tr>
				<tr>
                  <td><strong>Total E.Cess Amt</strong> </td>
                  <?php 
	$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
	$k=1;
	while($cessRow=DB_fetch_array($cessSql))
	{
	$caption[$k]=$cessRow['caption']; 
	
	$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
	while($rate_row=DB_fetch_array($rate_sql))
	{
	$rate[$k]=$rate_row['def_rate'];
	}
	$k++;
	} 
	?>
	<td><input name="e_cess_perc" id="ECessPercentageTot" type="text" value="<?php echo $GetRowData['e_cess_perc']; ?>" style="width:35px;" readonly   />
	<input name="tot_ecess_amt" id="ECessValueTot" type="text" value="<?php echo $GetRowData['tot_ecess_amt']; ?>"  style="width:70px;" readonly onfocus="calculateECess2()"/></td>
                </tr>
				<tr>
				<td><strong>Total SE E.Cess Amt</strong> </td>
				<td><input name="sahecess_per" id="SAHCessPercentageTot" type="text" value="<?php echo $GetRowData['sahecess_per']; ?>" style="width:35px;" readonly/>
	<input name="tot_sahecess_amt" id="SAHCessValueTot" type="text" value="<?php echo $GetRowData['tot_sahecess_amt']; ?>"  style="width:65px;" readonly onfocus="calculateSAHCess2()"/></td>
                </tr>
				<tr>
				<td><strong>Total Excise Duty Amt</strong> </td>

                  <td><input type="text" name="tot_excise_duty_amt" id="tot_excise_duty_amt3" value="<?php echo $GetRowData['tot_excise_duty_amt']; ?>" size="5" onfocus="calcexciseduty3(this.value)" /></td>

                </tr>
				<td><strong>Total Taxable Amt</strong> </td>

                  <td><input type="text" name="tot_taxable_amt" id="tot_taxable_amt3"  value="<?php echo $GetRowData['tot_taxable_amt']; ?>" size="5" onfocus="calctaxamt3(this.value)" /></td>

                </tr>

                <tr>

                  <td><strong>Input Tax </strong> </td>

                  <?php

				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';


				$Taxresult=DB_query($Taxsql,$db);

     	?>

              <td><select id="taxname1" name="vat_cst" onchange="tax_rate3(this.value)" style="width:100%;">

	          <option value="0">---Select---</option>

                  <?php 

			while($Taxmyrow=DB_fetch_array($Taxresult)){

			?>

                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($GetRowData['vat_cst']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>

                  <?php } ?>

              </select></td>

 

              </tr>

              <tr>

              	<td><strong>Tax Value</strong></td>

              <td><div id="taxval3">

                  <input type="text" name="taxvalue" id="taxvalue2" style="width:100%;" value="<?php echo $GetRowData['taxvalue']; ?>" readonly="true"/>

              </div>
	</td>
                   </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per3"  size="10" onchange="calsuroctamt3(this.value)" value=""/><input name="sur_oct_amt" type="text" id="sur_oct_amt3" value="<?php echo $GetRowData['sur_oct_per']; ?>" style="width:60%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freight" value="<?php echo $GetRowData['tot_freight']; ?>" id="TotalCharge1" style="width:100%;"/></td>
                </tr>
				 <td><strong>Loading/Unloading</strong> </td>
                  <td><input type="text" name="loading" value="<?php echo $GetRowData['loading']; ?>" id="loading1" style="width:100%;"/></td>
                </tr>
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_chargess" id="additionalCharges1" type="text" value="<?php echo $GetRowData['add_charges']; ?>" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
				<td><strong>Grand Total</strong></td>
                  <td>
				  <input type="text" name="grandtotals" id="GrandTotals3" onfocus="cal_grandamounts3()"  size="12" value="<?php echo $GetRowData['grandtotal']; ?>"/>
				  <input type="hidden"  id="orig_grand_tots3" value=""/>&nbsp;<strong>Round Off</strong>&nbsp;
				  <select name="round_off" id="round_off1" style="width:50px; height:20px" onchange="calcRounded3(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>
		     </th>
		<td></td>
		</tr>
			</table>
</div>
<?php } ?>
<?php if($grntype=='2' && $dutyType=='Itemwise') { ?>
<div id="importPo2" style="width:950px;overflow:auto; display:block;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr>
	<td class="tabledata"><strong>Sr.No.</strong></td>
	<td class="tabledata"><strong>Item Code</strong></td>
	<td class="tabledata"><strong>Description</strong></td>
	<td class="tabledata"><strong>UOM</strong></td>
	<!-- <th ><strong>Secondary UOM</strong></th>-->
	<td class="tabledata"><strong>PO QTY</strong></td>
	<td class="tabledata"><strong>Pending QTY</strong></td>
	<td class="tabledata"><strong>Batch No.</strong></td>
	<td class="tabledata"><strong>QTY AS PER BILL </strong></td>
	<td class="tabledata"><strong>QTY Recieved</strong></td>
	<!--<th><strong>Secondary QTY RECEIVED</strong></th>-->
	<td class="tabledata"><strong>Short Quantity</strong></td>
	<td class="tabledata"><strong>Rate</strong></td>
	<td class="tabledata"><strong>Amount</strong></td>
	<td class="tabledata"><strong>Dis. Type</strong></td>  
	<td class="tabledata"><strong>Dis. % <br />or amt.</strong></td>
	<td class="tabledata"><strong>Final<br  />Dis. Amt.</strong></td>
	<td class="tabledata"><strong>Discounted Amount</strong></td>
	<td class="tabledata" ><strong>Basic<br /> Amount</strong></td>
	<th ><strong>EXCISE FLAG</strong></th>
	<th ><strong>EXCISE</strong></th>
	<th ><strong>E-CESS</strong></th>
	<th ><strong>SE-CESS</strong></th>
	<th ><strong>Excise Amount</strong></th>
	<th ><strong>Total Amount</strong></th>
	<th ><strong>REMARKS </strong></th>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrnid']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	where order_no='".$orderNo."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']);
	}
	else
	{
		$pending_qty=$row['qty'];
	}	
	

?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
	
	</td>
	<td><?php echo $itemname ?></td>
	<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
	<!--<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit1,'unitname');
	echo $unitname; ?></td>-->
	
	<td><?php   echo $poqty=$row['POQty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="<?php echo $row['batch_no']; ?>" /></td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill3_<?php echo $i; ?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)" value="<?php echo $row['qty_as_per_bill']; ?>"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty3_<?php echo $i; ?>"  size="8"  onkeyup="check_po_qty1(<?php echo $i;?>)" value="<?php echo $row['reciveqty']; ?>" /></td>
	<td><input name="short_accessid[]" type="text" id="short_accessid3_<?php echo $i; ?>" value="<?php echo $row['short_accessid']; ?>" size="8" readonly="true" onfocus="calculate_poshort3(<?php echo $i ?>);"/></td>
	<td><?php //echo $row['rate'];?>
	<input name="itemrate[]" type="text" id="itemrate3_<?php echo $i; ?>" value="<?php echo $row['itemprice']; ?>"  size="8" readonly="true"/>
	</td>
	<td>
	<input name="itemamount[]" type="text" id="itemamount3_<?php echo $i; ?>" value="<?php echo $row['itemamount']; ?>" onfocus="calculateTotalPrice3(this.id)"  size="8"/>
	</td>
	 <td class="tabledata"><select style="width:80px;" name="DiscountType1[]" id="PerAmo3_<?php echo $i; ?>">
            <option value="Amount" <?php echo ($row['DiscountType1']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row['DiscountType1']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td id ="hideArea2"><input type="text" style="width:40px" name="discount[]" id="Discount3_<?php echo $i;?>" onblur="DiscountAmount4(this.value,this.id)" value="<?php echo $row['discount']; ?>"  /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc3_<?php echo $i; ?>" value="<?php echo $row['discounted_amount1']; ?>" readonly="true" style="width:100%;" /></td>
		<td class="tabledata" id ="hideArea3"><input type="text" value="<?php echo $row['NetRate1']; ?>" id="NetRate3_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" readonly/></td>
		<td class="tabledata" id ="hideArea4"><input type="text" value="<?php echo $row['basic']; ?>" style="width:70px" id="basic3_<?php echo $i;?>" name="basic[]" readonly/></td>
	<td><select name="billing_type[]" style="width:85px" id="billing_type_<?php echo $i;?>"  onchange="checkExcisable1(this.value,<?php echo $i; ?>)">
	<option value="">Select</option>
	<option value="NonExcisable"<?php if($row['billing_type']=='NonExcisable') { ?> selected="selected" <?php } ?>>NonExcisable</option>
	<option value="Excisable" <?php if($row['billing_type']=='Excisable') { ?> selected="selected" <?php } ?>>Excisable</option>
	<option value="IncludeTax" <?php if($row['billing_type']=='IncludeTax') { ?> selected="selected" <?php } ?>>IncludeTax</option>
	</select></td>
	<td><select name="excise_duty[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;" onchange="claculateExcise1(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag1(<?php echo $i; ?>)">
	<option value="">Select</option>
	<?php 
	$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
	while($excise_row=DB_fetch_array($excise_sql))
	{
	$c='';
	if($Excise_Duty==$excise_row['id'])
	$c='selected';
	?>
	<option value="<?php echo $excise_row['id'];?>"<?php echo $c; ?>><?php echo $excise_row['caption'];?></option>
	<?php 	
	}
	?> 
	</select><div id="exciseId_<?php echo $i; ?>">
	<input name="excise_perc[]" id="ExcisePercentage_<?php echo $i; ?>" type="text" value="<?php echo $row['excise_perc']; ?>"  style="width:35px;;"  /> 
	<input name="excise_val[]" id="exciseValue_<?php echo $i; ?>" type="text"  value="<?php echo $row['excise_val']; ?>"  style="width:70px;" onfocus="calculateExciseDuty1(<?php echo $i; ?>)" />
	</div></td>
	<?php 
	$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
	$k=1;
	while($cessRow=DB_fetch_array($cessSql))
	{
	$caption[$k]=$cessRow['caption']; 
	
	$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
	while($rate_row=DB_fetch_array($rate_sql))
	{
	$rate[$k]=$rate_row['def_rate'];
	}
	$k++;
	} 
	?>
	<td><input name="e_cess_perc[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $row['e_cess_perc']; ?>" style="width:35px;" readonly   /><!--onfocus="caldata1(<?php echo $i;?>)"-->
	<input name="e_cess_val[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $row['e_cess_val']; ?>"  style="width:70px;" readonly onfocus="calculateECess1(<?php echo $i; ?>)"/></td>
	<td><input name="sah_perc[]" id="SAHCessPercentage_<?php echo $i;?>" type="text"  value="<?php echo $row['sah_perc']; ?>" style="width:35px;" readonly/>
	<input name="sah_val[]" id="SAHCessValue_<?php echo $i;?>" type="text"  value="<?php echo $row['sah_val']; ?>"  style="width:65px;" readonly onfocus="calculateSAHCess1(<?php echo $i; ?>)"/></td>
	
	<td><input name="taxableamount[]" type="text" id="taxableamount_<?php echo $i?>"  value="<?php echo $row['taxamount_rate']; ?>"  size="12"  onfocus="caltaxamout1(<?php echo $i;?>)" /></td>
	
	<td><input name="val_after_disc[]" type="text" id="total_<?php echo $i?>" value="<?php echo $row['val_after_disc']; ?>" size="12" readonly="true" onfocus="value_after_discount1(<?php echo $i ?>);"/></td>
	
	
	<td><input type="text" name="remarks[]" value="<?php echo $row['remarks']; ?>" id="remarks" value=""/></td>
	
</tr>
  <?php $i++; }	 ?>
  <input type="hidden" name="countval" value="<?php echo $i; ?>"  id="count"/>

</table>
 </div>
 <div align="right" id="charges2">			
			<table width="40%">
			<th>
			  <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td><strong>TOTAL BASIC AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amounts" id="total_item_amount2" style="width:100%;" onfocus="cal_totalamount2()" value="<?php echo $GetRowData['total_amount']; ?>"/></td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_percs" id="pkg_perc" value="<?php echo $GetRowData['pkg_perc']; ?>" size="5" onchange="calcPackaging2(this.value)" /><input name="pkg_chargess" id="pkg_charges2" type="text" value="<?php echo $GetRowData['pkg_charges']; ?>" size="28" /></td>

                </tr>
				
				<tr>

                  <td><strong>Total Excise Amt</strong> </td>

                  <td><input type="text" name="tot_excise_amt" id="tot_excise_amt2" value="<?php echo $GetRowData['tot_excise_amt']; ?>" size="5" onfocus="calcexcise2(this.value)" /></td>

                </tr>
				<tr>

                  <td><strong>Total E.Cess Amt</strong> </td>

                  <td><input type="text" name="tot_ecess_amt" id="tot_ecess_amt2" value="<?php echo $GetRowData['tot_ecess_amt']; ?>" size="5" onfocus="calcecess2(this.value)" /></td>

                </tr>
				<td><strong>Total SE E.Cess Amt</strong> </td>

                  <td><input type="text" name="tot_sahecess_amt" id="tot_sahecess_amt2" value="<?php echo $GetRowData['tot_sahecess_amt']; ?>" size="5" onfocus="calcsahecess2(this.value)" /></td>

                </tr>
				</tr>
				<td><strong>Total Excise Duty Amt</strong> </td>

                  <td><input type="text" name="tot_excise_duty_amt" id="tot_excise_duty_amt2" value="<?php echo $GetRowData['tot_excise_duty_amt']; ?>" size="5" onfocus="calcexciseduty2(this.value)" /></td>

                </tr>
				</tr>
				<td><strong>Total Taxable Amt</strong> </td>

                  <td><input type="text" name="tot_taxable_amt" id="tot_taxable_amt2"  value="<?php echo $GetRowData['tot_taxable_amt']; ?>" size="5" onfocus="calctaxamt2(this.value)" /></td>

                </tr>

                <tr>

                  <td><strong>Input Tax </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_rate2(this.value)" style="width:100%;">

	          <option value="0">---Select---</option>

                  <?php 

			while($Taxmyrow=DB_fetch_array($Taxresult)){

			?>

                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($GetRowData['vat_cst']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>

                  <?php } ?>

              </select></td>
              </tr>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval2">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="<?php echo $GetRowData['vat_cst_val']; ?>" readonly="true"/>
              </div>
	</td>
                   </tr>
                <tr>

                  <td><strong>Surcharge Amount</strong> </td>

                  <td><input type="text" name="sur_oct_per" id="sur_oct_per2"  size="10" onchange="calsuroctamt2(this.value)" value="<?php echo $GetRowData['sur_oct_per']; ?>"/><input name="sur_oct_amt" type="text" id="sur_oct_amt2" value="<?php echo $GetRowData['sur_oct_amt']; ?>" style="width:60%;" /></td>

                </tr>

                <tr>

                  <td><strong>Freight</strong> </td>

                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:100%;" value="<?php echo $GetRowData['tot_freight']; ?>"/></td>

                </tr>

				 <td><strong>Loading/Unloading</strong> </td>

                  <td><input type="text" name="loading" id="loading" style="width:100%;" value="<?php echo $GetRowData['loading']; ?>"/></td>

                </tr>

                

                <tr>

                  <td><strong>Additional Charges</strong> </td>

                  <td><input name="add_chargess" id="additionalCharges" type="text" value="<?php echo $GetRowData['add_charges']; ?>" size="25" style="width:100%;" /></td>

                </tr>
                <tr>

				<td><strong>Grand Total</strong></td>
                  <td>
				  <input type="text" name="grandtotals" id="GrandTotals2" onfocus="cal_grandamounts2()"  size="12" value="<?php echo $GetRowData['grandtotal']; ?>"/>
				  <input type="hidden"  id="orig_grand_tots2" value=""/>&nbsp;<strong>Round Off</strong>&nbsp;
				  <select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded2(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>
		     </th>
		<td></td>
		</tr>
			</table>
</div>
<?php } ?>
</div>

<!--<div align="center">
	<input type="submit" name="save" value="Update" class="search" onclick="return confirmPost()" />
    <input type="submit" name="reset" class="search" value="Reset" /><a href="index.php?route=Inventory/transation/material_receipt_note_exo_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" class="search" value="Cancel" name="Back" /></a>
<input type="hidden" name="max_price" id="max_price" value="<?php echo $rowmax['max_price'];;?>" />
  </div>
-->
<div style="clear:both;"></div>
</form>

</div>












<script language="javascript" type="text/javascript">
function claculateExcise(id,str)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		var b=document.getElementById("basic_"+i).value;
	}
	else
	{
		var b=document.getElementById("basic").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)
    		{
			 
					if(id_brk.length>1)
					{
						var data=xmlhttp.responseText.split("__");
						document.getElementById("dutyamount_"+i).value=data[1];
						 
					}
					else
					{
						var data=xmlhttp.responseText.split("__");
						document.getElementById("dutyamount").value=data[1];
					}
					
					
    			
    		}
  		}
		xmlhttp.open("GET","calculatecustomduty.php?quotTaxId="+str+"&data="+b,true);
		xmlhttp.send();
}

function claculateExcise1(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_exo.php?mrnTaxId="+str+"&data="+i,true);

		xmlhttp.send();

}
function claculateExcise2(i,str)

{
	var param1 = document.getElementById("total_item_amount4").value;
	var param2 = document.getElementById("pkg_charges4").value;
	
	var discounted=parseFloat(param1)+parseFloat(param2);

	if (str.length==0)

  		{

  			document.getElementById("exciseIdTot").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("exciseIdTot").innerHTML=xmlhttp.responseText;

    		}

  		}

		xmlhttp.open("GET","calculateExcise_exo1.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 calculateExciseDuty1(i)
{

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

function calculateExciseDuty2(i)
{
var param1 = document.getElementById("total_item_amount4").value;
	var param2 = document.getElementById("pkg_charges4").value;
	
	var discounted=parseFloat(param1)+parseFloat(param2);
	var ExcisePercentage=document.getElementById("ExcisePercentageTot").value;
	
	var exciseVal=discounted*(ExcisePercentage/100);
	document.getElementById("exciseValueTot").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 checkexiseflag1(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 checkExcisable1(str,i)
{	
	if(str=='NonExcisable')
	{
	document.getElementById("exciseDuty_"+i).disabled=true;
	document.getElementById("ExcisePercentage_"+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("taxableamount_"+i).disabled=true;
	}
	else if(str=='Excisable' || str==0)
	{
	document.getElementById("exciseDuty_"+i).disabled=false;
	document.getElementById("ExcisePercentage_"+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("ExcisePercentage_"+i).disabled=true;
	document.getElementById("exciseValue_"+i).disabled=true;
	document.getElementById("ECessPercentage_"+i).disabled=true;
	document.getElementById("ECessValue_"+i).disabled=true;
	document.getElementById("SAHCessPercentage_"+i).disabled=true;
	document.getElementById("SAHCessValue_"+i).disabled=true;
	document.getElementById("taxable_amt_"+i).disabled=true;
	//document.getElementById("taxname_"+i).disabled=true;
	//document.getElementById("taxvalue_"+i).disabled=true;
	//document.getElementById("sur_oct_perc_"+i).disabled=true;
	//document.getElementById("sur_oct_amt_"+i).disabled=true;
	//document.getElementById("TotalCharge_"+i).disabled=true;
	//document.getElementById("packagingCharges_"+i).disabled=true;
	//document.getElementById("additionalCharges_"+i).disabled=true;
	//document.getElementById("roundOff_"+i).disabled=true;
	document.getElementById("exciseDuty_"+i).value='';
	document.getElementById("exciseValue_"+i).value='';
	document.getElementById("ECessPercentage_"+i).value='';
	document.getElementById("ECessValue_"+i).value='';
	document.getElementById("SAHCessPercentage_"+i).value='';
	document.getElementById("SAHCessValue_"+i).value='';
	document.getElementById("taxable_amt_"+i).value='';
	document.getElementById("taxname_"+i).value='';
	document.getElementById("taxvalue_"+i).value='';
	document.getElementById("sur_oct_perc_"+i).value='';
	document.getElementById("sur_oct_amt_"+i).value='';
	document.getElementById("TotalCharge_"+i).value='';
	document.getElementById("packagingCharges_"+i).value='';
	document.getElementById("additionalCharges_"+i).value='';
	document.getElementById("roundOff_"+i).value='';
	}
	document.getElementById("hid_billing_type_"+i).value=str;
}



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

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





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




function cal_totalamount_diectpo()
{
	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 cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;
	var taxamt=document.getElementById("taxvalue").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	//var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	if(roundOffVal==''){roundOffVal='-.0';}	
	var test=roundOffVal.split(".");	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
		 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }
	
}

function cal_grandtotal111(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic_"+i).value;	 
		 var Totaltaxable=document.getElementById("dutyamount_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type_"+i).value==2)
		{ 
			var grand_tot1=parseFloat(basic);
			var grand_tot=grand_tot1.toFixed(2);
			
		}  
		else{ 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var cvd = grand_tot1*(12/100);
		var grand_tot=cvd.toFixed(2);
		 } 
		 document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
	
	}
	else
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic").value;	 
		 var Totaltaxable=document.getElementById("dutyamount").value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type").value==2)
		{ 
			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("TotalSpecial").value=grand_tot1 ;	
	
	}
	
var cusduty = document.getElementById("custom_duty").value;
		if(cusduty=="")
		{
		document.getElementById("custom_duty").value = document.getElementById("dutyamount_"+i).value;
		}
		else
		{
		var sum1 = parseFloat(cusduty)+parseFloat(document.getElementById("dutyamount_"+i).value);
		document.getElementById("custom_duty").value = sum1.toFixed(2);
		} 
	
}

function cal_e_cess(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var tot = tot1*(2/100);
	var final_eces=tot.toFixed(2);
	document.getElementById("customecess_"+i).value=final_eces;	
}

function cal_esec_cess(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var tot = tot1*(1/100);
	var final_eces1=tot.toFixed(2);
	 document.getElementById("customsececess_"+i).value=final_eces1;	
}
function cal_add_duty(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var a = document.getElementById("basic_"+i).value; 
	var b = document.getElementById("dutyamount_"+i).value;
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var d = document.getElementById("customecess_"+i).value; 
	var e = document.getElementById("customsececess_"+i).value; 
	var tot12= parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
	var tot1 = tot12*(4/100);
	var final_eces2=tot1.toFixed(2);
	 document.getElementById("adduty_"+i).value=final_eces2 ;	
	
}
function cal_cvd_total11(id)
{
var count =document.getElementById("count").value;
var tot_cvd=0;
for(var i=0; i<count;i++){
	var cvd=document.getElementById("TotalSpecial_"+i).value;
	if(cvd==''){cvd=0;}
	tot_cvd=parseFloat(tot_cvd)+parseFloat(cvd);
}

//alert(tot_cvd);

var cvdtot = document.getElementById("cvd_total").value;
		if(cvdtot=="")
		{
		document.getElementById("cvd_total").value = document.getElementById("TotalSpecial_"+i).value;
		}
		else
		{
		var sum2 = parseFloat(cvdtot)+parseFloat(document.getElementById("TotalSpecial_"+i).value);
		document.getElementById("cvd_total").value = sum2.toFixed(2);
		} 
}

function cal_ecess_total(id)
{
var ecestot = document.getElementById("custom_ecess").value;
		if(ecestot=="")
		{
		document.getElementById("custom_ecess").value = document.getElementById("customecess_"+i).value;
		}
		else
		{
		var sum3 = parseFloat(ecestot)+parseFloat(document.getElementById("customecess_"+i).value);
		document.getElementById("custom_ecess").value = sum3.toFixed(2);
		} 
}
function cal_ecess_sec_total(id)
{
var ecesectot = document.getElementById("custom_sec_ecess").value;
		if(ecesectot=="")
		{
		document.getElementById("custom_sec_ecess").value = document.getElementById("customsececess_"+i).value;
		}
		else
		{
		var sum4 = parseFloat(ecesectot)+parseFloat(document.getElementById("customsececess_"+i).value);
		document.getElementById("custom_sec_ecess").value = sum4.toFixed(2);
		} 
}
function cal_addcharg_total(id)
{
var adcharge = document.getElementById("additionalCharges").value;
		if(adcharge=="")
		{
		document.getElementById("additionalCharges").value = document.getElementById("adduty_"+i).value;
		}
		else
		{
		var sum5= parseFloat(adcharge)+parseFloat(document.getElementById("adduty_"+i).value);
		document.getElementById("additionalCharges").value = sum5.toFixed(2);
		} 
}

function calcCustom(id)
{ 

var totalAmount = document.getElementById("total_item_amount3").value;
		if(totalAmount!="")
		{
		var percentage = document.getElementById("custom_duty_per").value;
		var result = totalAmount*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("custom_duty_new").value=final_result;	
		}
}

function calcCvd(id)
{ 
		var a1 = document.getElementById("total_item_amount3").value;
		var b1 = document.getElementById("custom_duty_new").value;
			
		if(a1!="")
		{
		var percentage = document.getElementById("cvd_per").value;
		var summ = parseFloat(a1)+parseFloat(b1);
		var result = summ*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("cvd_total_new").value=final_result;	
		}
}
function calcCustmexcess(id)
{ 
		var a2 = document.getElementById("custom_duty_new").value;
		var b2 = document.getElementById("cvd_total_new").value;
			
		if(a2!="")
		{
		var percentage2 = document.getElementById("cstm_ecess_per").value;
		var summ2 = parseFloat(a2)+parseFloat(b2);
		var result2 = summ2*(percentage2/100);
		var final_result2=result2.toFixed(2);
		document.getElementById("custom_ecess_new").value=final_result2;	
		}
}
function calcCustmexcessec(id)
{ 
		var a3 = document.getElementById("custom_duty_new").value;
		var b3 = document.getElementById("cvd_total_new").value;
		if(a3!="")
		{
		var percentage3 = document.getElementById("cstm_ecessec_per").value;
		var summ3 = parseFloat(a3)+parseFloat(b3);
		var result3 = summ3*(percentage3/100);
		var final_result3=result3.toFixed(2);
		document.getElementById("custom_sec_ecess_new").value=final_result3;	
		}
}
function calcadduty(id)
{ 
		var a4 = document.getElementById("total_item_amount3").value;
		var b4 = document.getElementById("custom_duty_new").value;
		var c4 = document.getElementById("cvd_total_new").value;
		var d4 = document.getElementById("custom_ecess_new").value;
		var e4 = document.getElementById("custom_sec_ecess_new").value;
		if(a4!="")
		{
		var percentage4 = document.getElementById("cstm_add_per").value;
		var summ4= parseFloat(a4)+parseFloat(b4)+parseFloat(c4)+parseFloat(d4)+parseFloat(e4);
		var result4 = summ4*(percentage4/100);
		var final_result4=result4.toFixed(2);
		document.getElementById("add_charges_new").value=final_result4;	
		}
}


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

function calcPackaging12(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount12").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges").value=pckgng_val.toFixed(2);
	}
}
function calcPackaging3(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount3").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges3").value=pckgng_val.toFixed(2);
	}
}
function calcPackaging4(str)
{
	if(str!='')
	{
	var tota_amt=document.getElementById("total_item_amount4").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkg_charges4").value=pckgng_val.toFixed(2);
	}
}




 






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 calculateECess1(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 calculateECess2()
{
	var exciseValue=document.getElementById("exciseValueTot").value;
	var ECessPercentage=document.getElementById("ExcisePercentageTot").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValueTot").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 calculateSAHCess1(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 calculateSAHCess2(i)
{
	var exciseValue=document.getElementById("exciseValueTot").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentageTot").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValueTot").value=total.toFixed(2);
}

function cal_grandtotal(id)
{ 
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic_"+i).value;	 
		 var Totaltaxable=document.getElementById("dutyamount_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type_"+i).value==2)
		{ 
			var grand_tot1=parseFloat(basic);
			var grand_tot=grand_tot1.toFixed(2);
			
		}  
		else{ 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var cvd = grand_tot1*(12/100);
		var grand_tot=cvd.toFixed(2);
		 } 
		 document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
	
	}
	else
	{ 
		//var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
		var basic=document.getElementById("basic").value;	 
		 var Totaltaxable=document.getElementById("dutyamount").value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 if(document.getElementById("hid_billing_type").value==2)
		{ 
			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("TotalSpecial").value=grand_tot1 ;	
	
	}
	
var cusduty = document.getElementById("custom_duty").value;
		if(cusduty=="")
		{
		document.getElementById("custom_duty").value = document.getElementById("dutyamount_"+i).value;
		}
		else
		{
		var sum1 = parseFloat(cusduty)+parseFloat(document.getElementById("dutyamount_"+i).value);
		document.getElementById("custom_duty").value = sum1.toFixed(2);
		} 
	
}
function cal_e_cess(id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var tot = tot1*(2/100);
	var final_eces=tot.toFixed(2);
	document.getElementById("customecess_"+i).value=final_eces;	
}

function cal_esec_cess(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var b = document.getElementById("dutyamount_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var tot = tot1*(1/100);
	var final_eces1=tot.toFixed(2);
	 document.getElementById("customsececess_"+i).value=final_eces1;	
}
function cal_add_duty(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	var a = document.getElementById("basic_"+i).value; 
	var b = document.getElementById("dutyamount_"+i).value;
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var d = document.getElementById("customecess_"+i).value; 
	var e = document.getElementById("customsececess_"+i).value; 
	var tot12= parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
	var tot1 = tot12*(4/100);
	var final_eces2=tot1.toFixed(2);
	 document.getElementById("adduty_"+i).value=final_eces2 ;	
	
}

function cal_basic_total(id)
{
var count =document.getElementById("count").value;
var tot_basic=0;
for(var i=0; i<count;i++){
	var basic=document.getElementById("basic_"+i).value;
	if(basic==''){basic=0;}
	tot_basic=parseFloat(tot_basic)+parseFloat(basic);
}
//alert(tot_basic);
document.getElementById("total_item_amount").value = tot_basic.toFixed(2);
}

function cal_custom_total(id)
{
var count =document.getElementById("count").value;
var tot_custom=0;
for(var i=0; i<count;i++){
	var dutyamt=document.getElementById("dutyamount_"+i).value;
	if(dutyamt==''){dutyamt=0;}
	tot_custom=parseFloat(tot_custom)+parseFloat(dutyamt);
}
//alert(tot_custom);
document.getElementById("custom_duty").value = tot_custom.toFixed(2);
}

function cal_cvd_total(id)
{

var count =document.getElementById("count").value;
var tot_cvd=0;
for(var i=0; i<count;i++){
	var cvd=document.getElementById("TotalSpecial_"+i).value;
	if(cvd==''){cvd=0;}
	tot_cvd=parseFloat(tot_cvd)+parseFloat(cvd);
}
//alert(tot_cvd);
document.getElementById("cvd_total").value = tot_cvd.toFixed(2);
}

function cal_ecess_total(id)
{
	var count =document.getElementById("count").value;
	var ecestot=0;
	for(var i=0; i<count;i++){
		var eces=document.getElementById("customecess_"+i).value;
		if(eces==''){eces=0;}
		ecestot=parseFloat(ecestot)+parseFloat(eces);
	}
	//alert(ecestot);
	document.getElementById("custom_ecess").value = ecestot.toFixed(2);
}
		
function cal_ecess_sec_total(id)
{
		var count =document.getElementById("count").value;
		var ecesectot=0;
		for(var i=0; i<count;i++){
			var ecess=document.getElementById("customsececess_"+i).value;
			if(ecess==''){ecess=0;}
			ecesectot=parseFloat(ecesectot)+parseFloat(ecess);
		}
		//alert(ecesectot);
		document.getElementById("custom_sec_ecess").value = ecesectot.toFixed(2);
}
function cal_addcharg_total(id)
{
		var count =document.getElementById("count").value;
		var adddutytot=0;
		for(var i=0; i<count;i++){
			var addduty=document.getElementById("adduty_"+i).value;
			if(addduty==''){addduty=0;}
			adddutytot=parseFloat(adddutytot)+parseFloat(addduty);
		}
		//alert(adddutytot);
		document.getElementById("additionalCharges").value = adddutytot.toFixed(2);
}

function calcCustom(id)
{ 

var totalAmount = document.getElementById("total_item_amount3").value;
		if(totalAmount!="")
		{
		var percentage = document.getElementById("custom_duty_per").value;
		var result = totalAmount*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("custom_duty_new").value=final_result;	
		}
}

function calcCvd(id)
{ 
		var a1 = document.getElementById("total_item_amount3").value;
		var b1 = document.getElementById("custom_duty_new").value;
			
		if(a1!="")
		{
		var percentage = document.getElementById("cvd_per").value;
		var summ = parseFloat(a1)+parseFloat(b1);
		var result = summ*(percentage/100);
		var final_result=result.toFixed(2);
		document.getElementById("cvd_total_new").value=final_result;	
		}
}
function calcCustmexcess(id)
{ 
		var a2 = document.getElementById("custom_duty_new").value;
		var b2 = document.getElementById("cvd_total_new").value;
			
		if(a2!="")
		{
		var percentage2 = document.getElementById("cstm_ecess_per").value;
		var summ2 = parseFloat(a2)+parseFloat(b2);
		var result2 = summ2*(percentage2/100);
		var final_result2=result2.toFixed(2);
		document.getElementById("custom_ecess_new").value=final_result2;	
		}
}
function calcCustmexcessec(id)
{ 
		var a3 = document.getElementById("custom_duty_new").value;
		var b3 = document.getElementById("cvd_total_new").value;
		if(a3!="")
		{
		var percentage3 = document.getElementById("cstm_ecessec_per").value;
		var summ3 = parseFloat(a3)+parseFloat(b3);
		var result3 = summ3*(percentage3/100);
		var final_result3=result3.toFixed(2);
		document.getElementById("custom_sec_ecess_new").value=final_result3;	
		}
}
function calcadduty(id)
{ 
		var a4 = document.getElementById("total_item_amount3").value;
		var b4 = document.getElementById("custom_duty_new").value;
		var c4 = document.getElementById("cvd_total_new").value;
		var d4 = document.getElementById("custom_ecess_new").value;
		var e4 = document.getElementById("custom_sec_ecess_new").value;
		if(a4!="")
		{
		var percentage4 = document.getElementById("cstm_add_per").value;
		var summ4= parseFloat(a4)+parseFloat(b4)+parseFloat(c4)+parseFloat(d4)+parseFloat(e4);
		var result4 = summ4*(percentage4/100);
		var final_result4=result4.toFixed(2);
		document.getElementById("add_charges_new").value=final_result4;	
		}
}


function tax_rate1(str)
{
	
	var taxableAmount=document.getElementById("total_item_amount").value;
	var taxableAmount1=document.getElementById("pkg_charges1").value;
	if(taxableAmount1==''){taxableAmount1=0;}
	var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
	if (str.length==0)
	{
	document.getElementById("taxval").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("taxval").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_tax_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 loading1=document.getElementById("loading1").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	//if(loading1=='') { loading=0;)
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	//var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	/*if(roundOffVal==''){roundOffVal='-.0';}
	var test=roundOffVal.split(".");
	if(test[0]=='-')
	{
	var dot=".";
	var roundval=dot + test[1];
	document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	}
	else
	{
	var dot=".";
	var roundval=dot + test[1];
	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	}*/
	document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}
function cal_grandamount1()
{
	var total=document.getElementById("total_item_amount12").value;
	var cdis_amt=document.getElementById("pkg_charges").value;
	var insurancecharges_amt=document.getElementById("custom_duty").value;
	var overseasfrieght_amt=document.getElementById("cvd_total").value;
	var localfreight_amt=document.getElementById("custom_ecess").value;
	var calclearingforwarding_amt=document.getElementById("custom_sec_ecess").value;	
	var detetioncharges_amt=document.getElementById("additionalCharges").value;	
	var othercharges=document.getElementById("TotalCharge").value;
	var othercharges1=document.getElementById("loading1").value;	
	if(total==''){total=0;}
	if(cdis_amt==''){cdis_amt=0;}
	if(insurancecharges_amt==''){insurancecharges_amt=0;}
	if(overseasfrieght_amt==''){overseasfrieght_amt=0;}
	if(localfreight_amt==''){localfreight_amt=0;}
	if(calclearingforwarding_amt==''){calclearingforwarding_amt=0;}
	if(detetioncharges_amt==''){detetioncharges_amt=0;}	if(othercharges==''){othercharges=0;}
	if(othercharges1==''){othercharges1=0;}
	 
	grandtotal=parseFloat(total)+parseFloat(cdis_amt)+parseFloat(insurancecharges_amt)+parseFloat(overseasfrieght_amt)+parseFloat(localfreight_amt)+parseFloat(calclearingforwarding_amt)+parseFloat(detetioncharges_amt)+parseFloat(othercharges)+parseFloat(othercharges1);
document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}

function cal_grandamount2()
{

	var total=document.getElementById("total_item_amount3").value;
	var cdis_amt=document.getElementById("pkg_charges3").value;
	var insurancecharges_amt=document.getElementById("custom_duty_new").value;
	var overseasfrieght_amt=document.getElementById("cvd_total_new").value;
	var localfreight_amt=document.getElementById("custom_ecess_new").value;
	var calclearingforwarding_amt=document.getElementById("custom_sec_ecess_new").value;	
	var detetioncharges_amt=document.getElementById("add_charges_new").value;	
	var othercharges=document.getElementById("TotalCharge").value;	
	var othercharges1=document.getElementById("loading1").value;	
	
	if(total==''){total=0;}
	if(cdis_amt==''){cdis_amt=0;}
	if(insurancecharges_amt==''){insurancecharges_amt=0;}
	if(overseasfrieght_amt==''){overseasfrieght_amt=0;}
	if(localfreight_amt==''){localfreight_amt=0;}
	if(calclearingforwarding_amt==''){calclearingforwarding_amt=0;}
	if(detetioncharges_amt==''){detetioncharges_amt=0;}	if(othercharges==''){othercharges=0;}
	if(othercharges1==''){othercharges1=0;}
	 
	
	grandtotal=parseFloat(total)+parseFloat(cdis_amt)+parseFloat(insurancecharges_amt)+parseFloat(overseasfrieght_amt)+parseFloat(localfreight_amt)+parseFloat(calclearingforwarding_amt)+parseFloat(detetioncharges_amt)+parseFloat(othercharges)+parseFloat(othercharges1);
document.getElementById("orig_grand_tot2").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("receiviedagaist").value;
 window.open("MRN_items.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&type="+type,"item_popup_window","height=500,width=800,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}



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



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





}  
  
   function DiscountAmount2(DA,id)
{



	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		//document.getElementById("stock_perunit_"+i).value=1;
		var discount_percent = document.getElementById("PerAmo2_"+i).value;	
		var rate = document.getElementById("Rate2_"+i).value;
		var discount = document.getElementById("Discount2_"+i).value;
		var quantity = document.getElementById("Quantity2_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		
		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("Discount2_"+i).value);
			if(isNaN(percent)){percent=0;}
			var subTotal = totalPrice-parseFloat(percent);
		
		}
		document.getElementById("perc2_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate2_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic2_"+i).value=subTotal.toFixed(2);
		
	}
	else
	{
	
	//document.getElementById("stock_perunit").value=1;
	
	var discount_percent = document.getElementById("PerAmo2").value;	
	var rate = document.getElementById("Rate2").value;
	var discount = document.getElementById("Discount2").value;
	var quantity = document.getElementById("Quantity2").value;
	var totalPrice = parseFloat(quantity)*parseFloat(rate);
	
	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("Discount2").value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
	
	}
	document.getElementById("perc2").value=percent.toFixed(2);
	document.getElementById("NetRate2").value=subTotal.toFixed(2);
	document.getElementById("basic2").value=subTotal.toFixed(2);
	
	
	
	}
	
	



	
 
}	
  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 calculateTotalPrice(id)
{
 

var id_brk=id.split('_');

	var i=id_brk[1];
 
	if(id_brk.length>1)
	{	 
		  if(document.getElementById("reciveqty_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty_"+i).focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty_"+i).value;
			Rate= document.getElementById("itemrate_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty").value;
			Rate= document.getElementById("itemrate").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount").value=Total.toFixed(2);		
		   }	
	
	}
}	 

function calculateTotalPrice1(id)
{
 

var id_brk=id.split('_');

	var i=id_brk[1];
 
	if(id_brk.length>1)
	{	 
		  if(document.getElementById("reciveqty1_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty1_"+i).focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty1_"+i).value;
			Rate= document.getElementById("itemrate1_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount1_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty1").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty1").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty1").value;
			Rate= document.getElementById("itemrate1").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount1").value=Total.toFixed(2);		
		   }	
	
	}
}	  
function calculateTotalPrice2(id)
{
 

var id_brk=id.split('_');

	var i=id_brk[1];
 
	if(id_brk.length>1)
	{	 
		  if(document.getElementById("reciveqty2_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty2_"+i).focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty2_"+i).value;
			Rate= document.getElementById("itemrate2_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount2_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty2").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty2").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty2").value;
			Rate= document.getElementById("itemrate2").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount2").value=Total.toFixed(2);		
		   }	
	
	}
}
function calculateTotalPrice3(id)
{

var id_brk=id.split('_');

	var i=id_brk[1];
	if(id_brk.length>1)
	{	
		  if(document.getElementById("reciveqty3_"+i).value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty3_"+i).focus();	
		  }
		  else
		  {	
			Quantity = document.getElementById("reciveqty3_"+i).value;
			Rate= document.getElementById("itemrate3_"+i).value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount3_"+i).value=Total.toFixed(2);		
		   }	
	
	
	}
	else
	{
		 if(document.getElementById("reciveqty3").value=='')
		  {
			alert("Must Enter Recive Qty");
		  document.getElementById("reciveqty3").focus();	
		  }
		  else
		  {	 
			Quantity = document.getElementById("reciveqty3").value;
			Rate= document.getElementById("itemrate3").value;
			var Total=Quantity*Rate;
			document.getElementById("itemamount3").value=Total.toFixed(2);		
		   }	
	
	}
}	  
function cal_totalamount2()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("basic2_"+i).value);

		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("total_item_amount2").value=total.toFixed(2);	
}
function cal_totalamount12()
{	
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("basic_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("total_item_amount12").value=total.toFixed(2);	
}
function cal_totalamount3()
{
var total=0;
var t=document.getElementById("count").value;
for(var i=0;i<t;i++)
	{
		var amt=parseFloat(document.getElementById("basic3_"+i).value);
		if(isNaN(amt)){amt=0;}
		total=parseFloat(total)+amt;	
	}	
document.getElementById("total_item_amount4").value=total.toFixed(2);	
}

function calcPackaging2(str)

{

	if(str!='')

	{

		var tota_amt=document.getElementById("total_item_amount2").value;

		var pckgng_val=(str/100)*tota_amt;

		document.getElementById("pkg_charges2").value=pckgng_val.toFixed(2);

	}
}

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

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

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

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

function calcexciseduty3()
{	
var exiceAMt = document.getElementById("exciseValueTot").value;
var ecessAMt = document.getElementById("ECessValueTot").value;
var esahAMt = document.getElementById("SAHCessValueTot").value;
if(isNaN(exiceAMt)){exiceAMt=0;}
if(isNaN(ecessAMt)){ecessAMt=0;}
if(isNaN(esahAMt)){esahAMt=0;}
var total = parseFloat(exiceAMt)+parseFloat(ecessAMt)+parseFloat(esahAMt);
document.getElementById("tot_excise_duty_amt3").value=total.toFixed(2);	
}

function calctaxamt2()
{	
var total=0;
var amt1=document.getElementById("tot_excise_duty_amt2").value;
if(isNaN(amt1)){amt1=0;}

var amt2=document.getElementById("total_item_amount2").value;
if(isNaN(amt2)){amt2=0;}

var amt3=document.getElementById("pkg_charges2").value;
if(isNaN(amt3)){amt3=0;}


total=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);	
		
document.getElementById("tot_taxable_amt2").value=total.toFixed(2);	
}

function calctaxamt3()
{	
var total=0;
var amt1=document.getElementById("tot_excise_duty_amt3").value;
if(isNaN(amt1)){amt1=0;}

var amt2=document.getElementById("total_item_amount4").value;
if(isNaN(amt2)){amt2=0;}

var amt3=document.getElementById("pkg_charges4").value;
if(isNaN(amt3)){amt3=0;}


total=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);	
		
document.getElementById("tot_taxable_amt3").value=total.toFixed(2);	
}

function tax_rate2(str)
{
var taxableAmount=document.getElementById("tot_taxable_amt2").value;
if(taxableAmount==''){taxableAmount=0;}
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("taxval2").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","get_tax_val.php?taxid="+str+"&amt="+taxableAmount,true);

xmlhttp.send();

}

function tax_rate3(str)
{
var taxableAmount=document.getElementById("tot_taxable_amt3").value;
if(taxableAmount==''){taxableAmount=0;}
if (str.length==0)
  {
  document.getElementById("taxval1").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("taxval3").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","get_tax_val1.php?taxid="+str+"&amt="+taxableAmount,true);

xmlhttp.send();

}
function calsuroctamt2(str)

{

	var amt=parseFloat(document.getElementById("taxvalue_").value);

	var	suroctper=parseFloat(document.getElementById("sur_oct_per2").value);

	var amount=(amt*suroctper)/100;

	document.getElementById("sur_oct_amt2").value=amount.toFixed(2);	

}

function calsuroctamt3(str)

{
	var amt=parseFloat(document.getElementById("taxvalue2").value);

	var	suroctper=parseFloat(document.getElementById("sur_oct_per3").value);

	var amount=(amt*suroctper)/100;

	document.getElementById("sur_oct_amt3").value=amount.toFixed(2);	

}

function cal_grandamounts2()
{
	var totaltax=document.getElementById("tot_taxable_amt2").value;
	var taxamt=document.getElementById("taxvalue_").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt2").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var loading=document.getElementById("loading").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	

	if(totaltax==''){totaltax=0;}
	if(taxamt==''){taxamt=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(loading==''){loading=0;}
	if(additionalCharges==''){additionalCharges=0;}

	

	var grandtotal=parseFloat(totaltax)+parseFloat(taxamt)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(loading)+parseFloat(additionalCharges);

	document.getElementById("GrandTotals2").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tots2").value=grandtotal.toFixed(2);	

}

function cal_grandamounts3()
{
	var totaltax=document.getElementById("tot_taxable_amt3").value;
	var taxamt=document.getElementById("taxvalue2").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt3").value;
	var TotalCharge=document.getElementById("TotalCharge1").value;
	var loading=document.getElementById("loading1").value;
	var additionalCharges=document.getElementById("additionalCharges1").value;	

	if(totaltax==''){totaltax=0;}
	if(taxamt==''){taxamt=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(loading==''){loading=0;}
	if(additionalCharges==''){additionalCharges=0;}

	

	var grandtotal=parseFloat(totaltax)+parseFloat(taxamt)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(loading)+parseFloat(additionalCharges);

	document.getElementById("GrandTotals3").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tots3").value=grandtotal.toFixed(2);	

}
function calcRounded2(str)

{

	var gtotal=document.getElementById('orig_grand_tots2').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('GrandTotals2').value=final;

}
function calcRounded3(str)

{

	var gtotal=document.getElementById('orig_grand_tots3').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('GrandTotals3').value=final;

}

function DiscountAmount(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo_"+i).value;
		var rate = document.getElementById("itemrate_"+i).value;
		var discount = document.getElementById("Discount_"+i).value;
		var quantity = document.getElementById("reciveqty_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount_"+i).value);
		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);
		document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	var count =document.getElementById("count").value;
var tot_cvd1=0;
for(var i=0; i<count;i++){
	if(subTotal==''){subTotal=0;}
	tot_cvd=parseFloat(tot_cvd)+parseFloat(subTotal);
}
//alert(tot_cvd);
document.getElementById("cvd_total").value = tot_cvd.toFixed(2);
		
}
 function DiscountAmount1(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo1_"+i).value;
		var rate = document.getElementById("itemrate1_"+i).value;
		var discount = document.getElementById("Discount1_"+i).value;
		var quantity = document.getElementById("reciveqty1_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount1_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc1_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate1_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic1_"+i).value=subTotal.toFixed(2);
		var totAmount3 = document.getElementById("total_item_amount3").value;
		if(totAmount3=="")
		{
		document.getElementById("total_item_amount3").value = subTotal.toFixed(2);
		}
		else
		{
		var sum = parseFloat(totAmount3)+parseFloat(subTotal);
		document.getElementById("total_item_amount3").value = sum.toFixed(2);
		}
		
		
}

function DiscountAmount3(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo2_"+i).value;
		var rate = document.getElementById("itemrate2_"+i).value;
		var discount = document.getElementById("Discount2_"+i).value;
		var quantity = document.getElementById("reciveqty2_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount2_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc2_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate2_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic2_"+i).value=subTotal.toFixed(2);
		//var totAmount3 = document.getElementById("GrandTotal1").value;
		//if(totAmount3=="")
		//{
		//document.getElementById("GrandTotal1").value = subTotal.toFixed(2);
		//}
		//else
		//{
		//var sum = parseFloat(totAmount3)+parseFloat(subTotal);
		//document.getElementById("GrandTotal1").value = sum.toFixed(2);
		//}
		
		
}
function DiscountAmount4(DA,id)
{
	id1=id.split("_");
	i=id1[1];
		var discount_percent = document.getElementById("PerAmo3_"+i).value;
		var rate = document.getElementById("itemrate3_"+i).value;
		var discount = document.getElementById("Discount3_"+i).value;
		var quantity = document.getElementById("reciveqty3_"+i).value;
		var totalPrice = parseFloat(quantity)*parseFloat(rate);
		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("Discount3_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc3_"+i).value=percent.toFixed(2);
		document.getElementById("NetRate3_"+i).value=subTotal.toFixed(2);
		document.getElementById("basic3_"+i).value=subTotal.toFixed(2);
		//var totAmount3 = document.getElementById("GrandTotal1").value;
		//if(totAmount3=="")
		//{
		//document.getElementById("GrandTotal1").value = subTotal.toFixed(2);
		//}
		//else
		//{
		//var sum = parseFloat(totAmount3)+parseFloat(subTotal);
		//document.getElementById("GrandTotal1").value = sum.toFixed(2);
		//}
		
		
}



	function FiendPurchasenumber(str)
	{
	var a= document.getElementById('sidecode').value;
	var vendor=document.getElementById("vendor").value;
	var storecode=document.getElementById("storecode").value;
	var receipt=document.getElementById("receiviedagaist").value;
	var mrnno=document.getElementById("mrnNos").value;
	var mrndate=document.getElementById("MRNdates").value;
	location.replace("index.php?route=Inventory/transation/material_receipt_note_exo_edit"+"&ordernos="+str+"&sitecode="+a+"&vendor="+vendor+"&storecode="+storecode+"&receipt="+receipt+"&mrnNum="+mrnno+"&mrnDate="+mrndate+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>");
	}
	function againstPR(str)
	{
	var a= document.getElementById('sitecode').value;
	var vendor=document.getElementById("vendor").value;
	var storecode=document.getElementById("storecode").value;
	var receipt=document.getElementById("receiviedagaist").value;
	location.replace("index.php?route=Inventory/transation/material_receipt_note_add_exo"+"&pr="+str+"&sitecode="+a+"&vendor="+vendor+"&storecode="+storecode+"&receipt="+receipt+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>");
	}

	

function confirmPost()
{
	if(document.getElementById("sitecode").value=='000')
	{
	alert("Must Select Site Name");
	document.getElementById("sitecode").focus();
	return false;
	}
	if(document.getElementById("storecode").value=='000')
	{
	alert("Must Select Store Name");
	document.getElementById("storecode").focus();
	return false;
	}
	if(document.getElementById("receiviedagaist").value=='0')
	{
	alert("Must Select Received Aganist Type");
	document.getElementById("receiviedagaist").focus();
	return false;
	}
	if(document.getElementById("vendor").value=='000')
	{
	alert("Must Select  Vender");
	document.getElementById("vendor").focus();
	return false;
	}
	if(document.getElementById("gatepassno").value=='')
	{
	alert("Must Enter Gate Entry No");
	document.getElementById("gatepassno").focus();
	return false;
	}
	if(document.getElementById("gatepassdate").value=='')
	{
	alert("Must Enter Gate Entry Date");
	document.getElementById("gatepassdate").focus();
	return false;
	}
	if(document.getElementById("entrycheck").value=='1')
	{
	alert("Duplicate Entry For Gate Entry Pass");
	document.getElementById("gatepassno").value='';
	document.getElementById("gatepassno").focus();
	return false;
	}
	
	
	var col=0;
	var cou=document.getElementById("count").value;
	for(var i=0;i<cou;i++)
	{	
	if(document.getElementById("qty_as_per_bill_"+i).value!='')
	{
	var col=1;
	}	
	}
	//if(col==0)
	//{
	//alert("please Fill All details of item");
	//return false;
	//}
	
		
	
	
	
	
	
	
	
	
	
	
	
	
	if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
	{
	alert("Grand Total amount should not be blank");
	document.getElementById("GrandTotal").focus();
	return false;
	}		
	
}

function confirmPost1()
{
	var max_price=document.getElementById("max_price").value;
	var grand_price=document.getElementById("GrandTotal").value;
	if(parseFloat(grand_price) > parseFloat(max_price)){
	$alertmasg="Grandtotal not more than Maximum Direct Purchase Allowed Amount - "+max_price;
	alert($alertmasg);
	return false;
	}
	
	if(document.getElementById("sitecode").value=='000')
	{
	alert("Must Select Site Name");
	document.getElementById("sitecode").focus();
	return false;
	}
	if(document.getElementById("storecode").value=='000')
	{
	alert("Must Select Store Name");
	document.getElementById("storecode").focus();
	return false;
	}
	if(document.getElementById("receiviedagaist").value=='0')
	{
	alert("Must Select Received Aganist Type");
	document.getElementById("receiviedagaist").focus();
	return false;
	}
	if(document.getElementById("vendor").value=='000')
	{
	alert("Must Select  Vender");
	document.getElementById("vendor").focus();
	return false;
	}
	if(document.getElementById("gatepassno").value=='')
	{
	alert("Must Enter Gate Entry No");
	document.getElementById("gatepassno").focus();
	return false;
	}
	if(document.getElementById("gatepassdate").value=='')
	{
	alert("Must Enter Gate Entry Date");
	document.getElementById("gatepassdate").focus();
	return false;
	}
	if(document.getElementById("entrycheck").value=='1')
	{
	alert("Duplicate Entry For Gate Entry Pass");
	document.getElementById("gatepassno").value='';
	document.getElementById("gatepassno").focus();
	return false;
	}
	
	var col=0;
	var cou=document.getElementById("count").value;
	for(var i=0;i<cou;i++)
	{	
	if(document.getElementById("qty_as_per_bill_"+i).value!='')
	{
	var col=1;
	}	
	}
	if(col==0)
	{
	alert("please Fill All details of item");
	return false;
	}
	
	if(document.getElementById("total_item_amount").value=='' || document.getElementById("total_item_amount").value=='0.00')
	{
	alert("Total amount should not be blank");
	document.getElementById("total_item_amount").focus();
	return false;
	}	
	
	if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
	{
	alert("Grand Total amount should not be blank");
	document.getElementById("GrandTotal").focus();
	return false;
	}		
	

}



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

function caltaxamout1(i)
				{
					
				var excise=parseFloat(document.getElementById("exciseDuty_"+i).value);
				
				if(excise!=0)
				{
				var basic_amount=document.getElementById("exciseValue_"+i).value;
				var ecessamt=document.getElementById("ECessValue_"+i).value;
				var sahamt=document.getElementById("SAHCessValue_"+i).value;
				var totaltax=parseFloat(basic_amount)+parseFloat(ecessamt)+parseFloat(sahamt);	
				document.getElementById('taxableamount_'+i).value=totaltax.toFixed(2);	
				}
				else
				{
				document.getElementById('taxableamount_'+i).value=0;		
				}	
					
				}
								function calvatamount(i)
								{
								
								var vatcst_per=document.getElementById('vatper').value;
								
								if(vatcst_per!=0)
								{
								var taxamt=parseFloat(document.getElementById('taxableamount_'+i).value);
								//var item_total_rate=parseFloat(document.getElementById('item_total_rate_'+i).value);
								var total=taxamt;
								var vatamount=(total*vatcst_per)/100;
								document.getElementById('vatcstamount_'+i).value=vatamount.toFixed(2);	
									
								}	
								else
								{
								document.getElementById('vatcstamount_'+i).value=0;	
								}
									
									
								}


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

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

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

function calculate_poshort1(id)
	{
	var qty_per_bill=parseInt(document.getElementById("qty_as_per_bill1_"+id).value);
	var reciveqty=parseInt(document.getElementById("reciveqty1_"+id).value);	
	if(document.getElementById("reciveqty1_"+id).value=='')
	{
	var reciveqty=0;	
	}
	else
	{
	var reciveqty=parseInt(document.getElementById("reciveqty1_"+id).value);	
	}
	var short_accessid=qty_per_bill-reciveqty;
	if(short_accessid<0){short_accessid=0;}
	document.getElementById("short_accessid1_"+id).value=short_accessid;
}

function calculate_poshort2(id)
	{
	var qty_per_bill2=parseInt(document.getElementById("qty_as_per_bill2_"+id).value);
	var reciveqty2=parseInt(document.getElementById("reciveqty2_"+id).value);	
	if(document.getElementById("reciveqty2_"+id).value=='')
	{
	var reciveqty2=0;	
	}
	else
	{
	var reciveqty2=parseInt(document.getElementById("reciveqty2_"+id).value);	
	}
	var short_accessid2=qty_per_bill2-reciveqty2;
	if(short_accessid2<0){short_accessid2=0;}
	document.getElementById("short_accessid2_"+id).value=short_accessid2;
}

function calculate_poshort3(id)
	{
	var qty_per_bill2=parseInt(document.getElementById("qty_as_per_bill3_"+id).value);
	var reciveqty2=parseInt(document.getElementById("reciveqty3_"+id).value);	
	if(document.getElementById("reciveqty3_"+id).value=='')
	{
	var reciveqty2=0;	
	}
	else
	{
	var reciveqty2=parseInt(document.getElementById("reciveqty3_"+id).value);	
	}
	var short_accessid2=qty_per_bill2-reciveqty2;
	if(short_accessid2<0){short_accessid2=0;}
	document.getElementById("short_accessid3_"+id).value=short_accessid2;
}


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 value_after_discount1(i)
{
	
	var basic = parseFloat(document.getElementById('basic2_'+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 grnDisabled1(str)
 {
 	if(str=="Itemwise")
	{
		if(document.getElementById("GrnType").value=="1")
		{
	document.getElementById("OLDimportPo1").style.display="none";
	document.getElementById("importPo1").style.display="block";
	document.getElementById("OLDcharges1").style.display='none';
	document.getElementById("charges1").style.display='block';
		}else if(document.getElementById("GrnType").value=="2")
		{
	document.getElementById("importPo2").style.display="block";
	document.getElementById("importPo1").style.display="none";
	document.getElementById("importPo3").style.display='none';
	document.getElementById("importPo4").style.display='none';
	document.getElementById("charges1").style.display='none';
	document.getElementById("charges2").style.display='block';
	document.getElementById("charges3").style.display='none';
	document.getElementById("charges4").style.display='none';
		}
	}
	else
	{
		if(document.getElementById("GrnType").value=="1")
		{
	document.getElementById("importPo1").style.display='none';
	document.getElementById("importPo2").style.display='none';
	document.getElementById("importPo3").style.display='block';
	document.getElementById("importPo4").style.display='none';
	document.getElementById("charges1").style.display='none';
	document.getElementById("charges2").style.display='none';
	document.getElementById("charges3").style.display='block';
	document.getElementById("charges4").style.display='none';
	}else if(document.getElementById("GrnType").value=="2")
		{
	document.getElementById("importPo1").style.display='none';
	document.getElementById("importPo2").style.display='none';
	document.getElementById("importPo3").style.display='none';
	document.getElementById("importPo4").style.display='block';
	document.getElementById("charges1").style.display='none';
	document.getElementById("charges2").style.display='none';
	document.getElementById("charges3").style.display='none';
	document.getElementById("charges4").style.display='block';
	}
	}
 }
 
function check_po1()
{
	var rowcount=document.getElementById("rowcount").value;
	for(var i=0;i<rowcount;i++)
	{
		poqty=parseFloat(document.getElementById("poqty_"+i).value);
		reciveqty=parseFloat(document.getElementById("reciveqty_"+i).value);
		if(reciveqty!='' && poqty!='')
		{
		if(reciveqty>poqty)
		{
			alert("Received Quantity Cannot Be Greater Than PO Quantity");
			document.getElementById("reciveqty_"+i).focus();
			return false; 
		}
		}
		
	}
}
 
function check_bill_qty(str,id)
{
  
	var poqty=parseInt(document.getElementById("pendingqty_"+id).value);
	var tolerance = document.getElementById("tolerance_"+id).value;
	if(tolerance==''){tolerance=0;}
	str1=parseInt(str);
	if(poqty!='')
	{
	var qty=(poqty*tolerance)/100;
	var poqty1=parseInt(poqty)+parseInt(qty);
	//var poqty2=poqty-qty;	
	if(str1>poqty1)
	{
		var altmsg = "Quantity As Per Bill Cannot Be Greater Than "+tolerance+" % more of PO Quantity";
		alert(altmsg);
		document.getElementById("qty_as_per_bill_"+id).value='';
		document.getElementById("reciveqty_"+id).value='';
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
	}
	}
}

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

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


}
}

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

/*function check_po()
{
	
	var sitecode=document.getElementById("sitecode").value;
	var storecode=document.getElementById("storecode").value;
	var vendor=document.getElementById("vendor").value; 
	var billno=document.getElementById("billno").value;
	
	if(sitecode=='000')
	{
		alert("Please Select Sitecode");
		return false; 
	}
	if(document.getElementById("receiviedagaist").value!="Without PO")
	{
	if(vendor=='000')
	{
		alert("Please Select Vendor");
		 return false;
	}
	}
	if(storecode=='000')
	{
		alert("Please Select Sitecode");
		 return false;
	}
	if(billno=='')
	{
		alert("Please Challan Or Bill");
		 return false;
	}
	return true;
}*/
</script>