inventory.php 5.39 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
46
47
48
49
50
51
52
$categories = \Pasteque\CategoriesService::getAll();
$prdCat = array();
// Link products to categories and don't track compositions
foreach ($products as $product) {
    if ($product->categoryId !== \Pasteque\CompositionsService::CAT_ID) {
        $prdCat[$product->categoryId][] = $product;
    }
}
53
$levels = \Pasteque\StocksService::getLevels($currLocation);
54
55
56
57
$prdLevel = array();
foreach ($levels as $level) {
    $prdLevel[$level->productId] = $level;
}
58
59
?>
<h1><?php \pi18n("Inventory", PLUGIN_NAME); ?></h1>
60

61
62
<?php if ($multilocations) {
    // Location picker ?>
63
64
65
66
67
68
69
70
<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>
71
72
<?php
}
73

74
75
76
77
78
$par = false;
foreach ($categories as $category) {
    if (isset($prdCat[$category->id])) {
        // Category header ?>
<h3><?php echo \Pasteque\esc_html($category->label); ?></h3>
79
80
81
82
83
84
85
<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>
86
87
88
89
			<th><?php \pi18n("Stock.SellValue"); ?></th>
			<th><?php \pi18n("Stock.BuyValue"); ?></th>
			<th><?php \pi18n("QuantityMin"); ?></th>
			<th><?php \pi18n("QuantityMax"); ?></th>
90
91
92
93
		</tr>
	</thead>
	<tbody>
<?php
94
95
96
97
98
99
100
101
102
        foreach ($prdCat[$category->id] as $product) {
            if (!isset($prdLevel[$product->id])) {
                continue;
            }
            // Level lines
            $par = !$par;
            $prdRef = "";
            $prdLabel = "";
            $imgSrc = "";
103
104
            $prdSellPrice = 0;
            $prdBuyPrice = 0;
105
106
107
108
109
110
111
112
            $level = $prdLevel[$product->id];
            if ($product->hasImage) {
                $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=product&id=" . $product->id;
            } else {
                $imgSrc = \Pasteque\PT::URL_ACTION_PARAM . "=img&w=product";
            }
            $prdLabel = $product->label;
            $prdRef = $product->reference;
113
114
            $prdSellPrice = $product->priceSell;
            $prdBuyPrice = $product->priceBuy;
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
            $security = $level->security;
            $max = $level->max;
            $qty = $level->qty !== null ? $level->qty : 0;
            $class = "";
            $help = "";
            if ($security !== null && $qty < $security) {
                $class=" warn-level";
                $help = ' title="' . \Pasteque\esc_attr(\i18n("Stock is below security level!", PLUGIN_NAME)) . '"';
            }
            if ($qty < 0) {
                $class=" alert-level";
                $help = ' title="' . \Pasteque\esc_attr(\i18n("Stock is negative!", PLUGIN_NAME)) . '"';
            } else if ($max !== NULL && $qty > $max) {
                $class=" alert-level";
                $help = ' title="' . \Pasteque\esc_attr(\i18n("Overstock!", PLUGIN_NAME)) . '"';
            }
131
132
133
134
135
136
            if (!isset($security)) {
                $security = \i18n("Undefined");
            }
            if (!isset($max)) {
                $max = \i18n("Undefined");
            }
137
138
            ?>
		<tr class="row-<?php echo $par ? 'par' : 'odd'; ?>">
139
                 <td><img class="thumbnail" src="?<?php echo \Pasteque\esc_attr($imgSrc); ?>" />
140
141
142
                 <td><?php echo \Pasteque\esc_html($prdRef); ?></td>
                 <td><?php echo \Pasteque\esc_html($prdLabel); ?></td>
                 <td class="numeric<?php echo $class; ?>"<?php echo $help; ?>><?php echo \Pasteque\esc_html($qty); ?></td>
143
144
145
146
                 <td><?php echo \Pasteque\esc_html(\i18nCurr($prdSellPrice*$qty)); ?></td>
                 <td><?php echo \Pasteque\esc_html(\i18nCurr($prdBuyPrice*$qty)); ?></td>
                 <td><?php echo \Pasteque\esc_html($security); ?></td>
                 <td><?php echo \Pasteque\esc_html($max); ?></td>
147
		</tr>
148
<?php
149
        } ?>
150
151
	</tbody>
</table>
152
153
<?php    }
}