<link rel="stylesheet" href="css/new_mxerp.css">
<?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']!='')
{
$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'])."',CompanyId='".$_SESSION['ACGCompanyId']."'"	;
		
	
	$query=DB_query($insert,$db);
	 $s->pageLocation('index.php?route=production_planning_jobcardllist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);
}

?>


<div class="body_contain">
<div class="tab_div">


<form action="" method="post" enctype="multipart/form-data">
<h1>Production Planning  Against Job Card</h1>
<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>



<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
<td class="tabledata"  style="width:120px;">Branch:</td>
<td><?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="000">Select</option>
      <?php    
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
      <option value="<?php echo $myrow['loccode']; ?>"><?php echo $myrow['locationname'];?></option>
      <?php  }	?> 
    </select></td>
 </tr>

 </table>

<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:810px;">
            <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
            	
            	<tr>
                  <td class="tabledata" style="width:120px;">V. No</td>
                    <td id="vouchar"  style="width:261px;"><input type="text" name="vouchar_no" style="width:100%;" id="vouchar_no"/></td>
                    	<td class="tabledata"  style="width:128px;">Job Card No</td>
                     <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:810px;">
	   <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr>
                 <td class="tabledata" style="width:120px;">Job Card Date	</td>
                    <td><input type="text" name="job_date" id="job_date"  style="width:100%;" >
                    	</td>
                    <td class="tabledata">W/O No.</td>
                     <td><input type="text"  style="width:100%;" name="wo_no" id="wo_no" >
                     </td>
                  </tr><tr>
                  	<td class="tabledata">Party Name</td>
                    <td><input type="text" name="party_name" id="party_name" style="width:100%;"/>
                    	</td>
                      <td class="tabledata">Item Name</td>
                     <td><input type="text"  style="width:100%;" name="item_name1" id="item_name1" >
                     </td></tr> 
                     <tr>
                  	<td class="tabledata">Order Qty</td>
                    <td colspan="3"><input type="text" name="order_qty" id="order_qty" style="width:100%;"/>
                    	</td>
</tr>    
                 </table></div>
       
        </td>
        </tr>
    </table></td></tr></table>
    <p align="left"> Production Planning Parameter Against Job Card No: </p>
    <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr>     <td class="tabledata" style="width:120px;">Production/Print Date</td>
                    <td><input type="text" name="print_date" id="print_date" style="width:100%"  class="datepicker"  >
                    	</td>
                    <td class="tabledata" style="width:120px;">Production Shift</td>
                     <td><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>
                     	  <td class="tabledata" >Production Qty</td>
                     <td style="width:120px;"><input type="text"   name="prod_qty" id="prod_qty" style="width:100%"  onfocus="data()" >
                     </td>
                  </tr>
				  <tr>
                  	<td class="tabledata">Start Time</td>
                    <td><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>
                      <td class="tabledata">End Time</td>
                     <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%" />
                     
                  	<td class="tabledata">Total Hrs</td>
                    <td><input type="text" name="total_hrs" id="total_hrs" style="width:100%" onfocus="calhrs()"/>
                    	
                     </td></tr>   
                     <tr>
                  	<td class="tabledata">Machine Center</td>
                    <td><select name="machine" style="width:100%"><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>
                      <td class="tabledata">Process</td>
                     <td><select name="process" id="process" style="width:100%" >
                     	<?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 } ?>
						</select></td>
                     
                  	<td class="tabledata">Raw Mat. To Be Consumed.</td>
                    <td><select name="raw_mat" style="width:100%">
                    <option value="0">Select</option>	
                    <option value="As_per_Store">As per Store</option>                  	
                    	
                    	
                    </select>
                    	
                     </td></tr>  
                      <tr>
                  	<td class="tabledata">Rejection allowed %</td>
                    <td><input type="text" name="rejection_allowed" id="rejection_allowed"  style="width:100%;">
                    	</td>
                      <td class="tabledata" >After Rejection Qty</td>
                     <td colspan="3"><input type="text"  style="width:100%" name="rejqty" id="rejqty" onfocus="percentage()"/></td>                     
</tr>  
                 </table>
		 <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr>
                 <td class="tabledata" style="width:120px;">Remarks</td>
                    <td colspan="3"><textarea name="remarks" style="width:100%" ></textarea>
                    	</td>
                   
                  </tr> </table>
	       <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
                <tr>
                 <td class="tabledata" style="width:120px;">Created By</td>
                    <td><input type="text" name="created" style="width:100%">
                    	</td>
				     <td class="tabledata">Approved By PPC Head</td><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" onclick="return validatedata();"/></p>				

</form>


</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)
    {
    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;	
}

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("rejection_allowed").value=='')
{
alert("Must Enter Rejection Allowed");
document.getElementById("rejection_allowed").focus();
return false;	
}	
if(document.getElementById("rejqty").value=='')
{
alert("Must Select Rejection Qty");
document.getElementById("rejqty").focus();
return false;	
}
return true;	
}
</script>



