<!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" />

<script language="javascript" src="../jscript/chainedselects.js"></script>
<script language="javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<?php
include ("../navigation/header.php");
$page_name = "Packing-design-edit";
include ("../navigation/access.php");

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

$design_no = $_GET['design_no'];

$table_name = $_SESSION['db_prefix']."_packaging_design";
$packaging_query = "SELECT packaging_design, pack_qty, est_qty FROM $table_name WHERE design_no = '".$design_no."' ";
$packaging_result = $con->query($packaging_query);
while($row = $packaging_result->fetch_assoc()) {
$packaging_design = $row["packaging_design"];
$pack_qty = $row["pack_qty"];
$est_qty = $row["est_qty"];

}


$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
$packaging_line_query = "SELECT * FROM $table_name WHERE design_no = '".$design_no."' ";
$packaging_line_result = $con->query($packaging_line_query);
$packaging_line_num = mysqli_num_rows($packaging_line_result);


$table_name = $_SESSION['db_prefix']."_store_items";
$store_item_query = "SELECT store_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Packaging'  ORDER BY item_name ASC";
	$store_item_result = $con->query($store_item_query);
	
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while($row = $store_item_result->fetch_assoc()) {
		$arrId2[$w] = $row["store_item_id"];
		$arrName2[$w] = $row["item_name"].'   ('.$row["unit"].')';
		$w++;
	}	

?>


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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 



<script type="text/javascript">
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>

<body >
<form name="form1" id="form1" action="packaging_design_edit_save.php" method="get">
<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="493"><label class="label_page_head">
              Edit packaging design
              <?php echo $packaging_design ?></label>
              </td>
              <td width="197"><label style="font-size:18px; "></label><br /><label style="font-size:18px; "></label></td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
<br />
<br />

      <div class="page_middle_frame">
     
      
        <div class="button_inside_frame"><br />

<?php

?>
              <table width="622" id="table_display" >
                <tr>
                  <td width="229" height="26" align="left" valign="top">Item</td>
                  <td width="200" align="left" valign="top">Group</td>
                  <td width="108" align="left" valign="top">&nbsp;</td>
                  <td width="65" align="left" valign="top">quantity</td>
                </tr>
                <?php
				$i=0;
				
				while($row = $packaging_line_result->fetch_assoc()) {
				$a0 = $row["design_no"];
				$a1 = $row["store_item_id"];
				$a2 = $row["quantity"];
				$a3 = $row["used_for"];
				
					 
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = $con->query($item_query);
						$row = mysqli_fetch_assoc($item_result);
						$a1a = $row['item_name'];
						$a3a = $row['unit'];
						$a4a = $row['subCategory'];
 
				 ?>
                <tr>
                  <td colspan="2" valign="middle">
                    <div id="store_item_divA<?php echo $i ?>"><img src="../images/line_edit.png" alt="" width="16" height="12" id="add_icon<?php echo $i ?>" title="Click to edit line" 
              onclick="
              document.getElementById('store_item_divA<?php echo $i ?>').hidden=true; 
              document.getElementById('store_item_divB<?php echo $i ?>').hidden=false; 
              document.getElementById('price_text<?php echo $i ?>').value='';
              document.getElementById('quantity_text<?php echo $i ?>').value=''; 
              document.getElementById('store_item_text<?php echo $i ?>').value =''; 
              " />
                      <input name="store_item_text<?php echo $i ?>" id="store_item_text<?php echo $i ?>" type="text" class="text300" value="<?php echo $a1a ?>" readonly="readonly" style="border:hidden; background-color:inherit" />
                      <input name="store_item_id<?php echo $i ?>" id="store_item_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>" />
                    </div>
                    <div id="store_item_divB<?php echo $i ?>" hidden="hidden">
                      <select name="category<?php echo $i ?>" id="category<?php echo $i ?>" class="select160"  onchange="document.getElementById('store_item_divA<?php echo $i ?>').hidden=true; document.getElementById('store_item_divB<?php echo $i ?>').hidden=false; document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex=-1; document.getElementById('index<?php echo $i ?>').value = document.getElementById('category<?php echo $i ?>').selectedIndex; ">
                      </select>
                      <input type="hidden" name="index<?php echo $i ?>" id="index<?php echo $i ?>" />
                      <select name="store_item_id_select<?php echo $i ?>" id="store_item_id_select<?php echo $i ?>" class="select230" onchange="
                      document.getElementById('store_item_id<?php echo $i ?>').value = document.getElementById('store_item_id_select<?php echo $i ?>').value;
                      
                    unit = document.getElementById('store_item_id_select<?php echo $i ?>').options[document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex].text;               		unit2 = unit.split('#'); 
              		unit3 = unit2[1];
                    document.getElementById('price_text<?php echo $i ?>').value = unit3;
                    
                    document.getElementById('amount_text<?php echo $i ?>').value = (document.getElementById('quantity_text<?php echo $i ?>').value * unit3).toFixed(2);
                    
                    "
              >
                      </select>
                      <input type="hidden" name="line_num" id="line_num" value="<?php echo $packaging_line_num?>" />
                                   
                  </div></td>
                  <td valign="middle">
                  <label> <input type="radio" name="used_for_group<?php echo $i ?>" value="block" id="used_for_group_0<?php echo $i ?>" <?php if ($a3=='block') { ?> checked="checked" <?php } ?> />block</label>
                  <br />
                  <label> <input type="radio" name="used_for_group<?php echo $i ?>" value="pallet" id="used_for_group_1<?php echo $i ?>" <?php if ($a3=='pallet') { ?> checked="checked" <?php } ?> />pallet</label>
                  </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, 4, '.', '') ?>" class="text50" width="50px"  onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\.....).*/, '$1')" onfocus = "this.select();" autocomplete="off" style="text-align:right" onchange="document.getElementById('edit_monitor').value='yes'; "/></td>
                </tr>
                <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
                <tr>
                  <td colspan="3" align="left" valign="top"><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/packaging_design_add_line.php?design_no=<?php echo $design_no ?>&packaging_design=<?php echo $packaging_design ?>', 'Select product', 'width=450px,height=75px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false;
	}
	else {
		alertMessage(1, 'packaging_design_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>&nbsp;
                 
                  <input type="hidden" name="edit_monitor" id="edit_monitor" value="no" />
                  <div align="right"><font color='#0047D4'>To delete a line, set qty to zero</font></div></td>
                  <td align="left" valign="middle">&nbsp;</td>
                </tr>
              </table><br />
<br />

              <table width="650" id="table_display2" >
                <tr>
                  <td><span class="wizard_frame">Units to be packed with this packing design:&nbsp;</span></td>
                  <td><select name="pack_qty_select" id="pack_qty_select">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="<?php echo $pack_qty ?>" selected="selected"><?php echo $pack_qty ?></option>
                  </select></td>
                </tr>
                <tr>
                  <td width="448">Estimated number of products to bepacked with this packing design:</td>
                  <td width="190"><input type="text" name="est_qty_text" id="est_qty_text" class="text60" onfocus = "this.select();"  value="<?php echo $est_qty ?>"/></td>
                </tr>
              </table>
              <br />
<br />
              
              <br />     
<br />
           
        </div>
        
        <div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="design_no_text" id="design_no_text" value="<?php echo $design_no ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../production/production_main.php?date=&branch=');" 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>
</div>
  </div>
  
  
</div>
</form>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "production/production_main.php?date=&branch=";	
include ("../navigation/production_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>