<?php ob_start();
error_reporting(0);
$PageSecurity = 4;
date_default_timezone_set('Asia/Kolkata');
$PageName = 'DispatchReceiptNote';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
?>
<script type="text/javascript" src="js/function-ajax.js" language="javascript"></script>
<?php 

if($_REQUEST['action']=='delete')
{
DB_query("delete from log_dispatchqty where dis_id='".$_REQUEST['mrnid']."' and id='".$_REQUEST['dirid']."'",$db);
DB_query("delete from log_dispatchgrnqty where dis_id='".$_REQUEST['mrnid']."' and parent_id='".$_REQUEST['dirid']."'",$db);
$itmiid=$s->GetFieldValue('log_dispatchqty','id="'.$_REQUEST['dirid'].'"','mst_itemid');
DB_query("update log_addmrnbox set dispatch=0 where dis_id='".$_REQUEST['mrnid']."' and itemid='".$itmiid."'",$db);

echo "<script>location='index.php?route=LOG/transaction/dispatch_note_edit&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&mrnid=".$_REQUEST['mrnid']."'</script>";
}

if($_REQUEST['save'])
{    

		DB_query("delete from log_dispatchqty where dis_id='".$_REQUEST['mrnid']."'",$db);
		DB_query("delete from log_dispatchgrnqty where dis_id='".$_REQUEST['mrnid']."'",$db);
		DB_query("update log_addmrnbox set dispatch=0 where dis_id='".$_REQUEST['mrnid']."'",$db);
		DB_query("update log_addmrnbox set dis_id=0 where dispatch=0",$db);
		
		$updatemrn_sql="UPDATE log_dispatch SET
		dis_date='".FormatDateForSQL1($_REQUEST['dis_date'])."',
		site='".$_REQUEST['site']."',
		store='".$_REQUEST['storecode']."',  
		type='".$_REQUEST['type']."',
		party_id='".$_REQUEST['party_id']."',
		to_site='".$_REQUEST['to_site']."',
		address='".$_REQUEST['address']."',
		contact_per='".$_REQUEST['contact_per']."',
		contact_no='".$_REQUEST['contact_no']."',
		mrn_no='".$_REQUEST['mrn_no']."',
		mrn_date='".FormatDateForSQL1($_REQUEST['mrn_date'])."',
		way_bill_no='".$_REQUEST['way_bill_no']."',
		way_bill_amt='".$_REQUEST['way_bill_amt']."',
		vehicle_no='".$_REQUEST['vehicle_no']."',
		lr_no='".$_REQUEST['lr_no']."',  
		lr_date='".FormatDateForSQL1($_REQUEST['lr_date'])."',
		remarks='".$_REQUEST['remarks']."',  
		modified_by='".$_SESSION['UserID']."',
		modified_date='".date('Y-m-d')."'
		WHERE id='".$_REQUEST['mrnid']."'";
		$updatemrn_res=DB_query($updatemrn_sql,$db);

 	   		
			$countval= count($_REQUEST['itemdataid']);
			for($i=0;$i<$countval;$i++)
			{
				if($_REQUEST['itemdataid'][$i]!='')
				{	
					$data_arr['dis_id']= $_REQUEST['mrnid'];
					$data_arr['mst_itemid']= $_POST['itemdataid'][$i];
					$data_arr['dispatchqty']= $_REQUEST['disqty'][$i];
					$data_arr['dispatchqty1']= $_REQUEST['disqty'][$i];
					$data_arr['store']= $_REQUEST['storecode'];
																
					$insert_mrm=$s->insertRecord('log_dispatchqty', $data_arr);
					$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
					$insertResult1 = DB_query($insert_mrm,$db,$ErrMsg);
					
				   $Lastreq_id1=DB_Last_Insert_ID($db,'log_dispatchqty',$ErrMsg);
				   if($insertResult1==true)
				   { 
				   		$countvalm= count($_REQUEST['ddgrn_'.$i]);
						for($m=0;$m<$countvalm;$m++)
						{
							if($_REQUEST['ddgrn_'.$i][$m]!='')
							{
								$data_arr1['parent_id']= $Lastreq_id1;
								$data_arr1['dis_id']= $_REQUEST['mrnid'];
								$data_arr1['mst_itemid']= $_REQUEST['itemdataid'][$i];
								$data_arr1['dispatchqty']= $_REQUEST['dddqty_'.$i][$m];
								$data_arr1['grn_id']= $_REQUEST['ddgrn_'.$i][$m];
																			
								$insert_mrm1=$s->insertRecord('log_dispatchgrnqty', $data_arr1);
								$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
								$insertResult2 = DB_query($insert_mrm1,$db,$ErrMsg);
							}
						}
						
						$countvalm1= count($_REQUEST['ddgrn1_'.$i]);
						for($m1=0;$m1<$countvalm1;$m1++)
						{
							if($_REQUEST['ddgrn1_'.$i][$m1]!='')
							{
								$data_arr1['parent_id']= $Lastreq_id1;
								$data_arr1['dis_id']= $_REQUEST['mrnid'];
								$data_arr1['mst_itemid']= $_REQUEST['itemdataid'][$i];
								$data_arr1['dispatchqty']= $_REQUEST['dddqty_'.$i][$m1];
								$data_arr1['grn_id']= $_REQUEST['ddgrn_'.$i][$m1];
																			
								$insert_mrm1=$s->insertRecord('log_dispatchgrnqty', $data_arr1);
								$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
								$insertResult2 = DB_query($insert_mrm1,$db,$ErrMsg);
							}
						}	
				   }
			   }
			}
			
			$countval1= $_REQUEST['countrow'];
			for($j=0;$j<$countval1;$j++)
			{
				if($_REQUEST['disboxid'][$j]==1){
					$qry_box="update log_addmrnbox set dispatch='".$_REQUEST['disboxid'][$j]."', dis_id='".$Lastreq_id."'
					  		 where id='".$_REQUEST['box_id'][$j]."'";			
					DB_query($qry_box,$db);
				}
			}
			 
	 $_SESSION['success_msg']="Update Successfully";
		echo "<script>location='index.php?route=LOG/transaction/dispatch_note_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	
	
}

