<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$date=date('d/m/Y');
 $time=date('h:i', time());
 $period=date(A);
 $timestamp = date("H:i", time());

function convertTime($time,$period)
{
	$timeBRK=explode(':',$time);
	if($period=='PM' && $timeBRK[0]!='12')
	{
		$time=$timeBRK[0]+12;
	}
	else 
	{
		$time=$timeBRK[0];
	}
	return $time.":".$timeBRK[1];
}
if($_REQUEST['Save']!='' and $_REQUEST['action'] == "addNew")
{
$jobdata = explode("#",$_REQUEST['job_ticket']);
$sql="Select prefix from locations where loccode='".$_REQUEST['site']."'";
$result=DB_query($sql,$db);
$row=DB_fetch_array($result);
$prefix=$row['prefix'];
$enquiry_sql="Select entry_slip_no from daily_production_process where branch_id='".$_REQUEST['site']."'
               and CompanyId='".$_SESSION['ACGCompanyId']."' order by entry_slip_no DESC limit 1";
$enquiry_result=DB_query($enquiry_sql,$db);

if(DB_num_rows($enquiry_result)>0)
{
	$enquiry_row=DB_fetch_array($enquiry_result);	
	$en1=explode("/",$enquiry_row['entry_slip_no']);	
	$next=$en1[2]+1;
	$finalString=$en1[0]."/DPE/".str_pad($next,5,"0",STR_PAD_LEFT);
}
else
{
	$finalString=$prefix."/DPE/00001";
}

$insert="insert into daily_production_process set 
				entry_slip_no='".$finalString."',
         	job_card_id='".$jobdata[0]."',
				job_card_type='".$jobdata[1]."',
				item='".$_REQUEST['item_name1']."',
         	job_card_date='".$_REQUEST['job_date']."',
				pp_slip_date='".FormatDateForSQL($_REQUEST['pp_slip'])."',
         	process_prod_date='".FormatDateForSQL($_REQUEST['process_prod_date'])."',
				process_in_date='".FormatDateForSQL($_REQUEST['startdate'])."',
         	process_out_date='".FormatDateForSQL($_REQUEST['enddate'])."',
         	process_name='".$_REQUEST['process_name']."',
				machine_operator='".$_REQUEST['machine_operator']."',
         	machine_center='".$_REQUEST['machine']."',
				process_in_time='".$_REQUEST['starttime']."',
				process_out_time='".$_REQUEST['endTime']."',
				production_shift='".$_REQUEST['production_shift']."',
         	actual_prod_qty='".$_REQUEST['actual_prod_qty']."',
		 		total_hrs='".$_REQUEST['total_process_hrs']."',
				rejection_allow='".$_REQUEST['rejection_allowed']."',
         	after_rejection='".$_REQUEST['rejqty']."',
				production_qty='".$_REQUEST['production_qty']."',
            branch_id='".$_REQUEST['site']."',
				remarks='".$_REQUEST['remarks']."',
				created='".$_REQUEST['created']."',
				approved_by='".$_REQUEST['approved']."',
		 		CompanyId='".$_SESSION['ACGCompanyId']."'";
		
      $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
	$query=DB_query($insert,$db,$ErrMsg);
	$Lastreq_id=DB_Last_Insert_ID($db,'daily_production_process',$ErrMsg);
	
	/******************************* Maintaing Process Qty ******************************/
	  
	     $seq=$s->GetFieldValue('job_process_details',"jobid='".$jobdata[0]."' and 
						process='".$_REQUEST['process_name']."'",'process_seq');
	  
           
	  
		  $sql1=DB_query("select * from job_process_details where jobid='".$jobdata[0]."' and 
						process!='".$_REQUEST['process_name']."' 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='".$jobdata[0]."' 
						  and from_process='".$_REQUEST['process_name']."' ",$db);
				$numdata=DB_num_rows($sql_check);		
				$row21=DB_fetch_array($sql_check);
				
				
				
				$pendingqty=$_REQUEST['actual_prod_qty']-$_REQUEST['production_qty'];
				$data['jobcard']=$jobdata[0];
				$data['from_process']=$_REQUEST['process_name'];
				$data['to_process']=$row1['process'];				
				
				$data['pending_qty']=$pendingqty;
				if($numdata==0)
				{
				if($row1['current_status']=='N')
				$data['status']=1;
				
				$data['contain_qty']=$_REQUEST['actual_prod_qty'];
				$data['move_qty']=$_REQUEST['production_qty'];
				$s->RecordInsert('daily_process_qty_maintain',$data);
				}
				else
				{
				$data['move_qty']=$_REQUEST['production_qty']+$row21['move_qty'];	
				$cond="jobcard='".$jobdata[0]."' and from_process='".$_REQUEST['process_name']."'";
				//$data['status']=1;
				$s->RecordEdit('daily_process_qty_maintain',$data,$cond);
				$toprocess=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='".$jobdata[0]."' and 
						from_process='".$_REQUEST['process_name']."'",'to_process');
						
	            $pendqty=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='".$jobdata[0]."' and 
						from_process='".$toprocess."'",'pending_qty');	
						
				$contain_qty=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='".$jobdata[0]."' and 
						from_process='".$toprocess."'",'contain_qty');						
				$data2['pending_qty']=$_REQUEST['production_qty']+$pendqty;
				$data2['contain_qty']=$_REQUEST['production_qty']+$contain_qty;
				$cond2="jobcard='".$jobdata[0]."' and from_process='".$toprocess."'";
				$s->RecordEdit('daily_process_qty_maintain',$data2,$cond2);
								
				}
            
    
            for($i=0;$i<count($_REQUEST['itemid']);$i++)
            {
            $data3['parentid']=$Lastreq_id; 
            $data3['processid']=$_REQUEST['process_name'];
            $data3['mst_itemid']=$_REQUEST['itemid'][$i];
            $data3['processqty']=$_REQUEST['processqty'][$i];
            $data3['actualqty']=$_REQUEST['actual'][$i];        
            $s->RecordInsert('daily_process_sub_item_details',$data3);
            }
            
            
            
            
            
            
		
		$update=DB_query("update job_process_details set shop_status=1 where jobid='".$jobdata[0]."' and 
						process='". $_REQUEST['process_name']."' ",$db);
		
	  
	
	//******************************   End ********************************************** //  
	
	
	
	
	 
	
	
     if($Lastreq_id!='')
	 {
	   $insert2="insert into daily_production_breakdown set daily_id='".$Lastreq_id."',
	           breakdown_applicable='".$_REQUEST['breakdown_applicable']."',
	           maintenance_dept='".$_REQUEST['maintenance_dept']."',
	           sub_break_type='".$_REQUEST['sub_breakdown']."',
	           maintenance_executive_name='".$_REQUEST['maintennace_ex_name']."',
	           breakdown_type='".$_REQUEST['breakdown_type']."',
			   breakdown_reason='".$_REQUEST['breakdown_reason']."',
	           breakdown_desc='".$_REQUEST['breakdown_desc']."',
			   breakdown_minute='".$_REQUEST['breakdown_minute']."',
	           break_down_strat_date='".FormatDateForSQL($_REQUEST['break_down_strat_date'])."',
			   break_down_s_time='".$_REQUEST['break_down_s_time']."',
	           break_down_end_date='".FormatDateForSQL($_REQUEST['break_down_end_date'])."',
			   break_down_e_time='".$_REQUEST['break_down_e_time']."'"; 	
			   
			   $query2=DB_query($insert2,$db);	
			  
          
            
            
			  
			  $qty=$_REQUEST['item_code'];
			  for($i=0;$i<count($qty);$i++)
			  { 
				$insert3="insert into daily_raw_material_consu set 
								daily_id='".$Lastreq_id."',
			          		mst_itemid='".$_REQUEST['item_code'][$i]."',
								group1='".$_REQUEST['group'][$i]."',
								size='".$_REQUEST['size'][$i]."',
								total_req_qty='".$_REQUEST['total_req_qty'][$i]."',
								act_consu_qty='".$_REQUEST['act_cons'][$i]."',
			          		diff_qty='".$_REQUEST['diff_qty'][$i]."'";
			
				$query3=DB_query($insert3,$db);
			}
				 		 	
	 }   
	 
	   /**********************  CHECKING TOTAL PRODUCTION QTY / FINAL PROCESS QTY ***************************/
	    
		$totalproduct=DB_query("select sum(prodqty) as prodqty from job_card_item_details
		 where jobid='".$jobdata[0]."'",$db);
			$row_productqty=DB_fetch_array($totalproduct);
			$data4=$row_productqty['prodqty']; 
		
		
	   $sql_check1=DB_query("select * from daily_process_qty_maintain where jobcard='".$jobdata[0]."' and to_process=0    and pending_qty=0.00",$db);
       $row4=DB_fetch_array($sql_check1);
       
       $check=$s->GetFieldValue("production_process_master","id='".$_REQUEST['process_name']."'","isFinal");
       
	   if($check['isFinal']==1)
	   {
	   $update=DB_query("update job_card set against_daily_status=1 where id='".$jobdata[0]."'",$db);
	   }
	    	   
	   
	   
	   
	   
	   
	   
	   /*************************************              END         **************************************/ 
	 
	 
	 
	 
	  
	  $s->pageLocation('index.php?route=daily_production_entrylist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);
	}
	
	
if($_REQUEST['action'] == 'edit' || $_REQUEST['action']=='view'){

$sql = "SELECT * FROM daily_production_process WHERE daily_id='".$_REQUEST['ID']."'";
$result = DB_query($sql,$db);
$row = DB_fetch_array($result);

$entry_slip_no = $row['entry_slip_no'];
$job_card_id = $row['job_card_id'];
$job_card_type = $row['job_card_type'];
$item = $row['item'];
$job_card_date = ($row['job_card_date'] !='')? date('d/m/Y',strtotime($row['job_card_date'])):"";
$pp_slip_date = ($row['pp_slip_date'] !='') ? date('d/m/Y',strtotime($row['pp_slip_date'])):"";
$process_prod_date = ($row['process_prod_date'] !='') ? date('d/m/Y',strtotime($row['process_prod_date'])):"";
$process_in_date = ($row['process_in_date'] !='') ? date('d/m/Y',strtotime($row['process_in_date'])) : "";
$process_out_date = ($row['process_out_date'] !='') ? date('d/m/Y',strtotime($row['process_out_date'])) : "";
$process_name = $row['process_name'];
$machine_operator = $row['machine_operator'];
$machine_center = $row['machine_center'];
$process_in_time = $row['process_in_time'];
$process_out_time = $row['process_out_time'];
$production_shift = $row['production_shift'];
$production_qty = $row['production_qty'];
$actual_prod_qty = $row['actual_prod_qty'];
$total_hrs = $row['total_hrs'];
$rejection_allow = $row['rejection_allow'];
$after_rejection = $row['after_rejection'];
$branch_id = $row['branch_id'];
$remarks = $row['remarks'];
$created = $row['created'];
$approved_by = $row['approved_by'];
$brkd_sql = "SELECT * FROM daily_production_breakdown where daily_id='".$_REQUEST['ID']."'";
$brkd_result = DB_query($brkd_sql,$db);
$breakRow = DB_fetch_array($brkd_result);
$breakdown_applicable = $breakRow['breakdown_applicable'];
$maintenance_dept = $breakRow['maintenance_dept'];
$maintenance_executive_name = $breakRow['maintenance_executive_name'];
$breakdown_type = $breakRow['breakdown_type'];
$breakdown_reason = $breakRow['breakdown_reason'];
$breakdown_desc = $breakRow['breakdown_desc'];
$breakdown_minute = $breakRow['breakdown_minute'];
$break_down_strat_date = ($breakRow['break_down_strat_date'] !='')?date('d/m/Y',strtotime($breakRow['break_down_strat_date'])): "";
$break_down_s_time = $breakRow['break_down_s_time'];
$break_down_end_date = ($breakRow['break_down_end_date'] !='') ? date('d/m/Y',strtotime($breakRow['break_down_end_date'])):"";
$break_down_e_time = $breakRow['break_down_e_time'];
$sub_break_type = $breakRow['sub_break_type'];
$brkid = $breakRow['id'];

}


if($_REQUEST['action'] =='edit' and $_REQUEST['Save'] !='')
{
	$jobdata = explode("#",$_REQUEST['job_ticket']);
	$update = "UPDATE daily_production_process set
					entry_slip_no='".$_REQUEST['entry_slip']."', 
					job_card_id='".$jobdata[0]."',
					job_card_type='".$jobdata[1]."',
					item='".$_REQUEST['item_name1']."',
					job_card_date='".$_REQUEST['job_date']."',
					pp_slip_date='".FormatDateForSQL($_REQUEST['pp_slip'])."',
					process_prod_date='".FormatDateForSQL($_REQUEST['process_prod_date'])."',
					process_in_date='".FormatDateForSQL($_REQUEST['startdate'])."',
					process_out_date='".FormatDateForSQL($_REQUEST['enddate'])."',
					process_name='".$_REQUEST['process_name']."',
					machine_operator='".$_REQUEST['machine_operator']."',
					machine_center='".$_REQUEST['machine']."',
					process_in_time='".$_REQUEST['starttime']."',
					process_out_time='".$_REQUEST['endTime']."',
					production_shift='".$_REQUEST['production_shift']."',
					actual_prod_qty='".$_REQUEST['actual_prod_qty']."',
					total_hrs='".$_REQUEST['total_process_hrs']."',
					rejection_allow='".$_REQUEST['rejection_allowed']."',
					after_rejection='".$_REQUEST['rejqty']."',
					branch_id='".$_REQUEST['site']."',
					remarks='".$_REQUEST['remarks']."',
					created='".$_REQUEST['created']."',
					approved_by='".$_REQUEST['approved']."'
					WHERE daily_id='".$_REQUEST['ID']."'";
					
	//DB_query($update,$db);
	
   
   $delete=DB_query("delete from daily_process_sub_item_details where parentid='".$_REQUEST['ID']."'
            and processid='".$_REQUEST['process_name']."'",$db);
            for($i=0;$i<count($_REQUEST['itemid']);$i++)
            {
            $data3['parentid']=$_REQUEST['ID']; 
            $data3['processid']=$_REQUEST['process_name'];
            $data3['mst_itemid']=$_REQUEST['itemid'][$i];
            $data3['processqty']=$_REQUEST['processqty'][$i];
            $data3['actualqty']=$_REQUEST['actual'][$i];        
            $s->RecordInsert('daily_process_sub_item_details',$data3);
            }
   
	$update2="UPDATE daily_production_breakdown set 
	           breakdown_applicable='".$_REQUEST['breakdown_type']."',
	           maintenance_dept='".$_REQUEST['maintenance_dept']."',
	           sub_break_type='".$_REQUEST['sub_breakdown']."',
	           maintenance_executive_name='".$_REQUEST['maintennace_ex_name']."',
	           breakdown_type='".$_REQUEST['breakdown_type']."',
			   breakdown_reason='".$_REQUEST['breakdown_reason']."',
	           breakdown_desc='".$_REQUEST['breakdown_desc']."',
			   breakdown_minute='".$_REQUEST['breakdown_minute']."',
	           break_down_strat_date='".FormatDateForSQL($_REQUEST['break_down_strat_date'])."',
			   break_down_s_time='".$_REQUEST['break_down_s_time']."',
	           break_down_end_date='".FormatDateForSQL($_REQUEST['break_down_end_date'])."',
			   break_down_e_time='".$_REQUEST['break_down_e_time']."'
			   WHERE id='".$_REQUEST['brkdid']."'"; 	
			   
	$query2=DB_query($update2,$db);	
			  
			  $qty=$_REQUEST['item_code'];
			  for($i=0;$i<count($qty);$i++)
			  { 
				$update3="UPDATE daily_raw_material_consu set 
			          			group1='".$_REQUEST['group'][$i]."',
								size='".$_REQUEST['size'][$i]."',
								total_req_qty='".$_REQUEST['total_req_qty'][$i]."',
								act_consu_qty='".$_REQUEST['act_cons'][$i]."',
			          			diff_qty='".$_REQUEST['diff_qty'][$i]."'
								WHERE id='".$_REQUEST['itemRowId'][$i]."'
								";
			
		$query3=DB_query($update3,$db);
			}
	
	$s->pageLocation('index.php?route=daily_production_entrylist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);

}
?>
<script src="ui/jquery.ui.timepicker.js"></script>
<div class="body_contain">
<div class="tab_div">
<h1>Daily Production Entry  Against Job Card</h1>

<form action="" method="post" >
<table width="70%">	
<?php if(count($msgErr)>0){?> 
   <tr class="row1">
   <td colspan="4"><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo "<div class='error'>".$msgErr[$i].'</div>';
   }
    ?></td>
   </tr>
   <?php } ?>	
	</table>
 <h3>General Details</h3>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr class="row1">
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
            	<tr class="row1">
                 <td width="14%" class="tabledata1"><strong>Branch</strong></td>
                    <td width="19%"><?php
	
 		$sql ="SELECT loccode, locationname FROM locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	 	$resultStkLocs = DB_query($sql,$db);
		?>
	                  <select name="site" style="width:100%" onchange="getdata(this.value);" id="site">
                              <option value="">Select</option>
      <?php    
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
      <option value="<?php echo $myrow['loccode']; ?>" <?php echo ($myrow['loccode']==$branch_id) ?"selected" :"" ;?>><?php echo $myrow['locationname'];?></option>
      <?php  }	?> 
    </select></td>
                    <td width="17%" class="tabledata1"><span class="tabledata1"><strong>Production Date</strong></span></td>
                     <td width="20%"><input type="text" name="pp_slip" value="<?php echo $pp_slip_date;?>" style="width:100%;" id="pp_slip" class="datepicker"/></td>
                     <td width="14%" class="tabledata1"><span class="tabledata1"><strong>Entry Slip No.</strong></span></td>
                     <td width="16%"><input type="text" name="entry_slip" style="width:100%;" id="entry_slip" value="<?php if($_REQUEST['action']=='edit'){echo $entry_slip_no;}else{echo "Auto Generated";}?>" readonly="true"/></td>
            	</tr>
            	<tr class="row1">
                 <td class="tabledata1"><strong>Item</strong></td>
				 <td id="vouchar"><input type="text" name="item_name1" style="width:100%;" id="item_name1" value="<?php echo $item;?>" /></td>
                    
                    	<td class="tabledata1"><strong>Job Card  No.</strong></td>
                     <td>
                 
                      <select  name="job_ticket" id="job_ticket" style="width:100%" onchange="getdata1(this.value);">
                    	<option value="0">Select</option> 
                    	<?php
						if($_REQUEST['action'] =='edit'){
							$jobarray =array();
						  	$sql1=DB_query("select id, job_card_no, 1 AS TYPE from job_card where site='".$branch_id."'
							 and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
						
	                 $sql2=DB_query("select id, job_card_no, 2 AS TYPE from job_route_card WHERE branch_id='".$branch_id."'
					         and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);

						while($row=DB_fetch_array($sql1))
						{ 
							$jobarray[] = $row;
						}
						
						while($row1=DB_fetch_array($sql2))
						{ 
							$jobarray[] = $row1;
						}
						foreach($jobarray as $jobrow){
                    	?>
                    	<option value="<?php echo $jobrow['id']."#".$jobrow['TYPE']; ?>" <?php echo ($jobrow['id']==$job_card_id) ? "selected" : "" ;?>><?php echo $jobrow['job_card_no']; ?></option>
                    	<?php } 
						}
						?></select>                     </td>
                     <td class="tabledata1"><span class="tabledata1"><strong>Job Card Date</strong></span></td>
                     <td><input type="text" name="job_date" id="job_date" style="width:100%;" value="<?php echo $job_card_date;?>" /></td>
            	</tr>
    
	   <tr class="row1">
      	<td class="tabledata1"><strong>WO No.</strong></td>
                    <td id="vouchar">
					<input type="text" name="indent_no" style="width:100%;" id="indent_no" value="<?php echo $s->GetFieldValue('prd_wo','id="'.$wo_no.'"','wo_no');?>" />
					<input type="hidden" name="indent_id" style="width:100%;" id="indent_no" value="<?php echo $indent_id;?>" />					</td>
                    	<td class="tabledata1"><strong>Size</strong></td>
                     <td>
					 <input type="text" name="size" style="width:100%;" id="size" value="<?php echo $s->GetFieldValue('size_master','id="'.$size_id.'"','size');?>" />
					<input type="hidden" name="size_id" style="width:100%;" id="size_id" value="<?php echo $size_id;?>" />					 </td>   
                     <td>&nbsp;</td>
                     <td>&nbsp;</td>
	   </tr>
      </table>
        </div></td>
      </tr> 
    
    <tr class="row1">
        <td nowrap="nowrap" colspan="2" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
            	
      </table></div></td>
      </tr> 
   
   <tr class="row1"><td><h3> Daily Production Details: </h3>
                    
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr class="row1">     <td width="14%" class="tabledata1"><strong>Process Name</strong></td>
                    <td width="19%">
                    	<select name="process_name" style="width:100%"  id="process_name" onchange="showmachine(this.value)">
                     	<option value="0">Select</option>
                     	<?php
                     	$data=DB_query("select * from production_process_master",$db);
                     	while($row=DB_fetch_array($data))
						{
                     	 ?>
                     	<option value="<?php echo $row['id']; ?>" <?php echo ($row['id']==$process_name) ? "selected" : "" ;?>><?php echo $row['manuf_process_name']; ?></option>
                     	<?php } ?>
                  </select></td>
                    <td width="17%" class="tabledata1"><strong>Machine Center</strong></td>
                     <td width="20%"><select name="machine" style="width:100%"  id="machine">
                     	<option value="0">Select</option>
                     	<?php
                     	$data=DB_query("select * from machine_center",$db);
                     	while($row=DB_fetch_array($data))
						{
                     	 ?>
                     	<option value="<?php echo $row['id']; ?>" <?php echo ($row['id']==$machine_center) ? "selected" : "" ;?>><?php echo $row['code']; ?></option>
                     	<?php } ?>
                  </select></td>
                     <td width="14%" class="tabledata1"><span class="tabledata1"><strong>Machine Operator</strong></span></td>
                     <td width="16%"><select name="machine_operator" style="width:100%" id="machine_operator">
                       <option value="0">Select</option>
                       <?php
                     	$data1=DB_query("select * from production_operator_master",$db);
                     	while($row1=DB_fetch_array($data1))
						{
                     	 ?>
                       <option value="<?php echo $row1['id']; ?>" <?php echo ($row1['id']==$machine_operator) ? "selected" : "" ;?>><?php echo $row1['operator_name']; ?></option>
                       <?php } ?>
                     </select></td>
                     
              </tr>
                     <tr class="row1">
                     	  <td class="tabledata1"  ><strong>Process Start Time </strong></td>
                    
                       	<td ><input type="text" name="startdate" id="startdate" value="<?php echo $process_in_date;?>"  style="width:55%"  class="datepicker">
                          <input type="text" name="starttime" id="starttime" value="<?php echo $process_in_time; ?>"  class="timepicker"  style="width:42%" /></td>
                    <td class="tabledata1"><strong>Process End Time</strong></td>
                    <td><input type="text" name="enddate" id="enddate" value="<?php echo $process_out_date;?>"  style="width:55%" class="datepicker" />
                      <input type="text" name="endTime" id="endTime" value="<?php echo $process_out_time;?>" class="timepicker" style="width:42%" /></td>
                    <td class="tabledata1"><span class="tabledata1"><strong>Total Process Hrs</strong></span></td>
					 <td><input type="text" name="total_process_hrs" style="width:100%;" readonly="readonly" value="<?php echo $total_hrs;?>" onfocus="calhrs()" /></td>
                     </tr>
                    <tr class="row1">
                      <td class="tabledata1"><strong>Production Shift</strong></td>
                      <td><select name="production_shift"
		    style="width:100%;" id="production_shift">
                        <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['id']==$production_shift) ? "selected" : "" ;?>><?php echo $shift_row['shift_name']; ?></option>
                        <?php } ?>
                      </select>
                      <td class="tabledata1"><strong>Process Producion Date</strong></td>
                    <td><input type="text" name="process_prod_date" class="datepicker" style="width:100%;" value="<?php if($process_prod_date!="") echo $process_prod_date; else echo date('d/m/Y') ?>"/></td>
                    <td class="tabledata1"><span class="tabledata1"><strong>Actual Prod Qty</strong></span></td>
                    <td><input type="text" name="actual_prod_qty" style="width:100%;" id="actual_prod_qty" value="<?php echo $actual_prod_qty;?>" /></td>
                   
                    </tr>   
                     <tr class="row1">                  	             
                     <td class="tabledata1"><strong>Rejection allowed</strong></td>
                     <td><input type="text" name="rejection_allowed" id="rejection_allowed" style="width:100%;" value="<?php echo $rejection_allow;?>" onkeyup="showsubitem(this.value)" /></td>
                     <td class="tabledata1"><span class="tabledata1"><strong>Production Qty</strong></span></td>
                    <td><input type="text" name="production_qty" id="production_qty" style="width:100%;" value="<?php echo $production_qty;?>"  /></td>
                    
                     </tr>
               
            </table></td></tr>
                <tr class="row1">
				<td><h3>BreakDown Process Production</h3>
                 
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                 <tr class="row1">
          <td class="tabledata1" width="14%"><strong>Breakdown Applicable </strong>:</td>
          <td valign="top" width="19%">
		  <select style="width:100%;" name="breakdown_applicable" id="breakdown_applicable">
            	<option value="NO" <?php echo ($breakdown_applicable == "NO") ? "selected" : "";?>>No</option>
				<option value="Yes" <?php echo ($breakdown_applicable == "Yes") ? "selected" : "";?>>Yes</option>
          </select></td>          
          <td width="17%" class="tabledata1"><strong>Breakdown Type :</strong></td>
          <td width="20%" valign="top"><select style="width:100%;" name="breakdown_type" id="breakdown_type">
          	<option value="0">--Select--</option>
            	<?php
            	$breaktype=DB_query("select * from break_down_master",$db);
				while($break_row=DB_fetch_array($breaktype))
				{            	
            	 ?>
            	 <option value="<?php echo $break_row['id']; ?>" <?php echo ($break_row['id']==$breakdown_type) ? "selected" : "" ;?>><?php echo $break_row['brack_down_type']; ?></option>
            	 <?php } ?>
          </select></td>
          
          <td width="14%" valign="top" class="tabledata1"><span class="tabledata1"><strong>Maintenance Dept :</strong></span></td>
          <td width="16%" valign="top"><select style="width:100%;" name="maintenance_dept" id="maintenance_dept">
            <option value="0">--Select--</option>
            <?php
            	$depart=DB_query("select * from deptmaster",$db);
            	while($depart_row=DB_fetch_array($depart))
				{
            	 ?>
            <option value="<?php echo $depart_row['id']; ?>" <?php echo ($depart_row['id']==$maintenance_dept) ? "selected" : "" ;?>><?php echo $depart_row['deptname']; ?></option>
            <?php } ?>
          </select></td>
              </tr>
       
            <tr class="row1">
            	<td class="tabledata1"><strong>Breakdown Date &amp; Time</strong> :</td>
          <td valign="top"><input type="text" name="break_down_strat_date" id="break_down_strat_date" value="<?php echo $break_down_strat_date;?>"   style="width:55%" class="datepicker" /> 
                     	<input type="text" name="break_down_s_time" id="break_down_s_time" value="<?php echo $break_down_s_time;?>" style="width:42%" class="timepicker"  /></td>
            	
            	<td class="tabledata1"><strong>End Date &amp; Time :</strong></td>
          <td valign="top"><input type="text" name="break_down_end_date" id="break_down_end_date" value="<?php echo $break_down_end_date;?>"   style="width:55%" class="datepicker" /> 
                     	<input type="text" name="break_down_e_time" id="break_down_e_time" value="<?php echo $break_down_e_time;?>" style="width:42%" class="timepicker"  /></td>
           <td valign="top" class="tabledata1"><strong>Breakdown in Minutes:</strong></td>
           <td valign="top"><input style="width:100%;" type="text" name="breakdown_minute" id="breakdown_minute" value="<?php echo $breakdown_minute; ?>" /></td>
            </tr>
		   
		   <tr class="row1">
           	 <td class="tabledata1"><strong>Breakdown Reason :</strong></td>
           <td valign="top">
          	<select style="width:100%;" name="breakdown_reason" id="breakdown_reason">
          	<option value="0">--Select--</option>
            	<?php
            	$breaktype1=DB_query("select * from break_down_type",$db);
				while($break_row1=DB_fetch_array($breaktype1))
				{            	
            	 ?>
            	 <option value="<?php echo $break_row1['id']; ?>" <?php echo ($break_row1['id']==$breakdown_reason) ? "selected" : "" ;?>><?php echo $break_row1['breakdown_reason']; ?></option>
            	 <?php } ?>
          </select>          	</td>  
         
          <td class="tabledata1"><strong>Breakdown Desc :</strong></td>
          <td valign="top"><input  type="text" style="width:100%;" name="breakdown_desc" id="breakdown_desc" value="<?php echo $breakdown_desc; ?>" /></td>
          <td valign="top" class="tabledata1"><strong>Sub Breakdown  :</strong></td>
          <td valign="top"><select style="width:100%;" name="sub_breakdown" id="sub_breakdown">
            <option value="0">Select</option>
            <?php $sub=DB_query("select * from tbl_sub_break_type",$db);
			while($rowsub=DB_fetch_array($sub))
			{
				?>
            <option value="<?php echo $rowsub['id']; ?>" <?php echo ($rowsub['id']==$sub_break_type) ? "selected" : "" ;?>><?php echo $rowsub['sub_breaktype']; ?></option>
            <?php } ?>
          </select>
            <input type="hidden" name="brkdid" id="brkdid" value="<?php echo $brkid;?>" /></td>
		   </tr>
          <tr class="row1">
       <td class="tabledata1"><strong> Excu Name :</strong></td>
          <td valign="top"><select name="maintennace_ex_name" style="width:100%;" id="maintennace_ex_name">
            <option value="0">--Select--</option>
            <?php
            	$depart1=DB_query("select * from production_maintenance_master",$db);
            	while($depart_row1=DB_fetch_array($depart1))
				{
            	 ?>
            <option value="<?php echo $depart_row1['id']; ?>" <?php echo ($depart_row1['id']==$maintenance_executive_name) ? "selected" : "" ;?>>
            <?php  echo $depart_row1['maintenance_name']; ?>
            </option>
            <?php } ?>
          </select></td>
            <td >&nbsp;</td>
			
          <td colspan="3">&nbsp;</td>
            </tr>    
           </table></td></tr>
                <tr class="row1"><td> <h3>Sub Item Details</h3>
              	<div id="datasub">
               <table width='100%' border='0' cellspacing='2' cellpadding='2' >
              <tr>
                <td><strong>S.No</strong></td>
               <td><strong>Item Code </strong></td>
                <td ><strong>Item Name </strong></td>				
				     <td ><strong>Process Qty</strong></td>
                <td ><strong>Actual Qty</strong></td>     
                  
              </tr>
 
 <?php 
              $i=1;
              $j=0;
             
          $sql3=DB_query("select * from job_card_item_details where jobid='".$job_card_id."'",$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');  
           
            $orderqty=$s->GetFieldValue("daily_process_sub_item_details","parentid='".$_REQUEST['ID']."' and
              processid='".$process_name."' and mst_itemid='".$row5['mst_itemid']."'","processqty");
            $actualqty=$s->GetFieldValue("daily_process_sub_item_details","parentid='".$_REQUEST['ID']."' and
              processid='".$process_name."' and mst_itemid='".$row5['mst_itemid']."'","actualqty");
           ?>
           <tr>
              	<td><?php echo $i; ?></td>
               	<td align='center'><input type='text' name='itemcode[]'  value='<?php echo $itemcode; ?>' readonly style='width:100%'/><input type='hidden' name='itemid[]'  value='<?php echo $row5['mst_itemid']; ?>' readonly/>
                   </td>
                <td align='center' width='25%'><input type='text' name='item_name[]'  value='<?php echo $itemname; ?>' readonly style='width:100%'/></td>
                
				
                <td align='center'><input type='text'  name='processqty[]'  value='<?php echo $orderqty; ?>' id='total_req_qty_<?php echo $j; ?>' readonly style='width:100%' /></td>  
                <td align='center'><input type='text'   name='actual[]' value='<?php echo $actualqty; ?>'  id='act_cons_<?php echo $j; ?>' style='width:100%' /></td>   
               
              </tr>
              <?php 
               $i++; $j++; }             
              
               
               ?>
               </table>
                   
                </div>
                <!--<tr class="row1"><td> <h3>Raw Material Consumptions</h3>
               
               	<div id="data12">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
              <tr class="row1">
               <td class="tabledata1"><strong>S.No</strong></td>
               <td class="tabledata1"><strong>Item Code </strong></td>
               <td width='25%' class="tabledata1"><strong>Item Name </strong></td>
	       <td class="tabledata1"><strong>Unit</strong></td>
<!--	       <td class="tabledata1"> Group </td>
               <td class="tabledata1">Make</td>
           <td class="tabledata1">Grade</td>
             <td class="tabledata1"><strong>Size</strong></td>
               <td class="tabledata1"><strong>Total Req Qty</strong></td>
               <td class="tabledata1"><strong>Act Consume Qty</strong></td>
               <td class="tabledata1"><strong>Diff. Qty</strong></td>
              </tr>
			  
			  	//if($_REQUEST['action'] =='edit' || $_REQUEST['action']=='view'){
				
					//$sqlitem = "SELECT * FROM daily_raw_material_consu WHERE daily_id='".$_REQUEST['ID']."'";
					//$res = DB_query($sqlitem,$db);
					//$cnt = 1;
					//$j=0;
					//while($row5 = DB_fetch_array($res))
					//{
					//$unit=$s->getField('item_master','id',$row5['mst_itemid'],'mst_unitid');
					//$unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
				//$data3.="<tr class='row1'>";
			   //$data3.="<td align='center'>".$cnt."</td>";
			//$data3.="<td align='center'><input type='text' name='item_code[$j]'  
			//value='".$s->getField('item_master','id',$row5['mst_itemid'],'StockID')."' readonly/></td>";
			//$data3.="<td align='center' width='25%'><input type='text' name='itemname[$j]' 
			// value='".$s->getField('item_master','id',$row5['mst_itemid'],'item_name')."' readonly/></td>";
			//$data3.="<td align='center'><input type='text' name='unit[$j]'  value='".$unitname."'readonly/></td>";
						//$data3.="<td align='center'><input type='text'  name='grade[$j]'  value='".$row5['grade']."'readonly/></td>";
	//$data3.="<td align='center'><input type='text'  name='size[$j]'   value='".$row5['size']."'readonly/></td>";
	//$data3.="<td align='center'><input type='text'  name='total_req_qty[$j]'  
	//value='".$row5['total_req_qty']."' id='total_req_qty_$j' readonly/></td>";  
	//$data3.="<td align='center'><input type='text'  name='act_cons[$j]'  id='act_cons_$j' 
	//value='".$row5['act_consu_qty']."' /></td>";   
	//$data3.="<td align='center'><input type='text'  name='diff_qty[$j]'  id='diff_qty_$j' 
	//value='".$row5['diff_qty']."' onfocus='caldiff($j)' readonly/></td>";
	//$data3.="<input type='hidden' name='itemRowId[]' value='".$row5['id']."' /></tr>";
					  //$cnt++;$j++;
					//}
					
				//}
				//echo $data3;
			  ?>
			  </table>
      	     </div></td></tr>-->
            
                 
                 <tr class="row1"><td>
		    <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr class="row1">
                 <td class="tabledata1" style="width:146px;"><strong>Remarks</strong></td>
                    <td><textarea name="remarks" style="width:100%"><?php echo $remarks;?></textarea>
               	  </td>
                   
                </tr> </table></td></tr>
             <tr class="row1"><td>
		<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr class="row1">
                 <td class="tabledata1" style="width:146px;"><strong>Created By</strong></td>
                    <td><input type="text" name="created" style="width:100%" value="<?php echo $created;?>"></td>
				     <td class="tabledata1"><strong>Approved By PPC Head</strong></td>
				     <td><select name="approved"  style="width:100%">
					<option value="0">Select</option>
					<option value="Yes" <?php echo ($approved_by =="Yes") ? "selected" : "";?>>Yes</option>
					<option value="No" <?php echo ($approved_by =="No") ? "selected" : "";?>>No</option>
					<option value="Pending" <?php echo ($approved_by =="Pending") ? "selected" : "";?>>Pending</option>
					</select></td></tr>
										</table></td></tr></table>
							<?php if($_REQUEST['action']!='view') { ?>			
						<p align="center"><input type="submit" name="Save" class="search" value="Save" onclick="return validatedata();" /></p>				<?php } else {?>
						
		<a href="index.php?route=daily_production_entrylist&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><p align="center"><input type="button" name="Back" class="search" value="back"  /></p></a>					
<?php } ?>
</form>



</div>
</div></div>







<script language="JavaScript"> 
  
function getdata(str) 
{	 
	
if (str.length==0)
  {
  document.getElementById("vouchar").innerHTML="";
 
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
		var data = xmlhttp.responseText.split("##");
      	//document.getElementById("vouchar").innerHTML=data[0];
		document.getElementById("job_ticket").innerHTML=data[1];
    }
  }
 
xmlhttp.open("GET","get_entryslip_jobcard.php?site="+str,true);
xmlhttp.send();
}

function calhrs()
{
var k=document.getElementById("starttime").value;
var j=document.getElementById("endTime").value;	
var k1=k.split(":");
var k2=j.split(":");
var hourDiff =  timeHourDifference(j,k);
}

function getdata1(str)
{
var str1 = str.split("#");

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	var data=xmlhttp.responseText.split("__");	 
	document.getElementById("item_name1").value=data[0];
	document.getElementById("job_date").value=data[1];
	//document.getElementById("data12").innerHTML=data[2];
   document.getElementById("datasub").innerHTML=data[9];
	document.getElementById("actual_prod_qty").value=data[3];
	document.getElementById("production_qty").value=data[3];	
	document.getElementById("process_name").innerHTML=data[4];
	document.getElementById("machine").innerHTML=data[5];
	document.getElementById("machine_operator").innerHTML=data[6];
	document.getElementById("indent_no").value=data[7];
	document.getElementById("indent_id").value=data[8];    
  }
  }
  if(str1[1] == 1)
	xmlhttp.open("GET","get_daily_production_job1.php?site="+str1[0],true);
  else  
	xmlhttp.open("GET","get_daily_production_job.php?site="+str1[0],true); 
xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);


}
function percentage()
{
var k=document.getElementById("production_qty").value;
var k1=document.getElementById("rejection_allowed").value;
var amount=parseFloat(k)*parseFloat(k1);
amount1=amount/100;
var amt=parseFloat(k)-parseFloat(amount1);
document.getElementById("rejqty").value=amt;
	
}
function caldiff(str)
{	
var k=document.getElementById("total_req_qty_"+str).value;
var k1=document.getElementById("act_cons_"+str).value;
var amount=parseFloat(k)-parseFloat(k1);	
document.getElementById("diff_qty_"+str).value=amount;	
}

function validatedata()
{

if(document.getElementById("site").value=='000')
{
alert("Must Select Branch Name");
document.getElementById("site").focus();
return false;	
}	
if(document.getElementById("job_ticket").value=='0')
{
alert("Must Select Job Ticket No");
document.getElementById("job_ticket").focus();
return false;		
}	
if(document.getElementById("machine").value=='0')
{
alert("Must Select Machine Center");
document.getElementById("machine").focus();
return false;	
	
}	
if(document.getElementById("process_name").value=='0')
{
alert("Must Select process_name");
document.getElementById("process_name").focus();
return false;	
	
}	
if(document.getElementById("machine_operator").value=='0')
{
alert("Must Select Operator");
document.getElementById("machine_operator").focus();
return false;	
	
}	
if(document.getElementById("production_shift").value=='0')
{
alert("Must Select production shift");
document.getElementById("production_shift").focus();
return false;	
	
}	
if(document.getElementById("breakdown_applicable").value=='Yes')
{
	
	if(document.getElementById("breakdown_type").value=='0')
	{
	alert("Must Select Breakdown Type");
	document.getElementById("breakdown_type").focus();
	return false;	
		
	}	
	if(document.getElementById("maintenance_dept").value=='0')
	{
	alert("Must Select Maintenance Dept");
	document.getElementById("maintenance_dept").focus();
	return false;	
		
	}	
	if(document.getElementById("maintennace_ex_name").value=='0')
	{
	alert("Must Select Maintenance Ex Name");
	document.getElementById("maintennace_ex_name").focus();
	return false;	
		
	}	
	if(document.getElementById("breakdown_reason").value=='0')
	{
	alert("Must Select Breakdown Reason ");
	document.getElementById("breakdown_reason").focus();
	return false;	
		
	}	
	if(document.getElementById("sub_breakdown").value=='0')
	{
	alert("Must Select Sub Breakdown  ");
	document.getElementById("sub_breakdown").focus();
	return false;	
		
	}

}	
if(document.getElementById("rejection_allowed").value=='')
{
alert("Must Enter Rejection Allowed  ");
document.getElementById("rejection_allowed").focus();
return false;	
	
}	


return true;
	
	
}

function showsubitem(str)
{
 
 if (str.length==0)
  {
  document.getElementById("datasub").innerHTML="";
 
  return;
  }
  else if(document.getElementById("actual_prod_qty").value=='')
   {
    alert("Plz Check Actual Production Qty ");
    document.getElementById("rejection_allowed").value='';
    document.getElementById("datasub").innerHTML="";
    return ;
   }
 else
  {
  var actulqty=document.getElementById("actual_prod_qty").value; 
  var prdqty=parseFloat(document.getElementById("actual_prod_qty").value)-parseFloat(str);
  document.getElementById("production_qty").value=prdqty.toFixed(2); 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
    var data=xmlhttp.responseText.split("__");	 
	document.getElementById("datasub").innerHTML=data[0];
		
    }
  }
  }
 var jobcard=document.getElementById("job_ticket").value;
 
xmlhttp.open("GET","get_daily_production_subitem.php?site="+prdqty+"&jobcard="+jobcard,true);
xmlhttp.send();

}


function showmachine(str)
{

if (str.length==0)
  {
  document.getElementById("machine").innerHTML="";
 
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     //alert(xmlhttp.responseText);
    var data=xmlhttp.responseText.split("__");	 
	document.getElementById("actual_prod_qty").value=data[0];
	//document.getElementById("production_qty").value=data[0];
	document.getElementById("machine").innerHTML=data[1];
	document.getElementById("machine_operator").innerHTML=data[2];		
   document.getElementById("datasub").innerHTML=data[3];		
    }
  }
 var jobcard=document.getElementById("job_ticket").value;
 
xmlhttp.open("GET","get_machine_jobcard.php?site="+str+"&jobcard="+jobcard,true);
xmlhttp.send();




}

$('.timepicker').timepicker();

</script>
