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 $productstatic = new Product($this->db);
947
948 $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete
949
950 $result = 0;
951
952 $this->db->begin();
953
954 if (!empty($fk_movement)) {
955 $stockmove = new MouvementStock($this->db);
956 $stockmove->setOrigin($this->element, $this->id);
957
958 // The fk_movement was not recorded so we try to guess the product and quantity to restore.
959 $moline = new MoLine($this->db);
960 $TArrayMoLine = $moline->fetchAll('', '', 1, 0, '(fk_stock_movement:=:'.((int) $fk_movement).')');
961 $moline = array_shift($TArrayMoLine);
962
963 $movement = new MouvementStock($this->db);
964 $movement->fetch($fk_movement);
965 $productstatic->fetch($movement->product_id);
966 $qtytoprocess = $movement->qty;
967
968 // Reverse stock movement
969 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
970 $codemovementCancel = $langs->trans("StockIncrease");
971
972 if (($qtytoprocess >= 0)) {
973 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel);
974 } else {
975 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel);
976 }
977 if ($idstockmove < 0) {
978 $this->error++;
979 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
980 } else {
981 $result = $moline->delete($user, $notrigger);
982 }
983 } elseif (!empty($arrayoflines)) {
984 $stockmove = new MouvementStock($this->db);
985 $stockmove->setOrigin($this->element, $this->id);
986
987 // Loop on each child lines
988 foreach ($arrayoflines as $key => $arrayofline) {
989 $lineDetails = $arrayoflines[$key];
990 $productstatic->fetch($lineDetails['fk_product']);
991 $qtytoprocess = $lineDetails['qty'];
992
993 // Reverse stock movement
994 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
995 $codemovementCancel = $langs->trans("StockIncrease");
996
997
998 if ($qtytoprocess >= 0) {
999 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1000 } else {
1001 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1002 }
1003 if ($idstockmove < 0) {
1004 $this->error++;
1005 setEventMessages($stockmove->error, $stockmove->errors, 'errors');
1006 } else {
1007 $moline = new MoLine($this->db);
1008 $moline->fetch($lineDetails['rowid']);
1009
1010 $resdel = $moline->delete($user, $notrigger);
1011 if ($resdel < 0) {
1012 $this->error++;
1013 setEventMessages($moline->error, $moline->errors, 'errors');
1014 }
1015 }
1016 }
1017
1018 if (empty($this->error)) {
1019 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1020 }
1021 } else {
1022 // No child lines and no associated movement
1023 $result = $this->deleteLineCommon($user, $idline, $notrigger);
1024 }
1025
1026 if (!empty($this->error) || $result <= 0) {
1027 $this->db->rollback();
1028 } else {
1029 $this->db->commit();
1030 }
1031
1032 return $result;
1033 }
1034
1035
1043 public function getNextNumRef($prod)
1044 {
1045 global $langs, $conf;
1046 $langs->load("mrp");
1047
1048 if (getDolGlobalString('MRP_MO_ADDON')) {
1049 $mybool = false;
1050
1051 $file = getDolGlobalString('MRP_MO_ADDON') . ".php";
1052 $classname = getDolGlobalString('MRP_MO_ADDON');
1053
1054 // Include file with class
1055 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1056 foreach ($dirmodels as $reldir) {
1057 $dir = dol_buildpath($reldir."core/modules/mrp/");
1058
1059 // Load file with numbering class (if found)
1060 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1061 }
1062
1063 if (!$mybool) {
1064 dol_print_error(null, "Failed to include file ".$file);
1065 return '';
1066 }
1067
1068 $obj = new $classname();
1069 '@phan-var-force ModeleNumRefMos $obj';
1070 $numref = $obj->getNextValue($prod, $this);
1071
1072 if ($numref != "") {
1073 return $numref;
1074 } else {
1075 $this->error = $obj->error;
1076 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1077 return "";
1078 }
1079 } else {
1080 print $langs->trans("Error")." ".$langs->trans("Error_MRP_MO_ADDON_NotDefined");
1081 return "";
1082 }
1083 }
1084
1092 public function validate($user, $notrigger = 0)
1093 {
1094 global $conf;
1095
1096 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1097
1098 $error = 0;
1099
1100 // Protection
1101 if ($this->status == self::STATUS_VALIDATED) {
1102 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
1103 return 0;
1104 }
1105
1106 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->create))
1107 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mrp->mrp_advance->validate))))
1108 {
1109 $this->error='NotEnoughPermissions';
1110 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
1111 return -1;
1112 }*/
1113
1114 $now = dol_now();
1115
1116 $this->db->begin();
1117
1118 // Define new ref
1119 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
1120 $this->fetch_product();
1121 $num = $this->getNextNumRef($this->product);
1122 } else {
1123 $num = $this->ref;
1124 }
1125 $this->newref = $num;
1126
1127 // Validate
1128 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1129 $sql .= " SET ref = '".$this->db->escape($num)."',";
1130 $sql .= " status = ".self::STATUS_VALIDATED.",";
1131 $sql .= " date_valid = '".$this->db->idate($now)."',";
1132 $sql .= " fk_user_valid = ".((int) $user->id);
1133 $sql .= " WHERE rowid = ".((int) $this->id);
1134
1135 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
1136 $resql = $this->db->query($sql);
1137 if (!$resql) {
1138 dol_print_error($this->db);
1139 $this->error = $this->db->lasterror();
1140 $error++;
1141 }
1142
1143 if (!$error && !$notrigger) {
1144 // Call trigger
1145 $result = $this->call_trigger('MRP_MO_VALIDATE', $user);
1146 if ($result < 0) {
1147 $error++;
1148 }
1149 // End call triggers
1150 }
1151
1152 if (!$error) {
1153 $this->oldref = $this->ref;
1154
1155 // Rename directory if dir was a temporary ref
1156 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
1157 // Now we rename also files into index
1158 $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)."'";
1159 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1160 $resql = $this->db->query($sql);
1161 if (!$resql) {
1162 $error++;
1163 $this->error = $this->db->lasterror();
1164 }
1165 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'mrp/".$this->db->escape($this->newref)."'";
1166 $sql .= " WHERE filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
1167 $resql = $this->db->query($sql);
1168 if (!$resql) {
1169 $error++;
1170 $this->error = $this->db->lasterror();
1171 }
1172
1173 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
1174 $oldref = dol_sanitizeFileName($this->ref);
1175 $newref = dol_sanitizeFileName($num);
1176 $dirsource = $conf->mrp->dir_output.'/'.$oldref;
1177 $dirdest = $conf->mrp->dir_output.'/'.$newref;
1178 if (!$error && file_exists($dirsource)) {
1179 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
1180
1181 if (@rename($dirsource, $dirdest)) {
1182 dol_syslog("Rename ok");
1183 // Rename docs starting with $oldref with $newref
1184 $listoffiles = dol_dir_list($conf->mrp->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1185 foreach ($listoffiles as $fileentry) {
1186 $dirsource = $fileentry['name'];
1187 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1188 $dirsource = $fileentry['path'].'/'.$dirsource;
1189 $dirdest = $fileentry['path'].'/'.$dirdest;
1190 @rename($dirsource, $dirdest);
1191 }
1192 }
1193 }
1194 }
1195 }
1196
1197 // Set new ref and current status
1198 if (!$error) {
1199 $this->ref = $num;
1200 $this->status = self::STATUS_VALIDATED;
1201 }
1202
1203 if (!$error) {
1204 $this->db->commit();
1205 return 1;
1206 } else {
1207 $this->db->rollback();
1208 return -1;
1209 }
1210 }
1211
1219 public function setDraft($user, $notrigger = 0)
1220 {
1221 // Protection
1222 if ($this->status <= self::STATUS_DRAFT) {
1223 return 0;
1224 }
1225
1226 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1227 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1228 {
1229 $this->error='Permission denied';
1230 return -1;
1231 }*/
1232
1233 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MRP_MO_UNVALIDATE');
1234 }
1235
1244 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false)
1245 {
1246 // Protection
1247 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) {
1248 return 0;
1249 }
1250
1251 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1252 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1253 {
1254 $this->error='Permission denied';
1255 return -1;
1256 }*/
1257
1258 $error = 0;
1259 $this->db->begin();
1260
1261 if ($also_cancel_consumed_and_produced_lines) {
1262 $result = $this->cancelConsumedAndProducedLines($user, 0, true, $notrigger);
1263 if ($result < 0) {
1264 $error++;
1265 }
1266 }
1267
1268 if (!$error) {
1269 $result = $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL');
1270 if ($result < 0) {
1271 $error++;
1272 }
1273 }
1274
1275 if ($error) {
1276 $this->db->rollback();
1277 return -1;
1278 } else {
1279 $this->db->commit();
1280 return 1;
1281 }
1282 }
1283
1291 public function reopen($user, $notrigger = 0)
1292 {
1293 // Protection
1294 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) {
1295 return 0;
1296 }
1297
1298 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write))
1299 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate))))
1300 {
1301 $this->error='Permission denied';
1302 return -1;
1303 }*/
1304
1305 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MRP_MO_REOPEN');
1306 }
1307
1317 public function cancelConsumedAndProducedLines($user, $mode = 0, $also_delete_lines = false, $notrigger = 0)
1318 {
1319 global $langs;
1320
1321 if (!isModEnabled('stock')) {
1322 return 1;
1323 }
1324
1325 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1326 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
1327 $error = 0;
1328 $langs->load('stocks');
1329
1330 $this->db->begin();
1331
1332 // Cancel consumed lines
1333 if (empty($mode) || $mode == 1) {
1334 $arrayoflines = $this->fetchLinesLinked('consumed');
1335 if (!empty($arrayoflines)) {
1336 foreach ($arrayoflines as $key => $lineDetails) {
1337 $productstatic = new Product($this->db);
1338 $productstatic->fetch($lineDetails['fk_product']);
1339 $qtytoprocess = $lineDetails['qty'];
1340
1341 // Reverse stock movement
1342 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1343 $codemovementCancel = $langs->trans("StockIncrease");
1344
1345 $stockmove = new MouvementStock($this->db);
1346 $stockmove->setOrigin($this->element, $this->id);
1347 if ($qtytoprocess >= 0) {
1348 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1349 } else {
1350 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1351 }
1352 if ($idstockmove < 0) {
1353 $this->error = $stockmove->error;
1354 $this->errors = $stockmove->errors;
1355 $error++;
1356 break;
1357 }
1358
1359 if ($also_delete_lines) {
1360 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1361 if ($result < 0) {
1362 $error++;
1363 break;
1364 }
1365 }
1366 }
1367 }
1368 }
1369
1370 // Cancel produced lines
1371 if (empty($mode) || $mode == 2) {
1372 $arrayoflines = $this->fetchLinesLinked('produced');
1373 if (!empty($arrayoflines)) {
1374 foreach ($arrayoflines as $key => $lineDetails) {
1375 $productstatic = new Product($this->db);
1376 $productstatic->fetch($lineDetails['fk_product']);
1377 $qtytoprocess = $lineDetails['qty'];
1378
1379 // Reverse stock movement
1380 $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref);
1381 $codemovementCancel = $langs->trans("StockDecrease");
1382
1383 $stockmove = new MouvementStock($this->db);
1384 $stockmove->setOrigin($this->element, $this->id);
1385 if ($qtytoprocess >= 0) {
1386 $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel);
1387 } else {
1388 $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel);
1389 }
1390 if ($idstockmove < 0) {
1391 $this->error = $stockmove->error;
1392 $this->errors = $stockmove->errors;
1393 $error++;
1394 break;
1395 }
1396
1397 if ($also_delete_lines) {
1398 $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger);
1399 if ($result < 0) {
1400 $error++;
1401 break;
1402 }
1403 }
1404 }
1405 }
1406 }
1407
1408 if ($error) {
1409 $this->db->rollback();
1410 return -1;
1411 } else {
1412 $this->db->commit();
1413 return 1;
1414 }
1415 }
1416
1423 public function getTooltipContentArray($params)
1424 {
1425 global $langs;
1426
1427 $langs->loadLangs(['mrp', 'products']);
1428 $nofetch = isset($params['nofetch']);
1429
1430 $datas = [];
1431
1432 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ManufacturingOrder").'</u>';
1433 if (isset($this->status)) {
1434 $datas['picto'] .= ' '.$this->getLibStatut(5);
1435 }
1436 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1437 if (isset($this->label)) {
1438 $datas['label'] = '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1439 }
1440 if (isset($this->mrptype)) {
1441 $datas['type'] = '<br><b>'.$langs->trans('Type').':</b> '.$this->fields['mrptype']['arrayofkeyval'][$this->mrptype];
1442 }
1443 if (isset($this->qty)) {
1444 $datas['qty'] = '<br><b>'.$langs->trans('QtyToProduce').':</b> '.$this->qty;
1445 }
1446 if (!$nofetch && isset($this->fk_product)) {
1447 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1448 $product = new Product($this->db);
1449 $product->fetch($this->fk_product);
1450 $datas['product'] = '<br><b>'.$langs->trans('Product').':</b> '.$product->getNomUrl(1, '', 0, -1, 1);
1451 }
1452 if (!$nofetch && isset($this->fk_warehouse)) {
1453 require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
1454 $warehouse = new Entrepot($this->db);
1455 $warehouse->fetch($this->fk_warehouse);
1456 $datas['warehouse'] = '<br><b>'.$langs->trans('WarehouseForProduction').':</b> '.$warehouse->getNomUrl(1, '', 0, 1);
1457 }
1458
1459 return $datas;
1460 }
1461
1472 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1473 {
1474 global $conf, $langs, $action, $hookmanager;
1475
1476 if (!empty($conf->dol_no_mouse_hover)) {
1477 $notooltip = 1; // Force disable tooltips
1478 }
1479
1480 $result = '';
1481 $params = [
1482 'id' => $this->id,
1483 'objecttype' => $this->element,
1484 'option' => $option,
1485 'nofetch' => 1,
1486 ];
1487 $classfortooltip = 'classfortooltip';
1488 $dataparams = '';
1489 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1490 $classfortooltip = 'classforajaxtooltip';
1491 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1492 $label = '';
1493 } else {
1494 $label = implode($this->getTooltipContentArray($params));
1495 }
1496
1497 $url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$this->id;
1498 if ($option == 'production') {
1499 $url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$this->id;
1500 }
1501
1502 if ($option != 'nolink') {
1503 // Add param to save lastsearch_values or not
1504 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1505 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1506 $add_save_lastsearch_values = 1;
1507 }
1508 if ($add_save_lastsearch_values) {
1509 $url .= '&save_lastsearch_values=1';
1510 }
1511 }
1512
1513 $linkclose = '';
1514 if (empty($notooltip)) {
1515 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1516 $label = $langs->trans("ShowMo");
1517 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1518 }
1519 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1520 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1521 } else {
1522 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1523 }
1524
1525 $linkstart = '<a href="'.$url.'"';
1526 $linkstart .= $linkclose.'>';
1527 $linkend = '</a>';
1528
1529 $result .= $linkstart;
1530 if ($withpicto) {
1531 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
1532 }
1533 if ($withpicto != 2) {
1534 $result .= $this->ref;
1535 }
1536 $result .= $linkend;
1537 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1538
1539 $hookmanager->initHooks(array('modao'));
1540 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1541 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1542 if ($reshook > 0) {
1543 $result = $hookmanager->resPrint;
1544 } else {
1545 $result .= $hookmanager->resPrint;
1546 }
1547
1548 return $result;
1549 }
1550
1557 public function getLibStatut($mode = 0)
1558 {
1559 return $this->LibStatut($this->status, $mode);
1560 }
1561
1562 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1570 public function LibStatut($status, $mode = 0)
1571 {
1572 // phpcs:enable
1573 if (empty($this->labelStatus)) {
1574 global $langs;
1575 //$langs->load("mrp");
1576 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1577 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatedToProduce');
1578 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1579 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1580 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1581
1582 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1583 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1584 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress');
1585 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced');
1586 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
1587 }
1588
1589 $statusType = 'status'.$status;
1590 if ($status == self::STATUS_VALIDATED) {
1591 $statusType = 'status1';
1592 }
1593 if ($status == self::STATUS_INPROGRESS) {
1594 $statusType = 'status4';
1595 }
1596 if ($status == self::STATUS_PRODUCED) {
1597 $statusType = 'status6';
1598 }
1599 if ($status == self::STATUS_CANCELED) {
1600 $statusType = 'status9';
1601 }
1602
1603 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1604 }
1605
1612 public function info($id)
1613 {
1614 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1615 $sql .= ' fk_user_creat, fk_user_modif';
1616 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1617 $sql .= ' WHERE t.rowid = '.((int) $id);
1618 $result = $this->db->query($sql);
1619 if ($result) {
1620 if ($this->db->num_rows($result)) {
1621 $obj = $this->db->fetch_object($result);
1622
1623 $this->id = $obj->rowid;
1624
1625 $this->user_creation_id = $obj->fk_user_creat;
1626 $this->user_modification_id = $obj->fk_user_modif;
1627 $this->date_creation = $this->db->jdate($obj->datec);
1628 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1629 }
1630
1631 $this->db->free($result);
1632 } else {
1633 dol_print_error($this->db);
1634 }
1635 }
1636
1643 public function initAsSpecimen()
1644 {
1645 $ret = $this->initAsSpecimenCommon();
1646
1647 $this->lines = array();
1648
1649 return $ret;
1650 }
1651
1658 public function getLinesArray($rolefilter = '')
1659 {
1660 $this->lines = array();
1661
1662 $objectline = new MoLine($this->db);
1663
1664 $filter = '(fk_mo:=:'.((int) $this->id).')';
1665 if (!empty($rolefilter)) {
1666 $filter .= " AND (role:=:'".$this->db->escape($rolefilter)."')";
1667 }
1668 $result = $objectline->fetchAll('ASC', 'position', 0, 0, $filter);
1669
1670 if (is_numeric($result)) {
1671 $this->error = $objectline->error;
1672 $this->errors = $objectline->errors;
1673 return $result;
1674 } else {
1675 $this->lines = $result;
1676 return $this->lines;
1677 }
1678 }
1679
1691 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1692 {
1693 global $langs;
1694
1695 $langs->load("mrp");
1696
1697 if (!dol_strlen($modele)) {
1698 //$modele = 'standard';
1699 $modele = ''; // Remove this once a pdf_standard.php exists.
1700
1701 if ($this->model_pdf) {
1702 $modele = $this->model_pdf;
1703 } elseif (getDolGlobalString('MRP_MO_ADDON_PDF')) {
1704 $modele = getDolGlobalString('MRP_MO_ADDON_PDF');
1705 }
1706 }
1707
1708 $modelpath = "core/modules/mrp/doc/";
1709
1710 if (empty($modele)) {
1711 return 1; // Remove this once a pdf_standard.php exists.
1712 }
1713
1714 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1715 }
1716
1727 public function printOriginLinesList($restrictlist = '', $selectedLines = array())
1728 {
1729 global $langs, $hookmanager, $form, $action;
1730
1731 $langs->load('stocks');
1732 $text_stock_options = $langs->trans("RealStockDesc").'<br>';
1733 $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
1734 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
1735 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
1736 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
1737 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
1738 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
1739 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
1740 $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'<br>' : '');
1741
1742 print '<tr class="liste_titre">';
1743 // Product or sub-bom
1744 print '<td class="linecoldescription">'.$langs->trans('Ref');
1745 if (getDolGlobalString('BOM_SUB_BOM')) {
1746 print ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
1747 print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
1748 }
1749 print '</td>';
1750 // Qty
1751 print '<td class="right">'.$langs->trans('Qty');
1752 if ($this->bom->bomtype == 0) {
1753 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", (string) $this->bom->qty).')</span>';
1754 } else {
1755 print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", (string) $this->bom->qty).')</span>';
1756 }
1757 // Unit
1758 print '<td class="right">'.$langs->trans('Unit');
1759
1760 print '</td>';
1761 print '<td class="center">'.$form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1).'</td>';
1762 print '<td class="center">'.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).'</td>';
1763 print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
1764 print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
1765 print '<td class="center">'.$langs->trans('MoChildGenerate').'</td>';
1766 //print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
1767 //print '<td class="center"></td>';
1768 print '</tr>';
1769 $i = 0;
1770
1771 if (!empty($this->lines)) {
1772 foreach ($this->lines as $line) {
1773 $reshook = 0;
1774 if (is_object($hookmanager)) {
1775 $parameters = array('line' => $line, 'i' => $i, 'restrictlist' => $restrictlist, 'selectedLines' => $selectedLines);
1776 if (!empty($line->fk_parent_line)) {
1777 $parameters['fk_parent_line'] = $line->fk_parent_line;
1778 }
1779 $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1780 }
1781 if (empty($reshook)) {
1782 $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
1783 }
1784
1785 $i++;
1786 }
1787 }
1788 }
1789
1790
1804 public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array())
1805 {
1806 if (!$line instanceof MoLine) {
1807 dol_syslog(__METHOD__.'::pringOriginLine $line is '.get_class($line).'<>MoLine', LOG_WARNING);
1808 parent::printOriginLine($line, $var, $restrictlist, $defaulttpldir, $selectedLines);
1809 return;
1810 }
1811 $productstatic = new Product($this->db);
1812
1813 $this->tpl['id'] = $line->id;
1814
1815 $this->tpl['label'] = '';
1816 if (!empty($line->fk_product) && $line->fk_product > 0) {
1817 $productstatic->fetch($line->fk_product);
1818 $productstatic->load_virtual_stock();
1819 $this->tpl['label'] .= $productstatic->getNomUrl(1);
1820 //$this->tpl['label'].= ' - '.$productstatic->label;
1821 } else {
1822 // If origin MO line is not a product, but another MO
1823 // TODO
1824 }
1825
1826 $this->tpl['qty_bom'] = 1;
1827 if (is_object($this->bom) && $this->bom->qty > 1) {
1828 $this->tpl['qty_bom'] = $this->bom->qty;
1829 }
1830
1831 $this->tpl['stock'] = $productstatic->stock_reel;
1832 $this->tpl['seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1833 $this->tpl['virtual_stock'] = $productstatic->stock_theorique;
1834 $this->tpl['qty'] = $line->qty;
1835 $this->tpl['fk_unit'] = $line->fk_unit;
1836 $this->tpl['qty_frozen'] = $line->qty_frozen;
1837 $this->tpl['disable_stock_change'] = $line->disable_stock_change;
1838 $this->tpl['efficiency'] = $line->efficiency;
1839
1840
1841 global $conf; // used into template
1842 $res = include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php';
1843 }
1844
1853 public static function replaceThirdparty($db, $origin_id, $dest_id)
1854 {
1855 $tables = array('mrp_mo');
1856
1857 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1858 }
1859
1860
1866 public function getMoChilds()
1867 {
1868 $TMoChilds = array();
1869 $error = 0;
1870
1871 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child";
1872 $sql .= " WHERE fk_parent_line IN ";
1873 $sql .= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent";
1874 $sql .= " WHERE fk_mo=".((int) $this->id).")";
1875
1876 $resql = $this->db->query($sql);
1877
1878 if ($resql) {
1879 if ($this->db->num_rows($resql) > 0) {
1880 while ($obj = $this->db->fetch_object($resql)) {
1881 $MoChild = new Mo($this->db);
1882 $res = $MoChild->fetch($obj->rowid);
1883 if ($res > 0) {
1884 $TMoChilds[$MoChild->id] = $MoChild;
1885 } else {
1886 $error++;
1887 }
1888 }
1889 }
1890 } else {
1891 $error++;
1892 }
1893
1894 if ($error) {
1895 return -1;
1896 } else {
1897 return $TMoChilds;
1898 }
1899 }
1900
1907 public function getAllMoChilds($depth = 0)
1908 {
1909 if ($depth > 1000) {
1910 return -1;
1911 }
1912
1913 $TMoChilds = array();
1914 $error = 0;
1915
1916 $childMoList = $this->getMoChilds();
1917
1918 if ($childMoList == -1) {
1919 return -1;
1920 }
1921
1922 foreach ($childMoList as $childMo) {
1923 $TMoChilds[$childMo->id] = $childMo;
1924 }
1925
1926 foreach ($childMoList as $childMo) {
1927 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1928
1929 if ($childMoChildren == -1) {
1930 $error++;
1931 } else {
1932 foreach ($childMoChildren as $child) {
1933 $TMoChilds[$child->id] = $child;
1934 }
1935 }
1936 }
1937
1938 if ($error) {
1939 return -1;
1940 } else {
1941 return $TMoChilds;
1942 }
1943 }
1944
1945
1946
1952 public function getMoParent()
1953 {
1954 $MoParent = new Mo($this->db);
1955 $error = 0;
1956
1957 $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo";
1958 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1959 $sql .= " WHERE mo.rowid = ".((int) $this->id);
1960
1961 $resql = $this->db->query($sql);
1962
1963 if ($resql) {
1964 if ($this->db->num_rows($resql) > 0) {
1965 $obj = $this->db->fetch_object($resql);
1966 $res = $MoParent->fetch($obj->id_moparent);
1967 if ($res < 0) {
1968 $error++;
1969 }
1970 } else {
1971 return 0;
1972 }
1973 } else {
1974 $error++;
1975 }
1976
1977 if ($error) {
1978 return -1;
1979 } else {
1980 return $MoParent;
1981 }
1982 }
1983
1984 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1991 public function load_board($user)
1992 {
1993 // phpcs:enable
1994 global $conf, $langs;
1995 if ($user->socid) {
1996 return -1; // Protection pour éviter appel par utilisateur externe
1997 }
1998
1999 $now = dol_now();
2000
2001 $sql = "SELECT rowid, date_end_planned FROM ".$this->db->prefix()."mrp_mo";
2002 $sql .= " WHERE status IN (" . self::STATUS_VALIDATED . ", " . self::STATUS_INPROGRESS .")"; // 1 = Ouvert, 2 = En cours
2003 $sql .= " AND entity IN (".getEntity('mrp_mo').")";
2004
2005 $resql = $this->db->query($sql);
2006 if ($resql) {
2007 $langs->load("mrp");
2008 $response = new WorkboardResponse();
2009 $warning_delay = $conf->mrp->progress->warning_delay ;
2010 $response->warning_delay = $warning_delay / 86400;
2011 $response->label = $langs->trans("MOProgress");
2012 $response->labelShort = $langs->trans("MOProgress");
2013 $response->url = DOL_URL_ROOT.'/mrp/mo_list.php?search_status=-2';
2014 $response->img = img_object('', "mrp");
2015
2016
2017 while ($obj = $this->db->fetch_object($resql)) {
2018 $response->nbtodo++;
2019
2020 if (!empty($obj->date_end_planned)) {
2021 $date_end_planned = $this->db->jdate($obj->date_end_planned);
2022 if ($now > ($date_end_planned + $warning_delay)) {
2023 $response->nbtodolate++;
2024 $response->url_late = DOL_URL_ROOT.'/mrp/mo_list.php?search_status=-2&search_option=late';
2025 }
2026 }
2027 }
2028
2029 return $response;
2030 } else {
2031 dol_print_error($this->db);
2032 $this->error = $this->db->error();
2033 return -1;
2034 }
2035 }
2036
2042 public function hasDelay()
2043 {
2044 global $conf;
2045
2046 if ($this->status != Mo::STATUS_VALIDATED && $this->status != Mo::STATUS_INPROGRESS) {
2047 return false;
2048 }
2049 if (empty($this->date_end_planned)) {
2050 return false;
2051 }
2052 return (dol_now() > ((int) $this->date_end_planned + $conf->mrp->progress->warning_delay));
2053 }
2054
2055
2063 public function getKanbanView($option = '', $arraydata = null)
2064 {
2065 global $langs;
2066 '@phan-var-force array{selected?:int<0,1>,bom?:Bom,product?:product} $arraydata';
2067
2068 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2069
2070 $return = '<div class="box-flex-item box-flex-grow-zero">';
2071 $return .= '<div class="info-box info-box-sm">';
2072 $return .= '<span class="info-box-icon bg-infobox-action">';
2073 $return .= img_picto('', $this->picto);
2074 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
2075 $return .= '</span>';
2076 $return .= '<div class="info-box-content">';
2077 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2078 if ($selected >= 0) {
2079 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2080 }
2081 if (!empty($arraydata['bom'])) {
2082 $return .= '<br><span class="info-box-label">'.$arraydata['bom']->getNomUrl(1).'</span>';
2083 }
2084 if (!empty($arraydata['product'])) {
2085 $return .= '<br><span class="info-box-label">'.$arraydata['product']->getNomUrl(1).'</span>';
2086 if (property_exists($this, 'qty')) {
2087 $return .= ' <span class="info-box-label">('.$langs->trans("Qty").' '.$this->qty.')</span>';
2088 }
2089 } else {
2090 if (property_exists($this, 'qty')) {
2091 $return .= '<br><span class="info-box-label">'.$langs->trans('Quantity').' : '.$this->qty.'</span>';
2092 }
2093 }
2094 if (method_exists($this, 'getLibStatut')) {
2095 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2096 }
2097 $return .= '</div>';
2098 $return .= '</div>';
2099 $return .= '</div>';
2100 return $return;
2101 }
2102}
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