//**************************Modify Section*******************************************************
if(isset($_REQUEST['mrnid']))
{
	    $condition="id='".$_REQUEST['mrnid']."'";
		$GetData=$s->GetRecord('log_dispatch', $condition);
		$GetResultData= DB_query($GetData,$db);
		$GetRowData=DB_fetch_array($GetResultData);
				
		$dis_no=$GetRowData['dis_no'];
		$dis_date=$GetRowData['dis_date'];
		$site=$GetRowData['site'];
		$store=$GetRowData['store'];
		$type=$GetRowData['type'];
	    $party_id=$GetRowData['party_id'];
		$to_site=$GetRowData['to_site'];
		$address=$GetRowData['address'];
		$contact_per=$GetRowData['contact_per'];
		$contact_no=$GetRowData['contact_no'];
		$mrn_no=$GetRowData['mrn_no'];
		$mrn_date=$GetRowData['mrn_date'];
		$way_bill_no=$GetRowData['way_bill_no'];
		$way_bill_amt=$GetRowData['way_bill_amt'];
		$vehicle_no=$GetRowData['vehicle_no'];
		$lr_no=$GetRowData['lr_no'];
		$lr_date=$GetRowData['lr_date'];
		$remarks=$GetRowData['remarks'];
}
?>
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:fixed;
left:280px;
top:200px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<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>Edit Dispatch Note</strong></h1>
<input name="usertype" id="usertype" type="hidden" value="<?php echo $dealertype; ?>" />
 
