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


//************INSERT RECORD HERE******START HERE**********14-06-2013***********AS**********************************

if($_REQUEST['save'])
{
      
	date_default_timezone_set('Asia/Calcutta');
	$financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
	 $sql="Select MRNNo from addmrn where site='".$_REQUEST['sitecode']."' 
	and INSTR(`MRNNo`, '$financial') > 0 order by id desc limit 0,1";
	$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."' and module_id='".$_REQUEST['modid']."' ",$db);
    $prefix_row=DB_fetch_array($prefix_sql);
    //$prefixf=explode("/",$prefix_row['prefix_code']);
    $prefix1=$prefix_row['prefix_code'];
	$result=DB_query($sql,$db);
	$myrow=DB_fetch_array($result);
	//echo DB_num_rows($result);
	if(DB_num_rows($result)>0)
	{
	//$Reqno=$myrow['Reqno'];
	//$req_part1=substr($Reqno,-4);
	$ExplBill=explode("/",$myrow['MRNNo']);
	$maxval = $ExplBill[3];
	//echo $req_part1;
	$req_final=$maxval+1;
	//echo "<br>".$req_final;
	}
	else
	{
	$req_final="1";
	}
	
	$string=$_REQUEST['sitecode']."/".$financial."/".$prefix1.'/';
	$final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);
	
	
	//$data['MRNNo']           =$final_string; 
	$data['MRNDate']         =FormatDateForSQL($_REQUEST['MRNdate']);  
	$data['site']            =$_REQUEST['sitecode']; 
	$data['StoreCode']       =$_REQUEST['storecode'];
	$data['ReceivedAgainst'] =$_REQUEST['receiviedagaist'];
	$data['ReceivedFrom']    =$_REQUEST['vendor'];
	$data['Type']            =$_REQUEST['PoType'];
	$data['Po_category']     =$_REQUEST['Pocategory'];
	$data['order_no']        =$_REQUEST['PONo']; 
	$data['req_no']          =$_REQUEST['req_no'];
	$data['DocumentType']    =$_REQUEST['DocumentType'];
	$data['BillNo']          =$_REQUEST['billno'];  
	$data['MRNVoucherDate']  =FormatDateForSQL($_REQUEST['MRNVoucherDate']); 
	$data['GetPassNo']       =$_REQUEST['gatepassno']; 
	$data['gatepassdate']    =FormatDateForSQL($_REQUEST['gatepassdate']);
	$data['VehicleNo']       =$_REQUEST['vehicalno']; 
	$data['TimeIn']          =$_REQUEST['timein']; 
	$data['Timeout']         =$_REQUEST['timeout']; 
	$data['LRno']            =$_REQUEST['lrno'];
	$data['form_type']       =$_REQUEST['form_type'];
	$data['form_no']         =$_REQUEST['form_no'];
	$data['Transp_name']     =$_REQUEST['transport'];
	$data['RemarksIfAny']    =$_REQUEST['RemarksIfAny']; 
	$data['transaction_time'] =FormatDateForSQL($_REQUEST['MRNdate'])." ".date('H:i:s', time());
	$data['totalBillQty']    =$_REQUEST['totalBillQty'];
	$data['totalRecQty']     =$_REQUEST['totalRecQty'];
    $data['mrnstatus']       ="Pending";
	$data['Grn_Type']        ="Direct";	
	$data['companyID']       =$_SESSION['ACGCompanyId'];
	$data['createdby']       =$_SESSION['UserID'];
	$data['duty_type']       ='Consolidated';
    $data['totalBillQty']    =$_REQUEST['totalBillQty'];
    $data['totalRecQty']     =$_REQUEST['totalRecQty'];
	$cond="id='".$_REQUEST['mrnid']."'";
	$s->RecordEdit('addmrn',$data,$cond);
	$Lastreq_id=$_REQUEST['mrnid'];

	$delete=DB_query("delete from addmrnqty where issue_id='".$_REQUEST['mrnid']."'",$db);
	 $delete=DB_query("delete from stock_valuation_tbl where against_voucher_main_id='".$_REQUEST['mrnid']."' and type='MRN'",$db);
	
	for($i=0;$i<count($_REQUEST['mst_itemid']);$i++)
	{
		if($_REQUEST['mst_itemid'][$i]!='')
		{				
			$data_arr['issue_id']         =$Lastreq_id;
			//$data_arr['issue_qty']        =$_POST['issuebalanc'][$i];			
			$data_arr['mst_itemid']       =$_POST['mst_itemid'][$i];
          	$data_arr['POQty']            =$_REQUEST['poqty'][$i];
           // $data_arr['issue_qty']        =$_POST['issuebalanc'][$i];
			$data_arr['qty_as_per_bill']  =$_REQUEST['qtyasperbill'][$i];
			$data_arr['reciveqty']        =$_REQUEST['reciveqty'][$i];
			$data_arr['stock_qty2']       =$_REQUEST['reciveqty2'][$i];
			$data_arr['short_accessid']   =$_REQUEST['shortaccessid'][$i];			
			$data_arr['batch_no']         =$_REQUEST['batchNo'][$i]; 	
			//$data_arr['rate']         	  =$_REQUEST['rate'][$i]; 	
			//$data_arr['amount']           =$_REQUEST['amount'][$i]; 	


			
			$data_arr['mfg']         	  =FormatDateForSQL($_REQUEST['mfg'][$i]); 	
			$data_arr['expiry']           =FormatDateForSQL($_REQUEST['expiry'][$i]); 	

			// $data_arr['trasaction']     =FormatDateForSQL($_REQUEST['MRNdate'])." ".date('H:i:s', time());;
           

			//$data_arr['size']             =$_REQUEST['sizesp'][$i];
			$data_arr['minSign']          =$_REQUEST['minSign'][$i];
			//$data_arr['Gread']            =$_REQUEST['gradesp'][$i];		
            $data_arr['conv_fac']         =$_REQUEST['conv_fac'][$i];
            $data_arr['mst_unitid']       =$_REQUEST['unit'][$i];
            $data_arr['mst_sec_unitid']       =$_REQUEST['unit2'][$i];
            $data_arr['mrprate']          =$_REQUEST['mrprate'][$i];

			if($_REQUEST['receiviedagaist']=='Indent')
			$data_arr['grn_type']         ='Indent';
			else
			$data_arr['grn_type']         ='Indirect';			
			
			if($_REQUEST['short_qty'][$i]!=0)
			$data_arr['status']           = "N";
			else
			$data_arr['status']           ="Y";
		    $data_arr['qty_type']         ='P';

			
		  $s->RecordInsert('addmrnqty', $data_arr);
		  $dtls_Lastreq_id=DB_Last_Insert_ID($db,'addmrnqty',$ErrMsg);
         



          /*************************   Stock Valution *******************************/

   //  $check_current_opening="Select * from stock_valuation_tbl where  site='".$_REQUEST['sitecode']."'
     // and  store='".$_REQUEST['storecode']."'   and mst_itemid='".$_POST['mst_itemid'][$i]."' 
    //  and flag=0 order by id ASC ";
   // $check_current_op_result=DB_query($check_current_opening,$db);
    //if(DB_num_rows($check_current_op_result)=='0')
    //{

               $primary_unit=$s->getField('item_master','id',$_POST['mst_itemid'][$i],'mst_unitid');
               $secondary_unit=$s->getField('item_master','id',$_POST['mst_itemid'][$i],'conv_unit');
               $data_stock['site']                     =$_REQUEST['sitecode'];
               $data_stock['store']                    =$_REQUEST['storecode'];
               $data_stock['mst_itemid']               =$_POST['mst_itemid'][$i];
               $data_stock['primary_unit']             =$primary_unit;
               $data_stock['secondary_unit']           =$secondary_unit;
               $data_stock['against_voucher_main_id']  =$Lastreq_id;
               $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
               $data_stock['type']                     ='MRN';                    
               $data_stock['status']=0;               
               $data_stock['inwardqty_primary']       = $_REQUEST['reciveqty'][$i];
               $data_stock['pending_qty']              =$_REQUEST['reciveqty'][$i];
               $data_stock['inwardqty_secondary']     = $_REQUEST['reciveqty2'][$i];
               $data_stock['inward_rate']             = $_REQUEST['mrprate'][$i];
              // $data_stock['inwared_value']            =$_REQUEST['amount'][$i];
               $data_stock['batch_no']                 =$_REQUEST['batchNo'][$i];
               $data_stock['date_of_mfg']              =FormatDateForSQL($_REQUEST['mfg'][$i]);
               $data_stock['date_of_expiry']           =FormatDateForSQL($_REQUEST['expiry'][$i]);
               $data_stock['trasaction']               =date("Y/m/d h:i:sa");
             

               $s->RecordInsert('stock_valuation_tbl', $data_stock);


    //}

   /* else
    {
      $pendingqty=$_REQUEST['reciveqty'][$i];
      $t=0;
      while($check_current_op_row=DB_fetch_array($check_current_op_result))
      {
         if($pendingqty!='0.00')
         {
              $id=$check_current_op_row['id'];
              if($check_current_op_row['pending_qty']!='0.00')
              {
                  if($check_current_op_row['pending_qty']>$pendingqty)
                   {
                       $inwardpenqty=$check_current_op_row['pending_qty']-$pendingqty;
                        $outwards_qty=$pendingqty;
                        $outward_rate=$check_current_op_row['inward_rate'];
                        $outwardamount=$check_current_op_row['inward_rate']*$outwards_qty;
                   }
                   else
                   {
                        $inwardpenqty='0';
                        $outwards_qty=$check_current_op_row['pending_qty'];
                        $outward_rate=$check_current_op_row['inward_rate'];
                        $outwardamount=$check_current_op_row['inward_rate']*$outwards_qty;
                   }
                 
                 $primary_unit=$s->getField('item_master','id',$_POST['itemdataid'][$i],'mst_unitid');
                 $secondary_unit=$s->getField('item_master','id',$_POST['itemdataid'][$i],'conv_unit');
                 $data_stock['site']                     =$_REQUEST['site'];
                 $data_stock['store']                    =$_REQUEST['store'];
                 $data_stock['mst_itemid']               =$_POST['mst_itemid'][$i];
                
                 $data_stock['primary_unit']             =$primary_unit;
                 $data_stock['secondary_unit']           =$secondary_unit;
                 $data_stock['against_voucher_main_id']  =$Lastreq_id;
                 $data_stock['against_voucher_dtls_id']  =$dtls_Lastreq_id;
                 $data_stock['type']                     ='FMR';    
                 if($check_current_op_row['status']=='1')
                  $data_stock['status']=1;
                 else
                  $data_stock['status']=0;               
                 $data_stock['inwardqty_primary']       = $outwards_qty;
                 $data_stock['pending_qty']             =$outwards_qty;
                 $data_stock['inwardqty_secondary']     = $outwards_qty*$_REQUEST['convfac'][$i];  
                 //$data_stock['inward_rate']             =$_REQUEST['rate'][$i];
                 //$data_stock['inwared_value']           =$_REQUEST['amount'][$i];
                 $data_stock['batch_no']                =$_REQUEST['batchNo'][$i];
               	 $data_stock['date_of_mfg']              =FormatDateForSQL($_REQUEST['mfg'][$i]);
                 $data_stock['date_of_expiry']           =FormatDateForSQL($_REQUEST['expiry'][$i]);


               
                 $data_stock['trasaction']               =date('H:i:s', time());

                         // $data_stock['batch_no']                 =$_REQUEST['batchNo'][$i];
                $s->RecordInsert('stock_valuation_tbl', $data_stock);
                $pendingqty=$pendingqty-$outwards_qty;
                 if($inwardpenqty!=0)
                     $status=0;
                 else
                    $status=1;
                  $update_summary="Update  stock_valuation_tbl set pending_qty='".$inwardpenqty."',
                                       flag='".$status."' where id=$id ";
                   $result2=DB_query($update_summary,$db);
                 }
                }   
                 $t++;  
                     
              }
           }*/
       
			
    
		}//END OF IF HERE
		
		
		
	}// END OF FRO LOOP HERE
	
	$_SESSION['success_msg']="Saved Successfully";
	$s->pageLocation("index.php?route=Inventory/transation/material_receipt_note_index_direct".$rurl);
}




?>
<div id="PickedItems" style="display:none"></div>

<script type="text/javascript">

//Jquery.noConflict();
$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=profile_popup]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var site=document.getElementById("sitecode").value;
             if($('#sitecode').val()=='000')
           {
    	alert('Please select site.');
    	return false;
            }
     if($('#storecode').val()=='' || $('#storecode').val()==0)
     {
     	alert('Please select store.');
     	return false;
     }
     

		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#PickedItems").dialog({
				title:'Item List',
				modal: true,
				resizable: false,
				width:1000,
				height:450,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		GetitemListForDirectPO(site);
		});
	});



