<?php 
ob_start();
$PageSecurity = 4;
$PageName = 'Purchase Requisition';
include('includes/session.inc');
include('includes/function_lib.php');


$IndentId=$_REQUEST['IndentId'];
$VendorId=$_REQUEST['vendorId'];

//echo "SELECT id,indentPrno,mapped_vendor,quotaion_status FROM indentpr_mapping where indentPrno='".$IndentId."' and find_in_set($VendorId,mapped_vendor) and quotaion_status=0 and id='".$_REQUEST['mapid']."'";
$SqlGetParantId=DB_query("SELECT id,indentPrno,mapped_vendor,quotaion_status FROM indentpr_mapping where indentPrno='".$IndentId."' and find_in_set($VendorId,mapped_vendor) and quotaion_status=0 and id='".$_REQUEST['mapid']."'",$db);
$GetIndentPrId=DB_fetch_array($SqlGetParantId);
$SQlInDentDetails=DB_query("SELECT * FROM indentpr_mapping_details where parantId='".$GetIndentPrId['id']."' and qty!=''" ,$db);?>
<input type="hidden" name="indentId" value="<?php echo $GetIndentPrId['id']; ?>" />
<input type="hidden" name="mapped_Vendors" value="<?php echo $GetIndentPrId['mapped_vendor']; ?>" />
<table width="140%" border="1" cellspacing="0" cellpadding="3" style=" border:1px solid #333333;">
<tr bgcolor="#d4d4d4">
	<td class="tabledata">SrNo.</td>
	<td class="tabledata">Item Name</td>
	<td class="tabledata">UOM</td>
	<td class="tabledata">Qty</td>
	<td class="tabledata">Quoted Rate </td>
	<td class="tabledata">Currency </td>
	<td class="tabledata">Total Price</td>
	<td class="tabledata">Discount Type</td>
	<td class="tabledata">Discount Amt</td>
	<td class="tabledata">Discounted Amount</td>
	<td class="tabledata">Sub Total</td>
	<!--<td class="tabledata">Special Discount Type</td>
	<td class="tabledata">Special Discount Amt</td>
	<td class="tabledata">Special Discounted Amt</td>-->
	<td class="tabledata">Basic Amount</td>
	<td class="tabledata">Excise flag</td>
	<td class="tabledata">Excise</td>
	<td class="tabledata">Excise Value</td>
	<td class="tabledata">E-Cess</td>
	<td class="tabledata">E-Cess Value</td>
	<td class="tabledata">SAH-E Cess</td>
	<td class="tabledata">SAH-E Cess Value</td>
	<td class="tabledata">Excise<br />Amt.</td>
	<td class="tabledata">Total<br /> Amt.</td>
