<?php 
if(isset($_POST['Save']))
{
	 $del1=DB_query("delete from job_process_details where jobid='".$_REQUEST['SID']."'",$db);
	$data['site']=$_REQUEST['mst_branchid'];
	$data['job_date']=FormatDateForSQL($_REQUEST['jobcarddate']);
	$data['priority']=$_REQUEST['priority'];
	$data['remarks']=$_REQUEST['remarks'];  
	$data['startdate']=FormatDateForSQL($_REQUEST['stardate']);
	$data['enddate']=FormatDateForSQL($_REQUEST['finisheddate']);
	$data['step']=$_REQUEST['step'];
	 $condition="id='".$_REQUEST['SID']."'"; 
	$s->RecordEdit('job_card', $data, $condition);
   
	if($_REQUEST['SID']!='')
	{
		
	for($cnt1=0;$cnt1<count($_REQUEST['process']);$cnt1++)
	{
	if($_REQUEST['process'][$cnt1]!=''){
	   $insert3="Insert into job_process_details set
	    jobid='".$_REQUEST['SID']."',  
	   item='".$_REQUEST['item'][$cnt1]."', 
	   process='".$_REQUEST['process'][$cnt1]."',  
	   machine='".$_POST['machine'][$cnt1]."',
	   status1='".$_REQUEST['status1'][$cnt1]."', 
	   operator='".$_POST['operator'][$cnt1]."',   
	   exp_date='".FormatDateForSQL($_REQUEST['exp_com_date'][$cnt1])."',
	   current_status='".$_POST['status'][$cnt1]."'";
	  $result3=DB_query($insert3,$db);					
	}	
	
	}
	}
   $s->pageLocation("index.php?route=Production/JobrouteCard/job_route_creation".$rurl);



     }

$sql1=DB_query("select * from job_card where id='".$_REQUEST['SID']."'",$db);
$row1=DB_fetch_array($sql1);
extract($row1);


?>

<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<div class="body_contain">
<div class="tab_div">

<h1>JOB CARD CREATION</h1>

