<?php 
session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
global $db;
//echo $_REQUEST['godown'];
$function_filter[]=$_REQUEST['sitecode'];
$function_filter[]=$_REQUEST['godown'];
$function_filter[]=date("Y-m-d");
$function_filter[]=date("Y-m-d");
//print_r($function_filter);
$main_item=$_REQUEST['itemid'];
 $tdata='';

$sql_wo=DB_query("Select id from prd_model_group where CompanyId='".$_SESSION['ACGCompanyId']."' and mst_itemid='".$main_item."'",$db);
$res_wo=db_fetch_array($sql_wo);
$sql1=DB_query("Select mst_itemid from prd_model_sub_group where CompanyId='".$_SESSION['ACGCompanyId']."' and parentid='".$res_wo['id']."'",$db);
if(DB_num_rows($sql1)){
$tdata="<table width='100%' border='1' cellpadding='3' cellspacing='0' style='border-collapse:collapse; border:#666666 solid 1px;'>";
 $tdata.= "<tr class='row1'>";
    $tdata.="<td class='headerl_1'>Sr. No.</td>";
    $tdata.=  "<td class='headerl_2'></td>";
    $tdata.= "<td class='headerl_3'>Part Code</td>";
    $tdata.= "<td class='headerl_4'>Part Name</td>";  
    $tdata.= "<td class='tabledata'>UOM</td>";
    $tdata.= "<td class='tabledata'>Stock Qty</td>";
    $tdata.="<td class='tabledata'>Received Qty </td>";
    $tdata.="<td class='tabledata'>Process </td>";
    $tdata.="<td class='tabledata'>Machine Center </td></tr>";

   
    $tdata.= "<tbody id='dataTable'>";

 while($row1=DB_fetch_array($sql1)){

$sql_item=DB_query("Select id,item_name,StockID,mst_unitid from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$row1['mst_itemid']."'",$db);
$item=db_fetch_array($sql_item);



 $op=openingBalance($function_filter,$item['id']);
								//echo "openingBalance"."<br>";
								
								$in_1=receivedMRN($function_filter,$item['id']);
								
								//echo "receivedMRN"."<br>";
								$out_1=issueSlip($function_filter,$item['id']);
								// echo "issueSlip"."<br>";
								$out_2=issueSiteToSite($function_filter,$item['id']);		
								// echo "issuesitetosite"."<br>";
								$in_2=receivedSiteToSite($function_filter,$item['id']);
								// echo " receivesitetosite"."<br>";
								$out_3=issueMatarialReturn($function_filter,$item['id']);
								$out_4=Rgpchallan($function_filter,$item['id']);
								$out_5=Nrgp($function_filter,$item['id']);
								 //$out_6=invoice($function_filter,$myrow['id']);
								 // $out_7=disptch($function_filter,$item['id']);
								$in_3=receivedReturn($function_filter,$item['id']);		 
								//$in_4=return_rejection($function_filter,$myrow['id']);
								$in_4=Rgpreturn($function_filter,$item['id']);
								$in_5=FinishedMR($function_filter,$item['id']);
								 $invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
								
								 $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
								$tot=trim($invalue)-trim($outvalue);
								 $total_current=$tot;
                                                                
  $tdata.= "<tr  class='row1'>";
   $tdata.="<td class='headercol1'><input name='delitem[]' type='checkbox'  id='delitem' /></td>";
 $tdata.="<td class='headercol2'><input  type='hidden' name='itemid[]' id='itemid' readonly=''  value='".$item['id']."' /></td>";
 $tdata.="<td class='headercol3'><input type='text' id='itemcode' name='itemcode[]' value='".$item['StockID']."'/></td>";
 $tdata.="<td class='headercol4'><input type='text' name='desc[]'  id='descriptions'  value='".$item['item_name']."' readonly /></td> ";
 $tdata.="<td class='col1'><input type='text' name='uom[]' id='uom' value='".$s->getField('unitsofmeasure','unitid',$item['mst_unitid'],'unitname')."' readonly  size='30'/></td>";
 $tdata.= "<td class='col1'><input type='text' name='stock[]' id='stock' value='".$total_current."' readonly  size='30'/> </td>";
 $tdata.=  "<td class='col1'><input  type='text' name='reciveqty[]'  id='reciveqty' size='30'   value=''   /></td>";
 $tdata.="<td class='col1'><select name='prodprocess[]' id='prodprocess' >";
$tdata.="<option value='0'>Select</option>";
$sqlp=DB_query("select * from production_process_master",$db);
while($rowp=DB_fetch_array($sqlp))
{
    $tdata.="<option value=".$rowp['id'].">".$rowp['manuf_process_name']."</option>";
}
 $tdata.="</select></td>";
 	 $tdata.="<td class='col1'><select name='machine[]' id='machine' >";
	   $tdata.= "<option value='0'>Select</option>";
            $sqlm=DB_query("select * from machine_center",$db);
	   while($rowm=DB_fetch_array($sqlm))
	   {
     $tdata.="<option value=".$rowm['id'].">".$rowm['name']."</option>";
           }
      $tdata.="</select></td> </tr>";
 }
  $tdata.="</tbody>
</table>";
}
	   
	
echo $tdata;

?>