<h3 >GENERAL DETAILS</h3>
<table width="100%"  border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata1">Location</td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td><?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
     <select name="site" onchange="getreqitemdata(this.value)" id="sitecode" style="width:70px"    >
      <option value="0">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($site==$site_row['loccode']?'selected':'')?>><?php echo $site_row['loccode'];?></option>
      <?php } ?>
    </select></td>
	  <td><div id="txtsite">
	    <?php
	
	$site_sql="Select locationname from locations where loccode ='".$site."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($site))
	{
	?>
	    <input name="sitename" type="text" id="sitename"  value="<?php echo $site_row['locationname'];?>" size="20" readonly="true">
	<?php } else {?>
	<input name="sitename" type="text" id="sitename"  value="<?php echo $sitename;?>" size="20" readonly="true">
	<?php } ?>
	<input type="hidden" name="hidden_site" id="hidden_site" value="<?php echo $_REQUEST['hidden_site'];?>"/></div></td>
	</tr>
	<tr></tr>
	</table>
	</td>
	<td  class="tabledata1">Warehouse</td>
    <td id="storedata">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select id, StoreCode, StoreName from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in ('".$_SESSION['AssignedBranch']."') order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="storecode" name="storecode"  style="width:100%">
		<option value="0">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($store==$myrow['id'])
				$p="selected";
		?>
			<option Value="<?php echo $myrow['id']; ?>" <?php echo $p; ?>><?php echo $myrow['StoreName']; ?></option>
		<?php }
		?>
		</select>		</td>
        <!--<td><div id="txtid"><input type="text" name="storename" id="storename" size="20" readonly="true" value="<?php echo $storename; ?>"></div></td>-->
      </tr>
    </table></td>
    <td class="tabledata1">Dis No.</td>
    <td><input type="text" value="<?php echo $dis_no;?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td  class="tabledata1">DIS Date </td>
    <td><input type="text" value="<?php echo ConvertSQLDate($dis_date);?>" style="width:150px;" name="dis_date" readonly="true" class="datepicker"></td>
  	<td class="tabledata1">Type</td>
    <td><select name="type" id="type"  style="width:150px;">
		<option value="0" <?php if($type=="0"){echo "selected";}?> >---Select---</option>
		<option value="G" <?php if($type=="0"){echo "selected";}?> >---Against GRN---</option>
		</select></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 if($party_id==$party_row['id']){echo "selected";}?>><?php echo $party_row['c_name'];?></option>	
	  <?php 	
	  }
      ?>
    </select></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Site To</td>
    <td ><select name="to_site" id="site_to"  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 if($to_site==$party_row['id']){echo "selected";}?>><?php echo  $myrow['StoreName']; ?></option>
		<?php }
			?>
		</select>
	</td>
	<td class="tabledata1">Site Address</td>
    <td><textarea name="address" id="address"><?php echo $address;?></textarea></td>
	<td class="tabledata1">Contact Person</td>
    <td><input type="text" name="contact_per" id="contact_per"  style="width:150px;" value="<?php echo $contact_per;?>" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Mobile</td>
    <td><input name="contact_no" id="contact_no" type="text" value="<?php echo $contact_no;?>" size="25" style="width:100%;"/></td>
    <td  class="tabledata1">MRN No.</td>
    <td><input type="text" style="width:150px;" name="mrn_no" id="mrn_no" value="<?php echo $mrn_no;?>"></td>
    <td class="tabledata1">MRN Date</td>
    <td><input name="mrn_date" type="text" id="mrn_date" style="width:150px;" value="<?php echo ConvertSQLDate($mrn_date);?>" 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="<?php echo $way_bill_no;?>"/></td>
	<td class="tabledata1">Way Bill Amount</td>
    <td><input name="way_bill_amt" type="text" id="way_bill_amt" style="width:150px;"  value="<?php echo $way_bill_amt;?>"/></td>
	<td class="tabledata1">Vehicle no.</td>
    <td><input name="vehicle_no" type="text" id="vehicle_no" style="width:150px;"  value="<?php echo $vehicle_no;?>"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1">LR no.</td>
    <td><input name="lr_no" type="text" id="lr_no" style="width:150px;"  value="<?php echo $lr_no;?>"/></td>
    <td class="tabledata1">LR Date</td>
    <td><input type="text" name="lr_date" id="lr_date"  style="width:150px;" class="datepicker" value="<?php echo ConvertSQLDate($lr_date);?>" /></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;"><?php echo $remarks;?></textarea></td>
  </tr>
