<link rel="stylesheet" href="css/new_mxerp.css">
<?php 
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
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_desc']=='0')
  {
  	  $msgErr[]="Please Select Item  Name"	;
      $fstatus=false;
  }
   if($_REQUEST['process_name']=='0')
  {
  	  $msgErr[]="Please Select Process Name"	;
      $fstatus=false;
  }
  if($_REQUEST['order_qty']=='')
  {
  	  $msgErr[]="Must Enter Order Qty"	;
      $fstatus=false;
  }
	 if($_REQUEST['toll_per']=='')
  {
  	  $msgErr[]="Must Required Tollerence Percentage"	;
      $fstatus=false;
  }
	 if($_REQUEST['total_prod_qty']=='')
  {
  	  $msgErr[]="Must Required Tollerence Production Qty"	;
      $fstatus=false;
  }
	if($_REQUEST['approved_by']=='0')
  {
  	  $msgErr[]="Please Select Approved By"	;
      $fstatus=false;
  }
	
}


if($_REQUEST['Save']!='' and $fstatus)
{
 $insert="insert into job_route_card set job_card_no='".$_REQUEST['job_ticket']."',job_card_date='".FormatDateForSQL($_REQUEST['job_date'])."',customer_name='".$_REQUEST['customer_name']."'
          ,sop_no='".$_REQUEST['sop_no']."',sop_date='".$_REQUEST['sop_date']."',party_order_no='".$_REQUEST['customer_po']."'
          ,part_code='".$_REQUEST['item_desc']."',process_name='".$_REQUEST['process_name']."',batch_no='".$_REQUEST['batch_no']."',order_qty='".$_REQUEST['order_qty']."'
           ,tollerence_per='".$_REQUEST['toll_per']."',total_prod_qty='".$_REQUEST['total_prod_qty']."',branch_id='".$_REQUEST['site']."',CompanyId='".$_SESSION['ACGCompanyId']."'";
		  
          $query=DB_query($insert,$db);	
		  $s->pageLocation('index.php?route=job_route_cardlist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);
}


?>

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

<h1>Job Route Card Creations </h1>

<form action="" method="post">

	<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" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">

                  <tr>
                    <td class="tabledata1">Branch</th>
                    <td colspan="3">	 <?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>


                  <tr>
                    <td class="tabledata1">Job Ticket No</th>
                    <td  id="jobticket"><input type="text" name="job_ticket" id="job_ticket" style="width:100%" readonly>
                      			</td>
                    <td class="tabledata1">Date</th>
                    <td><input type="text" name="job_date" id="job_date"  size="6"  style="width:100%;" class="datepicker">
                    </td>
                  </tr>
                  <tr>
                    <td class="tabledata1">Batch No</th>
                    <td><input type="text" name="batch_no" id="batch_no" style="width:100%;"/></td>
                    <td class="tabledata1">Item Description</th>
                     <td><select name="item_desc" id="item_desc" style="width:100%;" onchange="generateCode(this.value);">                    	
                     	<option value="0">Select</option>	 
			        	<?php 
			        	$sql="select * from item_master ";
						$query=DB_query($sql,$db);
						while($row=DB_fetch_array($query))
						{
			        	?>	
			        	<option value="<?php echo $row['id']; ?>"><?php echo $row['item_name']; ?></option>
			        	<?php } ?>	
			             </select></td>
                  </tr>
                  <tr>
                  	<td class="tabledata1"   nowrap="nowrap">W/O No</th>
                       <td  id="quoteId"><select name="sop_no" id="sop_no" style="width:100%;">  </select></td>
                  <td class="tabledata1"  nowrap="nowrap">Sop Date</th>
                  <td> <input type="text" name="sop_date" style="width:100%;"  id="sop_date"> </td>
                  </tr>
                  <tr>
                    <td class="tabledata1"  nowrap="nowrap">Customer Name</th>
                    <td><input type="text" name="customer_name" id="customer_name" style="width:100%;"/></td>
                    <td class="tabledata1"   nowrap="nowrap">Process Name</th>
                     <td><select  style="width:100%;" name="process_name" id="process_name">
                     <option value="0">Select </option>
            	<?php
            	$sql=DB_query("select * from production_process_master",$db);
				while($rowsql=DB_fetch_array($sql))
				{			
            	 ?>
            	 <option value="<?php echo $rowsql['id']; ?>"><?php echo $rowsql['manuf_process_name']; ?></option>
            	<?php } ?></select></td></tr>
                <tr>
                  <td class="tabledata1"  nowrap="nowrap">Order Qty</th>
                  <td><input name="order_qty" type="text" value=""  style="width:100%;"  id="order_qty"></td>
                  <td class="tabledata1"   nowrap="nowrap">Customer PO Ref No</th>
                  	<td><input name="customer_po" type="text" value="" style="width:100%;" id="customer_po"></td>
                  </tr>
                  <tr>
                  	<td class="tabledata1">Tollerence %</th>
                    <td><input type="text" name="toll_per" id="toll_per" style="width:100%">
                      			</td>
                    <td class="tabledata1">Total Production Qty</th>
                    <td><input type="text" name="total_prod_qty" id="total_prod_qty"  style="width:100%;" onfocus="percentage();">
                    </td>
                  	
                  </tr>
                  <tr>
                  	<td class="tabledata1">Created By</th>
                    <td><input type="text" name="created_by" id="created_by" style="width:100%">
                      			</td>
                    <td class="tabledata1">Approved By Commercial Dept.</th>
                    <td><Select  name="approved_by" id="approved_by"   style="width:100%;" >
                    	<option value="0">Selcct</option>
                    	<option value="Yes">Yes</option>
                    	<option value="No">No</option>
                        <option value="Pending">Pending</option>
                     </select>
                    </td>
                  	
                  </tr>
                  <tr>
                  	<td class="tabledata1">Remarks</th>
                    <td  colspan="3"><textarea  name="created_by" id="created_by" style="width:100%"></textarea>
                      			</td>
                  </tr>
                  </table>


      <p align="center"><input type="submit" name="Save" value="Save"  onclick="return validatedata();"/></p>
      </form>

</div></div>

      
      
<script language="JavaScript"> 
  
function generateCode(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)
    {
    	//alert(xmlhttp.responseText);
    document.getElementById("quoteId").innerHTML=xmlhttp.responseText;
    
    }
  }
 