function GetitemListForDirectPO(str)
{   $('#PickedItems').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>');
   

	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("PickedItems").innerHTML=xmlhttp.responseText;
	}
	}
    
     var store=$('#storecode').val();

	xmlhttp.open("GET","direct_po_items1.php?site="+str+"&store="+store,true);
	xmlhttp.send();
}

function validation()
{
   var t=0;
 var count=document.getElementById("hiditemcount").value;
 if(count=='')
 {
 	if(document.getElementById('itemid').value=='' ||  document.getElementById("poqty").value=='')
 	 t=1;

 }
 else
 {
  if(document.getElementById('itemid').value=='' || document.getElementById("poqty").value=='')
 	t=1;
 for(var k=1;k<=count;k++)
 {
if(document.getElementById('itemid_'+k).value=='' ||  document.getElementById("poqty_"+k).value=='')
 	t=1;

 }


 }
 if(t==1)
 alert("Product Information Required");

 if(document.getElementById("sitecode").value=='000')
     {
        alert('Select Branch');
        document.getElementById("sitecode").focus();
        return false;
     }
     
     if(document.getElementById("receiviedagaist").value=='0')
     {
        alert('Select Received Against');
        document.getElementById("receiviedagaist").focus();
        return false;
     }
     
     if(document.getElementById("vendor").value=='')
     {
        alert('Select Received From');
        document.getElementById("vendor").focus();
        return false;
     }
     
     if(document.getElementById("gatepassno").value=='')
     {
        alert('Enter Gate Entry No');
        document.getElementById("gatepassno").focus();
        return false;
     }
     
     if(document.getElementById("gatepassdate").value=='')
     {
        alert('Enter Gate Pass Date');
        document.getElementById("gatepassdate").focus();
        return false;
     }


    


}
function getSubCategory()
{    
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{   
	document.getElementById("srch_subcateory").innerHTML=xmlhttp.responseText;
       // getdata1();
	}
	}
        var category=document.getElementById("srch_cateory").value;
	xmlhttp.open("GET","ajax_subcategory.php?cat="+category,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	
function getData1()
{       
	 var site=document.getElementById("sitecode").value;
         var code=document.getElementById("srch_code").value;
         var name=document.getElementById("srch_name").value; 
         var category=document.getElementById("srch_cateory").value;
         var subcat=document.getElementById("srch_subcateory").value;
         var store=document.getElementById('storecode').value;
         $.post('ajax_item_list_srch_grn.php',{'code':code,'site':site,'name':name,'cat':category,'subcat':subcat,'store':store},function(data){
         	$('#ItemListDiv').html(data);

         });
}	

function cal_cvd_total_amount(str)
{
var id_brk=str.split('_');
	var i=id_brk[1];
	
	if(i==undefined)
	{
		var basic=document.getElementById("basic").value;	 
		 var Totaltaxable=document.getElementById("CustomDutyAmt").value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var cvdPer = document.getElementById("cvdpercentage").value;
		var cvd = grand_tot1*(cvdPer/100);
		var grand_tot=cvd.toFixed(2);
		 
		 document.getElementById("TotalSpecial").value=grand_tot ;	
	}
	else
	{
	  var basic=document.getElementById("basic_"+i).value;	 
		 var Totaltaxable=document.getElementById("CustomDutyAmt_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
	  
 	 
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable); 
		var cvdPer = document.getElementById("cvdpercentage_"+i).value;
		var cvd = grand_tot1*(cvdPer/100);
		var grand_tot=cvd.toFixed(2);
		 
		 document.getElementById("TotalSpecial_"+i).value=grand_tot ;
	
	
	
	
	}
	




}


function grnDisabled1(str)
 {
	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("divordertype").innerHTML=data[0];
		document.getElementById("basicamtdetails").innerHTML=data[1];
	}
	}
	var purtype=document.getElementById("PoType").value;
	
	xmlhttp.open("GET","ajax_grn_order_type1.php?OrderType="+purtype+"&dutytype="+str,true);
	xmlhttp.send();
 }
function cal_cvd_total_amount1(str)
{
var id_brk=str.split('_');
	var i=id_brk[2];
	if(i==undefined)
	{
	var id1="TotalSpecial";
		var data=cal_cvd_total_amount(id1);
	}	
	else
	{
	var id1="TotalSpecial_"+i;
	var data=cal_cvd_total_amount(id1);
	}	




}


function cal_e_cess1(id)
{
//alert(id);
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(i==undefined)
	{
	if(document.getElementById("CustomDutyAmt") && document.getElementById("CustomDutyAmt").value!='')
	var b = document.getElementById("CustomDutyAmt").value; 
	else
	var b=0;
	
	//var b = document.getElementById("CustomDutyAmt").value; 
	var c = document.getElementById("TotalSpecial").value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var ecessPer = document.getElementById("ecesspercentage").value;
	var tot = tot1*(ecessPer/100);
	var final_eces=tot.toFixed(2);
	document.getElementById("customecess").value=final_eces;	
	}
	else
	{
	if(document.getElementById("CustomDutyAmt_"+i) && document.getElementById("CustomDutyAmt_"+i).value!='')
	var b = document.getElementById("CustomDutyAmt_"+i).value; 
	else
	var b=0;
	//alert(b);
	//var b = document.getElementById("CustomDutyAmt_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var ecessPer = document.getElementById("ecesspercentage_"+i).value;
	var tot = tot1*(ecessPer/100);
	var final_eces=tot.toFixed(2);
	document.getElementById("customecess_"+i).value=final_eces;
	
	
	
	
	}
}

function cal_esec_cess1(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(i==undefined)
	{
	if(document.getElementById("CustomDutyAmt") && document.getElementById("CustomDutyAmt").value!='')
	var b = document.getElementById("CustomDutyAmt").value; 
	else
	var b=0;
	//var b = document.getElementById("CustomDutyAmt").value; 
	var c = document.getElementById("TotalSpecial").value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var secEcessPer = document.getElementById("secesspercentage").value; 
	var tot = tot1*(secEcessPer/100);
	var final_eces1=tot.toFixed(2);
	document.getElementById("customsececess").value=final_eces1;	
	}
	else
	{
	if(document.getElementById("CustomDutyAmt_"+i) && document.getElementById("CustomDutyAmt_"+i).value!='')
	var b = document.getElementById("CustomDutyAmt_"+i).value; 
	else
	var b=0;
	
	//var b = document.getElementById("CustomDutyAmt_"+i).value; 
	var c = document.getElementById("TotalSpecial_"+i).value; 
	var tot1= parseFloat(b)+parseFloat(c);
	var secEcessPer = document.getElementById("secesspercentage_"+i).value; 
	var tot = tot1*(secEcessPer/100);
	var final_eces1=tot.toFixed(2);
	document.getElementById("customsececess_"+i).value=final_eces1;
	
	
	
	}
}

function cal_add_duty1(id)
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(i==undefined)
	{	
	var a = document.getElementById("basic").value; 
	if(document.getElementById("CustomDutyAmt") && document.getElementById("CustomDutyAmt").value!='')
	var b = document.getElementById("CustomDutyAmt").value; 
	else
	var b=0;
	//var b = document.getElementById("CustomDutyAmt").value;
	var c = document.getElementById("TotalSpecial").value; 
	var d = document.getElementById("customecess").value; 
	var e = document.getElementById("customsececess").value; 
		var tot12= parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
	var addPer = document.getElementById("addpercentage").value; 
	var tot1 = tot12*(addPer/100);
	var final_eces2=tot1.toFixed(2);
	document.getElementById("adduty").value=final_eces2 ;	
	}
	else
	{
	var a = document.getElementById("basic_"+i).value; 
	if(document.getElementById("CustomDutyAmt_"+i) && document.getElementById("CustomDutyAmt_"+i).value!='')
	var b = document.getElementById("CustomDutyAmt_"+i).value; 
	else
	var b=0;
	//var b = document.getElementById("CustomDutyAmt_"+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 addPer = document.getElementById("addpercentage_"+i).value; 
	var tot1 = tot12*(addPer/100);
	var final_eces2=tot1.toFixed(2);
	document.getElementById("adduty_"+i).value=final_eces2 ;	
	
	
	}
	
}


function ajax_cur_rate_cal(str,id1)
{
 var j=id1.split("_");
   var id=j[1];
  
   if(j[1]!=undefined)
   {
var basicAmt = document.getElementById("NetRate_"+id).value;
if(document.getElementById("convrate_"+id).value!='')
var con_fac=document.getElementById("convrate_"+id).value;
else
var con_fac=1;
var total=parseFloat(basicAmt)*parseFloat(con_fac);
document.getElementById("basic_"+id).value=total.toFixed(2);
}
else
{
var basicAmt = document.getElementById("NetRate").value;
if(document.getElementById("convrate").value!='')
var con_fac=document.getElementById("convrate").value;
else
var con_fac=1;
var total=parseFloat(basicAmt)*parseFloat(con_fac);

document.getElementById("basic").value=total.toFixed(2);
}




}


function ajax_cur_rate(str,id)
 {
 
   var j=id.split("_");
   var i=j[1];
  
   if(j[1]==undefined)
   {
   
 	var basicAmt = document.getElementById("NetRate").value;
	
	var oldid=document.getElementById("itemCurrency").value;
	if (str==''){
  		document.getElementById("convrate").value="";
 	 	return;
  	}
	}
	else
	{
	var basicAmt = document.getElementById("NetRate_"+i).value;
	var oldid=document.getElementById("itemCurrency_"+i).value;
	if (str==''){
  		document.getElementById("convrate_"+i).value="";
 	 	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){
	    
		var data=xmlhttp.responseText.split("__");
		if(data[0]=="")
		{
		alert('Conversion Rate is Empty');
		if(j[1]!=undefined)
		{
		document.getElementById("convcurr_"+i).focus();
		}
		else
		{
		document.getElementById("convcurr").focus();
		}
		return false;
		}
		else
		{
		
		if(j[1]==undefined)
    	document.getElementById("convrate").value=data[0];
		else
		document.getElementById("convrate_"+i).value=data[0];
		}
		if(j[1]!=undefined)
		document.getElementById("basic_"+i).value=data[1];
		else
		document.getElementById("basic").value=data[1];

   }
   
 }
xmlhttp.open("GET","ajax_get_rate.php?oldCur="+oldid+"&newCur="+str+"&basicAmount="+basicAmt,true);
xmlhttp.send();
 }

function addRow(tableID) 
{
		
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1)+1;
	document.getElementById("rowcount1").value=rr;
	document.getElementById("hiditemcount").value=rr;
	document.getElementById("edit_cnt").value=rr;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newCount=parseInt(rowCount);
	var newcell = row.insertCell(i);
	newcell.style.background='#fff';	
	
	//newcell.className='tabledata';
	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	//var nod_id = newcell.childNodes[0].id;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	//newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	//newcell.childNodes[0].name = newcell.childNodes[0].name;
	
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	
	
}
function deleteRow(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
		document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
		}
		catch(e) 
		{
			alert(e);
		}

}