<tr class="row1">
	<td  colspan="6">   
		<hr>
			 <h1 align="center" style="text-align:center;">Dispatch Products</h1>
			<br />
		<div style="overflow:auto; width:950px; margin-left:auto; margin-right:auto; height:auto">
    <div id="itemdata">
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
	  	<tr class="row1">
			<td style="text-align:left;" colspan="9">
				<input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" />&nbsp;
			</td>			 
		</tr>
        <tr>
          <th><strong>S. No.</strong></th>
          <th></th>
          <th><strong>Item Code</strong></th>
          <th><strong>Item Name</strong></th>
          <th><strong>UOM</strong></th>
          <th><strong>Total Avl Qty</strong></th>
		   <th><strong>Dispatch Qty</strong></th>
		    <th><strong>Balance Qty</strong></th>
			<th><strong>GRN No</strong></th>
        </tr>
		<?php 
		$i=0;
		$iiicc='';
		$icc='';
		$sql_edit=DB_query("Select * from log_dispatchqty where dis_id='".$_REQUEST['mrnid']."'",$db);
		while($record_edit=DB_fetch_array($sql_edit))
		{
		
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
			?>
		<tr>	
		<td>
			<a href="index.php?route=LOG/transaction/dispatch_note_edit&action=delete&mrnid=<?php echo $_REQUEST['mrnid']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=delitem&dirid=<?php echo $record_edit['id'];?>"><img src="images/delete.gif" /></a>
		</td>
		<td>
			<input  type="hidden"   readonly=""  id="itemdataid1_<?php echo $i; ?>"  name="itemdataid[]"  value="<?php echo $record_edit['mst_itemid']; ?>" />
		</td>
		<td>
			<?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'StockID'); ?>
		</td>
		<td>
			<?php echo $s->getField('item_master','id',$record_edit['mst_itemid'],'item_name'); ?>
		</td>
		<td>
			<?php $unit= $s->getField('item_master','id',$record_edit['mst_itemid'],'mst_unitid'); ?>
			<?php echo $s->getField('unitsofmeasure','unitid',$unit,'unitname');  ?>       	 
		</td>
		<?php
			$avl_sql = "SELECT SUM(reciveqty) AS rqty FROM log_addmrnqty where mst_itemid='".$record_edit['mst_itemid']."' AND grn_id IN (select id from log_add_mrn where store='".$store."')";
        	$Resulta=DB_query($avl_sql,$db);
	    	$myrowa =DB_fetch_array($Resulta);
			if($myrowa['rqty']==''){$myrowa['rqty']=0;}
		
			$avl_sqlb = "SELECT SUM(dispatchqty) AS dqty FROM log_dispatchqty where mst_itemid='".$record_edit['mst_itemid']."' AND dis_id IN (select id from log_dispatch where store='".$store."')";
        	$Resultb=DB_query($avl_sqlb,$db);
	    	$myrowb =DB_fetch_array($Resultb);
			if($myrowb['dqty']==''){$myrowb['dqty']=0;}
		?>
		<td>
			<input  type="text" name="avaqty[]"  id="avaqty1_<?php echo $i; ?>" size="30"   value="<?php echo $myrowa['rqty']+$record_edit['dispatchqty']-$myrowb['dqty'];	?>"  /></td>
		<td>
			<input  type="text" name="disqty[]"  id="disqty1_<?php echo $i; ?>" size="30"  value="<?php echo $record_edit['dispatchqty'];?>"  onkeyup="checkqty1(this.value,this.id,<?php echo $_REQUEST['mrnid'];?>)"  />
		</td>
		<td>
			<input  type="text" name="penqty[]"  id="penqty1_<?php echo $i; ?>" size="30"   value="<?php echo $myrowa['rqty']-$myrowb['dqty']?>" readonly  />
		</td>
		<td id="grn1_<?php echo $i;?>">
			<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
				<tr>
					<th>GRN Id</th>
					<th>Dis Qty</th>
				</tr> 
				<?php  
				$dm1=0; 
				$avl_sqlb = "SELECT * FROM log_dispatchgrnqty where mst_itemid='".$record_edit['mst_itemid']."' AND dis_id='".$_REQUEST['mrnid']."'";
				$Resultb=DB_query($avl_sqlb,$db);
				while($myrowb =DB_fetch_array($Resultb)){
				?> 
				<tr bgcolor="#FFFFFF">
					<td><input type="text" id="ddgrn_<?php echo $i.$dm1;?>" name="ddgrn_<?php echo $i;?>[]" value="<?php echo $myrowb['grn_id'];?>" readonly="true" />
					<?php $icc.=$myrowb['grn_id'].",".$record_edit['mst_itemid'].":";?>
					</td>
					<td ><input type="text" id="dddqty_<?php echo $i.$dm1;?>" name="dddqty_<?php echo $i;?>[]" value="<?php echo $myrowb['dispatchqty'];?>" readonly="true" /></td>
				</tr>
				<?php  $dm1++;} ?>	
				<tr><td colspan="3"><input type="hidden" id="rowcal1_<?php echo $i;?>" name="rowcal1_<?php echo $i;?>" value="<?php echo $dm1;?>" /></td></tr>
			</table>
		</td>
		</tr>
		<?php $iiicc.=$s->getField('item_master','id',$record_edit['mst_itemid'],'StockID').",";?>
		<?php $i++; } ?>
		<input id="iiicode" value="<?php echo $iiicc;?>" type="hidden" />
		<input name="cherow" id="cherow" value="<?php echo $i;?>" type="hidden" />
		<input name="cherow1" id="cherow1" value="<?php echo $icc;?>" type="hidden" />
        <tbody id="dataTable">
          <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" id="delitem" /></td>
            <td><input  type="hidden"   readonly=""  id="itemdataid"  name="itemdataid[]" /></td>
            <td><input type="text" value="" tabindex=""   id="itemcode" name="itemcode[]"size="20"
			 onkeyup="opendatas1(this.value,this.id)"/>
            </td>
            <td><input type="text" name="desc[]"  id="descriptions" size="25"  value="" readonly/></td>
            <td><input type="text" name="uom[]" id="uom" value="" readonly /> </td>
			<td><input  type="text" name="avaqty[]"  id="avaqty" size="30"   value="" readonly   /></td>
	 		<td><input  type="text" name="disqty[]"  id="disqty" size="30"   value="" onkeyup="checkqty(this.value,this.id)"   /></td>
		  <td><input  type="text" name="penqty[]"  id="penqty" size="30"  value="" readonly /></td>
            <td id="dgrn"><input  type="text" name="grn[]"  id="grn" size="30"   value="" readonly  /></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" />
	</td>
