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


if($_REQUEST['GrnType']==1 && $_REQUEST['type']=='Consolidated')
{ ?>
  <div id="importPo3" style="width:950px;overflow:auto;">
    <table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
      <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>Pending QTY</strong></td>
        <td class="tabledata"><strong>Batch No.</strong></td>
        <td class="tabledata"><strong>QTY AS PER BILL </strong></td>
        <td class="tabledata"><strong>QTY Recieved</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" id ="hideArea16">Dis. Type</td>
        <td class="tabledata" id ="hideArea15">Dis. % <br />
          or amt.</td>
        <td class="tabledata" id ="hideArea14">Final<br  />
          Dis. Amt.</td>
        <td class="tabledata" id ="hideArea13">Discounted Amount</td>
        <td class="tabledata" id ="hideArea12">Basic<br />
          Amt.</td>
      </tr>
      <?php 
$i=0;
$sql=DB_query("select * from direct_po_details where parent_id='".$_REQUEST['po']."' and status='Pending'",$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');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	 //$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	//where order_no='".$_GET['orderno']."' and mst_itemid='".$row['mst_itemid']."'";
	  $check_last_mrn="Select qty from direct_po_details 
	where parent_id='".$_REQUEST['po']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	$check_last_mrn1="Select sum(reciveqty) from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id 
	where addmrn.PO_WO_MTO='".$_REQUEST['po']."' and addmrnqty.mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
	
	$last_mrn_row1=DB_fetch_array($last_mrn_res1);
	 $last_mrn_row1['sum(reciveqty)'];
	if($last_mrn_row['qty']>=$last_mrn_row1['sum(reciveqty)'])
	{
		$pending_qty=$last_mrn_row['qty']-($last_mrn_row1['sum(reciveqty)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['qty'];
	}	
	
$oldCur = $row['currency'];
?>
      <tr bgcolor="#c1c1c1">
        <td><?php echo $i+1;?></td>
        <td><?php echo $itemcode;?>
           <input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="text" readonly="" id="mst_itemid_<?php echo $i; ?>" name="details_id[]" size="15" value="<?php echo $row['id']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" 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['qty']; ?>
              <input name="poqty[]" type="hidden" id="poqty[]" value="<?php echo $poqty;?>" size="10"/></td>
        <td><?php   echo $pending_qty;?>
              <input type="hidden" name="pending_qty[]" id="pending_qty[]" value="<?php echo $pending_qty;?>" />
          </td>
        <td><input type="text" name="batch_no[]" id="batch_no[]" value="" /></td>
        <td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
          </td>
        <td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i; ?>"  size="8"/></td>
          <td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i; ?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" 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['rate'];?>"  size="8" readonly="true"/>
          </td>
        <td><input name="itemamount[]" type="text" id="itemamount_<?php echo $i; ?>" value="" onfocus="calculateTotalPrice(this.id)"  size="8"/>
          </td>
        <td class="tabledata"><select style="width:80px;" name="DiscountType1[]" id="PerAmo_<?php echo $i; ?>">
              <option value="Amount" <?php echo ($row['dis_type']=='Amount')?'selected':''?>>Amount</option>
              <option value="PercentAmt"<?php echo ($row['dis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
        <td id ="hideArea2"><input type="text" style="width:40px" name="discount[]" id="Discount_<?php echo $i;?>" onblur="DiscountAmount(this.value,this.id)" value="<?php echo $row['dis_per'];?>" /></td>
        <td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc_<?php echo $i; ?>"  readonly="true" style="width:100%;" /></td>
          <td class="tabledata" id ="hideArea3"><input type="text"  id="NetRate_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" readonly/></td>
        <td class="tabledata"><input type="text" style="width:70px" id="basic_<?php echo $i;?>" name="basic[]" readonly/></td>
      </tr>
      <?php $i++; }	 ?>
      <input type="hidden" name="countval" value="<?php echo $i; ?>"  id="count"/>
    </table>
  </div>	
  <div style="clear:both"></div>
<div align="right" id="charges1">			
			<table width="40%">
			<tr><th>
		      <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_amounts" 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" readonly="true"/>
				  <select style="width:80px;" name="tot_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"  
				  onblur="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><input type="text" name="pkg_percs" id="pkg_perc" value="<?php echo $venddata['pkg_per']; ?>" size="5" onkeyup="calcPackagingd(this.value)" /><input name="pkg_chargess" id="pkg_charges" type="text" value="" size="28"  
				  onfocus="calcPackagingd()" /></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_dutys" 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_totals" 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/ Insurance</strong> </td>
                  <td><input type="text" name="tot_freights" id="TotalCharge2" style="width:100%;" value="<?php echo $venddata['totalcharge']; ?>"     /></td>
                </tr>
				<tr>
                  <td><strong>Loading/Unloading</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="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>
		     </th>
		<td>		</td>
		</tr>
			</table>
</div>
 <?php
}
elseif($_REQUEST['GrnType']==1 && $_REQUEST['type']=='Itemwise')
{ ?>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>
 <div id="importPo1" style="width:950px;overflow:auto;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<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>Pending QTY</strong></th>
	<th class="tabledata"><strong>Batch No.</strong></th>
	<th class="tabledata"><strong>QTY AS PER BILL </strong></th>
	<th class="tabledata"><strong>QTY Recieved</strong></th>
	<th class="tabledata"><strong>Short Quantity</strong></th>
	<th class="tabledata"><strong>Rate</strong></th>
	<th class="tabledata"><strong>Amount</strong></th>
	<th class="tabledata"><strong>Dis. Type</strong></th> 
	<th class="tabledata"><strong>Dis. % <br />or amt</strong>.</th>
	<th class="tabledata"><strong>Final<br  />Dis. Amt.</strong></th>
	<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 direct_po_details where parent_id='".$_REQUEST['po']."' and status='Pending'",$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');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	//$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	//where order_no='".$_GET['orderno']."' and mst_itemid='".$row['mst_itemid']."'";
	 $check_last_mrn="Select qty from direct_po_details 
	where parent_id='".$_REQUEST['po']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	$check_last_mrn1="Select sum(reciveqty) from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id 
	where addmrn.PO_WO_MTO='".$_REQUEST['po']."' and addmrnqty.mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
	
	$last_mrn_row1=DB_fetch_array($last_mrn_res1);
	 $last_mrn_row1['sum(reciveqty)'];
	if($last_mrn_row['qty']>=$last_mrn_row1['sum(reciveqty)'])
	{
		$pending_qty=$last_mrn_row['qty']-($last_mrn_row1['sum(reciveqty)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['qty'];
	}	
?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="text" readonly="" id="mst_itemid_<?php echo $i; ?>" name="details_id[]" size="15" value="<?php echo $row['id']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" 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['qty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="<?php echo $row['batch_no'];?>" /></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" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i; ?>"  size="8" value="<?php echo $row['reciveqty']; ?>"  /></td>
	<td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i; ?>" value="<?php echo  $row['short_accessid'];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
	<td><?php //echo $row['rate'];?>
	<input name="itemrate[]" type="rext" id="itemrate_<?php echo $i; ?>" readonly="true"  size="8" value="<?php echo  $row['rate'];?>"/>
	</td>
	<td>
	<input name="itemamount[]" type="text" id="itemamount_<?php echo $i; ?>" onfocus="calculateTotalPrice(this.id)"  size="8" readonly="true" value="<?php echo $row['itemamount'];?>"/>
	</td>
	<td class="tabledata"><select style="width:80px;" name="DiscountType1[]" id="PerAmo_<?php echo $i; ?>">
            <option value="Amount"<?php echo ($row['dis_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row['dis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td><input type="text" style="width:40px" name="discount[]" id="Discount_<?php echo $i;?>" onblur="DiscountAmount(this.value,this.id)" value="<?php echo $row['dis_per'];?>" /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc_<?php echo $i; ?>"  readonly="true" style="width:100%;" onFocus="Check(this.value)" value="<?php echo $row['discounted_amount1'];?>"/></td> 
		<td class="tabledata"><input type="text"  id="NetRate_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" value="<?php echo $row['NetRate1'];?>" readonly/></td>
		<td><input name="itemCurrency[]" type="hidden" id="itemCurrency_<?php echo $i; ?>" value="<?php echo $row['currency']; 
		?>" size="8" readonly="true"/>
		<input name="itemCurrencyread[]" type="text" id="itemCurrencyname_<?php echo $i; ?>" value="<?php echo $s->getField('currency_master','id',$row['currency'],'abbreviation');
		?>" size="8" readonly="true"/>
	</td>
	<td class="tabledata"><select style="width:80px;" name="conv_curr[]" onchange="ajax_cur_rate(this.value,<?php echo $i; ?>);" id="conv_curr_<?php echo $i; ?>">
	<option value="">--Select--</option>
			<?php $curr_sql=DB_query("Select * from currency_master",$db);
			while($curr_row=DB_fetch_array($curr_sql))
			{ 
			$convRate=$curr_row['']; ?>
            <option value="<?php echo $curr_row['id']; ?>"<?php echo ($row['conv_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" value="<?php echo $row['conv_rate'];?>"/></td>
		<td class="tabledata"><input type="text" style="width:70px" 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 ($row['Excise_type']=='Amount')?'selected':''?>>Yes</option>
	<option value="2"<?php echo ($row['Excise_type']=='Amount')?'selected':''?>>No</option>
</select></td>
	<td class="tabledata"><select name="Excise_Duty1[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;"    onchange="claculateExcise(this.id,this.value)" 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['id'];?>"<?php echo ($row['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;?>" readonly="" onfocus="checkduty(this.id)" name="duty_amount[]" style="width:70px;" onblur="cal_custom_total(this.id)" value="<?php echo $row['duty_amount_1'];?>"/></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" 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;" onfocus="cal_grandtotal(this.id);" value="<?php echo $row['TotalAmount1'];?>" onblur="cal_cvd_total(this.id);"/></td>
		<td class="tabledata"><input type="text" id="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;" onblur="cal_ecess_total(this.id);" value="<?php echo $row['custom_ecess'];?>" onfocus="cal_e_cess1(this.id);" / ></td>
		<td class="tabledata"> <input type="text" readonly id="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);" value="<?php echo $row['custom_sec_ecess'];?>"  onfocus="cal_esec_cess1(this.id);" / ></td>
		<td class="tabledata"><input type="text" readonly id="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;" value="<?php echo $row['adduty'];?>" 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="40%">
			<tr><th>
		      <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_amounts" id="total_item_amount12" style="width:100%;" onfocus="cal_totalamount12()" />
				
				  </td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_percs" id="pkg_perc" size="5" onkeyup="calcPackaging12(this.value)" /><input name="pkg_chargess" id="pkg_charges" type="text" size="28"  
				  onfocus="calcPackaging1()" /></td>
                </tr>
                <tr>
                  <td><strong>Custom Duty</strong> </td>
              <td><input type="text" name="custom_dutys" id="custom_duty" style="width:100%;" /></td>
              </tr>
              <tr>
              	<td><strong>CVD</strong></td>
              <td><div id="taxval">
                  <input type="text" name="cvd_totals" id="cvd_total" style="width:100%;"/>
              </div>

	</td>
                </tr>
                <tr>
                  <td><strong>Custom E.Cess</strong> </td>
                  <td><input type="text" name="custom_ecesss" id="custom_ecess" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Custom SE.Cess</strong> </td>
                  <td><input type="text" name="custom_sec_ecesss" id="custom_sec_ecess" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Additional Duty </strong> </td>
                  <td><input name="add_chargess" id="additionalCharges" type="text" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight/Insurance</strong> </td>
                  <td><input type="text" name="tot_freights" id="TotalCharge" style="width:100%;"   /></td>
                </tr>
				<tr>
                  <td><strong>Loading /Unloading</strong> </td>
                  <td><input type="text" name="loadings" id="loading1" style="width:100%;" /></td>
                </tr>
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotals" id="GrandTotal" onfocus="cal_grandamount1()"  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>
		     </th>
		<td>		</td>
		</tr>
			</table>

</div>
<?php
}
elseif($_REQUEST['GrnType']==2 && $_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>
	<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>Pending QTY</strong></td>
	<td class="tabledata"><strong>Batch No.</strong></td>
	<td class="tabledata"><strong>QTY AS PER BILL </strong></td>
	<td class="tabledata"><strong>QTY Recieved</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"><strong>Dis. Type</strong></td>  
	<td class="tabledata"><strong>Dis. % <br />or amt.</strong></td>
	<td class="tabledata"><strong>Final<br  />Dis. Amt.</strong></td>
	<td class="tabledata"><strong>Discounted Amount</strong></td>
	<td class="tabledata" ><strong>Basic<br /> Amount</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 direct_po_details where parent_id='".$_REQUEST['po']."' and status='Pending'",$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');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	//$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
	//where order_no='".$_GET['orderno']."' and mst_itemid='".$row['mst_itemid']."'";
	 $check_last_mrn="Select qty from direct_po_details 
	where parent_id='".$_REQUEST['po']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	$check_last_mrn1="Select sum(reciveqty) from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id 
	where addmrn.PO_WO_MTO='".$_REQUEST['po']."' and addmrnqty.mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
	
	$last_mrn_row1=DB_fetch_array($last_mrn_res1);
	 $last_mrn_row1['sum(reciveqty)'];
	if($last_mrn_row['qty']>=$last_mrn_row1['sum(reciveqty)'])
	{
		$pending_qty=$last_mrn_row['qty']-($last_mrn_row1['sum(reciveqty)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['qty'];
	}	
	

?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="text" readonly="" id="mst_itemid_<?php echo $i; ?>" name="details_id[]" size="15" value="<?php echo $row['id']; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" 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['qty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="" /></td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i; ?>"  size="8"/></td>
	<td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i; ?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
	<td>
	<input name="itemrate[]" type="rext" id="itemrate_<?php echo $i; ?>" readonly="true"  size="8" value="<?php echo  $row['rate'];?>"/>
	</td>
	<td>
	<input name="itemamount[]" type="text" id="itemamount_<?php echo $i; ?>" onfocus="calculateTotalPrice(this.id)"  size="8" readonly="true" value="<?php echo $row['itemamount'];?>"/>
	</td>
	<td class="tabledata"><select style="width:80px;" name="DiscountType1[]" id="PerAmo_<?php echo $i; ?>">
            <option value="Amount" <?php echo ($row['dis_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row['dis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td><input type="text" style="width:40px" name="discount[]" id="Discount_<?php echo $i;?>" onblur="DiscountAmount(this.value,this.id)" value="<?php echo $row['dis_per'];?>" /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc_<?php echo $i; ?>"  readonly="true" style="width:100%;" onFocus="Check(this.value)"/></td> 
		<td class="tabledata"><input type="text"  id="NetRate_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" readonly/></td>
		<td class="tabledata"><input type="text" style="width:70px" id="basic_<?php echo $i;?>" 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_duty[]" 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" value="<?php echo $ExcisePercentage;?>"  style="width:35px;;"  /> 
	<input name="excise_val[]" id="exciseValue_<?php echo $i; ?>" type="text" value="" 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   /><!--onfocus="caldata1(<?php echo $i;?>)"-->
	<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="40%">
			<th>
			  <table width="100%" border="0" cellspacing="2" cellpadding="2">

                <tr>

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

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

               </tr>

              <tr>

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

                  <td><input type="text" name="pkg_percs" id="pkg_perc" value="" size="5" onchange="calcPackaging2(this.value)" /><input name="pkg_chargess" id="pkg_charges" type="text" value="" size="28" /></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 E.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>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_rate2(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="taxvalue" style="width:100%;" value="" readonly="true"/>

              </div>



	</td>

                   </tr>

                <tr>

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

                  <td><input type="text" name="sur_oct_per" id="sur_oct_per"  size="10" onchange="calsuroctamt2(this.value)" value=""/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:60%;" /></td>

                </tr>

                <tr>

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

                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:100%;" value=""/></td>

                </tr>

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

                  <td><input type="text" name="loading" id="loading" style="width:100%;" 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>Grand Total</strong></td>

                  <td>
				  <input type="text" name="grandtotals" id="GrandTotals" onfocus="cal_grandamounts2()"  size="12" value=""/>
				  <input type="hidden"  id="orig_grand_tots" value=""/>&nbsp;<strong>Round Off</strong>&nbsp;
				  <select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded2(this.value)">

				  <option value="">None</option>

				  <option value="+" <?php if($GetRowData['round_off']=='+') echo "selected";?>>+</option>

				  <option value="-" <?php if($GetRowData['round_off']=='-') echo "selected";?>>-</option>

				  </select></td>

                </tr>

              </table>
		     </th>
		<td></td>
		</tr>
			</table>
</div>
<?php 
}
elseif($_REQUEST['GrnType']==2 && $_REQUEST['type']=='Consolidated')
{ ?>
<div id="importPo4" style="width:950px;overflow:auto;">
<table width="232%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<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>Pending QTY</strong></td>
	<td class="tabledata"><strong>Batch No.</strong></td>
	<td class="tabledata"><strong>QTY AS PER BILL </strong></td>
	<td class="tabledata"><strong>QTY Recieved</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" id ="hideArea16">Dis. Type</td>  
	<td class="tabledata" id ="hideArea15">Dis. % <br />or amt.</td>
	<td class="tabledata" id ="hideArea14">Final<br  />Dis. Amt.</td>
	<td class="tabledata" id ="hideArea13">Discounted Amount</td>
	<td class="tabledata" id ="hideArea12">Basic<br /> Amt.</td>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from direct_po_details where parent_id='".$_REQUEST['po']."' and status='Pending'",$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');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	$check_last_mrn="Select qty from direct_po_details 
	where parent_id='".$_REQUEST['po']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	 $check_last_mrn1="Select sum(reciveqty) from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id 
	where addmrn.PO_WO_MTO='".$_REQUEST['po']."' and addmrnqty.mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
	
	$last_mrn_row1=DB_fetch_array($last_mrn_res1);
	 $last_mrn_row1['sum(reciveqty)'];
	if($last_mrn_row['qty']!='' && $last_mrn_row1['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['qty']-($last_mrn_row1['sum(reciveqty)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['qty'];
	}		
	

?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />
	<input type="text" readonly="" id="mst_itemid_<?php echo $i; ?>" name="details_id[]" size="15" value="<?php echo $row['id']; ?>" />
	</td>
	<td><?php echo $itemname ?></td>
	<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
	<td><?php   echo $poqty=$row['qty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />
	</td>
	<td><input type="text" name="batch_no[]" id="batch_no_<?php echo $i; ?>" value="" /></td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill3_<?php echo $i; ?>"  size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>
	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty3_<?php echo $i; ?>"  size="8" /></td>
	<td><input name="short_accessid[]" type="text" id="short_accessid3_<?php echo $i; ?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" size="8" readonly="true" onfocus="calculate_poshort3(<?php echo $i ?>);"/></td>
	<td><?php //echo $row['rate'];?>
	<input name="itemrate[]" type="text" id="itemrate3_<?php echo $i; ?>" value="<?php echo  $row['rate'];?>"  size="8" readonly="true"/>
	</td>
	<td><?php //echo $row['rate']*$poqty;?>
	<input name="itemamount[]" type="text" id="itemamount3_<?php echo $i; ?>" value="" onfocus="calculateTotalPrice3(this.id)"  size="8"/>
	</td>
	 <td class="tabledata" id ="hideArea1"><select style="width:80px;" name="DiscountType1[]" id="PerAmo3_<?php echo $i; ?>">
            <option value="Amount" <?php echo ($_POST['PerAmo']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($_POST['PerAmo']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		  <td id ="hideArea2"><input type="text" style="width:40px" name="discount[]" id="Discount3_<?php echo $i;?>" onblur="DiscountAmount4(this.value,this.id)" value="<?php echo $discount;?>" /></td>
	<td class="tabledata"><input type="text" name="discounted_amount1[]" id="perc3_<?php echo $i; ?>"  readonly="true" style="width:100%;" /></td>
		<td class="tabledata"><input type="text"  id="NetRate3_<?php echo $i;?>" name="NetRate1[]" style="width:70px;" readonly/></td>
		<td class="tabledata"><input type="text" style="width:70px" id="basic3_<?php echo $i;?>" name="basic[]" readonly/></td>
</tr>
  <?php $i++; }	 ?>
  <input type="hidden" name="countval3" value="<?php echo $i; ?>"  id="count"/>
</table>
 </div>
 <div align="right" id="charges4">	
		<table width="40%">
			<tr><th>
			  <table width="100%" border="0" cellspacing="2" cellpadding="2">

                <tr>
                  <td><strong>TOTAL BASIC AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amounts" id="total_item_amount4" style="width:100%;" onfocus="cal_totalamount3()" value=""/></td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_percs" id="pkg_perc4" value="" size="5" onchange="calcPackaging4(this.value)" /><input name="pkg_chargess" id="pkg_charges4" type="text" value="" size="28" /></td>
                </tr>
				<tr>
                  <td><strong>Total Excise Amt</strong> </td>
                  <td><select name="tot_excise_amt11" 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="tot_excise_amt" 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 E.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;" readonly onfocus="calculateSAHCess2()"/></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" value="" 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" value="" 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><input type="text" name="sur_oct_per" id="sur_oct_per3"  size="10" onchange="calsuroctamt3(this.value)" value=""/><input name="sur_oct_amt" type="text" id="sur_oct_amt3" value="" style="width:60%;" /></td>

                </tr>

                <tr>

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

                  <td><input type="text" name="tot_freight" id="TotalCharge1" style="width:100%;" value=""/></td>

                </tr>

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

                  <td><input type="text" name="loading" id="loading1" style="width:100%;" value=""/></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>Grand Total</strong></td>

                  <td>
				  <input type="text" name="grandtotals" id="GrandTotals3" onfocus="cal_grandamounts3()"  size="12" value=""/>
				  <input type="hidden"  id="orig_grand_tots3" value=""/>&nbsp;<strong>Round Off</strong>&nbsp;
				  <select name="round_off" id="round_off1" style="width:50px; height:20px" onchange="calcRounded3(this.value)">

				  <option value="">None</option>

				  <option value="+" <?php if($GetRowData['round_off']=='+') echo "selected";?>>+</option>

				  <option value="-" <?php if($GetRowData['round_off']=='-') echo "selected";?>>-</option>

				  </select></td>

                </tr>

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