dolibarr 23.0.3
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' => 'isModEnabled("bom")', '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' => 'isModEnabled("project")', '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 );
114
118 public $rowid;
119
123 public $ref;
124
128 public $mrptype;
129
133 public $label;
134
138 public $qty;
139
143 public $fk_warehouse;
144
148 public $fk_soc;
149
153 public $socid;
154
158 public $note_public;
159
163 public $note_private;
164
168 public $date_valid;
169
173 public $fk_user_creat;
177 public $fk_user_modif;
181 public $import_key;
185 public $status;
186
190 public $fk_product;
191
195 public $product;
196
200 public $date_start_planned;
201
205 public $date_end_planned;
206
210 public $fk_bom;
211
215 public $bom;
216
220 public $fk_project;
221
226 public $oldQty;
227
228
229 // If this object has a subtable with lines
230
234 public $table_element_line = 'mrp_production';
235
239 public $fk_element = 'fk_mo';
240
244 public $class_element_line = 'MoLine';
245
249 protected $childtables = array();
250
254 protected $childtablesoncascade = array('mrp_production');
255
259 public $lines = array();
260
264 public $line = null;
265
269 public $fk_parent_line;
270
274 public $tpl = array();
275
276
282 public function __construct(DoliDB $db)
283 {
284 global $langs;
285
286 $this->db = $db;
287
288 $this->ismultientitymanaged = 1;
289 $this->isextrafieldmanaged = 1;
290
291 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
292 $this->fields['rowid']['visible'] = 0;
293 }
294 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
295 $this->fields['entity']['enabled'] = 0;
296 }
297
298 // Unset fields that are disabled
299 foreach ($this->fields as $key => $val) {
300 if (isset($val['enabled']) && empty($val['enabled'])) {
301 unset($this->fields[$key]);
302 }
303 }
304
305 // Translate some data of arrayofkeyval
306 foreach ($this->fields as $key => $val) {
307 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
308 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
309 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
310 }
311 }
312 }
313 }
314
322 public function create(User $user, $notrigger = 0)
323 {
324 $error = 0;
325 $idcreated = 0;
326
327 // 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
328 if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && !getDolGlobalString('ALLOW_USE_KITS_INTO_BOM_AND_MO') && $this->fk_product > 0) {
329 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
330 $tmpproduct = new Product($this->db);
331 $tmpproduct->fetch((int) $this->fk_product);
332 if ($tmpproduct->hasFatherOrChild(1) > 0) {
333 $this->error = 'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
334 $this->errors[] = $this->error;
335 return -2;
336 }
337 }
338
339 $this->db->begin();
340
341 if ($this->fk_bom > 0) {
342 // If there is a known BOM, we force the type of MO to the type of BOM
343 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
344 $tmpbom = new BOM($this->db);
345 $tmpbom->fetch($this->fk_bom);
346
347 $this->mrptype = $tmpbom->bomtype;
348 }
349
350
351 $idcreated = $this->createCommon($user, $notrigger);
352 if ($idcreated <= 0) {
353 $error++;
354 }
355
356 if (!$error) {
357 $result = $this->createProduction($user, $notrigger); // Insert lines from BOM
358 if ($result <= 0) {
359 $error++;
360 }
361 }
362
363 if (!$error) {
364 $this->db->commit();
365 return $idcreated;
366 } else {
367 $this->db->rollback();
368 return -1;
369 }
370 }
371
379 public function createFromClone(User $user, $fromid)
380 {
381 global $langs, $extrafields;
382 $error = 0;
383
384 dol_syslog(__METHOD__, LOG_DEBUG);
385
386 $object = new self($this->db);
387
388 $this->db->begin();
389
390 // Load source object
391 $result = $object->fetchCommon($fromid);
392 if ($result > 0 && !empty($object->table_element_line)) {
393 $object->fetchLines();
394 }
395
396 // get lines so they will be clone
397 //foreach($this->lines as $line)
398 // $line->fetch_optionals();
399
400 // Reset some properties
401 unset($object->id);
402 unset($object->fk_user_creat);
403 unset($object->import_key);
404
405 // We make $object->lines empty to sort it without produced and consumed lines
406 $TLines = $object->lines;
407 $object->lines = array();
408
409 // Remove produced and consumed lines
410 foreach ($TLines as $key => $line) {
411 if (in_array($line->role, array('consumed', 'produced'))) {
412 unset($object->lines[$key]);
413 } else {
414 $object->lines[] = $line;
415 }
416 }
417
418
419 // Clear fields @phan-suppress-next-line PhanTypeMismatchProperty
420 $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
421 // @phan-suppress-next-line PhanTypeInvalidDimOffset
422 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
423 $object->status = self::STATUS_DRAFT;
424 // ...
425 // Clear extrafields that are unique
426 if (is_array($object->array_options) && count($object->array_options) > 0) {
427 $extrafields->fetch_name_optionals_label($this->table_element);
428 foreach ($object->array_options as $key => $option) {
429 $shortkey = preg_replace('/options_/', '', $key);
430 if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) {
431 //var_dump($key);
432 //var_dump($clonedObj->array_options[$key]); exit;
433 unset($object->array_options[$key]);
434 }
435 }
436 }
437
438 // Create clone
439 $object->context['createfromclone'] = 'createfromclone';
440 $result = $object->createCommon($user);
441 if ($result < 0) {
442 $error++;
443 $this->error = $object->error;
444 $this->errors = $object->errors;
445 }
446
447 if (!$error) {
448 // copy internal contacts
449 if ($this->copy_linked_contact($object, 'internal') < 0) {
450 $error++;
451 }
452 }
453
454 if (!$error) {
455 // copy external contacts if same company
456 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
457 if ($this->copy_linked_contact($object, 'external') < 0) {
458 $error++;
459 }
460 }
461 }
462
463 unset($object->context['createfromclone']);
464
465 // End
466 if (!$error) {
467 $this->db->commit();
468 return $object;
469 } else {
470 $this->db->rollback();
471 return -1;
472 }
473 }
474
482 public function fetch($id, $ref = null)
483 {
484 $result = $this->fetchCommon($id, $ref);
485 if ($result > 0 && !empty($this->table_element_line)) {
486 $this->fetchLines();
487 }
488
489 $this->socid = $this->fk_soc;
490
491 return $result;
492 }
493
499 public function fetchLines()
500 {
501 $this->lines = array();
502
503 $result = $this->fetchLinesCommon();
504 return $result;
505 }
506
507
519 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
520 {
521 dol_syslog(__METHOD__, LOG_DEBUG);
522
523 $records = array();
524
525 $sql = 'SELECT ';
526 $sql .= $this->getFieldList();
527 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
528 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
529 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
530 } else {
531 $sql .= ' WHERE 1 = 1';
532 }
533
534 // Manage filter
535 if (is_array($filter)) {
536 $sqlwhere = array();
537 if (count($filter) > 0) {
538 foreach ($filter as $key => $value) {
539 if ($key == 't.rowid') {
540 $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
541 } elseif (strpos($key, 'date') !== false) {
542 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate((int) $value)."'";
543 } else {
544 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
545 }
546 }
547 }
548 if (count($sqlwhere) > 0) {
549 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
550 }
551
552 $filter = '';
553 }
554
555 // Manage filter
556 $errormessage = '';
557 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
558 if ($errormessage) {
559 $this->errors[] = $errormessage;
560 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
561 return -1;
562 }
563
564 if (!empty($sortfield)) {
565 $sql .= $this->db->order($sortfield, $sortorder);
566 }
567 if (!empty($limit)) {
568 $sql .= $this->db->plimit($limit, $offset);
569 }
570
571 $resql = $this->db->query($sql);
572 if ($resql) {
573 $num = $this->db->num_rows($resql);
574 $i = 0;
575 while ($i < min($limit, $num)) {
576 $obj = $this->db->fetch_object($resql);
577
578 $record = new self($this->db);
579 $record->setVarsFromFetchObj($obj);
580
581 $records[$record->id] = $record;
582
583 $i++;
584 }
585 $this->db->free($resql);
586
587 return $records;
588 } else {
589 $this->errors[] = 'Error '.$this->db->lasterror();
590 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
591
592 return -1;
593 }
594 }
595
603 public function fetchLinesLinked($role, $lineid = 0)
604 {
605 $resarray = array();
606 $mostatic = new MoLine($this->db);
607
608 $sql = 'SELECT ';
609 $sql .= $mostatic->getFieldList();
610 $sql .= ' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.' as t';
611 $sql .= " WHERE t.role = '".$this->db->escape($role)."'";
612 if ($lineid > 0) {
613 $sql .= ' AND t.fk_mrp_production = '.((int) $lineid);
614 } else {
615 $sql .= 'AND t.fk_mo = '.((int) $this->id);
616 }
617
618 $resql = $this->db->query($sql);
619 if ($resql) {
620 $num = $this->db->num_rows($resql);
621
622 $i = 0;
623 while ($i < $num) {
624 $obj = $this->db->fetch_object($resql);
625 if ($obj) {
626 $resarray[] = array(
627 'rowid' => (int) $obj->rowid,
628 'date' => $this->db->jdate($obj->date_creation),
629 'qty' => (float) $obj->qty,
630 'role' => $obj->role,
631 'fk_product' => $obj->fk_product,
632 'fk_warehouse' => $obj->fk_warehouse,
633 'batch' => $obj->batch,
634 'fk_stock_movement' => $obj->fk_stock_movement,
635 'fk_unit' => $obj->fk_unit
636 );
637 }
638
639 $i++;
640 }
641
642 return $resarray;
643 } else {
644 $this->error = $this->db->lasterror();
645 return array();
646 }
647 }
648
649
655 public function countMovements()
656 {
657 $result = 0;
658
659 $sql = 'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.'stock_mouvement as sm';
660 $sql .= " WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->id);
661
662 $resql = $this->db->query($sql);
663 if ($resql) {
664 $num = $this->db->num_rows($resql);
665
666 $i = 0;
667 while ($i < $num) {
668 $obj = $this->db->fetch_object($resql);
669 if ($obj) {
670 $result = $obj->nb;
671 }
672
673 $i++;
674 }
675 } else {
676 $this->error = $this->db->lasterror();
677 }
678
679 return $result;
680 }
681
682
690 public function update(User $user, $notrigger = 0)
691 {
692 $error = 0;
693
694 $this->db->begin();
695
696 $result = $this->updateCommon($user, $notrigger);
697 if ($result <= 0) {
698 $error++;
699 }
700
701 // Update the lines (the qty) to consume or to produce
702 $result = $this->updateProduction($user, $notrigger);
703 if ($result <= 0) {
704 $error++;
705 }
706
707 if (!$error) {
708 $this->db->commit();
709 return 1;
710 } else {
711 $this->db->rollback();
712 return -1;
713 }
714 }
715
716
724 public function createProduction(User $user, $notrigger = 0)
725 {
726 $error = 0;
727 $role = "";
728
729 if ($this->status != self::STATUS_DRAFT) {
730 dol_syslog("Bad status for MO object. Can't add production lines. Check that MO has status DRAFT.");
731 $this->error = "Bad status for MO object. Can't add production lines. Check that MO has status DRAFT.";
732 return -1;
733 }
734
735 $this->db->begin();
736
737 // Insert lines in mrp_production table from BOM data
738
739 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'mrp_production WHERE fk_mo = '.((int) $this->id);
740 $this->db->query($sql);
741
742 $moline = new MoLine($this->db);
743
744 // Line to produce
745 $moline->fk_mo = (int) $this->id;
746 $moline->qty = (float) $this->qty;
747 $moline->fk_product = (int) $this->fk_product;
748 $moline->fk_warehouse = (int) $this->fk_warehouse;
749 $moline->position = 1;
750
751 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
752 $tmpproduct = new Product($this->db);
753 $tmpproduct->fetch((int) $this->fk_product);
754 $moline->fk_unit = $tmpproduct->fk_unit;
755
756 if ($this->fk_bom > 0) { // If a BOM is defined, we know what to produce.
757 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
758 $bom = new BOM($this->db);
759 $bom->fetch($this->fk_bom);
760 if ($bom->bomtype == 1) {
761 $role = 'toproduce';
762 $moline->role = 'toconsume';
763 } else {
764 $role = 'toconsume';
765 $moline->role = 'toproduce';
766 }
767 } else {
768 $bom = null;
769 if ($this->mrptype == 1) {
770 $moline->role = 'toconsume';
771 } else {
772 $moline->role = 'toproduce';
773 }
774 }
775
776 $resultline = $moline->create($user, 0); // Never use triggers here
777 if ($resultline <= 0) {
778 $error++;
779 $this->setErrorsFromObject($moline);
780 }
781
782 if ($this->fk_bom > 0 && is_object($bom)) { // If a BOM is defined, we know what to consume.
783 if ($bom->id > 0) {
784 // process lines to consume, this needs to recurse through BOM's
785 $error += $this->processBOM($user, $role, $bom, (float) $this->qty);
786 }
787 }
788
789 if (!$error) {
790 $this->db->commit();
791 return 1;
792 } else {
793 $this->db->rollback();
794 return -1;
795 }
796 }
797
798
808 public function processBOM(User $user, $role, $bom, $quantity)
809 {
810 $error = 0;
811
812 $quantity /= $bom->qty;
813 foreach ($bom->lines as $line) {
814 $quantity_line = !$line->qty_frozen ? $line->qty * $quantity / (!empty($line->efficiency) ? $line->efficiency : 1) : 1;
815
816 $tmpproduct = new Product($this->db);
817 $tmpproduct->fetch($line->fk_product);
818 if ($line->fk_bom_child > 0) {
819 $bom = new BOM($this->db);
820 $bom->fetch((int) $line->fk_bom_child);
821 $error += $this->processBOM($user, $role, $bom, $quantity_line);
822 } else {
823 $moline = new MoLine($this->db);
824 $moline->fk_mo = $this->id;
825 $moline->origin_id = $line->id;
826 $moline->origin_type = 'bomline';
827 if (!empty($line->fk_unit)) {
828 $moline->fk_unit = $line->fk_unit;
829 }
830
831 $moline->qty = (float) price2num($quantity_line, 'MS'); // Calculate with Qty to produce and more presition
832 if ($moline->qty <= 0) {
833 $error++;
834 $this->error = "BadValueForquantityToConsume";
835 $this->errors[] = $this->error;
836 } else {
837 $moline->fk_product = $line->fk_product;
838 //$moline->fk_warehouse = !empty($line->fk_warehouse) ? $line->fk_warehouse : (!empty($bom->fk_warehouse) ? $bom->fk_warehouse : $this->fk_warehouse);
839 if (in_array($role, array('toconsume', 'consumed'))) {
840 $moline->fk_warehouse = null;
841 } else { // to produce / produced
842 $moline->fk_warehouse = $this->fk_warehouse; // We fill the production warehouse defined in MO. Do not use the one of the BOM, if a BOM has a production warehouse set, it should have been already copied into the MO.
843 }
844 $moline->role = $role;
845 $moline->position = $line->position;
846 $moline->qty_frozen = $line->qty_frozen;
847 $moline->disable_stock_change = $line->disable_stock_change;
848 if (!empty($line->fk_default_workstation)) {
849 $moline->fk_default_workstation = $line->fk_default_workstation;
850 }
851
852 $resultline = $moline->create($user, 0); // Never use triggers here
853 //var_dump($moline);
854 if ($resultline <= 0) {
855 $error++;
856 $this->error = $moline->error;
857 $this->errors[] = $moline->error;
858 $this->errors = array_merge($this->errors, $moline->errors);
859 dol_print_error($this->db, $moline->error, $moline->errors);
860 }
861 }
862 }
863 if ($error) {
864 break;
865 }
866 }
867 return $error;
868 }
869
870
878 public function updateProduction(User $user, $notrigger = 0)
879 {
880 $error = 0;
881
882 if ($this->status != self::STATUS_DRAFT) {
883 return 1;
884 }
885
886 $this->db->begin();
887
888 $oldQty = $this->oldQty;
889 $newQty = $this->qty;
890 if ($newQty != $oldQty && !empty($this->oldQty)) {
891 $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "mrp_production WHERE fk_mo = " . (int) $this->id;
892 $resql = $this->db->query($sql);
893 if ($resql) {
894 while ($obj = $this->db->fetch_object($resql)) {
895 $moLine = new MoLine($this->db);
896 $res = $moLine->fetch($obj->rowid);
897 if (!$res) {
898 $error++;
899 }
900
901 if ($moLine->role == 'toconsume' || $moLine->role == 'toproduce') {
902 if (empty($moLine->qty_frozen)) {
903 $qty = $newQty * $moLine->qty / $oldQty;
904 $moLine->qty = (float) price2num($qty, 'MS');
905 $res = $moLine->update($user);
906 if (!$res) {
907 $error++;
908 }
909 }
910 }
911 }
912 }
913 }
914 if (!$error) {
915 $this->db->commit();
916 return 1;
917 } else {
918 $this->db->rollback();
919 return -1;
920 }
921 }
922
923
932 public function delete(User $user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
933 {
934 $error = 0;
935 $this->db->begin();
936
937 if ($also_cancel_consumed_and_produced_lines) {
938 $result = $this->cancelConsumedAndProducedLines($user, 0, false, $notrigger);
939 if ($result < 0) {
940 $error++;
941 }
942 }
943
944 if (!$error) {
945 $result = $this->deleteCommon($user, $notrigger);
946 if ($result < 0) {
947 $error++;
948 }
949 }
950
951 if ($error) {
952 $this->db->rollback();
953 return -1;
954 } else {
955 $this->db->commit();
956 return 1;
957 }
958 }
959
969 public function deleteLine(User $user, $idline, $notrigger = 0, $fk_movement = 0)
970 {
971 global $langs;
972 $langs->loadLangs(array('stocks', 'mrp'));
973
974 if ($this->status < 0) {
975 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
976 return -2;
977 }
978 $productstatic = new Product($this->db);
979
980 $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete
981
982 $result = 0;
983 $error = 0;
984
985 $this->db->begin();
986
987 if (!empty($fk_movement)) {
988 $stockmove = new MouvementStock($this->db);
989 $stockmove->setOrigin($this->element, $this->id);
990
991 // The fk_movement was not recorded so we try to guess the product and quantity to restore.
992 $moline = new MoLine($this->db);
993 $TArrayMoLine = $moline->fetchAll('', '', 1, 0, '(fk_stock_movement:=:'.((int) $fk_movement).')');
994 $moline = array_shift($TArrayMoLine);
995
996 $movement = new MouvementStock($this->db);
997 $movement->fetch($fk_movement);
998 $productstatic->fetch($movement->product_id);
999 $qtytoprocess = $movement->qty;
1000
1001 // Reverse stock movement
1002 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1003 $codemovementCancel = $langs->trans("StockIncrease");
1004
1005 if (($qtytoprocess >= 0)) {
1006 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel);
1007 } else {
1008 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel);
1009 }
1010 if ($idstockmove < 0) {
1011 $this->setErrorsFromObject($stockmove);
1012 } else {
1013 $result = $moline->delete($user, $notrigger);
1014 }
1015 } elseif (!empty($arrayoflines)) {
1016 $stockmove = new MouvementStock($this->db);
1017 $stockmove->setOrigin($this->element, $this->id);
1018
1019 // Loop on each child lines
1020 foreach ($arrayoflines as $key => $arrayofline) {
1021 $lineDetails = $arrayoflines[$key];
1022 $productstatic->fetch($lineDetails['fk_product']);
1023 $qtytoprocess = $lineDetails['qty'];
1024
1025 // Reverse stock movement
1026 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1027 $codemovementCancel = $langs->trans("StockIncrease");
1028
1029
1030 if ($qtytoprocess >= 0) {
1031 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1032 } else {
1033 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1034 }
1035 if ($idstockmove < 0) {
1036 $error++;
1037 $this->setErrorsFromObject($stockmove);
1038 } else {
1039 $moline = new MoLine($this->db);
1040 $moline->fetch($lineDetails['rowid']);
1041
1042 $resdel = $moline->delete($user, $notrigger);
1043 if ($resdel < 0) {
1044 $error++;
1045 $this->setErrorsFromObject($moline);
1046 }
1047 }
1048
1049 if ($error == 0) {
1050 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1051 }
1052 }
1053 } else {
1054 // No child lines and no associated movement
1055 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1056 }
1057
1058 if ($error != 0 || $result <= 0) {
1059 $this->db->rollback();
1060 } else {
1061 $this->db->commit();
1062 }
1063
1064 return $result;
1065 }
1066
1067
1075 public function getNextNumRef($prod)
1076 {
1077 global $langs, $conf;
1078 $langs->load("mrp");
1079
1080 if (getDolGlobalString('MRP_MO_ADDON')) {
1081 $mybool = false;
1082
1083 $file = getDolGlobalString('MRP_MO_ADDON') . ".php";
1084 $classname = getDolGlobalString('MRP_MO_ADDON');
1085
1086 // Include file with class
1087 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1088 foreach ($dirmodels as $reldir) {
1089 $dir = dol_buildpath($reldir."core/modules/mrp/");
1090
1091 // Load file with numbering class (if found)
1092 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1093 }
1094
1095 if (!$mybool) {
1096 dol_print_error(null, "Failed to include file ".$file);
1097 return '';
1098 }
1099
1100 $obj = new $classname();
1101 '@phan-var-force ModeleNumRefMos $obj';
1102 $numref = $obj->getNextValue($prod, $this);
1103
1104 if ($numref != "") {
1105 return $numref;
1106 } else {
1107 $this->error = $obj->error;
1108 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1109 return "";
1110 }
1111 } else {
1112 print $langs->trans("Error")." ".$langs->trans("Error_MRP_MO_ADDON_NotDefined");
1113 return "";
1114 }
1115 }
1116
1124 public function validate($user, $notrigger = 0)
1125 {
1126 global $conf;
1127
1128 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1129
1130 $error = 0;
1131
1132 // Protection
1133 if ($this->status == self::STATUS_VALIDATED) {
1134 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
1135 return 0;
1136 }
1137
1138 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->create))
1139 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->mrp_advance->validate))))
1140 {
1141 $this->error='NotEnoughPermissions';
1142 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
1143 return -1;
1144 }*/
1145
1146 $now = dol_now();
1147
1148 $this->db->begin();
1149
1150 // Define new ref
1151 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
1152 $this->fetch_product();
1153 $num = $this->getNextNumRef($this->product);
1154 } else {
1155 $num = (string) $this->ref;
1156 }
1157 $this->newref = $num;
1158
1159 // Validate
1160 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1161 $sql .= " SET ref = '".$this->db->escape($num)."',";
1162 $sql .= " status = ".self::STATUS_VALIDATED.",";
1163 $sql .= " date_valid = '".$this->db->idate($now)."',";
1164 $sql .= " fk_user_valid = ".((int) $user->id);
1165 $sql .= " WHERE rowid = ".((int) $this->id);
1166
1167 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
1168 $resql = $this->db->query($sql);
1169 if (!$resql) {
1170 dol_print_error($this->db);
1171 $this->error = $this->db->lasterror();
1172 $error++;
1173 }
1174
1175 if (!$error && !$notrigger) {
1176 // Call trigger
1177 $result = $this->call_trigger('MRP_MO_VALIDATE', $user);
1178 if ($result < 0) {
1179 $error++;
1180 }
1181 // End call triggers
1182 }
1183
1184 if (!$error) {
1185 $this->oldref = $this->ref;
1186
1187 // Rename directory if dir was a temporary ref
1188 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
1189 // Now we rename also files into index
1190 $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)."'";
1191 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1192 $resql = $this->db->query($sql);
1193 if (!$resql) {
1194 $error++;
1195 $this->error = $this->db->lasterror();
1196 }
1197 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'mrp/".$this->db->escape($this->newref)."'";
1198 $sql .= " WHERE filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1199 $resql = $this->db->query($sql);
1200 if (!$resql) {
1201 $error++;
1202 $this->error = $this->db->lasterror();
1203 }
1204
1205 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
1206 $oldref = dol_sanitizeFileName($this->ref);
1207 $newref = dol_sanitizeFileName($num);
1208 $dirsource = $conf->mrp->dir_output.'/'.$oldref;
1209 $dirdest = $conf->mrp->dir_output.'/'.$newref;
1210 if (!$error && file_exists($dirsource)) {
1211 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
1212
1213 if (@rename($dirsource, $dirdest)) {
1214 dol_syslog("Rename ok");
1215 // Rename docs starting with $oldref with $newref
1216 $listoffiles = dol_dir_list($conf->mrp->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1217 foreach ($listoffiles as $fileentry) {
1218 $dirsource = $fileentry['name'];
1219 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1220 $dirsource = $fileentry['path'].'/'.$dirsource;
1221 $dirdest = $fileentry['path'].'/'.$dirdest;
1222 @rename($dirsource, $dirdest);
1223 }
1224 }
1225 }
1226 }
1227 }
1228
1229 // Set new ref and current status
1230 if (!$error) {
1231 $this->ref = $num;
1232 $this->status = self::STATUS_VALIDATED;
1233 }
1234
1235 if (!$error) {
1236 $this->db->commit();
1237 return 1;
1238 } else {
1239 $this->db->rollback();
1240 return -1;
1241 }
1242 }
1243
1251 public function setDraft($user, $notrigger = 0)
1252 {
1253 // Protection
1254 if ($this->status <= self::STATUS_DRAFT) {
1255 return 0;
1256 }
1257
1258 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1259 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1260 {
1261 $this->error='Permission denied';
1262 return -1;
1263 }*/
1264
1265 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MRP_MO_UNVALIDATE');
1266 }
1267
1276 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
1277 {
1278 // Protection
1279 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) {
1280 return 0;
1281 }
1282
1283 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1284 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1285 {
1286 $this->error='Permission denied';
1287 return -1;
1288 }*/
1289
1290 $error = 0;
1291 $this->db->begin();
1292
1293 if ($also_cancel_consumed_and_produced_lines) {
1294 $result = $this->cancelConsumedAndProducedLines($user, 0, true, $notrigger);
1295 if ($result < 0) {
1296 $error++;
1297 }
1298 }
1299
1300 if (!$error) {
1301 $result = $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL');
1302 if ($result < 0) {
1303 $error++;
1304 }
1305 }
1306
1307 if ($error) {
1308 $this->db->rollback();
1309 return -1;
1310 } else {
1311 $this->db->commit();
1312 return 1;
1313 }
1314 }
1315
1323 public function reopen($user, $notrigger = 0)
1324 {
1325 // Protection
1326 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) {
1327 return 0;
1328 }
1329
1330 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1331 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1332 {
1333 $this->error='Permission denied';
1334 return -1;
1335 }*/
1336
1337 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MRP_MO_REOPEN');
1338 }
1339
1349 public function cancelConsumedAndProducedLines($user, $mode = 0, $also_delete_lines = false, $notrigger = 0)
1350 {
1351 global $langs;
1352
1353 if (!isModEnabled('stock')) {
1354 return 1;
1355 }
1356
1357 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1358 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
1359 $error = 0;
1360 $langs->load('stocks');
1361
1362 $this->db->begin();
1363
1364 // Cancel consumed lines
1365 if (empty($mode) || $mode == 1) {
1366 $arrayoflines = $this->fetchLinesLinked('consumed');
1367 if (!empty($arrayoflines)) {
1368 foreach ($arrayoflines as $key => $lineDetails) {
1369 $productstatic = new Product($this->db);
1370 $productstatic->fetch($lineDetails['fk_product']);
1371 $qtytoprocess = $lineDetails['qty'];
1372
1373 // Reverse stock movement
1374 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1375 $codemovementCancel = $langs->trans("StockIncrease");
1376
1377 $stockmove = new MouvementStock($this->db);
1378 $stockmove->setOrigin($this->element, $this->id);
1379 if ($qtytoprocess >= 0) {
1380 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1381 } else {
1382 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1383 }
1384 if ($idstockmove < 0) {
1385 $this->error = $stockmove->error;
1386 $this->errors = $stockmove->errors;
1387 $error++;
1388 break;
1389 }
1390
1391 if ($also_delete_lines) {
1392 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1393 if ($result < 0) {
1394 $error++;
1395 break;
1396 }
1397 }
1398 }
1399 }
1400 }
1401
1402 // Cancel produced lines
1403 if (empty($mode) || $mode == 2) {
1404 $arrayoflines = $this->fetchLinesLinked('produced');
1405 if (!empty($arrayoflines)) {
1406 foreach ($arrayoflines as $key => $lineDetails) {
1407 $productstatic = new Product($this->db);
1408 $productstatic->fetch($lineDetails['fk_product']);
1409 $qtytoprocess = $lineDetails['qty'];
1410
1411 // Reverse stock movement
1412 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1413 $codemovementCancel = $langs->trans("StockDecrease");
1414
1415 $stockmove = new MouvementStock($this->db);
1416 $stockmove->setOrigin($this->element, $this->id);
1417 if ($qtytoprocess >= 0) {
1418 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1419 } else {
1420 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1421 }
1422 if ($idstockmove < 0) {
1423 $this->error = $stockmove->error;
1424 $this->errors = $stockmove->errors;
1425 $error++;
1426 break;
1427 }
1428
1429 if ($also_delete_lines) {
1430 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1431 if ($result < 0) {
1432 $error++;
1433 break;
1434 }
1435 }
1436 }
1437 }
1438 }
1439
1440 if ($error) {
1441 $this->db->rollback();
1442 return -1;
1443 } else {
1444 $this->db->commit();
1445 return 1;
1446 }
1447 }
1448
1455 public function getTooltipContentArray($params)
1456 {
1457 global $langs;
1458
1459 $langs->loadLangs(['mrp', 'products']);
1460 $nofetch = isset($params['nofetch']);
1461
1462 $datas = [];
1463
1464 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ManufacturingOrder").'</u>';
1465 if (isset($this->status)) {
1466 $datas['picto'] .= ' '.$this->getLibStatut(5);
1467 }
1468 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1469 if (isset($this->label)) {
1470 $datas['label'] = '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1471 }
1472 if (isset($this->mrptype)) {
1473 $datas['type'] = '<br><b>'.$langs->trans('Type').':</b> '.$this->fields['mrptype']['arrayofkeyval'][$this->mrptype];
1474 }
1475 if (isset($this->qty)) {
1476 $datas['qty'] = '<br><b>'.$langs->trans('QtyToProduce').':</b> '.$this->qty;
1477 }
1478 if (!$nofetch && isset($this->fk_product)) {
1479 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1480 $product = new Product($this->db);
1481 $product->fetch($this->fk_product);
1482 $datas['product'] = '<br><b>'.$langs->trans('Product').':</b> '.$product->getNomUrl(1, '', 0, -1, 1);
1483 }
1484 if (!$nofetch && isset($this->fk_warehouse)) {
1485 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
1486 $warehouse = new Entrepot($this->db);
1487 $warehouse->fetch($this->fk_warehouse);
1488 $datas['warehouse'] = '<br><b>'.$langs->trans('WarehouseForProduction').':</b> '.$warehouse->getNomUrl(1, '', 0, 1);
1489 }
1490
1491 return $datas;
1492 }
1493
1504 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1505 {
1506 global $conf, $langs, $action, $hookmanager;
1507
1508 if (!empty($conf->dol_no_mouse_hover)) {
1509 $notooltip = 1; // Force disable tooltips
1510 }
1511
1512 $result = '';
1513 $params = [
1514 'id' => $this->id,
1515 'objecttype' => $this->element,
1516 'option' => $option,
1517 'nofetch' => 1,
1518 ];
1519 $classfortooltip = 'classfortooltip';
1520 $dataparams = '';
1521 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1522 $classfortooltip = 'classforajaxtooltip';
1523 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1524 $label = '';
1525 } else {
1526 $label = implode($this->getTooltipContentArray($params));
1527 }
1528
1529 $url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$this->id;
1530 if ($option == 'production') {
1531 $url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$this->id;
1532 }
1533
1534 if ($option != 'nolink') {
1535 // Add param to save lastsearch_values or not
1536 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1537 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1538 $add_save_lastsearch_values = 1;
1539 }
1540 if ($add_save_lastsearch_values) {
1541 $url .= '&save_lastsearch_values=1';
1542 }
1543 }
1544
1545 $linkclose = '';
1546 if (empty($notooltip)) {
1547 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1548 $label = $langs->trans("ShowMo");
1549 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1550 }
1551 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1552 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1553 } else {
1554 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1555 }
1556
1557 $linkstart = '<a href="'.$url.'"';
1558 $linkstart .= $linkclose.'>';
1559 $linkend = '</a>';
1560
1561 $result .= $linkstart;
1562 if ($withpicto) {
1563 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
1564 }
1565 if ($withpicto != 2) {
1566 $result .= $this->ref;
1567 }
1568 $result .= $linkend;
1569 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1570
1571 $hookmanager->initHooks(array('modao'));
1572 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1573 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1574 if ($reshook > 0) {
1575 $result = $hookmanager->resPrint;
1576 } else {
1577 $result .= $hookmanager->resPrint;
1578 }
1579
1580 return $result;
1581 }
1582
1589 public function getLibStatut($mode = 0)
1590 {
1591 return $this->LibStatut($this->status, $mode);
1592 }
1593
1594 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1602 public function LibStatut($status, $mode = 0)
1603 {
1604 // phpcs:enable
1605 if (empty($this->labelStatus)) {
1606 global $langs;
1607 //$langs->load("mrp");
1608 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1609 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatedToProduce');
1610 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1611 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1612 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1613
1614 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1615 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1616 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1617 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1618 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1619 }
1620
1621 $statusType = 'status'.$status;
1622 if ($status == self::STATUS_VALIDATED) {
1623 $statusType = 'status1';
1624 }
1625 if ($status == self::STATUS_INPROGRESS) {
1626 $statusType = 'status4';
1627 }
1628 if ($status == self::STATUS_PRODUCED) {
1629 $statusType = 'status6';
1630 }
1631 if ($status == self::STATUS_CANCELED) {
1632 $statusType = 'status9';
1633 }
1634
1635 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1636 }
1637
1644 public function info($id)
1645 {
1646 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1647 $sql .= ' fk_user_creat, fk_user_modif';
1648 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1649 $sql .= ' WHERE t.rowid = '.((int) $id);
1650 $result = $this->db->query($sql);
1651 if ($result) {
1652 if ($this->db->num_rows($result)) {
1653 $obj = $this->db->fetch_object($result);
1654
1655 $this->id = $obj->rowid;
1656
1657 $this->user_creation_id = $obj->fk_user_creat;
1658 $this->user_modification_id = $obj->fk_user_modif;
1659 $this->date_creation = $this->db->jdate($obj->datec);
1660 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1661 }
1662
1663 $this->db->free($result);
1664 } else {
1665 dol_print_error($this->db);
1666 }
1667 }
1668
1675 public function initAsSpecimen()
1676 {
1677 $ret = $this->initAsSpecimenCommon();
1678
1679 $this->lines = array();
1680
1681 return $ret;
1682 }
1683
1690 public function getLinesArray($rolefilter = '')
1691 {
1692 $this->lines = array();
1693
1694 $objectline = new MoLine($this->db);
1695
1696 $filter = '(fk_mo:=:'.((int) $this->id).')';
1697 if (!empty($rolefilter)) {
1698 $filter .= " AND (role:=:'".$this->db->escape($rolefilter)."')";
1699 }
1700 $result = $objectline->fetchAll('ASC', 'position', 0, 0, $filter);
1701
1702 if (is_numeric($result)) {
1703 $this->error = $objectline->error;
1704 $this->errors = $objectline->errors;
1705 return $result;
1706 } else {
1707 $this->lines = $result;
1708 return $this->lines;
1709 }
1710 }
1711
1723 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1724 {
1725 global $langs;
1726
1727 $langs->load("mrp");
1728
1729 if (!dol_strlen($modele)) {
1730 //$modele = 'standard';
1731 $modele = ''; // Remove this once a pdf_standard.php exists.
1732
1733 if ($this->model_pdf) {
1734 $modele = $this->model_pdf;
1735 } elseif (getDolGlobalString('MRP_MO_ADDON_PDF')) {
1736 $modele = getDolGlobalString('MRP_MO_ADDON_PDF');
1737 }
1738 }
1739
1740 $modelpath = "core/modules/mrp/doc/";
1741
1742 if (empty($modele)) {
1743 return 1; // Remove this once a pdf_standard.php exists.
1744 }
1745
1746 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1747 }
1748
1759 public function printOriginLinesList($restrictlist = '', $selectedLines = array())
1760 {
1761 global $langs, $hookmanager, $form, $action;
1762
1763 $langs->load('stocks');
1764 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
1765 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
1766 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
1767 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
1768 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
1769 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
1770 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
1771 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
1772 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
1773
1774 print '<tr class="liste_titre">';
1775 // Product or sub-bom
1776 print '<td class="linecoldescription">'.$langs->trans('Ref');
1777 if (getDolGlobalString('BOM_SUB_BOM')) {
1778 print ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
1779 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
1780 }
1781 print '</td>';
1782 // Qty
1783 print '<td class="right">'.$langs->trans('Qty');
1784 if ($this->bom->bomtype == 0) {
1785 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", (string) $this->bom->qty).')</span>';
1786 } else {
1787 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", (string) $this->bom->qty).')</span>';
1788 }
1789 // Unit
1790 print '<td class="right">'.$langs->trans('Unit');
1791
1792 print '</td>';
1793 print '<td class="center">'.$form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1).'</td>';
1794 print '<td class="center">'.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).'</td>';
1795 print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
1796 print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
1797 print '<td class="center">'.$langs->trans('MoChildGenerate').'</td>';
1798 //print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
1799 //print '<td class="center"></td>';
1800 print '</tr>';
1801 $i = 0;
1802
1803 if (!empty($this->lines)) {
1804 foreach ($this->lines as $line) {
1805 $reshook = 0;
1806 if (is_object($hookmanager)) {
1807 $parameters = array('line' => $line, 'i' => $i, 'restrictlist' => $restrictlist, 'selectedLines' => $selectedLines);
1808 if (!empty($line->fk_parent_line)) {
1809 $parameters['fk_parent_line'] = $line->fk_parent_line;
1810 }
1811 $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1812 }
1813 if (empty($reshook)) {
1814 $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
1815 }
1816
1817 $i++;
1818 }
1819 }
1820 }
1821
1822
1836 public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array())
1837 {
1838 if (!$line instanceof MoLine) {
1839 dol_syslog(__METHOD__.'::pringOriginLine $line is '.get_class($line).'<>MoLine', LOG_WARNING);
1840 parent::printOriginLine($line, $var, $restrictlist, $defaulttpldir, $selectedLines);
1841 return;
1842 }
1843 $productstatic = new Product($this->db);
1844
1845 $this->tpl['id'] = $line->id;
1846
1847 $this->tpl['label'] = '';
1848 if (!empty($line->fk_product) && $line->fk_product > 0) {
1849 $productstatic->fetch($line->fk_product);
1850 $productstatic->load_stock(); // load_virtual_stock() is done in load_stock()
1851 $this->tpl['label'] .= $productstatic->getNomUrl(1);
1852 //$this->tpl['label'].= ' - '.$productstatic->label;
1853 } else {
1854 // If origin MO line is not a product, but another MO
1855 // TODO
1856 }
1857
1858 $this->tpl['qty_bom'] = 1;
1859 if (is_object($this->bom) && $this->bom->qty > 1) {
1860 $this->tpl['qty_bom'] = $this->bom->qty;
1861 }
1862
1863 $this->tpl['stock'] = $productstatic->stock_reel;
1864 $this->tpl['seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1865 $this->tpl['virtual_stock'] = $productstatic->stock_theorique;
1866 $this->tpl['qty'] = $line->qty;
1867 $this->tpl['fk_unit'] = $line->fk_unit;
1868 $this->tpl['qty_frozen'] = $line->qty_frozen;
1869 $this->tpl['disable_stock_change'] = $line->disable_stock_change;
1870 $this->tpl['efficiency'] = $line->efficiency;
1871
1872
1873 global $conf; // used into template
1874 include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php';
1875 }
1876
1885 public static function replaceThirdparty($db, $origin_id, $dest_id)
1886 {
1887 $tables = array('mrp_mo');
1888
1889 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1890 }
1891
1892
1898 public function getMoChilds()
1899 {
1900 $TMoChilds = array();
1901 $error = 0;
1902
1903 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child";
1904 $sql .= " WHERE fk_parent_line IN ";
1905 $sql .= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent";
1906 $sql .= " WHERE fk_mo=".((int) $this->id).")";
1907
1908 $resql = $this->db->query($sql);
1909
1910 if ($resql) {
1911 if ($this->db->num_rows($resql) > 0) {
1912 while ($obj = $this->db->fetch_object($resql)) {
1913 $MoChild = new Mo($this->db);
1914 $res = $MoChild->fetch($obj->rowid);
1915 if ($res > 0) {
1916 $TMoChilds[$MoChild->id] = $MoChild;
1917 } else {
1918 $error++;
1919 }
1920 }
1921 }
1922 } else {
1923 $error++;
1924 }
1925
1926 if ($error) {
1927 return -1;
1928 } else {
1929 return $TMoChilds;
1930 }
1931 }
1932
1939 public function getAllMoChilds($depth = 0)
1940 {
1941 if ($depth > 1000) {
1942 return -1;
1943 }
1944
1945 $TMoChilds = array();
1946 $error = 0;
1947
1948 $childMoList = $this->getMoChilds();
1949
1950 if ($childMoList == -1) {
1951 return -1;
1952 }
1953
1954 foreach ($childMoList as $childMo) {
1955 $TMoChilds[$childMo->id] = $childMo;
1956 }
1957
1958 foreach ($childMoList as $childMo) {
1959 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1960
1961 if ($childMoChildren == -1) {
1962 $error++;
1963 } else {
1964 foreach ($childMoChildren as $child) {
1965 $TMoChilds[$child->id] = $child;
1966 }
1967 }
1968 }
1969
1970 if ($error) {
1971 return -1;
1972 } else {
1973 return $TMoChilds;
1974 }
1975 }
1976
1977
1978
1984 public function getMoParent()
1985 {
1986 $MoParent = new Mo($this->db);
1987 $error = 0;
1988
1989 $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo";
1990 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1991 $sql .= " WHERE mo.rowid = ".((int) $this->id);
1992
1993 $resql = $this->db->query($sql);
1994
1995 if ($resql) {
1996 if ($this->db->num_rows($resql) > 0) {
1997 $obj = $this->db->fetch_object($resql);
1998 $res = $MoParent->fetch($obj->id_moparent);
1999 if ($res < 0) {
2000 $error++;
2001 }
2002 } else {
2003 return 0;
2004 }
2005 } else {
2006 $error++;
2007 }
2008
2009 if ($error) {
2010 return -1;
2011 } else {
2012 return $MoParent;
2013 }
2014 }
2015
2016 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2023 public function load_board($user)
2024 {
2025 // phpcs:enable
2026 global $conf, $langs;
2027 if ($user->socid) {
2028 return -1; // Protection pour éviter appel par utilisateur externe
2029 }
2030
2031 $now = dol_now();
2032
2033 $sql = "SELECT rowid, date_end_planned FROM ".$this->db->prefix()."mrp_mo";
2034 $sql .= " WHERE status IN (" . self::STATUS_VALIDATED . ", " . self::STATUS_INPROGRESS .")"; // 1 = Ouvert, 2 = En cours
2035 $sql .= " AND entity IN (".getEntity('mrp_mo').")";
2036
2037 $resql = $this->db->query($sql);
2038 if ($resql) {
2039 $langs->load("mrp");
2040 $response = new WorkboardResponse();
2041 $warning_delay = $conf->mrp->progress->warning_delay ;
2042 $response->warning_delay = $warning_delay / 86400;
2043 $response->label = $langs->trans("MOProgress");
2044 $response->labelShort = $langs->trans("MOProgress");
2045 $response->url = DOL_URL_ROOT.'/mrp/mo_list.php?search_status=-2';
2046 $response->img = img_object('', "mrp");
2047
2048
2049 while ($obj = $this->db->fetch_object($resql)) {
2050 $response->nbtodo++;
2051
2052 if (!empty($obj->date_end_planned)) {
2053 $date_end_planned = $this->db->jdate($obj->date_end_planned);
2054 if ($now > ($date_end_planned + $warning_delay)) {
2055 $response->nbtodolate++;
2056 $response->url_late = DOL_URL_ROOT.'/mrp/mo_list.php?search_status=-2&search_option=late';
2057 }
2058 }
2059 }
2060
2061 return $response;
2062 } else {
2063 dol_print_error($this->db);
2064 $this->error = $this->db->error();
2065 return -1;
2066 }
2067 }
2068
2074 public function hasDelay()
2075 {
2076 global $conf;
2077
2078 if ($this->status != Mo::STATUS_VALIDATED && $this->status != Mo::STATUS_INPROGRESS) {
2079 return false;
2080 }
2081 if (empty($this->date_end_planned)) {
2082 return false;
2083 }
2084 return (dol_now() > ((int) $this->date_end_planned + $conf->mrp->progress->warning_delay));
2085 }
2086
2087
2095 public function getKanbanView($option = '', $arraydata = null)
2096 {
2097 global $langs;
2098 '@phan-var-force array{selected?:int<0,1>,bom?:Bom,product?:product} $arraydata';
2099
2100 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2101
2102 $return = '<div class="box-flex-item box-flex-grow-zero">';
2103 $return .= '<div class="info-box info-box-sm">';
2104 $return .= '<span class="info-box-icon bg-infobox-action">';
2105 $return .= img_picto('', $this->picto);
2106 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
2107 $return .= '</span>';
2108 $return .= '<div class="info-box-content">';
2109 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2110 if ($selected >= 0) {
2111 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2112 }
2113 if (!empty($arraydata['bom'])) {
2114 $return .= '<br><span class="info-box-label">'.$arraydata['bom']->getNomUrl(1).'</span>';
2115 }
2116 if (!empty($arraydata['product'])) {
2117 $return .= '<br><span class="info-box-label">'.$arraydata['product']->getNomUrl(1).'</span>';
2118 if (property_exists($this, 'qty')) {
2119 $return .= ' <span class="info-box-label">('.$langs->trans("Qty").' '.$this->qty.')</span>';
2120 }
2121 } else {
2122 if (property_exists($this, 'qty')) {
2123 $return .= '<br><span class="info-box-label">'.$langs->trans('Quantity').' : '.$this->qty.'</span>';
2124 }
2125 }
2126 if (method_exists($this, 'getLibStatut')) {
2127 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2128 }
2129 $return .= '</div>';
2130 $return .= '</div>';
2131 $return .= '</div>';
2132 return $return;
2133 }
2134}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$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.
setErrorsFromObject($object)
setErrorsFromObject
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.
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:282
fetchLinesLinked($role, $lineid=0)
Get list of lines linked to current line for a defined role.
Definition mo.class.php:603
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:499
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:322
fetch($id, $ref=null)
Load object in memory from the database.
Definition mo.class.php:482
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
Definition mo.class.php:519
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
processBOM(User $user, $role, $bom, $quantity)
Recurse through BOM only adding products to the list of lines to consume/produce.
Definition mo.class.php:808
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:878
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:690
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:724
deleteLine(User $user, $idline, $notrigger=0, $fk_movement=0)
Delete a line of object in database.
Definition mo.class.php:969
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:655
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition mo.class.php:379
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:64
dol_now($mode='gmt')
Return date for now.
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.