<?php 
$title = _('Job Route Card Creations');

   if(isset($_POST['Save'])) 
   {

		/******************************* Maintaing Process Qty ******************************/
	  
	 
	    for($i=0;$i<count($_REQUEST['chk']);$i++)
		{
	  
	      $seq=$s->GetFieldValue('job_process_details',"jobid='". $_REQUEST['jobcardid'][$i]."' and 
						process='". $_REQUEST['privious'][$i]."'",'process_seq');
	  
          
	  
		  $sql1=DB_query("select * from job_process_details where jobid='". $_REQUEST['jobcardid'][$i]."' and 
						process!='". $_REQUEST['privious'][$i]."' and process_seq >'".$seq."'
						 order by process_seq ASC limit 0,1",$db);
				$row1=DB_fetch_array($sql1);
				
						
				$sql_check=DB_query("SELECT * FROM daily_process_qty_maintain where jobcard='".$_REQUEST['jobcardid'][$i]."' 
						  and from_process='". $_REQUEST['privious'][$i]."' ",$db);
				$numdata=DB_num_rows($sql_check);		
				$row21=DB_fetch_array($sql_check);				
				$pendingqty=$_REQUEST['actual_prod_qty'][$i]-$_REQUEST['finalqty'][$i];
				$data['jobcard']=$_REQUEST['jobcardid'][$i];
				$data['from_process']= $_REQUEST['privious'][$i];
				$data['to_process']=$row1['process'];
				
				
				$data['pending_qty']=$pendingqty;
				if($numdata==0)
				{
				
				$data['contain_qty']=$_REQUEST['actual_prod_qty'][$i];
				$data['move_qty']=$_REQUEST['finalqty'][$i];
				
				
			
				
				$s->RecordInsert('daily_process_qty_maintain',$data);
				$s->RecordInsert('daily_shop_floor_qty_maintain',$data);	
				}
				else
				{
				$data['status']=1;
				$data['move_qty']=$_REQUEST['finalqty'][$i];	
				$cond="jobcard='". $_REQUEST['jobcardid'][$i]."' and from_process='". $_REQUEST['privious'][$i]."'";
				$s->RecordEdit('daily_process_qty_maintain',$data,$cond);
				$toprocess=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='". $_REQUEST['jobcardid'][$i]."' and 
						from_process='". $_REQUEST['privious'][$i]."'",'to_process');
						
	            $pendqty=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='". $_REQUEST['jobcardid'][$i]."' and 
						from_process='".$toprocess."'",'pending_qty');	
						
				$contain_qty=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='". $_REQUEST['jobcardid'][$i]."' and 
						from_process='".$toprocess."'",'contain_qty');						
				$data2['pending_qty']=$_REQUEST['finalqty'][$i]+$pendqty;
				$data2['contain_qty']=$_REQUEST['finalqty'][$i]+$contain_qty;
				$cond2="jobcard='". $_REQUEST['jobcardid '][$i]."' and from_process='".$toprocess."'";
				
				
				
				$s->RecordEdit('daily_process_qty_maintain',$data2,$cond2);
				$s->RecordEdit('daily_shop_floor_qty_maintain',$data2,$cond2);
				
				
				}
				
				
				
			$update=DB_query("update job_process_details set qc_status=1 where jobid='". $_REQUEST['jobcardid'][$i]."' and 
						process='". $_REQUEST['privious'][$i]."' ",$db);	
				
			
		
		}
	  
	/*******************************   End ***********************************************/   


   }

?>

<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<div class="body_contain">
<div class="tab_div">

<h1>Shop Floor Process</h1>
<form action="" method="post">
  <table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr class="row1">
	<td class="tabledata1">&nbsp;</td>
	<td width="29%" class="tabledata1">&nbsp;</td>
	<td width="18%" class="tabledata1">Job Card No:</td>
	<td width="20%"><select name="jobcard" id="jobcard" style="width:150px;">  
					   <option value="0">-Select-</option>	
					   <?php 
					   $sql=DB_query("select * from job_card where  CompanyId ='".$_SESSION['ACGCompanyId']."'",$db);
					   while($row1=DB_fetch_array($sql))
					   {					   
					   ?>
					   <option value="<?php echo $row1['id']; ?>" <?php if($_POST['jobcard']==$row1['id']) { ?> selected="selected" <?php } ?>><?php echo $row1['job_card_no']; ?></option>
					   	<?php } ?>			   
					   </select></td>
	<td width="25%" class="tabledata1"><input type="submit" name="search" value="Search" class="search" />	</td>
	</tr>
</table>
</form>



<form action="" method="post">
<?php if($_REQUEST['search'])
	{
	?>
<fieldset><legend style="font-size:12px;"><strong>Process Wise Detail</strong></legend> 
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th width="6%"><strong>S.No. </strong></th>
		  <th width="16%"><strong>Job Card No</strong></th>
		  <th width="16%"><strong>Job Card Date</strong></th>
		 <th width="16%"><strong>Lot No</strong></th>
		  <th width="16%"><strong>PROCESS</strong></th>
		  <th width="16%"><strong>Item</strong></th>
		  <th width="16%"><strong>Qty</strong></th>
		  <th width="16%"><strong>Reject Qty</strong></th>
		 <th width="16%"><strong>Final Qty</strong></th> 
	    </tr>
	<?php 
	$jobcardno=$_REQUEST['jobcard'];
	$i=0;
	$sql=DB_query("select * from job_card where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$jobcardno."'",$db);
	while($row=DB_fetch_array($sql))
	{
	$sql1=DB_query("select * from job_process_details where jobid='".$row['id']."' and qc_status=0 
	order by id limit 0,1 ",$db);
	while($row1=DB_fetch_array($sql1))
	{
	  $seq=$s->GetFieldValue('job_process_details',"jobid='".$row['id']."' and 
						process='".$row1['process']."'",'process_seq');
	 				
	 $processid=$s->GetFieldValue('job_process_details',"jobid='".$row['id']."' and 
						process_seq='".$seq."'",'process');					
	
	
	$totalproduct=DB_query("select  move_qty as prodqty from daily_process_qty_maintain where jobcard='".$row['id']."'
	    and from_process='".$processid."'",$db);
	$numrow1=DB_num_rows($totalproduct);
		
	$row_productqty=DB_fetch_array($totalproduct);
	$data4=$row_productqty['prodqty']; 

	if($data4!='')
	{ 
	?>	
		
     <tr >
    <td><input type="checkbox" name="chk[]" id="chk"  style="width:2%;"></td>
	<td><input type="hidden" name="jobcardid[]" value="<?php echo $row['id']; ?>" /><?php echo $row['job_card_no']; ?></td>
	<td><?php echo ConvertSQLDate($row['job_date']); ?></td>
	<td><?php echo $row['lotno']; ?></td>	
     <td><input type="text" name="process[]" id="process" style="width:100%" value="<?php echo $processid; ?>" />
	 	  <input type="text" name="privious[]" value="<?php echo $row1['process']; ?>" />
     <?php	  echo $s->getField('production_process_master','id',$processid,'manuf_process_name'); ?>
	    </select></td>
    <td><input type="hidden" name="mstitemid[]" value="<?php echo $row['work_itemid']; ?>" /><?php echo $s->getField('item_master','id',$row['work_itemid'],'item_name'); ?></td>
	<td><input type="text" name="actual_prod_qty[]" value="<?php echo $data4; ?>" id="qty_<?php echo $i; ?>"  readonly="true"/></td>
	<td><input type="text" name="rejectqty[]"  onkeyup="showtotalqty(this.value,<?php echo $i; ?>)" id="rejectqty_<?php echo $i; ?>" /></td>
	<td><input type="text" name="finalqty[]" value="" id="finalqty_<?php echo $i; ?>" /></td>
  </tr>

  <?php $i++; } } }  ?>
	</table>
	
	</fieldset>
	<?php if($data4!='') { ?>
	 <p align="center"><input type="submit" name="Save" class="search" value="Save"  onclick="return validatedata();"/></p>
<?php }  }?>
</form>
	  

	 
</div></div>
<script>

function showtotalqty(str,i)
{
if(str!='')
{
var qty=document.getElementById("qty_"+i).value;
var amt=parseFloat(qty)-parseFloat(str);

document.getElementById("finalqty_"+i).value=amt.toFixed(2);
}
else
{
alert("Must Enter Rejection Qty");

}
}



</script>
      
      
