<p class="form-title">Registro de Nuevo Usuario</p>
<?php 
if (!Forms::checkPermission(FORM_USER_NEW)) {
    return;
}
require_once 'inc/class.store.php';
$stores = Store::getAllActive("name", "ASC");
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : "";
$lastname = isset($_POST['lastname']) ? $_POST['lastname'] : "";
$username = isset($_POST['username']) ? $_POST['username'] : "";
$passwd = isset($_POST['passwd']) ? $_POST['passwd'] : "";
$ci = isset($_POST['ci']) ? $_POST['ci'] : "";
$address = isset($_POST['address']) ? $_POST['address'] : "";
$phone = isset($_POST['phone']) ? $_POST['phone'] : "";
$role = isset($_POST['role']) ? $_POST['role'] : "";
$store = isset($_POST['store']) ? $_POST['store'] : "";
$email = isset($_POST['email']) ? $_POST['email'] : "";
$active = true;
if (isset($_POST['page'])) {
    $active = isset($_POST['active']);
}
include 'inc/widget/error.php';
?>
<form action="" method="POST" enctype="multipart/form-data">
	<table class="form">
	<tbody>
	<tr>
		<td class="label">Nombre:</td>
		<td><input name="firstname" type="text" value="<?php 
echo $firstname;
?>
	<tr>
		<td class="label">Stock:</td>
		<td><input name="stock" type="text" readonly="readonly" id="stock" value="0" size="20"/></td>
	</tr>
	<tr>
		<td class="label">Activo:</td>
		<td><input name="active" type="checkbox" id="active" value="1"/></td>
	</tr>
	<tr>
		<td class="label">Almacen</td>
		<td>
			<?php 
if ($storeid) {
    echo "<input type='hidden' name='storeid' value='{$storeid}'/>{$store->name}";
} else {
    $stores = Store::getAllActive("name");
    echo "<select name='storeid'>";
    echo "<option value=''>-Seleccione-</option>";
    foreach ($stores as $store) {
        echo "<option value='{$store->id}'>{$store->name}</option>";
    }
    echo "</select>";
}
?>
		</td>
	</tr>
	<tr>
		<td class="label">Costo:</td>
		<td><input name="costo" onchange="sumar()" type="text" id="costo" value="0" size="30"/></td>
	</tr>
	<tr>
<p class="form-title">Listado de Productos</p>
<?php 
if (!Forms::checkPermission(FORM_ITEM_LIST)) {
    return;
}
require_once 'inc/class.mysqli.php';
require_once 'inc/class.item.php';
require_once 'inc/class.store.php';
require_once 'inc/class.formatter.php';
$db = Database::getInstance();
$stores = Store::getAllActive("");
?>

<div id="tabs">
	<ul>
	<?php 
foreach ($stores as $store) {
    echo "<li><a href='#tab_{$store->id}'>{$store->name}</a></li>";
}
?>
	</ul>
	<?php 
foreach ($stores as $store) {
    ?>
	<div id="tab_<?php 
    echo $store->id;
    ?>
">
		<table class="default" style="width:99.9%">
		<thead>
		<tr>
<?php

require_once 'inc/class.queries.php';
require_once 'inc/class.store.php';
$stores = Store::getAllActive('', '');
?>
<div style="font-size:0.9em">
	<p class="form-subtitle">Stock en almacenes</p>
	<?php 
foreach ($stores as $store) {
    echo "<table class='default' style='float:left;margin-right:0.2em'>";
    echo "<caption style='text-align:center'>{$store->name}</caption>";
    echo "<thead><tr><th>Item</th><th>Stock</td></tr></thead>";
    $itemsStock = Queries::getStock($store->id, "stock", "ASC", 10);
    foreach ($itemsStock as $row) {
        echo "<tr>";
        echo "<td>{$row['name']}</td>";
        echo "<td class='number" . ($row['stock'] < $row['stock_min'] ? " mandatory" : "") . "'>{$row['stock']}</td>";
        echo "</tr>";
    }
    echo "</table>";
}
?>
	<br style="clear:both"/>
	<p>Los items de <span class="mandatory">color</span> estan por debajo del stock m&iacute;nimo.</p>
</div>
<p class="form-title">Traspasos</p>
<?php 
require_once 'inc/class.store.php';
$db = Database::getInstance();
$session = Session::getInstance();
$storeid = isset($_GET['storeid']) ? $_GET['storeid'] : false;
$stores = Store::getAllActive('name', 'ASC');
if ($session->userlevel < USER_LEVEL) {
    die("Acceso Denegado");
}
if (isset($_POST['data_row'])) {
    // Traspaso de lotes
    foreach ($_POST['data_row'] as $row) {
        $jsonRow = json_decode(urldecode($row));
        Store::transfer($jsonRow->source, $jsonRow->target, $jsonRow->stock, $session->uniqueid);
    }
}
?>
<form action="index.php" method="GET">
	<input type="hidden" name="pages" value="traspaso_new"/>
	Ver lotes por almacen:
	<select name="storeid">
	<option value="">- Todos -</option>
<?php 
foreach ($stores as $store) {
    echo "<option value='{$store->id}'" . (isset($_GET['storeid']) && $_GET['storeid'] == $store->id ? " selected=\"selected\"" : "") . ">{$store->name}</option>";
}
?>
	</select>
	<input type="submit" value="Aceptar"/>
</form>