<?php
$PageSecurity = 2;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');


if($_REQUEST['GrnType']=='IO' && $_REQUEST['type']=='Consolidated')
{ ?>
<div style="clear:both"></div>
<div align="right" id="charges1">
  <div id="importPo3" style="width:100%; margin:auto;">
    <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
      <tr class="row1">
        <td colspan="14" style="text-align:center;" class="tabledata1"><strong>Against :</strong>
            <input type="radio" name="calc_total_against" id="radio" value="bill" onclick="calculateAgainst(this.value)" />
            <strong>Bill Qty</strong>
            <input type="radio" name="calc_total_against" id="radio2" value="received" onclick="calculateAgainst(this.value)"/>
            <strong>Received Qty</strong></td>
      </tr>
      <tr>
        <td class="tabledata"><strong>Sr.No.</strong></td>
        <td class="tabledata"><strong>Item Code</strong></td>
        <td class="tabledata"><strong>Description</strong></td>
        <td class="tabledata"><strong>UOM</strong></td>
        <td class="tabledata"><strong>PO QTY</strong></td>
        <td class="tabledata"><strong>Bill QTY</strong></td>
        <td class="tabledata"><strong>Recieved QTY</strong></td>
        <td class="tabledata"><strong>Short Quantity</strong></td>
        <td class="tabledata"><strong>Rate</strong></td>
        <td class="tabledata"><strong>Amount</strong></td>
        <td class="tabledata" colspan="2" width="15%"><strong>Discount</strong></td>
        <td class="tabledata"><strong>Basic<br /> Amt.</strong></td>
        <td class="tabledata"><strong>Currency</strong></td>
      </tr>
      <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrn']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	
$oldCur =$row['currency'];
?>
      <tr bgcolor="#c1c1c1">
        <td><?php echo $i+1;?></td>
        <td><?php echo $itemcode;?>
            <input type="hidden" name="convfac[]" id="convfac[]" value="<?php echo $confac; ?>" />
            <input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
            <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
            <input type="hidden" readonly="" id="tolrancees[]" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
            <input type="hidden" readonly="" id="pending[]" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
        </td>
        <td><?php echo $itemname ?></td>
        <td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
        <td><?php   echo $poqty=$row['POQty']; ?>
            <input name="poqty[]" type="hidden" id="poqty[]" value="<?php echo $poqty;?>" size="10"/></td>
        <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>" value="<?php echo $row['qty_as_per_bill'];?>"  size="8" readonly onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
        </td>
        <td><input name="reciveqty[]" readonly type="text" id="reciveqty_<?php echo $i; ?>" value="<?php echo $row['reciveqty'];?>" size="8"/></td>
        <td><input name="short_accessid[]" type="text" id="short_accessid[]" value="<?php echo $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
        <td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i; ?>" value="<?php echo $ratVal= $row['itemprice']; ?>"  size="8" readonly="true"/>
        </td>
        <td><input name="itemamount[]" readonly type="text" id="itemamount_<?php echo $i; ?>" value="<?php echo $ratVal*$row['reciveqty']; ?>" onfocus="calculateAmuunt(<?php echo $i; ?>)"  size="8"/>
        </td> 
               <td class="tabledata"><input type="text" readonly value="<?php echo $curId=$row['discount']; 
		?>" name="discount[]" onkeyup="DiscountAmounts(this.value,<?php echo $i; ?>)" size="8" id="Discount1_<?php echo $i; ?>"/>
        </td>
        <td><input name="DiscountType1[]" type="hidden" id="PerAmo_<?php echo $i; ?>"
		 value="<?php echo $row['disc_type']; 
		?>" size="8" readonly />
		<input  name="DiscountType[]" type="text"  id="PerAmo_<?php echo $i; ?>" value="<?php if($row['disc_type']=='Amount')
		{ echo 'Amt'; } else { echo '%'; }
		?>" size="8" readonly/>
	</td>
       <td class="tabledata"><input type="text" style="width:70px" id="basic_<?php echo $i; ?>" value="<?php 
	   $ab= $ratVal*$row['reciveqty'];
	   if($row['dis_type']=='Amount')
	   {
	   echo $result = $ab-$curId;
	   }
	   else
	   {
	   $resultMid = ($ab*$curId)/100;
	   echo $result = $ab-$resultMid;
	   }
	   ?>" name="basic[]" readonly/></td>
       <td><input name="itemCurrency[]" type="hidden" id="itemCurrency_<?php echo $i; ?>"
	    value="<?php echo $curId =$row['currency']; 		?>" size="8" readonly />
		<input name="itemCurrencyread[]" type="text" id="itemCurrencyname_<?php echo $i; ?>" value="<?php echo $s->getField('currency_master','id',$curId,'abbreviation');
		?>" size="8" readonly/>
	</td>
      </tr>
      <?php $i++; }	 ?>
      <input type="hidden" name="countval2" value="<?php echo $i; ?>"  id="count"/>
    </table>
  </div><br />
