<?php
if(isset($_POST['Save']))
{
$qty=$_REQUEST['count'];
for($i=0;$i<$qty;$i++)
{	
$check=DB_query("select * from shop_floor_production where job_no='".$_REQUEST['job_no'][$i]."' ",$db);
$num=DB_num_rows($check);
if($num<=0)
{
$time1=$_REQUEST['shift_start'][$i];
$time2=$_REQUEST['start_AMPM'][$i];	
$timein=$time1.$time2;	
$time3=$_REQUEST['shift_end'][$i];
$time4=$_REQUEST['end_AMPM'][$i];	
$timeout=$time3.$time4;
$insert="insert into shop_floor_production set job_no='".$_REQUEST['job_no'][$i]."',job_route_card_id='".$_REQUEST['jobid'][$i]."'
          ,process_name='".$_REQUEST['process_name'][$i]."',process_para='".$_REQUEST['process_parameter'][$i]."',machine_center='".$_REQUEST['machine_center'][$i]."'
          ,production_operator='".$_REQUEST['production_operator'][$i]."',shift_of_production='".$_REQUEST['shift_of_production'][$i]."'
          ,in_time='".$timein."',out_time='".$timeout."',last_pend_wip_qty='".$_REQUEST['last_pen_wip_qty'][$i]."',rejection_date='".FormatDateForSQL($_REQUEST['rejection_intimation'][$i])."'
          ,quality_insp_ex_name='".$_REQUEST['quality_ins_ex_name'][$i]."',rejection_qty='".$_REQUEST['rejection_qty'][$i]."',qc_ok_qty='".$_REQUEST['qc_ok_qty'][$i]."'";
		  $query=DB_query($insert,$db);
         $update=DB_query("update job_route_card set status=1 where id='".$_REQUEST['jobid'][$i]."'",$db);
}
else {
	     $updatedata=DB_query("update shop_floor_production set process_name='".$_REQUEST['process_name'][$i]."',process_para='".$_REQUEST['process_parameter'][$i]."',machine_center='".$_REQUEST['machine_center'][$i]."'
          ,production_operator='".$_REQUEST['production_operator'][$i]."',shift_of_production='".$_REQUEST['shift_of_production'][$i]."'
          ,in_time='".$timein."' ,out_time='".$timeout."',last_pend_wip_qty='".$_REQUEST['last_pen_wip_qty'][$i]."',rejection_date='".FormatDateForSQL($_REQUEST['rejection_intimation'][$i])."'
          ,quality_insp_ex_name='".$_REQUEST['quality_ins_ex_name'][$i]."',rejection_qty='".$_REQUEST['rejection_qty'][$i]."',qc_ok_qty='".$_REQUEST['qc_ok_qty'][$i]."'",$db);
    }	
}		
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shop Floor Production QC</title>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.mrp-haiding{
		font:16px Georgia, "Times New Roman", Times, serif;
		color:#000;
		font-weight:bold;
}
.search-haiding{
		font:14px Georgia, "Times New Roman", Times, serif;
		color:#000;
		font-weight:bold;
}
.text{
		font:12px Georgia, "Times New Roman", Times, serif;
		color:#000;
}
.text-table{
		font:12px Georgia, "Times New Roman", Times, serif;
		color:#fff;
		padding-left:5px;
}
.border-table{
		border:1px solid #dedede;
}
.scroll{
		margin:0px;
		padding:0px;
		overflow:scroll;
		width:988px;
		height: 300px;
}
-->
</style></head>

<body>
<table width="990" border="0" align="center" cellpadding="0" cellspacing="0">
 
 
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="top">
    <fieldset>
    <legend class="search-haiding">Shop Floor Production QC</legend>
    <table width="990" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>&nbsp;</td>
      </tr> 
      <tr>
        <td align="left" valign="top"><form action=""  method="post">	
        	<table width="990" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="81" align="left" valign="top" class="text">From Date :</td>
            <td width="113" align="left" valign="top">
              <input type="text" name="from_date"  id="from_date" class="datepicker" value="<?php echo $_REQUEST['from_date']; ?>"/></td>
            <td width="64" align="left" valign="top" class="text">To Date :</td>
            <td width="124" align="left" valign="top"><input type="text" name="to_date"  id="to_date" class="datepicker" value="<?php echo $_REQUEST['to_date']; ?>"/></td>
            <td width="60" align="left" valign="top" class="text">Branch :</td>
            <td width="331" align="left" valign="top"><select name="site" id="site" >
                        <option value="0">Select Branch</option>
     <?php 	   $site_sql = "SELECT prefix,loccode, locationname from locations";$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))	{	?>
         <option value="<?php echo $site_row['loccode']; ?>" <?php if($_REQUEST['site']==$site_row['locationname']){ ?> selected="selected" <?php }?>><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
   </select></td> 
            <td  width="250"  align="left" valign="top"><input type="submit" name="Search" value="Search" /></td>
          </tr>
        </table></form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><form action="" method="post">
        	<div class="scroll">        	
        	<table width="988" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td><table width="4000" border="0" cellpadding="0" cellspacing="0">
              <tr class="text-table">
                <td class="text-table" width="40" height="40" align="left" bgcolor="#999999">Job No.</td>
                <td class="text-table" width="80" align="left" bgcolor="#999999">Job Date</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Party Name</td>
                <td class="text-table" width="80" align="left" bgcolor="#999999">Order Number</td>
                <td class="text-table" width="80" align="left" bgcolor="#999999"> Order Date</td>
                <td class="text-table" width="100" align="left" bgcolor="#999999">Part Code</td>
                <td class="text-table" width="190" align="left" bgcolor="#999999">Material Name</td>
                <td class="text-table" width="80" align="left" bgcolor="#999999">UOM</td>
                <td class="text-table" width="80" align="left" bgcolor="#999999">Production Date</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Process Name</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Process Parameter</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Machine Center</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Production Operator</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Shift of Production</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">In Time</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Out Time</td>
               <td class="text-table" width="190" align="left" bgcolor="#999999">Rejection Date & Time</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Rejection Department</td>
                <td class="text-table" width="190" align="left" bgcolor="#999999">Quality Inspec Executive Name</td>
                 <td class="text-table" width="130" align="left" bgcolor="#999999">Last Pending WIP QTY</td>
                <td class="text-table" width="130" align="left" bgcolor="#999999">Production Qty</td>
                <td class="text-table" width="133" align="left" bgcolor="#999999">Rejection Qty</td>
                <td class="text-table" width="143" align="left" bgcolor="#999999">QC OK Qty</td>
                <td class="text-table" width="107" align="left" bgcolor="#999999">Unit Name</td>
              </tr>
              <?php
              if(isset($_POST['Search']))
			   {    	
                    $fordate = $_POST['from_date'];
					$todate = $_POST['to_date'];
					$fromdate = explode("/", $fordate);
					$daydate = $fromdate['0'];
					$Monthdate = $fromdate['1'];
					$yeardate = $fromdate['2'];
					$fdate = $yeardate."-".$Monthdate."-".$daydate;					   
					$tredate   = explode("/", $todate);
					$dayda     = $tredate['0'];
					$Monthda   = $tredate['1'];
					$yearda    = $tredate['2'];
					$toyrdate  = $yearda."-".$Monthda."-".$dayda;
					$filter = array();	
					if($_REQUEST['from_date'] != '' && $_REQUEST['to_date'] != '')
 	                $filter[]="job_card_date between '".$fdate."' and '".$toyrdate."'";
 	                if($_REQUEST['site']!='000')
	                $filter[]="branch_code='".$_REQUEST['site']."' ";  
				   if($filter != '')	{
		          $filter1 = implode(" and ",$filter);
					if($_REQUEST['site']!='000' || $_REQUEST['from_date']!='' || $_REQUEST['to_date']!='')
					{
					 $sql = "select * from job_route_card  where status='0' and  $filter1 group by id";
					}
					else
					{
					$sql = "select* from job_route_card  where status='0' "; 
					}
				}
			    else
			  	{  
	  				  $sql="select * from job_route_card where status='0' ";
		        }    
			   $quantity=0;
			   $quantity1=0;
               $i=0;    
               $sql1=DB_query($sql,$db);
               $num=DB_num_rows($sql1);
			   if($num>0)
			   {
               while($data=DB_fetch_array($sql1))
			   {
			   $sqldata=DB_query("select sum(total_prod_qty),sum(balance_wip) from job_route_process where masterid='".$data['id']."'",$db);	
			   $sql_row=DB_fetch_array($sqldata);
			     $quantity=$quantity+$sql_row['sum(total_prod_qty)'];
				  $quantity1=$quantity1+$sql_row['sum(balance_wip)'];
			 			  ?>
              <tr height="20px;">
                <td align="left" valign="top">
                <input type="hidden" name="jobid[<?php echo $i; ?>]" value="<?php echo $data['id']; ?>" />
                <input type="hidden" name="job_no[<?php echo $i; ?>]" id="job_no_<?php echo $i; ?>"  value="<?php echo $data['job_card_no']; ?>"><?php echo $data['job_card_no']; ?> </td>
                 <td align="left" valign="top"><input type="hidden" name="job_date[<?php echo $i; ?>]" id="job_date_<?php echo $i; ?>" value="<?php echo $data['job_card_date']; ?>"><?php echo $data['job_card_date']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="party_name[<?php echo $i; ?>]" id="party_name_<?php echo $i; ?>" value="<?php echo $data['job_card_no']; ?>"><?php echo $data['job_card_no']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="order_number[<?php echo $i; ?>]" id="order_number_<?php echo $i; ?>" value="<?php echo $data['party_order_no']; ?>"><?php echo $data['party_order_no']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="order_date[<?php echo $i; ?>]" id="order_date_<?php echo $i; ?>" value="<?php echo $data['order_date']; ?>"><?php echo $data['order_date']; ?></td>
                <td align="left" valign="top"> <?php $storeid=$s->getField('item_master','id',$data['part_code'],'StockId'); ?>
                <input type="hidden" name="part_code[<?php echo $i; ?>]" id="part_code_<?php echo $i; ?>" value="<?php echo $storeid; ?>"><?php echo $storeid; ?></td>
                <td align="left" valign="top"><input type="hidden" name="material_name[<?php echo $i; ?>]" id="material_name_<?php echo $i; ?>" value="<?php echo $data['item_name']; ?>"><?php echo $data['item_name']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="uom[<?php echo $i; ?>]" id="uom_<?php echo $i; ?>" value="<?php echo $data['unit']; ?>"><?php echo $data['unit']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="production_date[<?php echo $i; ?>]" id="production_date_<?php echo $i; ?>" value="<?php echo $data['job_card_date']; ?>"><?php echo $data['job_card_date']; ?></td>
                <td align="left" valign="top"><select  name="process_name[<?php echo $i; ?>]" id="process_name_<?php echo $i; ?>" >
                <option value="0">--Select--</option><?php $process=DB_query("select * from production_process_master",$db);
				while($process_row=DB_fetch_array($process)){	?>
				<option value="<?php echo $process_row['id']; ?>"><?php echo $process_row['manuf_process_name']; ?></option>
				<?php } ?> </select></td>
                <td align="left" valign="top"><input type="text" name="process_parameter[<?php echo $i; ?>]" id="process_parameter_<?php echo $i; ?>" value=""></td>
                <td align="left" valign="top"><select  name="machine_center[<?php echo $i; ?>]" id="machine_center">
                <option value="0">--Select--</option>  	<?php $machine=DB_query("select * from machine_center",$db);
				while($machine_row=DB_fetch_array($machine)){	?>
				<option value="<?php echo $machine_row['id']; ?>"><?php echo $machine_row['code']; ?></option>
				<?php } ?> </select></td>
                <td align="left" valign="top"><select  name="production_operator[<?php echo $i; ?>]" id="production_operato_<?php echo $i; ?>r">
                <option value="0">--Select--</option><?php $production=DB_query("select * from production_operator_master",$db);
				while($production_row=DB_fetch_array($production))	{		?>
				<option value="<?php echo $production_row['id']; ?>"><?php echo $production_row['operator_name']; ?></option>
				<?php } ?></select></td>
                <td align="left" valign="top"><select  name="shift_of_production[<?php echo $i; ?>]" id="shift_of_production_<?php echo $i; ?>">
                <option value="0">--Select--</option><?php $shift=DB_query("select * from production_shift",$db);
				while($shift_row=DB_fetch_array($shift)){	?>
				<option value="<?php echo $shift_row['id']; ?>"><?php echo $shift_row['shift_name']; ?></option>
				<?php } ?> 	</select></td>
                <td align="left" valign="top"><?php if(isset($_REQUEST['shift_start'])){$shift_start=$_REQUEST['shift_start'];} else{$shift_start='00:00';}?>
				     <input name="shift_start[<?php echo $i; ?>]" type="text" id="shift_start" value="" size="10" />
					 <select name="start_AMPM[<?php echo $i; ?>]" id="start_AMPM" style="width:40px">
					 <option value="AM"<?php echo ($_REQUEST['start_AMPM']=='AM'?'selected':'')?>>AM</option>
					 <option value="PM"<?php echo ($_REQUEST['start_AMPM']=='PM'?'selected':'')?>>PM</option>
					 </select></td>
     <td align="left" valign="top">	<?php if(isset($_REQUEST['shift_end'])){$shift_end=$_REQUEST['shift_end'];} else{$shift_end='00:00';}?>
             <input name="shift_end[<?php echo $i; ?>]" type="text"  value="" size="15">
				 <select name="end_AMPM[<?php echo $i; ?>]" id="end_AMPM" style="width:40px">
				 <option value="AM"<?php echo ($_REQUEST['end_AMPM']=='AM'?'selected':'')?>>AM</option>
				 <option value="PM"<?php echo ($_REQUEST['end_AMPM']=='PM'?'selected':'')?>>PM</option>
				 </select></td>
                 <td align="left" valign="top"><input type="text" name="rejection_intimation[<?php echo $i; ?>]" id="rejection_intimation_<?php echo $i; ?>" value="" class="datepicker"></td>
                <td align="left" valign="top"><select name="rejection_dept" id="rejection_dept"><option value="0">--Select--</option><?php 	$rejection_dept=DB_query("select * from deptmaster",$db);
					while($dept_row=DB_fetch_array($rejection_dept))
					{ ?>	
                	<option value="<?php echo $dept_row['id']; ?>"><?php echo $dept_row['deptname']; ?></option>
                	<?php } ?>	
                	</select>	
                </td>
                <td align="left" valign="top"><input type="text" name="quality_ins_ex_name[<?php echo $i; ?>]" id="quality_ins_ex_name_<?php echo $i; ?>"  value="<?php echo $data['quality_insp_execu_name']; ?>" ></td>
                <td align="left" valign="top"><input type="hidden" name="last_pen_wip_qty[<?php echo $i; ?>]" id="last_pen_wip_qty_<?php echo $i; ?>" value="<?php echo $quantity1; ?>"><?php echo $quantity1; ?></td>
                <td align="left" valign="top"><input type="hidden" name="production_qty[<?php echo $i; ?>]" id="production_qty_<?php echo $i; ?>" value="<?php echo $quantity; ?>"><?php echo $quantity ; ?></td>
                <td align="left" valign="top"><input type="text" name="rejection_qty[<?php echo $i; ?>]" id="rejection_qty_<?php echo $i; ?>"  onchange="calqty(<?php echo $i; ?>);"></td>
                <td align="left" valign="top"><input type="text" name="qc_ok_qty[<?php echo $i; ?>]" id="qc_ok_qty_<?php echo $i; ?>" value=""></td>
                <td align="left" valign="top"><input type="hidden" name="unit_name[<?php echo $i; ?>]" id="unit_name_<?php echo $i; ?>" value="<?php echo $data['branch_code']; ?>"  ><?php echo $site=$s->getField('locations','loccode',$data['branch_code'],'locationname'); ?></td>
                </tr><?php $i++; }} else { ?>
                 <tr><td colspan="24" align="center"><?php echo "No Records Found"; ?></td><?php  } } ?><input type="hidden" name="count" value="<?php echo $i; ?>" />
                 </table></td>
          </tr>
          
        </table></div><p align="center"><input type="submit" name="Save" value="Save" /></p></form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      
    </table>    
    </fieldset>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
<script language="JavaScript">
function calqty(str)
{
var receive=document.getElementById("production_qty_"+str).value;
var	reject=document.getElementById("rejection_qty_"+str).value;
var t=parseFloat(receive)-parseFloat(reject);
document.getElementById("qc_ok_qty_"+str).value=t.toFixed(2);
}
</script>