</tr>
</table>
<div align="right">	 		
	<table width="100%">
		<tr>
			<td>
			 
			 <br /><br />
			 <div id="box_block"><!--style="display:none;"-->
			 <hr>
			 <h1 align="center" style="text-align:center;">Dispatch Boxes</h1>
			<br />
			<div align="left">
				<input type="button" onClick="open_box(<?php echo $_REQUEST['mrnid'];?>)" value="Get Boxes" class="search" id="upload_boxes" />
  			 </div>
			<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>Dispatch 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 confirmPost12()" />-->
		<input type="submit" name="save" value="Save"/>
		<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 get_vendor(str)
  {
	var site=document.getElementById("site").value;
	if (site==0)
	{
	alert("Please select a site");
	return;
	}
	if (str==0)
	{
	alert("Please select a warehouse");
	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("grn_no").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_grnblank.php",true);
	xmlhttp.send();
}
 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 contactDetails(str)
{
	if (str.length==0)
  {
  document.getElementById("contactId").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("contactId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showPartyDetails.php?contact="+str,true);
xmlhttp.send();
}



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 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("sitecode").value=='0')
{
alert("Must Select Site Name");
document.getElementById("sitecode").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("party_id").value=='0')
{
alert("Must Select  Party");
document.getElementById("party_id").focus();
return false;
}

return true;
}

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

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

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

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

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


}
}

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



function 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 supplier.");
//		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("grnno").innerHTML=xmlhttp.responseText;
//	}
//	}
//	xmlhttp.open("GET","get_grn.php?sid="+str,true);
//	xmlhttp.send();
//}


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)
	{
	//alert(xmlhttp.responseText);
	document.getElementById("grnno").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_grn.php?sid="+str+"&storid="+storid,true);
	xmlhttp.send();
}

