<?php
$today = date("Y-m-d");


if ($_SESSION['stores_group']=='Aggregates') {
$table_name = $_SESSION['db_prefix']."_store_items";
$store_itemQuery = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE subCategory ='Aggregates'  ORDER BY item_name ASC";
	$store_itemResult = execsql($store_itemQuery);
	$store_itemNum = mysql_num_rows($store_itemResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_itemNum) {
		$arrId1[$w] = mysql_result($store_itemResult, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_itemResult, $w, "item_name");
		$arrAvailable[$w] = mysql_result($store_itemResult, $w, "quantity");
		$w++;
	}
}

if ($_SESSION['stores_group']=='Cleaning materials') {
$table_name = $_SESSION['db_prefix']."_store_items";
$store_itemQuery = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE subCategory ='Cleaning materials'  ORDER BY item_name ASC";
	$store_itemResult = execsql($store_itemQuery);
	$store_itemNum = mysql_num_rows($store_itemResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_itemNum) {
		$arrId1[$w] = mysql_result($store_itemResult, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_itemResult, $w, "item_name");
		$arrAvailable[$w] = mysql_result($store_itemResult, $w, "quantity");
		$w++;
	}
}

if ($_SESSION['stores_group']=='Consumables') {
$table_name = $_SESSION['db_prefix']."_store_items";
$store_itemQuery = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE subCategory ='Consumables'  ORDER BY item_name ASC";
	$store_itemResult = execsql($store_itemQuery);
	$store_itemNum = mysql_num_rows($store_itemResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_itemNum) {
		$arrId1[$w] = mysql_result($store_itemResult, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_itemResult, $w, "item_name");
		$arrAvailable[$w] = mysql_result($store_itemResult, $w, "quantity");
		$w++;
	}
}


if ($_SESSION['stores_group']=='PPE') {
$table_name = $_SESSION['db_prefix']."_store_items";
$store_itemQuery = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE subCategory ='PPE'  ORDER BY item_name ASC";
	$store_itemResult = execsql($store_itemQuery);
	$store_itemNum = mysql_num_rows($store_itemResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_itemNum) {
		$arrId1[$w] = mysql_result($store_itemResult, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_itemResult, $w, "item_name");
		$arrAvailable[$w] = mysql_result($store_itemResult, $w, "quantity");
		$w++;
	}
}

if ($_SESSION['stores_group']=='Tools') {
$table_name = $_SESSION['db_prefix']."_store_items";
$store_itemQuery = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE subCategory ='Tools'  ORDER BY item_name ASC";
	$store_itemResult = execsql($store_itemQuery);
	$store_itemNum = mysql_num_rows($store_itemResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_itemNum) {
		$arrId1[$w] = mysql_result($store_itemResult, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_itemResult, $w, "item_name");
		$arrAvailable[$w] = mysql_result($store_itemResult, $w, "quantity");
		$w++;
	}
}

if ($_SESSION['stores_group']=='Welding and Engineering') {
$table_name = $_SESSION['db_prefix']."_store_items";
$store_itemQuery = "SELECT store_item_id, item_name, quantity FROM $table_name WHERE subCategory ='Welding and Engineering'  ORDER BY item_name ASC";
	$store_itemResult = execsql($store_itemQuery);
	$store_itemNum = mysql_num_rows($store_itemResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $store_itemNum) {
		$arrId1[$w] = mysql_result($store_itemResult, $w, "store_item_id");
		$arrName1[$w] = mysql_result($store_itemResult, $w, "item_name");
		$arrAvailable[$w] = mysql_result($store_itemResult, $w, "quantity");
		$w++;
	}
}
	
