dolibarr 25.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-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 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:User:user/class/user.class.php', 'label' => 'UserCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 170),
113 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', '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
203 public $fk_bom_child;
204
210 public function __construct(DoliDB $db)
211 {
212 global $langs;
213
214 $this->db = $db;
215
216 $this->ismultientitymanaged = 0;
217 $this->isextrafieldmanaged = 1;
218
219 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
220 $this->fields['rowid']['visible'] = 0;
221 }
222 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
223 $this->fields['entity']['enabled'] = 0;
224 }
225
226 // Unset fields that are disabled
227 foreach ($this->fields as $key => $val) {
228 if (isset($val['enabled']) && empty($val['enabled'])) {
229 unset($this->fields[$key]);
230 }
231 }
232
233 // Translate some data of arrayofkeyval
234 if (is_object($langs)) {
235 foreach ($this->fields as $key => $val) {
236 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
237 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
238 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
239 }
240 }
241 }
242 }
243 }
244
252 public function create(User $user, $notrigger = 0)
253 {
254 if (empty($this->qty)) {
255 $this->error = 'ErrorEmptyValueForQty';
256 return -1;
257 }
258
259 return $this->createCommon($user, $notrigger);
260 }
261
269 public function fetch($id, $ref = null)
270 {
271 $result = $this->fetchCommon($id, $ref);
272 return $result;
273 }
274
286 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
287 {
288 dol_syslog(__METHOD__, LOG_DEBUG);
289
290 $records = array();
291
292 $sql = 'SELECT ';
293 $sql .= $this->getFieldList();
294 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
295 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
296 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
297 } else {
298 $sql .= ' WHERE 1 = 1';
299 }
300
301 // Deprecated.
302 if (is_array($filter)) {
303 $sqlwhere = array();
304 if (count($filter) > 0) {
305 foreach ($filter as $key => $value) {
306 if ($key == 't.rowid' || $key == 'fk_mo' || $key == 'origin_id') {
307 $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
308 } elseif ($key == 'origin_type') {
309 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'";
310 } elseif (strpos($key, 'date') !== false) {
311 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate((int) $value)."'";
312 } else {
313 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
314 }
315 }
316 }
317 if (count($sqlwhere) > 0) {
318 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
319 }
320
321 $filter = '';
322 }
323
324 // Manage filter
325 $errormessage = '';
326 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
327 if ($errormessage) {
328 $this->errors[] = $errormessage;
329 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
330 return -1;
331 }
332
333 if (!empty($sortfield)) {
334 $sql .= $this->db->order($sortfield, $sortorder);
335 }
336 if (!empty($limit)) {
337 $sql .= $this->db->plimit($limit, $offset);
338 }
339
340 $resql = $this->db->query($sql);
341 if ($resql) {
342 $num = $this->db->num_rows($resql);
343 $i = 0;
344 while ($i < ($limit ? min($limit, $num) : $num)) {
345 $obj = $this->db->fetch_object($resql);
346
347 $record = new self($this->db);
348 $record->setVarsFromFetchObj($obj);
349
350 $records[$record->id] = $record;
351
352 $i++;
353 }
354 $this->db->free($resql);
355
356 return $records;
357 } else {
358 $this->errors[] = 'Error '.$this->db->lasterror();
359 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
360
361 return -1;
362 }
363 }
364
372 public function update(User $user, $notrigger = 0)
373 {
374 return $this->updateCommon($user, $notrigger);
375 }
376
384 public function delete(User $user, $notrigger = 0)
385 {
386 return $this->deleteCommon($user, $notrigger);
387 //return $this->deleteCommon($user, $notrigger, 1);
388 }
389}
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.