<?php 
if(isset($_POST['Save']))
{

   $sql=DB_query("select * from daily_jobwork where jobcardid='".$_REQUEST['jobcardno']."'",$db);
   $numrow=DB_num_rows($sql);
   if($numrow>0) 
   {
   $del=DB_query("delete from daily_jobwork_process where dailyid='".$_REQUEST['jobcardno']."'",$db);
   $myrow1=DB_fetch_array($sql);
   $masterId=$myrow1['id'];
   	if($masterId!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['process']);$cnt++)
	{
	if($_REQUEST['remarks1'][$cnt]!=''){
	    $insert2="Insert into daily_jobwork_process set
	      dailyid='".$masterId."',  
		  item='".$_REQUEST['itemid'][$cnt]."',  
	      process='".$_REQUEST['process'][$cnt]."',  
	      machine='".$_REQUEST['machine'][$cnt]."', 
		  operator='".$_REQUEST['operator'][$cnt]."', 
		  status='".$_REQUEST['status'][$cnt]."', 
		  exp_date='".FormatDateForSQL($_REQUEST['date'][$cnt])."',
	      remarks='".$_POST['remarks1'][$cnt]."'";
	     $result2=DB_query($insert2,$db);
		 if($_REQUEST['remarks1'][$cnt]!='')
		 {
		 $update=DB_query("update job_process_details set status1=1 where id='".$_REQUEST['jobprocessid'][$cnt]."'",$db);
		 
		 }  
		 }
		 }
		 }
   }
   else
   {
	$data['site']=$_REQUEST['mst_branchid'];
	$data['jobcardid']=$_REQUEST['jobcardno'];
	$data['date']=FormatDateForSQL($_REQUEST['date']);
	$data['wo_no']=$_REQUEST['work_order_no'];
	$data['delivery_date']=FormatDateForSQL($_REQUEST['deliverydate']);
	$data['remarks']=$_REQUEST['remarks'];
	$data['wo_date']=FormatDateForSQL($_REQUEST['orderdate']);
	$data['createdBy']=$_SESSION['UserID'];  
	$data['createdDate']=date('Y-m-d');
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
    $s->RecordInsert('daily_jobwork', $data);
    $masterId=DB_Last_Insert_ID($db,'daily_jobwork','id');
	if($masterId!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['process']);$cnt++)
	{
	if($_REQUEST['remarks1'][$cnt]!=''){
	    $insert2="Insert into daily_jobwork_process set
	      dailyid='".$masterId."',  
		  item='".$_REQUEST['itemid'][$cnt]."',  
	      process='".$_REQUEST['process'][$cnt]."',  
	      machine='".$_REQUEST['machine'][$cnt]."', 
		  operator='".$_REQUEST['operator'][$cnt]."', 
		  status='".$_REQUEST['status'][$cnt]."', 
		  exp_date='".FormatDateForSQL($_REQUEST['date'][$cnt])."',
	      remarks='".$_POST['remarks1'][$cnt]."'";
	     $result2=DB_query($insert2,$db);
		 if($_REQUEST['remarks1'][$cnt]!='')
		 {
		 $update=DB_query("update job_process_details set status1=1 where id='".$_REQUEST['jobprocessid'][$cnt]."'",$db);
		 
		 }
		 }
		 					
	}	
	}
	
	
	
	
	}
   $s->pageLocation("index.php?route=Production/JobrouteCard/daily_job_cardlist".$rurl);



     }


?>




<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>
<br />
<div class="body_contain">
<div class="tab_div">

<h1>Daily Job Card Progress Entry </h1>