function getItemsList(id,code,shade,desc,uom,netrate,mrprate,stock,ctr,tolerance,confac,unit2)
{
	//alert(confac);
	var dup='empty';
	var itemcount=parseInt(document.getElementById('rowcount1').value)+1;
	
	var edit_cnt=document.getElementById('edit_cnt').value;
	//alert(edit_cnt);
	if(edit_cnt=='')
	{
		var counter=1;
	} 
	else if(edit_cnt>itemcount)
	{
		var counter=edit_cnt;
		var itemcount=parseFloat(counter)+parseFloat(itemcount);
	}
	else
	{
		var counter=edit_cnt;
	}
	
	//alert(counter);
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
	
	if(document.getElementById("row_id_"+ctr).checked==true)
	{
	
	    
		if(document.getElementById('itemid') && document.getElementById('itemid').value=='')
		{
			if(edit_cnt=='')
			{
				var counter=0;
			}
		
			for(var j=0; j<counter; j++)
			{
				if(document.getElementById('itemid1_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
			}
			
			if(dup=='empty')
			{	
				//var data=addRow('dataTable');
				document.getElementById('itemid').value = id;
				document.getElementById('itemcode').value = code;
				document.getElementById('itemname').value = shade;
                document.getElementById('unit').innerHTML = uom;
                document.getElementById('unit2').innerHTML = unit2;
                document.getElementById('convfac').value = confac;
                document.getElementById('confac1').value=confac;
                document.getElementById('tolerances').value = tolerance;
				//document.getElementById('total_stock').value = stock;
				//document.getElementById('itemdesc').value = desc;	
				//document.getElementById('price').value = netrate;
				//document.getElementById('mrpper').value = mrprate;
				
			}
		}
		else
		{
			for(var i=counter; i<=itemcount; i++)
			{	
			
			
				if(edit_cnt=='')
				{
					var counter=0;
				}
				for(var j=0; j<counter; j++)
				{}
				if(document.getElementById('itemid'))
				{
				if(document.getElementById('itemid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(document.getElementById('itemid1_'+i))
				{
				if(document.getElementById('itemid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(dup=='empty')
				{	
				
				 if(!document.getElementById('itemid_'+i))
				 {
				 var data= addRow('dataTable');	
				 }
				if(document.getElementById('itemid_'+i))
					{					
					
					if(document.getElementById('itemid_'+i).value=='')
					{	
						document.getElementById('itemid_'+i).value = id;
						document.getElementById('itemcode_'+i).value = code;
						document.getElementById('itemname_'+i).value = shade;
                        document.getElementById('unit_'+i).innerHTML = uom;
                         document.getElementById('unit2_'+i).innerHTML = unit2;
                        document.getElementById('convfac_'+i).value = confac;
                        document.getElementById('confac1_'+i).value=confac;
                        //document.getElementById('tolerances_'+i).value = tolerance;
						//document.getElementById('total_stock_'+i).value = stock;
						//document.getElementById('itemdesc_'+i).value = desc;	
						//document.getElementById('price_'+i).value = netrate;
						//document.getElementById('mrpper_'+i).value = mrprate;	
						break;
						break;
					}
					}
					else
					{
						continue;
					}
				}
			}
		}
	}
	

	else
	{
	
		if(document.getElementById('itemid').value==document.getElementById("row_id_"+ctr).value)
		{
			document.getElementById('itemid').value = '';
			document.getElementById('itemcode').value = '';
			document.getElementById('itemname').value = '';
                        document.getElementById('unit').innerHTML = '';
                        document.getElementById('tolerances').value = tolerance;
			document.getElementById('total_stock').value='';
			document.getElementById('itemdesc').value = '';
			document.getElementById('price').value = '';
			document.getElementById('mrpper').value = '';
		}
		else
		{
		
			for(var i=counter; i<itemcount; i++)
			{
				if(document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
					document.getElementById('itemid_'+i).value = '';
					document.getElementById('itemcode_'+i).value = '';
					document.getElementById('itemname_'+i).value = '';
                                         document.getElementById('unit_'+i).innerHTML = '';
                                         document.getElementById('tolerances_'+i).value = '';
					document.getElementById('total_stock_'+i).value='';
					document.getElementById('itemdesc_'+i).value = '';	
					document.getElementById('price_'+i).value = '';
					document.getElementById('mrpper_'+i).value = '';
				}
			}
		}
	}
//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
}
	

/* function addBatch(obj,id)
{
	
	var idk=id.split('_');
	if(idk[1]==undefined)
	{

		
		var thisRow = $(obj).closest( 'tr' )[0];
        $( thisRow ).clone().insertAfter( thisRow ).find( 'input:text' );
        $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});

        var bilqty=$(obj).closest('tr').find('input[id=qtyasperbill]').val();
		var shortqty=document.getElementById('shortDirect').value;
		if(bilqty!='')
		{
			var total=parseFloat(bilqty)+parseFloat(shortqty);
			document.getElementById('shortDirect').value=total.toFixed(2);
		}

		var recqty2=$(obj).closest('tr').find('input[id=reciveqty2]').val();
		var shortqty1=document.getElementById('short1Direct').value;
		if(recqty2!='')
		{
			var total=parseFloat(recqty2)+parseFloat(shortqty1);
			document.getElementById('short1Direct').value=total.toFixed(2);
		}

		$(obj).closest('tr').find('input[id=mfg]').attr('id','mfg_1');
    	$(obj).closest('tr').find('input[id=expiry]').attr('id','expiry_1');
    	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
  

	}
	else
	{
		var thisRow = $(obj).closest( 'tr' )[0];
        $( thisRow ).clone().insertAfter( thisRow ).find( 'input:text' );
        $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});

        var bilqty=$(obj).closest('tr').find('input[id=qtyasperbill_'+idk[1]+']').val();
       var shortqty=document.getElementById('shortDirect').value;
        if(bilqty!='')
		{
			var total=parseFloat(bilqty)+parseFloat(shortqty);
			document.getElementById('shortDirect').value=total.toFixed(2);
		}

		var recqty2=$(obj).closest('tr').find('input[id=reciveqty2_'+idk[1]+']').val();
		var shortqty1=document.getElementById('short1Direct').value;
		if(recqty2!='')
		{
			var total=parseFloat(recqty2)+parseFloat(shortqty1);
			document.getElementById('short1Direct').value=total.toFixed(2);
		}

		var k=parseInt(idk[1])+parseInt(1);
		
       	$(obj).closest('tr').find('input[id=mfg_'+idk[1]+']').attr('id','mfg_'+k);
       	$(obj).closest('tr').find('input[id=expiry_'+idk[1]+']').attr('id','expiry_'+k);
       	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	}        
} */


function addBatch(obj,id)
{
	var idk=id.split('_');
	if(idk[1]==undefined)
	{

		
		var thisRow = $(obj).closest( 'tr' )[0];
        $( thisRow ).clone().insertBefore( thisRow ).find( 'input:text' );
        $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});


   /*------------- ----------------- Code for hide PO Quantity on click of Add Button Starts Here ------------------------------------------- */
           $(obj).closest('tr').find('input[id=itemcode]').hide();
           $(obj).closest('tr').find('input[id=itemname]').hide();
           $(obj).closest('tr').find('input[id=poqty]').hide().val('0');
           $(obj).closest('tr').find('input[id=batchNo]').val('');
           $(obj).closest('tr').find('input[id=mfg]').val('');
           $(obj).closest('tr').find('input[id=expiry]').val('');
           $(obj).closest('tr').find('input[id=qtyasperbill]').val('');
           $(obj).closest('tr').find('input[id=reciveqty]').val('');
           $(obj).closest('tr').find('input[id=reciveqty2]').val('');
           $(obj).closest('tr').find('input[id=minSign]').val('');
           $(obj).closest('tr').find('input[id=shortaccessid]').val('');

  /*------------- ----------------- Code for hide PO Quantity on click of Add Button Ends Here ---------------------------------------------- */

        var bilqty=$(obj).closest('tr').find('input[id=qtyasperbill]').val();
		var shortqty=document.getElementById('shortDirect').value;
		if(bilqty!='')
		{
			var total=parseFloat(bilqty)+parseFloat(shortqty);
			document.getElementById('shortDirect').value=total.toFixed(2);
		}

		var recqty2=$(obj).closest('tr').find('input[id=reciveqty2]').val();
		var shortqty1=document.getElementById('short1Direct').value;
		if(recqty2!='')
		{
			var total=parseFloat(recqty2)+parseFloat(shortqty1);
			document.getElementById('short1Direct').value=total.toFixed(2);
		}

		$(obj).closest('tr').find('input[id=mfg]').attr('id','mfg_1');
    	$(obj).closest('tr').find('input[id=expiry]').attr('id','expiry_1');
    	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
  

	}
	else
	{
		var thisRow = $(obj).closest( 'tr' )[0];
        $( thisRow ).clone().insertBefore( thisRow ).find( 'input:text' );


        $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});

   /*------------- ----------------- Code for hide PO Quantity on click of Add Button Starts Here ------------------------------------------- */
          
           $(obj).closest('tr').find('input[id=add_'+idk[1]+']').hide();
           $(obj).closest('tr').find('input[id=itemcode_'+idk[1]+']').hide();
           $(obj).closest('tr').find('input[id=itemname_'+idk[1]+']').hide();
           $(obj).closest('tr').find('input[id=poqty_'+idk[1]+']').hide().val('');
           $(obj).closest('tr').find('input[id=batchNo_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=mfg_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=expiry_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=qtyasperbill_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=reciveqty_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=reciveqty2_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=minSign_'+idk[1]+']').val('');
           $(obj).closest('tr').find('input[id=shortaccessid_'+idk[1]+']').val('');

  /*------------- ----------------- Code for hide PO Quantity on click of Add Button Ends Here ------------------------------------------- */

        var bilqty=$(obj).closest('tr').find('input[id=qtyasperbill_'+idk[1]+']').val();
       var shortqty=document.getElementById('shortDirect').value;
        if(bilqty!='')
		{
			var total=parseFloat(bilqty)+parseFloat(shortqty);
			document.getElementById('shortDirect').value=total.toFixed(2);
		}

		var recqty2=$(obj).closest('tr').find('input[id=reciveqty2_'+idk[1]+']').val();
		var shortqty1=document.getElementById('short1Direct').value;
		if(recqty2!='')
		{
			var total=parseFloat(recqty2)+parseFloat(shortqty1);
			document.getElementById('short1Direct').value=total.toFixed(2);
		}

		var k=parseInt(idk[1])+parseInt(1);
		
       	$(obj).closest('tr').find('input[id=mfg_'+idk[1]+']').attr('id','mfg_'+k);
       	$(obj).closest('tr').find('input[id=expiry_'+idk[1]+']').attr('id','expiry_'+k);
       	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	}        
}





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


function ChkGRNType(str)
{
	if(str=='PO')
	{
		document.getElementById('Ptype1').style.display = "block";
		document.getElementById('Ptype2').style.display = "block";
		document.getElementById('indentpo_no').disabled = false;
		document.getElementById('indentpo_date').disabled = false;
	}
	else if(str=='Indent')
	{
		document.getElementById('Ptype1').style.display = "none";
		document.getElementById('Ptype2').style.display = "none";
		document.getElementById('indentpo_no').disabled = false;
		document.getElementById('indentpo_date').disabled = false;
	}
	else if(str=='Without PO')
	{
		document.getElementById('Ptype1').style.display = "block";
		document.getElementById('Ptype2').style.display = "block";
		document.getElementById('indentpo_no').disabled = true;
		document.getElementById('indentpo_date').disabled = true;
	}
	else
	{
		document.getElementById('Ptype1').style.display = "none";
		document.getElementById('Ptype2').style.display = "none";
		document.getElementById('indentpo_no').disabled = false;
		document.getElementById('indentpo_date').disabled = false;
	}
}


function GetIndentPONo(str)
{
	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("inprno").innerHTML=xmlhttp.responseText;
	}
	}
	var site=document.getElementById("sitecode").value;
	var receag=document.getElementById("receiviedagaist").value;
	var purtype=document.getElementById("PoType").value;
	xmlhttp.open("GET","ajax_get_indent_po_no.php?supplierId="+str+"&ReciveAng="+receag+"&POType="+purtype+"&Branch="+site,true);
	xmlhttp.send();
}


function GetPODetails(str)
{
	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("alldatadetails").innerHTML=data[0];
		document.getElementById("basicamtdetails").innerHTML=data[1];
	}
	}
	var purtype=document.getElementById("PoType").value;
	xmlhttp.open("GET","ajax_getpodetails.php?POID="+str+"&POType="+purtype,true);
	xmlhttp.send();
}




function check_bill_qty(str,id)
{
	var poqty=parseInt(document.getElementById("pending_qty_"+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("qty_received_"+id).value='';
		document.getElementById("qty_as_per_bill_"+id).focus();
		return false;
	}
	}
}



function check_po_qty1(i)
{
	var poqty=parseInt(document.getElementById("pending_qty_"+i).value);
	var str=parseInt(document.getElementById("qty_received_"+i).value);
	var tolerance = document.getElementById("tolerance_"+i).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 = "QTY Received Cannot Be Greater Than "+tolerance+" % more of PO Quantity";
		alert(altmsg);
		document.getElementById("qty_received_"+i).value='';
		document.getElementById("qty_received_"+i).focus();
		return false;
	}
	}
}




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

function DiscountAmount(DA,id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var discount_percent = document.getElementById("PerAmo").value;
		var rate = document.getElementById("Rate").value;
		var discount = document.getElementById("Discount").value;
		var quantity = document.getElementById("Quantity").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").value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
		}
		document.getElementById("perc").value=percent.toFixed(2);
		document.getElementById("NetRate").value=subTotal.toFixed(2);
		document.getElementById("basic").value=subTotal.toFixed(2);
	}
	else
	{
		var discount_percent = document.getElementById("PerAmo_"+i).value;
		var rate = document.getElementById("Rate_"+i).value;
		var discount = document.getElementById("Discount_"+i).value;
		var quantity = document.getElementById("Quantity_"+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);
	}
}




function CustomDutyType(val,id)
{
	id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		if(document.getElementById("cuntomDutyFlag").value=='2')
		{
			document.getElementById("CustonDuty").disabled=true; 
			document.getElementById("CustomDutyAmt").disabled=true; 
		}
		else
		{
			document.getElementById("CustonDuty").disabled=false; 
			document.getElementById("CustomDutyAmt").disabled=false; 
		}
	}
	else
	{
		if(document.getElementById("cuntomDutyFlag_"+i).value=='2')
		{
			document.getElementById("CustonDuty_"+i).disabled=true; 
			document.getElementById("CustomDutyAmt_"+i).disabled=true; 
		}
		else
		{
			document.getElementById("CustonDuty_"+i).disabled=false; 
			document.getElementById("CustomDutyAmt_"+i).disabled=false; 
		}
	}
	
}

