dolibarr 21.0.0-alpha
mo.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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.'/mrp/class/moline.class.php';
29
33class Mo extends CommonObject
34{
38 public $element = 'mo';
39
43 public $table_element = 'mrp_mo';
44
48 public $picto = 'mrp';
49
50
51 const STATUS_DRAFT = 0;
52 const STATUS_VALIDATED = 1; // To produce
53 const STATUS_INPROGRESS = 2;
54 const STATUS_PRODUCED = 3;
55 const STATUS_CANCELED = 9;
56
57
87 public $fields = array(
88 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id",),
89 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'position' => 5, 'notnull' => 1, 'default' => '1', 'index' => 1),
90 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 4, 'position' => 10, 'notnull' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'comment' => "Reference of object", 'showoncombobox' => 1, 'noteditable' => 1),
91 'fk_bom' => array('type' => 'integer:Bom:bom/class/bom.class.php:0:(t.status:=:1)', 'filter' => 'active=1', 'label' => 'BOM', 'enabled' => '$conf->bom->enabled', 'visible' => 1, 'position' => 33, 'notnull' => -1, 'index' => 1, 'comment' => "Original BOM", 'css' => 'minwidth100 maxwidth500', 'csslist' => 'tdoverflowmax150', 'picto' => 'bom'),
92 'mrptype' => array('type' => 'integer', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'position' => 34, 'notnull' => 1, 'default' => '0', 'arrayofkeyval' => array(0 => 'Manufacturing', 1 => 'Disassemble'), 'css' => 'minwidth150', 'csslist' => 'minwidth150 center'),
93 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php:0', 'label' => 'Product', 'enabled' => 'isModEnabled("product")', 'visible' => 1, 'position' => 35, 'notnull' => 1, 'index' => 1, 'comment' => "Product to produce", 'css' => 'maxwidth300', 'csslist' => 'tdoverflowmax100', 'picto' => 'product'),
94 'qty' => array('type' => 'real', 'label' => 'QtyToProduce', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'notnull' => 1, 'comment' => "Qty to produce", 'css' => 'width75', 'default' => '1', 'isameasure' => 1),
95 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 42, 'notnull' => -1, 'searchall' => 1, 'showoncombobox' => 2, 'css' => 'maxwidth300', 'csslist' => 'tdoverflowmax200', 'alwayseditable' => 1),
96 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1', 'label' => 'ThirdParty', 'picto' => 'company', 'enabled' => 'isModEnabled("societe")', 'visible' => -1, 'position' => 50, 'notnull' => -1, 'index' => 1, 'css' => 'maxwidth400', 'csslist' => 'tdoverflowmax150'),
97 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'picto' => 'project', 'enabled' => '$conf->project->enabled', 'visible' => -1, 'position' => 51, 'notnull' => -1, 'index' => 1, 'css' => 'minwidth200 maxwidth400', 'csslist' => 'tdoverflowmax100'),
98 'fk_warehouse' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php:0', 'label' => 'WarehouseForProduction', 'picto' => 'stock', 'enabled' => 'isModEnabled("stock")', 'visible' => 1, 'position' => 52, 'css' => 'maxwidth400', 'csslist' => 'tdoverflowmax200'),
99 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 61, 'notnull' => -1,),
100 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 62, 'notnull' => -1,),
101 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 500, 'notnull' => 1,),
102 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 501, 'notnull' => 1,),
103 'date_valid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -2, 'position' => 502,),
104 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'position' => 510, 'notnull' => 1, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax100'),
105 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'position' => 511, 'notnull' => -1, 'csslist' => 'tdoverflowmax100'),
106 'date_start_planned' => array('type' => 'datetime', 'label' => 'DateStartPlannedMo', 'enabled' => 1, 'visible' => 1, 'position' => 55, 'notnull' => -1, 'index' => 1, 'help' => 'KeepEmptyForAsap', 'alwayseditable' => 1, 'csslist' => 'nowraponall'),
107 'date_end_planned' => array('type' => 'datetime', 'label' => 'DateEndPlannedMo', 'enabled' => 1, 'visible' => 1, 'position' => 56, 'notnull' => -1, 'index' => 1, 'alwayseditable' => 1, 'csslist' => 'nowraponall'),
108 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 1000, 'notnull' => -1,),
109 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 1010),
110 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 2, 'position' => 1000, 'default' => '0', 'notnull' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '2' => 'InProgress', '3' => 'StatusMOProduced', '9' => 'Canceled')),
111 'fk_parent_line' => array('type' => 'integer:MoLine:mrp/class/mo.class.php', 'label' => 'ParentMo', 'enabled' => 1, 'visible' => 0, 'position' => 1020, 'default' => '0', 'notnull' => 0, 'index' => 1,'showoncombobox' => 0),
112 );
116 public $rowid;
120 public $entity;
124 public $ref;
125
129 public $mrptype;
133 public $label;
134
138 public $qty;
142 public $fk_warehouse;
146 public $fk_soc;
150 public $socid;
151
155 public $note_public;
156
160 public $note_private;
161
165 public $date_valid;
166
170 public $fk_user_creat;
174 public $fk_user_modif;
178 public $import_key;
182 public $status;
183
187 public $fk_product;
188
192 public $product;
193
197 public $date_start_planned;
198
202 public $date_end_planned;
203
207 public $fk_bom;
208
212 public $bom;
213
217 public $fk_project;
218
223 public $oldQty;
224
225
226 // If this object has a subtable with lines
227
231 public $table_element_line = 'mrp_production';
232
236 public $fk_element = 'fk_mo';
237
241 public $class_element_line = 'MoLine';
242
246 protected $childtables = array();
247
251 protected $childtablesoncascade = array('mrp_production');
252
256 public $lines = array();
257
261 public $line = null;
262
266 public $fk_parent_line;
267
271 public $tpl = array();
272
273
279 public function __construct(DoliDB $db)
280 {
281 global $langs;
282
283 $this->db = $db;
284
285 $this->ismultientitymanaged = 1;
286 $this->isextrafieldmanaged = 1;
287
288 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
289 $this->fields['rowid']['visible'] = 0;
290 }
291 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
292 $this->fields['entity']['enabled'] = 0;
293 }
294
295 // Unset fields that are disabled
296 foreach ($this->fields as $key => $val) {
297 if (isset($val['enabled']) && empty($val['enabled'])) {
298 unset($this->fields[$key]);
299 }
300 }
301
302 // Translate some data of arrayofkeyval
303 foreach ($this->fields as $key => $val) {
304 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
305 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
306 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
307 }
308 }
309 }
310 }
311
319 public function create(User $user, $notrigger = 0)
320 {
321 $error = 0;
322 $idcreated = 0;
323
324 // If kits feature is enabled and we don't allow kits into BOM and MO, we check that the product is not a kit/virtual product
325 if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && !getDolGlobalString('ALLOW_USE_KITS_INTO_BOM_AND_MO') && $this->fk_product > 0) {
326 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
327 $tmpproduct = new Product($this->db);
328 $tmpproduct->fetch($this->fk_product);
329 if ($tmpproduct->hasFatherOrChild(1) > 0) {
330 $this->error = 'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
331 $this->errors[] = $this->error;
332 return -1;
333 }
334 }
335
336 $this->db->begin();
337
338 if ($this->fk_bom > 0) {
339 // If there is a known BOM, we force the type of MO to the type of BOM
340 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
341 $tmpbom = new BOM($this->db);
342 $tmpbom->fetch($this->fk_bom);
343
344 $this->mrptype = $tmpbom->bomtype;
345 }
346
347 if (!$error) {
348 $idcreated = $this->createCommon($user, $notrigger);
349 if ($idcreated <= 0) {
350 $error++;
351 }
352 }
353
354 if (!$error) {
355 $result = $this->createProduction($user, $notrigger); // Insert lines from BOM
356 if ($result <= 0) {
357 $error++;
358 }
359 }
360
361 if (!$error) {
362 $this->db->commit();
363 return $idcreated;
364 } else {
365 $this->db->rollback();
366 return -1;
367 }
368 }
369
377 public function createFromClone(User $user, $fromid)
378 {
379 global $langs, $extrafields;
380 $error = 0;
381
382 dol_syslog(__METHOD__, LOG_DEBUG);
383
384 $object = new self($this->db);
385
386 $this->db->begin();
387
388 // Load source object
389 $result = $object->fetchCommon($fromid);
390 if ($result > 0 && !empty($object->table_element_line)) {
391 $object->fetchLines();
392 }
393
394 // get lines so they will be clone
395 //foreach($this->lines as $line)
396 // $line->fetch_optionals();
397
398 // Reset some properties
399 unset($object->id);
400 unset($object->fk_user_creat);
401 unset($object->import_key);
402
403 // We make $object->lines empty to sort it without produced and consumed lines
404 $TLines = $object->lines;
405 $object->lines = array();
406
407 // Remove produced and consumed lines
408 foreach ($TLines as $key => $line) {
409 if (in_array($line->role, array('consumed', 'produced'))) {
410 unset($object->lines[$key]);
411 } else {
412 $object->lines[] = $line;
413 }
414 }
415
416
417 // Clear fields @phan-suppress-next-line PhanTypeMismatchProperty
418 $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
419 // @phan-suppress-next-line PhanTypeInvalidDimOffset
420 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
421 $object->status = self::STATUS_DRAFT;
422 // ...
423 // Clear extrafields that are unique
424 if (is_array($object->array_options) && count($object->array_options) > 0) {
425 $extrafields->fetch_name_optionals_label($this->table_element);
426 foreach ($object->array_options as $key => $option) {
427 $shortkey = preg_replace('/options_/', '', $key);
428 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
429 //var_dump($key);
430 //var_dump($clonedObj->array_options[$key]); exit;
431 unset($object->array_options[$key]);
432 }
433 }
434 }
435
436 // Create clone
437 $object->context['createfromclone'] = 'createfromclone';
438 $result = $object->createCommon($user);
439 if ($result < 0) {
440 $error++;
441 $this->error = $object->error;
442 $this->errors = $object->errors;
443 }
444
445 if (!$error) {
446 // copy internal contacts
447 if ($this->copy_linked_contact($object, 'internal') < 0) {
448 $error++;
449 }
450 }
451
452 if (!$error) {
453 // copy external contacts if same company
454 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
455 if ($this->copy_linked_contact($object, 'external') < 0) {
456 $error++;
457 }
458 }
459 }
460
461 unset($object->context['createfromclone']);
462
463 // End
464 if (!$error) {
465 $this->db->commit();
466 return $object;
467 } else {
468 $this->db->rollback();
469 return -1;
470 }
471 }
472
480 public function fetch($id, $ref = null)
481 {
482 $result = $this->fetchCommon($id, $ref);
483 if ($result > 0 && !empty($this->table_element_line)) {
484 $this->fetchLines();
485 }
486
487 $this->socid = $this->fk_soc;
488
489 return $result;
490 }
491
497 public function fetchLines()
498 {
499 $this->lines = array();
500
501 $result = $this->fetchLinesCommon();
502 return $result;
503 }
504
505
517 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
518 {
519 dol_syslog(__METHOD__, LOG_DEBUG);
520
521 $records = array();
522
523 $sql = 'SELECT ';
524 $sql .= $this->getFieldList();
525 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
526 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
527 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
528 } else {
529 $sql .= ' WHERE 1 = 1';
530 }
531
532 // Manage filter
533 if (is_array($filter)) {
534 $sqlwhere = array();
535 if (count($filter) > 0) {
536 foreach ($filter as $key => $value) {
537 if ($key == 't.rowid') {
538 $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
539 } elseif (strpos($key, 'date') !== false) {
540 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
541 } else {
542 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
543 }
544 }
545 }
546 if (count($sqlwhere) > 0) {
547 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
548 }
549
550 $filter = '';
551 }
552
553 // Manage filter
554 $errormessage = '';
555 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
556 if ($errormessage) {
557 $this->errors[] = $errormessage;
558 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
559 return -1;
560 }
561
562 if (!empty($sortfield)) {
563 $sql .= $this->db->order($sortfield, $sortorder);
564 }
565 if (!empty($limit)) {
566 $sql .= $this->db->plimit($limit, $offset);
567 }
568
569 $resql = $this->db->query($sql);
570 if ($resql) {
571 $num = $this->db->num_rows($resql);
572 $i = 0;
573 while ($i < min($limit, $num)) {
574 $obj = $this->db->fetch_object($resql);
575
576 $record = new self($this->db);
577 $record->setVarsFromFetchObj($obj);
578
579 $records[$record->id] = $record;
580
581 $i++;
582 }
583 $this->db->free($resql);
584
585 return $records;
586 } else {
587 $this->errors[] = 'Error '.$this->db->lasterror();
588 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
589
590 return -1;
591 }
592 }
593
601 public function fetchLinesLinked($role, $lineid = 0)
602 {
603 $resarray = array();
604 $mostatic = new MoLine($this->db);
605
606 $sql = 'SELECT ';
607 $sql .= $mostatic->getFieldList();
608 $sql .= ' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.' as t';
609 $sql .= " WHERE t.role = '".$this->db->escape($role)."'";
610 if ($lineid > 0) {
611 $sql .= ' AND t.fk_mrp_production = '.((int) $lineid);
612 } else {
613 $sql .= 'AND t.fk_mo = '.((int) $this->id);
614 }
615
616 $resql = $this->db->query($sql);
617 if ($resql) {
618 $num = $this->db->num_rows($resql);
619
620 $i = 0;
621 while ($i < $num) {
622 $obj = $this->db->fetch_object($resql);
623 if ($obj) {
624 $resarray[] = array(
625 'rowid' => $obj->rowid,
626 'date' => $this->db->jdate($obj->date_creation),
627 'qty' => $obj->qty,
628 'role' => $obj->role,
629 'fk_product' => $obj->fk_product,
630 'fk_warehouse' => $obj->fk_warehouse,
631 'batch' => $obj->batch,
632 'fk_stock_movement' => $obj->fk_stock_movement,
633 'fk_unit' => $obj->fk_unit
634 );
635 }
636
637 $i++;
638 }
639
640 return $resarray;
641 } else {
642 $this->error = $this->db->lasterror();
643 return array();
644 }
645 }
646
647
653 public function countMovements()
654 {
655 $result = 0;
656
657 $sql = 'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.'stock_mouvement as sm';
658 $sql .= " WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->id);
659
660 $resql = $this->db->query($sql);
661 if ($resql) {
662 $num = $this->db->num_rows($resql);
663
664 $i = 0;
665 while ($i < $num) {
666 $obj = $this->db->fetch_object($resql);
667 if ($obj) {
668 $result = $obj->nb;
669 }
670
671 $i++;
672 }
673 } else {
674 $this->error = $this->db->lasterror();
675 }
676
677 return $result;
678 }
679
680
688 public function update(User $user, $notrigger = 0)
689 {
690 $error = 0;
691
692 $this->db->begin();
693
694 $result = $this->updateCommon($user, $notrigger);
695 if ($result <= 0) {
696 $error++;
697 }
698
699 // Update the lines (the qty) to consume or to produce
700 $result = $this->updateProduction($user, $notrigger);
701 if ($result <= 0) {
702 $error++;
703 }
704
705 if (!$error) {
706 $this->db->commit();
707 return 1;
708 } else {
709 $this->db->rollback();
710 return -1;
711 }
712 }
713
714
722 public function createProduction(User $user, $notrigger = 0)
723 {
724 $error = 0;
725 $role = "";
726
727 if ($this->status != self::STATUS_DRAFT) {
728 return -1;
729 }
730
731 $this->db->begin();
732
733 // Insert lines in mrp_production table from BOM data
734 if (!$error) {
735 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'mrp_production WHERE fk_mo = '.((int) $this->id);
736 $this->db->query($sql);
737
738 $moline = new MoLine($this->db);
739
740 // Line to produce
741 $moline->fk_mo = $this->id;
742 $moline->qty = $this->qty;
743 $moline->fk_product = $this->fk_product;
744 $moline->position = 1;
745 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
746 $tmpproduct = new Product($this->db);
747 $tmpproduct->fetch($this->fk_product);
748 $moline->fk_unit = $tmpproduct->fk_unit;
749
750 if ($this->fk_bom > 0) { // If a BOM is defined, we know what to produce.
751 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
752 $bom = new BOM($this->db);
753 $bom->fetch($this->fk_bom);
754 if ($bom->bomtype == 1) {
755 $role = 'toproduce';
756 $moline->role = 'toconsume';
757 } else {
758 $role = 'toconsume';
759 $moline->role = 'toproduce';
760 }
761 } else {
762 if ($this->mrptype == 1) {
763 $moline->role = 'toconsume';
764 } else {
765 $moline->role = 'toproduce';
766 }
767 }
768
769 $resultline = $moline->create($user, false); // Never use triggers here
770 if ($resultline <= 0) {
771 $error++;
772 $this->error = $moline->error;
773 $this->errors = $moline->errors;
774 }
775
776 if ($this->fk_bom > 0) { // If a BOM is defined, we know what to consume.
777 if ($bom->id > 0) {
778 // Lines to consume
779 if (!$error) {
780 foreach ($bom->lines as $line) {
781 $moline = new MoLine($this->db);
782
783 $moline->fk_mo = $this->id;
784 $moline->origin_id = $line->id;
785 $moline->origin_type = 'bomline';
786 if (!empty($line->fk_unit)) {
787 $moline->fk_unit = $line->fk_unit;
788 }
789 if ($line->qty_frozen) {
790 $moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce
791 } else {
792 $moline->qty = (float) price2num(($line->qty / (!empty($bom->qty) ? $bom->qty : 1)) * $this->qty / (!empty($line->efficiency) ? $line->efficiency : 1), 'MS'); // Calculate with Qty to produce and more presition
793 }
794 if ($moline->qty <= 0) {
795 $error++;
796 $this->error = "BadValueForquantityToConsume";
797 $this->errors[] = $this->error;
798 break;
799 } else {
800 $moline->fk_product = $line->fk_product;
801 $moline->role = $role;
802 $moline->position = $line->position;
803 $moline->qty_frozen = $line->qty_frozen;
804 $moline->disable_stock_change = $line->disable_stock_change;
805 if (!empty($line->fk_default_workstation)) {
806 $moline->fk_default_workstation = $line->fk_default_workstation;
807 }
808
809 $resultline = $moline->create($user, false); // Never use triggers here
810 if ($resultline <= 0) {
811 $error++;
812 $this->error = $moline->error;
813 $this->errors[] = $moline->error;
814 $this->errors = array_merge($this->errors, $moline->errors);
815 dol_print_error($this->db, $moline->error, $moline->errors);
816 break;
817 }
818 }
819 }
820 }
821 }
822 }
823 }
824
825 if (!$error) {
826 $this->db->commit();
827 return 1;
828 } else {
829 $this->db->rollback();
830 return -1;
831 }
832 }
833
841 public function updateProduction(User $user, $notrigger = 0)
842 {
843 $error = 0;
844
845 if ($this->status != self::STATUS_DRAFT) {
846 return 1;
847 }
848
849 $this->db->begin();
850
851 $oldQty = $this->oldQty;
852 $newQty = $this->qty;
853 if ($newQty != $oldQty && !empty($this->oldQty)) {
854 $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "mrp_production WHERE fk_mo = " . (int) $this->id;
855 $resql = $this->db->query($sql);
856 if ($resql) {
857 while ($obj = $this->db->fetch_object($resql)) {
858 $moLine = new MoLine($this->db);
859 $res = $moLine->fetch($obj->rowid);
860 if (!$res) {
861 $error++;
862 }
863
864 if ($moLine->role == 'toconsume' || $moLine->role == 'toproduce') {
865 if (empty($moLine->qty_frozen)) {
866 $qty = $newQty * $moLine->qty / $oldQty;
867 $moLine->qty = (float) price2num($qty, 'MS');
868 $res = $moLine->update($user);
869 if (!$res) {
870 $error++;
871 }
872 }
873 }
874 }
875 }
876 }
877 if (!$error) {
878 $this->db->commit();
879 return 1;
880 } else {
881 $this->db->rollback();
882 return -1;
883 }
884 }
885
886
895 public function delete(User $user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
896 {
897 $error = 0;
898 $this->db->begin();
899
900 if ($also_cancel_consumed_and_produced_lines) {
901 $result = $this->cancelConsumedAndProducedLines($user, 0, false, $notrigger);
902 if ($result < 0) {
903 $error++;
904 }
905 }
906
907 if (!$error) {
908 $result = $this->deleteCommon($user, $notrigger);
909 if ($result < 0) {
910 $error++;
911 }
912 }
913
914 if ($error) {
915 $this->db->rollback();
916 return -1;
917 } else {
918 $this->db->commit();
919 return 1;
920 }
921 }
922
932 public function deleteLine(User $user, $idline, $notrigger = 0, $fk_movement = 0)
933 {
934 global $langs;
935 $langs->loadLangs(array('stocks', 'mrp'));
936
937 if ($this->status < 0) {
938 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
939 return -2;
940 }
941 $productstatic = new Product($this->db);
942
943 $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete
944
945 $result = 0;
946
947 $this->db->begin();
948
949 if (!empty($arrayoflines)) {
950 // If there is child lines
951 $stockmove = new MouvementStock($this->db);
952 $stockmove->setOrigin($this->element, $this->id);
953
954 if (!empty($fk_movement)) {
955 // The fk_movement was not recorded so we try to guess the product and quantity to restore.
956 $moline = new MoLine($this->db);
957 $TArrayMoLine = $moline->fetchAll('', '', 1, 0, '(fk_stock_movement:=:'.((int) $fk_movement).')');
958 $moline = array_shift($TArrayMoLine);
959
960 $movement = new MouvementStock($this->db);
961 $movement->fetch($fk_movement);
962 $productstatic->fetch($movement->product_id);
963 $qtytoprocess = $movement->qty;
964
965 // Reverse stock movement
966 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
967 $codemovementCancel = $langs->trans("StockIncrease");
968
969 if (($qtytoprocess >= 0)) {
970 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel);
971 } else {
972 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel);
973 }
974 if ($idstockmove < 0) {
975 $this->error++;
976 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
977 } else {
978 $result = $moline->delete($user, $notrigger);
979 }
980 } else {
981 // Loop on each child lines
982 foreach ($arrayoflines as $key => $arrayofline) {
983 $lineDetails = $arrayoflines[$key];
984 $productstatic->fetch($lineDetails['fk_product']);
985 $qtytoprocess = $lineDetails['qty'];
986
987 // Reverse stock movement
988 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
989 $codemovementCancel = $langs->trans("StockIncrease");
990
991
992 if ($qtytoprocess >= 0) {
993 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
994 } else {
995 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
996 }
997 if ($idstockmove < 0) {
998 $this->error++;
999 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
1000 } else {
1001 $moline = new MoLine($this->db);
1002 $moline->fetch($lineDetails['rowid']);
1003
1004 $resdel = $moline->delete($user, $notrigger);
1005 if ($resdel < 0) {
1006 $this->error++;
1007 setEventMessages($moline->error, $moline->errors, 'errors');
1008 }
1009 }
1010 }
1011
1012 if (empty($this->error)) {
1013 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1014 }
1015 }
1016 } else {
1017 // No child lines
1018 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1019 }
1020
1021 if (!empty($this->error) || $result <= 0) {
1022 $this->db->rollback();
1023 } else {
1024 $this->db->commit();
1025 }
1026
1027 return $result;
1028 }
1029
1030
1038 public function getNextNumRef($prod)
1039 {
1040 global $langs, $conf;
1041 $langs->load("mrp");
1042
1043 if (getDolGlobalString('MRP_MO_ADDON')) {
1044 $mybool = false;
1045
1046 $file = getDolGlobalString('MRP_MO_ADDON') . ".php";
1047 $classname = getDolGlobalString('MRP_MO_ADDON');
1048
1049 // Include file with class
1050 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1051 foreach ($dirmodels as $reldir) {
1052 $dir = dol_buildpath($reldir."core/modules/mrp/");
1053
1054 // Load file with numbering class (if found)
1055 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1056 }
1057
1058 if (!$mybool) {
1059 dol_print_error(null, "Failed to include file ".$file);
1060 return '';
1061 }
1062
1063 $obj = new $classname();
1064 $numref = $obj->getNextValue($prod, $this);
1065
1066 if ($numref != "") {
1067 return $numref;
1068 } else {
1069 $this->error = $obj->error;
1070 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1071 return "";
1072 }
1073 } else {
1074 print $langs->trans("Error")." ".$langs->trans("Error_MRP_MO_ADDON_NotDefined");
1075 return "";
1076 }
1077 }
1078
1086 public function validate($user, $notrigger = 0)
1087 {
1088 global $conf;
1089
1090 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1091
1092 $error = 0;
1093
1094 // Protection
1095 if ($this->status == self::STATUS_VALIDATED) {
1096 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
1097 return 0;
1098 }
1099
1100 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->create))
1101 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->mrp_advance->validate))))
1102 {
1103 $this->error='NotEnoughPermissions';
1104 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
1105 return -1;
1106 }*/
1107
1108 $now = dol_now();
1109
1110 $this->db->begin();
1111
1112 // Define new ref
1113 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
1114 $this->fetch_product();
1115 $num = $this->getNextNumRef($this->product);
1116 } else {
1117 $num = $this->ref;
1118 }
1119 $this->newref = $num;
1120
1121 // Validate
1122 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1123 $sql .= " SET ref = '".$this->db->escape($num)."',";
1124 $sql .= " status = ".self::STATUS_VALIDATED.",";
1125 $sql .= " date_valid='".$this->db->idate($now)."',";
1126 $sql .= " fk_user_valid = ".$user->id;
1127 $sql .= " WHERE rowid = ".((int) $this->id);
1128
1129 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
1130 $resql = $this->db->query($sql);
1131 if (!$resql) {
1132 dol_print_error($this->db);
1133 $this->error = $this->db->lasterror();
1134 $error++;
1135 }
1136
1137 if (!$error && !$notrigger) {
1138 // Call trigger
1139 $result = $this->call_trigger('MRP_MO_VALIDATE', $user);
1140 if ($result < 0) {
1141 $error++;
1142 }
1143 // End call triggers
1144 }
1145
1146 if (!$error) {
1147 $this->oldref = $this->ref;
1148
1149 // Rename directory if dir was a temporary ref
1150 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
1151 // Now we rename also files into index
1152 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'mrp/".$this->db->escape($this->newref)."'";
1153 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1154 $resql = $this->db->query($sql);
1155 if (!$resql) {
1156 $error++;
1157 $this->error = $this->db->lasterror();
1158 }
1159 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'mrp/".$this->db->escape($this->newref)."'";
1160 $sql .= " WHERE filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1161 $resql = $this->db->query($sql);
1162 if (!$resql) {
1163 $error++;
1164 $this->error = $this->db->lasterror();
1165 }
1166
1167 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
1168 $oldref = dol_sanitizeFileName($this->ref);
1169 $newref = dol_sanitizeFileName($num);
1170 $dirsource = $conf->mrp->dir_output.'/'.$oldref;
1171 $dirdest = $conf->mrp->dir_output.'/'.$newref;
1172 if (!$error && file_exists($dirsource)) {
1173 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
1174
1175 if (@rename($dirsource, $dirdest)) {
1176 dol_syslog("Rename ok");
1177 // Rename docs starting with $oldref with $newref
1178 $listoffiles = dol_dir_list($conf->mrp->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1179 foreach ($listoffiles as $fileentry) {
1180 $dirsource = $fileentry['name'];
1181 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1182 $dirsource = $fileentry['path'].'/'.$dirsource;
1183 $dirdest = $fileentry['path'].'/'.$dirdest;
1184 @rename($dirsource, $dirdest);
1185 }
1186 }
1187 }
1188 }
1189 }
1190
1191 // Set new ref and current status
1192 if (!$error) {
1193 $this->ref = $num;
1194 $this->status = self::STATUS_VALIDATED;
1195 }
1196
1197 if (!$error) {
1198 $this->db->commit();
1199 return 1;
1200 } else {
1201 $this->db->rollback();
1202 return -1;
1203 }
1204 }
1205
1213 public function setDraft($user, $notrigger = 0)
1214 {
1215 // Protection
1216 if ($this->status <= self::STATUS_DRAFT) {
1217 return 0;
1218 }
1219
1220 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1221 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1222 {
1223 $this->error='Permission denied';
1224 return -1;
1225 }*/
1226
1227 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MRP_MO_UNVALIDATE');
1228 }
1229
1238 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
1239 {
1240 // Protection
1241 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) {
1242 return 0;
1243 }
1244
1245 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1246 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1247 {
1248 $this->error='Permission denied';
1249 return -1;
1250 }*/
1251
1252 $error = 0;
1253 $this->db->begin();
1254
1255 if ($also_cancel_consumed_and_produced_lines) {
1256 $result = $this->cancelConsumedAndProducedLines($user, 0, true, $notrigger);
1257 if ($result < 0) {
1258 $error++;
1259 }
1260 }
1261
1262 if (!$error) {
1263 $result = $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL');
1264 if ($result < 0) {
1265 $error++;
1266 }
1267 }
1268
1269 if ($error) {
1270 $this->db->rollback();
1271 return -1;
1272 } else {
1273 $this->db->commit();
1274 return 1;
1275 }
1276 }
1277
1285 public function reopen($user, $notrigger = 0)
1286 {
1287 // Protection
1288 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) {
1289 return 0;
1290 }
1291
1292 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1293 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1294 {
1295 $this->error='Permission denied';
1296 return -1;
1297 }*/
1298
1299 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MRP_MO_REOPEN');
1300 }
1301
1311 public function cancelConsumedAndProducedLines($user, $mode = 0, $also_delete_lines = false, $notrigger = 0)
1312 {
1313 global $langs;
1314
1315 if (!isModEnabled('stock')) {
1316 return 1;
1317 }
1318
1319 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1320 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
1321 $error = 0;
1322 $langs->load('stocks');
1323
1324 $this->db->begin();
1325
1326 // Cancel consumed lines
1327 if (empty($mode) || $mode == 1) {
1328 $arrayoflines = $this->fetchLinesLinked('consumed');
1329 if (!empty($arrayoflines)) {
1330 foreach ($arrayoflines as $key => $lineDetails) {
1331 $productstatic = new Product($this->db);
1332 $productstatic->fetch($lineDetails['fk_product']);
1333 $qtytoprocess = $lineDetails['qty'];
1334
1335 // Reverse stock movement
1336 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1337 $codemovementCancel = $langs->trans("StockIncrease");
1338
1339 $stockmove = new MouvementStock($this->db);
1340 $stockmove->setOrigin($this->element, $this->id);
1341 if ($qtytoprocess >= 0) {
1342 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1343 } else {
1344 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1345 }
1346 if ($idstockmove < 0) {
1347 $this->error = $stockmove->error;
1348 $this->errors = $stockmove->errors;
1349 $error++;
1350 break;
1351 }
1352
1353 if ($also_delete_lines) {
1354 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1355 if ($result < 0) {
1356 $error++;
1357 break;
1358 }
1359 }
1360 }
1361 }
1362 }
1363
1364 // Cancel produced lines
1365 if (empty($mode) || $mode == 2) {
1366 $arrayoflines = $this->fetchLinesLinked('produced');
1367 if (!empty($arrayoflines)) {
1368 foreach ($arrayoflines as $key => $lineDetails) {
1369 $productstatic = new Product($this->db);
1370 $productstatic->fetch($lineDetails['fk_product']);
1371 $qtytoprocess = $lineDetails['qty'];
1372
1373 // Reverse stock movement
1374 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1375 $codemovementCancel = $langs->trans("StockDecrease");
1376
1377 $stockmove = new MouvementStock($this->db);
1378 $stockmove->setOrigin($this->element, $this->id);
1379 if ($qtytoprocess >= 0) {
1380 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1381 } else {
1382 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1383 }
1384 if ($idstockmove < 0) {
1385 $this->error = $stockmove->error;
1386 $this->errors = $stockmove->errors;
1387 $error++;
1388 break;
1389 }
1390
1391 if ($also_delete_lines) {
1392 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1393 if ($result < 0) {
1394 $error++;
1395 break;
1396 }
1397 }
1398 }
1399 }
1400 }
1401
1402 if ($error) {
1403 $this->db->rollback();
1404 return -1;
1405 } else {
1406 $this->db->commit();
1407 return 1;
1408 }
1409 }
1410
1417 public function getTooltipContentArray($params)
1418 {
1419 global $langs;
1420
1421 $langs->loadLangs(['mrp', 'products']);
1422 $nofetch = isset($params['nofetch']);
1423
1424 $datas = [];
1425
1426 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ManufacturingOrder").'</u>';
1427 if (isset($this->status)) {
1428 $datas['picto'] .= ' '.$this->getLibStatut(5);
1429 }
1430 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1431 if (isset($this->label)) {
1432 $datas['label'] = '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1433 }
1434 if (isset($this->mrptype)) {
1435 $datas['type'] = '<br><b>'.$langs->trans('Type').':</b> '.$this->fields['mrptype']['arrayofkeyval'][$this->mrptype];
1436 }
1437 if (isset($this->qty)) {
1438 $datas['qty'] = '<br><b>'.$langs->trans('QtyToProduce').':</b> '.$this->qty;
1439 }
1440 if (!$nofetch && isset($this->fk_product)) {
1441 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1442 $product = new Product($this->db);
1443 $product->fetch($this->fk_product);
1444 $datas['product'] = '<br><b>'.$langs->trans('Product').':</b> '.$product->getNomUrl(1, '', 0, -1, 1);
1445 }
1446 if (!$nofetch && isset($this->fk_warehouse)) {
1447 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
1448 $warehouse = new Entrepot($this->db);
1449 $warehouse->fetch($this->fk_warehouse);
1450 $datas['warehouse'] = '<br><b>'.$langs->trans('WarehouseForProduction').':</b> '.$warehouse->getNomUrl(1, '', 0, 1);
1451 }
1452
1453 return $datas;
1454 }
1455
1466 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1467 {
1468 global $conf, $langs, $action, $hookmanager;
1469
1470 if (!empty($conf->dol_no_mouse_hover)) {
1471 $notooltip = 1; // Force disable tooltips
1472 }
1473
1474 $result = '';
1475 $params = [
1476 'id' => $this->id,
1477 'objecttype' => $this->element,
1478 'option' => $option,
1479 'nofetch' => 1,
1480 ];
1481 $classfortooltip = 'classfortooltip';
1482 $dataparams = '';
1483 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1484 $classfortooltip = 'classforajaxtooltip';
1485 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1486 $label = '';
1487 } else {
1488 $label = implode($this->getTooltipContentArray($params));
1489 }
1490
1491 $url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$this->id;
1492 if ($option == 'production') {
1493 $url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$this->id;
1494 }
1495
1496 if ($option != 'nolink') {
1497 // Add param to save lastsearch_values or not
1498 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1499 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1500 $add_save_lastsearch_values = 1;
1501 }
1502 if ($add_save_lastsearch_values) {
1503 $url .= '&save_lastsearch_values=1';
1504 }
1505 }
1506
1507 $linkclose = '';
1508 if (empty($notooltip)) {
1509 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1510 $label = $langs->trans("ShowMo");
1511 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1512 }
1513 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1514 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1515 } else {
1516 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1517 }
1518
1519 $linkstart = '<a href="'.$url.'"';
1520 $linkstart .= $linkclose.'>';
1521 $linkend = '</a>';
1522
1523 $result .= $linkstart;
1524 if ($withpicto) {
1525 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
1526 }
1527 if ($withpicto != 2) {
1528 $result .= $this->ref;
1529 }
1530 $result .= $linkend;
1531 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1532
1533 $hookmanager->initHooks(array('modao'));
1534 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1535 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1536 if ($reshook > 0) {
1537 $result = $hookmanager->resPrint;
1538 } else {
1539 $result .= $hookmanager->resPrint;
1540 }
1541
1542 return $result;
1543 }
1544
1551 public function getLibStatut($mode = 0)
1552 {
1553 return $this->LibStatut($this->status, $mode);
1554 }
1555
1556 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1564 public function LibStatut($status, $mode = 0)
1565 {
1566 // phpcs:enable
1567 if (empty($this->labelStatus)) {
1568 global $langs;
1569 //$langs->load("mrp");
1570 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1571 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatedToProduce');
1572 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1573 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1574 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1575
1576 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1577 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1578 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1579 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1580 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1581 }
1582
1583 $statusType = 'status'.$status;
1584 if ($status == self::STATUS_VALIDATED) {
1585 $statusType = 'status1';
1586 }
1587 if ($status == self::STATUS_INPROGRESS) {
1588 $statusType = 'status4';
1589 }
1590 if ($status == self::STATUS_PRODUCED) {
1591 $statusType = 'status6';
1592 }
1593 if ($status == self::STATUS_CANCELED) {
1594 $statusType = 'status9';
1595 }
1596
1597 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1598 }
1599
1606 public function info($id)
1607 {
1608 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1609 $sql .= ' fk_user_creat, fk_user_modif';
1610 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1611 $sql .= ' WHERE t.rowid = '.((int) $id);
1612 $result = $this->db->query($sql);
1613 if ($result) {
1614 if ($this->db->num_rows($result)) {
1615 $obj = $this->db->fetch_object($result);
1616
1617 $this->id = $obj->rowid;
1618
1619 $this->user_creation_id = $obj->fk_user_creat;
1620 $this->user_modification_id = $obj->fk_user_modif;
1621 $this->date_creation = $this->db->jdate($obj->datec);
1622 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1623 }
1624
1625 $this->db->free($result);
1626 } else {
1627 dol_print_error($this->db);
1628 }
1629 }
1630
1637 public function initAsSpecimen()
1638 {
1639 $ret = $this->initAsSpecimenCommon();
1640
1641 $this->lines = array();
1642
1643 return $ret;
1644 }
1645
1652 public function getLinesArray($rolefilter = '')
1653 {
1654 $this->lines = array();
1655
1656 $objectline = new MoLine($this->db);
1657
1658 $filter = '(fk_mo:=:'.((int) $this->id).')';
1659 if (!empty($rolefilter)) {
1660 $filter .= " AND (role:=:'".$this->db->escape($rolefilter)."')";
1661 }
1662 $result = $objectline->fetchAll('ASC', 'position', 0, 0, $filter);
1663
1664 if (is_numeric($result)) {
1665 $this->error = $objectline->error;
1666 $this->errors = $objectline->errors;
1667 return $result;
1668 } else {
1669 $this->lines = $result;
1670 return $this->lines;
1671 }
1672 }
1673
1685 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1686 {
1687 global $langs;
1688
1689 $langs->load("mrp");
1690
1691 if (!dol_strlen($modele)) {
1692 //$modele = 'standard';
1693 $modele = ''; // Remove this once a pdf_standard.php exists.
1694
1695 if ($this->model_pdf) {
1696 $modele = $this->model_pdf;
1697 } elseif (getDolGlobalString('MRP_MO_ADDON_PDF')) {
1698 $modele = getDolGlobalString('MRP_MO_ADDON_PDF');
1699 }
1700 }
1701
1702 $modelpath = "core/modules/mrp/doc/";
1703
1704 if (empty($modele)) {
1705 return 1; // Remove this once a pdf_standard.php exists.
1706 }
1707
1708 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1709 }
1710
1721 public function printOriginLinesList($restrictlist = '', $selectedLines = array())
1722 {
1723 global $langs, $hookmanager, $form, $action;
1724
1725 $langs->load('stocks');
1726 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
1727 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
1728 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
1729 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
1730 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
1731 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
1732 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
1733 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
1734 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
1735
1736 print '<tr class="liste_titre">';
1737 // Product or sub-bom
1738 print '<td class="linecoldescription">'.$langs->trans('Ref');
1739 if (getDolGlobalString('BOM_SUB_BOM')) {
1740 print ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
1741 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
1742 }
1743 print '</td>';
1744 // Qty
1745 print '<td class="right">'.$langs->trans('Qty');
1746 if ($this->bom->bomtype == 0) {
1747 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", $this->bom->qty).')</span>';
1748 } else {
1749 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", $this->bom->qty).')</span>';
1750 }
1751 // Unit
1752 print '<td class="right">'.$langs->trans('Unit');
1753
1754 print '</td>';
1755 print '<td class="center">'.$form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1).'</td>';
1756 print '<td class="center">'.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).'</td>';
1757 print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
1758 print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
1759 print '<td class="center">'.$langs->trans('MoChildGenerate').'</td>';
1760 //print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
1761 //print '<td class="center"></td>';
1762 print '</tr>';
1763 $i = 0;
1764
1765 if (!empty($this->lines)) {
1766 foreach ($this->lines as $line) {
1767 $reshook = 0;
1768 if (is_object($hookmanager)) {
1769 $parameters = array('line' => $line, 'i' => $i, 'restrictlist' => $restrictlist, 'selectedLines' => $selectedLines);
1770 if (!empty($line->fk_parent_line)) {
1771 $parameters['fk_parent_line'] = $line->fk_parent_line;
1772 }
1773 $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1774 }
1775 if (empty($reshook)) {
1776 $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
1777 }
1778
1779 $i++;
1780 }
1781 }
1782 }
1783
1784
1798 public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array())
1799 {
1800 if (!$line instanceof MoLine) {
1801 dol_syslog(__METHOD__.'::pringOriginLine $line is '.get_class($line).'<>MoLine', LOG_WARNING);
1802 parent::printOriginLine($line, $var, $restrictlist, $defaulttpldir, $selectedLines);
1803 return;
1804 }
1805 $productstatic = new Product($this->db);
1806
1807 $this->tpl['id'] = $line->id;
1808
1809 $this->tpl['label'] = '';
1810 if (!empty($line->fk_product) && $line->fk_product > 0) {
1811 $productstatic->fetch($line->fk_product);
1812 $productstatic->load_virtual_stock();
1813 $this->tpl['label'] .= $productstatic->getNomUrl(1);
1814 //$this->tpl['label'].= ' - '.$productstatic->label;
1815 } else {
1816 // If origin MO line is not a product, but another MO
1817 // TODO
1818 }
1819
1820 $this->tpl['qty_bom'] = 1;
1821 if (is_object($this->bom) && $this->bom->qty > 1) {
1822 $this->tpl['qty_bom'] = $this->bom->qty;
1823 }
1824
1825 $this->tpl['stock'] = $productstatic->stock_reel;
1826 $this->tpl['seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1827 $this->tpl['virtual_stock'] = $productstatic->stock_theorique;
1828 $this->tpl['qty'] = $line->qty;
1829 $this->tpl['fk_unit'] = $line->fk_unit;
1830 $this->tpl['qty_frozen'] = $line->qty_frozen;
1831 $this->tpl['disable_stock_change'] = $line->disable_stock_change;
1832 $this->tpl['efficiency'] = $line->efficiency;
1833
1834 global $conf; // used into template
1835 $res = include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php';
1836 }
1837
1846 public static function replaceThirdparty($db, $origin_id, $dest_id)
1847 {
1848 $tables = array('mrp_mo');
1849
1850 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1851 }
1852
1853
1859 public function getMoChilds()
1860 {
1861 $TMoChilds = array();
1862 $error = 0;
1863
1864 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child";
1865 $sql .= " WHERE fk_parent_line IN ";
1866 $sql .= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent";
1867 $sql .= " WHERE fk_mo=".((int) $this->id).")";
1868
1869 $resql = $this->db->query($sql);
1870
1871 if ($resql) {
1872 if ($this->db->num_rows($resql) > 0) {
1873 while ($obj = $this->db->fetch_object($resql)) {
1874 $MoChild = new Mo($this->db);
1875 $res = $MoChild->fetch($obj->rowid);
1876 if ($res > 0) {
1877 $TMoChilds[$MoChild->id] = $MoChild;
1878 } else {
1879 $error++;
1880 }
1881 }
1882 }
1883 } else {
1884 $error++;
1885 }
1886
1887 if ($error) {
1888 return -1;
1889 } else {
1890 return $TMoChilds;
1891 }
1892 }
1893
1900 public function getAllMoChilds($depth = 0)
1901 {
1902 if ($depth > 1000) {
1903 return -1;
1904 }
1905
1906 $TMoChilds = array();
1907 $error = 0;
1908
1909 $childMoList = $this->getMoChilds();
1910
1911 if ($childMoList == -1) {
1912 return -1;
1913 }
1914
1915 foreach ($childMoList as $childMo) {
1916 $TMoChilds[$childMo->id] = $childMo;
1917 }
1918
1919 foreach ($childMoList as $childMo) {
1920 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1921
1922 if ($childMoChildren == -1) {
1923 $error++;
1924 } else {
1925 foreach ($childMoChildren as $child) {
1926 $TMoChilds[$child->id] = $child;
1927 }
1928 }
1929 }
1930
1931 if ($error) {
1932 return -1;
1933 } else {
1934 return $TMoChilds;
1935 }
1936 }
1937
1938
1939
1945 public function getMoParent()
1946 {
1947 $MoParent = new Mo($this->db);
1948 $error = 0;
1949
1950 $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo";
1951 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1952 $sql .= " WHERE mo.rowid = ".((int) $this->id);
1953
1954 $resql = $this->db->query($sql);
1955
1956 if ($resql) {
1957 if ($this->db->num_rows($resql) > 0) {
1958 $obj = $this->db->fetch_object($resql);
1959 $res = $MoParent->fetch($obj->id_moparent);
1960 if ($res < 0) {
1961 $error++;
1962 }
1963 } else {
1964 return 0;
1965 }
1966 } else {
1967 $error++;
1968 }
1969
1970 if ($error) {
1971 return -1;
1972 } else {
1973 return $MoParent;
1974 }
1975 }
1976
1984 public function getKanbanView($option = '', $arraydata = null)
1985 {
1986 global $langs;
1987
1988 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1989
1990 $return = '<div class="box-flex-item box-flex-grow-zero">';
1991 $return .= '<div class="info-box info-box-sm">';
1992 $return .= '<span class="info-box-icon bg-infobox-action">';
1993 $return .= img_picto('', $this->picto);
1994 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
1995 $return .= '</span>';
1996 $return .= '<div class="info-box-content">';
1997 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1998 if ($selected >= 0) {
1999 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2000 }
2001 if (!empty($arraydata['bom'])) {
2002 $return .= '<br><span class="info-box-label">'.$arraydata['bom']->getNomUrl(1).'</span>';
2003 }
2004 if (!empty($arraydata['product'])) {
2005 $return .= '<br><span class="info-box-label">'.$arraydata['product']->getNomUrl(1).'</span>';
2006 if (property_exists($this, 'qty')) {
2007 $return .= ' <span class="info-box-label">('.$langs->trans("Qty").' '.$this->qty.')</span>';
2008 }
2009 } else {
2010 if (property_exists($this, 'qty')) {
2011 $return .= '<br><span class="info-box-label">'.$langs->trans('Quantity').' : '.$this->qty.'</span>';
2012 }
2013 }
2014 if (method_exists($this, 'getLibStatut')) {
2015 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2016 }
2017 $return .= '</div>';
2018 $return .= '</div>';
2019 $return .= '</div>';
2020 return $return;
2021 }
2022}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:640
$object ref
Definition info.php:79
Class for BOM.
Definition bom.class.php:45
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetch_product()
Load the product with id $this->fk_product into this->product.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the 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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage warehouses.
Class for Mo.
Definition mo.class.php:34
__construct(DoliDB $db)
Constructor.
Definition mo.class.php:279
fetchLinesLinked($role, $lineid=0)
Get list of lines linked to current line for a defined role.
Definition mo.class.php:601
getMoChilds()
Function used to return children of Mo.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
printOriginLinesList($restrictlist='', $selectedLines=array())
Return HTML table table of source object lines TODO Move this and previous function into output html ...
fetchLines()
Load object lines in memory from the database.
Definition mo.class.php:497
getNextNumRef($prod)
Returns the reference to the following non used MO depending on the active numbering module defined i...
create(User $user, $notrigger=0)
Create object into database.
Definition mo.class.php:319
fetch($id, $ref=null)
Load object in memory from the database.
Definition mo.class.php:480
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
Definition mo.class.php:517
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
reopen($user, $notrigger=0)
Set back to validated status.
getMoParent()
Function used to return children of Mo.
getLinesArray($rolefilter='')
Create an array of lines.
updateProduction(User $user, $notrigger=0)
Update quantities in lines to consume and/or lines to produce.
Definition mo.class.php:841
LibStatut($status, $mode=0)
Return the status.
cancel($user, $notrigger=0, $also_cancel_consumed_and_produced_lines=false)
Set cancel status.
setDraft($user, $notrigger=0)
Set draft status.
printOriginLine($line, $var, $restrictlist='', $defaulttpldir='/core/tpl', $selectedLines=array())
Return HTML with a line of table array of source object lines TODO Move this and previous function in...
update(User $user, $notrigger=0)
Update object into database.
Definition mo.class.php:688
getAllMoChilds($depth=0)
Function used to return all child MOs recursively.
createProduction(User $user, $notrigger=0)
Erase and update the line to consume and to produce.
Definition mo.class.php:722
deleteLine(User $user, $idline, $notrigger=0, $fk_movement=0)
Delete a line of object in database.
Definition mo.class.php:932
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
validate($user, $notrigger=0)
Validate Mo.
cancelConsumedAndProducedLines($user, $mode=0, $also_delete_lines=false, $notrigger=0)
Cancel consumed and produced lines (movement stocks)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getTooltipContentArray($params)
getTooltipContentArray
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
getLibStatut($mode=0)
Return label of the status.
info($id)
Load the info information in the object.
countMovements()
Count number of movement with origin of MO.
Definition mo.class.php:653
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition mo.class.php:377
Class MoLine.
Class to manage stock movements.
Class to manage products or services.
Class to manage Dolibarr users.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.