<form action="" method="post">
<fieldset><legend style="font-size:12px;"><strong>Job Card Creation</strong></legend>
	
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
              <tr>
                    <th width="13%" class="tabledata1">Branch</th>
                    <td width="20%"  id="jobticket">
					<select name="mst_branchid" id="mst_branchid" style="width:100%;"  onchange="showsitename158(this.value)">
					
	        		<?php 			
		          $sql_state=DB_query("SELECT loccode,locationname FROM  
				  locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode='".$site."' ",$db);	
			       while($SiteName=DB_fetch_array($sql_state)) 
				   {	
				   $c='';
				   if($site=$SiteName['loccode'])
				   $c='Selected';		
			        ?>
			<option value="<?php echo $SiteName['loccode']; ?>" <?php echo $c; ?> ><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select></td>
               <th width="13%" class="tabledata1">Job Card No </th>
              <td width="20%"><input type="text" name="jobcard_no" id="jobcard_no" value="<?php echo $job_card_no; ?>" readonly="readonly"  style="width:100%;" > </td>
              <th>Job Card Date</th>
               <td><input type="text" name="jobcarddate" id="jobcarddate" value="<?php echo ConvertSQLDate($job_date); ?>"  style="width:100%;" class="datepicker"></td>
               </tr>
                <tr>
				<th class="tabledata1">W/O No</th>
                    <td><div id="workod">
					<select name="work_order_no" id="work_order_no" style="width:100%;">  
					  
					<?php 
					$floor_sql=DB_query("Select * from prd_wo where id='".$wo_no."'  order by wo_no ASC   ",$db);
	                while($floor_row=DB_fetch_array($floor_sql))
	                {
					$d='';
					  if($wo_no=$floor_row['id'])
					$d='selected';
					?>
		           <option value="<?php echo $floor_row['id']; ?>" <?php echo $d; ?> ><?php echo $floor_row['wo_no'] ; ?></option>
					<?php } ?>
									   
					   </select></div></td>
                    <th class="tabledata1">W/O Item </th>
                     <td><div id="oderitem">
					<?php					
	          echo $item=$s->getField('item_master','id',$work_itemid,'item_name');		     
	     ?>
       
					
			        	 </select></div></td>
                     <th>W/O Date</th>
                     <td><div id="orderdate">
					<?php $ordate=$s->getField('prd_wo','id',$wo_no,'wo_date'); ?>
					 <input type="text" name="orderdate" id="orderdate"  style="width:100%;"
					 value="<?php echo ConvertSQLDate($ordate); ?>"  readonly="true"></div></td>
                  </tr>
                  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Customer Name</th>
                       <td><div id="cliendata">
					   <?php  
					    
					    $venname=$s->getField('clientmaster','id ',$client_id,'c_name'); ?>
	         <input type='text' name='client' id='client' value="<?php echo $venname; ?>" readonly="readonly"  style='width:100%;' >
	
					   
					   </div>
					   </td>
                  <th class="tabledata1"  nowrap="nowrap">Order Dispatch Date</th>
                  <td> <input type="text" name="deliverydate" id="deliverydate"  style="width:100%;" 
				   value="<?php echo ConvertSQLDate($delivery_date); ?>" readonly="readonly"> </td>
                  <th>Mode Of Testing </th>
                  <td><select  style="width:100%;" name="priority" id="priority">
                     <option value="0">-Select-</option>
					  <option value="S"  <?php if($priority=='S') { ?> selected="selected" <?php } ?>>Sampling</option>
					 <option value="M" <?php if($priority=='M') { ?> selected="selected" <?php } ?>>Mass Production</option>
					 <option value="T" <?php if($priority=='T') { ?> selected="selected" <?php } ?>>Testing/Trial</option>
            		
					 
					 </select></td>
                  </tr>
				  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Lot No </th>
                    <td><input type="text" id="batch_no" name="batch_no" value="<?php echo $lotno; ?>" readonly="true"
					 style="width:100%;"/></td>
                  <th class="tabledata1"  nowrap="nowrap">Order Qty.</th>
                  <td><input type="text" name="order_qty" id="order_qty" readonly="readonly" style="width:100%;"
				   value="<?php echo $order_qty; ?>"></td>
                  <th class="tabledata1"  nowrap="nowrap">Order Type</th>
                  <td><input type="text" name="order_type" id="order_type" readonly="readonly" 
				  	  value="<?php echo $Order_type; ?>" ></td>
                  </tr>
				  <tr>
				  <th class="tabledata1"   nowrap="nowrap">Start Date </th>
                    <td><input type="text" id="startdate" name="stardate" value="<?php echo ConvertSQLDate($startdate); ?>"
					class="datepicker" style="width:100%;"/></td>
                  <th class="tabledata1"  nowrap="nowrap">Finished Date </th>
                  <td><input type="text" name="finisheddate" id="finisheddate" class="datepicker"
				  value="<?php echo ConvertSQLDate($enddate); ?>" readonly="readonly" style="width:100%;"></td>
                  <th class="tabledata1"  nowrap="nowrap">Step</th>
                  <td><input type="text" name="step" id="step"  value="<?php echo $step; ?>"></td>
				  </tr>
				  <tr>
				  <th class="tabledata1"   nowrap="nowrap">Card No </th>
                    <td><input type="text" id="cardno" name="cardno"  style="width:100%;"  value="<?php echo $cardno ; ?>"
					readonly="readonly"
					/></td>
                  <th class="tabledata1"  nowrap="nowrap">&nbsp;</th>
                  <td>&nbsp;</td>
                  <th class="tabledata1"  nowrap="nowrap">&nbsp;</th>
                  <td>&nbsp;</td>
				  </tr>
                  
                  </table>
</fieldset>
<!--     
<p align="left">
<input type="button" class="search"   onclick="addRow('dataTable')" value="AddRow" />
<input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete" /></p> -->                 

<fieldset><legend style="font-size:12px;"><strong>Job Card Item Detail</strong></legend> 
<table width="100%" border="1" cellspacing="0" cellpadding="2">
  <tr>
		
           <th><strong>S. No.</strong></th>
           <th></th>
           <th><strong>PART CODE </strong></th>
           <th><strong>ITEM NAME</strong></th>
           <th><strong>UOM</strong></th>
           <th><strong>ITEM QTY</strong></th>
                 </tr>
		 <tbody id="dataTable">
		<?php 
$i=1;
$sql2=DB_query("select * from job_card_item_details where jobid='".$_REQUEST['SID']."'",$db);
while($row2=DB_fetch_array($sql2))
{
$itemcode=$s->getField('item_master','id',$row2['mst_itemid'],'StockID'); 
$itemname=$s->getField('item_master','id',$row2['mst_itemid'],'item_name');
$unit=$s->getField('item_master','id',$row2['mst_itemid'],'mst_unitid'); 
$unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname'); 
?>
      <tr>
     <td class="tabledata"><input name="delitem[]" type="checkbox" value="" id="delitem_<?php echo $i; ?>" /></td>
	  <td class="tabledata"><input  type="hidden"   readonly=""  id="itemdataid_<?php echo $i; ?>"  name="itemdataid[]" value='<?php echo $row2['mst_itemid'];?>'/></td>
<td class="tabledata"><input type="text"  tabindex="" id="itemcode_<?php echo $i; ?>" name="itemcode[]"size="20" onkeyup="opendata(this.value,this.id)"  value='<?php echo $itemcode;?>'/>          </td>
      <td class="tabledata"><input type="text" name="desc[]"  id="descriptions_<?php echo $i; ?>" size="25"  value='<?php echo $itemname;?>' /></td>
      <td class="tabledata"><input type="text" name="uom[]" id="uom_<?php echo $i; ?>" value="<?php echo $unitname; ?>" readonly /> </td>
      <td class="tabledata"><input type="text" name="itemqty[]" id="itemqty_<?php echo $i; ?>" value="<?php echo $row2['prodqty']; ?>"  style="width:100%;"></td>
     
      </tr>
  <?php 
 $i++; }
 
 ?>
  <input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
  </tbody>
	</table>
	<div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  
	</fieldset>
<br />
<!--<p align="left"><input type="button" onClick="addRow1('dataTable1')" value="Add Rows" accesskey="A" class="search" />&nbsp;
<input type="button" class="search"  onclick="deleteRowOrder1('dataTable1')" value="Delete" /></p>-->
<fieldset><legend style="font-size:12px;"><strong>Process Detail</strong></legend> 
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th width="6%"><strong>S.No. </strong></th>
		   <th width="16%"><strong>Item</strong></th>
          <th width="16%"><strong>PROCESS</strong></th>
          <th width="16%"><strong>MACHINE</strong></th>
          <th width="20%"><strong>OPERATOR</strong></th>
          <th width="19%"><strong>EXP COM DATE</strong></th>
		  <th></th>
          <th width="23%"><strong>QC REQUIRED</strong></th>
        </tr>
		<tbody id="dataTable1">
<?php 
$j=1;
$sql3=DB_query("select * from job_process_details where jobid='".$_REQUEST['SID']."'",$db);
while($row3=DB_fetch_array($sql3))
{

?>	
     <tr>
    <td class="tabledata"><input type="checkbox" name="chk" id="chk_<?php echo $j; ?>"  style="width:2%;"></td>
    <td class="tabledata"><select name="item[]" id="item" style="width:100%" >
	<option value="0">---Select----</option>
     <?php 
	 $prod=DB_query("select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($prod1=DB_fetch_array($prod))
	 {
	 $t='';
	 if($row3['item']==$prod1['id'])
	 $t='selected';
	 ?>
	 <option value="<?php echo $prod1['id']; ?>" <?php echo $t; ?>><?php echo $prod1['item_name']; ?></option>
	<?php } ?> 
   
   </select></td>
      <td class="tabledata"> <select name="process[]" id="process_<?php echo $j; ?>" style="width:100%" >
     <?php 
	 $prod=DB_query("select * from production_process_master where CompanyId='".$_SESSION['ACGCompanyId']."' 
	 and id='".$row3['process']."'",$db); 
	 while($prod1=DB_fetch_array($prod))
	 {
	 $l='';
	 if($row3['process']==$prod1['id'])
	 $l='Selected';
	 ?>
	 <option value="<?php echo $prod1['id']; ?>" <?php echo $l; ?> ><?php echo $prod1['manuf_process_name']; ?></option>
	<?php } ?>
	    </select></td>
    <td class="tabledata"><select name="machine[]" style="width:100%" id="machine_<?php echo $j; ?>">
	<option value="0">---Select----</option>
     <?php 
	 $mach=DB_query("select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($mach1=DB_fetch_array($mach))
	 {
	 $m='';
	 if($row3['machine']==$mach1['id'])
	 $m='selected';
	 ?>
	 <option value="<?php echo $mach1['id']; ?>" <?php echo $m; ?> ><?php echo $mach1['name']; ?></option>
	<?php } ?>
	    </select></td>
    <td class="tabledata"><select name="operator[]" id="operator_<?php echo $j; ?>" style="width:100%" >
	<option value="0">---Select----</option>
    <?php 
	 $oper=DB_query("select * from production_operator_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($oper1=DB_fetch_array($oper))
	 {
	 $n='';
	 if($row3['operator']==$oper1['id'])
	 $n='selected';
	 ?>
	 <option value="<?php echo $oper1['id']; ?>" <?php echo $n; ?>><?php echo $oper1['operator_name']; ?></option>
	<?php } ?>
	    </select></td>
    <td class="tabledata"><input type="text" name="exp_com_date[]" id="expcomdate_<?php echo $j; ?>"  style="width:100%;" 
	onClick="javascript:NewCal(this.id,'ddmmyyyy')"  value="<?php echo ConvertSQLDate($row3['exp_date']);  ?>" ></td>
     <td class="tabledata"><input type="hidden" name="status1[]" value="<?php echo $row3['status1']; ?>" /></td>
    <td class="tabledata"><select name="status[]" id="status" style="width:100%" >
	<option value='Y' <?php if($row3['current_status']=='Y') { ?> selected="selected" <?php } ?> >Yes</option>
     <option value="N" <?php if($row3['current_status']=='N') { ?> selected="selected" <?php } ?>  >No</option>
	 	 </select></td>
  </tr>
  <?php $j++; } ?>
  <input type="hidden" name="" value="<?php echo $j; ?>" id="edit_cnt1" />
  </tbody>
	</table>
	<input type="hidden" name="hiditemcount" id="hiditemcount1" value="" />
	</fieldset>
	
	
	  <br />
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th><strong>Remarks </strong></th>
          <td colspan="5"><textarea name="remarks"  style=" width:100%" rows="2"><?php echo  $remarks; ?></textarea></th>
         
        </tr>
		
	</table>
	  

	  <p align="center"><input type="submit" name="Save" value="Save"  class="search" onclick="return validatedata();"/></p>
</form>
</div></div>
<script>
function addRow1(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	r = rowCount+1;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	 
		var newcell = row.insertCell(i);
		newcell.className='tabledata';
		newcell.innerHTML = table.rows[0].cells[i].innerHTML;
		switch(newcell.childNodes[0].type) 
		{
			case "text":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "hidden":
			newcell.childNodes[0].value = "";
			var nod_id_hidden = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id =nod_id_hidden[0]+'_'+r;
			break;

			case "button":
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "checkbox":
			newcell.childNodes[0].checked = false;
			var nod_id_chk = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id_chk[0]+'_'+r;
			break;

			case "select-one":
			newcell.childNodes[0].selectedIndex = 0;
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;	
			
			case "textarea":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;
		}
	}
}
	
function deleteRowOrder1(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length - 1;
		if(rowCount==0){
			alert("You Not delete First row.");
		}else{
			table.deleteRow(rowCount);
		}

	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}
	
function showsitename158(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("workod").innerHTML=data[1];
	
    }
  }
  xmlhttp.open("GET","GoDownIssueSlip7.php?site="+str,true);
	xmlhttp.send();


	
}

function Get_oderdata1(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("oderitem").innerHTML=data[0];
	document.getElementById("orderdate").innerHTML=data[1];
	document.getElementById("cliendata").innerHTML=data[2];
    }
  }
  
xmlhttp.open("GET","get_orderdata1.php?salid="+str,true);
xmlhttp.send();	
	
}

function opendata(str,id)
{
 
 if (str.length == 0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	
	
	

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)
    {
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  

  xmlhttp.open("GET","showpopup5.php?site="+str+"&data="+id,true);
	xmlhttp.send();


	
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}


function getItemsList1(id,code,shade,netrate,ctr)
{ 
    var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	if(ctr1[1]==undefined)
	{
	//if(document.getElementById('itemdataid').value=='')
	//{
	
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	
	//}
	}
	else
	{
	//if(document.getElementById('itemdataid_'+i).value=='')
	//{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	
	//}	
	}	
	document.getElementById("lightbox").style.display='none';
	var data= addRow('dataTable')
	
}


function addRow(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	r = rowCount+1;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	 
		var newcell = row.insertCell(i);
		newcell.className='tabledata';
		newcell.innerHTML = table.rows[0].cells[i].innerHTML;
		switch(newcell.childNodes[0].type) 
		{
			case "text":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "hidden":
			newcell.childNodes[0].value = "";
			var nod_id_hidden = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id =nod_id_hidden[0]+'_'+r;
			break;

			case "button":
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "checkbox":
			newcell.childNodes[0].checked = false;
			var nod_id_chk = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id_chk[0]+'_'+r;
			break;

			case "select-one":
			newcell.childNodes[0].selectedIndex = 0;
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;	
			
			case "textarea":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;
		}
	}
}
	
function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length - 1;
		if(rowCount==0){
			alert("You Not delete First row.");
		}else{
			table.deleteRow(rowCount);
		}

	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}

</script>
      
      