function cal_grandtotalImp_consolidate(id)
{
		id1=id.split("_");
		i=id1[1];
		
		if(i==undefined)
		{
		var basic=document.getElementById("basic").value;
		
		if(basic==''){basic=0;}
		
		
		var grand_tot1= parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
			
		document.getElementById("TotalSpecialamt").value=grand_tot;
		}
		else
		{
		var basic=document.getElementById("basic_"+i).value;
		
		if(basic==''){basic=0;}
		
		
		var grand_tot1=parseFloat(basic);
		
		var grand_tot=grand_tot1.toFixed(2);
		document.getElementById("TotalSpecialamt_"+i).value=grand_tot;
		
		
		}
}



function cal_grandtotalImp(id)
{
		id1=id.split("_");
		i=id1[1];
		if(i==undefined)
		{
		var basic=document.getElementById("basic").value;
		var Totaltaxable=document.getElementById("CustomDutyAmt").value;
		var Totaltaxable1=document.getElementById("TotalSpecial").value;
		var Totaltaxable2=document.getElementById("customecess").value;
		var Totaltaxable3=document.getElementById("customsececess").value;
		var Totaltaxable4=document.getElementById("adduty").value;
		if(basic==''){basic=0;}
		if(Totaltaxable1==''){Totaltaxable1=0;}
		if(Totaltaxable2==''){Totaltaxable2=0;}
		if(Totaltaxable3==''){Totaltaxable3=0;}
		if(Totaltaxable4==''){Totaltaxable4=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable)+parseFloat(Totaltaxable1)
		+parseFloat(Totaltaxable2)+parseFloat(Totaltaxable3)+parseFloat(Totaltaxable4);
		var grand_tot=grand_tot1.toFixed(2);
		
		
		
		document.getElementById("TotalSpecialamt").value=grand_tot;
		}
		else
		{
		var basic=document.getElementById("basic_"+i).value;
		var Totaltaxable=document.getElementById("CustomDutyAmt_"+i).value;
		var Totaltaxable1=document.getElementById("TotalSpecial_"+i).value;
		var Totaltaxable2=document.getElementById("customecess_"+i).value;
		var Totaltaxable3=document.getElementById("customsececess_"+i).value;
		var Totaltaxable4=document.getElementById("adduty_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable1==''){Totaltaxable1=0;}
		if(Totaltaxable2==''){Totaltaxable2=0;}
		if(Totaltaxable3==''){Totaltaxable3=0;}
		if(Totaltaxable4==''){Totaltaxable4=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable)+parseFloat(Totaltaxable1)
		+parseFloat(Totaltaxable2)+parseFloat(Totaltaxable3)+parseFloat(Totaltaxable4);
		var grand_tot=grand_tot1.toFixed(2);
		
		
		document.getElementById("TotalSpecialamt_"+i).value=grand_tot;
		
		
		}
}



//function cal_grandtotalImp(id)
//{
//	
//	id1=id.split("_");
//	i=id1[1];
//	if(i==undefined)
//	{
//		var type_of_bill=document.getElementById("cuntomDuty_Flag").value;
//		var basic=document.getElementById("basic").value;
//		var Totaltaxable=document.getElementById("CustomDutyAmt").value;
//		if(basic==''){basic=0;}
//		if(Totaltaxable==''){Totaltaxable=0;}
//		if(document.getElementById("cuntomDuty_Flag").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_tot;
//	}
//	else
//	{
//		var type_of_bill=document.getElementById("cuntomDuty_Flag_"+i).value;
//		var basic=document.getElementById("basic_"+i).value;
//		var Totaltaxable=document.getElementById("CustomDutyAmt_"+i).value;
//		if(basic==''){basic=0;}
//		if(Totaltaxable==''){Totaltaxable=0;}
//		if(document.getElementById("cuntomDuty_Flag_"+i).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_"+i).value=grand_tot;
//	}	
//}



function cal_totalamount()
{   
    if(document.getElementById("NetRate"))
	var firstrow=document.getElementById("NetRate").value;
	if(firstrow==''){firstrow=0;}
	var total=0;
	var t=document.getElementById("hiditemcount").value;
	for(var i=1;i<=t;i++)
	{
	   if(document.getElementById("NetRate_"+i))
	   {
		var amt=parseFloat(document.getElementById("NetRate_"+i).value);
		total=parseFloat(total)+amt;	
	   }	
	}
	var fintotal=parseFloat(firstrow)+parseFloat(total);
	document.getElementById("total_item_amount").value=fintotal.toFixed(2);	
	
	
var hdcnt=document.getElementById("hiditemcount").value;
	var flag=0;
	var flag1=0;
	if(document.getElementById("cuntomDutyFlag"))
	{
	if(document.getElementById("cuntomDutyFlag").value==1)
	{
		flag=1;
	}
	}
	if(hdcnt!='')
	{
		for(var j=1;j<=hdcnt;j++)
		{ 
		    if(document.getElementById("cuntomDutyFlag_"+j))
			{
			if(document.getElementById("cuntomDutyFlag_"+j).value==1)
			{
				flag1=1;
			}
			}
		}
	}	
	if(flag==1 || flag1==1)
	{
		document.getElementById("CustomDuty").disabled=true;
	}
	else
	{
		document.getElementById("CustomDuty").disabled=false;
	}

}


function CalculateCustomDuty(id,val)
{
var id1=id.split("_");
	var i=id1[1];
	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("__");
		var k=data[0];
		if(i==undefined)
		{
			document.getElementById("CustomDutyAmt").value=data[1];
		}
		else
		{
			document.getElementById("CustomDutyAmt_"+i).value=data[1];
		}
	}
	}
	
	if(i==undefined)
	{
		var basicamt=document.getElementById("basic").value;
	}
	else
	{
		var basicamt=document.getElementById("basic_"+i).value;
	}
	xmlhttp.open("GET","ajax_get_cutom_duty.php?ids="+id+"&vls="+val+"&bamt="+basicamt,true);
	xmlhttp.send();
}


function claculateExcisetotal(id,str)
{  
		var b=document.getElementById("total_item_amount").value;	 
	 
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
				var data=xmlhttp.responseText.split("__"); 
			 	document.getElementById("rateval").value=data[0];
				document.getElementById("custondutyval").value=data[1];
    		}
  		}
		xmlhttp.open("GET","ajax_calculate_customduty.php?quotTaxId="+str+"&data="+b,true);
		xmlhttp.send();


}


function claculateExcise(id,val)
{
	
	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("__");
		var k=data[0];
		if(data[0]=='')
		{
			document.getElementById("exciseValue").value=data[1];
		}
		else
		{
			document.getElementById("exciseValue_"+k).value=data[1];
		}
	}
	}
	var id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		var basicamt=document.getElementById("basic").value;
	}
	else
	{
		var basicamt=document.getElementById("basic_"+i).value;
	}
	xmlhttp.open("GET","ajax_getexcisevalue.php?ids="+id+"&vls="+val+"&bamt="+basicamt,true);
	xmlhttp.send();
}

function cal_totalamountwithduty()
{
	var hdcnt=document.getElementById("hiditemcount").value;
	var chka=document.getElementById("CustomDuty").value;
	if(chka==0)
	{
		var total=0;
		amtone=parseFloat(document.getElementById("CustomDutyAmt").value);
		for(var j=1;j<=hdcnt;j++)
		{
			if(document.getElementById("CustomDutyAmt_"+j).value!='')
			{
				var amt=parseFloat(document.getElementById("CustomDutyAmt_"+j).value);
				total=parseFloat(total)+amt;	
			}
			else
			{
				total=0;
			}
		}
		total=total+amtone;
		document.getElementById("custondutyval").value=total.toFixed(2);		
	}
	else
	{
		var basic=document.getElementById("total_item_amount").value;
		var rate=document.getElementById("rateval").value;
		if(basic==''){basic=0;}
		var calexc=(basic*rate)/100;
		document.getElementById("custondutyval").value=calexc.toFixed(2);	
		
	}
}





function calsuroctamtipm(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("insurancecharges_amt").value=amount.toFixed(2);	
}

function reversecalsuroctamt(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
 var amount=(100*str)/amt;
 document.getElementById("insurancecharges").value=amount.toFixed(2);	
}
 
function caloverfreight(str)

{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("overseasfrieght_amt").value=amount.toFixed(2);	
}

function reversecaloverfreight(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value);  
var amount=(100*str)/amt;
document.getElementById("overseasfrieght").value=amount.toFixed(2);	
}

function callocalfreight(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("localfreight_amt").value=amount.toFixed(2);	
}

function reversecallocalfreight(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var per=parseFloat(document.getElementById("localfreight").value); 
var amount=(100*str)/amt;
 document.getElementById("localfreight").value=amount.toFixed(2);	
}


function calclearingforwarding(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("calclearingforwarding_amt").value=amount.toFixed(2);	
}

function reversecalclearingforwarding(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var per=parseFloat(document.getElementById("clearingforwarding").value); 
var amount=(100*str)/amt;
 document.getElementById("clearingforwarding").value=amount.toFixed(2);	
}

function caldetetioncharges(str)
{
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var amount=(amt*str)/100;
document.getElementById("detetioncharges_amt").value=amount.toFixed(2);	
}

function reversecaldetetioncharges(str)
{ 
var amt=parseFloat(document.getElementById("total_item_amount").value); 
var per=parseFloat(document.getElementById("detetioncharges").value); 
var amount=(100*str)/amt;
 document.getElementById("detetioncharges").value=amount.toFixed(2);	
}




function cal_grandamountimp()
{
	
	var total=document.getElementById("total_item_amount").value;
	var cdis_amt=document.getElementById("custondutyval").value;
	var insurancecharges_amt=document.getElementById("insurancecharges_amt").value;
	var overseasfrieght_amt=document.getElementById("overseasfrieght_amt").value;
	var localfreight_amt=document.getElementById("localfreight_amt").value;
	var calclearingforwarding_amt=document.getElementById("calclearingforwarding_amt").value;	
	var detetioncharges_amt=document.getElementById("detetioncharges_amt").value;	
	var othercharges=document.getElementById("othercharges").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;}
	 
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(cdis_amt)+parseFloat(insurancecharges_amt)+parseFloat(overseasfrieght_amt)+parseFloat(localfreight_amt)+parseFloat(calclearingforwarding_amt)+parseFloat(detetioncharges_amt)+parseFloat(othercharges);
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	

}



function checkCustomtype(id)
{
	id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		if(document.getElementById("cuntomDutyFlag").value=='')
		{
			alert("please Select The Custom Duty Flag First !");
			return false;
		}
	}
	else
	{
		if(document.getElementById("cuntomDutyFlag_"+i).value=='')
		{
			alert("please Select The Custom Duty Flag First !");
			return false;
		}
	}
}

<!--------------------------------------------INPORT ORDER CALCULATION PART---------------------------------------------------------------------->




<!--------------------------------------------DOMESTIC ORDER CALCULATION PART---------------------------------------------------------------------->


function checkExcisable(str,id)
{
	id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
	if(str=='NonExcisable')
	{
		document.getElementById("exciseDuty").disabled=true;
		document.getElementById("exciseValue").disabled=true;
		document.getElementById("cessID1").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("cessID2").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxableamt").disabled=true;
		
		
		document.getElementById("exciseDuty").value='0';
		document.getElementById("exciseValue").value='';
		document.getElementById("cessID1").value='';
		document.getElementById("ECessValue").value='';
		document.getElementById("cessID2").value='';
		document.getElementById("SAHCessValue").value='';
		document.getElementById("taxableamt").value='';
   document.getElementById("TotalSpecialamt_"+i).value=document.getElementById("basic_"+i).value; 
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty").disabled=false;
		document.getElementById("exciseValue").disabled=false;
		document.getElementById("cessID1").disabled=false;
		document.getElementById("ECessValue").disabled=false;
		document.getElementById("cessID2").disabled=false;
		document.getElementById("SAHCessValue").disabled=false;
		document.getElementById("taxableamt").disabled=false;
	}
	else
	{
		document.getElementById("exciseDuty").disabled=true;
		document.getElementById("exciseValue").disabled=true;
		document.getElementById("cessID1").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("cessID2").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxableamt").disabled=true;
		
		
		document.getElementById("exciseDuty").value='0';
		document.getElementById("exciseValue").value='';
		document.getElementById("cessID1").value='';
		document.getElementById("ECessValue").value='';
		document.getElementById("cessID2").value='';
		document.getElementById("SAHCessValue").value='';
		document.getElementById("taxableamt").value='';
	}
	document.getElementById("hidbillingtype").value=str;
	}
	else
	{
	if(str=='NonExcisable')
	{
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("cessID1_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("cessID2_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		
		
		document.getElementById("exciseDuty_"+i).value='0';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cessID1_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cessID2_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
    document.getElementById("TotalSpecialamt_"+i).value=document.getElementById("basic_"+i).value;
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("cessID1_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("cessID2_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxable_amt_"+i).disabled=false;	
	}
	else
	{
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("cessID1_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("cessID2_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		
		
		document.getElementById("exciseDuty_"+i).value='0';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("cessID1_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("cessID2_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
	}
	document.getElementById("hidbillingtype_"+i).value=str;
	}
	
}



function claculateExcisetotal(id,str)
{  
		var b=document.getElementById("total_item_amount").value;	 
	 
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
				var data=xmlhttp.responseText.split("__"); 
			 	document.getElementById("rateval").value=data[0];
				document.getElementById("custondutyval").value=data[1];
    		}
  		}
		xmlhttp.open("GET","ajax_calculate_customduty.php?quotTaxId="+str+"&data="+b,true);
		xmlhttp.send();


}


function checkexiseflag(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		if(document.getElementById("hidbillingtype").value=='')
		{
		alert("Select Tax Type");
		document.getElementById("hidbillingtype").focus();
		}	
	}
	else
	{
		if(document.getElementById("hidbillingtype_"+i).value=='')
		{
		alert("Select Tax Type");
		document.getElementById("hid_billing_type_"+i).focus();
		}	

	}
}


