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