<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
 $date=date('d/m/Y');
 $time=date('h:i', time());
 $period=date(A);
 $timestamp = date("H:i", time())." ".$period;

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['item_name1']=='')
  {
  	  $msgErr[]="Please Select Item  Name"	;
      $fstatus=false;
  }
   if($_REQUEST['vouchar_no']=='')
  {
  	  $msgErr[]="Must Enter Vouchar Slip"	;
      $fstatus=false;
  }
  if($_REQUEST['party_name']=='')
  {
  	  $msgErr[]="Must Enter Party Name"	;
      $fstatus=false;
  }
	 if($_REQUEST['print_date']=='')
  {
  	  $msgErr[]="Must Required Product Print date"	;
      $fstatus=false;
  }
	 if($_REQUEST['production_shift']=='0')
  {
  	  $msgErr[]="Must Select Productin Shift"	;
      $fstatus=false;
  }
  if($_REQUEST['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['total_hrs']=='')
  {
  	  $msgErr[]="Must Enter Total Hrs"	;
      $fstatus=false;
  }
  
	if($_REQUEST['machine ']=='0')
  {
  	  $msgErr[]="Please Select Machine Center"	;
      $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 job_production_card set vouchar_no='".$_REQUEST['vouchar_no']."'
         ,job_card_id='".$_REQUEST['job_ticket']."',job_card_date='".$_REQUEST['job_date']."',sop_no='".$_REQUEST['wo_no']."'
         ,party_name='".$_REQUEST['party_name']."',
        item_name='".$_REQUEST['item_name1']."',order_qty='".$_REQUEST['order_qty']."'
        ,production_print_date='".FormatDateForSQL($_REQUEST['print_date'])."'
        ,production_shift='".$_REQUEST['production_shift']."',production_qty='".$_REQUEST['prod_qty']."'
        ,start_time='".$_REQUEST['starttime']."',end_time='".$_REQUEST['endTime']."'
        ,total_hrs='".$_REQUEST['total_hrs']."',
        machine_center='".$_REQUEST['machine']."',process='".$_REQUEST['process']."',raw_mat_consumed='".$_REQUEST['raw_mat']."'
        ,rejection_allow='".$_REQUEST['rejection_allowed']."',remarks='".$_REQUEST['remarks']."',created_by='".$_REQUEST['created']."'
        ,approved_ppc='".$_REQUEST['approved']."',branch_id='".$_REQUEST['site']."',start_date='".FormatDateForSQL($_REQUEST['startdate'])."'
        ,enddate='".FormatDateForSQL($_REQUEST['enddate'])."'"	;
	
	$query=DB_query($insert,$db);
	 $s->pageLocation('index.php?route=production_planning_jobcardllist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);
}

?>


<form action="" method="post" enctype="multipart/form-data">
<p align="center"><strong><h2 align="center">Production Planning  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>

<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>V. No</strong></th>
                    <td width="27%" id="vouchar"><input type="text" name="vouchar_no" style="width:100%;" id="vouchar_no"/></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>
                 <th align="left"><strong>Job Card Date	</strong></th>
                    <td><input type="text" name="job_date" id="job_date"  size="6"  style="width:100%;" >
                    	</td>
                    <th align="left"><strong>W/O No.</strong></th>
                     <td><input type="text"  style="width:100%;" name="wo_no" id="wo_no" >
                     </td>
                  </tr><tr>
                  	<th width="24%" align="left"><strong>Party Name</strong></th>
                    <td width="27%"><input type="text" name="party_name" id="party_name" style="width:100%;"/>
                    	</td>
                      <th align="left"><strong>Item Name</strong></th>
                     <td><input type="text"  style="width:100%;" name="item_name1" id="item_name1" >
                     </td></tr> 
                     <tr>
                  	<th width="24%" align="left"><strong>Order Qty</strong></th>
                    <td width="27%"><input type="text" name="order_qty" id="order_qty" style="width:100%;"/>
                    	</td>
                      <td ></td>
                     <td>
                     </td></tr>    
                 </table></div>
       
        </td>
        </tr>
    </table></td></tr></table>
    <p align="left"><strong> Production Planning Parameter Against Job Card No: </strong></p>
                    <table width="100%" cellpadding="2" cellspacing="1" border="1">
                <tr>     <th width="8%"><strong>Production/Print Date</strong></th>
                    <td width="15%"><input type="text" name="print_date" id="print_date"  class="datepicker"  >
                    	</td>
                    <th width="15%"  align="left"><strong>Production Shift</strong></th>
                     <td width="25%" ><select name="production_shift" style="width:100%" >
                     	<option value="0">Select</option>
                     	<?php
                     	$data=DB_query("select * from production_shift",$db);
                     	while($row=DB_fetch_array($data))
						{
                     	 ?>
                     	<option value="<?php echo $row['id']; ?>"><?php echo $row['shift_name']; ?></option>
                     	<?php } ?>
                     </select></td>
                     	  <th width="33%"  align="left" ><strong>Production Qty</strong></th>
                     <td  width="25%"><input type="text"   name="prod_qty" id="prod_qty"  onfocus="data()" >
                     </td>
                  </tr><tr>
                  	<th width="24%" align="left"><strong>Start Time</strong></th>
                    <td width="27%"><input type="text" name="startdate" id="startdate" value="<?php echo $startdate;?>"  style="width:50%"  class="datepicker"  />
                    	 <input type="text" name="starttime" id="starttime" value="<?php echo $timestamp; ?>"  style="width:35%" />
                    	</td>
                      <th align="left"><strong>End Time</strong></th>
                     <td><input type="text" name="enddate" id="enddate" value="<?php echo $enddate;?>"  style="width:50%" class="datepicker" /> 
                     	<input type="text" name="endTime" id="endTime" value="<?php echo $timestamp;?>" style="width:35%" />
                     
                  	<th width="15%" align="left"><strong>Total Hrs</strong></th>
                    <td width="27%"><input type="text" name="total_hrs" id="total_hrs" style="width:65%" onfocus="calhrs()"/>
                    	
                     </td></tr>   
                     <tr>
                  	<th width="24%" align="left"><strong>Machine Center</strong></th>
                    <td width="27%"><select name="machine"><option value="0">Select</option>
                    	<?php
                    	$machine=DB_query("select * from machine_center",$db);
                    	while($machine_data=DB_fetch_array($machine))
						{
                    	?>
                    	<option value="<?php echo $machine_data['id']; ?>"><?php echo $machine_data['code']; ?></option>
                    	<?php } ?>
                    	
                    </select>
                    	</td>
                      <th align="left"><strong>Process</strong></th>
                     <td><select name="process" id="process" >
                     	<?php
                    	$machine1=DB_query("select * from production_process_master",$db);
                    	while($machine_data1=DB_fetch_array($machine1))
						{
                    	?>
                    	<option value="<?php echo $machine_data1['id']; ?>"><?php echo $machine_data1['manuf_process_name']; ?></option>
                    	<?php } ?>
                     
                  	<th width="24%" align="left"><strong>Raw Mat. To Be Consumed.</strong></th>
                    <td width="27%"><select name="raw_mat">
                    <option value="0">Select</option>	
                    <option value="As_per_Store">As per Store</option>                  	
                    	
                    	
                    </select>
                    	
                     </td></tr>  
                      <tr>
                  	<th width="24%" align="left"><strong>Rejection allowed %</strong></th>
                    <td width="27%"><input type="text" name="rejection_allowed" id="rejection_allowed">
                    	</td>
                      <th >After Rejection Qty</th>
                     <td><input type="text"  name="rejqty" id="rejqty" onfocus="percentage()"/></td>                     
                  	<td ></td>
                    <td >
                     </td></tr>  
                 </table>
                 <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>
                  <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","getvouchar_jobcard.php?site="+str,true);
xmlhttp.send();
}

function getdata1(str) 
{	 
	
if (str.length==0)
  {
  document.getElementById("quoteId").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("quoteId").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","get_job_production_card.php?site="+str,true);
xmlhttp.send();
}
function data()
{
document.getElementById("prod_qty").value=document.getElementById("order_qty").value;	
}
 function percentage()
{
var k=document.getElementById("prod_qty").value;
var k1=document.getElementById("rejection_allowed").value;
var k2=document.getElementById("rejqty").value;
var amount=parseFloat(k)*parseFloat(k1);
amount1=amount/100;
var amt=parseFloat(k)-parseFloat(amount1);
document.getElementById("rejqty").value=amt;
	
}
function calhrs()
{
	
var k=document.getElementById("endTime").value;
var k1=document.getElementById("starttime").value;	

}
</script>