function calEcessonchange(id,val)
{
	
	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("__");
		var k=data[0];
		if(data[0]=='')
		{
			document.getElementById("ECessValue").value=data[1];
		}
		else
		{
			document.getElementById("ECessValue_"+k).value=data[1];
		}
	}
	}
	var id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","ajax_ecesscalculation.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}



function calSHEcessonchange(id,val)
{
	
	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("__");
		var k=data[0];
		if(data[0]=='')
		{
			document.getElementById("SAHCessValue").value=data[1];
		}
		else
		{
			document.getElementById("SAHCessValue_"+k).value=data[1];
		}
	}
	}
	var id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","ajax_ecesscalculation.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}

function calculateTaxable(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var exciseValue=document.getElementById("exciseValue").value;
		var ECessValue=document.getElementById("ECessValue").value;
		var SAHCessValue=document.getElementById("SAHCessValue").value;
		
		if(exciseValue==''){exciseValue=0;}
		if(ECessValue==''){ECessValue=0;}
		if(SAHCessValue==''){SAHCessValue=0;}
		var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
		document.getElementById("taxableamt").value=TOTAL.toFixed(2);
	}
	else
	{
		var exciseValue=document.getElementById("exciseValue_"+i).value;
		var ECessValue=document.getElementById("ECessValue_"+i).value;
		var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
		
		if(exciseValue==''){exciseValue=0;}
		if(ECessValue==''){ECessValue=0;}
		if(SAHCessValue==''){SAHCessValue=0;}
		var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
		document.getElementById("taxableamt_"+i).value=TOTAL.toFixed(2);

	}
}

function cal_grandtotal(id)
{
	id1=id.split("_");
	i=id1[1];
	
	if(i==undefined)
	{
		var type_of_bill=document.getElementById("hidbillingtype").value;
		var basic=document.getElementById("basic").value;
		
		if(document.getElementById("taxableamt"))
		var Totaltaxable=document.getElementById("taxableamt").value;
		
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		if(document.getElementById("hidbillingtype").value=='NonExcisable')
		{
		var grand_tot1=parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
		}	
		else if(document.getElementById("hidbillingtype").value=='IncludeTax'){
		var grand_tot1= parseFloat(basic) ;
		var grand_tot=grand_tot1.toFixed(2);
		}
		else
		{
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
		var grand_tot=grand_tot1.toFixed(2);
		}
		
		
		document.getElementById("TotalSpecialamt").value=grand_tot;
	}
	else
	{
		var type_of_bill=document.getElementById("hidbillingtype_"+i).value;
		var basic=document.getElementById("basic_"+i).value;
		if(document.getElementById("taxableamt_"+i))
		var Totaltaxable=document.getElementById("taxableamt_"+i).value;
		if(basic==''){basic=0;}
		if(Totaltaxable==''){Totaltaxable=0;}
		if(document.getElementById("hidbillingtype_"+i).value=='NonExcisable')
		{
		var grand_tot1=parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
		}	
		else if(document.getElementById("hidbillingtype_"+i).value=='IncludeTax'){
		var grand_tot1= parseFloat(basic) ;
		var grand_tot=grand_tot1.toFixed(2);
		}
		else
		{
		var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
		var grand_tot=grand_tot1.toFixed(2);
		}
		document.getElementById("TotalSpecialamt_"+i).value=grand_tot;
	}	
}



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

function getpoType(str)
{
    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("gt1").innerHTML=data[0];
        document.getElementById("gt11").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","get_po_type.php?venID="+str,true);
	xmlhttp.send();
}

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=parseFloat(document.getElementById("taxvalue").value);
var	suroctper=parseFloat(document.getElementById("sur_oct_per").value);
var amount=(amt*suroctper)/100;
document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}


function cal_grandamount()
{
	
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
	document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}

function GetOrderType(str)
{

  if(str=='0')
   {
     document.getElementById("DutyType").disabled='';
  // document.getElementById("divordertype").innerHTML='';
  // document.getElementById("basicamtdetails").innerHTML='';
   }
 
 
  else if(str=='IO')
   {
   document.getElementById("DutyType").disabled='';
   //document.getElementById("divordertype").innerHTML='';
  // document.getElementById("basicamtdetails").innerHTML='';
   }
   else
   {
   document.getElementById("DutyType").disabled='disabled';
	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("divordertype").innerHTML=data[0];
		document.getElementById("basicamtdetails").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","ajax_grn_order_type_direct.php?OrderType="+str,true);
	xmlhttp.send();
	}
}


<!--------------------------------------------DOMESTIC ORDER CALCULATION PART---------------------------------------------------------------------->

function calculateTotalPrice(id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		Quantity=document.getElementById("Quantity").value;
		Rate= document.getElementById("Rate").value;
		if(Quantity==''){Quantity=0;}
		if(Rate==''){Rate=0;}
		var Total=Quantity*Rate;
		document.getElementById("totalValue").value=Total.toFixed(2);
	}
	else
	{
		Quantity=document.getElementById("Quantity_"+i).value;
		Rate= document.getElementById("Rate_"+i).value;
		if(Quantity==''){Quantity=0;}
		if(Rate==''){Rate=0;}
		var Total=Quantity*Rate;
		document.getElementById("totalValue_"+i).value=Total.toFixed(2);
	}
}
function calculate_poshort(id)
{	//alert(id);
        id1=id.split("_");
	i=id1[1];
        if(i==undefined){
	var qty_per_bill=parseInt(document.getElementById("qtyasperbill").value);
	var reciveqty=parseInt(document.getElementById("Quantity").value);	
	if(document.getElementById("Quantity").value=='')
	{
	var reciveqty=0;	
	}
	else
	{
	var reciveqty=parseInt(document.getElementById("Quantity").value);	
	}
	var short_accessid=qty_per_bill-reciveqty;
	if(short_accessid<0){short_accessid=0;}
        
        alert(short_accessid);
	document.getElementById("shortqty").value=short_accessid;
        }else{
        var qty_per_bill=parseInt(document.getElementById("qtyasperbill_"+i).value);
	var reciveqty=parseInt(document.getElementById("Quantity_"+i).value);	
	if(document.getElementById("Quantity_"+i).value=='')
	{
	var reciveqty=0;	
	}
	else
	{
	var reciveqty=parseInt(document.getElementById("Quantity_"+i).value);	
	}
	var short_accessid=qty_per_bill-reciveqty;
	if(short_accessid<0){short_accessid=0;}
	document.getElementById("shortqty_"+i).value=short_accessid;
        }
}

</script>

<?php 

$sql=DB_query("select * from addmrn where id='".$_REQUEST['mrnid']."'",$db);
$row=DB_fetch_array($sql);
extract($row);


?>


<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">	
<h1>Goods Receipt Note</h1>
<form action="" method="post" onsubmit="return validation()">
    <div id="gt11" ></div>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%" align="right">Branch <font color="#FF0000">*</font></td>
    <td width="20%"><?php $SQLSite=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' 
    and loccode in ('".$_SESSION['AssignedBranch']."')",$db); ?>
     <select name="sitecode" id="sitecode" onChange="GetStore(this.value)">
     <option value="000">Select Branch</option>
      <?php while($site_row=DB_fetch_array($SQLSite)){?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($site==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
      <?php } ?>
    </select></td>
    <td width="13%" align="right">GRN No.</td>
    <td width="20%"><input type="text" value="<?php echo $MRNNo; ?>" name="MRNNo" readonly="true"></td>
    <td width="13%" align="right">GRN Date</td>
    <td><input type="text" name="MRNdate" value="<?php echo ConvertSQLDate($MRNDate); ?>" id="MRNdate" readonly class="datepicker"></td>
  </tr>
  <tr class="row1">
    <td align="right">Store <font color="#FF0000">*</font></td>
    <td><select id="storecode" name="storecode" onFocus="check_po()">
			<option value="">Select Store</option> 
                    <?php $sql_store =DB_query("select id, StoreName from storetype where Store_Site IN('".$_SESSION['AssignedBranch']."') 
                    and CompanyId='".$_SESSION['ACGCompanyId']."' order by StoreCode ASC",$db);?>
<?php while($Storedetail=DB_fetch_array($sql_store))
{
$st='';
if($Storedetail['id']==$StoreCode)
$st="selected";
	?>
<option value="<?php echo $Storedetail['id']; ?>" <?php echo $st; ?>><?php echo $Storedetail['StoreName']; ?></option>
<?php }?> 
		</select></td>
    <td align="right">Recevied Against <font color="#FF0000">*</font></td>
    <td><select name="receiviedagaist" id="receiviedagaist" onChange="ChkGRNType(this.value)">
		<option value="Without PO" <?php if($ReceivedAgainst=='Without PO'){ echo "selected";} ?>>Without PO</option>
		<option value="Stock Transfer" <?php if($ReceivedAgainst=='Stock Transfer'){ echo "selected";} ?>>Stock Transfer</option>
    </select></td>
    <td align="right">Received From <font color="#FF0000">*</font></td>
    <td><select name="vendor" id="vendor"  onchange="getpoType(this.value)">
			<option value="" >Select</option>
			<?php $sql="select id  ,vendor_code, vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'  order by vendor_name";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			$p='';
			if($ReceivedFrom==$myrow['id'])
			$p="selected";
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo  str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
		</select></td>
  </tr>
  <tr class="row1"> 
    <td align="right">PO Type</td>
    <td id="gt1"><select name='PoType' id='PoType' ><!-- onChange="GetOrderType(this.value)" -->
		<option value="0">Select</option>
		<option value='IO' <?php if($Type=='IO') { ?> selected <?php } ?>>Import Order</option>
		<option value='DO' <?php if($Type=='DO') { ?> selected <?php } ?>>Domestic Order</option>
		   </select></td>
    <td align="right">PO Category</td>
    <td><select name='Pocategory' id='Pocategory' >
      <option value="0">Select</option>
      <option value='AT' <?php if($Po_category=='AT') { ?> selected <?php } ?>>Asset</option>
      <option value='MT' <?php if($Po_category=='MT') { ?> selected <?php } ?>>Material</option>
      <option value='SV' <?php if($Po_category=='SV') { ?> selected <?php } ?>>Service</option>
    </select></td>
    <td></td>
    <td><!--<select name="DutyType" id="DutyType" onChange="grnDisabled1(this.value)">
     
        <option value="Itemwise">Itemwise</option>
        <option value="Consolidated">Consolidated</option>       
      </select>--></td>
  </tr>
  <tr class="row1">
    <td align="right">Document Type</td>
    <td><select name="DocumentType" id="DocumentType">
	<option value="Challan" <?php if($DocumentType=='Challan') { ?> selected <?php } ?>>Challan</option>
	<option value="Bill" <?php if($DocumentType=='Bill') { ?> selected <?php } ?>>Bill</option>
	</select></td>
    <td align="right">Document No.</td>
    <td><input name="billno" type="text" id="billno" value="<?php  echo $BillNo; ?>" /></td>
    <td align="right">Challan / Bill Date</td>
    <td><input type="text" name="MRNVoucherDate" readonly="" class="datepicker"  onblur="valdate();"  
    	value="<?php echo ConvertSQLDate($MRNVoucherDate); ?>"/></td>
  </tr>
  <tr class="row1">
    <td align="right">Gate Entry No. <font color="#FF0000">*</font></td>
    <td><input type="text" name="gatepassno"  id="gatepassno"  value="<?php echo $GetPassNo; ?>" onkeyup="checkgatentyno(this.value)"; />
	<div id="entrycheck1"><input type="hidden" name="entrycheck" id="entrycheck"  value="<?php echo $entrycheck; ?>" /></div></td>
    <td align="right">Gate Entry Date <font color="#FF0000">*</font></td>
    <td><input type="text" name="gatepassdate" readonly="" id="gatepassdate" class="datepicker" 
    	value="<?php echo ConvertSQLDate($gatepassdate); ?>" /></td>
    <td align="right">Vehicle No.</td>
    <td><input name="vehicalno" type="text" id="vehicalno" value="<?php echo $VehicleNo; ?>"/></td>
  </tr>
  <tr class="row1">
    <td align="right">Receiving Time</td>
    <td><select name="timein" id="timein" style="width:49%;float:left;">
	<option value="Day" <?php echo $TimeIn=='Day'?'selected':''?>>Day</option>
	<option value="Night" <?php echo $TimeIn=='Night'?'selected':''?>>Night</option>
	</select><input type="text" name="timeout" value="<?php echo $Timeout;?>" style="width:49%;float:left;"></td>
    <td align="right">L R No.</td>
    <td><input name="lrno" type="text" id="lrno"  value="<?php echo $LRno; ?>"/></td>
    <td align="right">L R Date</td>
    <td><input name="lrdate" type="text" id="lrdate" readonly="" 
    	value="<?php echo ConvertSQLDate($LRdate); ?>"  onblur="LRdate();" class="datepicker"/></td>
  </tr>
    <tr class="row1">
    <td align="right">Form Type</td>
    <td><input type="text" name="form_type" id="form_type"  value="<?php echo $form_type; ?>" /></td>
    <td align="right">Form No.</td>
    <td><input type="text" name="form_no" id="form_no"  value="<?php echo $form_no; ?>"  /></td>
    <td align="right">Transporter Name</td>
    <td><input name="transport" type="text" value="<?php  echo $Transp_name;?>" /></td>
  </tr>
    <tr class="row1">
    <td align="right">Remarks</td>
    <td colspan="5"><textarea name="RemarksIfAny"  id="RemarksIfAny" ><?php echo $RemarksIfAny;?></textarea></td>
  </tr>
</table>

<p align="left"><!--<input type="button" onClick="addRow('dataTable')" value="Add More" class="search" />--> <input type="button" name="profile_popup" value="Pick Items" id="rofile_popup" class="search" /> <input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" /></p>

<h3>Items Details</h3>

<div id="divordertype">
<table width='100%' cellpadding='3' cellspacing='0' border='0' class="thborder">
	<tr>
	<th width="4%">S. No.</th>
    <th width="1"></th>
    <th width="10%">Item Code</th>
	<th>Item Name</th>
    <th width="6%">Qty.</th>
    <th width="7%">Batch No.</th>
    <th width="6%" >Date of Mfg.</th>
    <th width="6%">Date of Exp.</th>
    <th width="6%">Bill Qty.</th>
    <th style='text-align:center;' colspan='5'>Rec. Qty.</th>
    <th colspan='2' style='text-align:center;'>Short / Excess Qty.</th>
    <th width="1"></th> 
    <th width="6%">MRP</th>
    <!-- <td colspan=''>Amount</td> -->
 </tr>
<tbody id="dataTable">
<?php 
	$j=1;
	$sql_details=DB_query("select * from addmrnqty where issue_id='".$id."' order by id",$db);
	while($row1=DB_fetch_array($sql_details))
	{
		$itemname=$s->getField('item_master','id',$row1['mst_itemid'],'item_name');	
		$Stockid=$s->getField('item_master','id',$row1['mst_itemid'],'StockID');	
		$unit=$s->getField('item_master','id',$row1['mst_itemid'],'mst_unitid');
		$unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');	
		$confac=$s->getField('item_master','id',$row1['mst_itemid'],'conv_factor');	
	?>
<tr>
<td ><input type="checkbox" id="delitem[]"  /><?php if($row1['POQty']!='0.0000') { ?><input type="button" value="+" id='add_<?php echo $j; ?>' onclick="javascript:addBatch(this,this.id);"><?php } ?></td>
<td ><input type="hidden" name="mst_itemid[]" id="itemid_<?php echo $j; ?>" value="<?php echo $row1['mst_itemid'];?>" /><input type="hidden" name="tolerances[]" id="tolerances_<?php echo $j; ?>" /></td>
<td><?php if($row1['POQty']!='0.0000') { ?><input type='text' name='itemcode[]' id='itemcode_<?php echo $j; ?>'  readonly='' value="<?php echo $Stockid; ?>" /><?php } else { ?><input type='hidden' name='itemcode[]' id='itemcode_<?php echo $j; ?>'  readonly='' value="<?php echo $Stockid; ?>" /><?php } ?></td>
<td><?php if($row1['POQty']!='0.0000') { ?><input type='text' name='itemname[]' id='itemname_<?php echo $j; ?>'  readonly='' value="<?php echo $itemname; ?>" /> <?php } else { ?><input type='hidden' name='itemname[]' id='itemname_<?php echo $j; ?>'  readonly='' value="<?php echo $itemname; ?>" /> <?php } ?></td>
<td><?php if($row1['POQty']!='0.0000') { ?><input type='text' name='poqty[]' autocomplete='off' onkeypress="return isNumberKey(event)" id='poqty_<?php echo $j;?>'  value='<?php echo $row1['POQty']; ?>' ><?php } else { ?><input type='hidden' name='poqty[]' autocomplete='off' onkeypress="return isNumberKey(event)" id='poqty_<?php echo $j;?>'  value='<?php echo $row1['POQty']; ?>' ><?php }?></td>
<td><input type='text' name='batchNo[]' id='batchNo_<?php echo $j; ?>'   size='8'  value="<?php echo $row1['batch_no']; ?>" /></td>
<td ><input type="text" name="mfg[]" id="mfg_<?php echo $j; ?>" class="datepicker" value="<?php echo ConvertSQLDate($row1['mfg']); ?>" readonly="" ></td>
<td ><input type="text" name="expiry[]" id="expiry_<?php echo $j; ?>"  class="datepicker" readonly="" value="<?php echo ConvertSQLDate($row1['expiry']); ?>" ></td>
<td><input name='qtyasperbill[]' type='text' id='qtyasperbill_<?php echo $j; ?>' value="<?php echo $row1['qty_as_per_bill']; ?>" onkeypress="return isNumberKey(event)" autocomplete='off' onkeyup='calTotalQty1Direct(this.value,this.id,this);' size='8'/></td>
<td width="5%"><input name='reciveqty[]' type='text' id='reciveqty_<?php echo $j; ?>' value="<?php echo $row1['reciveqty']; ?>" onkeypress="return isNumberKey(event)" autocomplete='off' onkeyup='calTotalQty1Direct(this.value,this.id,this);'  size='8' /></td>
<td width="5%"><select name='unit[]' id='unit_<?php echo $j; ?>' ><?php
		 $sql_unit=DB_query("select * from unitsofmeasure where unitid='".$row1['mst_unitid']."'",$db);
         while($unit_data=DB_fetch_array($sql_unit))
         {?>
         	<option value='<?php echo $unit_data['unitid']; ?>'><?php echo $unit_data['unitname']; ?></option>
        <?php 
     	 } ?>
	</select>
</td>
<td width="1"><input name='conv_fac[]' type='hidden' id='convfac_<?php echo $j; ?>' value="<?php echo $row1['conv_fac'];?>" autocomplete='off'   size='8' /></td>
<td width="5%"><input name='reciveqty2[]' type='text' id='reciveqty2_<?php echo $j ?>' readonly autocomplete='off'   size='8' value="<?php echo $row1['stock_qty2'];?>"/></td>
<td width="5%"><select name='unit2[]' id='unit2_<?php echo $j; ?>'>
		<?php
		 $sql_unit=DB_query("select * from unitsofmeasure where unitid='".$row1['mst_sec_unitid']."'",$db);
         while($unit_data=DB_fetch_array($sql_unit))
         {?>
         	<option value='<?php echo $unit_data['unitid']; ?>'><?php echo $unit_data['unitname']; ?></option>
        <?php 
     	 } ?>
	</select></td>
<td width="3%"><input type='text' name='minSign[]' readonly="" id='minSign_<?php echo $j ?>' value="<?php echo $row1['minSign']; ?>" style="text-align:center;" /></td>
<td width="5%"><input name='shortaccessid[]' readonly="" type='text' id='shortaccessid_<?php echo $j; ?>'  value='<?php echo $row1['short_accessid']; ?>'  readonly='true' onfocus='calculate_poshort();'/></td>
<!--<td><input autocomplete='off' style="width:100%"  type='text' name='rate[]' id='rate_<?php //echo $j ?>' onkeyup="changeAmount(this.id,this.value,this)" onkeypress="return isNumberKey(event)" value="<?php //echo $row1['rate']; ?>" /></td>
<td><input autocomplete='off' style="width:100%" value="<?php //echo $row1['amount']; ?>" type='text' name='amount[]' id='amount_<?php //echo $j ?>' readonly="" /></td>-->
<td><input id='confac1' type='hidden'></td>
<td><input name='mrprate[]' type='text' id='mrprate_<?php echo $j ?>'  value="<?php echo $row1['mrprate']; ?>"  /></td>
</tr>
			
	<?php 
	$j++;}
?>
</tbody>
		 <tr>
			<td colspan='8' style='text-align:right;'><strong>Total Quantity</strong></td>
			<td><input name='totalBillQty' type='text' id='shortDirect' readonly="" value="<?php echo $totalBillQty;  ?>" size='8' /></td>
			<td><input name='totalRecQty' readonly="" value="<?php echo $totalRecQty; ?>" type='text' id='short1Direct'  size='8' /></td>
			<td colspan='8'></td>
			</tr>
		  </table>

<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $j; ?>" />
<input type="hidden" name="" value="<?php echo $j; ?>" id="edit_cnt" />
<input type="hidden" name="" value="<?php echo $j; ?>" id="rowcount1" />
	 

<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
	<td>&nbsp;</td>
	<td width="40%">
	<div id="basicamtdetails">
			<!--<table width="100%" border="0" cellspacing="0" cellpadding="3">
            <tr class="row1">
            	<td class="tabledata1"><strong>Basic Amount </strong> </td>
                <td><input name='basic_amt' id='total_item_amount' style='width:150px;' readonly onfocus='cal_totalamount()' ></td>
           </tr>
<tr class="row1">
				<td class="tabledata1"><strong>Custom Duty</strong></td>
				<td><select name="CustomDuty" id="CustomDuty" style="width:150px;" onChange="claculateExcisetotal(this.id,this.value)">
						<option value="0">Select</option>
						<?php $ServiceSql="select * from  custom_duty" ;
						$ServiceRes=DB_query($ServiceSql,$db);
						while($ServiceRow=DB_fetch_array($ServiceRes)){?>
						<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
						<?php } ?>
				   </select><br />
					<input name="custondutyval" id="custondutyval" 
					type="text"  style="width:150px;" onFocus="cal_totalamountwithduty()" />
					<input type="hidden" id="rateval" />
				</td>
			</tr>
      		<tr class="row1">
				<td class="tabledata1"><strong>Insurance charges</strong> </td>
                  <td><input type="text" name="insurancecharges" id="insurancecharges" style="width:50px;"   onblur="calsuroctamtipm(this.value)"/>
				  <input name="insurancecharges_amt" type="text"  onkeyup="reversecalsuroctamt(this.value);" id="insurancecharges_amt" style="width:100px;" /></td>
           </tr>
           <tr class="row1">
				<td class="tabledata1"><strong>Overseas Freight</strong> </td>
                <td><input type="text" name="overseasfrieght" id="overseasfrieght" style="width:50px;" onBlur="caloverfreight(this.value)"/><input name="overseasfrieght_amt" type="text" onkeyup="reversecaloverfreight(this.value);" id="overseasfrieght_amt" style="width:100px;" /></td>
          </tr>
			<tr class="row1">
				<td class="tabledata1"><strong>Local Freight</strong> </td>
                <td><input type="text" name="localfreight" id="localfreight" style="width:50px;" onBlur="callocalfreight(this.value)"/>
				<input name="localfreight_amt" type="text"  onkeyup="reversecallocalfreight(this.value);"  id="localfreight_amt"  style="width:100px;" /></td>
           </tr>
           <tr class="row1">
				<td class="tabledata1"><strong>Clearing & Forwarding</strong> </td>
                <td><input type="text" name="clearingforwarding" id="clearingforwarding" style="width:50px;" onBlur="calclearingforwarding(this.value)"/>
				<input name="calclearingforwarding_amt" type="text" onkeyup="reversecalclearingforwarding(this.value);" id="calclearingforwarding_amt" style="width:100px;" /></td>
          </tr>
			<tr class="row1">
				<td class="tabledata1"><strong>Detetion Charges</strong> </td>
                 <td><input type="text" name="detetioncharges" id="detetioncharges"  style="width:50px;" onBlur="caldetetioncharges(this.value)"/>
				 <input name="detetioncharges_amt" type="text" onkeyup="reversecaldetetioncharges(this.value);"   id="detetioncharges_amt" style="width:100px;" /></td>
           </tr>
			<tr class="row1">
				<td class="tabledata1"><strong>Other charges</strong></td>
                <td><input type="text" name="othercharges" id="othercharges"  style="width:150px;"/></td>
            </tr>		
            <tr class="row1">
				<td class="tabledata1"><strong>Grand Total</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" onFocus="cal_grandamountimp()"  style="width:150px;"/></td>
              </tr>
          </table>-->
		</div>
	</td>
</tr>
</table>
<p align="center" style="text-align:center;">
	<input type="submit" name="save" value="Save" class="search" onClick="return confirmPost()" />
    <input type="submit" name="reset" value="Reset" class="search" />&nbsp;<a href="index.php?route=Inventory/transation/material_receipt_note_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" class="search" value="Cancel" name="Back" /></a>
	</p>
</form>
</div>
</div>
<script>
function changeAmount(id,rate,obj)
{
	var brk=id.split("_");
    
	if(brk[1]=='' || brk[1]==undefined)
	{
		  var recqty = $(obj).closest('tr').find('input[id=reciveqty]').val();
		 
          if(recqty!='')
		  {
		  	var amount=parseFloat(recqty)*parseFloat(rate);
		  
		  	$(obj).closest('tr').find('input[id=amount]').val(amount.toFixed(2));
		  }
	}
	else
	{
		 var recqty = $(obj).closest('tr').find('input[id=reciveqty_'+brk[1]+']').val();
		
		 if(recqty!='')
		 {
		 	var amount=parseFloat(recqty)*parseFloat(rate);
		  	$(obj).closest('tr').find('input[id=amount_'+brk[1]+']').val(amount.toFixed(2));
		  
		  }
	}
}
function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       } 
function showconvac(str,id)
{
	
var brk=id.split('_');


if(str=='0')
{

	if(brk[1]==undefined)
	{
	var conf=document.getElementById('confac1').value;
	document.getElementById("convfac").value=conf;
	 var id1="reciveqty";
	var hrdvalue=document.getElementById(id1).value;
	calTotalQty1Direct(hrdvalue,id1);
	}
	else
	{
	var conf=document.getElementById('confac1_'+brk[1]).value;
	document.getElementById("convfac_"+brk[1]).value=conf;
	 var id1="reciveqty_"+brk[1];
	var hrdvalue=document.getElementById(id1).value;
	calTotalQty1Direct(hrdvalue,id1);
	}

   
}
else
{
var brk=id.split('_');

 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)
	{
	if(brk[1]==undefined)
	{
	document.getElementById("convfac").value=xmlhttp.responseText;
	var id1="reciveqty";
	var hrdvalue=document.getElementById(id1).value;
	
	calTotalQty1Direct(hrdvalue,id1);
    }
	else
	{
	document.getElementById("convfac_"+brk[1]).value=xmlhttp.responseText;
	var id1="reciveqty_"+brk[1];
	var hrdvalue=document.getElementById(id1).value;
	
	calTotalQty1Direct(hrdvalue,id1);
     }
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}

	if(brk[1]==undefined)
	{
	var str2=document.getElementById("itemid").value;
	}
	else
	{
	var str2=document.getElementById("itemid_"+brk[1]).value;
	}
	xmlhttp.open("GET","convactor.php?site="+str+"&itemid="+str2,true);
	xmlhttp.send();

}




}