<form action="" method="post">
<fieldset>
<legend style="font-size:12px;"><strong>Daily 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)">
					<option value="0">--Select--</option>
	        		<?php 			
		          $sql_state=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);	
			       while($SiteName=DB_fetch_array($sql_state)) 
				   {			
			        ?>
			<option value="<?php echo $SiteName['loccode']; ?>" ><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select></td>
               <th width="13%" class="tabledata1">Job Card No.  </th>
               <td width="20%"><div id="workod">&nbsp;</div></td>
              <th> Date</th>
               <td><input type="text" name="date" id="date"  style="width:100%;" class="datepicker"></td>
        </tr>
               
			   <tr>
				<th class="tabledata1">W/O No</th>
                    <td><div id="workod1">
					<select name="" id="" style="width:100%;">  
					   <option>-Select-</option>					   
				      </select></div></td>
                    <th class="tabledata1">W/O Item </th>
                     <td><div id="workitem"><select name="" id="" style="width:100%;">                    	
                     	<option value="">-Select-</option>	 
			        	 </select></div></td>
                     <th>W/O Date</th>
                     <td><div id="workdate"><input type="text" name="" id=""  style="width:100%;" class="datepicker"></div></td>
        </tr>
                  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Customer Name</th>
                       <td><div id="cliendata"></div>					   </td>
                  <th class="tabledata1"  nowrap="nowrap">Order Delivery Date</th>
                  <td><div id="delv"> <input type="text" name="deliverydate" id="deliverydate"  style="width:100%;"  readonly="readonly"> </div></td>
                  <td colspan="2"></td>
                  </tr>
      </table>
</fieldset>
     
    
	

<fieldset><legend style="font-size:12px;"><strong>Job Card Item Detail</strong></legend> 
<div id="itemdetails">
<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>
           <th><strong>EXPECTED COMPLETION  DATE</strong></th>
        </tr>
		 
     
 
	</table>
	</div>
  
	</fieldset>
<br />
<fieldset><legend style="font-size:12px;"><strong>Process Detail</strong></legend> 
	  <div id="processdetails">
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th width="6%"><strong>S.No. </strong></th>
          <th width="12%"><strong>PROCESS</strong></th>
          <th width="12%"><strong>MACHINE</strong></th>
          <th width="17%"><strong>OPERATOR</strong></th>
          <th width="16%"><strong>EXP COM DATE</strong></th>
          <th width="18%"><strong>CURRENT STATUS</strong></th>
          <th width="19%">Remarks</th>
        </tr>
		
	</table>
	</div>
	</fieldset>
	<fieldset><legend style="font-size:12px;"><strong>Completed Process Detail</strong></legend> 
	  <div id="processdetails1">
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th width="6%"><strong>S.No. </strong></th>
          <th width="12%"><strong>PROCESS</strong></th>
          <th width="12%"><strong>MACHINE</strong></th>
          <th width="17%"><strong>OPERATOR</strong></th>
          <th width="16%"><strong>EXP COM DATE</strong></th>
          <th width="18%"><strong>CURRENT STATUS</strong></th>
          <th width="19%">Remarks</th>
        </tr>
		
	</table>
	</div>
	</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="1"></textarea></th>
         
        </tr>
		
	</table>

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

	
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","GoDownIssueSlip8.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("workod1").innerHTML=data[4];
	document.getElementById("cliendata").innerHTML=data[2];
	document.getElementById("delv").innerHTML=data[3];
	document.getElementById("itemdetails").innerHTML=data[5];
	document.getElementById("workitem").innerHTML=data[0];
	document.getElementById("workdate").innerHTML=data[1];
	document.getElementById("processdetails").innerHTML=data[6];
	document.getElementById("processdetails1").innerHTML=data[7];
    }
  }
  
xmlhttp.open("GET","get_orderdata8.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;
		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.style.background='#e7e7e7';
			//  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;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
										
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}

function validatedata()
{
	if(document.getElementById("mst_branchid").value=='0')
	{
		alert("Please select The Branch First");
		document.getElementById("mst_branchid").focus();
		return false;
	}
	if(document.getElementById("jobcardno").value=='0')
	{
		alert("Please select The Job Card No First");
		document.getElementById("jobcardno").focus();
		return false;
	}
	if(document.getElementById("date").value=='')
	{
		alert("Please select The Date First");
		document.getElementById("date").focus();
		return false;
	}
}


</script>
      
      
