<?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'])
{
$fstatus=true;
  if($_REQUEST['site']=='000')
  {
  	  $msgErr[]="Please Select Branch Name"	;
      $fstatus=false;
  }
  if($_REQUEST['job_ticket']=='')
  {
  	  $msgErr[]="Please Enter Job Ticket No"	;
      $fstatus=false;
  }	
	 if($_REQUEST['job_date']=='')
  {
  	  $msgErr[]="Please Select  Date";
      $fstatus=false;
  }
  if($_REQUEST['pp_slip']=='')
  {
  	  $msgErr[]="Please Select  PP Slip Date";
      $fstatus=false;
  }
   if($_REQUEST['item_name1']=='')
  {
  	  $msgErr[]="Please Select Item  Name"	;
      $fstatus=false;
  }
   if($_REQUEST['entry_slip']=='')
  {
  	  $msgErr[]="Must Enter Entry Slip"	;
      $fstatus=false;
  }
  if($_REQUEST['process_name']=='0')
  {
  	  $msgErr[]="Must Select Process Name"	;
      $fstatus=false;
  }
	 if($_REQUEST['process_prod_date']=='')
  {
  	  $msgErr[]="Must Enter Process date"	;
      $fstatus=false;
  }
	 if($_REQUEST['machine']=='0')
  {
  	  $msgErr[]="Must Select Machine Center"	;
      $fstatus=false;
  }
  if($_REQUEST['machine_operator']=='0')
  {
  	  $msgErr[]="Must Select Machine Operator"	;
      $fstatus=false;
  }
  if($_REQUEST['actual_prod_qty']=='')
  {
  	  $msgErr[]="Must Enter Production Qty"	;
      $fstatus=false;
  }
   if($_REQUEST['startdate']=='')
  {
  	  $msgErr[]="Must Select Start Date"	;
      $fstatus=false;
  }
  if($_REQUEST['enddate']=='')
  {
  	  $msgErr[]="Must Select End Date"	;
      $fstatus=false;
  }
 	if($_REQUEST['production_shift ']=='0')
  {
  	  $msgErr[]="Please Select Production Shift"	;
      $fstatus=false;
  }
  if($_REQUEST['rejection_allowed']=='')
  {
  	  $msgErr[]="Please Enter Rejection Allowed"	;
      $fstatus=false;
  }
  if($_REQUEST['rejqty']=='')
  {
  	  $msgErr[]="Please Enter Rejection Qty"	;
      $fstatus=false;
  }
  if($_REQUEST['approved']=='0')
  {
  	  $msgErr[]="Please Select Approved By"	;
      $fstatus=false;
  } 
	
}
if($_REQUEST['Save']!='' and $fstatus)
{
$insert="insert into daily_production_process set entry_slip_no='".$_REQUEST['entry_slip']."',
         job_card_id='".$_REQUEST['job_ticket']."',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']."'";	
      $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
	$query=DB_query($insert,$db,$ErrMsg);
	$Lastreq_id=DB_Last_Insert_ID($db,'bill_material',$ErrMsg);
     if($Lastreq_id!='')
	 {
	$insert2="insert into daily_production_breakdown set daily_id='".$Lastreq_id."',
	           breakdown_applicable='".$_REQUEST['breakdown_type']."'
	           ,maintenance_dept='".$_REQUEST['maintenance_dept']."'
	           ,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."',
			          item_code='".$_REQUEST['item_code'][$i]."',item_name='".$_REQUEST['itemname'][$i]."',unit='".$_REQUEST['unit'][$i]."'
			          ,group1='".$_REQUEST['group'][$i]."',make='".$_REQUEST['make'][$i]."',grade='".$_REQUEST['grade'][$i]."'
			          ,gsm='".$_REQUEST['gsm'][$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);
			}
			
			
			   	
	 		 	
	 }    
	  $s->pageLocation('index.php?route=daily_production_entrylist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);
	
	
}



?>

<form action="" method="post" >
<p align="center"><strong><h2 align="center">Daily Production Entry  Against Job Card</h2></strong></p>
<br>
<table width="70%">	
<?php if(count($msgErr)>0){?>
   <tr>
   <td colspan="4"><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo "<div class='error'>".$msgErr[$i].'</div>';
   }
    ?></td>
   </tr>
   <?php } ?>	
	</table>
<p align="center"><strong>Branch:</strong>
	 <?php
	
 		$sql = 'SELECT loccode, locationname FROM locations';
	 	$resultStkLocs = DB_query($sql,$db);
		?>
	<select name="site" style="width:100px" onchange="getdata(this.value);">
	<option value="000">Select</option>
      <?php    
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
      <option value="<?php echo $myrow['loccode']; ?>"><?php echo $myrow['locationname'];?></option>
      <?php  }	?> 
    </select></p>
   
