dolibarr 21.0.0-alpha
moline.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2020 Lenin Rivas <lenin@leninrivas.com>
4 * Copyright (C) 2023-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
29
34{
38 public $element = 'mrp_production';
39
43 public $table_element = 'mrp_production';
44
48 public $parent_element = 'mo';
49
53 public $fk_parent_attribute = 'fk_mo';
54
95 public $fields = array(
96 'rowid' => array('type' => 'integer', 'label' => 'ID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
97 'fk_mo' => array('type' => 'integer', 'label' => 'Mo', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 15),
98 'origin_id' => array('type' => 'integer', 'label' => 'Origin', 'enabled' => 1, 'visible' => -1, 'notnull' => 0, 'position' => 17),
99 'origin_type' => array('type' => 'varchar(10)', 'label' => 'Origin type', 'enabled' => 1, 'visible' => -1, 'notnull' => 0, 'position' => 18),
100 'position' => array('type' => 'integer', 'label' => 'Position', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 20),
101 'fk_product' => array('type' => 'integer', 'label' => 'Product', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 25),
102 'fk_warehouse' => array('type' => 'integer', 'label' => 'Warehouse', 'enabled' => 1, 'visible' => -1, 'position' => 30),
103 'qty' => array('type' => 'real', 'label' => 'Qty', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 35),
104 'qty_frozen' => array('type' => 'smallint', 'label' => 'QuantityFrozen', 'enabled' => 1, 'visible' => 1, 'default' => '0', 'notnull' => 1, 'position' => 105, 'css' => 'maxwidth50imp', 'help' => 'QuantityConsumedInvariable'),
105 'disable_stock_change' => array('type' => 'smallint', 'label' => 'DisableStockChange', 'enabled' => 1, 'visible' => 1, 'default' => '0', 'notnull' => 1, 'position' => 108, 'css' => 'maxwidth50imp', 'help' => 'DisableStockChangeHelp'),
106 'batch' => array('type' => 'varchar(30)', 'label' => 'Batch', 'enabled' => 1, 'visible' => -1, 'position' => 140),
107 'role' => array('type' => 'varchar(10)', 'label' => 'Role', 'enabled' => 1, 'visible' => -1, 'position' => 145),
108 'fk_mrp_production' => array('type' => 'integer', 'label' => 'Fk mrp production', 'enabled' => 1, 'visible' => -1, 'position' => 150),
109 'fk_stock_movement' => array('type' => 'integer', 'label' => 'StockMovement', 'enabled' => 1, 'visible' => -1, 'position' => 155),
110 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 160),
111 'tms' => array('type' => 'timestamp', 'label' => 'Tms', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 165),
112 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 170),
113 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModification', 'enabled' => 1, 'visible' => -1, 'position' => 175),
114 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -1, 'position' => 180),
115 'fk_default_workstation' => array('type' => 'integer', 'label' => 'DefaultWorkstation', 'enabled' => 1, 'visible' => 1, 'notnull' => 0, 'position' => 185),
116 'fk_unit' => array('type' => 'int', 'label' => 'Unit', 'enabled' => 1, 'visible' => 1, 'notnull' => 0, 'position' => 186)
117 );
118
122 public $rowid;
126 public $fk_mo;
130 public $origin_id;
134 public $origin_type;
138 public $position;
142 public $fk_product;
146 public $fk_warehouse;
147
151 public $qty;
152
156 public $qty_frozen;
160 public $disable_stock_change;
164 public $efficiency;
165
169 public $batch;
173 public $role;
177 public $fk_mrp_production;
181 public $fk_stock_movement;
185 public $import_key;
189 public $fk_parent_line;
193 public $fk_unit;
194
198 public $fk_default_workstation;
199
205 public function __construct(DoliDB $db)
206 {
207 global $langs;
208
209 $this->db = $db;
210
211 $this->ismultientitymanaged = 0;
212 $this->isextrafieldmanaged = 1;
213
214 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
215 $this->fields['rowid']['visible'] = 0;
216 }
217 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
218 $this->fields['entity']['enabled'] = 0;
219 }
220
221 // Unset fields that are disabled
222 foreach ($this->fields as $key => $val) {
223 if (isset($val['enabled']) && empty($val['enabled'])) {
224 unset($this->fields[$key]);
225 }
226 }
227
228 // Translate some data of arrayofkeyval
229 if (is_object($langs)) {
230 foreach ($this->fields as $key => $val) {
231 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
232 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
233 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
234 }
235 }
236 }
237 }
238 }
239
247 public function create(User $user, $notrigger = 0)
248 {
249 if (empty($this->qty)) {
250 $this->error = 'ErrorEmptyValueForQty';
251 return -1;
252 }
253
254 return $this->createCommon($user, $notrigger);
255 }
256
264 public function fetch($id, $ref = null)
265 {
266 $result = $this->fetchCommon($id, $ref);
267 return $result;
268 }
269
281 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
282 {
283 dol_syslog(__METHOD__, LOG_DEBUG);
284
285 $records = array();
286
287 $sql = 'SELECT ';
288 $sql .= $this->getFieldList();
289 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
290 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
291 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
292 } else {
293 $sql .= ' WHERE 1 = 1';
294 }
295
296 // Deprecated.
297 if (is_array($filter)) {
298 $sqlwhere = array();
299 if (count($filter) > 0) {
300 foreach ($filter as $key => $value) {
301 if ($key == 't.rowid') {
302 $sqlwhere[] = $key." = ".((int) $value);
303 } elseif (strpos($key, 'date') !== false) {
304 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
305 } else {
306 $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
307 }
308 }
309 }
310 if (count($sqlwhere) > 0) {
311 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
312 }
313
314 $filter = '';
315 }
316
317 // Manage filter
318 $errormessage = '';
319 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
320 if ($errormessage) {
321 $this->errors[] = $errormessage;
322 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
323 return -1;
324 }
325
326 if (!empty($sortfield)) {
327 $sql .= $this->db->order($sortfield, $sortorder);
328 }
329 if (!empty($limit)) {
330 $sql .= $this->db->plimit($limit, $offset);
331 }
332
333 $resql = $this->db->query($sql);
334 if ($resql) {
335 $num = $this->db->num_rows($resql);
336 $i = 0;
337 while ($i < ($limit ? min($limit, $num) : $num)) {
338 $obj = $this->db->fetch_object($resql);
339
340 $record = new self($this->db);
341 $record->setVarsFromFetchObj($obj);
342
343 $records[$record->id] = $record;
344
345 $i++;
346 }
347 $this->db->free($resql);
348
349 return $records;
350 } else {
351 $this->errors[] = 'Error '.$this->db->lasterror();
352 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
353
354 return -1;
355 }
356 }
357
365 public function update(User $user, $notrigger = 0)
366 {
367 return $this->updateCommon($user, $notrigger);
368 }
369
377 public function delete(User $user, $notrigger = 0)
378 {
379 return $this->deleteCommon($user, $notrigger);
380 //return $this->deleteCommon($user, $notrigger, 1);
381 }
382}
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class MoLine.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, $notrigger=0)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
$fields
'type' field format: 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
$fk_parent_attribute
Class to manage Dolibarr users.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.