xmlhttp.open("GET","job_routepop.php?site="+str,true);
xmlhttp.send();
}
function gettotaldata(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("sop_date").value=data[0];
	document.getElementById("customer_name").value=data[1];
	document.getElementById("customer_po").value=data[2];
	document.getElementById("order_qty").value=data[3];
	
    }
  }
  xmlhttp.open("GET","get_totaldata.php?site="+str,true);
xmlhttp.send();

	
}

function percentage()
{
var k=document.getElementById("order_qty").value;
var k1=document.getElementById("toll_per").value;
var amount=parseFloat(k)*parseFloat(k1);
amount1=amount/100;
var amount2=parseFloat(amount1)+parseFloat(k);

document.getElementById("total_prod_qty").value=amount2;
	
}


  
function getdata(str5) 
{	 
	
if (str5.length==0)
  {
  document.getElementById("jobticket").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("jobticket").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","get_entryslip_jobcard.php?site5="+str5,true);
xmlhttp.send();
}

function validatedata()
{

if(document.getElementById("site").value=='000')
{
alert("Must Select Branch Name");
document.getElementById("site").focus();
return false;	
}	
if(document.getElementById("job_date").value=='')
{
alert("Must Select Job Date");
document.getElementById("job_date").focus();
return false;		
}	
if(document.getElementById("item_desc").value=='0')
{
alert("Must Enter item_desc");
document.getElementById("item_desc").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("order_qty").value=='')
{
alert("Must Enter order_qty");
document.getElementById("order_qty").focus();
return false;	
	
}	
if(document.getElementById("toll_per").value=='')
{
alert("Must Enter toll_per");
document.getElementById("toll_per").focus();
return false;	
	
}	
if(document.getElementById("total_prod_qty").value=='')
{
alert("Must Enter total_prod_qty");
document.getElementById("total_prod_qty").focus();
return false;	
	
}	
if(document.getElementById("approved_by").value=='0')
{
alert("Must Select approved_by");
document.getElementById("approved_by").focus();
return false;	
	
}	
return true;
	
	
}



</script>