<?php ob_start();
error_reporting(0);
$PageSecurity = 4;
date_default_timezone_set('Asia/Kolkata');
$PageName = 'TransferReceiptNote';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
if(isset($_GET['ModifyOrderNumber']) and $_SESSION[UserType]=='SuperAdmin')
{
	$title = _('Modify Purchase Order') . ' ' . $_GET['ModifyOrderNumber'];
}else{
}

if(isset($_GET['issueid'])  && isset($_GET['issueid']) !='')
{
	$title = _('Update Issue Slip');
}
$dealertype=$s->getField('www_users','id',$_SESSION['UserID'],'Type');
$Prefix_code = "CLD9/PO";
$url_cancel= "index.php?route=Inventory/transaction/transfer_note_index".$rurl;
$url_add= "index.php?route=Inventory/transaction/transfer_note_add".$rurl;
?>
<script type="text/javascript" src="js/function-ajax.js" language="javascript"></script>
<?php 
if(isset($_POST['save']))
{
	$prefixtitle='ATL/'.$_REQUEST['site'].'/SRN';	

	 
   					
	$SQLMax=DB_query("select srn_no as SrnNo from log_srn where site='".$_REQUEST['site']."' order by id DESC limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$num=DB_num_rows($SQLMax);
	if($num>0)
	{
	$explode=explode("/",$MaxQut['SrnNo']);
	$FinMx=$explode[3]+1;
	$FinalCode=$prefixtitle."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$prefixtitle."/".'00001';
	}			
		$data['srn_no'] = $FinalCode; 
		$data['srn_date'] = FormatDateForSQL1($_REQUEST['srn_date']);
		$data['site'] = $_REQUEST['site'];
		$data['store'] = $_REQUEST['storecode'];
		$data['type'] = $_REQUEST['type'];
		$data['party_id'] = $_REQUEST['party_id'];
		$data['from_site'] = $_REQUEST['from_site'];
		$data['address'] = $_REQUEST['address'];
		$data['contact_per'] = $_REQUEST['contact_per'];  
		$data['contact_no'] = $_REQUEST['contact_no'];
		$data['dis_id'] = $_REQUEST['dis_id'];
		$data['ref_no'] = $_REQUEST['ref_no'];
		$data['ref_date'] = FormatDateForSQL1($_REQUEST['ref_date']);
		$data['way_bill_no'] = $_REQUEST['way_bill_no'];
		$data['way_bill_amt'] = $_REQUEST['way_bill_amt'];
		$data['lr_no'] = $_REQUEST['lr_no'];  
		$data['lr_date'] = FormatDateForSQL1($_REQUEST['lr_date']);
		$data['remarks'] = $_REQUEST['remarks'];  
		$data['companyID'] = $_SESSION['ACGCompanyId'];
		$data['created_by']=$_SESSION['UserID'];
		$data['created_date']=date('Y-m-d');
	   	$insertsql=$s->insertRecord('log_srn', $data);
 	   	$insertResult = DB_query($insertsql,$db,$ErrMsg);
	   	$Lastreq_id=DB_Last_Insert_ID($db,'log_srn',$ErrMsg);
 	   	if($insertResult==true)
	   	{ 		
			$countval= count($_REQUEST['mst_itemid']);
			for($i=0;$i<$countval;$i++)
			{
				if($_REQUEST['dispatchqty'][$i]!='')
				{				
					$data_arr['srn_id']= $Lastreq_id;
					$data_arr['dis_id'] = $_REQUEST['dis_id'];
					$data_arr['mst_itemid']= $_POST['mst_itemid'][$i];
					$data_arr['transferqty']= $_REQUEST['dispatchqty'][$i];
					$data_arr['store']= $_REQUEST['storecode'];
																
					$insert_mrm=$s->insertRecord('log_srnqty', $data_arr);
					$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm,$db,$ErrMsg);	
					
			   }
			}
			$countval1= $_REQUEST['countrow'];
			for($j=0;$j<$countval1;$j++)
			{
				if($_REQUEST['disboxid'][$j]==1)
				{				
					$data_arr1['srn_id']= $Lastreq_id;
					$data_arr1['package_no']= $_POST['package_no'][$j];
					$data_arr1['no_of_package']= $_REQUEST['no_of_package'][$j];
					$data_arr1['content']= $_POST['content'][$j];				
					$data_arr1['layout']= $_REQUEST['layout'][$j];
					$data_arr1['itemid']= $_REQUEST['itemid'][$j];
					$data_arr1['itemname']= $s->GetFieldValue('item_master','id="'.$_REQUEST['itemid'][$j].'"','item_name');
					$data_arr1['store'] = $_REQUEST['storecode'];	
					$insert_mrm1=$s->insertRecord('log_srnbox', $data_arr1);
					$ErrMsg1 = _('An error occurred Record for Boxes Not Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm1,$db,$ErrMsg);	
			   }
			}
			
		
			 
	 }
	 $_SESSION['success_msg']="Update Successfully";
		echo "<script>location='index.php?route=LOG/transaction/transfer_note_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form action="" method="post" name="myform" id="myform">
<h1 align="center"><strong>Add Transfer Note</strong></h1>
<input name="usertype" id="usertype" type="hidden" value="<?php echo $dealertype; ?>" />
 
<h3 >GENERAL DETAILS</h3>
<table width="100%"  border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td class="tabledata1">Location </td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td><?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
     <select name="site" onchange="getreqitemdis(this.value)" id="site" style="width:70px"    >
      <option value="0">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($sitecode==$site_row['loccode']?'selected':'')?>><?php echo $site_row['loccode'];?></option>
      <?php } ?>
    </select></td>
	  <td><div id="txtsite">
	    <?php
	
	$site_sql="Select locationname from locations where loccode ='".$sitecode."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($sitecode))
	{
	?>
	    <input name="sitename" type="text" id="sitename"  value="<?php echo $site_row['locationname'];?>" size="20" readonly="true">
	<?php } else {?>
	<input name="sitename" type="text" id="sitename"  value="<?php echo $sitename;?>" size="20" readonly="true">
	<?php } ?>
	<input type="hidden" name="hidden_site" id="hidden_site" value="<?php echo $_REQUEST['hidden_site'];?>"/></div></td>
	</tr>
	<tr></tr>
	</table>	</td>
	<td  class="tabledata1">Warehouse</td>
    <td id="storedata">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select id, StoreCode, StoreName from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in ('".$_SESSION['AssignedBranch']."') order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="store" name="storecode"  style="width:100%">
		<option value="0">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($storecode==$myrow['id'])
				$p="selected";
		?>
			<option Value="<?php echo $myrow['id']; ?>" <?php echo $p; ?>><?php echo $myrow['StoreName']; ?></option>
		<?php }
		?>
		</select>		</td>
        <!--<td><div id="txtid"><input type="text" name="storename" id="storename" size="20" readonly="true" value="<?php echo $storename; ?>"></div></td>-->
      </tr>
    </table></td>
	<td  class="tabledata1">SRN No. </td>
    <td><input type="text" value="Will Be Generated On Saving" style="width:150px;" name="srn_no" readonly="true"></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">SRN Date </td>
    <td><input type="text" value="" style="width:150px;" name="srn_date" readonly="true" class="datepicker"></td>
  	<td class="tabledata1">Party Name</td>
    <td><select name="party_id" id="party_id" style="width:100%;">
		<option value="0">Select Party</option>
      <?php 
      $party=DB_query("Select id,client_code,c_name from clientmaster",$db);
	  while($party_row=DB_fetch_array($party))
	  {?>
	  <option value="<?php echo $party_row['id'];?>"><?php echo $party_row['c_name'];?></option>	
	  <?php 	
	  }
      ?>
    </select>
	</td>
	<td class="tabledata1">From Site</td>
	<td>
	  <select name="from_site" id="from_site"  style="width:150px;" onchange="getaddress(this.value)">
        <option value="0" >---Select---</option>
        <?php
			$sql="select id, StoreCode, StoreName from locations_to";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			?>
        <option  value="<?php echo $myrow['id']; ?>"><?php echo  $myrow['StoreName']; ?></option>
        <?php }
			?>
      </select>
	 </td>
