<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Production-edit";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");

require_once ('../include/tc_calendar.php');
	

$production_date = $_GET['production_date'];
$error = $_GET['e'];
	
$table_name2 = $_SESSION['db_prefix']."_production_plan";
$plan_query = "SELECT * FROM $table_name2 WHERE production_date ='".$production_date."' ";
$plan_result = mySQL_query($plan_query);
$plan_num = mysql_num_rows($plan_result);


$table_name = $_SESSION['db_prefix']."_permissions";
$permission_query = "SELECT access_id  FROM  $table_name  WHERE access_id ='". $_SESSION['access_id']."' AND page_name = 'Orders-order cancel' ";
$permission_result = mySQL_query($permission_query);
$permission_num = mysql_num_rows($permission_result);
if ($permission_num>0) { 
		$cancel = 'yes'; 
}
else {
	$cancel = 'no'; 
}
?>

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="javascript" src="../jscript/chainedselects.js"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/capitalize_textbox.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  

<script type="text/javascript">
function validate_required(input,alerttxt,maxvalue,orvalue)
{
with (input)
  {
  if (value<maxvalue)
    {
    alertMessage(1, '', 'The entered quantity is less than already delivered.<br>The entry is reversed to the original.<br><br>Please enter a valid quantity.');
	input.value = orvalue;
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script> 

<script type="text/javascript">
function validate_pallets(input,alerttxt,maxvalue,orvalue)
{
with (input)
  {
  if (value<maxvalue)
    {
    alertMessage(1, '', 'The entered quantity is less than already delivered.<br>The entry is reversed to the original.<br><br>Please enter a valid quantity.');
	input.value = orvalue;
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>

</head>

<body onload="<?php if ($error==1) { ?> alertMessage(1, '', 'Production of this product is already in the list. Edit the skip/batch quantity.'); <?php } ?>" >
<div class="main_frame" style="height:auto; min-height:555px;">
<div class="page_head_frame">
          <table width="690" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="293"><label class="label_page_head">
              Edit production plan</label>
              </td>
              <td width="397"><label style="font-size:18px; "><?php echo date("l, d-m-Y", strtotime($production_date)) ?></label></td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
<br />
<br />
<form action="edit_production_plan_save.php" method="get" name="form1" id="form1">
      <div class="page_middle_frame">
      <div class="page_inside_frame">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Production date:&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($production_date)) ?><br />
          Production plan details:<br />
            
            <?php

$table_name = $_SESSION['db_prefix']."_production_plan";
$line_query = "SELECT *  FROM $table_name WHERE  production_date =  '".$production_date."' ";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);
		  ?>
          </p>
          <table width="642" id="table_display" >
            <tr>
                  <td width="227" height="26" align="left" valign="top">Production</td>
                  <td width="117" align="left" valign="top">&nbsp;</td>
                  <td width="136" align="left" valign="top">Planned skips/batch</td>
                  <td width="96" align="left" valign="top">Produced<br />
                  skips/batch</td>
                  <td width="42" align="left" valign="top">&nbsp;</td>
                </tr>
                <?php
				$i=0;
				while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "plan_id");
					 $a1 = mysql_result($line_result, $i, "production_no");
					 $a1a = mysql_result($line_result, $i, "mix_design_name");
					 
					 
					 
					 	$table_name = $_SESSION['db_prefix']."_production_plan_lines";
						$qty_query = "SELECT quantity FROM $table_name WHERE production_no = '".$a1."' AND action = 'skip' ";
						$qty_result = mySQL_query($qty_query);
						$qty_num = mysql_num_rows($qty_result);
						if ($qty_num>0) {
								$a2 = mysql_result($qty_result, 0, "quantity");
						}
						else {
							$a2=0;
						}
						
						$table_name = $_SESSION['db_prefix']."_production_plan_lines";
						$produced_query = "SELECT quantity FROM $table_name WHERE production_no = '".$a1."' AND action = 'skip_count' ";
						$produced_result = mySQL_query($produced_query);
						$produced_num = mysql_num_rows($produced_result);
						if ($produced_num>0) {
								$a3 = mysql_result($produced_result, 0, "quantity");
						}
						else {
							$a3=0;
						}
					
					$a4 = mysql_result($line_result, $i, "cancelled");					 
					 
								 
				 ?>
                <tr>
                  <td colspan="2" valign="middle">
                    <?php echo $a1.' - '.$a1a ?>
                    <input type="hidden" name="line_num" id="line_num" value="<?php echo $line_num?>" />
                    <input type="hidden" name="production_no<?php echo $i ?>" id="production_no<?php echo $i ?>" value="<?php echo $a1?>" />
                    <input type="hidden" name="mix_design_name<?php echo $i ?>" id="mix_design_name<?php echo $i ?>" value="<?php echo $a1a?>" />
                    </td>
                  <td valign="middle"><input name="quantity_text<?php echo $i ?>" id="quantity_text<?php echo $i ?>" type="text" value="<?php echo number_format($a2, 1, '.', ',') ?>" class="text50" width="50px" onKeyUp="this.value = this.value.replace (/(\..).*/, '$1'); document.getElementById('amount_text<?php echo $i ?>').value = parseFloat(document.getElementById('quantity_text<?php echo $i ?>').value * document.getElementById('price_text<?php echo $i ?>').value).toFixed(2); calc_M(<?php echo $line_num?>);" onKeyPress="return isNumberKey(event)" onfocus = "this.select();" autocomplete="off"  onchange="document.getElementById('edit_monitor').value='yes'; " onblur="validate_required(quantity_text<?php echo $i?>, 'The delivery amount exceeds the balance, the entry will be cleared. ' +'\n'+ 'Please enter a valid amount.', <?php echo $a3 ?>, <?php echo $a2 ?>); " style="text-align:right" <?php if ($a4=='yes') { ?> hidden="hidden" <?php } ?>/>
                  </td>
                  <td valign="middle">
                  <input type="text" name="delivered_text" id="delivered_text" class="text50" width="50px" style="border:hidden;" disabled="disabled" value="<?php echo number_format($a3, 1, '.', ','); ?>" <?php if ($a4=='yes') { ?> hidden="hidden" <?php } ?>/></td>
                  <td valign="middle"><?php if ($a4=='yes') { ?> 
                  <a href="edit_production_reverse.php?production_date=<?php echo $production_date ?>&production_no=<?php echo $a1 ?>" onMouseover="ddrivetip('Click to cancel this production for today.', 150)"; onMouseout="hideddrivetip()"><img src="../images/undo.png" width="16" height="16" /></a> <?php } else { if ($a3==0) { ?><a href="edit_production_cancel.php?production_date=<?php echo $production_date ?>&production_no=<?php echo $a1 ?>" onMouseover="ddrivetip('Click to cancel this production for today.', 150)"; onMouseout="hideddrivetip()"><img src="../images/error.png" width="12" height="15" /></a><?php } } ?>
                
                  </td>
            </tr>
                <?php 
			   
				$i++;
				 }
				 ?>
                <tr>
                  <td colspan="2">
                    <a href="" onmouseover="ddrivetip('Click to add a new line.', 150)"; onmouseout="hideddrivetip()" onclick= " 
                  
	if (document.getElementById('edit_monitor').value=='no') {
		  editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/production_edit_add_line.php?production_date=<?php echo $production_date ?>', 'Add a production', 'width=450px,height=75px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false;
	}
	else {
		alertMessage(1, 'quotation_edit.php', 'Before adding a line, you need to save the changes you made. Click the Save button and try again.'); return false;
	}

                  ">
                    
                    <img src="../images//line_edit.png" width="16" height="12" /><font color='#0047D4'> New line</font></a>
                  <input type="hidden" name="edit_monitor" id="edit_monitor" value="no" /></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
              </table>
              </div>
              <br />
              <div class="page_inside_frame">
      <table width="600" border="0">
    <tr>
      <td width="189">
      </td>
      <td width="401" align="right"><input type="hidden" name="production_date" id="production_date" value="<?php echo $production_date ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../production/production_main.php?date=0');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onClick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; confirmRefresh();"  />
		
        </td>
    </tr>
  </table>
</div>
  
 <br />
  </div>
  </form>
  <!--end of tableMain--> 
  
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "production/production_main.php?date=";	
include ("../navigation/production_sidebar.php");?>
<body onload="accessdenied(); return false">
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php }
?>
</html>