<?php 
if(isset($_POST['Save']))
{
     
	if($_REQUEST['SID']!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['itemid']);$cnt++)
	{
	if($_REQUEST['itemid'][$cnt]!=''){
	  $data['status']=$_REQUEST['status'][$cnt];
	  $data['remarks']=$_REQUEST['remarks1'][$cnt];
	 $condition="id='".$_REQUEST['itemid'][$cnt]."'"; 
	 $s->RecordEdit('daily_jobwork_process', $data, $condition);				
	}	
	}
	
		
	
	}
	
   $s->pageLocation("index.php?route=Production/JobrouteCard/daily_job_cardlist".$rurl);



     }

$sql1=DB_query("select * from daily_jobwork 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>DAILY JOB CARD CREATION</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)">
					
	        		<?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 
			  $s->getField('job_card','id',$jobcardid,'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( $s->getField('job_card','id',$jobcardid,'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 salesorder where id='".$wo_no."'  order by orderNo 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['orderNo'] ; ?></option>
					<?php } ?>
									   
					   </select></div></td>
                    <th class="tabledata1">W/O Item </th>
                     <td><div id="oderitem">
					<?php					
	         $item=$s->getField('job_card','id',$jobcardid,'work_itemid');
					echo $s->getField('item_master','id',$item,'item_name'); ?>		     
	   
					
			        	 </select></div></td>
                     <th>W/O Date</th>
                     <td><div id="orderdate">
					<?php $ordate=$s->getField('salesorder','id',$wo_no,'orderDate'); ?>
					 <input type="text" name="orderdate" id="orderdate"  style="width:100%;"
					 value="<?php echo ConvertSQLDate($ordate); ?>" class="datepicker"></div></td>
                  </tr>
                  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Customer Name</th>
                       <td><div id="cliendata">
					   <?php  
					    $ven=$s->getField('salesorder','id ',$wo_no,'client');
					    $venname=$s->getField('clientmaster','id ',$ven,'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 Delivery Date</th>
                  <td> <input type="text" name="deliverydate" id="deliverydate"  style="width:100%;" 
				   value="<?php echo ConvertSQLDate($delivery_date); ?>" readonly="readonly"> </td>
                  <th>Priority</th>
                  <td><select  style="width:100%;" name="priority" id="priority">
                     <option value="0">-Select-</option>
            		 <option value="Urgent" <?php if($priority=='Urgent') { ?> selected="selected" <?php } ?>>Urgent</option>
					 <option value="Normal" <?php if($priority=='Normal') { ?> selected="selected" <?php } ?>>Normal</option>
					 
					 </select></td>
                  </tr>
                  
                  </table>
</fieldset>
     

<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>
           <th><strong>EXPECTED COMPLETION  DATE</strong></th>
        </tr>
		 <tbody id="dataTable">
		<?php 
$i=1;
$sql2=DB_query("select * from job_card_item_details where jobid='".$jobcardid."'",$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"><?php echo $i; ?></td>
	  <td class="tabledata"><?php echo $row2['mst_itemid'];?></td>
<td class="tabledata"><?php echo $itemcode;?>          </td>
      <td class="tabledata"><?php echo $itemname;?></td>
      <td class="tabledata"><?php echo $unitname; ?> </td>
      <td class="tabledata"><?php echo $row2['item_qty']; ?></td>
      <td class="tabledata"><?php echo ConvertSQLDate($row2['expected_date']); ?></td>
  </tr>
  <?php 
 $i++; }
 
 ?>
  </tbody>
	</table>
  
	</fieldset>
<br />
<fieldset><legend style="font-size:12px;"><strong>Process Detail</strong></legend> 
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th width="5%"><strong>S.No. </strong></th>
		   <th width="10%"><strong>Item</strong></th>
          <th width="11%"><strong>PROCESS</strong></th>
          <th width="9%"><strong>MACHINE</strong></th>
          <th width="10%"><strong>OPERATOR</strong></th>
          <th width="17%"><strong>EXP COM DATE</strong></th>
		  <th width="18%"><strong>CURRENT STATUS</strong></th>
		   <th width="20%"><strong>Remarks</strong></th>
        </tr>
		<tbody id="dataTable1">
<?php 
$j=1;
$sql3=DB_query("select * from daily_jobwork_process where dailyid='".$_REQUEST['SID']."'",$db);
while($row3=DB_fetch_array($sql3))
{

?>	
     <tr>
    <td class="tabledata"><?php echo $j; ?><input type="hidden" name="itemid[]"  value="<?php  echo $row3['id'];  ?>"/></td>
    <td class="tabledata"><?php echo $s->getField('item_master','id',$row3['item'],'item_name'); ?>
		</td>
      <td class="tabledata"><?php echo $s->getField('production_process_master','id',$row3['process'],'manuf_process_name'); ?> 
	  
	  </td>
    <td class="tabledata">
	<?php echo $s->getField('machine_center','id',$row3['machine'],'name'); ?> 
	  
	
	</td>
    <td class="tabledata">
	<?php echo $s->getField('production_operator_master','id',$row3['operator'],'operator_name'); ?> 
	
	</td>
    <td class="tabledata"><input type="text" name="exp_com_date[]" id="expcomdate_<?php echo $j; ?>"  style="width:100%;" 
	  value="<?php echo ConvertSQLDate($row3['exp_date']);  ?>"  readonly="readonly"></td>
    <td class="tabledata"><select name="status[]" id="status" style="width:100%" >
	
     <option value="Pending" <?php if($row3['status']=='Pending') { ?> selected="selected" <?php } ?>  >Pending</option>
	  <option value="In Process" <?php if($row3['status']=='In Process') { ?> selected="selected" <?php } ?>  >In Process</option>
	 <option value="Complete" <?php if($row3['status']=='Complete') { ?> selected="selected" <?php } ?>>Complete</option>	
		 </select></td>
	<td><textarea  name="remarks1[]" ><?php echo $row3['remarks']; ?></textarea></td>	 
  </tr>
  <?php $j++; } ?>
  </tbody>
	</table>
	</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"  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>
      
      
