<?php
$PageSecurity = 2;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
if($_REQUEST['site']!='')
{
$sql="SELECT * FROM clientmaster where client_code='".$_REQUEST['site']."' ";
$result=DB_query($sql,$db);
$row=DB_fetch_array($result);
?>
<table  border="0" cellspacing="2" cellpadding="5" align="center">
         
      
	  	  <tr>
        <th >Sr No.</th>
        <th>Item Name</th>
        <th>Expected Order</th>
         <th>Confirm  Order</th>
         <th>Rate/1000</th>
           <th>Confirm Value</th>
             <th>Expect Value</th>
        </tr>
	  	<?php
	  	$itmearray=array();
	  	$itemarray=explode(',',$row['assigned_items']);
		$j=1;
		for($k=0;$k<count($itemarray);$k++)
		{
		$itemcode=$s->getField('item_master','id',$itemarray[$k],'StockID');					
		$sql1="SELECT sum(Quantity) FROM salesorder_details INNER JOIN salesorder ON(salesorder_details.masterId = salesorder.id)
	           WHERE salesorder_details.ItemCode='".$itemcode."' and client='".$row['client_code']."'";
	 $data=DB_query($sql1,$db);
	 $datarow=DB_fetch_array($data);
	 $sql2="SELECT sum(pricePer) FROM salesorder_details INNER JOIN salesorder ON(salesorder_details.masterId = salesorder.id)
	  WHERE salesorder_details.ItemCode='".$itemcode."'"; 
	  $data3=DB_query($sql2,$db);
	 $datarow2=DB_fetch_array($data3);
	 $sql2="SELECT sum(valueAfterDisc) FROM invoice_details INNER JOIN invoice ON(invoice_details.invoiceid = invoice.invoice_id) WHERE invoice_details.ItemCode='".$itemcode."' and client_id='".$row['id']."'";
	  $data3=DB_query($sql2,$db);
	  $data3sql=DB_fetch_array($data3);	
	   ?>
	   <?php if(count($itemarray)==1)
	   {?>
	   	<tr><td colspan="7"><strong style="color: #12345"> No Records</strong></td></tr>
	   <tr height="15px"><td colspan="7">&nbsp;</td></tr>
	   	<?php }
	   	else {?>
      <tr>
        <td ><?php echo $j; ?><input type="hidden" name="count1[]" value="<?php echo $row['id']; ?>"  />
        	
        </td>
       <td ><?php echo$item=$s->getField('item_master','id',$itemarray[$k],'item_name'); ?>
       	<?php echo $item1=$s->getField('item_master','id',$itemarray[$k],'StockID'); ?>
       	<input type="hidden" name="item[]" value="<?php echo $item1; ?>" />
      <td><input type="text" name="expected_order[]"  value=""/></td>
       <td><input type="hidden" name="quantity[]" value="<?php echo $datarow['sum(Quantity)']; ?>">
       	<?php echo $datarow['sum(Quantity)']; ?></td>
        <td><?php echo $datarow2['sum(pricePer)']?>
        	<input type="hidden" name="priceper[]"  value="<?php echo $datarow2['sum(pricePer)']?>"></td>
         <td><?php echo	$data3sql['sum(valueAfterDisc)']; ?>
         	<input type="hidden" name="confirmvalue[]" value="<?php echo $data3sql['sum(valueAfterDisc)']; ?>" />
         </td>
      <td><input type="text" name="allocated_budget[]" value="" />
      	
      	  </td>
      </tr>
       <tr height="15px"><td colspan="7">&nbsp;</td></tr>
     <?php $j++; }  }  ?>
   
    </table>
<?php } ?>
