<?php 
session_name('CAKEPHP'); session_start();
$PageSecurity = 11;
include('includes/session.inc');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
include("includes/function_lib.php");
include('includes/stockcalculation.php');
$sql=DB_query("select * from dbl_enquiry_form where id='".$_REQUEST['id']."'",$db);
$row1=DB_fetch_array($sql);
extract($row1);
if(isset($_SESSION['dealerid']))
$function_filter[]=$_SESSION['dealerid'];
else
$function_filter[]=$dealer;
$function_filter[]='';
$function_filter[]=$date; 
$function_filter[]=$date; 
?>



<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<th ><strong>S.N.</strong></th>
<th ></th>
<th ><strong>Part Code</strong></th>
<th ><strong>Part Name</strong></th>
<th ><strong> UOM</strong></th>
<th><strong>Stock Qty</strong></th>
<th ><strong>PR Qty </strong></th>
<th ><strong>Order Qty</strong></th>
<th ><strong>Rate</strong></th>
<th ><strong>Sub Amt</strong></th>
<th ><strong>Discount Type</strong></th>
<th ><strong>Discount(%)</strong></th>
<th ><strong>Total Amt</strong></th>
<th><strong>Reserve PO</strong></th>
<th><strong>Delivery Date</strong></th>
</tr>
<?php
$i=0;

$sql=DB_query("select * from dbl_enquiry_details where parent_id='".$_REQUEST['id']."' and type='".$_REQUEST['site']."' and status=0",$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');
$unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname'); 

$op=openingBalance($function_filter,$row['mst_itemid']);
$in_1=receivedMRN($function_filter,$row['mst_itemid']);
$out_1=issueSlip($function_filter,$row['mst_itemid']);
$out_2=issueSiteToSite($function_filter,$row['mst_itemid']);		
$in_2=receivedSiteToSite($function_filter,$row['mst_itemid']);
$out_3=issueMatarialReturn($function_filter,$row['mst_itemid']);
$in_3=receivedReturn($function_filter,$row['mst_itemid']);	
$out_4=Rgpchallan($function_filter,$row['mst_itemid']);
$out_5=Nrgp($function_filter,$row['mst_itemid']);
$in_4=Rgpreturn($function_filter,$row['mst_itemid']);	 
$in_5=FinishedMR($function_filter,$row['mst_itemid']);
$out_6=dispatchsaleorder($function_filter,$row['mst_itemid']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6);
$tot=$invalue-$outvalue;
$stockbalance=$tot;	

if($row['close_qty']!='')
{
$pendingqty=$row['pendingqty']-$row['close_qty'];
}
else
{
$pendingqty=$row['pendingqty'];
}
if($pendingqty!='')
{
$orderqty=$pendingqty;
}
else
{
$orderqty=$row['req_qty'];
}
if($row['type']=='exciable')
{
$exciseamt12=$exciseamt12+$row['amount'];
}
 $rowtype=$s->getField('item_master','id',$row['mst_itemid'],'item_exciable');
 //echo $row['rate'];
if($_REQUEST['action']=='Edit')
{
$rate=$row['rate'];
}
else
{
$rate=$row['price'];
}

//echo $rate;



?>
<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><?php echo $i+1; ?></td>	
<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid" value="<?php echo $row['mst_itemid']; ?>" /></td>
<td class="tabledata"><?php echo $itemcode; ?> <input type="hidden" name="rowid[]" value="<?php echo $row['id']; ?>" /> </td>
<td class="tabledata" style="white-space:nowrap"><?php echo $itemname; ?></td>
<td class="tabledata"><?php echo $unitname; ?>
<input type="hidden" name="type[]" id="type1_<?php echo $i; ?>" value="<?php echo $rowtype; ?>" readonly="readonly" />
</td>
<td class="tabledata"><?php echo $stockbalance; ?></td>
<td class="tabledata"><input type="text" name="prqty[]" value="<?php echo $pendingqty; ?>" id="prqty_<?php echo $i; ?>" style="width:50;" readonly="readonly"/></td>
<td class="tabledata"><input type="text" name="orderqty[]" id="orderqty_<?php echo $i; ?>" style="width:50;"  value="<?php echo $orderqty; ?>" onkeyup="caldispatch(<?php echo $i; ?>)" /></td>
<td class="tabledata"><input type="text" name="rate[]"  id="rate_<?php echo $i; ?>" style="width:50;" onkeyup="calamt(this.value,<?php echo $i; ?>)" value="<?php echo $rate; ?>" readonly /></td>
<td class="tabledata"><input type="text" name="netrate[]"  id="netrate_<?php echo $i; ?>" style="width:50;" value="<?php echo $row['sub_amt']; ?>"  onfocus="calamt1(this.value,<?php echo $i; ?>)"/></td>
<td class="tabledata"><select style="width:80px;" name="PerAmo[]" id="PerAmo_<?php echo $i; ?>">
<option value="Amount" <?php if($row['discount_type']=='Amount') { ?> selected="selected" <?php } ?> >Amount</option>
<option value="PercentAmt" <?php if($row['discount_type']=='PercentAmt') { ?> selected="selected" <?php } ?>>Percent Amt</option>
</select></td>
<td class="tabledata"><input type="text"  name="Discount[]" id="Discount_<?php echo $i; ?>" onblur="DiscountAmount(this.value,<?php echo $i; ?>)" style="width:50;" value="<?php echo $row['discount_per']; ?>" /></td>		  
<td class="tabledata"><input type="text" name="total[]" id="total_<?php echo $i; ?>" style="width:50px;"  readonly="true"
value="<?php echo $row['total']; ?>" 
 /></td>
  <td class="tabledata"><select name="reserve[]" id="reserve_<?php echo $i; ?>" style="width:50px;">
 <option value="Y"<?php if($row['discount_type']=='Y') { ?> selected="selected" <?php } ?>>Yes</option>
 <option value="N" <?php if($row['discount_type']=='N') { ?> selected="selected" <?php } ?>>No</option>
 </select>
 </td>
 <td class="tabledata"><input type="text" style="width:54;" onClick="javascript:NewCal(this.id,'ddmmyyyy')" name="items_date[]" id="items_date_<?php echo $i; ?>"  /></td>
</tr>

<?php $i++; } ?>
<input type="hidden" name="count" id="count" value="<?php echo $i; ?>" />




</table>