<?php $PageSecurity = 11;
include('includes/session.inc');
//include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
if($_REQUEST['site']!='')
{
$sql="Select * from job_card where id='".$_REQUEST['jobcard']."'";
$result=DB_query($sql,$db);
$row=DB_fetch_array($result); 


$sql_process_maintain1=DB_query("select * from daily_process_qty_maintain 
                      where jobcard ='".$_REQUEST['jobcard']."' ",$db);

$sql_process_maintain=DB_query("select * from daily_process_qty_maintain 
                      where jobcard ='".$_REQUEST['jobcard']."' and from_process='".$_REQUEST['site']."' ",$db);
$numrow=DB_num_rows($sql_process_maintain1);
$sql_row_process=DB_fetch_array($sql_process_maintain);
if($numrow==0)
{ 
$totalproduct=DB_query("select sum(prodqty) as prodqty from job_card_item_details where jobid='".$_REQUEST['jobcard']."'",$db);
$row_productqty=DB_fetch_array($totalproduct);
$data4=$row_productqty['prodqty']; 
}
else
{
if($sql_row_process['from_process']==$_REQUEST['site'])
{
$checkpriviousprocess=$s->GetFieldValue("daily_process_qty_maintain","to_process='".$_REQUEST['site']."' and jobcard='".$_REQUEST['jobcard']."'","from_process");
 
 $checkpriviousprocess_status=$s->GetFieldValue("job_process_details","process='".$checkpriviousprocess."' and jobid='".$_REQUEST['jobcard']."'","current_status");
 
if($checkpriviousprocess_status=='h')
{
  $totalproduct=DB_query("select actualqty as prodqty from qc_process 
where jobcard='".$_REQUEST['jobcard']."' and processid='".$checkpriviousprocess."'  and status=h ",$db);
$row_productqty=DB_fetch_array($totalproduct);
}
else if($checkpriviousprocess_status=='f')
{
  $totalproduct=DB_query("select actualqty as prodqty from qc_process 
where jobcard='".$_REQUEST['jobcard']."' and processid='".$checkpriviousprocess."' and  status='f'",$db);
$row_productqty=DB_fetch_array($totalproduct); 
 
}

 else
 { 
$totalproduct=DB_query("select move_qty as prodqty from daily_process_qty_maintain 
where jobcard='".$_REQUEST['jobcard']."' and from_process='".$_REQUEST['site']."' and status=1",$db);
$row_productqty=DB_fetch_array($totalproduct);
 }
$data4=$row_productqty['prodqty']; 
}
else
{ 
  $checkpriviousprocess=$s->GetFieldValue("daily_process_qty_maintain","to_process='".$_REQUEST['site']."' and jobcard='".$_REQUEST['jobcard']."'","from_process");
 
  $checkpriviousprocess_status=$s->GetFieldValue("job_process_details","process='".$checkpriviousprocess."' and jobid='".$_REQUEST['jobcard']."'","current_status");
 
if($checkpriviousprocess_status=='h')
{
 
 
  $totalproduct=DB_query("select actualqty as prodqty from qc_process 
where jobcard='".$_REQUEST['jobcard']."' and processid='".$checkpriviousprocess."'  and status='h' ",$db);
$row_productqty=DB_fetch_array($totalproduct);
}
else if($checkpriviousprocess_status=='f')
{
  $totalproduct=DB_query("select actualqty as prodqty from qc_process 
where jobcard='".$_REQUEST['jobcard']."' and processid='".$checkpriviousprocess."'  and status='f'",$db);
$row_productqty=DB_fetch_array($totalproduct); 
 
}
 else
 { 
$totalproduct=DB_query("select move_qty as prodqty from daily_process_qty_maintain 
where jobcard='".$_REQUEST['jobcard']."' and to_process='".$_REQUEST['site']."' and status=1",$db);
$row_productqty=DB_fetch_array($totalproduct);
 }
$data4=$row_productqty['prodqty']; 

}

}

$data6='';
$data7='';

$sql1=DB_query("select * from job_process_details where jobid='".$_REQUEST['jobcard']."' and process='".$_REQUEST['site']."' ",$db);
while($row1=DB_fetch_array($sql1))
{

$machine=$row1['machine'];
$operator=$row1['operator'];
}

						 
						 
						 $data_sql1=DB_query("select * from machine_center where id ='".$machine."'",$db);
						  while($row12=DB_fetch_array($data_sql1))
						  {                     	
                     	$data6.="<option value=".$row12['id']."  >".$row12['name']."</option>";
                     	 } 
						 
						$data_sql2=DB_query("select * from production_operator_master where id ='".$operator."'",$db);
						while($row13=DB_fetch_array($data_sql2))
						{
                     	$data7.="<option value=".$row13['id']."  >".$row13['operator_name']."</option>";
                     	 } 
						  
                     $data10.="<table width='100%' border='0' cellspacing='2' cellpadding='2' >";
              $data10.="<tr>";
                $data10.="<th align='center'><strong>S.No</strong></th>";
               	$data10.="<th align='center' ><strong>Item Code </strong></th>";
                $data10.="<th align='center' width='25%'><strong>Item Name </strong></th>";
				
				        $data10.="<th align='center'><strong>Process Qty</strong></th>";
                $data10.="<th align='center'><strong>Actual Qty</strong></th>";
                  
                  
              $data10.="</tr>";
 
 
              $i=1;
              $j=0;
             
               $sql3=DB_query("select * from job_card_item_details where jobid='".$_REQUEST['jobcard']."'",$db);
			  while($row5=DB_fetch_array($sql3))
			  {                
           $itemcode=$s->getField('item_master','id',$row5['mst_itemid'],'StockID');  
           $itemname=$s->getField('item_master','id',$row5['mst_itemid'],'item_name');  
           $data10.="<tr>";
              	$data10.="<td align='center'>".$i."</td>";
               	$data10.="<td align='center'><input type='text' name='itemcode[]'  value='".$itemcode."' readonly style='width:100%'/><input type='hidden' name='itemid[]'  value='".$row5['mst_itemid']."' readonly/>
                   </td>";
                $data10.="<td align='center' width='25%'><input type='text' name='item_name[]'  value='".$itemname."' readonly style='width:100%'/></td>";				 
				$qty=$row5['item_qty']*$data4;
                $data10.="<td align='center'><input type='text'  name='processqty[]'  value='".$qty."' id='total_req_qty_$j' readonly style='width:100%' /></td>";  
                $data10.="<td align='center'><input type='text'   name='actual[]' value='".$qty."'  id='act_cons_$j' style='width:100%' /></td>";   
               
              $data10.="</tr>";
               $i++; $j++; }    
                         
	
	 
    echo  $data=$data4."__".$data6."__".$data7."__".$data10 ;      
    
    
    
    
           }  ?>