$table_name = $_SESSION['db_prefix']."_list_department";
$departmentQuery = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$departmentResult = execsql($departmentQuery);
	$departmentNum = mysql_num_rows($departmentResult);
	$w = 0;
	$arrId3 = array ();
	$arrName3 = array ();
	while ($w < $departmentNum) {
		$arrId3[$w] = mysql_result($departmentResult, $w, "item_name");
		$arrName3[$w] = mysql_result($departmentResult, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_list_company";
$companyQuery = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$companyResult = execsql($companyQuery);
	$companyNum = mysql_num_rows($companyResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $companyNum) {
		$arrId4[$w] = mysql_result($companyResult, $w, "item_name");
		$arrName4[$w] = mysql_result($companyResult, $w, "item_name");
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_store_items";
$available_query = "SELECT quantity FROM $table_name WHERE subCategory ='".$_SESSION['stores_group']."'  ORDER BY item_name ASC";
$available_result = mySQL_query($available_query);
$available_num = mysql_num_rows($available_result);
$i=0;
while ($i<$available_num) {
${'available'.$i} = mysql_result($available_result, $i, "quantity");
?>
<script>
available<?php echo $i ?> = <?php echo ${'available'.$i} ?> ;
</script> 



<script language="JavaScript" src="../jscript/capitalize_textbox.js"  type="text/javascript"></script>  

<?php	
$i++;
}

$table_name = $_SESSION['db_prefix']."_employee";
$employeeQuery = "SELECT emp_id, emp_first_name, emp_last_name FROM $table_name WHERE end_employ_date > '".$today."' ORDER BY emp_first_name ASC";
	$employeeResult = execsql($employeeQuery);
	$employeeNum = mysql_num_rows($employeeResult);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $employeeNum) {
		$arrId2[$w] = mysql_result($employeeResult, $w, "emp_id");
		$arrName2[$w] = mysql_result($employeeResult, $w, "emp_first_name").' '.mysql_result($employeeResult, $w, "emp_last_name");
		$w++;
	}

?>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>  

<script>
function stock_available() {
	var t = document.getElementById('store_item_select').selectedIndex-1;
	document.getElementById('available_text').value = window['available'+t] ;
	document.getElementById('qty_select').value = '';
}
</script>

<script>
function check_stock() {
	var qty = Number(document.getElementById('qty_select').value);
	var available = Number(document.getElementById('available_text').value);
	
	if (qty>available) {
	     alertMessage(1, '', 'There is not enough stock, enter a lower quantity');
		 document.getElementById('qty_select').value='';;
	}
}
</script>

</head>

<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide');" onFocus="MM_showHideLayers('wait','','hide');" >

<form id="form1" name="form1" method="get" action="supply_internalWizbase.php">
<div class="wizard_page_middle_frame">
<div class="wizard_frame" style="height:auto; min-height:200px;">

  Store item to supply:&nbsp;
  <label class="star">*</label>
&nbsp;&nbsp;   
    <select name="store_item_select" id="store_item_select" class="select300" onChange="stock_available()">
      <option value="<?php echo $_SESSION['store_item_id'] ?>" selected="selected"><?php echo $_SESSION['store_item_name'] ?></option>
      <?php 
    	for ($w = 0; $w < count($arrId1); $w++) {
		echo "<option value=\"".$arrId1[$w] . "\"" . ">" . $arrName1[$w] . "</option>";	
	    }
     ?>
    </select>
    <br>
<br>
Qty to supply:&nbsp;&nbsp;&nbsp;
  <label class="star">*</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="qty_select" id="qty_select" class="text50" onKeyPress="return numbersonly(this, event)" value="<?php echo $_SESSION['supply_qty'] ?>" onChange="check_stock();" autocomplete="off">
&nbsp;&nbsp;&nbsp;available stock: <input name="available_text" id="available_text" type="text" style="border:hidden; background-color:transparent;" readonly value="<?php echo $_SESSION['available_stock']  ?>"> 
  <br>
  <br>
  <?php if ($_SESSION['supply_group']=='employee') { ?>
  <div>  Supply to:&nbsp;&nbsp;
    <label class="star">*</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="supply_to_select" id="supply_to_select" class="select160" onChange="document.getElementById('received_text').value=document.getElementById('supply_to_select').options[document.getElementById('supply_to_select').selectedIndex].text;">
      <option value="<?php echo $_SESSION['supply_to'] ?>" selected="selected"><?php echo $_SESSION['emp_name'] ?></option>
      <?php 
    	for ($w = 0; $w < count($arrId2); $w++) {
		echo "<option value=\"".$arrId2[$w] . "\"" . ">" . $arrName2[$w] . "</option>";	
	    }
     ?>
    </select>
     &nbsp;&nbsp;&nbsp;&nbsp; Received by:&nbsp;&nbsp;
     <input type="text" name="received_text" id="received_text" class="text200" onBlur="capitalize(this)" onfocus = "this.select();" value="<?php echo $_SESSION['received_by'] ?>" readonly>
  </div>
  <?php } ?>
  
  <?php if ($_SESSION['supply_group']=='department') { ?>
  <div>  Supply to:&nbsp;&nbsp;
    <label class="star">*</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="supply_to_select" id="supply_to_select" class="select160">
      <option value="<?php echo $_SESSION['supply_to'] ?>" selected="selected"><?php echo $_SESSION['supply_to'] ?></option>
      <?php 
    	for ($w = 0; $w < count($arrId3); $w++) {
		echo "<option value=\"".$arrId3[$w] . "\"" . ">" . $arrName3[$w] . "</option>";	
	    }
     ?>
    </select>
  &nbsp;&nbsp;&nbsp;&nbsp; Received by:&nbsp;&nbsp;
  <select name="received_select" id="received_select" class="select160">
    <option value="<?php echo $_SESSION['received_by'] ?>" selected="selected"><?php echo $_SESSION['received_by'] ?></option>
    <?php 
    	for ($w = 0; $w < count($arrId2); $w++) {
		echo "<option value=\"".$arrName2[$w] . "\"" . ">" . $arrName2[$w] . "</option>";	
	    }
     ?>
  </select>
  </div>
  <?php } ?>
  
  <?php if ($_SESSION['supply_group']=='company') { ?>
  <div>  Supply to:&nbsp;&nbsp;
    <label class="star">*</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="supply_to_select" id="supply_to_select" class="select160">
      <option value="<?php echo $_SESSION['supply_to'] ?>" selected="selected"><?php echo $_SESSION['supply_to'] ?></option>
      <?php 
    	for ($w = 0; $w < count($arrId4); $w++) {
		echo "<option value=\"".$arrId4[$w] . "\"" . ">" . $arrName4[$w] . "</option>";	
	    }
     ?>
    </select>
    &nbsp;&nbsp;&nbsp;&nbsp; Received by:&nbsp;&nbsp;
    <input type="text" name="received_text" id="received_text" class="text200" onBlur="capitalize(this)" onfocus = "this.select();" value="<?php echo $_SESSION['received_by'] ?>">
  </div>
  <?php } ?>
  <br>
<br>
  
  <br>
<br>
Reason for supply:&nbsp;&nbsp;&nbsp;
<label class="star">*</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="reason_text" id="reason_text" type="text" class="text300" value="<?php echo $_SESSION['supply_reason'] ?>"> 
</div>

 
  
<div class="wizard_frame">
  <table width="590" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','supply_internalWizbase.php?s=&amp;p=1&l=a'); return document.MM_returnValue; ;return document.MM_returnValue"/></td>
            <td width="115">&nbsp;</td>
            <td width="99"><span class="wizard">
              <input name="error" type="hidden" id="error" value="0" />
              <input name="p" type="hidden" id="p" value="2" />
              <input name="s" type="hidden" id="s" value="2" />
              <input name="l" type="hidden" id="l" value="a" />
            </span></td>
            <td width="125" align="left"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false;  cancel_confirmation(1, '../store/store_main.php');;" value="Cancel" /></td>
            <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" /></td>
          </tr>
      </table>
    </div>
  </div>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("store_item_select","req","- store item.");
  frmvalidator.addValidation("supply_to_select","req","- employee.");
  frmvalidator.addValidation("qty_select","req","- quantity.");
  frmvalidator.addValidation("reason_text","req","- reason.");
  
</script>
</div>


</body>

