28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/mrp/class/moline.class.php';
39 public $element =
'mo';
44 public $table_element =
'mrp_mo';
49 public $picto =
'mrp';
52 const STATUS_DRAFT = 0;
53 const STATUS_VALIDATED = 1;
54 const STATUS_INPROGRESS = 2;
55 const STATUS_PRODUCED = 3;
56 const STATUS_CANCELED = 9;
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),
143 public $fk_warehouse;
163 public $note_private;
173 public $fk_user_creat;
177 public $fk_user_modif;
200 public $date_start_planned;
205 public $date_end_planned;
234 public $table_element_line =
'mrp_production';
239 public $fk_element =
'fk_mo';
244 public $class_element_line =
'MoLine';
249 protected $childtables = array();
254 protected $childtablesoncascade = array(
'mrp_production');
259 public $lines = array();
269 public $fk_parent_line;
274 public $tpl = array();
282 public $noFlattenBomLineIds = array();
296 $this->ismultientitymanaged = 1;
297 $this->isextrafieldmanaged = 1;
300 $this->fields[
'rowid'][
'visible'] = 0;
302 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
303 $this->fields[
'entity'][
'enabled'] = 0;
307 foreach ($this->fields as $key => $val) {
308 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
309 unset($this->fields[$key]);
314 foreach ($this->fields as $key => $val) {
315 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
316 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
317 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
337 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
338 $tmpproduct =
new Product($this->db);
339 $tmpproduct->fetch((
int) $this->fk_product);
340 if ($tmpproduct->hasFatherOrChild(1) > 0) {
341 $this->error =
'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
342 $this->errors[] = $this->error;
349 if ($this->fk_bom > 0) {
351 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
352 $tmpbom =
new BOM($this->db);
353 $tmpbom->fetch($this->fk_bom);
355 $this->mrptype = $tmpbom->bomtype;
360 if ($idcreated <= 0) {
375 $this->db->rollback();
389 global $langs, $extrafields;
399 $result =
$object->fetchCommon($fromid);
400 if ($result > 0 && !empty(
$object->table_element_line)) {
418 foreach ($TLines as $key => $line) {
419 if (in_array($line->role, array(
'consumed',
'produced'))) {
428 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->fields[
'ref'][
'default'];
430 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".
$object->label : $this->fields[
'label'][
'default'];
431 $object->status = self::STATUS_DRAFT;
434 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
435 $extrafields->fetch_name_optionals_label($this->table_element);
436 foreach (
$object->array_options as $key => $option) {
437 $shortkey = preg_replace(
'/options_/',
'', $key);
438 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
441 unset(
$object->array_options[$key]);
447 $object->context[
'createfromclone'] =
'createfromclone';
448 $result =
$object->createCommon($user);
452 $this->errors =
$object->errors;
464 if (property_exists($this,
'socid') && $this->socid ==
$object->socid) {
471 unset(
$object->context[
'createfromclone']);
478 $this->db->rollback();
490 public function fetch($id, $ref =
null)
493 if ($result > 0 && !empty($this->table_element_line)) {
497 $this->socid = $this->fk_soc;
509 $this->lines = array();
527 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
535 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
536 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
537 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
539 $sql .=
' WHERE 1 = 1';
543 if (is_array($filter)) {
545 if (count($filter) > 0) {
546 foreach ($filter as $key => $value) {
547 if ($key ==
't.rowid') {
548 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
549 } elseif (strpos($key,
'date') !==
false) {
550 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
552 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
556 if (count($sqlwhere) > 0) {
557 $sql .=
' AND ('.implode(
' '.$this->db->sanitize($filtermode).
' ', $sqlwhere).
')';
567 $this->errors[] = $errormessage;
568 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
572 if (!empty($sortfield)) {
573 $sql .= $this->db->order($sortfield, $sortorder);
575 if (!empty($limit)) {
576 $sql .= $this->db->plimit($limit, $offset);
579 $resql = $this->db->query($sql);
581 $num = $this->db->num_rows($resql);
583 while ($i < min($limit, $num)) {
584 $obj = $this->db->fetch_object($resql);
586 $record =
new self($this->db);
587 $record->setVarsFromFetchObj($obj);
589 $records[$record->id] = $record;
593 $this->db->free($resql);
597 $this->errors[] =
'Error '.$this->db->lasterror();
598 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
614 $mostatic =
new MoLine($this->db);
617 $sql .= $mostatic->getFieldList();
618 $sql .=
' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.
' as t';
619 $sql .=
" WHERE t.role = '".$this->db->escape($role).
"'";
621 $sql .=
' AND t.fk_mrp_production = '.((int) $lineid);
623 $sql .=
'AND t.fk_mo = '.((int) $this->
id);
626 $resql = $this->db->query($sql);
628 $num = $this->db->num_rows($resql);
632 $obj = $this->db->fetch_object($resql);
635 'rowid' => (
int) $obj->rowid,
636 'date' => $this->db->jdate($obj->date_creation),
637 'qty' => (
float) $obj->qty,
638 'role' => $obj->role,
639 'fk_product' => $obj->fk_product,
640 'fk_warehouse' => $obj->fk_warehouse,
641 'batch' => $obj->batch,
642 'fk_stock_movement' => $obj->fk_stock_movement,
643 'fk_unit' => $obj->fk_unit
652 $this->error = $this->db->lasterror();
667 $sql =
'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.
'stock_mouvement as sm';
668 $sql .=
" WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->
id);
670 $resql = $this->db->query($sql);
672 $num = $this->db->num_rows($resql);
676 $obj = $this->db->fetch_object($resql);
684 $this->error = $this->db->lasterror();
719 $this->db->rollback();
737 if ($this->
status != self::STATUS_DRAFT) {
738 dol_syslog(
"Bad status for MO object. Can't add production lines. Check that MO has status DRAFT.");
739 $this->error =
"Bad status for MO object. Can't add production lines. Check that MO has status DRAFT.";
747 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'mrp_production WHERE fk_mo = '.((int) $this->
id);
748 $this->db->query($sql);
750 $moline =
new MoLine($this->db);
753 $moline->fk_mo = (int) $this->
id;
754 $moline->qty = (float) $this->qty;
755 $moline->fk_product = (int) $this->fk_product;
756 $moline->fk_warehouse = (int) $this->fk_warehouse;
757 $moline->position = 1;
759 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
760 $tmpproduct =
new Product($this->db);
761 $tmpproduct->fetch((
int) $this->fk_product);
762 $moline->fk_unit = $tmpproduct->fk_unit;
764 if ($this->fk_bom > 0) {
765 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
766 $bom =
new BOM($this->db);
767 $bom->fetch($this->fk_bom);
768 if ($bom->bomtype == 1) {
770 $moline->role =
'toconsume';
773 $moline->role =
'toproduce';
777 if ($this->mrptype == 1) {
778 $moline->role =
'toconsume';
780 $moline->role =
'toproduce';
784 $resultline = $moline->create($user, 0);
785 if ($resultline <= 0) {
790 if ($this->fk_bom > 0 && is_object($bom)) {
793 $error += $this->
processBOM($user, $role, $bom, (
float) $this->qty);
801 $this->db->rollback();
820 $quantity /= $bom->qty;
821 foreach ($bom->lines as $line) {
822 $quantity_line = !$line->qty_frozen ? $line->qty * $quantity / (!empty($line->efficiency) ? $line->efficiency : 1) : 1;
824 $tmpproduct =
new Product($this->db);
825 $tmpproduct->fetch($line->fk_product);
826 if ($line->fk_bom_child > 0 && !in_array($line->id, $this->noFlattenBomLineIds)) {
827 $bom =
new BOM($this->db);
828 $bom->fetch((
int) $line->fk_bom_child);
829 $error += $this->
processBOM($user, $role, $bom, $quantity_line);
831 $moline =
new MoLine($this->db);
832 $moline->fk_mo = $this->id;
833 $moline->origin_id = $line->id;
834 $moline->origin_type =
'bomline';
835 if (!empty($line->fk_unit)) {
836 $moline->fk_unit = $line->fk_unit;
839 $moline->qty = (float)
price2num($quantity_line,
'MS');
840 if ($moline->qty <= 0) {
842 $this->error =
"BadValueForquantityToConsume";
843 $this->errors[] = $this->error;
845 $moline->fk_product = $line->fk_product;
847 if (in_array($role, array(
'toconsume',
'consumed'))) {
848 $moline->fk_warehouse =
null;
850 $moline->fk_warehouse = $this->fk_warehouse;
852 $moline->role = $role;
853 $moline->position = $line->position;
854 $moline->qty_frozen = $line->qty_frozen;
855 $moline->disable_stock_change = $line->disable_stock_change;
856 if (!empty($line->fk_default_workstation)) {
857 $moline->fk_default_workstation = $line->fk_default_workstation;
860 $resultline = $moline->create($user, 0);
862 if ($resultline <= 0) {
864 $this->error = $moline->error;
865 $this->errors[] = $moline->error;
866 $this->errors = array_merge($this->errors, $moline->errors);
890 if ($this->
status != self::STATUS_DRAFT) {
896 $oldQty = $this->oldQty;
897 $newQty = $this->qty;
898 if ($newQty != $oldQty && !empty($this->oldQty)) {
899 $sql =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"mrp_production WHERE fk_mo = " . (int) $this->
id;
900 $resql = $this->db->query($sql);
902 while ($obj = $this->db->fetch_object($resql)) {
903 $moLine =
new MoLine($this->db);
904 $res = $moLine->fetch($obj->rowid);
909 if ($moLine->role ==
'toconsume' || $moLine->role ==
'toproduce') {
910 if (empty($moLine->qty_frozen)) {
911 $qty = $newQty * $moLine->qty / $oldQty;
912 $moLine->qty = (float)
price2num($qty,
'MS');
913 $res = $moLine->update($user);
926 $this->db->rollback();
940 public function delete(
User $user, $notrigger = 0, $also_cancel_consumed_and_produced_lines =
false)
945 if ($also_cancel_consumed_and_produced_lines) {
954 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_mo";
955 $sql .=
" WHERE fk_mo = ".((int) $this->
id);
957 $result = $this->db->query($sql);
960 $this->errors[] = $this->db->lasterror();
972 $this->db->rollback();
989 public function deleteLine(
User $user, $idline, $notrigger = 0, $fk_movement = 0)
992 $langs->loadLangs(array(
'stocks',
'mrp'));
995 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
998 $productstatic =
new Product($this->db);
1007 if (!empty($fk_movement)) {
1009 $stockmove->setOrigin($this->element, $this->
id);
1012 $moline =
new MoLine($this->db);
1013 $TArrayMoLine = $moline->fetchAll(
'',
'', 1, 0,
'(fk_stock_movement:=:'.((
int) $fk_movement).
')');
1014 $moline = array_shift($TArrayMoLine);
1017 $movement->fetch($fk_movement);
1018 $productstatic->fetch($movement->product_id);
1019 $qtytoprocess = $movement->qty;
1022 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1023 $codemovementCancel = $langs->trans(
"StockIncrease");
1025 if (($qtytoprocess >= 0)) {
1026 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
'',
'', $movement->batch,
dol_now(), 0, $codemovementCancel);
1028 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $movement->batch, 0, $codemovementCancel);
1030 if ($idstockmove < 0) {
1033 $result = $moline->delete($user, $notrigger);
1035 } elseif (!empty($arrayoflines)) {
1037 $stockmove->setOrigin($this->element, $this->
id);
1040 foreach ($arrayoflines as $key => $arrayofline) {
1041 $lineDetails = $arrayoflines[$key];
1042 $productstatic->fetch($lineDetails[
'fk_product']);
1043 $qtytoprocess = $lineDetails[
'qty'];
1046 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1047 $codemovementCancel = $langs->trans(
"StockIncrease");
1050 if ($qtytoprocess >= 0) {
1051 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1053 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1055 if ($idstockmove < 0) {
1059 $moline =
new MoLine($this->db);
1060 $moline->fetch($lineDetails[
'rowid']);
1062 $resdel = $moline->delete($user, $notrigger);
1078 if ($error != 0 || $result <= 0) {
1079 $this->db->rollback();
1081 $this->db->commit();
1097 global $langs,
$conf;
1098 $langs->load(
"mrp");
1107 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1108 foreach ($dirmodels as $reldir) {
1112 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1120 $obj =
new $classname();
1121 '@phan-var-force ModeleNumRefMos $obj';
1122 $numref = $obj->getNextValue(
$prod, $this);
1124 if ($numref !=
"") {
1127 $this->error = $obj->error;
1132 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_MRP_MO_ADDON_NotDefined");
1148 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1153 if ($this->
status == self::STATUS_VALIDATED) {
1154 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
1171 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1177 $this->newref = $num;
1180 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1181 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1182 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1183 $sql .=
" date_valid = '".$this->db->idate($now).
"',";
1184 $sql .=
" fk_user_valid = ".((int) $user->id);
1185 $sql .=
" WHERE rowid = ".((int) $this->
id);
1187 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1188 $resql = $this->db->query($sql);
1191 $this->error = $this->db->lasterror();
1195 if (!$error && !$notrigger) {
1197 $result = $this->call_trigger(
'MRP_MO_VALIDATE', $user);
1205 $this->oldref = $this->ref;
1208 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1210 $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).
"'";
1211 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1212 $resql = $this->db->query($sql);
1215 $this->error = $this->db->lasterror();
1217 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'mrp/".$this->db->escape($this->newref).
"'";
1218 $sql .=
" WHERE filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1219 $resql = $this->db->query($sql);
1222 $this->error = $this->db->lasterror();
1228 $dirsource =
$conf->mrp->dir_output.
'/'.$oldref;
1229 $dirdest =
$conf->mrp->dir_output.
'/'.$newref;
1230 if (!$error && file_exists($dirsource)) {
1231 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1233 if (@rename($dirsource, $dirdest)) {
1236 $listoffiles =
dol_dir_list(
$conf->mrp->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1237 foreach ($listoffiles as $fileentry) {
1238 $dirsource = $fileentry[
'name'];
1239 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1240 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1241 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1242 @rename($dirsource, $dirdest);
1252 $this->
status = self::STATUS_VALIDATED;
1256 $this->db->commit();
1259 $this->db->rollback();
1274 if ($this->
status <= self::STATUS_DRAFT) {
1285 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'MRP_MO_UNVALIDATE');
1296 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines =
false)
1299 if ($this->
status != self::STATUS_VALIDATED && $this->
status != self::STATUS_INPROGRESS) {
1313 if ($also_cancel_consumed_and_produced_lines) {
1321 $result = $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'MRP_MO_CANCEL');
1328 $this->db->rollback();
1331 $this->db->commit();
1343 public function reopen($user, $notrigger = 0)
1346 if ($this->
status != self::STATUS_PRODUCED && $this->
status != self::STATUS_CANCELED) {
1357 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'MRP_MO_REOPEN');
1373 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1374 return parent::setCategoriesCommon($categories, Categorie::TYPE_MO);
1394 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1395 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
1397 $langs->load(
'stocks');
1402 if (empty($mode) || $mode == 1) {
1404 if (!empty($arrayoflines)) {
1405 foreach ($arrayoflines as $key => $lineDetails) {
1406 $productstatic =
new Product($this->db);
1407 $productstatic->fetch($lineDetails[
'fk_product']);
1408 $qtytoprocess = $lineDetails[
'qty'];
1411 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1412 $codemovementCancel = $langs->trans(
"StockIncrease");
1415 $stockmove->setOrigin($this->element, $this->
id);
1416 if ($qtytoprocess >= 0) {
1417 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1419 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1421 if ($idstockmove < 0) {
1422 $this->error = $stockmove->error;
1423 $this->errors = $stockmove->errors;
1428 if ($also_delete_lines) {
1429 $result = $this->
deleteLineCommon($user, $lineDetails[
'rowid'], $notrigger);
1440 if (empty($mode) || $mode == 2) {
1442 if (!empty($arrayoflines)) {
1443 foreach ($arrayoflines as $key => $lineDetails) {
1444 $productstatic =
new Product($this->db);
1445 $productstatic->fetch($lineDetails[
'fk_product']);
1446 $qtytoprocess = $lineDetails[
'qty'];
1449 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1450 $codemovementCancel = $langs->trans(
"StockDecrease");
1453 $stockmove->setOrigin($this->element, $this->
id);
1454 if ($qtytoprocess >= 0) {
1455 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1457 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1459 if ($idstockmove < 0) {
1460 $this->error = $stockmove->error;
1461 $this->errors = $stockmove->errors;
1466 if ($also_delete_lines) {
1467 $result = $this->
deleteLineCommon($user, $lineDetails[
'rowid'], $notrigger);
1478 $this->db->rollback();
1481 $this->db->commit();
1496 $langs->loadLangs([
'mrp',
'products']);
1497 $nofetch = isset($params[
'nofetch']);
1501 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ManufacturingOrder").
'</u>';
1502 if (isset($this->
status)) {
1503 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1505 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1506 if (isset($this->label)) {
1507 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1509 if (isset($this->mrptype)) {
1510 $datas[
'type'] =
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->fields[
'mrptype'][
'arrayofkeyval'][$this->mrptype];
1512 if (isset($this->qty)) {
1513 $datas[
'qty'] =
'<br><b>'.$langs->trans(
'QtyToProduce').
':</b> '.$this->qty;
1515 if (!$nofetch && isset($this->fk_product)) {
1516 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1517 $product =
new Product($this->db);
1518 $product->fetch($this->fk_product);
1519 $datas[
'product'] =
'<br><b>'.$langs->trans(
'Product').
':</b> '.$product->getNomUrl(1,
'', 0, -1, 1);
1521 if (!$nofetch && isset($this->fk_warehouse)) {
1522 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
1523 $warehouse =
new Entrepot($this->db);
1524 $warehouse->fetch($this->fk_warehouse);
1525 $datas[
'warehouse'] =
'<br><b>'.$langs->trans(
'WarehouseForProduction').
':</b> '.$warehouse->getNomUrl(1,
'', 0, 1);
1541 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1543 global
$conf, $langs, $action, $hookmanager;
1545 if (!empty(
$conf->dol_no_mouse_hover)) {
1552 'objecttype' => $this->element,
1553 'option' => $option,
1556 $classfortooltip =
'classfortooltip';
1559 $classfortooltip =
'classforajaxtooltip';
1560 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1566 $baseurl = DOL_URL_ROOT.
'/mrp/mo_card.php';
1567 if ($option ==
'production') {
1568 $baseurl = DOL_URL_ROOT.
'/mrp/mo_production.php';
1571 $query = [
'id' => $this->id];
1573 if ($option !=
'nolink') {
1575 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1576 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1577 $add_save_lastsearch_values = 1;
1579 if ($add_save_lastsearch_values) {
1580 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
1586 if (empty($notooltip)) {
1588 $label = $langs->trans(
"ShowMo");
1589 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1591 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1592 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1594 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1597 $linkstart =
'<a href="'.$url.
'"';
1598 $linkstart .= $linkclose.
'>';
1601 $result .= $linkstart;
1603 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1605 if ($withpicto != 2) {
1606 $result .= $this->ref;
1608 $result .= $linkend;
1611 $hookmanager->initHooks(array(
'modao'));
1612 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1613 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1615 $result = $hookmanager->resPrint;
1617 $result .= $hookmanager->resPrint;
1645 if (empty($this->labelStatus)) {
1648 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1649 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ValidatedToProduce');
1650 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1651 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1652 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1654 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1655 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
1656 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1657 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1658 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1661 $statusType =
'status'.$status;
1662 if ($status == self::STATUS_VALIDATED) {
1663 $statusType =
'status1';
1665 if ($status == self::STATUS_INPROGRESS) {
1666 $statusType =
'status4';
1668 if ($status == self::STATUS_PRODUCED) {
1669 $statusType =
'status6';
1671 if ($status == self::STATUS_CANCELED) {
1672 $statusType =
'status9';
1675 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1686 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1687 $sql .=
' fk_user_creat, fk_user_modif';
1688 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1689 $sql .=
' WHERE t.rowid = '.((int) $id);
1690 $result = $this->db->query($sql);
1692 if ($this->db->num_rows($result)) {
1693 $obj = $this->db->fetch_object($result);
1695 $this->
id = $obj->rowid;
1697 $this->user_creation_id = $obj->fk_user_creat;
1698 $this->user_modification_id = $obj->fk_user_modif;
1699 $this->date_creation = $this->db->jdate($obj->datec);
1700 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
1703 $this->db->free($result);
1719 $this->lines = array();
1732 $this->lines = array();
1734 $objectline =
new MoLine($this->db);
1736 $filter =
'(fk_mo:=:'.((int) $this->
id).
')';
1737 if (!empty($rolefilter)) {
1738 $filter .=
" AND (role:=:'".$this->db->escape($rolefilter).
"')";
1740 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, $filter);
1742 if (is_numeric($result)) {
1743 $this->error = $objectline->error;
1744 $this->errors = $objectline->errors;
1747 $this->lines = $result;
1748 return $this->lines;
1763 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1767 $langs->load(
"mrp");
1773 if ($this->model_pdf) {
1774 $modele = $this->model_pdf;
1780 $modelpath =
"core/modules/mrp/doc/";
1782 if (empty($modele)) {
1786 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1801 global $langs, $hookmanager, $form, $action;
1803 $langs->load(
'stocks');
1804 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
1805 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
1806 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
1807 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
1808 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
1809 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
1810 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
1811 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
1812 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
1814 print
'<tr class="liste_titre">';
1816 print
'<td class="linecoldescription">'.$langs->trans(
'Ref');
1818 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
1819 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
1823 print
'<td class="right">'.$langs->trans(
'Qty');
1824 if ($this->bom->bomtype == 0) {
1825 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityOf", (
string) $this->bom->qty).
')</span>';
1827 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityToConsumeOf", (
string) $this->bom->qty).
')</span>';
1830 print
'<td class="right">'.$langs->trans(
'Unit');
1833 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
1834 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
1835 print
'<td class="center">'.$langs->trans(
'QtyFrozen').
'</td>';
1836 print
'<td class="center">'.$langs->trans(
'DisableStockChange').
'</td>';
1837 print
'<td class="center">'.$langs->trans(
'MoChildGenerate').
'</td>';
1843 if (!empty($this->lines)) {
1844 foreach ($this->lines as $line) {
1846 if (is_object($hookmanager)) {
1847 $parameters = array(
'line' => $line,
'i' => $i,
'restrictlist' => $restrictlist,
'selectedLines' => $selectedLines);
1848 if (!empty($line->fk_parent_line)) {
1849 $parameters[
'fk_parent_line'] = $line->fk_parent_line;
1851 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
1853 if (empty($reshook)) {
1854 $this->
printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
1876 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
1878 if (!$line instanceof
MoLine) {
1879 dol_syslog(__METHOD__.
'::pringOriginLine $line is '.get_class($line).
'<>MoLine', LOG_WARNING);
1880 parent::printOriginLine($line, $var, $restrictlist, $defaulttpldir, $selectedLines);
1883 $productstatic =
new Product($this->db);
1885 $this->tpl[
'id'] = $line->id;
1887 $this->tpl[
'label'] =
'';
1888 if (!empty($line->fk_product) && $line->fk_product > 0) {
1889 $productstatic->fetch($line->fk_product);
1890 $productstatic->load_stock();
1891 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
1898 $this->tpl[
'qty_bom'] = 1;
1899 if (is_object($this->bom) && $this->bom->qty > 1) {
1900 $this->tpl[
'qty_bom'] = $this->bom->qty;
1903 $this->tpl[
'stock'] = $productstatic->stock_reel;
1904 $this->tpl[
'seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1905 $this->tpl[
'virtual_stock'] = $productstatic->stock_theorique;
1906 $this->tpl[
'qty'] = $line->qty;
1907 $this->tpl[
'fk_unit'] = $line->fk_unit;
1908 $this->tpl[
'qty_frozen'] = $line->qty_frozen;
1909 $this->tpl[
'disable_stock_change'] = $line->disable_stock_change;
1910 $this->tpl[
'efficiency'] = $line->efficiency;
1914 include DOL_DOCUMENT_ROOT.
'/mrp/tpl/originproductline.tpl.php';
1927 $tables = array(
'mrp_mo');
1940 $TMoChilds = array();
1943 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo_child";
1944 $sql .=
" WHERE fk_parent_line IN ";
1945 $sql .=
" (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_production as line_parent";
1946 $sql .=
" WHERE fk_mo=".((int) $this->
id).
")";
1948 $resql = $this->db->query($sql);
1951 if ($this->db->num_rows($resql) > 0) {
1952 while ($obj = $this->db->fetch_object($resql)) {
1953 $MoChild =
new Mo($this->db);
1954 $res = $MoChild->fetch($obj->rowid);
1956 $TMoChilds[$MoChild->id] = $MoChild;
1981 if ($depth > 1000) {
1985 $TMoChilds = array();
1990 if ($childMoList == -1) {
1994 foreach ($childMoList as $childMo) {
1995 $TMoChilds[$childMo->id] = $childMo;
1998 foreach ($childMoList as $childMo) {
1999 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
2001 if ($childMoChildren == -1) {
2004 foreach ($childMoChildren as $child) {
2005 $TMoChilds[$child->id] = $child;
2026 $MoParent =
new Mo($this->db);
2029 $sql =
"SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo";
2030 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
2031 $sql .=
" WHERE mo.rowid = ".((int) $this->
id);
2033 $resql = $this->db->query($sql);
2036 if ($this->db->num_rows($resql) > 0) {
2037 $obj = $this->db->fetch_object($resql);
2038 $res = $MoParent->fetch($obj->id_moparent);
2066 global
$conf, $langs;
2073 $sql =
"SELECT rowid, date_end_planned FROM ".$this->db->prefix().
"mrp_mo";
2074 $sql .=
" WHERE status IN (" . self::STATUS_VALIDATED .
", " . self::STATUS_INPROGRESS .
")";
2075 $sql .=
" AND entity IN (".getEntity(
'mrp_mo').
")";
2077 $resql = $this->db->query($sql);
2079 $langs->load(
"mrp");
2081 $warning_delay =
$conf->mrp->progress->warning_delay ;
2082 $response->warning_delay = $warning_delay / 86400;
2083 $response->label = $langs->trans(
"MOProgress");
2084 $response->labelShort = $langs->trans(
"MOProgress");
2085 $response->url = DOL_URL_ROOT.
'/mrp/mo_list.php?search_status=-2';
2089 while ($obj = $this->db->fetch_object($resql)) {
2090 $response->nbtodo++;
2092 if (!empty($obj->date_end_planned)) {
2093 $date_end_planned = $this->db->jdate($obj->date_end_planned);
2094 if ($now > ($date_end_planned + $warning_delay)) {
2095 $response->nbtodolate++;
2096 $response->url_late = DOL_URL_ROOT.
'/mrp/mo_list.php?search_status=-2&search_option=late';
2104 $this->error = $this->db->error();
2118 if ($this->
status != Mo::STATUS_VALIDATED && $this->
status != Mo::STATUS_INPROGRESS) {
2121 if (empty($this->date_end_planned)) {
2124 return (
dol_now() > ((
int) $this->date_end_planned +
$conf->mrp->progress->warning_delay));
2138 '@phan-var-force array{selected?:int<0,1>,bom?:Bom,product?:product} $arraydata';
2140 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2142 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2143 $return .=
'<div class="info-box info-box-sm">';
2144 $return .=
'<span class="info-box-icon bg-infobox-action">';
2147 $return .=
'</span>';
2148 $return .=
'<div class="info-box-content">';
2149 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2150 if ($selected >= 0) {
2151 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2153 if (!empty($arraydata[
'bom'])) {
2154 $return .=
'<br><span class="info-box-label">'.$arraydata[
'bom']->getNomUrl(1).
'</span>';
2156 if (!empty($arraydata[
'product'])) {
2157 $return .=
'<br><span class="info-box-label">'.$arraydata[
'product']->getNomUrl(1).
'</span>';
2158 if (property_exists($this,
'qty')) {
2159 $return .=
' <span class="info-box-label">('.$langs->trans(
"Qty").
' '.$this->qty.
')</span>';
2162 if (property_exists($this,
'qty')) {
2163 $return .=
'<br><span class="info-box-label">'.$langs->trans(
'Quantity').
' : '.$this->qty.
'</span>';
2166 if (method_exists($this,
'getLibStatut')) {
2167 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2169 $return .=
'</div>';
2170 $return .=
'</div>';
2171 $return .=
'</div>';
if(! $sortfield) if(! $sortorder) $object
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.
__construct(DoliDB $db)
Constructor.
fetchLinesLinked($role, $lineid=0)
Get list of lines linked to current line for a defined role.
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.
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.
fetch($id, $ref=null)
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
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.
reopen($user, $notrigger=0)
Set back to validated status.
hasDelay()
Is the manufactured delayed?
setCategories($categories)
Sets object to given categories.
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.
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.
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.
deleteLine(User $user, $idline, $notrigger=0, $fk_movement=0)
Delete a line of object in database.
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.
createFromClone(User $user, $fromid)
Clone an object into another one.
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...
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.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string