function calcAmt(strs,id)
{
     var totalamt=0;
     var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{   
   if(document.getElementById("Rate_"+i))     
   var str=document.getElementById("Rate_"+i).value;
   if(str==''){ str=0;}
    if(document.getElementById("poqty_"+i))  
    var qty=document.getElementById("poqty_"+i).value;
    if(qty==''){ qty=0;}
    var finalaAmt=parseFloat(qty)*parseFloat(str);
    
    document.getElementById("totalValue_"+i).value=finalaAmt.toFixed(2);
    document.getElementById("basic_"+i).value=finalaAmt.toFixed(2);
    
    
    var countcharges = document.getElementById("hiditemcount").value;
                for(var j=1;j<=countcharges;j++)
                {
                var qtyBill1 = document.getElementById("basic_"+j).value;
                if(qtyBill1==''){qtyBill1=0;}
                        var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
                }
                var firstRow=document.getElementById("basic").value;
                if(firstRow==''){ firstRow=0;}
                
                var totalamt=parseFloat(totalamt)+parseFloat(firstRow);
                document.getElementById("total_item_amount").value=totalamt.toFixed(2);
       }
       else
           {
               var totalamt=0;
                 if(document.getElementById("poqty"))  
                var qty=document.getElementById("poqty").value;
                if(qty==''){ qty=0;}
                 if(document.getElementById("Rate"))  
                 var str=document.getElementById("Rate").value;
                 if(str==''){ str=0;}
                var finalaAmt=parseFloat(qty)*parseFloat(str);

                document.getElementById("totalValue").value=finalaAmt.toFixed(2);
                document.getElementById("basic").value=finalaAmt.toFixed(2);
                
                var countcharges = document.getElementById("hiditemcount").value;
                for(var j=1;j<=countcharges;j++)
                {
                var qtyBill1 = document.getElementById("basic_"+j).value;
                if(qtyBill1==''){qtyBill1=0;}
                var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
                }
                var firstRow=document.getElementById("basic").value;
                if(firstRow==''){ firstRow=0;}                
                var totalamt=parseFloat(totalamt)+parseFloat(firstRow);
                document.getElementById("total_item_amount").value=totalamt.toFixed(2);
           }
}


/*function calTotalQty1Direct(val,idd)
{
    id1=idd.split("_");
	id=id1[1];
       //alert(id);
       var totalamt1=0;
        if(id==undefined)
	       {
             var qtyRec = document.getElementById("reciveqty").value;
             var qtyBill = document.getElementById("qtyasperbill").value;
             if(qtyRec==''){qtyRec=0;} 
             var confac=document.getElementById("convfac").value;
             if(confac=='') confac=0;
             var secondaryqty=parseFloat(qtyRec)*parseFloat(confac);
             document.getElementById("reciveqty2").value=secondaryqty.toFixed(2);         
              if(parseFloat(qtyBill)>parseFloat(qtyRec))
                {
                var diff = parseFloat(qtyBill)-parseFloat(qtyRec);
                document.getElementById("shortaccessid").value=diff.toFixed(2);
                //document.getElementById('minSign_'+id).style.display="block";
                document.getElementById('minSign').value="-";               
                }
                if(parseFloat(qtyBill)<=parseFloat(qtyRec))
                { 
                var diff = parseFloat(qtyRec)-parseFloat(qtyBill);
                document.getElementById("shortaccessid").value=diff.toFixed(2);
                //document.getElementById('minSign_'+id).style.display="block";
                document.getElementById('minSign').value="+";
                }
               if(document.getElementById("qtyasperbill"))
               var firstRow= document.getElementById("qtyasperbill").value;
                if(firstRow=='') { firstRow=0; }
                 if(document.getElementById("reciveqty"))
                var firstRow1= document.getElementById("reciveqty").value;
                if(firstRow1=='') { firstRow1=0; }
                var totalamt=0;
                var countcharges = document.getElementById("hiditemcount").value;
               // alert(countcharges);
                for(var i=1;i<=countcharges;i++)
                {
                if(document.getElementById("qtyasperbill_"+i))	
                var qtyBill1 = document.getElementById("qtyasperbill_"+i).value;
                if(document.getElementById("reciveqty_"+i))	
                var qtyRec1 = document.getElementById("reciveqty_"+i).value;                
                if(qtyBill1==''){qtyBill1=0;}
                if(qtyRec1==''){qtyRec1=0;}                
                var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
                var totalamt1=parseFloat(totalamt1)+parseFloat(qtyRec1);
                }
                alert(totalamt);
                var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
                var finalRes1=parseFloat(totalamt1)+parseFloat(firstRow1);
                document.getElementById("shortDirect").value=finalRes.toFixed(2);
                document.getElementById("short1Direct").value=finalRes1.toFixed(2);
               

                var poqty=parseInt(document.getElementById("pending").value);
                var tolerance = document.getElementById("tolerances").value;
                if(tolerance==''){tolerance=0;}
                if(poqty==''){poqty=0;}
                str1=parseInt(val);
                if(str1==''){str1=0;}
                if(tolerance=='')
                {
                        if(parseInt(poqty)<parseInt(str1))
                        {
                        alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
                        document.getElementById("qtyasperbill").focus();
                        document.getElementById("qtyasperbill").value='';
                        return false;
                        }
                }
                else
                {
                var p1 = (tolerance*poqty)/100;
                var p2 = parseFloat(poqty)+parseFloat(p1);
                        if(parseInt(p2)<parseInt(str1))
                        {
                        alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
                        document.getElementById("qtyasperbill").focus();
                        document.getElementById("qtyasperbill").value='';
                        return false;
                        }
                }
        }
        else
            {

            if(document.getElementById("reciveqty_"+id))	
        var qtyRec = document.getElementById("reciveqty_"+id).value;
            if(document.getElementById("qtyasperbill_"+id))	
             var qtyBill = document.getElementById("qtyasperbill_"+id).value;
        if(qtyRec==''){qtyRec=0;}
        if(qtyBill==''){qtyBill=0;}
           if(document.getElementById("convfac_"+id))
          var confac=document.getElementById("convfac_"+id).value;
             if(confac=='') confac=0;
             var secondaryqty=parseFloat(qtyRec)*parseFloat(confac);
             if(document.getElementById("reciveqty2_"+id))
             document.getElementById("reciveqty2_"+id).value=secondaryqty.toFixed(2);

                if(parseFloat(qtyBill)>parseFloat(qtyRec))
                {
                var diff = parseFloat(qtyBill)-parseFloat(qtyRec);
                if(document.getElementById("shortaccessid_"+id))
                document.getElementById("shortaccessid_"+id).value=diff.toFixed(2);
                //document.getElementById('minSign_'+id).style.display="block";
                if(document.getElementById("minSign_"+id))
                document.getElementById('minSign_'+id).value="-";
               
                }
                if(parseFloat(qtyBill)<=parseFloat(qtyRec))
                { 
                var diff = parseFloat(qtyRec)-parseFloat(qtyBill);
                if(document.getElementById("shortaccessid_"+id))
                document.getElementById("shortaccessid_"+id).value=diff.toFixed(2);
                //document.getElementById('minSign_'+id).style.display="block";
                if(document.getElementById("minSign_"+id))
                document.getElementById('minSign_'+id).value="+";
                }
                

                
                //document.getElementById("shortaccessid_"+id).value=diff.toFixed(2);
                if(document.getElementById("qtyasperbill"))
                var firstRow= document.getElementById("qtyasperbill").value;
                else
                var firstRow=0;	
                if(firstRow=='') { firstRow=0; }
                 if(document.getElementById("reciveqty"))
                var firstRow1= document.getElementById("reciveqty").value;
                else 
                var firstRow1=0; 
                if(firstRow1=='') { firstRow1=0; }
                var totalamt=0;
                var countcharges = document.getElementById("hiditemcount").value;
              
                for(var i=1;i<=countcharges;i++)
                {
                if(document.getElementById("qtyasperbill_"+i))	
                var qtyBill1 = document.getElementById("qtyasperbill_"+i).value;
                if(document.getElementById("reciveqty_"+i))
                var qtyRec1 = document.getElementById("reciveqty_"+i).value;
                
                if(qtyBill1==''){qtyBill1=0;}
                if(qtyRec1==''){qtyRec1=0;}
                
                var totalamt=parseFloat(totalamt)+parseFloat(qtyBill1);
                var totalamt1=parseFloat(totalamt1)+parseFloat(qtyRec1);
                }
               
                var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
                var finalRes1=parseFloat(totalamt1)+parseFloat(firstRow1);

                document.getElementById("shortDirect").value=finalRes.toFixed(2);
                document.getElementById("short1Direct").value=finalRes1.toFixed(2);
               

               // var poqty=parseInt(document.getElementById("pending_"+id).value);

        }
}*/
function calculateBillQty(id)
{
	
	var total= 0;
	
	jQuery('input[id^=qtyasperbill]').each(function(){
         var amount = parseFloat(jQuery(this).val());
         if(!isNaN(amount))
         	total+=parseFloat(amount);
    });
   document.getElementById(id).value=total.toFixed(2);
}
function calculateRecQty(id)
{
	
	var total= 0;
	
	jQuery('input[id^=reciveqty]').each(function(){
         var amount = parseFloat(jQuery(this).val());
         if(!isNaN(amount))
         	total+=parseFloat(amount);
    });
   document.getElementById(id).value=total.toFixed(2);
}
function calTotalQty1Direct(val,idd,obj)
{
    id1=idd.split("_");
	id=id1[1];
       //alert(id);
       var totalamt1=0;
        if(id==undefined)
	       {
             //var qtyRec = document.getElementById("reciveqty").value;
             var qtyRec=$(obj).closest('tr').find('input[id=reciveqty]').val();
          		
            // var qtyBill = document.getElementById("qtyasperbill").value;
             var qtyBill=$(obj).closest('tr').find('input[id=qtyasperbill]').val();
          	
			 if(qtyRec==''){qtyRec=0;}
			 var confac=$(obj).closest('tr').find('input[id=convfac]').val();

             if(confac=='') confac=0;
             var secondaryqty=parseFloat(qtyRec)*parseFloat(confac);
             $(obj).closest('tr').find('input[id=reciveqty2]').val(secondaryqty.toFixed(2));

         	 if(parseFloat(qtyBill)>parseFloat(qtyRec))
             {
                var diff = parseFloat(qtyBill)-parseFloat(qtyRec);
                $(obj).closest('tr').find('input[id=shortaccessid]').val(diff.toFixed(2));
                //document.getElementById('minSign_'+id).style.display="block";
                 $(obj).closest('tr').find('input[id=minSign]').val('-');
                
             }
             if(parseFloat(qtyBill)<=parseFloat(qtyRec))
             { 
                var diff = parseFloat(qtyRec)-parseFloat(qtyBill);
                $(obj).closest('tr').find('input[id=shortaccessid]').val(diff.toFixed(2));
                 $(obj).closest('tr').find('input[id=minSign]').val('+');
                
             }
             
             var firstRow=$(obj).closest('tr').find('input[id=qtyasperbill]').val();
             if(firstRow=='') { firstRow=0; }
	           var firstRow1= $(obj).closest('tr').find('input[id=reciveqty]').val();


             if(firstRow1=='') { firstRow1=0; }
             var totalamt=0;
              calculateBillQty('shortDirect');
              calculateRecQty('short1Direct');
            
            
             
              

             
             var poqty=parseInt($(obj).closest('tr').find('input[id=poqty').val());

             var tolerance= $(obj).closest('tr').find('input[id=tolerances').val()
             if(tolerance==''){tolerance=0;}
             if(poqty==''){poqty=0;}
             str1=parseInt(val);
             if(str1==''){str1=0;}
             if(tolerance=='')
             {
                 if(parseInt(poqty)<parseInt(str1))
                 {
                      alert('Bill Quantity Cannot Be Greater Than poqty Quantity');
                      $(obj).closest('tr').find('input[id=qtyasperbill').focus();
                      $(obj).closest('tr').find('input[id=qtyasperbill').val('');
                   	  return false;
                 }
             }
             else
             {
                var p1 = (tolerance*poqty)/100;
                var p2 = parseFloat(poqty)+parseFloat(p1);
                if(parseInt(p2)<parseInt(str1))
                {
                    alert('Bill Quantity Cannot Be Greater Than poqty Quantity');
                    $(obj).closest('tr').find('input[id=qtyasperbill').focus();
                    $(obj).closest('tr').find('input[id=qtyasperbill').val('');
                    return false;
                 }
             }
        }
        else
            {
       				//var qtyRec = document.getElementById("reciveqty").value;
             var qtyRec=$(obj).closest('tr').find('input[id=reciveqty_'+id+"]").val();
          		
            // var qtyBill = document.getElementById("qtyasperbill").value;
             var qtyBill=$(obj).closest('tr').find('input[id=qtyasperbill_'+id+"]").val();
          	
			 if(qtyRec==''){qtyRec=0;}
			 var confac=$(obj).closest('tr').find('input[id=convfac_'+id+"]").val();

             if(confac=='') confac=0;
             var secondaryqty=parseFloat(qtyRec)*parseFloat(confac);
             $(obj).closest('tr').find('input[id=reciveqty2_'+id+"]").val(secondaryqty.toFixed(2));

         	 if(parseFloat(qtyBill)>parseFloat(qtyRec))
             {
                var diff = parseFloat(qtyBill)-parseFloat(qtyRec);
                $(obj).closest('tr').find('input[id=shortaccessid_'+id+"]").val(diff.toFixed(2));
                //document.getElementById('minSign_'+id).style.display="block";
                 $(obj).closest('tr').find('input[id=minSign_'+id+"]").val('-');
                
             }
             if(parseFloat(qtyBill)<=parseFloat(qtyRec))
             { 
                var diff = parseFloat(qtyRec)-parseFloat(qtyBill);
                $(obj).closest('tr').find('input[id=shortaccessid_'+id+"]").val(diff.toFixed(2));
                 $(obj).closest('tr').find('input[id=minSign_'+id+"]").val('+');
                
             }
             
             var firstRow=$(obj).closest('tr').find('input[id=qtyasperbill_'+id+"]").val();
             if(firstRow=='') { firstRow=0; }
	           var firstRow1= $(obj).closest('tr').find('input[id=reciveqty_'+id+"]").val();


             if(firstRow1=='') { firstRow1=0; }
             var totalamt=0;
             //var countcharges =$(obj).closest('tr').find('input[id=hiditemcount_'+id+"]").val();
            calculateBillQty('shortDirect');
              calculateRecQty('short1Direct');
              

             
            // var poqty=parseInt($(obj).closest('tr').find('input[id=poqty_'+id+"]").val());
            var billqty1=parseFloat($(obj).closest('tr').find('input[id=qtyasperbill_'+id+"]").val());

             var tolerance= $(obj).closest('tr').find('input[id=tolerances_'+id+"]").val()
             if(tolerance==''){tolerance=0;}
             if(poqty==''){poqty=0;}
             str1=parseFloat(val);
             if(str1==''){str1=0;}
            // if(tolerance=='')
            // {
                 if(parseFloat(billqty1)<parseFloat(str1))
                 {
                      alert('Receive Quantity Cannot Be Greater Than Bill Quantity');
                      $(obj).closest('tr').find('input[id=reciveqty_'+id+"]").focus();
                      $(obj).closest('tr').find('input[id=reciveqty_'+id+"]").val('');
                   	  return false;
                 }
             //}
             else
             {
                var p1 = (tolerance*poqty)/100;
                var p2 = parseFloat(poqty)+parseFloat(p1);
                if(parseInt(p2)<parseInt(str1))
                {
                    alert('Bill Quantity Cannot Be Greater Than poqty Quantity');
                    $(obj).closest('tr').find('input[id=qtyasperbill_'+id+"]").focus();
                    $(obj).closest('tr').find('input[id=qtyasperbill_'+id+"]").val('');
                    return false;
                 }
             }	

            }
}