</tr>
<tr class="row1">
    <td class="tabledata1">Site Address</td>
    <td><textarea name="address" id="address"></textarea></td>
	<td class="tabledata1">Contact Person</td>
    <td><input type="text" name="contact_per" id="contact_per"  style="width:150px;" /></td>
	<td class="tabledata1">Mobile</td>
    <td><input name="contact_no" id="contact_no" type="text" value="" size="25" style="width:100%;"/></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">Dispatch No.</td>
    <td id="disval"><input type="text" style="width:150px;" name="dis_id" id="dis_id" readonly="true"></td>
    <td  class="tabledata1">Ref No.</td>
    <td><input type="text" style="width:150px;" name="ref_no" id="ref_no"></td>
    <td class="tabledata1">Ref Date</td>
    <td><input name="ref_date" type="text" id="ref_date" style="width:150px;" value="" readonly="true" class="datepicker" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Way bill No. </td>
    <td><input name="way_bill_no" type="text" id="way_bill_no" style="width:150px;"  value=""/></td>
	<td class="tabledata1">Way Bill Amount</td>
    <td><input name="way_bill_amt" type="text" id="way_bill_amt" style="width:150px;"  value=""/></td>
	<td class="tabledata1">Vehicle no.</td>
    <td><input name="vehicle_no" type="text" id="vehicle_no" style="width:150px;"  value=""/></td>
