<head>

<?php 
$cat_group =$_GET['cat_group'];

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

if ($cat_group=='Production') {
$table_name = $_SESSION['db_prefix']."_stockloss";
$check_query = "SELECT stockId FROM $table_name WHERE category = 'Production' AND date = '".$today."'  ";
$check_result = $con->query($check_query);
$check_num = mysqli_num_rows($check_result);

$table_name = $_SESSION['db_prefix']."_store_items";
$item_query = "SELECT store_item_id, item_name, category, subCategory, unit, minimumStock FROM $table_name WHERE category = 'Production' ORDER BY item_name ";
$item_result = $con->query($item_query);
$item_num = mysqli_num_rows($item_result);
}

if ($cat_group=='Products') {
$table_name = $_SESSION['db_prefix']."_stockloss";
$check_query = "SELECT stockId FROM $table_name WHERE category = 'Products' AND date = '".$today."'  ";
$check_result = $con->query($check_query);
$check_num = mysqli_num_rows($check_result);

$table_name = $_SESSION['db_prefix']."_product_store";
$item_query = "SELECT product_item_id, item_name, category, subCategory, unit, minimumStock FROM $table_name WHERE category = 'Product' ORDER BY item_name ";
$item_result = $con->query($item_query);
$item_num = mysqli_num_rows($item_result);
}



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

<!--jscript-->
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></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>

</head>
<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide'); " onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">

<?php 
if ($check_num!=0) { ?>
<div class="page_middle_frame">
<div style="float:left;">
<img src="../images/exclamation_mark_blue.png" width="64" height="64">
</div>
<div >
<br>
Stock count for production materials has already been recorded for <?php echo date("d-m-Y", strtotime($today)) ?>.<br><br>

A stock count for production materials can only be recorded once a day. You can edit the count records in "Edit stock count".<br><br>
<br>
<br>
</div>
</div>
<?php }
else {
?>
<div class="page_middle_frame">
<form name="form1" id="form1" action="stockCountWiz4_save.php" method="get">
<div style="float:left;">
<img src="../images/exclamation_mark_blue.png" width="48" height="48">
</div>
<div >
<label style="font-size:18px;">Important:</label><br>
Stock count should be done at day end.<br>
Stock count values to be entered AFTER all day entries for production and stores are entered.
<br>
<br>
</div>
<table width="525" id="dataTable">
  <thead>
  <tr>
    <td width="330">Item</td>
    <td width="79" align="center">Unit</td>
    <td width="100">Counted qty</td>
  </tr>
  </thead>
  <?php
  $i=0;
  while($row = $item_result->fetch_assoc()) {

		$store_item_id = $row["store_item_id"];
	  	$item = $row["item_name"];
	  	$category = $row["category"];
	  	$subCategory = $row["subCategory"];	  
	  	$unit = $row["unit"];
	?>
  <tr>
    <td><?php echo $item ?>
        <input name="item_name_text<?php echo $i ?>" id="item_name_text<?php echo $i ?>" type="hidden" value="<?php echo $item ?>">
        <input name="store_item_id_text<?php echo $i ?>" type="hidden" value="<?php echo $store_item_id ?>">
        <input name="category_text<?php echo $i ?>" type="hidden" value="<?php echo $category ?>">
        <input name="subCategory_text<?php echo $i ?>" type="hidden" value="<?php echo $subCategory ?>">
    </td>
    <td align="center"><?php echo $unit ?></td>
    <td align="center"><input type="text" name="counted_qty_text<?php echo $i ?>" id="counted_qty_text<?php echo $i ?>" class="text60"   onkeypress="return numbersonly(this, event)" style="text-align:right" autocomplete="off"></td>
    
  </tr>
  <?php
  $i++;
  }
  ?>
</table>
<br>
<br>

 <div class="page_inside_frame">
      <table width="645" border="0">
        <tr>
          <td width="405"><div align="left"> <img src="../images/info_blue.png" width="16" height="16">
            <label class="label_info">Quantity for all items need to be entered before saving.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Only one stock count per day can be done.</label>
          </div></td>
          <td width="230" align="right">
            <input name="line_num" id="line_num" type="hidden" value="<?php echo $item_num ?>">
            <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../store/store_main.php');" value="Close"/>
            <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; " /></td>
        </tr>
      </table>
    </div> 
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 150; i++) {
	frmvalidator.addValidation("counted_qty_text"+i,"req","- qty for "+document.getElementById('item_name_text'+i).value+".");
  }
  </script>   
</div>
<?php } ?>

</body>