</tr>
<?php $i=0; while($InPrDetails=DB_fetch_array($SQlInDentDetails)){ 
$ItemName=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'item_name');
$UnitId=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'mst_unitid');
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$UnitId."'",'unitname');?>
<tr class="rowdata">
	<td><?php echo $i+1; ?></td>
	<td><?php echo $ItemName; ?><input type="hidden" name="mst_itemid[<?php echo $i;?>]" id="mst_itemid" value="<?php echo $InPrDetails['mst_itemid'];?>"></td>
	<td><?php echo $UnitName; ?></td>
	<td><?php echo $InPrDetails['qty'];?><input type="hidden" name="Quantity[<?php echo $i;?>]" id="Quantity_<?php echo $i;?>"  value="<?php echo $InPrDetails['qty'];?>"
	/></td>
        <td><input style="width:100%;" onkeypress="javascript:return isNumberKey(this,event)" type="text" name="Rate[<?php echo $i;?>]" id="Rate_<?php echo $i;?>" onKeyUp="calculateTotalPrice(<?php echo $i;?>)"/></td>
	<td><select name="currency[]" style="width:100%;" >
	
	<?php 
	$sql_currency=DB_query("select * from currency_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row_currency=DB_fetch_array($sql_currency))
	{
	?>
	<option value="<?php echo $row_currency['id']; ?>"><?php echo $row_currency['abbreviation']; ?></option>
	<?php } ?>
	</select></td>
	<td><input style="width:100%;" type="text" name="totalPrice[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" readonly="true"/></td>
	<td><select style="width:100%;" name="DiscountType[<?php echo $i;?>]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount">Amount</option>
            <option value="PercentAmt">Percent Amt</option>
        </select></td>
	<td><input type="text" style="width:100%;" onkeypress="javascript:return isNumberKey(this,event)" name="Discount[<?php echo $i;?>]" id="Discount_<?php echo $i;?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" /></td>
	<td><input type="text" name="discounted_amount[<?php echo $i;?>]" id="perc_<?php echo $i;?>"  readonly="true" style="width:100%;" onfocus="Check(this.value,<?php echo $i;?>)"/></td>
	<td><input type="text"  id="NetRate_<?php echo $i;?>" name="NetRate[<?php echo $i;?>]" style="width:100%;" readonly/></td>
	<!--<td><select style="width:80px;" name="SpecialDicount_Type[<?php echo $i; ?>]" id="Perspc_<?php echo $i;?>">
    <option value="Amount" >Amount</option>
     <option value="PercentAmt">Percent Amt</option>
     </select></td>
	<td><input type="text" name="SpecialDiscount[<?php echo $i; ?>]" id="SpecialDiscount_<?php echo $i; ?>" style="width:70px;" onblur="DiscountAmountdpc(this.value,<?php echo $i; ?>)" /></td>
	<td><input type="text" name="SpecialDiscounted_Amt[<?php echo $i; ?>]" id="Specialperc_<?php echo $i; ?>"  style="width:70px;" onfocus="check1(this.value,<?php echo $i; ?>)"/></td>-->
	<td><input type="text" style="width:100%;" id="basic_<?php echo $i; ?>" name="basic_Amt[<?php echo $i; ?>]" readonly/></td>
	<td><select name="Excise_type[<?php echo $i;?>]" style="width:100%;" id="hid_billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,<?php echo $i; ?>,this.value)">
	<option value="">Select</option>
	<option value="NonExcisable">NonExcisable</option>
	<option value="Excisable">Excisable</option>
	<option value="IncludeTax">IncludeTax</option>
	</select></td>
	<td><select name="Excise_Duty[<?php echo $i; ?>]" id="exciseDuty_<?php echo $i; ?>" style="width:100%;" onchange="claculateExcise(this.id,this.value)" onfocus="checkexiseflag(<?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))
			{
			$g='';
			if($Excise_Duty==$excise_row['id'])
			{$g='selected';}	?>
				 <option value="<?php echo $excise_row['id']; ?>"><?php echo $excise_row['caption']; ?></option>
			<?php }?>
    	    
  	       </select>
  	      	<input name="ExcisePercentage[<?php echo $i; ?>]" id="ExcisePercentage_<?php echo $i; ?>" type="hidden" style="width:100%;" readonly />
	</td>
	<td>
	<input name="exciseValue[<?php echo $i; ?>]" id="exciseValue_<?php echo $i; ?>" type="text" style="width:100%;" />
	</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++;
			 } 	
			 
		$cessLedgerSql1=DB_query("Select * from excise_tax where ledgertype='cess' LIMIT 0,1",$db);	 
		$cessLedgerSql2=DB_query("Select * from excise_tax where ledgertype='cess' LIMIT 1,1",$db);	 	 
			 
			 ?>
	<td><select name="Cess_ID[<?php echo $i; ?>]" id="cess_ID1_<?php echo $i; ?>" onchange='calEcessonchange(this.id,this.value)' style="width:100%;">
	<option value=''>Select</option>
	<?php while($cessLedger1=DB_fetch_array($cessLedgerSql1)){?>
		<option value="<?php echo $cessLedger1['id'];?>"><?php echo $cessLedger1['caption'];?></option>
	<?php }?>
	</select>
	<input name="ECessPercentage[<?php echo $i; ?>]" id="ECessPercentage_<?php echo $i; ?>" type="hidden" value="<?php echo $rate[1]; ?>" style="width:100%;" readonly />
	</td>
	<td>
	<input name="ECessValue[<?php echo $i; ?>]" id="ECessValue_<?php echo $i; ?>" type="text" style="width:100%;" readonly />
	</td>
	<td><select name="SHECess_ID[<?php echo $i; ?>]" id="cess_ID2_<?php echo $i; ?>" style="width:100%;" onchange='calSHEcessonchange(this.id,this.value)'>
	<option value=''>Select</option>
	<?php while($cessLedger2=DB_fetch_array($cessLedgerSql2)){?>
		<option value="<?php echo $cessLedger2['id'];?>"><?php echo $cessLedger2['caption'];?></option>
	<?php }?>
	</select>
	<input name="SAHCessPercentage[<?php echo $i; ?>]" id="SAHCessPercentage_<?php echo $i; ?>" type="hidden" value="<?php echo $rate[2]; ?>" style="width:100%;" readonly/>
	</td>
	<td>
	<input name="SAHCessValue[<?php echo $i; ?>]" id="SAHCessValue_<?php echo $i; ?>" type="text" style="width:100%;" readonly />
	</td>
	<td><input type="text" name="taxable_amt[<?php echo $i; ?>]" id="taxable_amt_<?php echo $i; ?>" style="width:100%;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly/></td>
	<td><input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalAmount[<?php echo $i;?>]" style="width:100%;" readonly  onfocus="cal_grandtotal(<?php echo $i;?>);" value="0"/></td>
</tr>
<?php $i++;}?>

<input type="hidden" name="count" id="count" value="<?php echo $i;?>" style="width:100%;" /> 
</table>