</tr>
<tr class="row1">
	<td class="tabledata1">L R No.</td>
    <td><input name="lr_no" type="text" id="lr_no" style="width:150px;"  value=""/></td>
	<td class="tabledata1">L R Date</td>
    <td><input name="lr_date" type="text" id="lr_date" style="width:150px;"  value="" class="datepicker"/></td>
	<td class="tabledata1">&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr class="row1">
    <td  class="tabledata1">Remarks If Any</td>
    <td colspan="5"><textarea name="remarks"  id="remarks" style="width:830px;height:50px;"></textarea></td>
  </tr>
<!--<tr class="row1">
	<td style="text-align:left;" colspan="6">
		<input type="button" onClick="open_items()" value="Add Rows" accesskey="A" class="search" />&nbsp;
		<input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" />&nbsp;
	</td>			 
</tr>-->
<tr class="row1">
	<td  colspan="6">   
		<hr>
			 <h1 align="center" style="text-align:center;">Transfer Products</h1>
			 <br />
		<table width="100%" border="1" cellspacing="0" cellpadding="0">
		<tr class="row1">	
		<td class="tabledata1" style="width:40px;"><strong>S. No.</strong></td>
		<td class="tabledata1" style="width:20px;"><strong></strong></td>
		<td class="tabledata1"><strong>CODE </strong></td>
		<td class="tabledata1"><strong>NAME</strong></td>
		<td class="tabledata1"><strong>PART NO.</strong></td>
		<td class="tabledata1"><strong>UOM</strong></td>         
		<td class="tabledata1"><strong>QTY</strong></td>
		<td class="tabledata1"><strong>PENDING</strong></td>
		<td class="tabledata1"><strong>TRANSFER QTY</strong></td>    
		</tr>
		<tbody id='dataTable'></tbody>
		</table>
		</td>
</tr>
</table>
<div align="right">	 		
	<table width="100%">
		<tr>
			<td>
		      
			 
    <tr><td><br /><br />
			 <!--<div align="left">
				<input type="button" onClick="open_box()" value="Upload Boxes Manualy" class="search" id="upload_boxes" />
  			 </div>-->
			 <br /><br />
			 <div id="box_block"><!--style="display:none;"-->
			 <hr>
			 <h1 align="center" style="text-align:center;">Transfer Boxes</h1>
			 <br />
			<div style="height: auto" id="ItemListDiv">
			<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
			  <tr>
				<td class="tabledata1" colspan="3"><h3 style="color:#000000; font-size:16px;"><strong>Transfer Note Boxes Details</strong></h3></td>
				 <td class="tabledata1" colspan="2">&nbsp;</td>
			  </tr>
			  <tr>
			  	<td class="tabledata"><input name="disboxid" type="checkbox"   id="disboxid" onclick="DisBoxData()"/></td>
				<td class="tabledata">S. No.</td>
				<td class="tabledata">Package No.</td>
				<td class="tabledata">No. of Packages</td>
				<td class="tabledata">Content</td>
				<td class="tabledata">Layout</td>
				<td class="tabledata">Item</td>
			  </tr>
			   <tbody id="dataTablerows">
			   </tbody>
			</table>
			<br />
			</div>
			</div>
		</td></tr>
    </table>
		    </td></tr>
			 
		</table>
		
			
		<div align="center">
		<input type="submit" name="save" value="Save" onclick="return confirmPost()" />
		<input type="submit" name="reset" value="Reset" /><a href="index.php?route=LOG/transaction/dispatch_note_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" value="Cancel" name="Back" /></a>
		</div>
