Commit 89da4a3c authored by Cédric Houbart's avatar Cédric Houbart
Browse files

Inventory, low and overcrowd display

parent 3969207b
<?php
// POS-Tech API
//
// Copyright (C) 2012 Scil (http://scil.coop)
//
// This file is part of POS-Tech.
//
// POS-Tech is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// POS-Tech is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with POS-Tech. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
class StocksService {
private static function buildDBUser($db_user) {
$role = RolesService::get($db_user['ROLE']);
$user = User::__build($db_user['ID'], $db_user['NAME'],
$db_user['APPPASSWORD'], $role);
return $user;
}
static function getQties($warehouseId = NULL) {
$qties = array();
$pdo = PDOBuilder::getPDO();
if ($warehouseId === NULL) {
$sql = "SELECT PRODUCT, SUM(UNITS) FROM STOCKCURRENT "
. "GROUP BY PRODUCT";
$stmt = $pdo->prepare($sql);
$stmt->execute();
while ($row = $stmt->fetch()) {
$qties[$row[0]] = $row[1];
}
return $qties;
} else {
// TODO: multiple warehouses
return NULL;
}
}
static function getQty($productId, $warehouseId = NULL) {
$pdo = PDOBuilder::getPDO();
if ($warehouseID === NULL) {
$stmt = $pdo->prepare("SELECT SUM(UNITS) FROM STOCKCURRENT WHERE "
. "PRODUCT = :id GROUP BY PRODUCT");
$stmt->bindParam(":id", $productId);
$stmt->execute();
$res = $stmt->fetchAll();
return $res[0];
} else {
$stmt = $pdo->prepare("SELECT UNITS FROM STOCKCURRENT WHERE "
. "PRODUCT = :id AND LOCATION = :loc");
$stmt->bindParam(":id", $productId);
$stmt->bindParam(":loc", $warehouseId);
$stmt->execute();
return $stmt->fetchAll();
}
}
static function getLevels($warehouseId = NULL) {
$pdo = PDOBuilder::getPDO();
$lvls = array();
if ($warehouseId === NULL) {
$sql = "SELECT * FROM STOCKLEVEL";
$stmt = $pdo->prepare($sql);
$stmt->execute();
while ($row = $stmt->fetch()) {
$lvl = new \stdClass();
$lvl->id = $row['ID'];
$lvl->location = $row['LOCATION'];
$lvl->security = $row['STOCKSECURITY'];
$lvl->max = $row['STOCKMAXIMUM'];
$lvls[$row['PRODUCT']] = $lvl;
}
return $lvls;
}
// TODO: multiple warehouses
}
}
?>
......@@ -89,6 +89,7 @@ require_once(ABSPATH . "/inc/data/services/TaxesService.php");
require_once(ABSPATH . "/inc/data/services/TicketsService.php");
require_once(ABSPATH . "/inc/data/services/UsersService.php");
require_once(ABSPATH . "/inc/data/services/RolesService.php");
require_once(ABSPATH . "/inc/data/services/StocksService.php");
load_base_i18n(detect_preferred_language());
?>
......@@ -11,6 +11,7 @@
"Image": "Image",
"Quantity": "Quantity",
"Undefined": "Undefined",
"Product.label": "Name",
"Product.reference": "Reference",
......
......@@ -11,6 +11,7 @@
"Image": "Image",
"Quantity": "Quantité",
"Undefined": "Non défini",
"Product.label": "Désignation",
"Product.reference": "Référence",
......
......@@ -21,9 +21,11 @@
namespace BaseStocks;
$products = \Pasteque\ProductsService::getAll();
$stocks = \Pasteque\StocksService::getQties();
$levels = \Pasteque\StocksService::getLevels();
?>
<h1><?php \pi18n("Inventory", PLUGIN_NAME); ?></h1>
<div class="error">Not supported yet</div>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
......@@ -31,6 +33,7 @@ $products = \Pasteque\ProductsService::getAll();
<th><?php \pi18n("Product.reference"); ?></th>
<th><?php \pi18n("Product.label"); ?></th>
<th><?php \pi18n("Quantity"); ?></th>
<th><?php \pi18n("Security threshold", PLUGIN_NAME); ?></th>
</tr>
</thead>
<tbody>
......@@ -38,12 +41,23 @@ $products = \Pasteque\ProductsService::getAll();
$par = FALSE;
foreach ($products as $product) {
$par = !$par;
$qty = isset($stocks[$product->id]) ? $stocks[$product->id] : 0;
$security = isset($levels[$product->id]) ? $levels[$product->id]->security : NULL;
$max = isset($levels[$product->id]) ? $levels[$product->id]->max : NULL;
$class = "";
if ($security !== NULL && $qty < $security) {
$class=" warn-level";
}
if ($qty < 0 || ($max !== NULL && $qty > $max)) {
$class=" alert-level";
}
?>
<tr class="row-<?php echo $par ? 'par' : 'odd'; ?>">
<td><img class="thumbnail" src="?<?php echo \Pasteque\URL_ACTION_PARAM; ?>=img&w=product&id=<?php echo $product->id; ?>" />
<td><?php echo $product->reference; ?></td>
<td><?php echo $product->label; ?></td>
<td>???</td>
<td class="numeric<?php echo $class; ?>"><?php echo $qty; ?></td>
<td class="numeric"><?php echo $security === NULL ? \i18n("Undefined") : $security; ?></td>
</tr>
<?php
}
......
......@@ -8,5 +8,6 @@
"Output (sell)": "Output (sell)",
"Output (return to supplyer)": "Output (return to supplyer)",
"Inventory": "Inventory"
"Inventory": "Inventory",
"Security threshold": "Security threshold"
}
......@@ -8,5 +8,6 @@
"Output (sell)": "Sortie (vente)",
"Output (return to supplyer": "Sortie (retour au fournisseur)",
"Inventory": "Inventaire"
"Inventory": "Inventaire",
"Security threshold": "Seuil de sécurité"
}
......@@ -32,6 +32,7 @@ function tpl_open() {
<title><?php \pi18n("Pastèque"); ?></title>
<link rel="stylesheet" type="text/css" href="templates/pasteque/style.css" />
<link rel="stylesheet" type="text/css" href="templates/pasteque/catalog.css" />
<link rel="stylesheet" type="text/css" href="templates/pasteque/stock.css" />
<script type="text/javascript" src="templates/pasteque/js/jquery-1.9.1.min.js"></script>
</head>
<body>
......
.warn-level {
font-weight: bold;
color: #FF9E2D;
}
.alert-level {
font-weight: bold;
color: #F10C14;
}
......@@ -183,6 +183,9 @@ td {
border-top: 1px solid black;
padding: 10px 5px 10px 5px;
}
td.numeric {
text-align: center;
}
th {
text-align: left;
padding: 20px;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment