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

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

	 
   					
	$SQLMax=DB_query("select grn_no as QutNo from log_add_mrn order by id DESC limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$num=DB_num_rows($SQLMax);
	if($num>0)
	{
	$explode=explode("/",$MaxQut['QutNo']);
	$FinMx=$explode[2]+1;
	$FinalCode=$prefixtitle."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$prefixtitle."/".'00001';
	}			
	
		
		$data['grn_no'] = $FinalCode; 
		$data['grn_date'] = FormatDateForSQL($_REQUEST['grn_date']);
		$data['store'] = $_REQUEST['store'];
		$data['ptype'] = $_REQUEST['ptype'];  
		$data['vendor'] = $_REQUEST['vendor'];
		$data['vendor_address'] = $_REQUEST['vendor_address'];    
		$data['document_type'] = $_REQUEST['document_type'];  
		$data['document_no'] = $_REQUEST['document_no'];
		$data['doc_date'] = FormatDateForSQL1($_REQUEST['doc_date']);
		$data['gate_entry_no'] = $_REQUEST['gate_entry_no']; 
		$data['gate_entry_date']=FormatDateForSQL1($_REQUEST['gate_entry_date']);
		$data['vehicle_no'] = $_REQUEST['vehicle_no']; 
		$data['boe_no'] = $_REQUEST['boe_no']; 
		$data['lr_no'] = $_REQUEST['lr_no'];  
		$data['lr_date'] = FormatDateForSQL1($_REQUEST['lr_date']);
		$data['way_bill_no'] = $_REQUEST['way_bill_no'];
		$data['way_bill_amt'] = $_REQUEST['way_bill_amt'];
		$data['form_no'] = $_REQUEST['form_no'];
		$data['form_type'] = $_REQUEST['form_type']; 
		$data['package_srno'] = $_REQUEST['package_srno'];
		$data['receive_time'] = $_REQUEST['receive_time'];
		$data['pod_receive_date'] = FormatDateForSQL1($_REQUEST['pod_receive_date']);
		$data['pod_head_over_date'] = FormatDateForSQL1($_REQUEST['pod_head_over_date']);
		$data['remarks'] = $_REQUEST['remarks'];  
		$data['total_amt'] = $_REQUEST['total_item_amount'];
		$data['pkg_per'] = $_REQUEST['pkg_perc'];
		$data['pkg_amt'] = $_REQUEST['pkg_charges'];
		$data['excise_id'] = $_REQUEST['EDBillRate'];
		$data['excise_amt'] = $_REQUEST['totalDiscountedPrice'];
		$data['ecess_per'] = $_REQUEST['ECessPercentage'];
		$data['ecess_amt'] = $_REQUEST['ECessValue1'];
		$data['sah_per'] = $_REQUEST['SAHCessPercentage'];
		$data['sah_amt'] = $_REQUEST['SAHCessValue1'];
		$data['total_excise_amt'] = $_REQUEST['total_excise_amount'];		
		$data['vat_cst'] = $_REQUEST['vat_cst'];
		$data['vat_cst_amt'] = $_REQUEST['taxvalue'];
		$data['sur_per'] = $_REQUEST['sur_oct_per'];	
		$data['sur_amt'] = $_REQUEST['sur_oct_amt'];
		$data['freight'] = $_REQUEST['tot_freight'];
		$data['additional_charge'] = $_REQUEST['add_charges'];
		$data['grand_total'] = $_REQUEST['grandtotal'];
		$data['companyID'] = $_SESSION['ACGCompanyId'];
		$data['created_by']=$_SESSION['UserID'];
		$data['created_date']=date('Y-m-d');
	   $insertsql=$s->insertRecord('log_add_mrn', $data);
 	   $insertResult = DB_query($insertsql,$db,$ErrMsg);
	   $Lastreq_id=DB_Last_Insert_ID($db,'log_add_mrn',$ErrMsg);
 	   if($insertResult==true)
	   { 		
			$countval= count($_REQUEST['mst_itemid']);
			for($i=0;$i<$countval;$i++)
			{
				if($_REQUEST['reciveqty'][$i]!='')
				{				
					$data_arr['grn_id']= $Lastreq_id;
					$data_arr['mst_itemid']= $_POST['mst_itemid'][$i];
					$data_arr['reciveqty']= $_REQUEST['reciveqty'][$i];
					$data_arr['rate']= $_POST['itemrate'][$i];				
					$data_arr['total_price']= $_REQUEST['item_total_rate'][$i];	
											
					$insert_mrm=$s->insertRecord('log_addmrnqty', $data_arr);
					$ErrMsg = _('An error occurred Record Not Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm,$db,$ErrMsg);	
			   }
			}
			
			$countval1= $_REQUEST['countrow'];
			for($j=0;$j<$countval1;$j++)
			{
				if($_REQUEST['package_no'][$j]!='')
				{				
					$data_arr1['grn_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];	
											
					$insert_mrm1=$s->insertRecord('log_addmrnbox', $data_arr1);
					$ErrMsg1 = _('An error occurred Record for Boxes Not Save') . '. ' . _('The error says');
					$insertResult = DB_query($insert_mrm1,$db,$ErrMsg);	
			   }
			}
		
			 
	 }
	 $_SESSION['success_msg']="Update Successfully";
		echo "<script>location='index.php?route=LOG/transation/goods_receipt_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">
<h1 align="center"><strong>Goods  Receipt Note</strong></h1>
<input name="usertype" id="usertype" type="hidden" value="<?php echo $dealertype; ?>" />
 
<h3 >GENERAL DETAILS</h3>
<table width="100%"  border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td  class="tabledata1">GRN No. </td>
    <td><input type="text" value="Will Be Generated On Saving" style="width:150px;" name="grn_no" readonly="true"></td>
    <td   class="tabledata1">GRN Date </td>
    <td><input type="text"  style="width:150px;"   name="grn_date" value="<?php  echo date('d/m/Y');?>" id="grn_date" class="datepicker"></td>
	<td  class="tabledata1">Warehouse<font color="#FF0000">*</font></td>
    <td><?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select * from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in ('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select * from storetype where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
     <select name="store" style="width:150px;" id="store">
	 <option value="0">Select</option>
      <?php 
			while ($myrow=DB_fetch_array($site_sql))
				{				
				?>
      <option value="<?php echo $myrow['id']; ?>"  <?php  echo $p;?>><?php echo $myrow['StoreName'];?></option>
      <?  }	?>
    </select>
	</td>
  </tr>
<tr class="row1">
  	<td  class="tabledata1">Purchase Type</td>
    <td>
		<select name="ptype" id="ptype"	style="width:150px;">
			<option value="0">Select</option>
			<option value="1">Local</option>
			<option value="2">Import</option>
		</select>
	</td>
    <td  class="tabledata1">Supplier Name</td>
    <td ><select name="vendor" id="vendor"  style="width:150px;" onchange="getaddress(this.value)">
		<option value="0" >---Select---</option>
			<?php
			$sql="select id, vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo  str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
		</select></td>
		<td  class="tabledata1">Supplier Address</td>
		<td id="supaddress"><input type="text" style="width:150px;" name="vendor_address" id="vendor_address"></td>    
</tr>
<tr class="row1">
    <td class="tabledata1">Document Type</td>
    <td>
		<select name="document_type" id="document_type" style="width:150px;">
			<option value="0">Select</option>
			<option value="Challan">Challan</option>
			<option value="Bill">Bill</option>
		</select>
	</td>
    <td class="tabledata1">Document No</td>
    <td><input name="document_no" type="text" id="document_no" style="width:150px;" value="" /></td>
	<td class="tabledata1">Document Date</td>
    <td><input name="document_date" type="text" id="document_date" style="width:150px;" value="" class="datepicker" readonly="true" /></td>
</tr>
<tr class="row1">
    <td class="tabledata1">Gate Entry No.</td>
    <td><input type="text" name="gate_entry_no"  style="width:150px;" id="gate_entry_no"  value="" /></td>
    <td class="tabledata1">Gate Entry Date</td>
    <td><input type="text" name="gate_entry_date" id="gate_entry_date" style="width:150px;" class="datepicker" readonly="true" /></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">BOE No.</td>
    <td><input name="boe_no" type="text" id="boe_no" style="width:150px;"  value=""/></td>
    <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" readonly="true"/></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">Receiving Time</td>
    <td><input type="text" name="receive_time" id="receive_time" value="<?php echo date("H:i:s",time());?>" /></td>
</tr>
<tr class="row1">
    <td class="tabledata1">Form No</td>
    <td><input type="text" name="form_no" id="form_no"  style="width:150px;" /></td>
    <td class="tabledata1">Form Type</td>
    <td><input type="text" name="form_type" id="form_type"  style="width:150px;" /></td>
	<td class="tabledata1">Package Sr No.</td>
    <td><input type="text" name="package_srno" id="package_srno"  style="width:150px;" /></td>
</tr>
<tr class="row1">
    <td class="tabledata1">POD Received Date</td>
    <td><input name="pod_receive_date" type="text" id="pod_receive_date" style="width:150px;" value="" class="datepicker" readonly="true"/></td>
	<td class="tabledata1">POD Hand Over Date to Finance Team</td>
    <td><input name="pod_head_over_date" type="text" id="pod_head_over_date" style="width:150px;" value="" class="datepicker" readonly="true"/></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">   
		<table width="100%" border="1" cellspacing="0" cellpadding="0">
		<tr class="row1">	
		<td class="tabledata1" style="width:40px;"><strong>Select</strong></td>
		<td class="tabledata1" style="width:20px;"><strong></strong></td>
		<td class="tabledata1"><strong>ITEM CODE </strong></td>
		<td class="tabledata1"><strong>DESCRIPTION</strong></td>
		<td class="tabledata1"><strong>UOM</strong></td>         
		<td class="tabledata1"><strong>QTY RECEIVED</strong></td>
		<td class="tabledata1"><strong>RATE</strong></td>
		<td class="tabledata1"><strong>TOTAL PRICE</strong></td>    
		</tr>
		<tbody id='dataTable'>
		<tr class="row1">
		<td class="tabledata"><input name='delitem[]' type='checkbox' value='' /></td>
		<td class="tabledata"><input type="hidden" id="itemid" name="mst_itemid[]" 
		value="" /></td>
		<td class="tabledata"><input type='text' name='' id='itemcode' value=''  readonly /></td>
		<td class="tabledata"><input type='text' name='item_name[]' id='itemname' value='' readonly /></td>
		<td class="tabledata"><input type='text' name='uom[]' id='uom' value='' readonly /></td>
		<td class="tabledata"><input name="reciveqty[]" type="text" id="reciveqty" value=""  /></td>
		<td class="tabledata"><input name="itemrate[]" type="text" id="itemrate" value="" style="width:90px;" onkeyup="calc_total_price(this.id)"  /></td>
		<td class="tabledata"><input name="item_total_rate[]" type="text" id="itemtotalrate" value=""   style="width:90px;"
		readonly="readonly"/></td>
		</tr>
		</tbody>
		<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
		<input type="hidden" name="" value="" id="edit_cnt" />
		</table>
	</td>
</tr>
</table>
<div align="right">			
	<table width="100%">
		<tr>
			<td>
		      <table width="40%" border="1" cellspacing="0" cellpadding="3" align="right">
                <tr>
                  <td><strong>TOTAL AMOUNT <font color="#FF0000">*</font></strong> </td>
                  <td >
				 
				  <input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()"/>
				
				  </td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_perc" id="pkg_perc" value="<?php echo $venddata['pkg_per']; ?>" size="5" onkeyup="calcPackaging(this.value)" /><input name="pkg_charges" id="pkg_charges1" type="text" value="" size="28"  
				  onfocus="calcPackaging1()" /></td>
                </tr>
				<tr>
					<td><strong>Excise</strong></td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:150px;" onchange="calculateBillExcise(this.value)"  >
				<option value="0">--Select--</option>
				<?php
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
				$ServiceRes=DB_query($ServiceSql,$db);
				while($ServiceRow=DB_fetch_array($ServiceRes))
				{
				?>
				<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:100%;" onfocus="calculateTotalExcise()"/>
				</td>
			    </tr>
			<?php 
			$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			$k=1;
			while($cessRow=DB_fetch_array($cessSql))
			{
			$caption[$k]=$cessRow['caption']; 
			
			$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
			while($rate_row=DB_fetch_array($rate_sql))
			{
			$rate[$k]=$rate_row['def_rate'];
			}
			$k++;
			} 
			?>
			<tr>
					<td><strong>E-Cess</strong></td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:60px;" readonly />
						<input name="ECessValue1" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:120px;" readonly onfocus="calculateECess1()"/></td>
				</tr>
			<tr >
					<td><strong>SAH-E Cess</strong> </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:60px;" readonly/>
						<input name="SAHCessValue1" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:120px;" readonly onfocus="calculateSAHCess1()"/></td>
				</tr>
					<tr>
					<td><strong>Total Excise Amount</strong></td>
					<td><input type="text" name="total_excise_amount" id="total_item_amount1" style="width:150px;" onfocus="showexiseamt()" /></td>
					
					</tr>
                <tr>
                  <td><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT salestax_id ,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
				
				
     	?>
              <td><select id="taxname" name="vat_cst" onchange="tax_rate1(this.value)" style="width:100%;">
	          <option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($venddata['vat_cst_per']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
              </tr>
              <?php  $taxdata=$s->getField('sales_tax_master','salestax_id',$venddata['vat_cst_per'],'taxrate'); ?>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="" readonly="true" <?php if($venddata['vat_cst_per']!='') {?> onfocus="tax_rate1(<?php echo $venddata['vat_cst_per']; ?>)" <?php } ?>/>
              </div>

	</td>
                </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per" value="<?php echo $venddata['sur_oct_per']; ?>"  size="10" onfocus="calsuroctamt(this.value)"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:60%;" onfocus="calsuroctamt1()" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:100%;" value="<?php echo $venddata['totalcharge']; ?>"     /></td>
                </tr>
				<tr>
                  <td><strong>Loading /Unloading</strong> </td>
                  <td><input type="text" name="loading" id="loading1" style="width:100%;" value="<?php echo $venddata['loading']; ?>"     /></td>
                </tr>
                <tr>
                  <td><strong>Additional Duties </strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $venddata['add_charges']; ?>" size="25" style="width:100%;" /></td>
                </tr>
				
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12"/><input type="hidden"  id="orig_grand_tot" />&nbsp;<strong>Round Off</strong>&nbsp;<select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded(this.value)">
				  <option value="">None</option>
				  <option value="+">+</option>
				  <option value="-">-</option>
				  </select></td>
                </tr>
			  </table>
			 
			 </div>  <tr><td>
			 <div align="left">
				<input type="button" onClick="open_box()" value="Upload Boxes Manualy" class="search" id="upload_boxes" />
  			 </div>
			 <div style="display:none;" id="box_block">
			 <hr>
			 <h1 align="center" style="text-align:center;">Upload Boxes Manualy</h1>
			<br />
			<div style="height: auto" id="ItemListDiv">
			<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
			  <tr>
				<td class="tabledata1" colspan="3"><h3 style="color:#000000; font-size:16px;"><strong>Goods Received Note (GRN) Boxes Details</strong></h3></td>
				 <td class="tabledata1">No. of Rows</td>
				 <td class="tabledata1"><input type="text" name="countrow" id="countrow" value="" />
				 <input type="button" name="gen_rows" value="Generate Rows" onclick="generaterows()"/></td>
			  </tr>
			  <tr>
				<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>
			  </tr>
			   <tbody id="dataTablerows">
			  <tr>
				<td class="tabledata">1</td>
				<td class="tabledata"><input type="text" name="package_no[]" id="package_no" /></td>
				<td class="tabledata"><input type="text" name="no_of_package[]" id="no_of_package" ></td>
				<td class="tabledata"><input type="text" name="content[]" id="content"></td>
				<td class="tabledata">
					<select name="layout[]" id="layout_0" >
					<option value="0">Select</option>
					<?php 
					$sql1=DB_query("select * from log_floor where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
					while($sql_floor=DB_fetch_array($sql1))
					{
					?> 
					
					<option value="<?php echo  $sql_floor['floor_name'];?>"><?php echo $sql_floor['floor_name']; ?></option>
					<?php } ?>
					</select>
				</td>
			  </tr>
			   </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/transation/goods_receipt_note_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" value="Cancel" name="Back" /></a>
		</div>
</form>
<script language="javascript" type="text/javascript">
 function claculateExcise(i,str)
  {
	var discounted=document.getElementById("basic_"+i).value;
	if (str.length==0)
	{
	document.getElementById("exciseId_"+i).innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("exciseId_"+i).innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?mrnTaxId="+str+"&data="+i,true);
	xmlhttp.send();
}


function calculateExciseDuty(i)
{

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




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




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



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

function 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("sitecode").value=='000')
{
alert("Must Select Site Name");
document.getElementById("sitecode").focus();
return false;
}
if(document.getElementById("storecode").value=='000')
{
alert("Must Select Store Name");
document.getElementById("storecode").focus();
return false;
}
if(document.getElementById("receiviedagaist").value=='0')
{
alert("Must Select Received Aganist Type");
document.getElementById("receiviedagaist").focus();
return false;
}
if(document.getElementById("vendor").value=='000')
{
alert("Must Select  Vender");
document.getElementById("vendor").focus();
return false;
}
if(document.getElementById("gatepassno").value=='')
{
alert("Must Enter Gate Entry No");
document.getElementById("gatepassno").focus();
return false;
}
if(document.getElementById("gatepassdate").value=='')
{
alert("Must Enter Gate Entry Date");
document.getElementById("gatepassdate").focus();
return false;
}
if(document.getElementById("entrycheck").value=='1')
{
alert("Duplicate Entry For Gate Entry Pass");
document.getElementById("gatepassno").value='';
document.getElementById("gatepassno").focus();
return false;
}


var col=0;
var cou=document.getElementById("count").value;
for(var i=0;i<cou;i++)
{	
if(document.getElementById("qty_as_per_bill_"+i).value!='')
{
var col=1;
}	
}
if(col==0)
{
alert("please Fill All details of item");
return false;
}
	
if(document.getElementById("total_item_amount").value=='' || document.getElementById("total_item_amount").value=='0.00')
{
alert("Total amount should not be blank");
document.getElementById("total_item_amount").focus();
return false;
}



if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
{
alert("Grand Total amount should not be blank");
document.getElementById("GrandTotal").focus();
return false;
}		

}

function confirmPost1()
{
var max_price=document.getElementById("max_price").value;
var grand_price=document.getElementById("GrandTotal").value;
if(parseFloat(grand_price) > parseFloat(max_price)){
$alertmasg="Grandtotal not more than Maximum Direct Purchase Allowed Amount - "+max_price;
alert($alertmasg);
return false;
}

if(document.getElementById("sitecode").value=='000')
{
alert("Must Select Site Name");
document.getElementById("sitecode").focus();
return false;
}
if(document.getElementById("storecode").value=='000')
{
alert("Must Select Store Name");
document.getElementById("storecode").focus();
return false;
}
if(document.getElementById("receiviedagaist").value=='0')
{
alert("Must Select Received Aganist Type");
document.getElementById("receiviedagaist").focus();
return false;
}
if(document.getElementById("vendor").value=='000')
{
alert("Must Select  Vender");
document.getElementById("vendor").focus();
return false;
}
if(document.getElementById("gatepassno").value=='')
{
alert("Must Enter Gate Entry No");
document.getElementById("gatepassno").focus();
return false;
}
if(document.getElementById("gatepassdate").value=='')
{
alert("Must Enter Gate Entry Date");
document.getElementById("gatepassdate").focus();
return false;
}
if(document.getElementById("entrycheck").value=='1')
{
alert("Duplicate Entry For Gate Entry Pass");
document.getElementById("gatepassno").value='';
document.getElementById("gatepassno").focus();
return false;
}

var col=0;
var cou=document.getElementById("count").value;
for(var i=0;i<cou;i++)

{	
if(document.getElementById("qty_as_per_bill_"+i).value!='')
{
var col=1;
}	
}
if(col==0)
{
alert("please Fill All details of item");
return false;
}

if(document.getElementById("total_item_amount").value=='' || document.getElementById("total_item_amount").value=='0.00')
{
alert("Total amount should not be blank");
document.getElementById("total_item_amount").focus();
return false;
}	

if(document.getElementById("GrandTotal").value=='' || document.getElementById("GrandTotal").value=='0.00')
{
alert("Grand Total amount should not be blank");
document.getElementById("GrandTotal").focus();
return false;
}	
}
function caltaxamout(i)
{
var excise=parseFloat(document.getElementById("exciseDuty_"+i).value);
if(excise!=0)
{
var basic_amount=document.getElementById("exciseValue_"+i).value;
var ecessamt=document.getElementById("ECessValue_"+i).value;
var sahamt=document.getElementById("SAHCessValue_"+i).value;
var totaltax=parseFloat(basic_amount)+parseFloat(ecessamt)+parseFloat(sahamt);	
document.getElementById('taxableamount_'+i).value=totaltax.toFixed(2);	
}
else
{
document.getElementById('taxableamount_'+i).value=0;		
}	
}

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

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

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

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


}
}

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

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



function deleteRowOrder(tableID) 
{
	try 
	{
	var table = document.getElementById(tableID);
	//alert(table);
	var rowCount = table.rows.length;
	//alert(rowCount);
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = row.cells[0].childNodes[0];
	if(null != chkbox && true == chkbox.checked) 
	{
	if(rowCount <= 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 getaddress(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("supaddress").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","supaddress.php?sid="+str,true);
	xmlhttp.send();
}

function generaterows()
{  
	var str=document.getElementById("countrow").value;
	if(str=='' || str<=0){
		alert("Please enter Number of rows to generate.");
		return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("dataTablerows").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","generaterows.php?rno="+str,true);
	xmlhttp.send();
}
</script>