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),
117 'date_end_planned' => array(
'type'=>
'datetime',
'label'=>
'DateEndPlannedMo',
'enabled'=>1,
'visible'=>1,
'position'=>56,
'notnull'=>-1,
'index'=>1,
'alwayseditable'=>1),
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;
208 public $table_element_line =
'mrp_production';
213 public $fk_element =
'fk_mo';
218 public $class_element_line =
'MoLine';
223 protected $childtables = array();
228 protected $childtablesoncascade = array(
'mrp_production');
233 public $lines = array();
238 public $line = array();
243 public $fk_parent_line;
248 public $tpl = array();
257 global $conf, $langs;
261 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
262 $this->fields[
'rowid'][
'visible'] = 0;
264 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
265 $this->fields[
'entity'][
'enabled'] = 0;
269 foreach ($this->fields as $key => $val) {
270 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
271 unset($this->fields[$key]);
276 foreach ($this->fields as $key => $val) {
277 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
278 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
279 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
299 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
300 $tmpproduct =
new Product($this->db);
301 $tmpproduct->fetch($this->fk_product);
302 if ($tmpproduct->hasFatherOrChild(1) > 0) {
303 $this->error =
'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
304 $this->errors[] = $this->error;
311 if ($this->fk_bom > 0) {
313 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
314 $tmpbom =
new BOM($this->db);
315 $tmpbom->fetch($this->fk_bom);
317 $this->mrptype = $tmpbom->bomtype;
322 if ($idcreated <= 0) {
337 $this->db->rollback();
352 global $langs, $extrafields;
357 $object =
new self($this->db);
362 $result = $object->fetchCommon($fromid);
363 if ($result > 0 && !empty($object->table_element_line)) {
364 $object->fetchLines();
373 unset($object->fk_user_creat);
374 unset($object->import_key);
377 $TLines = $object->lines;
378 $object->lines = array();
381 foreach ($TLines as $key => $line) {
382 if (in_array($line->role, array(
'consumed',
'produced'))) {
383 unset($object->lines[$key]);
385 $object->lines[] = $line;
391 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->fields[
'ref'][
'default'];
392 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
393 $object->status = self::STATUS_DRAFT;
396 if (is_array($object->array_options) && count($object->array_options) > 0) {
397 $extrafields->fetch_name_optionals_label($this->table_element);
398 foreach ($object->array_options as $key => $option) {
399 $shortkey = preg_replace(
'/options_/',
'', $key);
400 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
403 unset($object->array_options[$key]);
409 $object->context[
'createfromclone'] =
'createfromclone';
410 $result = $object->createCommon($user);
413 $this->error = $object->error;
414 $this->errors = $object->errors;
426 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
433 unset($object->context[
'createfromclone']);
440 $this->db->rollback();
452 public function fetch($id, $ref =
null)
455 if ($result > 0 && !empty($this->table_element_line)) {
459 $this->socid = $this->fk_soc;
471 $this->lines = array();
489 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
499 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
500 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
501 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
503 $sql .=
' WHERE 1 = 1';
507 if (count($filter) > 0) {
508 foreach ($filter as $key => $value) {
509 if ($key ==
't.rowid') {
510 $sqlwhere[] = $key.
" = ".((int) $value);
511 } elseif (strpos($key,
'date') !==
false) {
512 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
513 } elseif ($key ==
'customsql') {
514 $sqlwhere[] = $value;
516 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
520 if (count($sqlwhere) > 0) {
521 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
524 if (!empty($sortfield)) {
525 $sql .= $this->db->order($sortfield, $sortorder);
527 if (!empty($limit)) {
528 $sql .= $this->db->plimit($limit, $offset);
531 $resql = $this->db->query($sql);
533 $num = $this->db->num_rows($resql);
535 while ($i < min($limit, $num)) {
536 $obj = $this->db->fetch_object($resql);
538 $record =
new self($this->db);
539 $record->setVarsFromFetchObj($obj);
541 $records[$record->id] = $record;
545 $this->db->free($resql);
549 $this->errors[] =
'Error '.$this->db->lasterror();
550 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
566 $mostatic =
new MoLine($this->db);
569 $sql .= $mostatic->getFieldList();
570 $sql .=
' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.
' as t';
571 $sql .=
" WHERE t.role = '".$this->db->escape($role).
"'";
573 $sql .=
' AND t.fk_mrp_production = '.((int) $lineid);
575 $sql .=
'AND t.fk_mo = '.((int) $this->
id);
578 $resql = $this->db->query($sql);
580 $num = $this->db->num_rows($resql);
584 $obj = $this->db->fetch_object($resql);
587 'rowid'=> $obj->rowid,
588 'date'=> $this->db->jdate($obj->date_creation),
590 'role' => $obj->role,
591 'fk_product' => $obj->fk_product,
592 'fk_warehouse' => $obj->fk_warehouse,
593 'batch' => $obj->batch,
594 'fk_stock_movement' => $obj->fk_stock_movement
603 $this->error = $this->db->lasterror();
618 $sql =
'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.
'stock_mouvement as sm';
619 $sql .=
" WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->
id);
621 $resql = $this->db->query($sql);
623 $num = $this->db->num_rows($resql);
627 $obj = $this->db->fetch_object($resql);
635 $this->error = $this->db->lasterror();
672 $this->db->rollback();
690 if ($this->status != self::STATUS_DRAFT) {
698 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'mrp_production WHERE fk_mo = '.((int) $this->
id);
699 $this->db->query($sql);
701 $moline =
new MoLine($this->db);
704 $moline->fk_mo = $this->id;
705 $moline->qty = $this->qty;
706 $moline->fk_product = $this->fk_product;
707 $moline->position = 1;
709 if ($this->fk_bom > 0) {
710 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
711 $bom =
new BOM($this->db);
712 $bom->fetch($this->fk_bom);
713 if ($bom->bomtype == 1) {
715 $moline->role =
'toconsume';
718 $moline->role =
'toproduce';
721 if ($this->mrptype == 1) {
722 $moline->role =
'toconsume';
724 $moline->role =
'toproduce';
728 $resultline = $moline->create($user,
false);
729 if ($resultline <= 0) {
731 $this->error = $moline->error;
732 $this->errors = $moline->errors;
736 if ($this->fk_bom > 0) {
740 foreach ($bom->lines as $line) {
741 $moline =
new MoLine($this->db);
743 $moline->fk_mo = $this->id;
744 $moline->origin_id = $line->id;
745 $moline->origin_type =
'bomline';
746 if ($line->qty_frozen) {
747 $moline->qty = $line->qty;
749 $moline->qty =
price2num(($line->qty / ( !empty($bom->qty) ? $bom->qty : 1 ) ) * $this->qty / ( !empty($line->efficiency) ? $line->efficiency : 1 ),
'MS');
751 if ($moline->qty <= 0) {
753 $this->error =
"BadValueForquantityToConsume";
756 $moline->fk_product = $line->fk_product;
757 $moline->role = $role;
758 $moline->position = $line->position;
759 $moline->qty_frozen = $line->qty_frozen;
760 $moline->disable_stock_change = $line->disable_stock_change;
761 if (!empty($line->fk_default_workstation)) $moline->fk_default_workstation = $line->fk_default_workstation;
763 $resultline = $moline->create($user,
false);
764 if ($resultline <= 0) {
766 $this->error = $moline->error;
767 $this->errors = $moline->errors;
782 $this->db->rollback();
798 if ($this->status != self::STATUS_DRAFT)
return 1;
802 $oldQty = $this->oldQty;
803 $newQty = $this->qty;
804 if ($newQty != $oldQty && !empty($this->oldQty)) {
805 $sql =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"mrp_production WHERE fk_mo = " . (int) $this->
id;
806 $resql = $this->db->query($sql);
808 while ($obj = $this->db->fetch_object($resql)) {
809 $moLine =
new MoLine($this->db);
810 $res = $moLine->fetch($obj->rowid);
813 if ($moLine->role ==
'toconsume' || $moLine->role ==
'toproduce') {
814 if (empty($moLine->qty_frozen)) {
815 $qty = $newQty * $moLine->qty / $oldQty;
816 $moLine->qty =
price2num($qty * (!empty($line->efficiency) ? $line->efficiency : 1 ),
'MS');
817 $res = $moLine->update($user);
829 $this->db->rollback();
842 public function delete(
User $user, $notrigger =
false)
859 $langs->loadLangs(array(
'stocks',
'mrp'));
861 if ($this->status < 0) {
862 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
866 $productstatic =
new Product($this->db);
867 $fk_movement =
GETPOST(
'fk_movement',
'int');
870 if (!empty($arrayoflines)) {
874 $stockmove->setOrigin($this->element, $this->
id);
876 if (!empty($fk_movement)) {
877 $moline =
new MoLine($this->db);
878 $TArrayMoLine = $moline->fetchAll(
'',
'', 1, 0, array(
'customsql' =>
'fk_stock_movement ='.$fk_movement));
879 $moline = array_shift($TArrayMoLine);
882 $movement->fetch($fk_movement);
883 $productstatic->fetch($movement->product_id);
884 $qtytoprocess = $movement->qty;
887 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
888 $codemovementCancel = $langs->trans(
"StockIncrease");
890 if (($qtytoprocess >= 0)) {
891 $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
'',
'', $movement->batch,
dol_now(), 0, $codemovementCancel);
893 $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $movement->batch, 0, $codemovementCancel);
895 if ($idstockmove < 0) {
897 $this->db->rollback();
902 return $moline->delete($user, $notrigger);
904 foreach ($arrayoflines as $key => $arrayofline) {
905 $lineDetails = $arrayoflines[$key];
906 $productstatic->fetch($lineDetails[
'fk_product']);
907 $qtytoprocess = $lineDetails[
'qty'];
910 $labelmovementCancel = $langs->trans(
"CancelProductionForRef", $productstatic->ref);
911 $codemovementCancel = $langs->trans(
"StockIncrease");
913 if ($qtytoprocess >= 0) {
914 $idstockmove = $stockmove->reception($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
'',
'', $lineDetails[
'batch'],
dol_now(), 0, $codemovementCancel);
916 $idstockmove = $stockmove->livraison($user, $lineDetails[
'fk_product'], $lineDetails[
'fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel,
dol_now(),
'',
'', $lineDetails[
'batch'], 0, $codemovementCancel);
918 if ($idstockmove < 0) {
920 $this->db->rollback();
943 global $langs, $conf;
946 if (!empty($conf->global->MRP_MO_ADDON)) {
949 $file = $conf->global->MRP_MO_ADDON.
".php";
950 $classname = $conf->global->MRP_MO_ADDON;
953 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
954 foreach ($dirmodels as $reldir) {
958 $mybool |= @include_once $dir.$file;
961 if ($mybool ===
false) {
966 $obj =
new $classname();
967 $numref = $obj->getNextValue($prod, $this);
972 $this->error = $obj->error;
977 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_MRP_MO_ADDON_NotDefined");
991 global $conf, $langs;
993 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
998 if ($this->status == self::STATUS_VALIDATED) {
999 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
1016 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1022 $this->newref = $num;
1025 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1026 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1027 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1028 $sql .=
" date_valid='".$this->db->idate($now).
"',";
1029 $sql .=
" fk_user_valid = ".$user->id;
1030 $sql .=
" WHERE rowid = ".((int) $this->
id);
1032 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1033 $resql = $this->db->query($sql);
1036 $this->error = $this->db->lasterror();
1040 if (!$error && !$notrigger) {
1042 $result = $this->
call_trigger(
'MRP_MO_VALIDATE', $user);
1050 $this->oldref = $this->ref;
1053 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1055 $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).
"'";
1056 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1057 $resql = $this->db->query($sql);
1059 $error++; $this->error = $this->db->lasterror();
1061 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'mrp/".$this->db->escape($this->newref).
"'";
1062 $sql .=
" WHERE filepath = 'mrp/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1063 $resql = $this->db->query($sql);
1065 $error++; $this->error = $this->db->lasterror();
1071 $dirsource = $conf->mrp->dir_output.
'/'.$oldref;
1072 $dirdest = $conf->mrp->dir_output.
'/'.$newref;
1073 if (!$error && file_exists($dirsource)) {
1074 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1076 if (@rename($dirsource, $dirdest)) {
1079 $listoffiles =
dol_dir_list($conf->mrp->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1080 foreach ($listoffiles as $fileentry) {
1081 $dirsource = $fileentry[
'name'];
1082 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1083 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1084 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1085 @rename($dirsource, $dirdest);
1095 $this->status = self::STATUS_VALIDATED;
1099 $this->db->commit();
1102 $this->db->rollback();
1117 if ($this->status <= self::STATUS_DRAFT) {
1128 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'MRP_MO_UNVALIDATE');
1138 public function cancel($user, $notrigger = 0)
1141 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) {
1152 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'MRP_MO_CANCEL');
1162 public function reopen($user, $notrigger = 0)
1165 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) {
1176 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'MRP_MO_REOPEN');
1188 global $conf, $langs;
1190 $langs->loadLangs([
'mrp',
'products']);
1191 $nofetch = isset($params[
'nofetch']) ? true :
false;
1195 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ManufacturingOrder").
'</u>';
1196 if (isset($this->status)) {
1197 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1199 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1200 if (isset($this->label)) {
1201 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1203 if (isset($this->mrptype)) {
1204 $datas[
'type'] =
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->fields[
'mrptype'][
'arrayofkeyval'][$this->mrptype];
1206 if (isset($this->qty)) {
1207 $datas[
'qty'] =
'<br><b>'.$langs->trans(
'QtyToProduce').
':</b> '.$this->qty;
1209 if (!$nofetch && isset($this->fk_product)) {
1210 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
1211 $product =
new Product($this->db);
1212 $product->fetch($this->fk_product);
1213 $datas[
'product'] =
'<br><b>'.$langs->trans(
'Product').
':</b> '.$product->getNomUrl(1,
'', 0, -1, 1);
1215 if (!$nofetch && isset($this->fk_warehouse)) {
1216 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/entrepot.class.php';
1217 $warehouse =
new Entrepot($this->db);
1218 $warehouse->fetch($this->fk_warehouse);
1219 $datas[
'warehouse'] =
'<br><b>'.$langs->trans(
'WarehouseForProduction').
':</b> '.$warehouse->getNomUrl(1,
'', 0, 1);
1235 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1237 global $conf, $langs, $hookmanager;
1239 if (!empty($conf->dol_no_mouse_hover)) {
1246 'objecttype' => $this->element,
1247 'option' => $option,
1250 $classfortooltip =
'classfortooltip';
1253 $classfortooltip =
'classforajaxtooltip';
1254 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1260 $url = DOL_URL_ROOT.
'/mrp/mo_card.php?id='.$this->id;
1261 if ($option ==
'production') {
1262 $url = DOL_URL_ROOT.
'/mrp/mo_production.php?id='.$this->id;
1265 if ($option !=
'nolink') {
1267 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1268 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1269 $add_save_lastsearch_values = 1;
1271 if ($add_save_lastsearch_values) {
1272 $url .=
'&save_lastsearch_values=1';
1277 if (empty($notooltip)) {
1278 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1279 $label = $langs->trans(
"ShowMo");
1280 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1282 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1283 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1285 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1288 $linkstart =
'<a href="'.$url.
'"';
1289 $linkstart .= $linkclose.
'>';
1292 $result .= $linkstart;
1294 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1296 if ($withpicto != 2) {
1297 $result .= $this->ref;
1299 $result .= $linkend;
1302 global $action, $hookmanager;
1303 $hookmanager->initHooks(array(
'modao'));
1304 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1305 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1307 $result = $hookmanager->resPrint;
1309 $result .= $hookmanager->resPrint;
1323 return $this->
LibStatut($this->status, $mode);
1337 if (empty($this->labelStatus)) {
1340 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1341 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ValidatedToProduce');
1342 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1343 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1344 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1346 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1347 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
1348 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1349 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1350 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1353 $statusType =
'status'.$status;
1354 if ($status == self::STATUS_VALIDATED) {
1355 $statusType =
'status1';
1357 if ($status == self::STATUS_INPROGRESS) {
1358 $statusType =
'status4';
1360 if ($status == self::STATUS_PRODUCED) {
1361 $statusType =
'status6';
1363 if ($status == self::STATUS_CANCELED) {
1364 $statusType =
'status9';
1367 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1378 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1379 $sql .=
' fk_user_creat, fk_user_modif';
1380 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1381 $sql .=
' WHERE t.rowid = '.((int) $id);
1382 $result = $this->db->query($sql);
1384 if ($this->db->num_rows($result)) {
1385 $obj = $this->db->fetch_object($result);
1386 $this->
id = $obj->rowid;
1388 $this->user_creation_id = $obj->fk_user_creat;
1389 $this->user_modification_id = $obj->fk_user_modif;
1390 $this->date_creation = $this->db->jdate($obj->datec);
1391 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
1394 $this->db->free($result);
1410 $this->lines = array();
1421 $this->lines = array();
1423 $objectline =
new MoLine($this->db);
1425 $TFilters = array(
'customsql'=>
'fk_mo = '.((
int) $this->
id));
1426 if (!empty($rolefilter)) $TFilters[
'role'] = $rolefilter;
1427 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, $TFilters);
1429 if (is_numeric($result)) {
1430 $this->error = $objectline->error;
1431 $this->errors = $objectline->errors;
1434 $this->lines = $result;
1435 return $this->lines;
1450 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1452 global $conf, $langs;
1454 $langs->load(
"mrp");
1460 if ($this->model_pdf) {
1461 $modele = $this->model_pdf;
1462 } elseif (!empty($conf->global->MO_ADDON_PDF)) {
1463 $modele = $conf->global->MO_ADDON_PDF;
1467 $modelpath =
"core/modules/mrp/doc/";
1469 if (empty($modele)) {
1473 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1485 global $conf, $langs;
1501 $this->db->commit();
1518 global $langs, $hookmanager, $conf, $form;
1520 $langs->load(
'stocks');
1521 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
1522 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
1523 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
1524 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
1525 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_BILL) ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
1526 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
1527 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
1528 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
1529 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
1531 print
'<tr class="liste_titre">';
1533 print
'<td class="linecoldescription">'.$langs->trans(
'Ref');
1534 if (!empty($conf->global->BOM_SUB_BOM)) {
1535 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
1536 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
1540 print
'<td class="right">'.$langs->trans(
'Qty');
1541 if ($this->bom->bomtype == 0) {
1542 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityOf", $this->bom->qty).
')</span>';
1544 print
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityToConsumeOf", $this->bom->qty).
')</span>';
1547 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
1548 print
'<td class="center">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
1549 print
'<td class="center">'.$langs->trans(
'QtyFrozen').
'</td>';
1550 print
'<td class="center">'.$langs->trans(
'DisableStockChange').
'</td>';
1551 print
'<td class="center">'.$langs->trans(
'MoChildGenerate').
'</td>';
1557 if (!empty($this->lines)) {
1558 foreach ($this->lines as $line) {
1560 if (is_object($hookmanager)) {
1561 $parameters = array(
'line'=>$line,
'i'=>$i,
'restrictlist'=>$restrictlist,
'selectedLines'=> $selectedLines);
1562 if (!empty($line->fk_parent_line)) { $parameters[
'fk_parent_line'] = $line->fk_parent_line; }
1563 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
1565 if (empty($reshook)) {
1566 $this->
printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
1588 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
1590 global $langs, $conf;
1592 $this->tpl[
'id'] = $line->id;
1594 $this->tpl[
'label'] =
'';
1595 if (!empty($line->fk_product)) {
1596 $productstatic =
new Product($this->db);
1597 $productstatic->fetch($line->fk_product);
1598 $productstatic->load_virtual_stock();
1599 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
1606 $this->tpl[
'qty_bom'] = 1;
1607 if (is_object($this->bom) && $this->bom->qty > 1) {
1608 $this->tpl[
'qty_bom'] = $this->bom->qty;
1611 $this->tpl[
'stock'] = $productstatic->stock_reel;
1612 $this->tpl[
'seuil_stock_alerte'] = $productstatic->seuil_stock_alerte;
1613 $this->tpl[
'virtual_stock'] = $productstatic->stock_theorique;
1614 $this->tpl[
'qty'] = $line->qty;
1615 $this->tpl[
'qty_frozen'] = $line->qty_frozen;
1616 $this->tpl[
'disable_stock_change'] = $line->disable_stock_change;
1617 $this->tpl[
'efficiency'] = $line->efficiency;
1619 $tpl = DOL_DOCUMENT_ROOT.
'/mrp/tpl/originproductline.tpl.php';
1620 $res = include $tpl;
1633 $tables = array(
'mrp_mo');
1647 $TMoChilds = array();
1650 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo_child";
1651 $sql.=
" WHERE fk_parent_line IN ";
1652 $sql.=
" (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mrp_production as line_parent";
1653 $sql.=
" WHERE fk_mo=".((int) $this->
id).
")";
1655 $resql = $this->db->query($sql);
1658 if ($this->db->num_rows($resql) > 0) {
1659 while ($obj = $this->db->fetch_object($resql)) {
1660 $MoChild =
new Mo($this->db);
1661 $res = $MoChild->fetch($obj->rowid);
1662 if ($res > 0) $TMoChilds[$MoChild->id] = $MoChild;
1684 $MoParent =
new Mo($this->db);
1687 $sql =
"SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX.
"mrp_mo as mo";
1688 $sql.=
" LEFT JOIN ".MAIN_DB_PREFIX.
"mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid";
1689 $sql.=
" WHERE mo.rowid = ".((int) $this->
id);
1691 $resql = $this->db->query($sql);
1694 if ($this->db->num_rows($resql) > 0) {
1695 $obj = $this->db->fetch_object($resql);
1696 $res = $MoParent->fetch($obj->id_moparent);
1697 if ($res < 0) $error++;
1723 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1725 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1726 $return .=
'<div class="info-box info-box-sm">';
1727 $return .=
'<span class="info-box-icon bg-infobox-action">';
1730 $return .=
'</span>';
1731 $return .=
'<div class="info-box-content">';
1732 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1733 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1734 if (!empty($arraydata[
'bom'])) {
1735 $return .=
'<br><span class="info-box-label">'.$arraydata[
'bom']->getNomUrl(1).
'</span>';
1737 if (!empty($arraydata[
'product'])) {
1738 $return .=
'<br><span class="info-box-label">'.$arraydata[
'product']->getNomUrl(1).
'</span>';
1740 if (property_exists($this,
'qty')) {
1741 $return .=
'<br><span class="info-box-label">'.$langs->trans(
'Quantity').
' : '.$this->qty.
'</span>';
1743 if (method_exists($this,
'getLibStatut')) {
1744 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1746 $return .=
'</div>';
1747 $return .=
'</div>';
1748 $return .=
'</div>';
1761 public $element =
'mrp_production';
1766 public $table_element =
'mrp_production';
1771 public $ismultientitymanaged = 0;
1776 public $isextrafieldmanaged = 0;
1778 public $fields = array(
1779 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
1780 'fk_mo' =>array(
'type'=>
'integer',
'label'=>
'Mo',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
1781 'origin_id' =>array(
'type'=>
'integer',
'label'=>
'Origin',
'enabled'=>1,
'visible'=>-1,
'notnull'=>0,
'position'=>17),
1782 'origin_type' =>array(
'type'=>
'varchar(10)',
'label'=>
'Origin type',
'enabled'=>1,
'visible'=>-1,
'notnull'=>0,
'position'=>18),
1783 'position' =>array(
'type'=>
'integer',
'label'=>
'Position',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>20),
1784 'fk_product' =>array(
'type'=>
'integer',
'label'=>
'Product',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
1785 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
1786 'qty' =>array(
'type'=>
'real',
'label'=>
'Qty',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
1787 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1788 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1789 'batch' =>array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
1790 'role' =>array(
'type'=>
'varchar(10)',
'label'=>
'Role',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
1791 'fk_mrp_production' =>array(
'type'=>
'integer',
'label'=>
'Fk mrp production',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
1792 'fk_stock_movement' =>array(
'type'=>
'integer',
'label'=>
'StockMovement',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
1793 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>160),
1794 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'Tms',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>165),
1795 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserCreation',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>170),
1796 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModification',
'enabled'=>1,
'visible'=>-1,
'position'=>175),
1797 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
1798 'fk_default_workstation' =>array(
'type'=>
'integer',
'label'=>
'DefaultWorkstation',
'enabled'=>1,
'visible'=>1,
'notnull'=>0,
'position'=>185)
1804 public $origin_type;
1807 public $fk_warehouse;
1810 public $disable_stock_change;
1814 public $fk_mrp_production;
1815 public $fk_stock_movement;
1816 public $date_creation;
1818 public $fk_user_creat;
1819 public $fk_user_modif;
1821 public $fk_parent_line;
1826 public $fk_default_workstation;
1835 global $conf, $langs;
1839 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
1840 $this->fields[
'rowid'][
'visible'] = 0;
1842 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
1843 $this->fields[
'entity'][
'enabled'] = 0;
1847 foreach ($this->fields as $key => $val) {
1848 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
1849 unset($this->fields[$key]);
1854 if (is_object($langs)) {
1855 foreach ($this->fields as $key => $val) {
1856 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1857 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
1858 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1874 if (empty($this->qty)) {
1875 $this->error =
'BadValueForQty';
1906 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1916 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1917 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1918 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
1920 $sql .=
' WHERE 1 = 1';
1923 $sqlwhere = array();
1924 if (count($filter) > 0) {
1925 foreach ($filter as $key => $value) {
1926 if ($key ==
't.rowid') {
1927 $sqlwhere[] = $key.
" = ".((int) $value);
1928 } elseif (strpos($key,
'date') !==
false) {
1929 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
1930 } elseif ($key ==
'customsql') {
1931 $sqlwhere[] = $value;
1933 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
1937 if (count($sqlwhere) > 0) {
1938 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
1941 if (!empty($sortfield)) {
1942 $sql .= $this->db->order($sortfield, $sortorder);
1944 if (!empty($limit)) {
1945 $sql .= $this->db->plimit($limit, $offset);
1948 $resql = $this->db->query($sql);
1950 $num = $this->db->num_rows($resql);
1952 while ($i < ($limit ? min($limit, $num) : $num)) {
1953 $obj = $this->db->fetch_object($resql);
1955 $record =
new self($this->db);
1956 $record->setVarsFromFetchObj($obj);
1958 $records[$record->id] = $record;
1962 $this->db->free($resql);
1966 $this->errors[] =
'Error '.$this->db->lasterror();
1967 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1992 public function delete(
User $user, $notrigger =
false)
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.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the 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='')
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.
cancel($user, $notrigger=0)
Set cancel status.
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.
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.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
validate($user, $notrigger=0)
Validate Mo.
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 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.