</form>
<script language="javascript" type="text/javascript">
function claculateExcise(i,str)
  {
	var discounted=document.getElementById("basic_"+i).value;
	if (str.length==0)
	{
	document.getElementById("exciseId_"+i).innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("exciseId_"+i).innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?mrnTaxId="+str+"&data="+i,true);
	xmlhttp.send();
}


function calculateExciseDuty(i)
{

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




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




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



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


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

	
}





function cal_totalamount_data()
{	

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

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



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

function calcPackaging(str)
{

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





function DiscountAmount(DA,i)
{


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



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

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


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

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

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


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

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

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

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

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


function open_items()
{
 var type=document.getElementById("store").value;
 window.open("mrn_items_for_logistic.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&type="+type,"item_popup_window","height=500,width=800,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

//function open_box()
//{
// window.open("mrn_boxes_for_logistic.php?action=add&modid=<?php //echo $_REQUEST['modid'];?>&frmid=<?php //echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=800,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
//}

function open_box()
{
 	if(document.getElementById("box_block").style.display=='none'){
		document.getElementById("box_block").style.display='block';
	}
}



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



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





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

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

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

}

function showsitename158(str)
{

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

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

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

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

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

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

}

}

function confirmPost()
{
if(document.getElementById("site").value=='0')
{
alert("Must Select Site Name");
document.getElementById("site").focus();
return false;
}
if(document.getElementById("storecode").value=='0' || document.getElementById("storecode").value=='000')
{
alert("Must Select Warehouse Name");
document.getElementById("storecode").focus();
return false;
}
if(document.getElementById("type").value=='0')
{
alert("Must Select Type");
document.getElementById("type").focus();
return false;
}
if(document.getElementById("grn_no").value=='0')
{
alert("Must Select  GRN No.");
document.getElementById("grn_no").focus();
return false;
}
if(document.getElementById("to_site").value=='0')
{
alert("Must Select To Site Name");
document.getElementById("to_site").focus();
return false;
}
if(document.getElementById("to_storecode").value=='0' || document.getElementById("to_storecode").value=='000')
{
alert("Must Select To Warehouse Name");
document.getElementById("to_storecode").focus();
return false;
}
var cou=document.getElementById("edit_cnt").value;
for(var i=1;i<=cou;i++)
{	
	if(document.getElementById("dispatchqty_"+i)){
		if(document.getElementById("dispatchqty_"+i).value=='')
		{
			alert("Please Fill Transfer Qty of All item.");
			return false;
		}	
	}
}
return true;
}

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

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

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

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

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


}
}

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



function deleteRowOrder(tableID) 
{
	try 
	{
	var table = document.getElementById(tableID);
	//alert(table);
	var rowCount = table.rows.length;
	//alert(rowCount);
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = row.cells[0].childNodes[0];
	if(null != chkbox && true == chkbox.checked) 
	{
	if(rowCount <= 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 getgrn(str)
{
	if(str==0){
		alert("Please select atleast one against type.");
		return;
	}
	var storid = document.getElementById("storecode").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("grnno").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_grn_stn1.php?sid="+str+"&storid="+storid,true);
	xmlhttp.send();
}

function getdisitem(str)
{
	if(str==0){
		alert("Please select atleast one Dispatch No..");
		return;
	}

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

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

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

}

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

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

}


function DisBoxData()
{	
	var t=document.getElementById("countrow").value;
	if(document.getElementById('disboxid').checked==true)
	{	
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('disboxid_'+i).checked=true;	
	}	
	}
	else
	{
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('disboxid_'+i).checked=false;	
	}
	}
}
function checkqty(str,strval){
	if(strval==''){
		alert("Please enter value in transfer Quantity.");
		return false;
	}
	var pqty = document.getElementById("pendingqty_"+str).value;
	if(parseFloat(strval)>parseFloat(pqty)){
		alert("Transfer quantity not more than pending Quantity");
		document.getElementById("dispatchqty_"+str).value="";
		document.getElementById("dispatchqty_"+str).focus();
		return false;
	}
 	return true;
}
function getaddress(str)
{
	var pid=document.getElementById("party_id").value;
	if(str==0){
		alert("Please select atleast one From Site.");
		return;
	}
	var warehou=document.getElementById("storecode").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data = xmlhttp.responseText.split("__");
	document.getElementById("address").value=data[0];
	document.getElementById("contact_per").value=data[1];
	document.getElementById("contact_no").value=data[2];
	document.getElementById("disval").innerHTML=data[3];
	}
	}
	xmlhttp.open("GET","siteaddress.php?sid="+str+"&cc=1&pid="+pid+"&warehou="+warehou,true);
	xmlhttp.send();
}
</script>