forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStockMvtWS.php
305 lines (262 loc) · 9.4 KB
/
StockMvtWS.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
/**
* Webservice entity for stock movements.
*
* @since 1.5.0
* @deprecated since 9.0 and will be removed in 10.0, this object model is no longer needed
*/
class StockMvtWSCore extends ObjectModelCore
{
public $id;
/**
* @var string The creation date of the movement
*/
public $date_add;
/**
* @var int The employee id, responsible of the movement
*/
public $id_employee;
/**
* @var string The first name of the employee responsible of the movement
*/
public $employee_firstname;
/**
* @var string The last name of the employee responsible of the movement
*/
public $employee_lastname;
/**
* @var int The stock id on wtich the movement is applied
*/
public $id_stock;
/**
* @var int the quantity of product with is moved
*/
public $physical_quantity;
/**
* @var int id of the movement reason assoiated to the movement
*/
public $id_stock_mvt_reason;
/**
* @var int Used when the movement is due to a customer order
*/
public $id_order = null;
/**
* @var int detrmine if the movement is a positive or negative operation
*/
public $sign;
/**
* @var int Used when the movement is due to a supplier order
*/
public $id_supply_order = null;
/**
* @var float Last value of the weighted-average method
*/
public $last_wa = null;
/**
* @var float Current value of the weighted-average method
*/
public $current_wa = null;
/**
* @var float The unit price without tax of the product associated to the movement
*/
public $price_te;
/**
* @var int Refers to an other id_stock_mvt : used for LIFO/FIFO implementation in StockManager
*/
public $referer;
/**
* @var int id_product (@see Stock::id_product)
*/
public $id_product;
/**
* @var int id_product_attribute (@see Stock::id_product_attribute)
*/
public $id_product_attribute;
/**
* @var int id_warehouse (@see Stock::id_warehouse)
*/
public $id_warehouse;
/**
* @var int id_currency (@see Warehouse::id_currency)
*/
public $id_currency;
/**
* @var string management_type (@see Warehouse::management_type)
*/
public $management_type;
/**
* @var string : Name of the product (@see Product::getProductName)
*/
public $product_name;
/**
* @var string EAN13 of the product (@see Stock::product_ean13)
*/
public $ean13;
/**
* @var string UPC of the product (@see Stock::product_upc)
*/
public $upc;
/**
* @var string MPN of the product (@see Stock::product_mpn)
*/
public $mpn;
/**
* @var string Reference of the product (@see Stock::product_reference)
*/
public $reference;
/**
* @see ObjectModel::$definition
*/
public static $definition = [
'table' => 'stock_mvt',
'primary' => 'id_stock_mvt',
'fields' => [
'id_employee' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'employee_firstname' => ['type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 255],
'employee_lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 255],
'id_stock' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'physical_quantity' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'id_stock_mvt_reason' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'id_order' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'],
'id_supply_order' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'],
'sign' => ['type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true],
'last_wa' => ['type' => self::TYPE_FLOAT, 'validate' => 'isPrice'],
'current_wa' => ['type' => self::TYPE_FLOAT, 'validate' => 'isPrice'],
'price_te' => ['type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true],
'referer' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true],
],
];
/**
* @see ObjectModel::$webserviceParameters
*/
protected $webserviceParameters = [
'fields' => [
'id_product' => ['xlink_resource' => 'products'],
'id_product_attribute' => ['xlink_resource' => 'combinations'],
'id_warehouse' => ['xlink_resource' => 'warehouses'],
'id_currency' => ['xlink_resource' => 'currencies'],
'management_type' => [],
'id_employee' => ['xlink_resource' => 'employees'],
'id_stock' => ['xlink_resource' => 'stocks'],
'id_stock_mvt_reason' => ['xlink_resource' => 'stock_movement_reasons'],
'id_order' => ['xlink_resource' => 'orders'],
'id_supply_order' => ['xlink_resource' => 'supply_orders'],
'product_name' => ['getter' => 'getWSProductName', 'i18n' => true],
'ean13' => [],
'upc' => [],
'reference' => [],
'mpn' => [],
],
'hidden_fields' => [
'referer',
'employee_firstname',
'employee_lastname',
],
];
/**
* Associations tables for attributes that require different tables than stated in ObjectModel::definition.
*
* @var array
*/
protected $tables_assoc = [
'id_product' => ['table' => 's'],
'id_product_attribute' => ['table' => 's'],
'id_warehouse' => ['table' => 's'],
'id_currency' => ['table' => 's'],
'management_type' => ['table' => 'w'],
'ean13' => ['table' => 's'],
'upc' => ['table' => 's'],
'mpn' => ['table' => 's'],
'reference' => ['table' => 's'],
];
/**
* @see ObjectModel
*/
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
// calls parent
parent::__construct($id, $id_lang, $id_shop);
if ((int) $this->id != 0) {
$res = $this->getWebserviceObjectList('', ' AND ' . $this->def['primary'] . ' = ' . (int) $this->id, '', '', true);
if (isset($res[0])) {
foreach ($this->tables_assoc as $key => $param) {
$this->{$key} = $res[0][$key];
}
}
}
}
/**
* @see ObjectModel::getWebserviceObjectList()
* Added $full for this specific object
*/
public function getWebserviceObjectList($join, $filter, $sort, $limit, $full = false)
{
$query = 'SELECT DISTINCT main.' . $this->def['primary'] . ' ';
if ($full) {
$query .= ', s.id_product, s.id_product_attribute, s.id_warehouse, w.id_currency, w.management_type,
s.ean13, s.upc, s.mpn, s.reference ';
}
$old_filter = $filter;
if ($filter) {
foreach ($this->tables_assoc as $key => $value) {
$filter = str_replace('main.`' . $key . '`', $value['table'] . '.`' . $key . '`', $filter);
}
}
$query .= 'FROM ' . _DB_PREFIX_ . $this->def['table'] . ' as main ';
if ($filter !== $old_filter || $full) {
$query .= 'LEFT JOIN ' . _DB_PREFIX_ . 'stock s ON (s.id_stock = main.id_stock) ';
$query .= 'LEFT JOIN ' . _DB_PREFIX_ . 'warehouse w ON (w.id_warehouse = s.id_warehouse) ';
$query .= 'LEFT JOIN ' . _DB_PREFIX_ . 'currency c ON (c.id_currency = w.id_currency) ';
}
if ($join) {
$query .= $join;
}
$query .= 'WHERE 1 ';
if ($filter) {
$query .= $filter . ' ';
}
if ($sort) {
$query .= $sort . ' ';
}
if ($limit) {
$query .= $limit . ' ';
}
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
/**
* Webservice : getter for the product name.
*/
public function getWSProductName()
{
$res = [];
foreach (Language::getIDs(true) as $id_lang) {
$res[$id_lang] = Product::getProductName($this->id_product, $this->id_product_attribute, $id_lang);
}
return $res;
}
}