inventory.php 3.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
//    Pastèque Web back office, Stocks module
//
//    Copyright (C) 2013 Scil (http://scil.coop)
//
//    This file is part of Pastèque.
//
//    Pastèque 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.
//
//    Pastèque 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 Pastèque.  If not, see <http://www.gnu.org/licenses/>.

namespace BaseStocks;

23
24
25
26
27
28
29
$modules = \Pasteque\get_loaded_modules(\Pasteque\get_user_id());
$multilocations = false;
$defaultLocationId = null;
if (in_array("stock_multilocations", $modules)) {
    $multilocations = true;
}

30
31
32
33
34
35
36
37
38
39
40
$locSrv = new \Pasteque\LocationsService();
$locations = $locSrv->getAll();
$locNames = array();
$locIds = array();
foreach ($locations as $location) {
    $locNames[] = $location->label;
    $locIds[] = $location->id;
}
$currLocation = null;
if (isset($_POST['location'])) {
    $currLocation = $_POST['location'];
41
42
} else {
    $currLocation = $locations[0]->id;
43
}
44
$products = \Pasteque\ProductsService::getAll(true);
45
$levels = \Pasteque\StocksService::getLevels($currLocation);
46
47
?>
<h1><?php \pi18n("Inventory", PLUGIN_NAME); ?></h1>
48

49
<?php if ($multilocations) { ?>
50
51
52
53
54
55
56
57
58
59
<form class="edit" action="<?php echo \Pasteque\get_current_url(); ?>" method="post">
	<div class="row">
		<?php \Pasteque\form_select("location", \i18n("Location"), $locIds, $locNames, $currLocation); ?>
	</div>
	<div class="row actions">
		<?php \Pasteque\form_send(); ?>
	</div>
</form>
<?php } ?>

60
61
62
63
64
65
66
67
68
69
70
71
<table cellpadding="0" cellspacing="0">
	<thead>
		<tr>
			<th></th>
			<th><?php \pi18n("Product.reference"); ?></th>
			<th><?php \pi18n("Product.label"); ?></th>
			<th><?php \pi18n("Quantity"); ?></th>
		</tr>
	</thead>
	<tbody>
<?php
$par = FALSE;
72
foreach ($levels as $level) {
73
$par = !$par;
74
75
76
77
78
79
80
81
82
83
84
85
$prdRef = "";
$prdLabel = "";
foreach ($products as $product) {
    if ($product->id == $level->productId) {
        $prdLabel = $product->label;
        $prdRef = $product->reference;
        break;
    }
}
$security = $level->security;
$max = $level->max;
$qty = $level->qty !== null ? $level->qty : 0;
86
$class = "";
87
$help = "";
88
89
if ($security !== NULL && $qty < $security) {
    $class=" warn-level";
90
    $help = ' title="' . \i18n("Stock is below security level!", PLUGIN_NAME) . '"';
91
}
92
if ($qty < 0) {
93
    $class=" alert-level";
94
    $help = ' title="' . \i18n("Stock is negative!", PLUGIN_NAME) . '"';
95
96
97
} else if ($max !== NULL && $qty > $max) {
    $class=" alert-level";
    $help = ' title="' . \i18n("Overstock!", PLUGIN_NAME) . '"';
98
}
99
100
?>
	<tr class="row-<?php echo $par ? 'par' : 'odd'; ?>">
101
	    <td><img class="thumbnail" src="?<?php echo \Pasteque\PT::URL_ACTION_PARAM; ?>=img&w=product&id=<?php echo $level->productId; ?>" />
102
103
		<td><?php echo $prdRef; ?></td>
		<td><?php echo $prdLabel; ?></td>
104
		<td class="numeric<?php echo $class; ?>"<?php echo $help; ?>><?php echo $qty; ?></td>
105
106
107
108
109
110
	</tr>
<?php
}
?>
	</tbody>
</table>