function get_grndetail(str,str1,str2)
{   

	if(str==0){
		alert("Please select atleast one supplier.");
		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("grn_date").value=data[0];
	document.getElementById("document_type").value=data[1];
	document.getElementById("document_no").value=data[2];
	document.getElementById("doc_date").value=data[3];
	document.getElementById("lr_no").value=data[4];
	document.getElementById("lr_date").value=data[5];
	document.getElementById("form_type").value=data[6];
	document.getElementById("form_no").value=data[7];
	document.getElementById("dataTable").innerHTML=data[8];
	document.getElementById("dataTablerows").innerHTML=data[9];
	}
	}
	//xmlhttp.open("GET","get_grndetails.php?grnid="+str+"&sid="+str1,true);
	//xmlhttp.send();
	if(str1=='G'){
	xmlhttp.open("GET","get_grndetails_stn.php?grnid="+str+"&storid="+str2,true);
	xmlhttp.send();
	}else if(str1=='S'){
	xmlhttp.open("GET","get_grndetails_stn1.php?grnid="+str+"&storid="+str2+"&type="+str1,true);
	xmlhttp.send();
	}
	
	
}

function getaddress(str)
{
	if(str==0){
		alert("Please select atleast one Site To.");
		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("address").value=data[0];
	document.getElementById("contact_per").value=data[1];
	document.getElementById("contact_no").value=data[2];
	}
	}
	xmlhttp.open("GET","siteaddress.php?sid="+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];
	//document.getElementById("grnno").innerHTML=data[2];
	
    }
  }
  xmlhttp.open("GET","getsitenamedis.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,strid){
	if(str==''){
		alert("Please enter value in dispatch Quantity.");
		return false;
	}
	var storecode = document.getElementById("storecode").value;
	var st = strid.split("_");
	var i=st[1];
	if(i==undefined){
		var itm = document.getElementById("itemdataid").value;
		var pqty = document.getElementById("avaqty").value;
		if(parseFloat(str)>parseFloat(pqty)){
			alert("Dispatch quantity not more than Available Quantity");
			document.getElementById(strid).value='';
			document.getElementById(strid).focus();
			return false;
		}
		var bqty = parseFloat(pqty)-parseFloat(str);
		document.getElementById("penqty").value=bqty.toFixed(2);
		
		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("dgrn").innerHTML=xmlhttp.responseText;
    		}
  		}
   		xmlhttp.open("GET","log_showgrn.php?dqty="+str+"&store="+storecode+"&itm="+itm+"&ci=0",true);
		xmlhttp.send();	
	}else{
		var itm = document.getElementById("itemdataid_"+i).value;
		var pqty = document.getElementById("avaqty_"+i).value;
		if(parseFloat(str)>parseFloat(pqty)){
			alert("Dispatch quantity not more than Available Quantity");
			document.getElementById(strid).value='';
			document.getElementById(strid).focus();
			return false;
		}
		var bqty = parseFloat(pqty)-parseFloat(str);
		document.getElementById("penqty_"+i).value=bqty.toFixed(2);
		
		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("dgrn_"+i).innerHTML=xmlhttp.responseText;
    		}
  		}
    	xmlhttp.open("GET","log_showgrn.php?dqty="+str+"&store="+storecode+"&itm="+itm+"&ci="+i,true);
		xmlhttp.send();	
	}
 	return true;
}

function opendatas1(str,id)
{
  var hic=document.getElementById("hiditemcount").value;
  var sitecode=document.getElementById("sitecode").value;
  var storecode=document.getElementById("storecode").value;

if(hic!='')
{
	var myhic = new Array();
	for(var g=0;g<=hic;g++)
	{
		if(g==0)
		{
			myhic[g]=document.getElementById("itemcode").value;
		}else{
			myhic[g]=document.getElementById("itemcode_"+g).value;
		}
	}
	if(document.getElementById("iiicode") && document.getElementById("iiicode").value!=''){
		myhic=myhic+","+document.getElementById("iiicode").value;
	}
}else{
	if(document.getElementById("iiicode") && document.getElementById("iiicode").value!=''){
		var myhic = new Array();
		myhic=myhic+","+document.getElementById("iiicode").value;
	}
}	

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

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

function getItemsList1(id,code,shade,netrate,ctr,ava)
{ 
    var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	if(ctr1[1]==undefined)
	{
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	document.getElementById('avaqty').value = ava;
	}
	else
	{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	document.getElementById('avaqty_'+i).value = ava;
	}	
	document.getElementById("lightbox").style.display='none';
	var data= addRow1('dataTable')
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}
function addRow1(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
			var newcell = row.insertCell(i);
			newcell.className='tabledata';
			if(i==8){
				newcell.id='dgrn_'+rowCount;
			}
           	//newcell.style.background='#ffff00';
			
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
			 

				//alert(newcell.childNodes[0].type);
				switch(newcell.childNodes[0].type) {

				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

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

				case "hidden":

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

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

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

				break;

				case "button":

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

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

				break;

				case "checkbox":

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

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	

			}
			
			

		}
		//document.getElementById(countid).innerHTML=rowCount;

	}
	
function open_box(str1)
{
	var sitecode=document.getElementById("sitecode").value;
    var storecode=document.getElementById("storecode").value;
	if(document.getElementById("itemdataid").value=='' && document.getElementById("iiicode").value=='')
	{
		alert("Please fill atleast one item details.");
		return false;
	}
	if(document.getElementById("itemdataid") && document.getElementById("itemdataid").value!=''){
 	var aa = document.getElementById("hiditemcount").value;
	
	if(aa=='')
	{
		aa=0;
	}
	
	
		var ff=0;
		var myval = new Array();
		for(var bb=0;bb<=aa;bb++){
			var cc = document.getElementById("rowcal_"+bb).value;
			for(var dd=0;dd<cc;dd++){
				if(bb==0){
					myval[ff]=document.getElementById("ddgrn_"+bb+dd).value+","+document.getElementById("itemdataid").value+":";
				}else{
					myval[ff]=document.getElementById("ddgrn_"+bb+dd).value+","+document.getElementById("itemdataid_"+bb).value+":";
				}
			ff=parseInt(ff)+1;
			}		
		}
	}
	if(myval==undefined){
		myval=document.getElementById("cherow1").value;
	}else{
		myval=myval+document.getElementById("cherow1").value;
	}

	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("dataTablerows").innerHTML=xmlhttp.responseText;
		}
	  }
	  
	  xmlhttp.open("GET","get_boxdetails1.php?myval="+myval+"&site="+sitecode+"&store="+storecode+"&str1="+str1,true);
	  xmlhttp.send();	
}


function checkqty1(str,strid,disid){
	if(str==''){
		alert("Please enter value in dispatch Quantity.");
		return false;
	}
	var storecode = document.getElementById("storecode").value;
	var st = strid.split("_");
	var i=st[1];
	if(i==undefined){
		var itm = document.getElementById("itemdataid1").value;
		var pqty = document.getElementById("avaqty1").value;
		if(parseFloat(str)>parseFloat(pqty)){
			alert("Dispatch quantity not more than Available Quantity");
			document.getElementById(strid).value='';
			document.getElementById(strid).focus();
			return false;
		}
		var bqty = parseFloat(pqty)-parseFloat(str);
		document.getElementById("penqty1").value=bqty.toFixed(2);
		
		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("dgrn1").innerHTML=xmlhttp.responseText;
    		}
  		}
   		xmlhttp.open("GET","log_showgrn1.php?dqty="+str+"&store="+storecode+"&itm="+itm+"&ci=0&disid="+disid,true);
		xmlhttp.send();	
	}else{
		var itm = document.getElementById("itemdataid1_"+i).value;
		var pqty = document.getElementById("avaqty1_"+i).value;
		if(parseFloat(str)>parseFloat(pqty)){
			alert("Dispatch quantity not more than Available Quantity");
			document.getElementById(strid).value='';
			document.getElementById(strid).focus();
			return false;
		}
		var bqty = parseFloat(pqty)-parseFloat(str);
		document.getElementById("penqty1_"+i).value=bqty.toFixed(2);
		
		var xmlhttp;
		if (window.XMLHttpRequest)
  		{
			// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}else{
			// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
				alert(xmlhttp.responseText);
				document.getElementById("grn1_"+i).innerHTML=xmlhttp.responseText;
    		}
  		}
    	xmlhttp.open("GET","log_showgrn1.php?dqty="+str+"&store="+storecode+"&itm="+itm+"&ci="+i+"&disid="+disid,true);
		xmlhttp.send();	
	}
 	return true;
}

	
</script>