<br />
			
			
		<table width="100%" cellpadding="3" cellspacing="0" border="1">
			<tr class="row1">
				<td valign="top" width="50%">
				<table width="100%" cellpadding="3" cellspacing="0" border="0">
				<tr class="row1">
				<td class="tabledata1"><strong>Ledger</strong></td>
				<td>
				<select name="ledger" id="ledger" style="width:200px;">
				<option value="000">---Select Ledger---</option>
				<?php
				$data1=array();				
				$SQLP=DB_query("SELECT GroupId FROM accountgroupmaster where GroupName='Purchase Accounts' or 
				GroupName='Fixed Assets'",$db);
				while($row1=DB_fetch_array($SQLP))
				{
				$data1[]=$row1['GroupId'];
				}
				$data2=implode("','",$data1);
				
				
									$GPId=DB_fetch_array($SQLP);
									$ledger_sql=DB_query("select AccountsID, AccountName from accountledger 
									where UnderGroup in('".$data2."') ORDER BY AccountName ASC",$db);
				while($ledger_row=DB_fetch_array($ledger_sql))
				{
				?>
				<option value="<?php echo $ledger_row['AccountsID'];?>"<?php echo ($ledger_row['AccountsID']==$_REQUEST['ledger']?'selected':'')?>><?php echo $ledger_row['AccountName'];?></option>
				<?php } ?>
				</select></td>
				</tr>
				<tr class="row1">
				<td class="tabledata1"><strong>Remarks If Any</strong></td>
				<td>
				<textarea name="remarks" id="remarks" style="width:200px;"><?php echo $_REQUEST['remarks'];?></textarea></td>
				</tr>
				  <tr class="row1">
					<td class="tabledata1"><strong>Excise Effect</strong></td>
					<td><select name='Excise_Effect' style="width:200px;">
					<option value="0">---</option>
					<option value="RG-23A"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23A')?'selected':''?>  >RG 23A &Iota; &Iota;nd</option>
						<option value="RG-23C"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23C')?'selected':''?>  >RG 23C &Iota; &Iota;nd</option>
						<option value="modvat"  <?php echo ( $mrn_row['Excise_Effect']=='modvat')?'selected':''?>  >Mod Vat</option>
					</select>&nbsp;</td>
				  </tr>
				  <tr class="row1">
				  <td class="tabledata1"><strong>Form Type</strong></td>
				  <td><select  name="form_type" id="form_type" style="width:200px; height:20px;">
				  <option value="">Select</option>
				  <?php
				 $formSql=DB_query("Select * from form_type_master",$db);
				while($formRow=DB_fetch_array($formSql))
				{
				?>
				  <option value="<?php  echo $formRow['id']?>"<?php echo ($formType==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option>
				  <?php }?>
				</select></td>
				  </tr>
 				 </table>
				</td>
							<td>
		      <table width="100%" border="1" cellspacing="0" cellpadding="3">
                <tr>
                  <td><strong>TOTAL AMOUNT <font color="#FF0000">*</font></strong> </td>
                  <td >
				  <input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onFocus="cal_totalamount()" value="<?php echo $totalAmount; ?>" />
				  </td>
               </tr>
			   <tr>
                  <td><strong>Currency Conversion<font color="#FF0000">*</font></strong> </td>
                  <td>
				  <input name="oldCurrency" type="hidden" id="oldCurrency" value="<?php echo $oldCur; 
		?>" size="8" />
				  <select style="width:80px;" name="conv_currency" id="tot_currency" onChange="ajax_cur_rate_tot(this.value);">
				  <option value="">--Select--</option>
			<?php $curr_sql=DB_query("Select * from currency_master",$db);
			while($curr_row=DB_fetch_array($curr_sql))
			{  ?>
            <option value="<?php echo $curr_row['id']; ?>"<?php echo ($_POST['currency']==$curr_row['id'])?'selected':''?>><?php echo $curr_row['abbreviation']; ?></option>
			<?php } ?>
          </select>
		  <input name="tot_conv_rate" id="tot_conv_rate" type="text" value="" size="28"  
				  onkeyup="calctotConvAmt(this.value)" />
				  </td>
               </tr>
			   <tr>
                  <td><strong>Conversion Amount</strong> </td>
                  <td><input type="text" name="tot_conv_amt" id="tot_conv_amt"  size="28" /></td>
                </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><select name="pckg_ledger" style="width:100px;" onchange="calcPackagingd(this.value)">
				  	<?php 
				  $pckLedger=DB_query("Select * from accountledger where ledgertype='pckcharge'",$db);
				  while($pckLedgerRow=DB_fetch_array($pckLedger))
				  {?>
				  <option value="<?php echo $pckLedgerRow['AccountsID'];?>"><?php echo $pckLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>			  
				  <input name="pkg_charges" id="pkg_charges" readonly type="text" size="28"/></td>
                </tr>
                <tr>
                  <td><strong>Custom Duty</strong> </td>
              <td><select name="custom_duty_per" id="custom_duty_per" style="width: 55%" onChange="calcCustomd(this.value)">
			  <option value="">--Select--</option>
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'Custom'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
			  <input type="text" name="custom_duty" id="custom_duty_new" style="width:100%;"/></td>
              </tr>
              <tr>
              	<td><strong>CVD</strong></td>
              <td><select name="cvd_per" id="cvd_per" style="width: 55%" onChange="calcCvdd(this.value)">
			  <option value="">--Select--</option>
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'CVD'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
                  <input type="text" name="cvd_total" id="cvd_total_new" style="width:100%;"/></td>
                </tr>
                <tr>
                  <td><strong>Custom E.Cess</strong> </td>
                  <td>
				  <select name="cstm_ecess_per" id="cstm_ecess_per" style="width: 55%" onChange="calcCustmexcessd(this.value)">
				   <option value="">--Select--</option>
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'ECESS'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select><input type="text" name="custom_ecess1" id="custom_ecess_new" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Custom SE E.Cess</strong> </td>
                  <td><select name="cstm_ecessec_per" id="cstm_ecessec_per" style="width: 55%" onChange="calcCustmexcessec(this.value)">
				<option value="">--Select--></option>  
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'SHE-CESS'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
				<input type="text" name="custom_sec_ecesss" id="custom_sec_ecess_new" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Additional Duty </strong> </td>
                  <td><select name="cstm_add_per" id="cstm_add_per" style="width: 55%" onChange="calcadduty(this.value)">
				  <option value="">--Select--></option>  
		<?php 
		$accgroup_sql = "select * from custom_duty where type = 'ADC'";
		$accgroup_result = DB_query($accgroup_sql,$db);
		while($accgroup_row = DB_fetch_array($accgroup_result))
		{ 	
		?>
		<option value="<?php echo $accgroup_row['def_rate'];?>"><?php echo $accgroup_row['caption'];?></option>
		<?php } ?>
		</select>
				  <input name="add_chargess" id="add_charges_new" type="text"  size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><select name="freight_ledger" id="TotalCharge" style="width:100px;" onchange="cal_grandamounts3()">
				  	<?php 
				  $frLedger=DB_query("Select * from accountledger where ledgertype='freight'",$db);
				  while($frLedgerRow=DB_fetch_array($frLedger))
				  {?>
				  <option value="<?php echo $frLedgerRow['AccountsID'];?>"><?php echo $frLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>
				  <input type="text" name="freight" id="TotalCharge1" style="width:100px;"/></td>
                </tr>
				 <tr>
                  <td><strong>Insurance</strong> </td>
                  <td><input type="text" name="insurance" id="insurance" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Clearing & Forwarding</strong> </td>
                  <td><input type="text" name="clearing" id="clearing" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Misc. Charges</strong> </td>
                  <td><input type="text" name="misCharge" id="misCharge" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Handling Charges</strong> </td>
                  <td><input type="text" name="loadings" id="loading2" style="width:100%;" value="<?php echo $venddata['loading']; ?>"/></td>
                </tr>
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotals" id="GrandTotal" onFocus="cal_grandamount5()"  size="5"/><input type="hidden"  id="orig_grand_tot"  size="5"/>&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><input type="text" name="roundVal1" id="roundVal1" size="5" /></td>
                </tr>
              </table></td></tr>
		     			</table>
</div>
 <?php
}
elseif($_REQUEST['GrnType']=='IO' && $_REQUEST['type']=='Itemwise')
{ ?>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>
 <div id="importPo1" style="width:950px;overflow:auto;">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr class="row1">
        <td colspan="14" style="text-align:center;" class="tabledata1"><strong>Against :</strong>
            <input type="radio" name="calc_total_against" id="radio" value="bill" onclick="calculateAgainst2(this.value)" />
            <strong>Bill Qty</strong>
            <input type="radio" name="calc_total_against" id="radio2" value="received" onclick="calculateAgainst2(this.value)"/>
            <strong>Received Qty</strong></td>
      </tr>
	<th class="tabledata"><strong>Sr.No.</strong></th>
	<th class="tabledata"><strong>Item Code</strong></th>
	<th class="tabledata"><strong>Description</strong></th>
	<th class="tabledata"><strong>UOM</strong></th>
	<th class="tabledata"><strong>PO QTY</strong></th>
	<th class="tabledata"><strong>Bill Qty</strong></th>
	<th class="tabledata"><strong>Recieved QTY</strong></th>
	<th class="tabledata"><strong>Short/Excess Quantity</strong></th>
	<th class="tabledata"><strong>Rate</strong></th>
	<th class="tabledata"><strong>Amount</strong></th>
	<td class="tabledata" colspan="2"><strong>Discount</strong></td>
	<th class="tabledata"><strong>Basic Amount</strong></th>
	<td class="tabledata"><strong>Currency</strong></td>
	<td class="tabledata" ><strong>Conversion<br /> Curr.</strong></td>
	<td class="tabledata"><strong>Conversion<br /> Rate</strong></td>
	<th class="tabledata"><strong>Basic<br /> Amt.(Converted)</strong></th>
	<th class="tabledata"><strong>Custom Duty Flag</strong></th>
	<th class="tabledata"><strong>Custom Duty</strong></th>
	<th class="tabledata"><strong>Duty Amount</strong></th>
	<th class="tabledata"><div style="width:47px;"><strong>CVD</strong></div></th>
	<th class="tabledata"><strong>Custom E.Cess</strong></th>
	<th class="tabledata"><strong>Custom SE.Cess</strong></th>
	<th class="tabledata"><strong>Add. Duty</strong></th>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrn']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$tolerance=$s->getField('item_master','id',$row['mst_itemid'],'tolerance');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
?>
 
       <tr bgcolor="#c1c1c1">
        <td><?php echo $i+1;?></td>
        <td><?php echo $itemcode;?>
            <input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
            <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
            <input type="hidden" readonly="" id="tolrancees[]" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
            <input type="hidden" readonly="" id="pending[]" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
        </td>
        <td><?php echo $itemname ?></td>
        <td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
        <td><?php   echo $poqty=$row['POQty']; ?>
            <input name="poqty[]" type="hidden" id="poqty[]" value="<?php echo $poqty;?>" size="10"/></td>
        <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>" value="<?php echo $row['qty_as_per_bill'];?>"  size="8" readonly onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
        </td>
        <td><input name="reciveqty[]" readonly type="text" id="reciveqty_<?php echo $i; ?>" value="<?php echo $row['reciveqty'];?>" size="8"/></td>
        <td><input name="short_accessid[]" type="text" id="short_accessid[]" value="<?php echo $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
        <td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i; ?>" value="<?php echo $row['itemprice']; ?>"  size="8" readonly="true"/>
        </td>
        <td><input name="itemamount[]" readonly type="text" id="itemamount_<?php echo $i; ?>" value="<?php echo $row['itemprice']*$row['reciveqty']; ?>" onfocus="calculateAmuunt(<?php echo $i; ?>)"  size="8"/>
        </td> 
        <td class="tabledata"><input type="text" readonly 
		value="<?php echo $row['discount'];	?>" name="discount[]" size="8" id="Discount1_<?php echo $i; ?>"/>
        </td>
		 <td><input name="DiscountType1[]" type="hidden" id="PerAmo_<?php echo $i; ?>" 
		 value="<?php echo $row['disc_type'];	?>" size="8" readonly />
		<input  name="DiscountType[]" type="text"  id="PerAmo_<?php echo $i; ?>" value="<?php if($row['disc_type']=='Amount')
		{ echo 'Amt'; } else { echo '%'; }
		?>" size="8" readonly/>
		
	</td>
		 <td class="tabledata"><input type="text" style="width:70px" id="NetRate1_<?php echo $i; ?>" value="<?php 
	   $ab= $row['itemprice']*$row['reciveqty'];
	   if($row['disc_type']=='Amount')
	   {
	   echo $result = $ab-$row['discount'];
	   }
	   else
	   {
	   $resultMid = ($ab*$row['discount'])/100;
	   echo $result = $ab-$resultMid;
	   }
	   ?>" name="NetRate1[]" readonly/>
	   
	   </td>
		<td><input name="itemCurrency[]" type="hidden" id="itemCurrency_<?php echo $i; ?>" 
		value="<?php echo $row['currency']; 	?>" size="8" readonly />
		<input name="itemCurrencyread[]" type="text" id="itemCurrencyname_<?php echo $i; ?>" value="<?php echo $s->getField('currency_master','id',$row['currency'],'abbreviation');
		?>" size="8" readonly/>
	</td>

	 <td>
				  <select style="width:80px;" name="con_curr[]" id="con_curr">
				  <option value="">--Select--</option>
			<?php $curr_sql=DB_query("Select * from currency_master",$db);
			while($curr_row=DB_fetch_array($curr_sql))
			{  ?>
            <option value="<?php echo $curr_row['id']; ?>"<?php echo ($_REQUEST['con_curr']==$curr_row['id'])?'selected':''?>><?php echo $curr_row['abbreviation']; ?></option>
			<?php } ?>
          </select>
				  </td>
		  <td>
		  <input name="conv_rate[]" type="text" id="conv_rate_<?php echo $i; ?>" size="8" onfocus="recieveValidate()" onkeyup="calcConvAmt(this.value,<?php echo $i; ?>)"/></td>
		<td class="tabledata"><input type="text" style="width:70px" readonly id="basic_<?php echo $i;?>" name="basic[]" onBlur="cal_basic_total(this.id)" onFocus="calConvertedAmount(this.value,<?php echo $i;?>);" /></td>
		<td class="tabledata"><select name="Excise_type[]" style="width:85px" id="hid_billing_type_<?php echo $i;?>"  onchange="checkExcisable11(this.value,<?php echo $i;?>)">
	<option value="">Select</option>
	<option value="1"<?php echo ($_REQUEST['Excise_type']=='1')?'selected':''?>>Yes</option>
	<option value="2"<?php echo ($_REQUEST['Excise_type']=='2')?'selected':''?>>No</option>
</select></td>
	<td class="tabledata"><select name="Excise_Duty1[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;" onchange="claculateExcise33(this.value,<?php echo $i; ?>)" onBlur="checkexiseflag(this.id)">
    	    <option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from custom_duty where type='custom'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['def_rate'];?>"<?php echo ($_REQUEST['Excise_Duty1']==$excise_row['id'])?'selected':''?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $j;?>"></div>
      </td>
		  <td class="tabledata"><input type="text"  id="dutyamount_<?php echo $i;?>" onFocus="checkduty(this.id)" name="duty_amount[]" style="width:70px;" onBlur="cal_custom_total(this.id)" readonly/></td><?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?> 
		<td class="tabledata">
		<input type="text" id="cvd_percentage" name="cvd_percentage" size="5" readonly value="<?php echo $s->getField('custom_duty','type','CVD','def_rate');?>" /><input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalAmount1[]" style="width:70px;"  onBlur="cal_cvd_total(this.id);"/></td>
		<td class="tabledata"><input type="text" id="ecess_percentage" name="ecess_percentage" readonly size="5" value="<?php echo $s->getField('custom_duty','type','ECESS','def_rate');?>" /><input type="text" id="customecess_<?php echo $i;?>" name="custom_ecess1[]" style="width:70px;"/></td>
		<td class="tabledata"> <input type="text" readonly id="secess_percentage" name="secess_percentage" size="5" value="<?php echo $s->getField('custom_duty','type','SHE-CESS','def_rate');?>" /><input type="text" id="customsececess_<?php echo $i;?>" name="custom_sec_ecess1[]" style="width:70px;" onBlur="cal_ecess_sec_total(this.id);" /></td>
		<td class="tabledata"><input type="text" readonly id="add_percentage" name="add_percentage" size="5" value="<?php echo $s->getField('custom_duty','type','ADC','def_rate');?>" /><input type="text" id="adduty_<?php echo $i;?>" name="adduty1[]" style="width:70px;"  onFocus="cal_add_duty1(this.id);"  onblur="cal_addcharg_total(this.id);"  / ></td>
</tr>
  <?php $i++; }	 ?>
  <input type="hidden" name="countval3" value="<?php echo $i; ?>"  id="count"/>
</table>
 </div>
</td>
</tr>
</table>
<div style="clear:both"></div>
<div align="right" id="charges1">			
			
		<table width="100%" cellpadding="3" cellspacing="0" border="1">
			<tr class="row1">
				<td valign="top" width="50%">
				<table width="100%" cellpadding="3" cellspacing="0" border="0">
				<tr class="row1">
				<td class="tabledata1"><strong>Ledger</strong></td>
				<td>
				<select name="ledger" id="ledger" style="width:200px;">
				<option value="000">---Select Ledger---</option>
				<?php
				$data1=array();				
				$SQLP=DB_query("SELECT GroupId FROM accountgroupmaster where GroupName='Purchase Accounts' or 
				GroupName='Fixed Assets'",$db);
				while($row1=DB_fetch_array($SQLP))
				{
				$data1[]=$row1['GroupId'];
				}
				$data2=implode("','",$data1);
				
				
									$GPId=DB_fetch_array($SQLP);
									$ledger_sql=DB_query("select AccountsID, AccountName from accountledger 
									where UnderGroup in('".$data2."') ORDER BY AccountName ASC",$db);
				while($ledger_row=DB_fetch_array($ledger_sql))
				{
				?>
				<option value="<?php echo $ledger_row['AccountsID'];?>"<?php echo ($ledger_row['AccountsID']==$_REQUEST['ledger']?'selected':'')?>><?php echo $ledger_row['AccountName'];?></option>
				<?php } ?>
				</select></td>
				</tr>
				<tr class="row1">
				<td class="tabledata1"><strong>Remarks If Any</strong></td>
				<td>
				<textarea name="remarks" id="remarks" style="width:200px;"><?php echo $_REQUEST['remarks'];?></textarea></td>
				</tr>
				  <tr class="row1">
					<td class="tabledata1"><strong>Excise Effect</strong></td>
					<td><select name='Excise_Effect' style="width:200px;">
					<option value="0">---</option>
					<option value="RG-23A"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23A')?'selected':''?>  >RG 23A &Iota; &Iota;nd</option>
						<option value="RG-23C"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23C')?'selected':''?>  >RG 23C &Iota; &Iota;nd</option>
						<option value="modvat"  <?php echo ( $mrn_row['Excise_Effect']=='modvat')?'selected':''?>  >Mod Vat</option>
					</select>&nbsp;</td>
				  </tr>
				  <tr class="row1">
				  <td class="tabledata1"><strong>Form Type</strong></td>
				  <td><select  name="form_type" id="form_type" style="width:200px; height:20px;">
				  <option value="">Select</option>
				  <?php
				 $formSql=DB_query("Select * from form_type_master",$db);
				while($formRow=DB_fetch_array($formSql))
				{
				?>
				  <option value="<?php  echo $formRow['id']?>"<?php echo ($formType==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option>
				  <?php }?>
				</select></td>
				  </tr>
 				 </table>
				</td>
				<td>
		      <table width="100%" border="1" cellspacing="0" cellpadding="3">
                <tr>
                  <td><strong>BASIC AMOUNT<font color="#FF0000">*</font></strong> </td>
                  <td >
				 
				  <input type="text" name="total_item_amount" readonly id="total_item_amount" style="width:100%;" onFocus="cal_totalamount()" />
				
				  </td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><select name="pckg_ledger" style="width:100px;" onchange="calcPackaging12(this.value)">
				  	<?php 
				  $pckLedger=DB_query("Select * from accountledger where ledgertype='pckcharge'",$db);
				  while($pckLedgerRow=DB_fetch_array($pckLedger))
				  {?>
				  <option value="<?php echo $pckLedgerRow['AccountsID'];?>"><?php echo $pckLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>			  
				  <input name="pkg_charges" id="pkg_charges" readonly type="text" size="28"/></td>
                </tr>
                <tr>
                  <td><strong>Custom Duty</strong> </td>
              <td><input type="text" readonly name="custom_duty" id="custom_duty" style="width:100%;" /></td>
              </tr>
              <tr>
              	<td><strong>CVD</strong></td>
              <td><div id="taxval">
                  <input type="text" readonly name="cvd_total" id="cvd_total" style="width:100%;"/>
              </div>

	</td>
                </tr>
                <tr>
                  <td><strong>Custom E.Cess</strong> </td>
                  <td><input type="text" readonly name="custom_ecess1" id="custom_ecess" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Custom SE.Cess</strong> </td>
                  <td><input type="text" name="custom_sec_ecesss" readonly id="custom_sec_ecess" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Additional Duty </strong> </td>
                  <td><input name="add_chargess" id="additionalCharges" readonly type="text" size="25" style="width:100%;" /></td>
                </tr>
               <tr>
                  <td><strong>Freight</strong> </td>
                  <td><select name="freight_ledger" id="TotalCharge" style="width:100px;" onchange="cal_grandamounts3()">
				  	<?php 
				  $frLedger=DB_query("Select * from accountledger where ledgertype='freight'",$db);
				  while($frLedgerRow=DB_fetch_array($frLedger))
				  {?>
				  <option value="<?php echo $frLedgerRow['AccountsID'];?>"><?php echo $frLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>
				  <input type="text" name="freight" id="TotalCharge1" style="width:100px;"/></td>
                </tr>
				 <tr>
                  <td><strong>Insurance</strong> </td>
                  <td><input type="text" name="insurance"  onKeyUp="calTotFreight(this.value)" id="insurance" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Clearing & Forwarding</strong> </td>
                  <td><input type="text" name="clearing"  onKeyUp="calTotFreight(this.value)" id="clearing" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Misc. Charges</strong> </td>
                  <td><input type="text" name="misCharge"  onKeyUp="calTotFreight(this.value)" id="misCharge" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Handling Charges</strong> </td>
                  <td><input type="text" name="loadings" onKeyUp="calTotHandling(this.value)" id="loading2" style="width:100%;" value="<?php echo $venddata['loading']; ?>"/></td>
                </tr>
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotals" readonly id="GrandTotal" onFocus="cal_grandamount4()"  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><input type="text" name="roundVal1" id="roundVal1" size="5" /></td>
                </tr>
              </table>
		    </td>
		<td>		</td>
		</tr>
			</table>

</div>
<?php
}
elseif($_REQUEST['GrnType']=='DO' && $_REQUEST['type']=='Itemwise')
{
 ?>
<div id="importPo2" style="width:950px;overflow:auto; display:block;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr class="row1">
	<td colspan="4" style="text-align:center;" class="tabledata1">
	<strong>Against :</strong>
	<input type="radio" name="calc_total_against" id="bill_id" value="bill" onclick="calculateAgainst3('bill')" />
	<strong>Bill Qty</strong> 
	<input type="radio" name="calc_total_against" id="received_id" value="received" onclick="calculateAgainst3('rec')"/>
	<strong>Received Qty</strong></td>
</tr>
<tr>
	<td class="tabledata"><strong>Sr.No.</strong></td>
	<td class="tabledata"><strong>Item Code</strong></td>
	<td class="tabledata"><strong>Description</strong></td>
	<td class="tabledata"><strong>UOM</strong></td>
	<td class="tabledata"><strong>PO QTY</strong></td>
	<td class="tabledata"><strong>Bill QTY</strong></td>
	<td class="tabledata"><strong>Recieved QTY</strong></td>
	<td class="tabledata"><strong>Short Quantity</strong></td>
	<td class="tabledata"><strong>Rate</strong></td>
	<td class="tabledata"><strong>Amount</strong></td>
	<td class="tabledata" colspan="2" width="15%"><strong>Discount</strong></td>
	<td class="tabledata"><strong>Basic<br />
	  Amt.</strong></td>
	<th ><strong>EXCISE FLAG</strong></th>
	<th ><strong>EXCISE</strong></th>
	<th ><strong>E-CESS</strong></th>
	<th ><strong>SE-CESS</strong></th>
	<th ><strong>Excise Amount</strong></th>
	<th ><strong>Total Amount</strong></th>
	<th ><strong>REMARKS </strong></th>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrn']."'",$db);

while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$tolerance=$s->getField('item_master','id',$row['mst_itemid'],'tolerance');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
?>
<tr bgcolor="#c1c1c1">
        <td><?php echo $i+1;?></td>
        <td><?php echo $itemcode;?>
            <input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
            <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
            <input type="hidden" readonly="" id="tolrancees[]" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
            <input type="hidden" readonly="" id="pending[]" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
        </td>
        <td><?php echo $itemname ?></td>
        <td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
        <td><?php   echo $poqty=$row['POQty']; ?>
            <input name="poqty[]" type="hidden" id="poqty[]" value="<?php echo $poqty;?>" size="10"/></td>
        <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>" value="<?php echo $row['qty_as_per_bill'];?>"  size="8" readonly onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
        </td>
        <td><input name="reciveqty[]" readonly type="text" id="reciveqty_<?php echo $i; ?>" value="<?php echo $row['reciveqty'];?>" size="8"/></td>
        <td><input name="short_accessid[]" type="text" id="short_accessid[]" value="<?php echo $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
        <td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i; ?>" value="<?php echo $ratVal= $row['itemprice']; ?>"  size="8" readonly="true"/>
        </td>
        <td><input name="itemamount[]" readonly type="text" id="itemamount_<?php echo $i; ?>" value="<?php echo $ratVal*$row['reciveqty']; ?>" onfocus="calculateAmuunt(<?php echo $i; ?>)"  size="8"/>
        </td> 
               <td class="tabledata"><input type="text" readonly value="<?php echo $curId =$row['discount']; 
		?>" name="discount[]" onkeyup="DiscountAmounts(this.value,<?php echo $i; ?>)" size="8" id="Discount1_<?php echo $i; ?>"/>
        </td>
       <td><input name="DiscountType1[]" type="hidden" id="PerAmo_<?php echo $i; ?>" value="<?php echo $row['disc_type']; 
		?>" size="8" readonly />
		<input  name="DiscountType[]" type="text"  id="PerAmo_<?php echo $i; ?>" value="<?php if($row['disc_type']=='Amount')
		{ echo 'Amt'; } else { echo '%'; }
		?>" size="8" readonly/>
	</td>
       <td class="tabledata"><input type="text" style="width:70px" id="basic_<?php echo $i; ?>" value="<?php 
	   $ab= $ratVal*$row['reciveqty'];
	   if($row['disc_type']=='Amount')
	   {
	   echo $result = $ab-$curId;
	   }
	   else
	   {
	   $resultMid = ($ab*$curId)/100;
	   echo $result = $ab-$resultMid;
	   }
	   ?>" name="basic[]" readonly/></td>
	<td><select name="billing_type[]" style="width:85px" id="billing_type_<?php echo $i;?>"  onchange="checkExcisable1(this.value,<?php echo $i; ?>)">
	<option value="">Select</option>
	<option value="NonExcisable"<?php if($tax_type=='NonExcisable') { ?> selected="selected" <?php } ?>>NonExcisable</option>
	<option value="Excisable" <?php if($tax_type=='Excisable') { ?> selected="selected" <?php } ?>>Excisable</option>
	<option value="IncludeTax" <?php if($tax_type=='IncludeTax') { ?> selected="selected" <?php } ?>>IncludeTax</option>
	</select></td>
	<td><select name="Excise_Duty1[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;" onChange="claculateExcise1(<?php echo $i; ?>,this.value)" onFocus="checkexiseflag1(<?php echo $i; ?>)">
	<option value="">Select</option>
	<?php 
	$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
	while($excise_row=DB_fetch_array($excise_sql))
	{
	$c='';
	if($Excise_Duty==$excise_row['id'])
	$c='selected';
	?>
	<option value="<?php echo $excise_row['id'];?>"<?php echo $c; ?>><?php echo $excise_row['caption'];?></option>
	<?php 	
	}
	?> 
	</select><div id="exciseId_<?php echo $i; ?>">
	<input name="excise_perc[]" id="ExcisePercentage_<?php echo $i; ?>" type="text" style="width:35px;;"  /> 
	<input name="excise_val[]" id="exciseValue_<?php echo $i; ?>" type="text"  style="width:70px;" onFocus="calculateExciseDuty1(<?php echo $i; ?>)" />
	</div></td>
	<?php 
	$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
	$k=1;
	while($cessRow=DB_fetch_array($cessSql))
	{
	$caption[$k]=$cessRow['caption']; 
	
	$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
	while($rate_row=DB_fetch_array($rate_sql))
	{
	$rate[$k]=$rate_row['def_rate'];
	}
	$k++;
	} 
	?>
	<td><input name="e_cess_perc[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly   />
	<input name="e_cess_val[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $Edu_Cess;?>"  style="width:70px;" readonly onFocus="calculateECess1(<?php echo $i; ?>)"/></td>
	<td><input name="sah_perc[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/>
	<input name="sah_val[]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $SHE_Cess;?>"  style="width:65px;" readonly onFocus="calculateSAHCess1(<?php echo $i; ?>)"/></td>
	
	<td><input name="taxableamount[]" type="text" id="taxableamount_<?php echo $i?>"  size="12"  onfocus="caltaxamout1(<?php echo $i;?>)" /></td>
	
	<td><input name="val_after_disc[]" type="text" id="total_<?php echo $i?>"  size="12" readonly="true" onFocus="value_after_discount1(<?php echo $i ?>);"/></td>
	
	
	<td><input type="text" name="remarks[]" id="remarks" value=""/></td>
	
</tr>
  <?php $i++; }	 ?>
  <input type="hidden" name="countval" value="<?php echo $i; ?>"  id="count"/>

</table>
</div>
 <div align="right" id="charges2">			
			
		<table width="100%" cellpadding="3" cellspacing="0" border="1">
			<tr class="row1">
				<td valign="top" width="50%">
				<table width="100%" cellpadding="3" cellspacing="0" border="0">
				<tr class="row1">
				<td class="tabledata1"><strong>Ledger</strong></td>
				<td>
				<select name="ledger" id="ledger" style="width:200px;">
				<option value="000">---Select Ledger---</option>
				<?php
				$data1=array();				
				$SQLP=DB_query("SELECT GroupId FROM accountgroupmaster where GroupName='Purchase Accounts' or 
				GroupName='Fixed Assets'",$db);
				while($row1=DB_fetch_array($SQLP))
				{
				$data1[]=$row1['GroupId'];
				}
				$data2=implode("','",$data1);
				
				
									$GPId=DB_fetch_array($SQLP);
									$ledger_sql=DB_query("select AccountsID, AccountName from accountledger 
									where UnderGroup in('".$data2."') ORDER BY AccountName ASC",$db);
				while($ledger_row=DB_fetch_array($ledger_sql))
				{
				?>
				<option value="<?php echo $ledger_row['AccountsID'];?>"<?php echo ($ledger_row['AccountsID']==$_REQUEST['ledger']?'selected':'')?>><?php echo $ledger_row['AccountName'];?></option>
				<?php } ?>
				</select></td>
				</tr>
				<tr class="row1">
				<td class="tabledata1"><strong>Remarks If Any</strong></td>
				<td>
				<textarea name="remarks" id="remarks" style="width:200px;"><?php echo $_REQUEST['remarks'];?></textarea></td>
				</tr>
				  <tr class="row1">
					<td class="tabledata1"><strong>Excise Effect</strong></td>
					<td><select name='Excise_Effect' style="width:200px;">
					<option value="0">---</option>
					<option value="RG-23A"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23A')?'selected':''?>  >RG 23A &Iota; &Iota;nd</option>
						<option value="RG-23C"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23C')?'selected':''?>  >RG 23C &Iota; &Iota;nd</option>
						<option value="modvat"  <?php echo ( $mrn_row['Excise_Effect']=='modvat')?'selected':''?>  >Mod Vat</option>
					</select>&nbsp;</td>
				  </tr>
				  <tr class="row1">
				  <td class="tabledata1"><strong>Form Type</strong></td>
				  <td><select  name="form_type" id="form_type" style="width:200px; height:20px;">
				  <option value="">Select</option>
				  <?php
				 $formSql=DB_query("Select * from form_type_master",$db);
				while($formRow=DB_fetch_array($formSql))
				{
				?>
				  <option value="<?php  echo $formRow['id']?>"<?php echo ($formType==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option>
				  <?php }?>
				</select></td>
				  </tr>
 				 </table>
				</td>
				<td>
			  <table width="100%" border="0" cellspacing="2" cellpadding="2">

                <tr>

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

                  <td ><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onFocus="cal_totalamount()" value=""/></td>

               </tr>

              <tr>

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

                  <td><select name="pckg_ledger" style="width:100px;" id="pkg_perc"  onchange="calcPackaging2(this.value)"
				   onblur="calcPackaging2(this.value)">
				  	<?php 
				  $pckLedger=DB_query("Select * from accountledger where ledgertype='pckcharge'",$db);
				  while($pckLedgerRow=DB_fetch_array($pckLedger))
				  {?>
				  <option value="<?php echo $pckLedgerRow['AccountsID'];?>"><?php echo $pckLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>
				  <input name="pkg_charges" id="pkg_charges" type="text" value="" style="width:100px;"  />
				 </td>

                </tr>
				
				<tr>

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

                  <td><input type="text" name="tot_excise_amt" id="tot_excise_amt" value="" size="5" onFocus="calcexcise2(this.value)" /></td>

                </tr>
				<tr>

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

                  <td><input type="text" name="tot_ecess_amt" id="tot_ecess_amt" value="" size="5" onFocus="calcecess2(this.value)" /></td>

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

                  <td><input type="text" name="tot_sahecess_amt" id="tot_sahecess_amt" value="" size="5" onFocus="calcsahecess2(this.value)" /></td>

                </tr>
				<tr>

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

                  <td><input name="add_chargess" id="additionalCharges" type="text" value="" size="25" style="width:100%;" /></td>

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

                  <td><input type="text" name="tot_excise_duty_amt" id="tot_excise_duty_amt" value="" size="5" onFocus="calcexciseduty2(this.value)" /></td>

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

                  <td><input type="text" name="tot_taxable_amt" id="tot_taxable_amt" value="" size="5" onFocus="calctaxamt2(this.value)" /></td>

                </tr>

                <tr>

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

                  <?php

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

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

     	?>

              <td><select id="taxname" name="vat_cst" onChange="tax_rate(this.value)" style="width:100%;">

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

                  <?php 

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

			?>

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

                  <?php } ?>

              </select></td>

 

              </tr>

              <tr>

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

              <td><div id="taxval">

                  <input type="text" name="taxvalue" id="taxvalue2" style="width:100%;" value="" readonly="true"/>

              </div>



	</td>

                </tr>

                <tr>

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

                  <td><select name="surcharge_ledger" id="" style="width:100px;" id="sur_oct_per" 
				  onchange="calsuroctamt2(this.value)" >
				  <?php 
				  $surLedger=DB_query("Select * from accountledger where ledgertype='surcharge'",$db);
				  while($surLedgerRow=DB_fetch_array($surLedger))
				  {?>
				  <option value="<?php echo $surLedgerRow['AccountsID'];?>"><?php echo $surLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>
				  <input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:100px;" /> </td>

                </tr>

                <tr>

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

                  <td><select name="freight_ledger" style="width:100px;" id="TotalCharge" onchange="cal_grandamounts2(this.value)">			  	<?php 
				  $frLedger=DB_query("Select * from accountledger where ledgertype='freight'",$db);
				  while($frLedgerRow=DB_fetch_array($frLedger))
				  {?>
				  <option value="<?php echo $frLedgerRow['AccountsID'];?>"><?php echo $frLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>		  
				  
				  <input type="text" name="freight" id="TotalCharge"  /></td>

                </tr>

				 <td><strong>Handling Charges</strong> </td>

                  <td><input type="text" name="loadings" id="loading" onkeyup="cal_grandamounts2(this.value)" style="width:100%;" value=""/></td>

                </tr>
                <tr>

				<td><strong>Grand Total</strong></td>

                  <td>
				  <input type="text" name="grandtotals" id="GrandTotal" onFocus="cal_grandamounts2()"  size="12" value=""/>
				  <input type="hidden"  id="orig_grand_tot" value=""/>&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><input type="text" name="roundVal1" id="roundVal1" size="5" /></td>

                </tr>

              </table>
		     </td>
		</tr>
			</table>
</div>
<?php 
}
elseif($_REQUEST['GrnType']=='DO' && $_REQUEST['type']=='Consolidated')
{ ?>
<div id="importPo4" style="width:950px;overflow:auto;">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
      <tr class="row1">
        <td colspan="14" style="text-align:center;" class="tabledata1"><strong>Against :</strong>
            <input type="radio" name="calc_total_against" id="radio" value="bill" onclick="calculateAgainst3(this.value)" />
            <strong>Bill Qty</strong>
            <input type="radio" name="calc_total_against" id="radio2" value="received" onclick="calculateAgainst3(this.value)"/>
            <strong>Received Qty</strong></td>
      </tr>
      <tr>
        <td class="tabledata"><strong>Sr.No.</strong></td>
        <td class="tabledata"><strong>Item Code</strong></td>
        <td class="tabledata"><strong>Description</strong></td>
        <td class="tabledata"><strong>UOM</strong></td>
        <td class="tabledata"><strong>PO QTY</strong></td>
        <td class="tabledata"><strong>Bill QTY</strong></td>
        <td class="tabledata"><strong>Recieved QTY</strong></td>
        <td class="tabledata"><strong>Short Quantity</strong></td>
        <td class="tabledata"><strong>Rate</strong></td>
        <td class="tabledata"><strong>Amount</strong></td>
        <td class="tabledata" colspan="2" width="15%"><strong>Discount</strong></td>
        <td class="tabledata"><strong>Basic<br />
          Amt.</strong></td>
        <td class="tabledata"><strong>Currency</strong></td>
      </tr>
      <?php 
$i=0;
$sql=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrn']."'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
$oldCur = $row['currency'];
?>
      <tr bgcolor="#c1c1c1">
        <td><?php echo $i+1;?></td>
        <td><?php echo $itemcode;?>
            <input type="hidden" readonly="" id="mst_itemid[]" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
            <input type="hidden" readonly="" id="itemcode[]" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
            <input type="hidden" readonly="" id="tolrancees[]" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
            <input type="hidden" readonly="" id="pending[]" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
        </td>
        <td><?php echo $itemname ?></td>
        <td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
        <td><?php   echo $poqty=$row['POQty']; ?>
            <input name="poqty[]" type="hidden" id="poqty[]" value="<?php echo $poqty;?>" size="10"/></td>
        <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>" value="<?php echo $row['qty_as_per_bill'];?>"  size="8" readonly onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
        </td>
        <td><input name="reciveqty[]" readonly type="text" id="reciveqty_<?php echo $i; ?>" value="<?php echo $row['reciveqty'];?>" size="8"/></td>
        <td><input name="short_accessid[]" type="text" id="short_accessid[]" value="<?php echo $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
        <td><input name="itemrate[]" type="text" id="itemrate_<?php echo $i; ?>" value="<?php echo $ratVal=$row['itemprice']; ?>"  size="8" readonly="true"/>
        </td>
        <td><input name="itemamount[]" readonly type="text" id="itemamount_<?php echo $i; ?>" value="<?php echo $ratVal*$row['reciveqty']; ?>" onfocus="calculateAmuunt(<?php echo $i; ?>)"  size="8"/>
        </td> 
               <td class="tabledata"><input type="text" readonly value="<?php echo $curId =$row['discount']; 
		?>" name="discount[]" onkeyup="DiscountAmounts(this.value,<?php echo $i; ?>)" size="8" id="Discount1_<?php echo $i; ?>"/>
        </td>
       <td><input name="DiscountType1[]" type="hidden" id="PerAmo_<?php echo $i; ?>" value="<?php echo $row['disc_type']; 
		?>" size="8" readonly />
		<input  name="DiscountType[]" type="text"  id="PerAmo_<?php echo $i; ?>" value="<?php if($row['disc_type']=='Amount')
		{ echo 'Amt'; } else { echo '%'; }
		?>" size="8" readonly/>
	</td>
	   <td class="tabledata"><input type="text" style="width:70px" id="basic_<?php echo $i; ?>" value="<?php 
	   $ab= $ratVal*$row['reciveqty'];
	   if($row['disc_type']=='Amount')
	   {
	   echo $result = $ab-$curId;
	   }
	   else
	   {
	   $resultMid = ($ab*$curId)/100;
	   echo $result = $ab-$resultMid;
	   }
	   ?>" name="basic[]" readonly/></td>
       <td><input name="itemCurrency[]" type="hidden" id="itemCurrency_<?php echo $i; ?>" value="<?php echo $curId =$row['currency']; 
		?>" size="8" readonly />
		<input name="itemCurrencyread[]" type="text" id="itemCurrencyname_<?php echo $i; ?>" value="<?php echo $s->getField('currency_master','id',$curId,'abbreviation');
		?>" size="8" readonly/>
	</td>
      </tr>
      <?php $i++; }	 ?>
      <input type="hidden" name="countval2" value="<?php echo $i; ?>"  id="count"/>
    </table>
</div>
 <div align="right" id="charges4">	
		<table width="100%">
			<tr>
			<td class="tabledata1" colspan="4">
		<table width="100%" cellpadding="3" cellspacing="0" border="1">
			<tr class="row1">
				<td valign="top" width="50%">
				<table width="100%" cellpadding="3" cellspacing="0" border="0">
				<tr class="row1">
				<td class="tabledata1"><strong>Ledger</strong></td>
				<td>
				<select name="ledger" id="ledger" style="width:200px;">
				<option value="000">---Select Ledger---</option>
				<?php
				$data1=array();				
				$SQLP=DB_query("SELECT GroupId FROM accountgroupmaster where GroupName='Purchase Accounts' or 
				GroupName='Fixed Assets'",$db);
				while($row1=DB_fetch_array($SQLP))
				{
				$data1[]=$row1['GroupId'];
				}
				$data2=implode("','",$data1);
				
				
									$GPId=DB_fetch_array($SQLP);
									$ledger_sql=DB_query("select AccountsID, AccountName from accountledger 
									where UnderGroup in('".$data2."') ORDER BY AccountName ASC",$db);
				while($ledger_row=DB_fetch_array($ledger_sql))
				{
				?>
				<option value="<?php echo $ledger_row['AccountsID'];?>"<?php echo ($ledger_row['AccountsID']==$_REQUEST['ledger']?'selected':'')?>><?php echo $ledger_row['AccountName'];?></option>
				<?php } ?>
				</select></td>
				</tr>
				<tr class="row1">
				<td class="tabledata1"><strong>Remarks If Any</strong></td>
				<td>
				<textarea name="remarks" id="remarks" style="width:200px;"><?php echo $_REQUEST['remarks'];?></textarea></td>
				</tr>
				  <tr class="row1">
					<td class="tabledata1"><strong>Excise Effect</strong></td>
					<td><select name='Excise_Effect' style="width:200px;">
					<option value="0">---</option>
					<option value="RG-23A"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23A')?'selected':''?>  >RG 23A &Iota; &Iota;nd</option>
						<option value="RG-23C"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23C')?'selected':''?>  >RG 23C &Iota; &Iota;nd</option>
						<option value="modvat"  <?php echo ( $mrn_row['Excise_Effect']=='modvat')?'selected':''?>  >Mod Vat</option>
					</select>&nbsp;</td>
				  </tr>
				  <tr class="row1">
				  <td class="tabledata1"><strong>Form Type</strong></td>
				  <td><select  name="form_type" id="form_type" style="width:200px; height:20px;">
				  <option value="">Select</option>
				  <?php
				 $formSql=DB_query("Select * from form_type_master",$db);
				while($formRow=DB_fetch_array($formSql))
				{
				?>
				  <option value="<?php  echo $formRow['id']?>"<?php echo ($formType==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option>
				  <?php }?>
				</select></td>
				  </tr>
 				 </table>
				</td>
				<td>
			  <table width="100%" border="0" cellspacing="2" cellpadding="2">

                <tr>
                  <td><strong>TOTAL BASIC AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onFocus="cal_totalamount()" value="<?php $s->getField('direct_po_details','id',$row['details_id'],'dis_per');
				  ?>"/></td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><select name="pckg_ledger" style="width:100px;" onchange="calcPackagingdDC(this.value)">
				  	<?php 
				  $pckLedger=DB_query("Select * from accountledger where ledgertype='pckcharge'",$db);
				  while($pckLedgerRow=DB_fetch_array($pckLedger))
				  {?>
				  <option value="<?php echo $pckLedgerRow['AccountsID'];?>"><?php echo $pckLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>			  
				  <input name="pkg_charges" id="pkg_charges" readonly type="text" size="28"/></td>
                </tr>
				<tr>
                  <td><strong>Total Excise Amt</strong> </td>
                  <td><select name="tot_excise_amt" id="exciseDutyTot" style="width:120px;" onChange="claculateExcise2(<?php echo $i; ?>,this.value)" onFocus="checkexiseflag1(<?php echo $i; ?>)">
	<option value="">Select</option>
	<?php 
	$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
	while($excise_row=DB_fetch_array($excise_sql))
	{
	$c='';
	if($Excise_Duty==$excise_row['id'])
	$c='selected';
	?>
	<option value="<?php echo $excise_row['id'];?>"<?php echo $c; ?>><?php echo $excise_row['caption'];?></option>
	<?php 	
	}
	?> 
	</select><div id="exciseIdTot">
	<input name="excise_perc" id="ExcisePercentageTot" type="text" value="<?php echo $ExcisePercentage;?>"  style="width:35px;;"  /> 
	<input name="exciseValue" id="exciseValueTot" type="text" value="" style="width:70px;" onFocus="calculateExciseDuty2(<?php echo $i; ?>)" />
	</div></td>
                </tr>
				<tr>
                  <td><strong>Total E.Cess Amt</strong> </td>
                  <?php 
	$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
	$k=1;
	while($cessRow=DB_fetch_array($cessSql))
	{
	$caption[$k]=$cessRow['caption']; 
	
	$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
	while($rate_row=DB_fetch_array($rate_sql))
	{
	$rate[$k]=$rate_row['def_rate'];
	}
	$k++;
	} 
	?>
	<td><input name="e_cess_perc" id="ECessPercentageTot" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly   />
	<input name="tot_ecess_amt" id="ECessValueTot" type="text" value="<?php echo $Edu_Cess;?>"  style="width:70px;" readonly onFocus="calculateECess2()"/></td>
                </tr>
				<tr>
				<td><strong>Total SE.Cess Amt</strong> </td>
				<td><input name="sahecess_per" id="SAHCessPercentageTot" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/>
	<input name="tot_sahecess_amt" id="SAHCessValueTot" type="text" value="<?php echo $SHE_Cess;?>"  style="width:65px;" onFocus="calculateSAHCess2()"/></td>
                </tr>
				 <tr>

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

                  <td><input name="add_chargess" id="additionalCharges1" type="text" value="" size="25" style="width:100%;" /></td>

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

                  <td><input type="text" name="tot_excise_duty_amt" id="tot_excise_duty_amt3" size="5" onFocus="calcexciseduty3(this.value)" /></td>

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

                  <td><input type="text" name="tot_taxable_amt" id="tot_taxable_amt3" size="5" onFocus="calctaxamt3(this.value)" /></td>

                </tr>

                <tr>

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

                  <?php

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


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

     	?>

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

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

                  <?php 

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

			?>

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

                  <?php } ?>

              </select></td>

 

              </tr>

              <tr>

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

              <td><div id="taxval3">

                  <input type="text" name="taxvalue" id="taxvalue2" style="width:100%;" value="" readonly="true"/>

              </div>



	</td>

                </tr>

                <tr>

                  <td><strong>Surcharge Amount</strong> </td>
                  <td><select name="surcharge_ledger" id="sur_oct_per3" style="width:100px;" onchange="cal_grandamountssur()" >
				  <?php 
				  $surLedger=DB_query("Select * from accountledger where ledgertype='surcharge'",$db);
				  while($surLedgerRow=DB_fetch_array($surLedger))
				  {?>
				  <option value="<?php echo $surLedgerRow['AccountsID'];?>"><?php echo $surLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>
				  <input name="sur_oct_amt" type="text" id="sur_oct_amt3" value="" style="width:100px;" /></td>

                </tr>

                <tr>

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

                  <td><select name="freight_ledger" id="TotalCharge" style="width:100px;" onchange="cal_grandamounts3()">
				  	<?php 
				  $frLedger=DB_query("Select * from accountledger where ledgertype='freight'",$db);
				  while($frLedgerRow=DB_fetch_array($frLedger))
				  {?>
				  <option value="<?php echo $frLedgerRow['AccountsID'];?>"><?php echo $frLedgerRow['AccountName'];?></option>
				  <?php 	
				  }
				  ?>
				  </select>
				  <input type="text" name="freight" id="TotalCharge1" style="width:100px;"/>
				  
				  </td>

                </tr>

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

                  <td><input type="text" name="loadings" onkeyup="cal_grandamounts3()" id="loading1" style="width:100%;" value=""/></td>

                </tr>


                <tr>

				<td><strong>Grand Total</strong></td>

                  <td>
				  <input type="text" name="grandtotals" id="GrandTotal" readonly onFocus="cal_grandamounts3()"  size="12" value=""/>
				  <input type="hidden"  id="orig_grand_tot" value=""/>&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><input type="text" name="roundVal1" id="roundVal1" size="5" /></td>

                </tr>

              </table>
		    </td>
		</tr></table>
		
   </table>
</div>
<?php
} ?>