<p align="left"><strong>General Details</strong></p>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
            <table width="100%" cellpadding="2" cellspacing="1" border="0">
            	
            	<tr>
                 <th align="left" width="24%"><strong>Entry Slip No.</strong></th>
                    <td width="27%" id="vouchar"><input type="text" name="entry_slip" style="width:100%;" id="entry_slip"/></td>
                    	<th align="left" width="20%"><strong>Job Card  No.</strong></th>
                     <td><select  name="job_ticket" id="job_ticket" style="width:100%" onchange="getdata1(this.value);" >
                    	<option value="0">Select</option> 
                    	<?php
                    	$sql=DB_query("select * from job_route_card",$db);
						while($row=DB_fetch_array($sql))
						{ 
                    	?>
                    	<option value="<?php echo $row['id']; ?>"><?php echo $row['job_card_no']; ?></option>
                    	<?php } ?></select>
                     </td>
      </tr>
      </table></div></td>
      </tr> 
      <tr>       	
    <td valign="top">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td colspan="4" id="quoteId">
     
        <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" >
    <tr>
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
            <table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr><tr>
                 <th align="left" width="24%"><strong>Item</strong></th>
                    <td width="27%" id="vouchar"><input type="text" name="item_name1" style="width:100%;" id="item_name1"/></td>
                    	<th align="left" width="20%"><strong>Job Card Date</strong></th>
                     <td><input type="text" name="job_date" id="job_date" style="width:100%;"></td>                  
      </tr>
        </table></div>      
        </td>
        </tr>
    </table></td></tr></table></td></tr>
    <tr>
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
            <table width="100%" cellpadding="2" cellspacing="1" border="0">
            	 <tr>
        <th align="left" width="24%"><strong>PP Slip No/Date</strong></th>
        <td width="27%" id="vouchar"><input type="text" name="pp_slip" style="width:100%;" id="pp_slip" class="datepicker"/></td><td></td><td></td>
      </tr>
      </table></div></td>
      </tr> 
   
   <tr><td><p align="left"><strong> Daily Production Details: </strong></p>
                    <table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr>     <th align="left" width="5%"><strong>Process Name</strong></th>
                    <td width="27%" >
                    	<select name="process_name" style="width:100%" >
                     	<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['manuf_process_name']; ?></option>
                     	<?php } ?>
                     </select>
                    	
                    	</td>
                    <th  align="left"><strong>Machine Center</strong></th>
                     <td><select name="machine" style="width:100%" >
                     	<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['code']; ?></option>
                     	<?php } ?>
                     </select></td>
                     </tr>
                     <tr>
                     	  <th width="33%"  align="left" ><strong>Machine Operator</strong></th>
                     <td  width="25%">
                     	<select name="machine_operator" style="width:100%" >
                     	<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['operator_name']; ?></option>
                     	<?php } ?>
                     </select>
                     	
                     	
                     	
                     	
                     </td>
                       	<th width="24%" align="left"><strong>Process Start Time
                       		</strong></th>
                    <td width="27%"><input type="text" name="startdate" id="startdate" value="<?php echo $startdate;?>"  style="width:60%"  class="datepicker"  />
                    	 <input type="text" name="starttime" id="starttime" value="<?php echo $timestamp; ?>"  style="width:35%" />
                    </td></tr>
                    <tr>
                      <th align="left"><strong>Process End Time</strong></th>
                     <td><input type="text" name="enddate" id="enddate" value="<?php echo $enddate;?>"  style="width:60%" class="datepicker" /> 
                     	<input type="text" name="endTime" id="endTime" value="<?php echo $timestamp;?>" style="width:35%" />
                     
                  	<th width="15%" align="left"><strong>Production Shift</strong></th>
                    <td width="27%"><select name="production_shift" style="width:100%;"><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></tr>   
                     <tr>
                  	<th width="24%" align="left"><strong>Process Producion Date</strong></th>
                    <td width="27%"><input type="text" name="process_prod_date" style="width:100%;">
                    	</td>
                      <th align="left"><strong>Actual Production/Print Qty</strong></th>
                     <td><input type="text" name="actual_prod_qty" style="width:100%;" id="actual_prod_qty" />
                     	
                     	
                     	
                     </td><//tr>
                 <tr>
                  	<th width="24%" align="left"><strong>Total Process Hrs</strong></th>
                    <td width="27%"><input type="text" name="total_process_hrs" style="width:100%;" readonly="readonly" onfocus="calhrs()" />
                     </td>
                  	<th width="24%" align="left"><strong>Rejection allowed %</strong></th>
                    <td width="27%"><input type="text" name="rejection_allowed" id="rejection_allowed" style="width:100%;">
                    </td></tr>
                    <tr>
                      <th >After Rejection Qty</th>
                     <td><input type="text"  name="rejqty" id="rejqty" onfocus="percentage()" style="width:100%;"/></td>                     
                  	<td ></td>
                    <td >
                     </td></tr>  
                 </table></td></tr>
                <tr><td> <p align="center"><strong>BreakDown Process Production</strong></p>
                 
                 <table width="100%" cellpadding="2" cellspacing="1" border="0" align="center" >
                 <tr>
          <th width="24%" align="left" class="text">Breakdown Applicable :</th>
          <td width="27%" align="left" valign="top"><select style="width:100%;" name="breakdown_applicable" id="breakdown_applicable">
          <option value="0">--Select--</option>
            	<option value="Yes">Yes</option>
            	<option value="NO">No</option>
          </select></td>          
          <th  align="left" class="text">Breakdown Type :</th>
          <td align="left" 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['brack_down_type']; ?></option>
            	 <?php } ?>
          </select></td>
          
          </tr>
        <tr>
          <th align="left" width="27%">Maintenance Department :</th>
          <td align="left" valign="top" width="24%"><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['deptname']; ?></option>
            	 <?php } ?>
          </select></td>
           <th align="left" class="text">Maintenance Executive Name :</th>
          <td align="left" valign="top"><select name="maintennace_ex_name" style="width:100%;" >
          	<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['maintenance_name']; ?></option>
            	 <?php } ?>
          </select>
          </td>
        </tr>
            <tr>
            	<th align="left" class="text">Breakdown Intimation Date &amp; Time :</th>
          <td align="left" valign="top"><input type="text" name="break_down_strat_date" id="break_down_strat_date" value="<?php echo $break_down_strat_date;?>"   style="width:60%" class="datepicker" /> 
                     	<input type="text" name="break_down_s_time" id="break_down_s_time" value="<?php echo $timestamp;?>" style="width:35%" /></td>
            	
            	<th align="left" class="text">Breakdown Intimation End Date &amp; Time :</th>
          <td align="left" valign="top"><input type="text" name="break_down_end_date" id="break_down_end_date" value="<?php echo $break_down_end_date;?>"   style="width:60%" class="datepicker" /> 
                     	<input type="text" name="break_down_e_time" id="break_down_e_time" value="<?php echo $timestamp;?>" style="width:35%" /></td>
          
           </tr><tr>
           	 <th  align="left" class="text">Breakdown Reason :</th>
           <td align="left" 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['breakdown_reason']; ?></option>
            	 <?php } ?>
          </select>
          	
          	</td>  
         
          <th  align="left" class="text">Breakdown in Minutes :</th>
          <td align="left" valign="top"><input style="width:100%;" type="text" name="breakdown_minute" id="breakdown_minute" /></td>
          
          </tr>
          <tr>
       <th  align="left" class="text">Breakdown Description :</th>
          <td align="left" valign="top" colspan="3"><input style="width:100%;" type="text" name="breakdown_desc" id="breakdown_desc" /></td>
            
            </tr>    
           </table></td></tr>
                <tr><td> <p align="center"><strong>Raw Material Consumptions</strong></p>
               <div align="center"><div style="overflow: auto; width: 900px; height: 150px;">
               	<div id="data12">
               		<table width="100%" border="0" cellspacing="2" cellpadding="2" >
              <tr>
               <th align='center'><strong>S.No</strong></th>
               <th align='center' ><strong>Item Code </strong></th>
               <th align='center' width='25%'><strong>Item Name </strong></th>
				<th align='center'><strong>Unit</strong></th>
				<th align='center'><strong> Group </strong></th>
               <th align='center'><strong>Make</strong></th>
                <th align='center'><strong>Grade</strong></th>
               <th align='center'><strong>Gsm</strong></th>
                <th align='center'><strong>Size</strong></th>
               <th align='center'><strong>Total Req Qty</strong></th>
               <th align='center'><strong>Act Consume Qty</strong></th>
                 <th align='center'><strong>Diff. Qty</strong></th>
                  
              </tr></table>
      	      </div></div></div></td></tr>
            
                 
                 <tr><td><table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr>
                 <th align="left" colspan="2" width="25%"><strong>Remarks</strong></th>
                    <td colspan="2" width="75%"><textarea name="remarks" style="width:100%" ></textarea>
                    	</td>
                   
                </tr> </table></td></tr>
             <tr><td> <table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr>
                 <th align="left"  width="25%"><strong>Created By</strong></th>
                    <td  ><input type="text" name="created" style="width:100%">
                    	</td>
				     <th>Approved By PPC Head</th><td><select name="approved"  style="width:100%">
					<option value="0">Select</option>
					<option value="Yes">Yes</option>
					<option value="No">No</option>
					<option value="Pending">Pending</option>
					</select></td></tr>
										</table></td></tr></table>
						<p align="center"><input type="submit" name="Save" value="Save" /></p>				

</form>
<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)
    {
    document.getElementById("vouchar").innerHTML=xmlhttp.responseText;
      }
  }
 
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);
alert(hourDiff);
}

function getdata1(str)
{

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("actual_prod_qty").value=data[3];
	
    }
  }
  xmlhttp.open("GET","get_daily_production_job.php?site="+str,true);
xmlhttp.send();

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

}
function percentage()
{
var k=document.getElementById("actual_prod_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;	
}


</script>
