28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
40 public $element =
'mo';
45 public $table_element =
'mrp_mo';
50 public $picto =
'mrp';
53 const STATUS_DRAFT = 0;
54 const STATUS_VALIDATED = 1;
55 const STATUS_INPROGRESS = 2;
56 const STATUS_PRODUCED = 3;
57 const STATUS_CANCELED = 9;
89 public $fields = array(
90 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'position' => 1,
'notnull' => 1,
'index' => 1,
'comment' =>
"Id",),
91 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'position' => 5,
'notnull' => 1,
'default' =>
'1',
'index' => 1),
92 '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),
93 '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'),
94 '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'),
95 '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'),
96 'qty' => array(
'type' =>
'real',
'label' =>
'QtyToProduce',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'notnull' => 1,
'comment' =>
"Qty to produce",
'css' =>
'width75',
'default' =>
'1',
'isameasure' => 1),
97 '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),
98 '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'),
99 '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'),
100 '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'),
101 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 61,
'notnull' => -1,),
102 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 62,
'notnull' => -1,),
103 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'position' => 500,
'notnull' => 1,),
104 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'position' => 501,
'notnull' => 1,),
105 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -2,
'position' => 502,),
106 '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'),
107 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'position' => 511,
'notnull' => -1,
'csslist' =>
'tdoverflowmax100'),
108 'date_start_planned' => array(
'type' =>
'datetime',
'label' =>
'DateStartPlannedMo',
'enabled' => 1,
'visible' => 1,
'position' => 55,
'notnull' => -1,
'index' => 1,
'help' =>
'KeepEmptyForAsap',
'alwayseditable' => 1,
'csslist' =>
'nowraponall'),
109 'date_end_planned' => array(
'type' =>
'datetime',
'label' =>
'DateEndPlannedMo',
'enabled' => 1,
'visible' => 1,
'position' => 56,
'notnull' => -1,
'index' => 1,
'alwayseditable' => 1,
'csslist' =>
'nowraponall'),
110 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 1000,
'notnull' => -1,),
111 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 1010),
112 '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')),
113 '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),
129 public $fk_warehouse;
141 public $note_private;
148 public $fk_user_creat;
149 public $fk_user_modif;
166 public $date_start_planned;
171 public $date_end_planned;
200 public $table_element_line =
'mrp_production';
205 public $fk_element =
'fk_mo';
210 public $class_element_line =
'MoLine';
215 protected $childtables = array();
220 protected $childtablesoncascade = array(
'mrp_production');
225 public $lines = array();
235 public $fk_parent_line;
240 public $tpl = array();
254 $this->ismultientitymanaged = 1;
255 $this->isextrafieldmanaged = 1;
258 $this->fields[
'rowid'][
'visible'] = 0;
260 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
261 $this->fields[
'entity'][
'enabled'] = 0;
265 foreach ($this->fields as $key => $val) {
266 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
267 unset($this->fields[$key]);
272 foreach ($this->fields as $key => $val) {
273 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
274 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
275 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
295 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
296 $tmpproduct =
new Product($this->db);
297 $tmpproduct->fetch($this->fk_product);
298 if ($tmpproduct->hasFatherOrChild(1) > 0) {
299 $this->error =
'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
300 $this->errors[] = $this->error;
307 if ($this->fk_bom > 0) {
309 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
310 $tmpbom =
new BOM($this->db);
311 $tmpbom->fetch($this->fk_bom);
313 $this->mrptype = $tmpbom->bomtype;
318 if ($idcreated <= 0) {
334 $this->db->rollback();
348 global $langs, $extrafields;
358 $result =
$object->fetchCommon($fromid);
359 if ($result > 0 && !empty(
$object->table_element_line)) {
377 foreach ($TLines as $key => $line) {
378 if (in_array($line->role, array(
'consumed',
'produced'))) {
387 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->fields[
'ref'][
'default'];
388 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".
$object->label : $this->fields[
'label'][
'default'];
389 $object->status = self::STATUS_DRAFT;
392 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
393 $extrafields->fetch_name_optionals_label($this->table_element);
394 foreach (
$object->array_options as $key => $option) {
395 $shortkey = preg_replace(
'/options_/',
'', $key);
396 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
399 unset(
$object->array_options[$key]);
405 $object->context[
'createfromclone'] =
'createfromclone';
406 $result =
$object->createCommon($user);
410 $this->errors =
$object->errors;
422 if (property_exists($this,
'socid') && $this->socid ==
$object->socid) {
429 unset(
$object->context[
'createfromclone']);
436 $this->db->rollback();
448 public function fetch($id, $ref =
null)
451 if ($result > 0 && !empty($this->table_element_line)) {
455 $this->socid = $this->fk_soc;
467 $this->lines = array();
485 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
493 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
494 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
495 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
497 $sql .=
' WHERE 1 = 1';
501 if (is_array($filter)) {
503 if (count($filter) > 0) {
504 foreach ($filter as $key => $value) {
505 if ($key ==
't.rowid') {
506 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
507 } elseif (strpos($key,
'date') !==
false) {
508 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate($value).
"'";
510 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
514 if (count($sqlwhere) > 0) {
515 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
525 $this->errors[] = $errormessage;
526 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
530 if (!empty($sortfield)) {
531 $sql .= $this->db->order($sortfield, $sortorder);
533 if (!empty($limit)) {
534 $sql .= $this->db->plimit($limit, $offset);
537 $resql = $this->db->query($sql);
539 $num = $this->db->num_rows($resql);
541 while ($i < min($limit, $num)) {
542 $obj = $this->db->fetch_object($resql);
544 $record =
new self($this->db);
545 $record->setVarsFromFetchObj($obj);
547 $records[$record->id] = $record;
551 $this->db->free($resql);
555 $this->errors[] =
'Error '.$this->db->lasterror();
556 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
572 $mostatic =
new MoLine($this->db);
575 $sql .= $mostatic->getFieldList();
576 $sql .=
' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.
' as t';
577 $sql .=
" WHERE t.role = '".$this->db->escape($role).
"'";
579 $sql .=
' AND t.fk_mrp_production = '.((int) $lineid);
581 $sql .=
'AND t.fk_mo = '.((int) $this->
id);
584 $resql = $this->db->query($sql);
586 $num = $this->db->num_rows($resql);
590 $obj = $this->db->fetch_object($resql);
593 'rowid' => $obj->rowid,
594 'date' => $this->db->jdate($obj->date_creation),
596 'role' => $obj->role,
597 'fk_product' => $obj->fk_product,
598 'fk_warehouse' => $obj->fk_warehouse,
599 'batch' => $obj->batch,
600 'fk_stock_movement' => $obj->fk_stock_movement,
601 'fk_unit' => $obj->fk_unit
610 $this->error = $this->db->lasterror();
625 $sql =
'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.
'stock_mouvement as sm';
626 $sql .=
" WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->
id);
628 $resql = $this->db->query($sql);
630 $num = $this->db->num_rows($resql);
634 $obj = $this->db->fetch_object($resql);
642 $this->error = $this->db->lasterror();
677 $this->db->rollback();
695 if ($this->
status != self::STATUS_DRAFT) {
703 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'mrp_production WHERE fk_mo = '.((int) $this->
id);
704 $this->db->query($sql);
706 $moline =
new MoLine($this->db);
709 $moline->fk_mo = $this->id;
710 $moline->qty = $this->qty;
711 $moline->fk_product = $this->fk_product;
712 $moline->position = 1;
713 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
714 $tmpproduct =
new Product($this->db);
715 $tmpproduct->fetch($this->fk_product);
716 $moline->fk_unit = $tmpproduct->fk_unit;
718 if ($this->fk_bom > 0) {
719 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
720 $bom =
new BOM($this->db);
721 $bom->fetch($this->fk_bom);
722 if ($bom->bomtype == 1) {
724 $moline->role =
'toconsume';
727 $moline->role =
'toproduce';
730 if ($this->mrptype == 1) {
731 $moline->role =
'toconsume';
733 $moline->role =
'toproduce';
737 $resultline = $moline->create($user,
false);
738 if ($resultline <= 0) {
740 $this->error = $moline->error;
741 $this->errors = $moline->errors;
744 if ($this->fk_bom > 0) {
748 foreach ($bom->lines as $line) {
749 $moline =
new MoLine($this->db);
751 $moline->fk_mo = $this->id;
752 $moline->origin_id = $line->id;
753 $moline->origin_type =
'bomline';
754 if (!empty($line->fk_unit)) {
755 $moline->fk_unit = $line->fk_unit;
757 if ($line->qty_frozen) {
758 $moline->qty = $line->qty;
760 $moline->qty = (float)
price2num(($line->qty / (!empty($bom->qty) ? $bom->qty : 1)) * $this->qty / (!empty($line->efficiency) ? $line->efficiency : 1),
'MS');
762 if ($moline->qty <= 0) {
764 $this->error =
"BadValueForquantityToConsume";
767 $moline->fk_product = $line->fk_product;
768 $moline->role = $role;
769 $moline->position = $line->position;
770 $moline->qty_frozen = $line->qty_frozen;
771 $moline->disable_stock_change = $line->disable_stock_change;
772 if (!empty($line->fk_default_workstation)) {
773 $moline->fk_default_workstation = $line->fk_default_workstation;
776 $resultline = $moline->create($user,
false);
777 if ($resultline <= 0) {
779 $this->error = $moline->error;
780 $this->errors = $moline->errors;
795 $this->db->rollback();
811 if ($this->
status != self::STATUS_DRAFT) {
817 $oldQty = $this->oldQty;
818 $newQty = $this->qty;
819 if ($newQty != $oldQty && !empty($this->oldQty)) {
820 $sql =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"mrp_production WHERE fk_mo = " . (int) $this->
id;
821 $resql = $this->db->query($sql);
823 while ($obj = $this->db->fetch_object($resql)) {
824 $moLine =
new MoLine($this->db);
825 $res = $moLine->fetch($obj->rowid);
830 if ($moLine->role ==
'toconsume' || $moLine->role ==
'toproduce') {
831 if (empty($moLine->qty_frozen)) {
832 $qty = $newQty * $moLine->qty / $oldQty;
833 $moLine->qty = (float)
price2num($qty,
'MS');
834 $res = $moLine->update($user);
847 $this->db->rollback();
861 public function delete(
User $user, $notrigger = 0, $also_cancel_consumed_and_produced_lines =
false)
866 if ($also_cancel_consumed_and_produced_lines) {
881 $this->db->rollback();
898 public function deleteLine(
User $user, $idline, $notrigger = 0, $fk_movement = 0)
901 $langs->loadLangs(array(
'stocks',
'mrp'));
904 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
907 $productstatic =
new Product($this->db);
915 if (!empty($arrayoflines)) {
918 $stockmove->setOrigin($this->element, $this->
id);
920 if (!empty($fk_movement)) {
922 $moline =
new MoLine($this->db);
923 $TArrayMoLine = $moline->fetchAll(
'',
'', 1, 0,
'(fk_stock_movement:=:'.((
int) $fk_movement).
')');
924 $moline = array_shift($TArrayMoLine);
927 $movement->fetch($fk_movement);
928 $productstatic->fetch($movement->product_id);
929 $qtytoprocess = $movement->qty;
932 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
933 $codemovementCancel = $langs->trans(
"StockIncrease");
935 if (($qtytoprocess >= 0)) {
936 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
'',
'', $movement->batch,
dol_now(), 0, $codemovementCancel);
938 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $movement->batch, 0, $codemovementCancel);
940 if ($idstockmove < 0) {
944 $result = $moline->delete($user, $notrigger);
948 foreach ($arrayoflines as $key => $arrayofline) {
949 $lineDetails = $arrayoflines[$key];
950 $productstatic->fetch($lineDetails[
'fk_product']);
951 $qtytoprocess = $lineDetails[
'qty'];
954 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
955 $codemovementCancel = $langs->trans(
"StockIncrease");
958 if ($qtytoprocess >= 0) {
959 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
961 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
963 if ($idstockmove < 0) {
967 $moline =
new MoLine($this->db);
968 $moline->fetch($lineDetails[
'rowid']);
970 $resdel = $moline->delete($user, $notrigger);
978 if (empty($this->error)) {
987 if (!empty($this->error) || $result <= 0) {
988 $this->db->rollback();
1006 global $langs, $conf;
1007 $langs->load(
"mrp");
1016 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1017 foreach ($dirmodels as $reldir) {
1021 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1024 if ($mybool ===
false) {
1029 $obj =
new $classname();
1030 $numref = $obj->getNextValue($prod, $this);
1032 if ($numref !=
"") {
1035 $this->error = $obj->error;
1040 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_MRP_MO_ADDON_NotDefined");
1056 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1061 if ($this->
status == self::STATUS_VALIDATED) {
1062 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
1079 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1085 $this->newref = $num;
1088 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1089 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1090 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1091 $sql .=
" date_valid='".$this->db->idate($now).
"',";
1092 $sql .=
" fk_user_valid = ".$user->id;
1093 $sql .=
" WHERE rowid = ".((int) $this->
id);
1095 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1096 $resql = $this->db->query($sql);
1099 $this->error = $this->db->lasterror();
1103 if (!$error && !$notrigger) {
1105 $result = $this->
call_trigger(
'MRP_MO_VALIDATE', $user);
1113 $this->oldref = $this->ref;
1116 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1118 $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).
"'";
1119 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1120 $resql = $this->db->query($sql);
1123 $this->error = $this->db->lasterror();
1125 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'mrp/".$this->db->escape($this->newref).
"'";
1126 $sql .=
" WHERE filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1127 $resql = $this->db->query($sql);
1130 $this->error = $this->db->lasterror();
1136 $dirsource = $conf->mrp->dir_output.
'/'.$oldref;
1137 $dirdest = $conf->mrp->dir_output.
'/'.$newref;
1138 if (!$error && file_exists($dirsource)) {
1139 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1141 if (@rename($dirsource, $dirdest)) {
1144 $listoffiles =
dol_dir_list($conf->mrp->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1145 foreach ($listoffiles as $fileentry) {
1146 $dirsource = $fileentry[
'name'];
1147 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1148 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1149 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1150 @rename($dirsource, $dirdest);
1160 $this->
status = self::STATUS_VALIDATED;
1164 $this->db->commit();
1167 $this->db->rollback();
1182 if ($this->
status <= self::STATUS_DRAFT) {
1193 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'MRP_MO_UNVALIDATE');
1204 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines =
false)
1207 if ($this->
status != self::STATUS_VALIDATED && $this->
status != self::STATUS_INPROGRESS) {
1221 if ($also_cancel_consumed_and_produced_lines) {
1229 $result = $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'MRP_MO_CANCEL');
1236 $this->db->rollback();
1239 $this->db->commit();
1251 public function reopen($user, $notrigger = 0)
1254 if ($this->
status != self::STATUS_PRODUCED && $this->
status != self::STATUS_CANCELED) {
1265 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'MRP_MO_REOPEN');
1281 if (!isModEnabled(
'stock')) {
1285 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1286 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
1288 $langs->load(
'stocks');
1293 if (empty($mode) || $mode == 1) {
1295 if (!empty($arrayoflines)) {
1296 foreach ($arrayoflines as $key => $lineDetails) {
1297 $productstatic =
new Product($this->db);
1298 $productstatic->fetch($lineDetails[
'fk_product']);
1299 $qtytoprocess = $lineDetails[
'qty'];
1302 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1303 $codemovementCancel = $langs->trans(
"StockIncrease");
1306 $stockmove->setOrigin($this->element, $this->
id);
1307 if ($qtytoprocess >= 0) {
1308 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1310 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1312 if ($idstockmove < 0) {
1313 $this->error = $stockmove->error;
1314 $this->errors = $stockmove->errors;
1319 if ($also_delete_lines) {
1320 $result = $this->
deleteLineCommon($user, $lineDetails[
'rowid'], $notrigger);
1331 if (empty($mode) || $mode == 2) {
1333 if (!empty($arrayoflines)) {
1334 foreach ($arrayoflines as $key => $lineDetails) {
1335 $productstatic =
new Product($this->db);
1336 $productstatic->fetch($lineDetails[
'fk_product']);
1337 $qtytoprocess = $lineDetails[
'qty'];
1340 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1341 $codemovementCancel = $langs->trans(
"StockDecrease");
1344 $stockmove->setOrigin($this->element, $this->
id);
1345 if ($qtytoprocess >= 0) {
1346 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1348 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1350 if ($idstockmove < 0) {
1351 $this->error = $stockmove->error;
1352 $this->errors = $stockmove->errors;
1357 if ($also_delete_lines) {
1358 $result = $this->
deleteLineCommon($user, $lineDetails[
'rowid'], $notrigger);
1369 $this->db->rollback();
1372 $this->db->commit();
1388 $langs->loadLangs([
'mrp',
'products']);
1389 $nofetch = isset($params[
'nofetch']) ? true :
false;
1393 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ManufacturingOrder").
'</u>';
1394 if (isset($this->
status)) {
1395 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1397 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1398 if (isset($this->label)) {
1399 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1401 if (isset($this->mrptype)) {
1402 $datas[
'type'] =
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->fields[
'mrptype'][
'arrayofkeyval'][$this->mrptype];
1404 if (isset($this->qty)) {
1405 $datas[
'qty'] =
'<br><b>'.$langs->trans(
'QtyToProduce').
':</b> '.$this->qty;
1407 if (!$nofetch && isset($this->fk_product)) {
1408 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1409 $product =
new Product($this->db);
1410 $product->fetch($this->fk_product);
1411 $datas[
'product'] =
'<br><b>'.$langs->trans(
'Product').
':</b> '.$product->getNomUrl(1,
'', 0, -1, 1);
1413 if (!$nofetch && isset($this->fk_warehouse)) {
1414 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
1415 $warehouse =
new Entrepot($this->db);
1416 $warehouse->fetch($this->fk_warehouse);
1417 $datas[
'warehouse'] =
'<br><b>'.$langs->trans(
'WarehouseForProduction').
':</b> '.$warehouse->getNomUrl(1,
'', 0, 1);
1433 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1435 global $conf, $langs, $action, $hookmanager;
1437 if (!empty($conf->dol_no_mouse_hover)) {
1444 'objecttype' => $this->element,
1445 'option' => $option,
1448 $classfortooltip =
'classfortooltip';
1451 $classfortooltip =
'classforajaxtooltip';
1452 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1458 $url = DOL_URL_ROOT.
'/mrp/mo_card.php?id='.$this->id;
1459 if ($option ==
'production') {
1460 $url = DOL_URL_ROOT.
'/mrp/mo_production.php?id='.$this->id;
1463 if ($option !=
'nolink') {
1465 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1466 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1467 $add_save_lastsearch_values = 1;
1469 if ($add_save_lastsearch_values) {
1470 $url .=
'&save_lastsearch_values=1';
1475 if (empty($notooltip)) {
1477 $label = $langs->trans(
"ShowMo");
1478 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1480 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1481 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1483 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1486 $linkstart =
'<a href="'.$url.
'"';
1487 $linkstart .= $linkclose.
'>';
1490 $result .= $linkstart;
1492 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1494 if ($withpicto != 2) {
1495 $result .= $this->ref;
1497 $result .= $linkend;
1500 $hookmanager->initHooks(array(
'modao'));
1501 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1502 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1504 $result = $hookmanager->resPrint;
1506 $result .= $hookmanager->resPrint;
1534 if (empty($this->labelStatus)) {
1537 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1538 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ValidatedToProduce');
1539 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1540 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1541 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1543 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1544 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
1545 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1546 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1547 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1550 $statusType =
'status'.$status;
1551 if ($status == self::STATUS_VALIDATED) {
1552 $statusType =
'status1';
1554 if ($status == self::STATUS_INPROGRESS) {
1555 $statusType =
'status4';
1557 if ($status == self::STATUS_PRODUCED) {
1558 $statusType =
'status6';
1560 if ($status == self::STATUS_CANCELED) {
1561 $statusType =
'status9';
1564 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1575 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1576 $sql .=
' fk_user_creat, fk_user_modif';
1577 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1578 $sql .=
' WHERE t.rowid = '.((int) $id);
1579 $result = $this->db->query($sql);
1581 if ($this->db->num_rows($result)) {
1582 $obj = $this->db->fetch_object($result);
1584 $this->
id = $obj->rowid;
1586 $this->user_creation_id = $obj->fk_user_creat;
1587 $this->user_modification_id = $obj->fk_user_modif;
1588 $this->date_creation = $this->db->jdate($obj->datec);
1589 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
1592 $this->db->free($result);
1608 $this->lines = array();
1621 $this->lines = array();
1623 $objectline =
new MoLine($this->db);
1625 $filter =
'(fk_mo:=:'.((int) $this->
id).
')';
1626 if (!empty($rolefilter)) {
1627 $filter .=
" AND (role:=:'".$this->db->escape($rolefilter).
"')";
1629 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, $filter);
1631 if (is_numeric($result)) {
1632 $this->error = $objectline->error;
1633 $this->errors = $objectline->errors;
1636 $this->lines = $result;
1637 return $this->lines;
1652 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1656 $langs->load(
"mrp");
1662 if ($this->model_pdf) {
1663 $modele = $this->model_pdf;
1669 $modelpath =
"core/modules/mrp/doc/";
1671 if (empty($modele)) {
1675 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1690 global $langs, $hookmanager, $form, $action;
1692 $langs->load(
'stocks');
1693 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
1694 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
1695 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
1696 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
1697 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
1698 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
1699 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
1700 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
1701 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
1703 print
'<tr class="liste_titre">';
1705 print
'<td class="linecoldescription">'.$langs->trans(
'Ref');
1707 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
1708 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
1712 print
'<td class="right">'.$langs->trans(
'Qty');
1713 if ($this->bom->bomtype == 0) {
1714 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityOf", $this->bom->qty).
')</span>';
1716 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityToConsumeOf", $this->bom->qty).
')</span>';
1719 print
'<td class="right">'.$langs->trans(
'Unit');
1722 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
1723 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
1724 print
'<td class="center">'.$langs->trans(
'QtyFrozen').
'</td>';
1725 print
'<td class="center">'.$langs->trans(
'DisableStockChange').
'</td>';
1726 print
'<td class="center">'.$langs->trans(
'MoChildGenerate').
'</td>';
1732 if (!empty($this->lines)) {
1733 foreach ($this->lines as $line) {
1735 if (is_object($hookmanager)) {
1736 $parameters = array(
'line' => $line,
'i' => $i,
'restrictlist' => $restrictlist,
'selectedLines' => $selectedLines);
1737 if (!empty($line->fk_parent_line)) {
1738 $parameters[
'fk_parent_line'] = $line->fk_parent_line;
1740 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
1742 if (empty($reshook)) {
1743 $this->
printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
1765 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
1767 $productstatic =
new Product($this->db);
1769 $this->tpl[
'id'] = $line->id;
1771 $this->tpl[
'label'] =
'';
1772 if (!empty($line->fk_product) && $line->fk_product > 0) {
1773 $productstatic->fetch($line->fk_product);
1774 $productstatic->load_virtual_stock();
1775 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
1782 $this->tpl[
'qty_bom'] = 1;
1783 if (is_object($this->bom) && $this->bom->qty > 1) {
1784 $this->tpl[
'qty_bom'] = $this->bom->qty;
1787 $this->tpl[
'stock'] = $productstatic->stock_reel;
1788 $this->tpl[
'seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1789 $this->tpl[
'virtual_stock'] = $productstatic->stock_theorique;
1790 $this->tpl[
'qty'] = $line->qty;
1791 $this->tpl[
'fk_unit'] = $line->fk_unit;
1792 $this->tpl[
'qty_frozen'] = $line->qty_frozen;
1793 $this->tpl[
'disable_stock_change'] = $line->disable_stock_change;
1794 $this->tpl[
'efficiency'] = $line->efficiency;
1797 $res = include DOL_DOCUMENT_ROOT.
'/mrp/tpl/originproductline.tpl.php';
1810 $tables = array(
'mrp_mo');
1823 $TMoChilds = array();
1826 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo_child";
1827 $sql .=
" WHERE fk_parent_line IN ";
1828 $sql .=
" (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_production as line_parent";
1829 $sql .=
" WHERE fk_mo=".((int) $this->
id).
")";
1831 $resql = $this->db->query($sql);
1834 if ($this->db->num_rows($resql) > 0) {
1835 while ($obj = $this->db->fetch_object($resql)) {
1836 $MoChild =
new Mo($this->db);
1837 $res = $MoChild->fetch($obj->rowid);
1839 $TMoChilds[$MoChild->id] = $MoChild;
1864 if ($depth > 1000) {
1868 $TMoChilds = array();
1873 if ($childMoList == -1) {
1877 foreach ($childMoList as $childMo) {
1878 $TMoChilds[$childMo->id] = $childMo;
1881 foreach ($childMoList as $childMo) {
1882 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1884 if ($childMoChildren == -1) {
1887 foreach ($childMoChildren as $child) {
1888 $TMoChilds[$child->id] = $child;
1909 $MoParent =
new Mo($this->db);
1912 $sql =
"SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo";
1913 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1914 $sql .=
" WHERE mo.rowid = ".((int) $this->
id);
1916 $resql = $this->db->query($sql);
1919 if ($this->db->num_rows($resql) > 0) {
1920 $obj = $this->db->fetch_object($resql);
1921 $res = $MoParent->fetch($obj->id_moparent);
1950 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1952 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1953 $return .=
'<div class="info-box info-box-sm">';
1954 $return .=
'<span class="info-box-icon bg-infobox-action">';
1957 $return .=
'</span>';
1958 $return .=
'<div class="info-box-content">';
1959 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1960 if ($selected >= 0) {
1961 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1963 if (!empty($arraydata[
'bom'])) {
1964 $return .=
'<br><span class="info-box-label">'.$arraydata[
'bom']->getNomUrl(1).
'</span>';
1966 if (!empty($arraydata[
'product'])) {
1967 $return .=
'<br><span class="info-box-label">'.$arraydata[
'product']->getNomUrl(1).
'</span>';
1968 if (property_exists($this,
'qty')) {
1969 $return .=
' <span class="info-box-label">('.$langs->trans(
"Qty").
' '.$this->qty.
')</span>';
1972 if (property_exists($this,
'qty')) {
1973 $return .=
'<br><span class="info-box-label">'.$langs->trans(
'Quantity').
' : '.$this->qty.
'</span>';
1976 if (method_exists($this,
'getLibStatut')) {
1977 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1979 $return .=
'</div>';
1980 $return .=
'</div>';
1981 $return .=
'</div>';
1995 public $element =
'mrp_production';
2000 public $table_element =
'mrp_production';
2053 'rowid' => array(
'type' =>
'integer',
'label' =>
'ID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
2054 'fk_mo' => array(
'type' =>
'integer',
'label' =>
'Mo',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 15),
2055 'origin_id' => array(
'type' =>
'integer',
'label' =>
'Origin',
'enabled' => 1,
'visible' => -1,
'notnull' => 0,
'position' => 17),
2056 'origin_type' => array(
'type' =>
'varchar(10)',
'label' =>
'Origin type',
'enabled' => 1,
'visible' => -1,
'notnull' => 0,
'position' => 18),
2057 'position' => array(
'type' =>
'integer',
'label' =>
'Position',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 20),
2058 'fk_product' => array(
'type' =>
'integer',
'label' =>
'Product',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 25),
2059 'fk_warehouse' => array(
'type' =>
'integer',
'label' =>
'Warehouse',
'enabled' => 1,
'visible' => -1,
'position' => 30),
2060 'qty' => array(
'type' =>
'real',
'label' =>
'Qty',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 35),
2061 'qty_frozen' => array(
'type' =>
'smallint',
'label' =>
'QuantityFrozen',
'enabled' => 1,
'visible' => 1,
'default' =>
'0',
'notnull' => 1,
'position' => 105,
'css' =>
'maxwidth50imp',
'help' =>
'QuantityConsumedInvariable'),
2062 'disable_stock_change' => array(
'type' =>
'smallint',
'label' =>
'DisableStockChange',
'enabled' => 1,
'visible' => 1,
'default' =>
'0',
'notnull' => 1,
'position' => 108,
'css' =>
'maxwidth50imp',
'help' =>
'DisableStockChangeHelp'),
2063 'batch' => array(
'type' =>
'varchar(30)',
'label' =>
'Batch',
'enabled' => 1,
'visible' => -1,
'position' => 140),
2064 'role' => array(
'type' =>
'varchar(10)',
'label' =>
'Role',
'enabled' => 1,
'visible' => -1,
'position' => 145),
2065 'fk_mrp_production' => array(
'type' =>
'integer',
'label' =>
'Fk mrp production',
'enabled' => 1,
'visible' => -1,
'position' => 150),
2066 'fk_stock_movement' => array(
'type' =>
'integer',
'label' =>
'StockMovement',
'enabled' => 1,
'visible' => -1,
'position' => 155),
2067 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 160),
2068 'tms' => array(
'type' =>
'timestamp',
'label' =>
'Tms',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 165),
2069 'fk_user_creat' => array(
'type' =>
'integer',
'label' =>
'UserCreation',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 170),
2070 'fk_user_modif' => array(
'type' =>
'integer',
'label' =>
'UserModification',
'enabled' => 1,
'visible' => -1,
'position' => 175),
2071 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -1,
'position' => 180),
2072 'fk_default_workstation' => array(
'type' =>
'integer',
'label' =>
'DefaultWorkstation',
'enabled' => 1,
'visible' => 1,
'notnull' => 0,
'position' => 185),
2073 'fk_unit' => array(
'type' =>
'int',
'label' =>
'Unit',
'enabled' => 1,
'visible' => 1,
'notnull' => 0,
'position' => 186)
2079 public $origin_type;
2082 public $fk_warehouse;
2093 public $disable_stock_change;
2101 public $fk_mrp_production;
2102 public $fk_stock_movement;
2104 public $fk_parent_line;
2110 public $fk_default_workstation;
2123 $this->ismultientitymanaged = 0;
2124 $this->isextrafieldmanaged = 1;
2126 if (!
getDolGlobalString(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid'])) {
2127 $this->fields[
'rowid'][
'visible'] = 0;
2129 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
2130 $this->fields[
'entity'][
'enabled'] = 0;
2134 foreach ($this->fields as $key => $val) {
2135 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
2136 unset($this->fields[$key]);
2141 if (is_object($langs)) {
2142 foreach ($this->fields as $key => $val) {
2143 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
2144 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
2145 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
2161 if (empty($this->qty)) {
2162 $this->error =
'ErrorEmptyValueForQty';
2193 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
2201 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
2202 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2203 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
2205 $sql .=
' WHERE 1 = 1';
2209 if (is_array($filter)) {
2210 $sqlwhere = array();
2211 if (count($filter) > 0) {
2212 foreach ($filter as $key => $value) {
2213 if ($key ==
't.rowid') {
2214 $sqlwhere[] = $key.
" = ".((int) $value);
2215 } elseif (strpos($key,
'date') !==
false) {
2216 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
2218 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
2222 if (count($sqlwhere) > 0) {
2223 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
2232 if ($errormessage) {
2233 $this->errors[] = $errormessage;
2234 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2238 if (!empty($sortfield)) {
2239 $sql .= $this->db->order($sortfield, $sortorder);
2241 if (!empty($limit)) {
2242 $sql .= $this->db->plimit($limit, $offset);
2245 $resql = $this->db->query($sql);
2247 $num = $this->db->num_rows($resql);
2249 while ($i < ($limit ? min($limit, $num) : $num)) {
2250 $obj = $this->db->fetch_object($resql);
2252 $record =
new self($this->db);
2253 $record->setVarsFromFetchObj($obj);
2255 $records[$record->id] = $record;
2259 $this->db->free($resql);
2263 $this->errors[] =
'Error '.$this->db->lasterror();
2264 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2289 public function delete(
User $user, $notrigger = 0)
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
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.
reopen($user, $notrigger=0)
Set back to validated status.
getMoParent()
Function used to return children of Mo.
getLinesArray($rolefilter='')
Create an array of lines.
updateProduction(User $user, $notrigger=0)
Update quantities in lines to consume and/or lines to produce.
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 clicable link of object (with eventually picto)
validate($user, $notrigger=0)
Validate Mo.
cancelConsumedAndProducedLines($user, $mode=0, $also_delete_lines=false, $notrigger=0)
Cancel consumed and produced lines (movement stocks)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getTooltipContentArray($params)
getTooltipContentArray
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
getLibStatut($mode=0)
Return label of the status.
info($id)
Load the info information in the object.
countMovements()
Count number of movement with origin of MO.
createFromClone(User $user, $fromid)
Clone an object into another one.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, $notrigger=0)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
$fields
'type' field format: 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
Class to manage stock movements.
Class to manage products or services.
Class to manage Dolibarr users.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.