function calTotalQtyDirect(val,idd)
{
	alert();
    var totalamt=0;
        id1=idd.split("_");
	id=id1[1];
       //alert(id);
        if(id==undefined)
	{
            var qtyBill = document.getElementById("qtyasperbill").value;

                if(qtyBill==''){qtyBill=0;}
                if(parseFloat(qtyBill)>=parseFloat(val))
                {
                var diff = parseFloat(qtyBill)-parseFloat(val);
                document.getElementById("shortaccessid").value=diff.toFixed(2);
                document.getElementById('minSign').value="";
                //document.getElementById('minSign').style.display="none";
                }
                else
                {
                var diff = parseFloat(val)-parseFloat(qtyBill);
                document.getElementById("shortaccessid").value=diff.toFixed(2);
                document.getElementById('minSign').style.display="block";
                document.getElementById('minSign').value="-";
                }

                var firstRow=document.getElementById("reciveqty").value;
                if(firstRow=='') { firstRow=0; }
                //alert(firstRow);
                var countcharges = document.getElementById("hiditemcount").value;
                for(var i=1;i<countcharges;i++)
                {
                var rec1 = document.getElementById("reciveqty_"+i).value;
                if(rec1==''){rec1=0;}
                        var totalamt=parseFloat(totalamt)+parseFloat(rec1);
                }
                //alert(totalamt);
                var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
                document.getElementById("short1Direct").value=finalRes.toFixed(2);
        }
        else
            {
                var qtyBill = document.getElementById("qtyasperbill_"+id).value;

                if(qtyBill==''){qtyBill=0;}
                if(parseFloat(qtyBill)>=parseFloat(val))
                {
                var diff = parseFloat(qtyBill)-parseFloat(val);
                document.getElementById("shortaccessid_"+id).value=diff.toFixed(2);
                document.getElementById('minSign_'+id).value="";
                //document.getElementById('minSign_'+id).style.display="none";
                }
                else
                {
                var diff = parseFloat(val)-parseFloat(qtyBill);
                document.getElementById("shortaccessid_"+id).value=diff.toFixed(2);
                document.getElementById('minSign_'+id).style.display="block";
                document.getElementById('minSign_'+id).value="-";
                }

                var firstRow=document.getElementById("reciveqty").value;
                if(firstRow=='') { firstRow=0; }
                
                var countcharges = document.getElementById("hiditemcount").value;
                for(var i=1;i<=countcharges;i++)
                {
                var rec1 = document.getElementById("reciveqty_"+i).value;
                if(rec1==''){rec1=0;}
                        var totalamt=parseFloat(totalamt)+parseFloat(rec1);
                }
                var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
                document.getElementById("short1Direct").value=finalRes.toFixed(2);
            }
}  

function calculateTotalPriceNew(id,idd)
{
	
			
                        var totalamt=0;
                        id1=idd.split("_");
                        i=id1[1];
                        if(i==undefined)
	{
             
			Quantity = document.getElementById("poqty").value;
			Rate= document.getElementById("Rate").value;
			disct= document.getElementById("Discount").value;
			perAmount = document.getElementById("PerAmo").value;
			var Total=parseFloat(Quantity*Rate);
			var totalamt=0;
			document.getElementById("totalValue").value=Total.toFixed(2);
			if(disct!=""){
				if(perAmount=='Amount'){
					var finalAmount = parseFloat(Quantity*Rate)-parseFloat(disct);
					document.getElementById("basic").value=finalAmount.toFixed(2);
                                        document.getElementById("perc").value=parseFloat(disct).toFixed(2);
				}else{
					var finalAmount =parseFloat(Quantity*Rate)- parseFloat((Quantity*Rate)*disct/100);
					document.getElementById("basic").value=finalAmount.toFixed(2);
                                        document.getElementById("perc").value=parseFloat((Quantity*Rate)*disct/100).toFixed(2);
				}
			}else{
				document.getElementById("basic").value=Total.toFixed(2);
			}
	
	
			
			var c =document.getElementById("hiditemcount").value;
                        //alert(c);
			for(var l=1;l<=c;l++){
				if(document.getElementById("basic_"+l)!=null){
					if(document.getElementById("basic_"+l).value!='')
						var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}}
                    
                    var firstRow=document.getElementById("basic").value;
                    if(firstRow==''){ firstRow=0;}
			
                        var totalamt=parseFloat(firstRow)+parseFloat(totalamt);
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);
            
            
        }
        else
            {
                        var totalamt=0;
			Quantity = document.getElementById("poqty_"+i).value;
			Rate= document.getElementById("Rate_"+i).value;
			disct= document.getElementById("Discount_"+i).value;
			perAmount = document.getElementById("PerAmo_"+i).value;
			var Total=parseFloat(Quantity*Rate);
			var totalamt=0;
			document.getElementById("totalValue_"+i).value=Total.toFixed(2);
			if(disct!=""){
				if(perAmount=='Amount'){
					var finalAmount = parseFloat(Quantity*Rate)-parseFloat(disct);
					document.getElementById("basic_"+i).value=finalAmount.toFixed(2);
                                        document.getElementById("perc_"+i).value=parseFloat(disct).toFixed(2);
				}else{
					var finalAmount =parseFloat(Quantity*Rate)- parseFloat((Quantity*Rate)*disct/100);
					document.getElementById("basic_"+i).value=finalAmount.toFixed(2);
                                        document.getElementById("perc_"+i).value=parseFloat((Quantity*Rate)*disct/100).toFixed(2);
				}
			}else{
				document.getElementById("basic_"+i).value=Total.toFixed(2);
			}
	
	
			
			var c =document.getElementById("hiditemcount").value;
			for(var l=1;l<=c;l++){
				if(document.getElementById("basic_"+l)!=null){
					if(document.getElementById("basic_"+l).value!='')
						var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}}
                     var firstRow=document.getElementById("basic").value;
                    if(firstRow==''){ firstRow=0;}
			
                        var totalamt=parseFloat(firstRow)+parseFloat(totalamt);			
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);
                        }
                        
}
</script>
