dolibarr 22.0.5
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-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 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 -2;
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((int) $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 dol_syslog("Bad status for MO object. Can't add production lines. Check that MO has status DRAFT.");
730 $this->error = "Bad status for MO object. Can't add production lines. Check that MO has status DRAFT.";
731 return -1;
732 }
733
734 $this->db->begin();
735
736 // Insert lines in mrp_production table from BOM data
737 if (!$error) {
738 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'mrp_production WHERE fk_mo = '.((int) $this->id);
739 $this->db->query($sql);
740
741 $moline = new MoLine($this->db);
742
743 // Line to produce
744 $moline->fk_mo = $this->id;
745 $moline->qty = $this->qty;
746 $moline->fk_product = $this->fk_product;
747 $moline->position = 1;
748
749 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
750 $tmpproduct = new Product($this->db);
751 $tmpproduct->fetch($this->fk_product);
752 $moline->fk_unit = $tmpproduct->fk_unit;
753
754 if ($this->fk_bom > 0) { // If a BOM is defined, we know what to produce.
755 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
756 $bom = new BOM($this->db);
757 $bom->fetch($this->fk_bom);
758 if ($bom->bomtype == 1) {
759 $role = 'toproduce';
760 $moline->role = 'toconsume';
761 } else {
762 $role = 'toconsume';
763 $moline->role = 'toproduce';
764 }
765 } else {
766 $bom = null;
767 if ($this->mrptype == 1) {
768 $moline->role = 'toconsume';
769 } else {
770 $moline->role = 'toproduce';
771 }
772 }
773
774 $resultline = $moline->create($user, 0); // Never use triggers here
775 if ($resultline <= 0) {
776 $error++;
777 $this->error = $moline->error;
778 $this->errors = $moline->errors;
779 }
780
781 if ($this->fk_bom > 0 && is_object($bom)) { // If a BOM is defined, we know what to consume.
782 if ($bom->id > 0) {
783 // Lines to consume
784 if (!$error) {
785 foreach ($bom->lines as $line) {
786 $moline = new MoLine($this->db);
787
788 $moline->fk_mo = $this->id;
789 $moline->origin_id = $line->id;
790 $moline->origin_type = 'bomline';
791 if (!empty($line->fk_unit)) {
792 $moline->fk_unit = $line->fk_unit;
793 }
794 if ($line->qty_frozen) {
795 $moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce
796 } else {
797 $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
798 }
799 if ($moline->qty <= 0) {
800 $error++;
801 $this->error = "BadValueForquantityToConsume";
802 $this->errors[] = $this->error;
803 break;
804 } else {
805 $moline->fk_product = $line->fk_product;
806 $moline->role = $role;
807 $moline->position = $line->position;
808 $moline->qty_frozen = $line->qty_frozen;
809 $moline->disable_stock_change = $line->disable_stock_change;
810 if (!empty($line->fk_default_workstation)) {
811 $moline->fk_default_workstation = $line->fk_default_workstation;
812 }
813
814 $resultline = $moline->create($user, 0); // Never use triggers here
815 if ($resultline <= 0) {
816 $error++;
817 $this->error = $moline->error;
818 $this->errors[] = $moline->error;
819 $this->errors = array_merge($this->errors, $moline->errors);
820 dol_print_error($this->db, $moline->error, $moline->errors);
821 break;
822 }
823 }
824 }
825 }
826 }
827 }
828 }
829
830 if (!$error) {
831 $this->db->commit();
832 return 1;
833 } else {
834 $this->db->rollback();
835 return -1;
836 }
837 }
838
846 public function updateProduction(User $user, $notrigger = 0)
847 {
848 $error = 0;
849
850 if ($this->status != self::STATUS_DRAFT) {
851 return 1;
852 }
853
854 $this->db->begin();
855
856 $oldQty = $this->oldQty;
857 $newQty = $this->qty;
858 if ($newQty != $oldQty && !empty($this->oldQty)) {
859 $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "mrp_production WHERE fk_mo = " . (int) $this->id;
860 $resql = $this->db->query($sql);
861 if ($resql) {
862 while ($obj = $this->db->fetch_object($resql)) {
863 $moLine = new MoLine($this->db);
864 $res = $moLine->fetch($obj->rowid);
865 if (!$res) {
866 $error++;
867 }
868
869 if ($moLine->role == 'toconsume' || $moLine->role == 'toproduce') {
870 if (empty($moLine->qty_frozen)) {
871 $qty = $newQty * $moLine->qty / $oldQty;
872 $moLine->qty = (float) price2num($qty, 'MS');
873 $res = $moLine->update($user);
874 if (!$res) {
875 $error++;
876 }
877 }
878 }
879 }
880 }
881 }
882 if (!$error) {
883 $this->db->commit();
884 return 1;
885 } else {
886 $this->db->rollback();
887 return -1;
888 }
889 }
890
891
900 public function delete(User $user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
901 {
902 $error = 0;
903 $this->db->begin();
904
905 if ($also_cancel_consumed_and_produced_lines) {
906 $result = $this->cancelConsumedAndProducedLines($user, 0, false, $notrigger);
907 if ($result < 0) {
908 $error++;
909 }
910 }
911
912 if (!$error) {
913 $result = $this->deleteCommon($user, $notrigger);
914 if ($result < 0) {
915 $error++;
916 }
917 }
918
919 if ($error) {
920 $this->db->rollback();
921 return -1;
922 } else {
923 $this->db->commit();
924 return 1;
925 }
926 }
927
937 public function deleteLine(User $user, $idline, $notrigger = 0, $fk_movement = 0)
938 {
939 global $langs;
940 $langs->loadLangs(array('stocks', 'mrp'));
941
942 if ($this->status < 0) {
943 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
944 return -2;
945 }
946
947 // The line must belong to this MO (checked before any stock movement is reversed)
948 $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
949 $sql .= " WHERE rowid = ".((int) $idline)." AND fk_mo = ".((int) $this->id);
950 $resql = $this->db->query($sql);
951 if (!$resql || !$this->db->num_rows($resql)) {
952 $this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
953 return -1;
954 }
955
956 $productstatic = new Product($this->db);
957
958 $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete
959
960 $result = 0;
961
962 $this->db->begin();
963
964 if (!empty($fk_movement)) {
965 $stockmove = new MouvementStock($this->db);
966 $stockmove->setOrigin($this->element, $this->id);
967
968 // The fk_movement was not recorded so we try to guess the product and quantity to restore.
969 $moline = new MoLine($this->db);
970 $TArrayMoLine = $moline->fetchAll('', '', 1, 0, '(fk_stock_movement:=:'.((int) $fk_movement).')');
971 $moline = is_array($TArrayMoLine) ? array_shift($TArrayMoLine) : null;
972 if (!is_object($moline) || (int) $moline->fk_mo !== (int) $this->id) {
973 $this->db->rollback();
974 $this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
975 return -1;
976 }
977
978 $movement = new MouvementStock($this->db);
979 $movement->fetch($fk_movement);
980 $productstatic->fetch($movement->product_id);
981 $qtytoprocess = $movement->qty;
982
983 // Reverse stock movement
984 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
985 $codemovementCancel = $langs->trans("StockIncrease");
986
987 if (($qtytoprocess >= 0)) {
988 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel);
989 } else {
990 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel);
991 }
992 if ($idstockmove < 0) {
993 $this->error++;
994 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
995 } else {
996 $result = $moline->delete($user, $notrigger);
997 }
998 } elseif (!empty($arrayoflines)) {
999 $stockmove = new MouvementStock($this->db);
1000 $stockmove->setOrigin($this->element, $this->id);
1001
1002 // Loop on each child lines
1003 foreach ($arrayoflines as $key => $arrayofline) {
1004 $lineDetails = $arrayoflines[$key];
1005 $productstatic->fetch($lineDetails['fk_product']);
1006 $qtytoprocess = $lineDetails['qty'];
1007
1008 // Reverse stock movement
1009 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1010 $codemovementCancel = $langs->trans("StockIncrease");
1011
1012
1013 if ($qtytoprocess >= 0) {
1014 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1015 } else {
1016 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1017 }
1018 if ($idstockmove < 0) {
1019 $this->error++;
1020 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
1021 } else {
1022 $moline = new MoLine($this->db);
1023 $moline->fetch($lineDetails['rowid']);
1024
1025 $resdel = $moline->delete($user, $notrigger);
1026 if ($resdel < 0) {
1027 $this->error++;
1028 setEventMessages($moline->error, $moline->errors, 'errors');
1029 }
1030 }
1031 }
1032
1033 if (empty($this->error)) {
1034 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1035 }
1036 } else {
1037 // No child lines and no associated movement
1038 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1039 }
1040
1041 if (!empty($this->error) || $result <= 0) {
1042 $this->db->rollback();
1043 } else {
1044 $this->db->commit();
1045 }
1046
1047 return $result;
1048 }
1049
1050
1058 public function getNextNumRef($prod)
1059 {
1060 global $langs, $conf;
1061 $langs->load("mrp");
1062
1063 if (getDolGlobalString('MRP_MO_ADDON')) {
1064 $mybool = false;
1065
1066 $file = getDolGlobalString('MRP_MO_ADDON') . ".php";
1067 $classname = getDolGlobalString('MRP_MO_ADDON');
1068
1069 // Include file with class
1070 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1071 foreach ($dirmodels as $reldir) {
1072 $dir = dol_buildpath($reldir."core/modules/mrp/");
1073
1074 // Load file with numbering class (if found)
1075 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1076 }
1077
1078 if (!$mybool) {
1079 dol_print_error(null, "Failed to include file ".$file);
1080 return '';
1081 }
1082
1083 $obj = new $classname();
1084 '@phan-var-force ModeleNumRefMos $obj';
1085 $numref = $obj->getNextValue($prod, $this);
1086
1087 if ($numref != "") {
1088 return $numref;
1089 } else {
1090 $this->error = $obj->error;
1091 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1092 return "";
1093 }
1094 } else {
1095 print $langs->trans("Error")." ".$langs->trans("Error_MRP_MO_ADDON_NotDefined");
1096 return "";
1097 }
1098 }
1099
1107 public function validate($user, $notrigger = 0)
1108 {
1109 global $conf;
1110
1111 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1112
1113 $error = 0;
1114
1115 // Protection
1116 if ($this->status == self::STATUS_VALIDATED) {
1117 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
1118 return 0;
1119 }
1120
1121 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->create))
1122 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->mrp_advance->validate))))
1123 {
1124 $this->error='NotEnoughPermissions';
1125 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
1126 return -1;
1127 }*/
1128
1129 $now = dol_now();
1130
1131 $this->db->begin();
1132
1133 // Define new ref
1134 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
1135 $this->fetch_product();
1136 $num = $this->getNextNumRef($this->product);
1137 } else {
1138 $num = $this->ref;
1139 }
1140 $this->newref = $num;
1141
1142 // Validate
1143 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1144 $sql .= " SET ref = '".$this->db->escape($num)."',";
1145 $sql .= " status = ".self::STATUS_VALIDATED.",";
1146 $sql .= " date_valid = '".$this->db->idate($now)."',";
1147 $sql .= " fk_user_valid = ".((int) $user->id);
1148 $sql .= " WHERE rowid = ".((int) $this->id);
1149
1150 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
1151 $resql = $this->db->query($sql);
1152 if (!$resql) {
1153 dol_print_error($this->db);
1154 $this->error = $this->db->lasterror();
1155 $error++;
1156 }
1157
1158 if (!$error && !$notrigger) {
1159 // Call trigger
1160 $result = $this->call_trigger('MRP_MO_VALIDATE', $user);
1161 if ($result < 0) {
1162 $error++;
1163 }
1164 // End call triggers
1165 }
1166
1167 if (!$error) {
1168 $this->oldref = $this->ref;
1169
1170 // Rename directory if dir was a temporary ref
1171 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
1172 // Now we rename also files into index
1173 $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)."'";
1174 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1175 $resql = $this->db->query($sql);
1176 if (!$resql) {
1177 $error++;
1178 $this->error = $this->db->lasterror();
1179 }
1180 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'mrp/".$this->db->escape($this->newref)."'";
1181 $sql .= " WHERE filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1182 $resql = $this->db->query($sql);
1183 if (!$resql) {
1184 $error++;
1185 $this->error = $this->db->lasterror();
1186 }
1187
1188 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
1189 $oldref = dol_sanitizeFileName($this->ref);
1190 $newref = dol_sanitizeFileName($num);
1191 $dirsource = $conf->mrp->dir_output.'/'.$oldref;
1192 $dirdest = $conf->mrp->dir_output.'/'.$newref;
1193 if (!$error && file_exists($dirsource)) {
1194 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
1195
1196 if (@rename($dirsource, $dirdest)) {
1197 dol_syslog("Rename ok");
1198 // Rename docs starting with $oldref with $newref
1199 $listoffiles = dol_dir_list($conf->mrp->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1200 foreach ($listoffiles as $fileentry) {
1201 $dirsource = $fileentry['name'];
1202 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1203 $dirsource = $fileentry['path'].'/'.$dirsource;
1204 $dirdest = $fileentry['path'].'/'.$dirdest;
1205 @rename($dirsource, $dirdest);
1206 }
1207 }
1208 }
1209 }
1210 }
1211
1212 // Set new ref and current status
1213 if (!$error) {
1214 $this->ref = $num;
1215 $this->status = self::STATUS_VALIDATED;
1216 }
1217
1218 if (!$error) {
1219 $this->db->commit();
1220 return 1;
1221 } else {
1222 $this->db->rollback();
1223 return -1;
1224 }
1225 }
1226
1234 public function setDraft($user, $notrigger = 0)
1235 {
1236 // Protection
1237 if ($this->status <= self::STATUS_DRAFT) {
1238 return 0;
1239 }
1240
1241 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1242 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1243 {
1244 $this->error='Permission denied';
1245 return -1;
1246 }*/
1247
1248 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MRP_MO_UNVALIDATE');
1249 }
1250
1259 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
1260 {
1261 // Protection
1262 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) {
1263 return 0;
1264 }
1265
1266 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1267 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1268 {
1269 $this->error='Permission denied';
1270 return -1;
1271 }*/
1272
1273 $error = 0;
1274 $this->db->begin();
1275
1276 if ($also_cancel_consumed_and_produced_lines) {
1277 $result = $this->cancelConsumedAndProducedLines($user, 0, true, $notrigger);
1278 if ($result < 0) {
1279 $error++;
1280 }
1281 }
1282
1283 if (!$error) {
1284 $result = $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL');
1285 if ($result < 0) {
1286 $error++;
1287 }
1288 }
1289
1290 if ($error) {
1291 $this->db->rollback();
1292 return -1;
1293 } else {
1294 $this->db->commit();
1295 return 1;
1296 }
1297 }
1298
1306 public function reopen($user, $notrigger = 0)
1307 {
1308 // Protection
1309 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) {
1310 return 0;
1311 }
1312
1313 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1314 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1315 {
1316 $this->error='Permission denied';
1317 return -1;
1318 }*/
1319
1320 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MRP_MO_REOPEN');
1321 }
1322
1332 public function cancelConsumedAndProducedLines($user, $mode = 0, $also_delete_lines = false, $notrigger = 0)
1333 {
1334 global $langs;
1335
1336 if (!isModEnabled('stock')) {
1337 return 1;
1338 }
1339
1340 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1341 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
1342 $error = 0;
1343 $langs->load('stocks');
1344
1345 $this->db->begin();
1346
1347 // Cancel consumed lines
1348 if (empty($mode) || $mode == 1) {
1349 $arrayoflines = $this->fetchLinesLinked('consumed');
1350 if (!empty($arrayoflines)) {
1351 foreach ($arrayoflines as $key => $lineDetails) {
1352 $productstatic = new Product($this->db);
1353 $productstatic->fetch($lineDetails['fk_product']);
1354 $qtytoprocess = $lineDetails['qty'];
1355
1356 // Reverse stock movement
1357 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1358 $codemovementCancel = $langs->trans("StockIncrease");
1359
1360 $stockmove = new MouvementStock($this->db);
1361 $stockmove->setOrigin($this->element, $this->id);
1362 if ($qtytoprocess >= 0) {
1363 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1364 } else {
1365 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1366 }
1367 if ($idstockmove < 0) {
1368 $this->error = $stockmove->error;
1369 $this->errors = $stockmove->errors;
1370 $error++;
1371 break;
1372 }
1373
1374 if ($also_delete_lines) {
1375 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1376 if ($result < 0) {
1377 $error++;
1378 break;
1379 }
1380 }
1381 }
1382 }
1383 }
1384
1385 // Cancel produced lines
1386 if (empty($mode) || $mode == 2) {
1387 $arrayoflines = $this->fetchLinesLinked('produced');
1388 if (!empty($arrayoflines)) {
1389 foreach ($arrayoflines as $key => $lineDetails) {
1390 $productstatic = new Product($this->db);
1391 $productstatic->fetch($lineDetails['fk_product']);
1392 $qtytoprocess = $lineDetails['qty'];
1393
1394 // Reverse stock movement
1395 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1396 $codemovementCancel = $langs->trans("StockDecrease");
1397
1398 $stockmove = new MouvementStock($this->db);
1399 $stockmove->setOrigin($this->element, $this->id);
1400 if ($qtytoprocess >= 0) {
1401 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1402 } else {
1403 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1404 }
1405 if ($idstockmove < 0) {
1406 $this->error = $stockmove->error;
1407 $this->errors = $stockmove->errors;
1408 $error++;
1409 break;
1410 }
1411
1412 if ($also_delete_lines) {
1413 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1414 if ($result < 0) {
1415 $error++;
1416 break;
1417 }
1418 }
1419 }
1420 }
1421 }
1422
1423 if ($error) {
1424 $this->db->rollback();
1425 return -1;
1426 } else {
1427 $this->db->commit();
1428 return 1;
1429 }
1430 }
1431
1438 public function getTooltipContentArray($params)
1439 {
1440 global $langs;
1441
1442 $langs->loadLangs(['mrp', 'products']);
1443 $nofetch = isset($params['nofetch']);
1444
1445 $datas = [];
1446
1447 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ManufacturingOrder").'</u>';
1448 if (isset($this->status)) {
1449 $datas['picto'] .= ' '.$this->getLibStatut(5);
1450 }
1451 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1452 if (isset($this->label)) {
1453 $datas['label'] = '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1454 }
1455 if (isset($this->mrptype)) {
1456 $datas['type'] = '<br><b>'.$langs->trans('Type').':</b> '.$this->fields['mrptype']['arrayofkeyval'][$this->mrptype];
1457 }
1458 if (isset($this->qty)) {
1459 $datas['qty'] = '<br><b>'.$langs->trans('QtyToProduce').':</b> '.$this->qty;
1460 }
1461 if (!$nofetch && isset($this->fk_product)) {
1462 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1463 $product = new Product($this->db);
1464 $product->fetch($this->fk_product);
1465 $datas['product'] = '<br><b>'.$langs->trans('Product').':</b> '.$product->getNomUrl(1, '', 0, -1, 1);
1466 }
1467 if (!$nofetch && isset($this->fk_warehouse)) {
1468 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
1469 $warehouse = new Entrepot($this->db);
1470 $warehouse->fetch($this->fk_warehouse);
1471 $datas['warehouse'] = '<br><b>'.$langs->trans('WarehouseForProduction').':</b> '.$warehouse->getNomUrl(1, '', 0, 1);
1472 }
1473
1474 return $datas;
1475 }
1476
1487 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1488 {
1489 global $conf, $langs, $action, $hookmanager;
1490
1491 if (!empty($conf->dol_no_mouse_hover)) {
1492 $notooltip = 1; // Force disable tooltips
1493 }
1494
1495 $result = '';
1496 $params = [
1497 'id' => $this->id,
1498 'objecttype' => $this->element,
1499 'option' => $option,
1500 'nofetch' => 1,
1501 ];
1502 $classfortooltip = 'classfortooltip';
1503 $dataparams = '';
1504 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1505 $classfortooltip = 'classforajaxtooltip';
1506 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1507 $label = '';
1508 } else {
1509 $label = implode($this->getTooltipContentArray($params));
1510 }
1511
1512 $url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$this->id;
1513 if ($option == 'production') {
1514 $url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$this->id;
1515 }
1516
1517 if ($option != 'nolink') {
1518 // Add param to save lastsearch_values or not
1519 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1520 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1521 $add_save_lastsearch_values = 1;
1522 }
1523 if ($add_save_lastsearch_values) {
1524 $url .= '&save_lastsearch_values=1';
1525 }
1526 }
1527
1528 $linkclose = '';
1529 if (empty($notooltip)) {
1530 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1531 $label = $langs->trans("ShowMo");
1532 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1533 }
1534 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1535 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1536 } else {
1537 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1538 }
1539
1540 $linkstart = '<a href="'.$url.'"';
1541 $linkstart .= $linkclose.'>';
1542 $linkend = '</a>';
1543
1544 $result .= $linkstart;
1545 if ($withpicto) {
1546 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
1547 }
1548 if ($withpicto != 2) {
1549 $result .= $this->ref;
1550 }
1551 $result .= $linkend;
1552 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1553
1554 $hookmanager->initHooks(array('modao'));
1555 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1556 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1557 if ($reshook > 0) {
1558 $result = $hookmanager->resPrint;
1559 } else {
1560 $result .= $hookmanager->resPrint;
1561 }
1562
1563 return $result;
1564 }
1565
1572 public function getLibStatut($mode = 0)
1573 {
1574 return $this->LibStatut($this->status, $mode);
1575 }
1576
1577 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1585 public function LibStatut($status, $mode = 0)
1586 {
1587 // phpcs:enable
1588 if (empty($this->labelStatus)) {
1589 global $langs;
1590 //$langs->load("mrp");
1591 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1592 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatedToProduce');
1593 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1594 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1595 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1596
1597 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1598 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1599 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1600 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1601 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1602 }
1603
1604 $statusType = 'status'.$status;
1605 if ($status == self::STATUS_VALIDATED) {
1606 $statusType = 'status1';
1607 }
1608 if ($status == self::STATUS_INPROGRESS) {
1609 $statusType = 'status4';
1610 }
1611 if ($status == self::STATUS_PRODUCED) {
1612 $statusType = 'status6';
1613 }
1614 if ($status == self::STATUS_CANCELED) {
1615 $statusType = 'status9';
1616 }
1617
1618 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1619 }
1620
1627 public function info($id)
1628 {
1629 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1630 $sql .= ' fk_user_creat, fk_user_modif';
1631 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1632 $sql .= ' WHERE t.rowid = '.((int) $id);
1633 $result = $this->db->query($sql);
1634 if ($result) {
1635 if ($this->db->num_rows($result)) {
1636 $obj = $this->db->fetch_object($result);
1637
1638 $this->id = $obj->rowid;
1639
1640 $this->user_creation_id = $obj->fk_user_creat;
1641 $this->user_modification_id = $obj->fk_user_modif;
1642 $this->date_creation = $this->db->jdate($obj->datec);
1643 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1644 }
1645
1646 $this->db->free($result);
1647 } else {
1648 dol_print_error($this->db);
1649 }
1650 }
1651
1658 public function initAsSpecimen()
1659 {
1660 $ret = $this->initAsSpecimenCommon();
1661
1662 $this->lines = array();
1663
1664 return $ret;
1665 }
1666
1673 public function getLinesArray($rolefilter = '')
1674 {
1675 $this->lines = array();
1676
1677 $objectline = new MoLine($this->db);
1678
1679 $filter = '(fk_mo:=:'.((int) $this->id).')';
1680 if (!empty($rolefilter)) {
1681 $filter .= " AND (role:=:'".$this->db->escape($rolefilter)."')";
1682 }
1683 $result = $objectline->fetchAll('ASC', 'position', 0, 0, $filter);
1684
1685 if (is_numeric($result)) {
1686 $this->error = $objectline->error;
1687 $this->errors = $objectline->errors;
1688 return $result;
1689 } else {
1690 $this->lines = $result;
1691 return $this->lines;
1692 }
1693 }
1694
1706 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1707 {
1708 global $langs;
1709
1710 $langs->load("mrp");
1711
1712 if (!dol_strlen($modele)) {
1713 //$modele = 'standard';
1714 $modele = ''; // Remove this once a pdf_standard.php exists.
1715
1716 if ($this->model_pdf) {
1717 $modele = $this->model_pdf;
1718 } elseif (getDolGlobalString('MRP_MO_ADDON_PDF')) {
1719 $modele = getDolGlobalString('MRP_MO_ADDON_PDF');
1720 }
1721 }
1722
1723 $modelpath = "core/modules/mrp/doc/";
1724
1725 if (empty($modele)) {
1726 return 1; // Remove this once a pdf_standard.php exists.
1727 }
1728
1729 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1730 }
1731
1742 public function printOriginLinesList($restrictlist = '', $selectedLines = array())
1743 {
1744 global $langs, $hookmanager, $form, $action;
1745
1746 $langs->load('stocks');
1747 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
1748 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
1749 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
1750 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
1751 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
1752 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
1753 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
1754 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
1755 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
1756
1757 print '<tr class="liste_titre">';
1758 // Product or sub-bom
1759 print '<td class="linecoldescription">'.$langs->trans('Ref');
1760 if (getDolGlobalString('BOM_SUB_BOM')) {
1761 print ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
1762 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
1763 }
1764 print '</td>';
1765 // Qty
1766 print '<td class="right">'.$langs->trans('Qty');
1767 if ($this->bom->bomtype == 0) {
1768 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", (string) $this->bom->qty).')</span>';
1769 } else {
1770 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", (string) $this->bom->qty).')</span>';
1771 }
1772 // Unit
1773 print '<td class="right">'.$langs->trans('Unit');
1774
1775 print '</td>';
1776 print '<td class="center">'.$form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1).'</td>';
1777 print '<td class="center">'.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).'</td>';
1778 print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
1779 print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
1780 print '<td class="center">'.$langs->trans('MoChildGenerate').'</td>';
1781 //print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
1782 //print '<td class="center"></td>';
1783 print '</tr>';
1784 $i = 0;
1785
1786 if (!empty($this->lines)) {
1787 foreach ($this->lines as $line) {
1788 $reshook = 0;
1789 if (is_object($hookmanager)) {
1790 $parameters = array('line' => $line, 'i' => $i, 'restrictlist' => $restrictlist, 'selectedLines' => $selectedLines);
1791 if (!empty($line->fk_parent_line)) {
1792 $parameters['fk_parent_line'] = $line->fk_parent_line;
1793 }
1794 $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1795 }
1796 if (empty($reshook)) {
1797 $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
1798 }
1799
1800 $i++;
1801 }
1802 }
1803 }
1804
1805
1819 public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array())
1820 {
1821 if (!$line instanceof MoLine) {
1822 dol_syslog(__METHOD__.'::pringOriginLine $line is '.get_class($line).'<>MoLine', LOG_WARNING);
1823 parent::printOriginLine($line, $var, $restrictlist, $defaulttpldir, $selectedLines);
1824 return;
1825 }
1826 $productstatic = new Product($this->db);
1827
1828 $this->tpl['id'] = $line->id;
1829
1830 $this->tpl['label'] = '';
1831 if (!empty($line->fk_product) && $line->fk_product > 0) {
1832 $productstatic->fetch($line->fk_product);
1833 $productstatic->load_stock(); // load_virtual_stock() is done in load_stock()
1834 $this->tpl['label'] .= $productstatic->getNomUrl(1);
1835 //$this->tpl['label'].= ' - '.$productstatic->label;
1836 } else {
1837 // If origin MO line is not a product, but another MO
1838 // TODO
1839 }
1840
1841 $this->tpl['qty_bom'] = 1;
1842 if (is_object($this->bom) && $this->bom->qty > 1) {
1843 $this->tpl['qty_bom'] = $this->bom->qty;
1844 }
1845
1846 $this->tpl['stock'] = $productstatic->stock_reel;
1847 $this->tpl['seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1848 $this->tpl['virtual_stock'] = $productstatic->stock_theorique;
1849 $this->tpl['qty'] = $line->qty;
1850 $this->tpl['fk_unit'] = $line->fk_unit;
1851 $this->tpl['qty_frozen'] = $line->qty_frozen;
1852 $this->tpl['disable_stock_change'] = $line->disable_stock_change;
1853 $this->tpl['efficiency'] = $line->efficiency;
1854
1855
1856 global $conf; // used into template
1857 $res = include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php';
1858 }
1859
1868 public static function replaceThirdparty($db, $origin_id, $dest_id)
1869 {
1870 $tables = array('mrp_mo');
1871
1872 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1873 }
1874
1875
1881 public function getMoChilds()
1882 {
1883 $TMoChilds = array();
1884 $error = 0;
1885
1886 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child";
1887 $sql .= " WHERE fk_parent_line IN ";
1888 $sql .= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent";
1889 $sql .= " WHERE fk_mo=".((int) $this->id).")";
1890
1891 $resql = $this->db->query($sql);
1892
1893 if ($resql) {
1894 if ($this->db->num_rows($resql) > 0) {
1895 while ($obj = $this->db->fetch_object($resql)) {
1896 $MoChild = new Mo($this->db);
1897 $res = $MoChild->fetch($obj->rowid);
1898 if ($res > 0) {
1899 $TMoChilds[$MoChild->id] = $MoChild;
1900 } else {
1901 $error++;
1902 }
1903 }
1904 }
1905 } else {
1906 $error++;
1907 }
1908
1909 if ($error) {
1910 return -1;
1911 } else {
1912 return $TMoChilds;
1913 }
1914 }
1915
1922 public function getAllMoChilds($depth = 0)
1923 {
1924 if ($depth > 1000) {
1925 return -1;
1926 }
1927
1928 $TMoChilds = array();
1929 $error = 0;
1930
1931 $childMoList = $this->getMoChilds();
1932
1933 if ($childMoList == -1) {
1934 return -1;
1935 }
1936
1937 foreach ($childMoList as $childMo) {
1938 $TMoChilds[$childMo->id] = $childMo;
1939 }
1940
1941 foreach ($childMoList as $childMo) {
1942 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1943
1944 if ($childMoChildren == -1) {
1945 $error++;
1946 } else {
1947 foreach ($childMoChildren as $child) {
1948 $TMoChilds[$child->id] = $child;
1949 }
1950 }
1951 }
1952
1953 if ($error) {
1954 return -1;
1955 } else {
1956 return $TMoChilds;
1957 }
1958 }
1959
1960
1961
1967 public function getMoParent()
1968 {
1969 $MoParent = new Mo($this->db);
1970 $error = 0;
1971
1972 $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo";
1973 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1974 $sql .= " WHERE mo.rowid = ".((int) $this->id);
1975
1976 $resql = $this->db->query($sql);
1977
1978 if ($resql) {
1979 if ($this->db->num_rows($resql) > 0) {
1980 $obj = $this->db->fetch_object($resql);
1981 $res = $MoParent->fetch($obj->id_moparent);
1982 if ($res < 0) {
1983 $error++;
1984 }
1985 } else {
1986 return 0;
1987 }
1988 } else {
1989 $error++;
1990 }
1991
1992 if ($error) {
1993 return -1;
1994 } else {
1995 return $MoParent;
1996 }
1997 }
1998
1999 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2006 public function load_board($user)
2007 {
2008 // phpcs:enable
2009 global $conf, $langs;
2010 if ($user->socid) {
2011 return -1; // Protection pour éviter appel par utilisateur externe
2012 }
2013
2014 $now = dol_now();
2015
2016 $sql = "SELECT rowid, date_end_planned FROM ".$this->db->prefix()."mrp_mo";
2017 $sql .= " WHERE status IN (" . self::STATUS_VALIDATED . ", " . self::STATUS_INPROGRESS .")"; // 1 = Ouvert, 2 = En cours
2018 $sql .= " AND entity IN (".getEntity('mrp_mo').")";
2019
2020 $resql = $this->db->query($sql);
2021 if ($resql) {
2022 $langs->load("mrp");
2023 $response = new WorkboardResponse();
2024 $warning_delay = $conf->mrp->progress->warning_delay ;
2025 $response->warning_delay = $warning_delay / 86400;
2026 $response->label = $langs->trans("MOProgress");
2027 $response->labelShort = $langs->trans("MOProgress");
2028 $response->url = DOL_URL_ROOT.'/mrp/mo_list.php?search_status=-2';
2029 $response->img = img_object('', "mrp");
2030
2031
2032 while ($obj = $this->db->fetch_object($resql)) {
2033 $response->nbtodo++;
2034
2035 if (!empty($obj->date_end_planned)) {
2036 $date_end_planned = $this->db->jdate($obj->date_end_planned);
2037 if ($now > ($date_end_planned + $warning_delay)) {
2038 $response->nbtodolate++;
2039 $response->url_late = DOL_URL_ROOT.'/mrp/mo_list.php?search_status=-2&search_option=late';
2040 }
2041 }
2042 }
2043
2044 return $response;
2045 } else {
2046 dol_print_error($this->db);
2047 $this->error = $this->db->error();
2048 return -1;
2049 }
2050 }
2051
2057 public function hasDelay()
2058 {
2059 global $conf;
2060
2061 if ($this->status != Mo::STATUS_VALIDATED && $this->status != Mo::STATUS_INPROGRESS) {
2062 return false;
2063 }
2064 if (empty($this->date_end_planned)) {
2065 return false;
2066 }
2067 return (dol_now() > ((int) $this->date_end_planned + $conf->mrp->progress->warning_delay));
2068 }
2069
2070
2078 public function getKanbanView($option = '', $arraydata = null)
2079 {
2080 global $langs;
2081 '@phan-var-force array{selected?:int<0,1>,bom?:Bom,product?:product} $arraydata';
2082
2083 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2084
2085 $return = '<div class="box-flex-item box-flex-grow-zero">';
2086 $return .= '<div class="info-box info-box-sm">';
2087 $return .= '<span class="info-box-icon bg-infobox-action">';
2088 $return .= img_picto('', $this->picto);
2089 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
2090 $return .= '</span>';
2091 $return .= '<div class="info-box-content">';
2092 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2093 if ($selected >= 0) {
2094 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2095 }
2096 if (!empty($arraydata['bom'])) {
2097 $return .= '<br><span class="info-box-label">'.$arraydata['bom']->getNomUrl(1).'</span>';
2098 }
2099 if (!empty($arraydata['product'])) {
2100 $return .= '<br><span class="info-box-label">'.$arraydata['product']->getNomUrl(1).'</span>';
2101 if (property_exists($this, 'qty')) {
2102 $return .= ' <span class="info-box-label">('.$langs->trans("Qty").' '.$this->qty.')</span>';
2103 }
2104 } else {
2105 if (property_exists($this, 'qty')) {
2106 $return .= '<br><span class="info-box-label">'.$langs->trans('Quantity').' : '.$this->qty.'</span>';
2107 }
2108 }
2109 if (method_exists($this, 'getLibStatut')) {
2110 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2111 }
2112 $return .= '</div>';
2113 $return .= '</div>';
2114 $return .= '</div>';
2115 return $return;
2116 }
2117}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$object ref
Definition info.php:90
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.
hasDelay()
Is the manufactured delayed?
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:846
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:937
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
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
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