27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
38 public $element =
'mo';
43 public $table_element =
'mrp_mo';
48 public $ismultientitymanaged = 1;
53 public $isextrafieldmanaged = 1;
58 public $picto =
'mrp';
61 const STATUS_DRAFT = 0;
62 const STATUS_VALIDATED = 1;
63 const STATUS_INPROGRESS = 2;
64 const STATUS_PRODUCED = 3;
65 const STATUS_CANCELED = 9;
97 public $fields = array(
98 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
99 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'position'=>5,
'notnull'=>1,
'default'=>
'1',
'index'=>1),
100 '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),
101 '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'),
102 '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'),
103 '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'),
104 'qty' => array(
'type'=>
'real',
'label'=>
'QtyToProduce',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'notnull'=>1,
'comment'=>
"Qty to produce",
'css'=>
'width75',
'default'=>1,
'isameasure'=>1),
105 '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),
106 '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'),
107 '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'),
108 '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'),
109 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>61,
'notnull'=>-1,),
110 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>62,
'notnull'=>-1,),
111 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>500,
'notnull'=>1,),
112 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
113 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,),
114 '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'),
115 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'position'=>511,
'notnull'=>-1,
'csslist'=>
'tdoverflowmax100'),
116 'date_start_planned' => array(
'type'=>
'datetime',
'label'=>
'DateStartPlannedMo',
'enabled'=>1,
'visible'=>1,
'position'=>55,
'notnull'=>-1,
'index'=>1,
'help'=>
'KeepEmptyForAsap',
'alwayseditable'=>1,
'csslist'=>
'nowraponall'),
117 'date_end_planned' => array(
'type'=>
'datetime',
'label'=>
'DateEndPlannedMo',
'enabled'=>1,
'visible'=>1,
'position'=>56,
'notnull'=>-1,
'index'=>1,
'alwayseditable'=>1,
'csslist'=>
'nowraponall'),
118 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
119 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
120 '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')),
121 '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),
133 public $fk_warehouse;
145 public $note_private;
150 public $date_creation;
162 public $fk_user_creat;
163 public $fk_user_modif;
180 public $date_start_planned;
185 public $date_end_planned;
214 public $table_element_line =
'mrp_production';
219 public $fk_element =
'fk_mo';
224 public $class_element_line =
'MoLine';
229 protected $childtables = array();
234 protected $childtablesoncascade = array(
'mrp_production');
239 public $lines = array();
244 public $line = array();
249 public $fk_parent_line;
254 public $tpl = array();
264 global $conf, $langs;
269 $this->fields[
'rowid'][
'visible'] = 0;
271 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
272 $this->fields[
'entity'][
'enabled'] = 0;
276 foreach ($this->fields as $key => $val) {
277 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
278 unset($this->fields[$key]);
283 foreach ($this->fields as $key => $val) {
284 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
285 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
286 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
306 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
307 $tmpproduct =
new Product($this->db);
308 $tmpproduct->fetch($this->fk_product);
309 if ($tmpproduct->hasFatherOrChild(1) > 0) {
310 $this->error =
'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
311 $this->errors[] = $this->error;
318 if ($this->fk_bom > 0) {
320 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
321 $tmpbom =
new BOM($this->db);
322 $tmpbom->fetch($this->fk_bom);
324 $this->mrptype = $tmpbom->bomtype;
329 if ($idcreated <= 0) {
345 $this->db->rollback();
359 global $langs, $extrafields;
364 $object =
new self($this->db);
369 $result = $object->fetchCommon($fromid);
370 if ($result > 0 && !empty($object->table_element_line)) {
371 $object->fetchLines();
380 unset($object->fk_user_creat);
381 unset($object->import_key);
384 $TLines = $object->lines;
385 $object->lines = array();
388 foreach ($TLines as $key => $line) {
389 if (in_array($line->role, array(
'consumed',
'produced'))) {
390 unset($object->lines[$key]);
392 $object->lines[] = $line;
398 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->fields[
'ref'][
'default'];
399 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
400 $object->status = self::STATUS_DRAFT;
403 if (is_array($object->array_options) && count($object->array_options) > 0) {
404 $extrafields->fetch_name_optionals_label($this->table_element);
405 foreach ($object->array_options as $key => $option) {
406 $shortkey = preg_replace(
'/options_/',
'', $key);
407 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
410 unset($object->array_options[$key]);
416 $object->context[
'createfromclone'] =
'createfromclone';
417 $result = $object->createCommon($user);
420 $this->error = $object->error;
421 $this->errors = $object->errors;
433 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
440 unset($object->context[
'createfromclone']);
447 $this->db->rollback();
459 public function fetch($id, $ref =
null)
462 if ($result > 0 && !empty($this->table_element_line)) {
466 $this->socid = $this->fk_soc;
478 $this->lines = array();
496 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
506 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
507 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
508 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
510 $sql .=
' WHERE 1 = 1';
514 if (count($filter) > 0) {
515 foreach ($filter as $key => $value) {
516 if ($key ==
't.rowid') {
517 $sqlwhere[] = $key.
" = ".((int) $value);
518 } elseif (strpos($key,
'date') !==
false) {
519 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
520 } elseif ($key ==
'customsql') {
521 $sqlwhere[] = $value;
523 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
527 if (count($sqlwhere) > 0) {
528 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
531 if (!empty($sortfield)) {
532 $sql .= $this->db->order($sortfield, $sortorder);
534 if (!empty($limit)) {
535 $sql .= $this->db->plimit($limit, $offset);
538 $resql = $this->db->query($sql);
540 $num = $this->db->num_rows($resql);
542 while ($i < min($limit, $num)) {
543 $obj = $this->db->fetch_object($resql);
545 $record =
new self($this->db);
546 $record->setVarsFromFetchObj($obj);
548 $records[$record->id] = $record;
552 $this->db->free($resql);
556 $this->errors[] =
'Error '.$this->db->lasterror();
557 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
573 $mostatic =
new MoLine($this->db);
576 $sql .= $mostatic->getFieldList();
577 $sql .=
' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.
' as t';
578 $sql .=
" WHERE t.role = '".$this->db->escape($role).
"'";
580 $sql .=
' AND t.fk_mrp_production = '.((int) $lineid);
582 $sql .=
'AND t.fk_mo = '.((int) $this->
id);
585 $resql = $this->db->query($sql);
587 $num = $this->db->num_rows($resql);
591 $obj = $this->db->fetch_object($resql);
594 'rowid'=> $obj->rowid,
595 'date'=> $this->db->jdate($obj->date_creation),
597 'role' => $obj->role,
598 'fk_product' => $obj->fk_product,
599 'fk_warehouse' => $obj->fk_warehouse,
600 'batch' => $obj->batch,
601 'fk_stock_movement' => $obj->fk_stock_movement,
602 'fk_unit' => $obj->fk_unit
611 $this->error = $this->db->lasterror();
626 $sql =
'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.
'stock_mouvement as sm';
627 $sql .=
" WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->
id);
629 $resql = $this->db->query($sql);
631 $num = $this->db->num_rows($resql);
635 $obj = $this->db->fetch_object($resql);
643 $this->error = $this->db->lasterror();
678 $this->db->rollback();
696 if ($this->
status != self::STATUS_DRAFT) {
704 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'mrp_production WHERE fk_mo = '.((int) $this->
id);
705 $this->db->query($sql);
707 $moline =
new MoLine($this->db);
710 $moline->fk_mo = $this->id;
711 $moline->qty = $this->qty;
712 $moline->fk_product = $this->fk_product;
713 $moline->position = 1;
714 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
715 $tmpproduct =
new Product($this->db);
716 $tmpproduct->fetch($this->fk_product);
717 $moline->fk_unit = $tmpproduct->fk_unit;
719 if ($this->fk_bom > 0) {
720 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
721 $bom =
new BOM($this->db);
722 $bom->fetch($this->fk_bom);
723 if ($bom->bomtype == 1) {
725 $moline->role =
'toconsume';
728 $moline->role =
'toproduce';
731 if ($this->mrptype == 1) {
732 $moline->role =
'toconsume';
734 $moline->role =
'toproduce';
738 $resultline = $moline->create($user,
false);
739 if ($resultline <= 0) {
741 $this->error = $moline->error;
742 $this->errors = $moline->errors;
746 if ($this->fk_bom > 0) {
750 foreach ($bom->lines as $line) {
751 $moline =
new MoLine($this->db);
753 $moline->fk_mo = $this->id;
754 $moline->origin_id = $line->id;
755 $moline->origin_type =
'bomline';
756 if (!empty($line->fk_unit)) {
757 $moline->fk_unit = $line->fk_unit;
759 if ($line->qty_frozen) {
760 $moline->qty = $line->qty;
762 $moline->qty =
price2num(($line->qty / (!empty($bom->qty) ? $bom->qty : 1)) * $this->qty / (!empty($line->efficiency) ? $line->efficiency : 1),
'MS');
764 if ($moline->qty <= 0) {
766 $this->error =
"BadValueForquantityToConsume";
767 $this->errors[] = $this->error;
770 $moline->fk_product = $line->fk_product;
771 $moline->role = $role;
772 $moline->position = $line->position;
773 $moline->qty_frozen = $line->qty_frozen;
774 $moline->disable_stock_change = $line->disable_stock_change;
775 if (!empty($line->fk_default_workstation)) {
776 $moline->fk_default_workstation = $line->fk_default_workstation;
779 $resultline = $moline->create($user,
false);
780 if ($resultline <= 0) {
782 $this->error = $moline->error;
783 $this->errors[] = $moline->error;
784 $this->errors = array_merge($this->errors, $moline->errors);
799 $this->db->rollback();
815 if ($this->
status != self::STATUS_DRAFT) {
821 $oldQty = $this->oldQty;
822 $newQty = $this->qty;
823 if ($newQty != $oldQty && !empty($this->oldQty)) {
824 $sql =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"mrp_production WHERE fk_mo = " . (int) $this->
id;
825 $resql = $this->db->query($sql);
827 while ($obj = $this->db->fetch_object($resql)) {
828 $moLine =
new MoLine($this->db);
829 $res = $moLine->fetch($obj->rowid);
834 if ($moLine->role ==
'toconsume' || $moLine->role ==
'toproduce') {
835 if (empty($moLine->qty_frozen)) {
836 $qty = $newQty * $moLine->qty / $oldQty;
838 $res = $moLine->update($user);
851 $this->db->rollback();
865 public function delete(
User $user, $notrigger =
false, $also_cancel_consumed_and_produced_lines =
false)
870 if ($also_cancel_consumed_and_produced_lines) {
885 $this->db->rollback();
904 $langs->loadLangs(array(
'stocks',
'mrp'));
907 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
910 $productstatic =
new Product($this->db);
911 $fk_movement =
GETPOST(
'fk_movement',
'int');
918 if (!empty($arrayoflines)) {
921 $stockmove->setOrigin($this->element, $this->
id);
923 if (!empty($fk_movement)) {
925 $moline =
new MoLine($this->db);
926 $TArrayMoLine = $moline->fetchAll(
'',
'', 1, 0, array(
'customsql' =>
'fk_stock_movement = '.(
int) $fk_movement));
927 $moline = array_shift($TArrayMoLine);
930 $movement->fetch($fk_movement);
931 $productstatic->fetch($movement->product_id);
932 $qtytoprocess = $movement->qty;
935 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
936 $codemovementCancel = $langs->trans(
"StockIncrease");
938 if (($qtytoprocess >= 0)) {
939 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
'',
'', $movement->batch,
dol_now(), 0, $codemovementCancel);
941 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $movement->batch, 0, $codemovementCancel);
943 if ($idstockmove < 0) {
947 $result = $moline->delete($user, $notrigger);
951 foreach ($arrayoflines as $key => $arrayofline) {
952 $lineDetails = $arrayoflines[$key];
953 $productstatic->fetch($lineDetails[
'fk_product']);
954 $qtytoprocess = $lineDetails[
'qty'];
957 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
958 $codemovementCancel = $langs->trans(
"StockIncrease");
961 if ($qtytoprocess >= 0) {
962 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
964 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
966 if ($idstockmove < 0) {
970 $moline =
new MoLine($this->db);
971 $moline->fetch($lineDetails[
'rowid']);
973 $resdel = $moline->delete($user, $notrigger);
981 if (empty($this->error)) {
990 if (!empty($this->error) || $result <= 0) {
991 $this->db->rollback();
1009 global $langs, $conf;
1010 $langs->load(
"mrp");
1016 $classname = $conf->global->MRP_MO_ADDON;
1019 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1020 foreach ($dirmodels as $reldir) {
1024 $mybool |= @include_once $dir.$file;
1027 if ($mybool ===
false) {
1032 $obj =
new $classname();
1033 $numref = $obj->getNextValue($prod, $this);
1035 if ($numref !=
"") {
1038 $this->error = $obj->error;
1043 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_MRP_MO_ADDON_NotDefined");
1057 global $conf, $langs;
1059 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1064 if ($this->
status == self::STATUS_VALIDATED) {
1065 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
1082 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1088 $this->newref = $num;
1091 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1092 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1093 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1094 $sql .=
" date_valid='".$this->db->idate($now).
"',";
1095 $sql .=
" fk_user_valid = ".$user->id;
1096 $sql .=
" WHERE rowid = ".((int) $this->
id);
1098 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1099 $resql = $this->db->query($sql);
1102 $this->error = $this->db->lasterror();
1106 if (!$error && !$notrigger) {
1108 $result = $this->
call_trigger(
'MRP_MO_VALIDATE', $user);
1116 $this->oldref = $this->ref;
1119 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1121 $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).
"'";
1122 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1123 $resql = $this->db->query($sql);
1126 $this->error = $this->db->lasterror();
1128 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'mrp/".$this->db->escape($this->newref).
"'";
1129 $sql .=
" WHERE filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1130 $resql = $this->db->query($sql);
1133 $this->error = $this->db->lasterror();
1139 $dirsource = $conf->mrp->dir_output.
'/'.$oldref;
1140 $dirdest = $conf->mrp->dir_output.
'/'.$newref;
1141 if (!$error && file_exists($dirsource)) {
1142 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1144 if (@rename($dirsource, $dirdest)) {
1147 $listoffiles =
dol_dir_list($conf->mrp->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1148 foreach ($listoffiles as $fileentry) {
1149 $dirsource = $fileentry[
'name'];
1150 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1151 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1152 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1153 @rename($dirsource, $dirdest);
1163 $this->
status = self::STATUS_VALIDATED;
1167 $this->db->commit();
1170 $this->db->rollback();
1185 if ($this->
status <= self::STATUS_DRAFT) {
1196 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'MRP_MO_UNVALIDATE');
1207 public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines =
false)
1210 if ($this->
status != self::STATUS_VALIDATED && $this->
status != self::STATUS_INPROGRESS) {
1224 if ($also_cancel_consumed_and_produced_lines) {
1232 $result = $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'MRP_MO_CANCEL');
1239 $this->db->rollback();
1242 $this->db->commit();
1254 public function reopen($user, $notrigger = 0)
1257 if ($this->
status != self::STATUS_PRODUCED && $this->
status != self::STATUS_CANCELED) {
1268 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'MRP_MO_REOPEN');
1284 if (!isModEnabled(
'stock')) {
1288 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1289 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
1291 $langs->load(
'stocks');
1296 if (empty($mode) || $mode == 1) {
1298 if (!empty($arrayoflines)) {
1299 foreach ($arrayoflines as $key => $lineDetails) {
1300 $productstatic =
new Product($this->db);
1301 $productstatic->fetch($lineDetails[
'fk_product']);
1302 $qtytoprocess = $lineDetails[
'qty'];
1305 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1306 $codemovementCancel = $langs->trans(
"StockIncrease");
1309 $stockmove->setOrigin($this->element, $this->
id);
1310 if ($qtytoprocess >= 0) {
1311 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1313 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1315 if ($idstockmove < 0) {
1316 $this->error = $stockmove->error;
1317 $this->errors = $stockmove->errors;
1322 if ($also_delete_lines) {
1323 $result = $this->
deleteLineCommon($user, $lineDetails[
'rowid'], $notrigger);
1334 if (empty($mode) || $mode == 2) {
1336 if (!empty($arrayoflines)) {
1337 foreach ($arrayoflines as $key => $lineDetails) {
1338 $productstatic =
new Product($this->db);
1339 $productstatic->fetch($lineDetails[
'fk_product']);
1340 $qtytoprocess = $lineDetails[
'qty'];
1343 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
1344 $codemovementCancel = $langs->trans(
"StockDecrease");
1347 $stockmove->setOrigin($this->element, $this->
id);
1348 if ($qtytoprocess >= 0) {
1349 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
1351 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
1353 if ($idstockmove < 0) {
1354 $this->error = $stockmove->error;
1355 $this->errors = $stockmove->errors;
1360 if ($also_delete_lines) {
1361 $result = $this->
deleteLineCommon($user, $lineDetails[
'rowid'], $notrigger);
1372 $this->db->rollback();
1375 $this->db->commit();
1389 global $conf, $langs;
1391 $langs->loadLangs([
'mrp',
'products']);
1392 $nofetch = isset($params[
'nofetch']) ? true :
false;
1396 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ManufacturingOrder").
'</u>';
1397 if (isset($this->
status)) {
1398 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1400 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1401 if (isset($this->label)) {
1402 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1404 if (isset($this->mrptype)) {
1405 $datas[
'type'] =
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->fields[
'mrptype'][
'arrayofkeyval'][$this->mrptype];
1407 if (isset($this->qty)) {
1408 $datas[
'qty'] =
'<br><b>'.$langs->trans(
'QtyToProduce').
':</b> '.$this->qty;
1410 if (!$nofetch && isset($this->fk_product)) {
1411 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1412 $product =
new Product($this->db);
1413 $product->fetch($this->fk_product);
1414 $datas[
'product'] =
'<br><b>'.$langs->trans(
'Product').
':</b> '.$product->getNomUrl(1,
'', 0, -1, 1);
1416 if (!$nofetch && isset($this->fk_warehouse)) {
1417 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
1418 $warehouse =
new Entrepot($this->db);
1419 $warehouse->fetch($this->fk_warehouse);
1420 $datas[
'warehouse'] =
'<br><b>'.$langs->trans(
'WarehouseForProduction').
':</b> '.$warehouse->getNomUrl(1,
'', 0, 1);
1436 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1438 global $conf, $langs, $action, $hookmanager;
1440 if (!empty($conf->dol_no_mouse_hover)) {
1447 'objecttype' => $this->element,
1448 'option' => $option,
1451 $classfortooltip =
'classfortooltip';
1454 $classfortooltip =
'classforajaxtooltip';
1455 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1461 $url = DOL_URL_ROOT.
'/mrp/mo_card.php?id='.$this->id;
1462 if ($option ==
'production') {
1463 $url = DOL_URL_ROOT.
'/mrp/mo_production.php?id='.$this->id;
1466 if ($option !=
'nolink') {
1468 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1469 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1470 $add_save_lastsearch_values = 1;
1472 if ($add_save_lastsearch_values) {
1473 $url .=
'&save_lastsearch_values=1';
1478 if (empty($notooltip)) {
1480 $label = $langs->trans(
"ShowMo");
1481 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1483 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1484 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1486 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1489 $linkstart =
'<a href="'.$url.
'"';
1490 $linkstart .= $linkclose.
'>';
1493 $result .= $linkstart;
1495 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1497 if ($withpicto != 2) {
1498 $result .= $this->ref;
1500 $result .= $linkend;
1503 $hookmanager->initHooks(array(
'modao'));
1504 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1505 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1507 $result = $hookmanager->resPrint;
1509 $result .= $hookmanager->resPrint;
1537 if (empty($this->labelStatus)) {
1540 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1541 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ValidatedToProduce');
1542 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1543 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1544 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1546 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1547 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
1548 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1549 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1550 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1553 $statusType =
'status'.$status;
1554 if ($status == self::STATUS_VALIDATED) {
1555 $statusType =
'status1';
1557 if ($status == self::STATUS_INPROGRESS) {
1558 $statusType =
'status4';
1560 if ($status == self::STATUS_PRODUCED) {
1561 $statusType =
'status6';
1563 if ($status == self::STATUS_CANCELED) {
1564 $statusType =
'status9';
1567 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1578 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1579 $sql .=
' fk_user_creat, fk_user_modif';
1580 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1581 $sql .=
' WHERE t.rowid = '.((int) $id);
1582 $result = $this->db->query($sql);
1584 if ($this->db->num_rows($result)) {
1585 $obj = $this->db->fetch_object($result);
1587 $this->
id = $obj->rowid;
1589 $this->user_creation_id = $obj->fk_user_creat;
1590 $this->user_modification_id = $obj->fk_user_modif;
1591 $this->date_creation = $this->db->jdate($obj->datec);
1592 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
1595 $this->db->free($result);
1611 $this->lines = array();
1622 $this->lines = array();
1624 $objectline =
new MoLine($this->db);
1626 $TFilters = array(
'customsql'=>
'fk_mo = '.((
int) $this->
id));
1627 if (!empty($rolefilter)) {
1628 $TFilters[
'role'] = $rolefilter;
1630 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, $TFilters);
1632 if (is_numeric($result)) {
1633 $this->error = $objectline->error;
1634 $this->errors = $objectline->errors;
1637 $this->lines = $result;
1638 return $this->lines;
1653 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1655 global $conf, $langs;
1657 $langs->load(
"mrp");
1663 if ($this->model_pdf) {
1664 $modele = $this->model_pdf;
1670 $modelpath =
"core/modules/mrp/doc/";
1672 if (empty($modele)) {
1676 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1688 global $conf, $langs;
1704 $this->db->commit();
1721 global $langs, $hookmanager, $conf, $form, $action;
1723 $langs->load(
'stocks');
1724 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
1725 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
1726 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
1727 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
1728 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
1729 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
1730 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
1731 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
1732 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
1734 print
'<tr class="liste_titre">';
1736 print
'<td class="linecoldescription">'.$langs->trans(
'Ref');
1738 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
1739 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
1743 print
'<td class="right">'.$langs->trans(
'Qty');
1744 if ($this->bom->bomtype == 0) {
1745 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityOf", $this->bom->qty).
')</span>';
1747 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityToConsumeOf", $this->bom->qty).
')</span>';
1750 print
'<td class="right">'.$langs->trans(
'Unit');
1753 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
1754 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
1755 print
'<td class="center">'.$langs->trans(
'QtyFrozen').
'</td>';
1756 print
'<td class="center">'.$langs->trans(
'DisableStockChange').
'</td>';
1757 print
'<td class="center">'.$langs->trans(
'MoChildGenerate').
'</td>';
1763 if (!empty($this->lines)) {
1764 foreach ($this->lines as $line) {
1766 if (is_object($hookmanager)) {
1767 $parameters = array(
'line'=>$line,
'i'=>$i,
'restrictlist'=>$restrictlist,
'selectedLines'=> $selectedLines);
1768 if (!empty($line->fk_parent_line)) {
1769 $parameters[
'fk_parent_line'] = $line->fk_parent_line;
1771 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
1773 if (empty($reshook)) {
1774 $this->
printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
1796 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
1798 $productstatic =
new Product($this->db);
1800 $this->tpl[
'id'] = $line->id;
1802 $this->tpl[
'label'] =
'';
1803 if (!empty($line->fk_product) && $line->fk_product > 0) {
1804 $productstatic->fetch($line->fk_product);
1805 $productstatic->load_virtual_stock();
1806 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
1813 $this->tpl[
'qty_bom'] = 1;
1814 if (is_object($this->bom) && $this->bom->qty > 1) {
1815 $this->tpl[
'qty_bom'] = $this->bom->qty;
1818 $this->tpl[
'stock'] = $productstatic->stock_reel;
1819 $this->tpl[
'seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1820 $this->tpl[
'virtual_stock'] = $productstatic->stock_theorique;
1821 $this->tpl[
'qty'] = $line->qty;
1822 $this->tpl[
'fk_unit'] = $line->fk_unit;
1823 $this->tpl[
'qty_frozen'] = $line->qty_frozen;
1824 $this->tpl[
'disable_stock_change'] = $line->disable_stock_change;
1825 $this->tpl[
'efficiency'] = $line->efficiency;
1828 $res = include DOL_DOCUMENT_ROOT.
'/mrp/tpl/originproductline.tpl.php';
1841 $tables = array(
'mrp_mo');
1854 $TMoChilds = array();
1857 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo_child";
1858 $sql.=
" WHERE fk_parent_line IN ";
1859 $sql.=
" (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_production as line_parent";
1860 $sql.=
" WHERE fk_mo=".((int) $this->
id).
")";
1862 $resql = $this->db->query($sql);
1865 if ($this->db->num_rows($resql) > 0) {
1866 while ($obj = $this->db->fetch_object($resql)) {
1867 $MoChild =
new Mo($this->db);
1868 $res = $MoChild->fetch($obj->rowid);
1870 $TMoChilds[$MoChild->id] = $MoChild;
1895 if ($depth > 1000) {
1899 $TMoChilds = array();
1904 if ($childMoList == -1) {
1908 foreach ($childMoList as $childMo) {
1909 $TMoChilds[$childMo->id] = $childMo;
1912 foreach ($childMoList as $childMo) {
1913 $childMoChildren = $childMo->getAllMoChilds($depth + 1);
1915 if ($childMoChildren == -1) {
1918 foreach ($childMoChildren as $child) {
1919 $TMoChilds[$child->id] = $child;
1940 $MoParent =
new Mo($this->db);
1943 $sql =
"SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo";
1944 $sql.=
" LEFT JOIN ".MAIN_DB_PREFIX.
"mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1945 $sql.=
" WHERE mo.rowid = ".((int) $this->
id);
1947 $resql = $this->db->query($sql);
1950 if ($this->db->num_rows($resql) > 0) {
1951 $obj = $this->db->fetch_object($resql);
1952 $res = $MoParent->fetch($obj->id_moparent);
1981 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1983 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1984 $return .=
'<div class="info-box info-box-sm">';
1985 $return .=
'<span class="info-box-icon bg-infobox-action">';
1988 $return .=
'</span>';
1989 $return .=
'<div class="info-box-content">';
1990 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1991 if ($selected >= 0) {
1992 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1994 if (!empty($arraydata[
'bom'])) {
1995 $return .=
'<br><span class="info-box-label">'.$arraydata[
'bom']->getNomUrl(1).
'</span>';
1997 if (!empty($arraydata[
'product'])) {
1998 $return .=
'<br><span class="info-box-label">'.$arraydata[
'product']->getNomUrl(1).
'</span>';
2000 if (property_exists($this,
'qty')) {
2001 $return .=
'<br><span class="info-box-label">'.$langs->trans(
'Quantity').
' : '.$this->qty.
'</span>';
2003 if (method_exists($this,
'getLibStatut')) {
2004 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2006 $return .=
'</div>';
2007 $return .=
'</div>';
2008 $return .=
'</div>';
2021 public $element =
'mrp_production';
2026 public $table_element =
'mrp_production';
2031 public $ismultientitymanaged = 0;
2036 public $isextrafieldmanaged = 1;
2038 public $fields = array(
2039 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
2040 'fk_mo' =>array(
'type'=>
'integer',
'label'=>
'Mo',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
2041 'origin_id' =>array(
'type'=>
'integer',
'label'=>
'Origin',
'enabled'=>1,
'visible'=>-1,
'notnull'=>0,
'position'=>17),
2042 'origin_type' =>array(
'type'=>
'varchar(10)',
'label'=>
'Origin type',
'enabled'=>1,
'visible'=>-1,
'notnull'=>0,
'position'=>18),
2043 'position' =>array(
'type'=>
'integer',
'label'=>
'Position',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>20),
2044 'fk_product' =>array(
'type'=>
'integer',
'label'=>
'Product',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
2045 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
2046 'qty' =>array(
'type'=>
'real',
'label'=>
'Qty',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
2047 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'notnull' => 1,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
2048 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'notnull' => 1,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
2049 'batch' =>array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
2050 'role' =>array(
'type'=>
'varchar(10)',
'label'=>
'Role',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
2051 'fk_mrp_production' =>array(
'type'=>
'integer',
'label'=>
'Fk mrp production',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
2052 'fk_stock_movement' =>array(
'type'=>
'integer',
'label'=>
'StockMovement',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
2053 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>160),
2054 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'Tms',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>165),
2055 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserCreation',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>170),
2056 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModification',
'enabled'=>1,
'visible'=>-1,
'position'=>175),
2057 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
2058 'fk_default_workstation' =>array(
'type'=>
'integer',
'label'=>
'DefaultWorkstation',
'enabled'=>1,
'visible'=>1,
'notnull'=>0,
'position'=>185),
2059 'fk_unit' =>array(
'type'=>
'int',
'label'=>
'Unit',
'enabled'=>1,
'visible'=>1,
'notnull'=>0,
'position'=>186)
2065 public $origin_type;
2068 public $fk_warehouse;
2071 public $disable_stock_change;
2075 public $fk_mrp_production;
2076 public $fk_stock_movement;
2077 public $date_creation;
2079 public $fk_user_creat;
2080 public $fk_user_modif;
2082 public $fk_parent_line;
2088 public $fk_default_workstation;
2097 global $conf, $langs;
2101 if (!
getDolGlobalString(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid'])) {
2102 $this->fields[
'rowid'][
'visible'] = 0;
2104 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
2105 $this->fields[
'entity'][
'enabled'] = 0;
2109 foreach ($this->fields as $key => $val) {
2110 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
2111 unset($this->fields[$key]);
2116 if (is_object($langs)) {
2117 foreach ($this->fields as $key => $val) {
2118 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
2119 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
2120 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
2136 if (empty($this->qty)) {
2137 $this->error =
'BadValueForQty';
2168 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
2178 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
2179 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2180 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
2182 $sql .=
' WHERE 1 = 1';
2185 $sqlwhere = array();
2186 if (count($filter) > 0) {
2187 foreach ($filter as $key => $value) {
2188 if ($key ==
't.rowid') {
2189 $sqlwhere[] = $key.
" = ".((int) $value);
2190 } elseif (strpos($key,
'date') !==
false) {
2191 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
2192 } elseif ($key ==
'customsql') {
2193 $sqlwhere[] = $value;
2195 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
2199 if (count($sqlwhere) > 0) {
2200 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
2203 if (!empty($sortfield)) {
2204 $sql .= $this->db->order($sortfield, $sortorder);
2206 if (!empty($limit)) {
2207 $sql .= $this->db->plimit($limit, $offset);
2210 $resql = $this->db->query($sql);
2212 $num = $this->db->num_rows($resql);
2214 while ($i < ($limit ? min($limit, $num) : $num)) {
2215 $obj = $this->db->fetch_object($resql);
2217 $record =
new self($this->db);
2218 $record->setVarsFromFetchObj($obj);
2220 $records[$record->id] = $record;
2224 $this->db->free($resql);
2228 $this->errors[] =
'Error '.$this->db->lasterror();
2229 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
2254 public function delete(
User $user, $notrigger =
false)
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
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.
update(User $user, $notrigger=false)
Update object into database.
fetchLinesLinked($role, $lineid=0)
Get list of lines linked to current line for a defined role.
getMoChilds()
Function used to return childs 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...
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetch($id, $ref=null)
Load object 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.
updateProduction(User $user, $notrigger=true)
Update quantities in lines to consume and/or lines to produce.
getMoParent()
Function used to return childs of Mo.
getLinesArray($rolefilter='')
Create an array of lines.
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...
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
getAllMoChilds($depth=0)
Function used to return all child MOs recursively.
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)
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getTooltipContentArray($params)
getTooltipContentArray
createProduction(User $user, $notrigger=true)
Erase and update the line to consume and to produce.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
getLibStatut($mode=0)
Return label of the status.
info($id)
Load the info information in the object.
create(User $user, $notrigger=false)
Create object into database.
countMovements()
Count number of movement with origin of MO.
createFromClone(User $user, $fromid)
Clone an object into another one.
create(User $user, $notrigger=false)
Create object into database.
update(User $user, $notrigger=false)
Update object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $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.
Class to manage stock movements.
Class to manage products or services.
Class to manage Dolibarr users.
dol_dir_list($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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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.