dolibarr 21.0.0-beta
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
746 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
747 $tmpproduct = new Product($this->db);
748 $tmpproduct->fetch($this->fk_product);
749 $moline->fk_unit = $tmpproduct->fk_unit;
750
751 if ($this->fk_bom > 0) { // If a BOM is defined, we know what to produce.
752 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
753 $bom = new BOM($this->db);
754 $bom->fetch($this->fk_bom);
755 if ($bom->bomtype == 1) {
756 $role = 'toproduce';
757 $moline->role = 'toconsume';
758 } else {
759 $role = 'toconsume';
760 $moline->role = 'toproduce';
761 }
762 } else {
763 $bom = null;
764 if ($this->mrptype == 1) {
765 $moline->role = 'toconsume';
766 } else {
767 $moline->role = 'toproduce';
768 }
769 }
770
771 $resultline = $moline->create($user, false); // Never use triggers here
772 if ($resultline <= 0) {
773 $error++;
774 $this->error = $moline->error;
775 $this->errors = $moline->errors;
776 }
777
778 if ($this->fk_bom > 0 && is_object($bom)) { // If a BOM is defined, we know what to consume.
779 if ($bom->id > 0) {
780 // Lines to consume
781 if (!$error) {
782 foreach ($bom->lines as $line) {
783 $moline = new MoLine($this->db);
784
785 $moline->fk_mo = $this->id;
786 $moline->origin_id = $line->id;
787 $moline->origin_type = 'bomline';
788 if (!empty($line->fk_unit)) {
789 $moline->fk_unit = $line->fk_unit;
790 }
791 if ($line->qty_frozen) {
792 $moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce
793 } else {
794 $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
795 }
796 if ($moline->qty <= 0) {
797 $error++;
798 $this->error = "BadValueForquantityToConsume";
799 $this->errors[] = $this->error;
800 break;
801 } else {
802 $moline->fk_product = $line->fk_product;
803 $moline->role = $role;
804 $moline->position = $line->position;
805 $moline->qty_frozen = $line->qty_frozen;
806 $moline->disable_stock_change = $line->disable_stock_change;
807 if (!empty($line->fk_default_workstation)) {
808 $moline->fk_default_workstation = $line->fk_default_workstation;
809 }
810
811 $resultline = $moline->create($user, false); // Never use triggers here
812 if ($resultline <= 0) {
813 $error++;
814 $this->error = $moline->error;
815 $this->errors[] = $moline->error;
816 $this->errors = array_merge($this->errors, $moline->errors);
817 dol_print_error($this->db, $moline->error, $moline->errors);
818 break;
819 }
820 }
821 }
822 }
823 }
824 }
825 }
826
827 if (!$error) {
828 $this->db->commit();
829 return 1;
830 } else {
831 $this->db->rollback();
832 return -1;
833 }
834 }
835
843 public function updateProduction(User $user, $notrigger = 0)
844 {
845 $error = 0;
846
847 if ($this->status != self::STATUS_DRAFT) {
848 return 1;
849 }
850
851 $this->db->begin();
852
853 $oldQty = $this->oldQty;
854 $newQty = $this->qty;
855 if ($newQty != $oldQty && !empty($this->oldQty)) {
856 $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "mrp_production WHERE fk_mo = " . (int) $this->id;
857 $resql = $this->db->query($sql);
858 if ($resql) {
859 while ($obj = $this->db->fetch_object($resql)) {
860 $moLine = new MoLine($this->db);
861 $res = $moLine->fetch($obj->rowid);
862 if (!$res) {
863 $error++;
864 }
865
866 if ($moLine->role == 'toconsume' || $moLine->role == 'toproduce') {
867 if (empty($moLine->qty_frozen)) {
868 $qty = $newQty * $moLine->qty / $oldQty;
869 $moLine->qty = (float) price2num($qty, 'MS');
870 $res = $moLine->update($user);
871 if (!$res) {
872 $error++;
873 }
874 }
875 }
876 }
877 }
878 }
879 if (!$error) {
880 $this->db->commit();
881 return 1;
882 } else {
883 $this->db->rollback();
884 return -1;
885 }
886 }
887
888
897 public function delete(User $user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
898 {
899 $error = 0;
900 $this->db->begin();
901
902 if ($also_cancel_consumed_and_produced_lines) {
903 $result = $this->cancelConsumedAndProducedLines($user, 0, false, $notrigger);
904 if ($result < 0) {
905 $error++;
906 }
907 }
908
909 if (!$error) {
910 $result = $this->deleteCommon($user, $notrigger);
911 if ($result < 0) {
912 $error++;
913 }
914 }
915
916 if ($error) {
917 $this->db->rollback();
918 return -1;
919 } else {
920 $this->db->commit();
921 return 1;
922 }
923 }
924
934 public function deleteLine(User $user, $idline, $notrigger = 0, $fk_movement = 0)
935 {
936 global $langs;
937 $langs->loadLangs(array('stocks', 'mrp'));
938
939 if ($this->status < 0) {
940 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
941 return -2;
942 }
943 $productstatic = new Product($this->db);
944
945 $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete
946
947 $result = 0;
948
949 $this->db->begin();
950
951 if (!empty($arrayoflines)) {
952 // If there is child lines
953 $stockmove = new MouvementStock($this->db);
954 $stockmove->setOrigin($this->element, $this->id);
955
956 if (!empty($fk_movement)) {
957 // The fk_movement was not recorded so we try to guess the product and quantity to restore.
958 $moline = new MoLine($this->db);
959 $TArrayMoLine = $moline->fetchAll('', '', 1, 0, '(fk_stock_movement:=:'.((int) $fk_movement).')');
960 $moline = array_shift($TArrayMoLine);
961
962 $movement = new MouvementStock($this->db);
963 $movement->fetch($fk_movement);
964 $productstatic->fetch($movement->product_id);
965 $qtytoprocess = $movement->qty;
966
967 // Reverse stock movement
968 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
969 $codemovementCancel = $langs->trans("StockIncrease");
970
971 if (($qtytoprocess >= 0)) {
972 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel);
973 } else {
974 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel);
975 }
976 if ($idstockmove < 0) {
977 $this->error++;
978 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
979 } else {
980 $result = $moline->delete($user, $notrigger);
981 }
982 } else {
983 // Loop on each child lines
984 foreach ($arrayoflines as $key => $arrayofline) {
985 $lineDetails = $arrayoflines[$key];
986 $productstatic->fetch($lineDetails['fk_product']);
987 $qtytoprocess = $lineDetails['qty'];
988
989 // Reverse stock movement
990 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
991 $codemovementCancel = $langs->trans("StockIncrease");
992
993
994 if ($qtytoprocess >= 0) {
995 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
996 } else {
997 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
998 }
999 if ($idstockmove < 0) {
1000 $this->error++;
1001 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
1002 } else {
1003 $moline = new MoLine($this->db);
1004 $moline->fetch($lineDetails['rowid']);
1005
1006 $resdel = $moline->delete($user, $notrigger);
1007 if ($resdel < 0) {
1008 $this->error++;
1009 setEventMessages($moline->error, $moline->errors, 'errors');
1010 }
1011 }
1012 }
1013
1014 if (empty($this->error)) {
1015 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1016 }
1017 }
1018 } else {
1019 // No child lines
1020 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1021 }
1022
1023 if (!empty($this->error) || $result <= 0) {
1024 $this->db->rollback();
1025 } else {
1026 $this->db->commit();
1027 }
1028
1029 return $result;
1030 }
1031
1032
1040 public function getNextNumRef($prod)
1041 {
1042 global $langs, $conf;
1043 $langs->load("mrp");
1044
1045 if (getDolGlobalString('MRP_MO_ADDON')) {
1046 $mybool = false;
1047
1048 $file = getDolGlobalString('MRP_MO_ADDON') . ".php";
1049 $classname = getDolGlobalString('MRP_MO_ADDON');
1050
1051 // Include file with class
1052 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1053 foreach ($dirmodels as $reldir) {
1054 $dir = dol_buildpath($reldir."core/modules/mrp/");
1055
1056 // Load file with numbering class (if found)
1057 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1058 }
1059
1060 if (!$mybool) {
1061 dol_print_error(null, "Failed to include file ".$file);
1062 return '';
1063 }
1064
1065 $obj = new $classname();
1066 '@phan-var-force ModeleNumRefMos $obj';
1067 $numref = $obj->getNextValue($prod, $this);
1068
1069 if ($numref != "") {
1070 return $numref;
1071 } else {
1072 $this->error = $obj->error;
1073 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1074 return "";
1075 }
1076 } else {
1077 print $langs->trans("Error")." ".$langs->trans("Error_MRP_MO_ADDON_NotDefined");
1078 return "";
1079 }
1080 }
1081
1089 public function validate($user, $notrigger = 0)
1090 {
1091 global $conf;
1092
1093 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1094
1095 $error = 0;
1096
1097 // Protection
1098 if ($this->status == self::STATUS_VALIDATED) {
1099 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
1100 return 0;
1101 }
1102
1103 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->create))
1104 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->mrp_advance->validate))))
1105 {
1106 $this->error='NotEnoughPermissions';
1107 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
1108 return -1;
1109 }*/
1110
1111 $now = dol_now();
1112
1113 $this->db->begin();
1114
1115 // Define new ref
1116 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
1117 $this->fetch_product();
1118 $num = $this->getNextNumRef($this->product);
1119 } else {
1120 $num = $this->ref;
1121 }
1122 $this->newref = $num;
1123
1124 // Validate
1125 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1126 $sql .= " SET ref = '".$this->db->escape($num)."',";
1127 $sql .= " status = ".self::STATUS_VALIDATED.",";
1128 $sql .= " date_valid = '".$this->db->idate($now)."',";
1129 $sql .= " fk_user_valid = ".((int) $user->id);
1130 $sql .= " WHERE rowid = ".((int) $this->id);
1131
1132 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
1133 $resql = $this->db->query($sql);
1134 if (!$resql) {
1135 dol_print_error($this->db);
1136 $this->error = $this->db->lasterror();
1137 $error++;
1138 }
1139
1140 if (!$error && !$notrigger) {
1141 // Call trigger
1142 $result = $this->call_trigger('MRP_MO_VALIDATE', $user);
1143 if ($result < 0) {
1144 $error++;
1145 }
1146 // End call triggers
1147 }
1148
1149 if (!$error) {
1150 $this->oldref = $this->ref;
1151
1152 // Rename directory if dir was a temporary ref
1153 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
1154 // Now we rename also files into index
1155 $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)."'";
1156 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1157 $resql = $this->db->query($sql);
1158 if (!$resql) {
1159 $error++;
1160 $this->error = $this->db->lasterror();
1161 }
1162 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'mrp/".$this->db->escape($this->newref)."'";
1163 $sql .= " WHERE filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1164 $resql = $this->db->query($sql);
1165 if (!$resql) {
1166 $error++;
1167 $this->error = $this->db->lasterror();
1168 }
1169
1170 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
1171 $oldref = dol_sanitizeFileName($this->ref);
1172 $newref = dol_sanitizeFileName($num);
1173 $dirsource = $conf->mrp->dir_output.'/'.$oldref;
1174 $dirdest = $conf->mrp->dir_output.'/'.$newref;
1175 if (!$error && file_exists($dirsource)) {
1176 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
1177
1178 if (@rename($dirsource, $dirdest)) {
1179 dol_syslog("Rename ok");
1180 // Rename docs starting with $oldref with $newref
1181 $listoffiles = dol_dir_list($conf->mrp->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1182 foreach ($listoffiles as $fileentry) {
1183 $dirsource = $fileentry['name'];
1184 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1185 $dirsource = $fileentry['path'].'/'.$dirsource;
1186 $dirdest = $fileentry['path'].'/'.$dirdest;
1187 @rename($dirsource, $dirdest);
1188 }
1189 }
1190 }
1191 }
1192 }
1193
1194 // Set new ref and current status
1195 if (!$error) {
1196 $this->ref = $num;
1197 $this->status = self::STATUS_VALIDATED;
1198 }
1199
1200 if (!$error) {
1201 $this->db->commit();
1202 return 1;
1203 } else {
1204 $this->db->rollback();
1205 return -1;
1206 }
1207 }
1208
1216 public function setDraft($user, $notrigger = 0)
1217 {
1218 // Protection
1219 if ($this->status <= self::STATUS_DRAFT) {
1220 return 0;
1221 }
1222
1223 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1224 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1225 {
1226 $this->error='Permission denied';
1227 return -1;
1228 }*/
1229
1230 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MRP_MO_UNVALIDATE');
1231 }
1232
1241 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
1242 {
1243 // Protection
1244 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) {
1245 return 0;
1246 }
1247
1248 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1249 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1250 {
1251 $this->error='Permission denied';
1252 return -1;
1253 }*/
1254
1255 $error = 0;
1256 $this->db->begin();
1257
1258 if ($also_cancel_consumed_and_produced_lines) {
1259 $result = $this->cancelConsumedAndProducedLines($user, 0, true, $notrigger);
1260 if ($result < 0) {
1261 $error++;
1262 }
1263 }
1264
1265 if (!$error) {
1266 $result = $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL');
1267 if ($result < 0) {
1268 $error++;
1269 }
1270 }
1271
1272 if ($error) {
1273 $this->db->rollback();
1274 return -1;
1275 } else {
1276 $this->db->commit();
1277 return 1;
1278 }
1279 }
1280
1288 public function reopen($user, $notrigger = 0)
1289 {
1290 // Protection
1291 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) {
1292 return 0;
1293 }
1294
1295 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1296 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1297 {
1298 $this->error='Permission denied';
1299 return -1;
1300 }*/
1301
1302 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MRP_MO_REOPEN');
1303 }
1304
1314 public function cancelConsumedAndProducedLines($user, $mode = 0, $also_delete_lines = false, $notrigger = 0)
1315 {
1316 global $langs;
1317
1318 if (!isModEnabled('stock')) {
1319 return 1;
1320 }
1321
1322 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1323 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
1324 $error = 0;
1325 $langs->load('stocks');
1326
1327 $this->db->begin();
1328
1329 // Cancel consumed lines
1330 if (empty($mode) || $mode == 1) {
1331 $arrayoflines = $this->fetchLinesLinked('consumed');
1332 if (!empty($arrayoflines)) {
1333 foreach ($arrayoflines as $key => $lineDetails) {
1334 $productstatic = new Product($this->db);
1335 $productstatic->fetch($lineDetails['fk_product']);
1336 $qtytoprocess = $lineDetails['qty'];
1337
1338 // Reverse stock movement
1339 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1340 $codemovementCancel = $langs->trans("StockIncrease");
1341
1342 $stockmove = new MouvementStock($this->db);
1343 $stockmove->setOrigin($this->element, $this->id);
1344 if ($qtytoprocess >= 0) {
1345 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1346 } else {
1347 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1348 }
1349 if ($idstockmove < 0) {
1350 $this->error = $stockmove->error;
1351 $this->errors = $stockmove->errors;
1352 $error++;
1353 break;
1354 }
1355
1356 if ($also_delete_lines) {
1357 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1358 if ($result < 0) {
1359 $error++;
1360 break;
1361 }
1362 }
1363 }
1364 }
1365 }
1366
1367 // Cancel produced lines
1368 if (empty($mode) || $mode == 2) {
1369 $arrayoflines = $this->fetchLinesLinked('produced');
1370 if (!empty($arrayoflines)) {
1371 foreach ($arrayoflines as $key => $lineDetails) {
1372 $productstatic = new Product($this->db);
1373 $productstatic->fetch($lineDetails['fk_product']);
1374 $qtytoprocess = $lineDetails['qty'];
1375
1376 // Reverse stock movement
1377 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1378 $codemovementCancel = $langs->trans("StockDecrease");
1379
1380 $stockmove = new MouvementStock($this->db);
1381 $stockmove->setOrigin($this->element, $this->id);
1382 if ($qtytoprocess >= 0) {
1383 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1384 } else {
1385 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1386 }
1387 if ($idstockmove < 0) {
1388 $this->error = $stockmove->error;
1389 $this->errors = $stockmove->errors;
1390 $error++;
1391 break;
1392 }
1393
1394 if ($also_delete_lines) {
1395 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1396 if ($result < 0) {
1397 $error++;
1398 break;
1399 }
1400 }
1401 }
1402 }
1403 }
1404
1405 if ($error) {
1406 $this->db->rollback();
1407 return -1;
1408 } else {
1409 $this->db->commit();
1410 return 1;
1411 }
1412 }
1413
1420 public function getTooltipContentArray($params)
1421 {
1422 global $langs;
1423
1424 $langs->loadLangs(['mrp', 'products']);
1425 $nofetch = isset($params['nofetch']);
1426
1427 $datas = [];
1428
1429 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ManufacturingOrder").'</u>';
1430 if (isset($this->status)) {
1431 $datas['picto'] .= ' '.$this->getLibStatut(5);
1432 }
1433 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1434 if (isset($this->label)) {
1435 $datas['label'] = '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1436 }
1437 if (isset($this->mrptype)) {
1438 $datas['type'] = '<br><b>'.$langs->trans('Type').':</b> '.$this->fields['mrptype']['arrayofkeyval'][$this->mrptype];
1439 }
1440 if (isset($this->qty)) {
1441 $datas['qty'] = '<br><b>'.$langs->trans('QtyToProduce').':</b> '.$this->qty;
1442 }
1443 if (!$nofetch && isset($this->fk_product)) {
1444 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1445 $product = new Product($this->db);
1446 $product->fetch($this->fk_product);
1447 $datas['product'] = '<br><b>'.$langs->trans('Product').':</b> '.$product->getNomUrl(1, '', 0, -1, 1);
1448 }
1449 if (!$nofetch && isset($this->fk_warehouse)) {
1450 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
1451 $warehouse = new Entrepot($this->db);
1452 $warehouse->fetch($this->fk_warehouse);
1453 $datas['warehouse'] = '<br><b>'.$langs->trans('WarehouseForProduction').':</b> '.$warehouse->getNomUrl(1, '', 0, 1);
1454 }
1455
1456 return $datas;
1457 }
1458
1469 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1470 {
1471 global $conf, $langs, $action, $hookmanager;
1472
1473 if (!empty($conf->dol_no_mouse_hover)) {
1474 $notooltip = 1; // Force disable tooltips
1475 }
1476
1477 $result = '';
1478 $params = [
1479 'id' => $this->id,
1480 'objecttype' => $this->element,
1481 'option' => $option,
1482 'nofetch' => 1,
1483 ];
1484 $classfortooltip = 'classfortooltip';
1485 $dataparams = '';
1486 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1487 $classfortooltip = 'classforajaxtooltip';
1488 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1489 $label = '';
1490 } else {
1491 $label = implode($this->getTooltipContentArray($params));
1492 }
1493
1494 $url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$this->id;
1495 if ($option == 'production') {
1496 $url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$this->id;
1497 }
1498
1499 if ($option != 'nolink') {
1500 // Add param to save lastsearch_values or not
1501 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1502 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1503 $add_save_lastsearch_values = 1;
1504 }
1505 if ($add_save_lastsearch_values) {
1506 $url .= '&save_lastsearch_values=1';
1507 }
1508 }
1509
1510 $linkclose = '';
1511 if (empty($notooltip)) {
1512 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1513 $label = $langs->trans("ShowMo");
1514 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1515 }
1516 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1517 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1518 } else {
1519 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1520 }
1521
1522 $linkstart = '<a href="'.$url.'"';
1523 $linkstart .= $linkclose.'>';
1524 $linkend = '</a>';
1525
1526 $result .= $linkstart;
1527 if ($withpicto) {
1528 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
1529 }
1530 if ($withpicto != 2) {
1531 $result .= $this->ref;
1532 }
1533 $result .= $linkend;
1534 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1535
1536 $hookmanager->initHooks(array('modao'));
1537 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1538 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1539 if ($reshook > 0) {
1540 $result = $hookmanager->resPrint;
1541 } else {
1542 $result .= $hookmanager->resPrint;
1543 }
1544
1545 return $result;
1546 }
1547
1554 public function getLibStatut($mode = 0)
1555 {
1556 return $this->LibStatut($this->status, $mode);
1557 }
1558
1559 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1567 public function LibStatut($status, $mode = 0)
1568 {
1569 // phpcs:enable
1570 if (empty($this->labelStatus)) {
1571 global $langs;
1572 //$langs->load("mrp");
1573 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1574 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatedToProduce');
1575 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1576 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1577 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1578
1579 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1580 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1581 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1582 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1583 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1584 }
1585
1586 $statusType = 'status'.$status;
1587 if ($status == self::STATUS_VALIDATED) {
1588 $statusType = 'status1';
1589 }
1590 if ($status == self::STATUS_INPROGRESS) {
1591 $statusType = 'status4';
1592 }
1593 if ($status == self::STATUS_PRODUCED) {
1594 $statusType = 'status6';
1595 }
1596 if ($status == self::STATUS_CANCELED) {
1597 $statusType = 'status9';
1598 }
1599
1600 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1601 }
1602
1609 public function info($id)
1610 {
1611 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1612 $sql .= ' fk_user_creat, fk_user_modif';
1613 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1614 $sql .= ' WHERE t.rowid = '.((int) $id);
1615 $result = $this->db->query($sql);
1616 if ($result) {
1617 if ($this->db->num_rows($result)) {
1618 $obj = $this->db->fetch_object($result);
1619
1620 $this->id = $obj->rowid;
1621
1622 $this->user_creation_id = $obj->fk_user_creat;
1623 $this->user_modification_id = $obj->fk_user_modif;
1624 $this->date_creation = $this->db->jdate($obj->datec);
1625 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1626 }
1627
1628 $this->db->free($result);
1629 } else {
1630 dol_print_error($this->db);
1631 }
1632 }
1633
1640 public function initAsSpecimen()
1641 {
1642 $ret = $this->initAsSpecimenCommon();
1643
1644 $this->lines = array();
1645
1646 return $ret;
1647 }
1648
1655 public function getLinesArray($rolefilter = '')
1656 {
1657 $this->lines = array();
1658
1659 $objectline = new MoLine($this->db);
1660
1661 $filter = '(fk_mo:=:'.((int) $this->id).')';
1662 if (!empty($rolefilter)) {
1663 $filter .= " AND (role:=:'".$this->db->escape($rolefilter)."')";
1664 }
1665 $result = $objectline->fetchAll('ASC', 'position', 0, 0, $filter);
1666
1667 if (is_numeric($result)) {
1668 $this->error = $objectline->error;
1669 $this->errors = $objectline->errors;
1670 return $result;
1671 } else {
1672 $this->lines = $result;
1673 return $this->lines;
1674 }
1675 }
1676
1688 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1689 {
1690 global $langs;
1691
1692 $langs->load("mrp");
1693
1694 if (!dol_strlen($modele)) {
1695 //$modele = 'standard';
1696 $modele = ''; // Remove this once a pdf_standard.php exists.
1697
1698 if ($this->model_pdf) {
1699 $modele = $this->model_pdf;
1700 } elseif (getDolGlobalString('MRP_MO_ADDON_PDF')) {
1701 $modele = getDolGlobalString('MRP_MO_ADDON_PDF');
1702 }
1703 }
1704
1705 $modelpath = "core/modules/mrp/doc/";
1706
1707 if (empty($modele)) {
1708 return 1; // Remove this once a pdf_standard.php exists.
1709 }
1710
1711 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1712 }
1713
1724 public function printOriginLinesList($restrictlist = '', $selectedLines = array())
1725 {
1726 global $langs, $hookmanager, $form, $action;
1727
1728 $langs->load('stocks');
1729 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
1730 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
1731 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
1732 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
1733 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
1734 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
1735 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
1736 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
1737 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
1738
1739 print '<tr class="liste_titre">';
1740 // Product or sub-bom
1741 print '<td class="linecoldescription">'.$langs->trans('Ref');
1742 if (getDolGlobalString('BOM_SUB_BOM')) {
1743 print ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
1744 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
1745 }
1746 print '</td>';
1747 // Qty
1748 print '<td class="right">'.$langs->trans('Qty');
1749 if ($this->bom->bomtype == 0) {
1750 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", $this->bom->qty).')</span>';
1751 } else {
1752 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", $this->bom->qty).')</span>';
1753 }
1754 // Unit
1755 print '<td class="right">'.$langs->trans('Unit');
1756
1757 print '</td>';
1758 print '<td class="center">'.$form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1).'</td>';
1759 print '<td class="center">'.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).'</td>';
1760 print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
1761 print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
1762 print '<td class="center">'.$langs->trans('MoChildGenerate').'</td>';
1763 //print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
1764 //print '<td class="center"></td>';
1765 print '</tr>';
1766 $i = 0;
1767
1768 if (!empty($this->lines)) {
1769 foreach ($this->lines as $line) {
1770 $reshook = 0;
1771 if (is_object($hookmanager)) {
1772 $parameters = array('line' => $line, 'i' => $i, 'restrictlist' => $restrictlist, 'selectedLines' => $selectedLines);
1773 if (!empty($line->fk_parent_line)) {
1774 $parameters['fk_parent_line'] = $line->fk_parent_line;
1775 }
1776 $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1777 }
1778 if (empty($reshook)) {
1779 $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
1780 }
1781
1782 $i++;
1783 }
1784 }
1785 }
1786
1787
1801 public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array())
1802 {
1803 if (!$line instanceof MoLine) {
1804 dol_syslog(__METHOD__.'::pringOriginLine $line is '.get_class($line).'<>MoLine', LOG_WARNING);
1805 parent::printOriginLine($line, $var, $restrictlist, $defaulttpldir, $selectedLines);
1806 return;
1807 }
1808 $productstatic = new Product($this->db);
1809
1810 $this->tpl['id'] = $line->id;
1811
1812 $this->tpl['label'] = '';
1813 if (!empty($line->fk_product) && $line->fk_product > 0) {
1814 $productstatic->fetch($line->fk_product);
1815 $productstatic->load_virtual_stock();
1816 $this->tpl['label'] .= $productstatic->getNomUrl(1);
1817 //$this->tpl['label'].= ' - '.$productstatic->label;
1818 } else {
1819 // If origin MO line is not a product, but another MO
1820 // TODO
1821 }
1822
1823 $this->tpl['qty_bom'] = 1;
1824 if (is_object($this->bom) && $this->bom->qty > 1) {
1825 $this->tpl['qty_bom'] = $this->bom->qty;
1826 }
1827
1828 $this->tpl['stock'] = $productstatic->stock_reel;
1829 $this->tpl['seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1830 $this->tpl['virtual_stock'] = $productstatic->stock_theorique;
1831 $this->tpl['qty'] = $line->qty;
1832 $this->tpl['fk_unit'] = $line->fk_unit;
1833 $this->tpl['qty_frozen'] = $line->qty_frozen;
1834 $this->tpl['disable_stock_change'] = $line->disable_stock_change;
1835 $this->tpl['efficiency'] = $line->efficiency;
1836
1837
1838 global $conf; // used into template
1839 $res = include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php';
1840 }
1841
1850 public static function replaceThirdparty($db, $origin_id, $dest_id)
1851 {
1852 $tables = array('mrp_mo');
1853
1854 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1855 }
1856
1857
1863 public function getMoChilds()
1864 {
1865 $TMoChilds = array();
1866 $error = 0;
1867
1868 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child";
1869 $sql .= " WHERE fk_parent_line IN ";
1870 $sql .= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent";
1871 $sql .= " WHERE fk_mo=".((int) $this->id).")";
1872
1873 $resql = $this->db->query($sql);
1874
1875 if ($resql) {
1876 if ($this->db->num_rows($resql) > 0) {
1877 while ($obj = $this->db->fetch_object($resql)) {
1878 $MoChild = new Mo($this->db);
1879 $res = $MoChild->fetch($obj->rowid);
1880 if ($res > 0) {
1881 $TMoChilds[$MoChild->id] = $MoChild;
1882 } else {
1883 $error++;
1884 }
1885 }
1886 }
1887 } else {
1888 $error++;
1889 }
1890
1891 if ($error) {
1892 return -1;
1893 } else {
1894 return $TMoChilds;
1895 }
1896 }
1897
1904 public function getAllMoChilds($depth = 0)
1905 {
1906 if ($depth > 1000) {
1907 return -1;
1908 }
1909
1910 $TMoChilds = array();
1911 $error = 0;
1912
1913 $childMoList = $this->getMoChilds();
1914
1915 if ($childMoList == -1) {
1916 return -1;
1917 }
1918
1919 foreach ($childMoList as $childMo) {
1920 $TMoChilds[$childMo->id] = $childMo;
1921 }
1922
1923 foreach ($childMoList as $childMo) {
1924 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1925
1926 if ($childMoChildren == -1) {
1927 $error++;
1928 } else {
1929 foreach ($childMoChildren as $child) {
1930 $TMoChilds[$child->id] = $child;
1931 }
1932 }
1933 }
1934
1935 if ($error) {
1936 return -1;
1937 } else {
1938 return $TMoChilds;
1939 }
1940 }
1941
1942
1943
1949 public function getMoParent()
1950 {
1951 $MoParent = new Mo($this->db);
1952 $error = 0;
1953
1954 $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo";
1955 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1956 $sql .= " WHERE mo.rowid = ".((int) $this->id);
1957
1958 $resql = $this->db->query($sql);
1959
1960 if ($resql) {
1961 if ($this->db->num_rows($resql) > 0) {
1962 $obj = $this->db->fetch_object($resql);
1963 $res = $MoParent->fetch($obj->id_moparent);
1964 if ($res < 0) {
1965 $error++;
1966 }
1967 } else {
1968 return 0;
1969 }
1970 } else {
1971 $error++;
1972 }
1973
1974 if ($error) {
1975 return -1;
1976 } else {
1977 return $MoParent;
1978 }
1979 }
1980
1988 public function getKanbanView($option = '', $arraydata = null)
1989 {
1990 global $langs;
1991 '@phan-var-force array{selected?:int<0,1>,bom?:Bom,product?:product} $arraydata';
1992
1993 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1994
1995 $return = '<div class="box-flex-item box-flex-grow-zero">';
1996 $return .= '<div class="info-box info-box-sm">';
1997 $return .= '<span class="info-box-icon bg-infobox-action">';
1998 $return .= img_picto('', $this->picto);
1999 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
2000 $return .= '</span>';
2001 $return .= '<div class="info-box-content">';
2002 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2003 if ($selected >= 0) {
2004 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2005 }
2006 if (!empty($arraydata['bom'])) {
2007 $return .= '<br><span class="info-box-label">'.$arraydata['bom']->getNomUrl(1).'</span>';
2008 }
2009 if (!empty($arraydata['product'])) {
2010 $return .= '<br><span class="info-box-label">'.$arraydata['product']->getNomUrl(1).'</span>';
2011 if (property_exists($this, 'qty')) {
2012 $return .= ' <span class="info-box-label">('.$langs->trans("Qty").' '.$this->qty.')</span>';
2013 }
2014 } else {
2015 if (property_exists($this, 'qty')) {
2016 $return .= '<br><span class="info-box-label">'.$langs->trans('Quantity').' : '.$this->qty.'</span>';
2017 }
2018 }
2019 if (method_exists($this, 'getLibStatut')) {
2020 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2021 }
2022 $return .= '</div>';
2023 $return .= '</div>';
2024 $return .= '</div>';
2025 return $return;
2026 }
2027}
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: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.
$tpl
@ var array{id:int,label:string,qty_bom:int|float,stock:float,seuil_stock_alerte:float,...
Definition mo.class.php:271
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:843
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:934
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.
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
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.
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_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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79