27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'mo';
44 public $table_element =
'mrp_mo';
49 public $ismultientitymanaged = 0;
54 public $isextrafieldmanaged = 1;
59 public $picto =
'mrp';
62 const STATUS_DRAFT = 0;
63 const STATUS_VALIDATED = 1;
64 const STATUS_INPROGRESS = 2;
65 const STATUS_PRODUCED = 3;
66 const STATUS_CANCELED = 9;
95 public $fields = array(
96 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
97 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'position'=>5,
'notnull'=>1,
'default'=>
'1',
'index'=>1),
98 '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),
99 'fk_bom' => array(
'type'=>
'integer:Bom:bom/class/bom.class.php:0:t.status=1',
'filter'=>
'active=1',
'label'=>
'BOM',
'enabled'=>1,
'visible'=>1,
'position'=>33,
'notnull'=>-1,
'index'=>1,
'comment'=>
"Original BOM",
'css'=>
'minwidth100 maxwidth300'),
100 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php:0',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>35,
'notnull'=>1,
'index'=>1,
'comment'=>
"Product to produce",
'css'=>
'maxwidth300',
'picto'=>
'product'),
101 'qty' => array(
'type'=>
'real',
'label'=>
'QtyToProduce',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'notnull'=>1,
'comment'=>
"Qty to produce",
'css'=>
'width75',
'default'=>1,
'isameasure'=>1),
102 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>1,
'position'=>42,
'notnull'=>-1,
'searchall'=>1,
'showoncombobox'=>
'1',),
103 'fk_soc' => array(
'type'=>
'integer:Societe:societe/class/societe.class.php:1',
'label'=>
'ThirdParty',
'picto'=>
'company',
'enabled'=>1,
'visible'=>-1,
'position'=>50,
'notnull'=>-1,
'index'=>1,
'css'=>
'maxwidth400'),
104 'fk_project' => array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Project',
'picto'=>
'project',
'enabled'=>1,
'visible'=>-1,
'position'=>51,
'notnull'=>-1,
'index'=>1,
'css'=>
'minwidth200 maxwidth400'),
105 'fk_warehouse' => array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php:0',
'label'=>
'WarehouseForProduction',
'picto'=>
'stock',
'enabled'=>1,
'visible'=>1,
'position'=>52,
'css'=>
'maxwidth400'),
106 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>61,
'notnull'=>-1,),
107 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>62,
'notnull'=>-1,),
108 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>500,
'notnull'=>1,),
109 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
110 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,),
111 'fk_user_creat' => array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>510,
'notnull'=>1,
'foreignkey'=>
'user.rowid',),
112 'fk_user_modif' => array(
'type'=>
'integer',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'position'=>511,
'notnull'=>-1,),
113 'date_start_planned' => array(
'type'=>
'datetime',
'label'=>
'DateStartPlannedMo',
'enabled'=>1,
'visible'=>1,
'position'=>55,
'notnull'=>-1,
'index'=>1,
'help'=>
'KeepEmptyForAsap'),
114 'date_end_planned' => array(
'type'=>
'datetime',
'label'=>
'DateEndPlannedMo',
'enabled'=>1,
'visible'=>1,
'position'=>56,
'notnull'=>-1,
'index'=>1,),
115 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
116 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
117 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>1,
'visible'=>2,
'position'=>1000,
'default'=>0,
'notnull'=>1,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Brouillon',
'1'=>
'Validated',
'2'=>
'InProgress',
'3'=>
'StatusMOProduced',
'9'=>
'Canceled')),
124 public $fk_warehouse;
135 public $note_private;
140 public $date_creation;
144 public $fk_user_creat;
145 public $fk_user_modif;
153 public $date_start_planned;
158 public $date_end_planned;
171 public $table_element_line =
'mo_production';
176 public $fk_element =
'fk_mo';
181 public $class_element_line =
'MoLine';
186 protected $childtables = array();
191 protected $childtablesoncascade = array(
'mrp_production');
196 public $lines = array();
207 global $conf, $langs;
211 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->
fields[
'rowid'])) $this->
fields[
'rowid'][
'visible'] = 0;
212 if (empty($conf->multicompany->enabled) && isset($this->
fields[
'entity'])) $this->
fields[
'entity'][
'enabled'] = 0;
215 foreach ($this->
fields as $key => $val)
217 if (isset($val[
'enabled']) && empty($val[
'enabled']))
219 unset($this->
fields[$key]);
224 foreach ($this->
fields as $key => $val)
226 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval']))
228 foreach ($val[
'arrayofkeyval'] as $key2 => $val2)
230 $this->
fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
252 if ($this->fk_product > 0) {
253 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
255 $tmpproduct->fetch($this->fk_product);
256 if ($tmpproduct->hasFatherOrChild(1) > 0) {
257 $this->error =
'ErrorAVirtualProductCantBeUsedIntoABomOrMo';
258 $this->errors[] = $this->error;
259 $this->
db->rollback();
267 if ($idcreated <= 0) {
282 $this->
db->rollback();
297 global $langs, $extrafields;
302 $object =
new self($this->db);
307 $result = $object->fetchCommon($fromid);
308 if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
316 unset($object->fk_user_creat);
317 unset($object->import_key);
320 $object->ref = empty($this->
fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->
fields[
'ref'][
'default'];
321 $object->label = empty($this->
fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->
fields[
'label'][
'default'];
322 $object->status = self::STATUS_DRAFT;
325 if (is_array($object->array_options) && count($object->array_options) > 0)
327 $extrafields->fetch_name_optionals_label($this->table_element);
328 foreach ($object->array_options as $key => $option)
330 $shortkey = preg_replace(
'/options_/',
'', $key);
331 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey]))
334 unset($object->array_options[$key]);
340 $object->context[
'createfromclone'] =
'createfromclone';
341 $result = $object->createCommon($user);
344 $this->error = $object->error;
345 $this->errors = $object->errors;
360 if (property_exists($this,
'socid') && $this->socid == $object->socid)
367 unset($object->context[
'createfromclone']);
374 $this->
db->rollback();
386 public function fetch($id, $ref = null)
389 if ($result > 0 && !empty($this->table_element_line)) $this->
fetchLines();
400 $this->lines = array();
418 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
428 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
429 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
430 else $sql .=
' WHERE 1 = 1';
433 if (count($filter) > 0) {
434 foreach ($filter as $key => $value) {
435 if ($key ==
't.rowid') {
436 $sqlwhere[] = $key.
'='.$value;
437 } elseif (strpos($key,
'date') !==
false) {
438 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
439 } elseif ($key ==
'customsql') {
440 $sqlwhere[] = $value;
442 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
446 if (count($sqlwhere) > 0) {
447 $sql .=
' AND ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
450 if (!empty($sortfield)) {
451 $sql .= $this->
db->order($sortfield, $sortorder);
453 if (!empty($limit)) {
454 $sql .=
' '.$this->db->plimit($limit, $offset);
461 while ($i < min($limit, $num))
463 $obj = $this->
db->fetch_object(
$resql);
465 $record =
new self($this->db);
466 $record->setVarsFromFetchObj($obj);
468 $records[$record->id] = $record;
476 $this->errors[] =
'Error '.$this->db->lasterror();
477 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
496 $sql .= $mostatic->getFieldList();
497 $sql .=
' FROM '.MAIN_DB_PREFIX.$mostatic->table_element.
' as t';
498 $sql .=
" WHERE t.role = '".$this->db->escape($role).
"'";
499 if ($lineid > 0) $sql .=
' AND t.fk_mrp_production = '.$lineid;
500 else $sql .=
'AND t.fk_mo = '.$this->id;
508 $obj = $this->
db->fetch_object(
$resql);
511 'rowid'=> $obj->rowid,
512 'date'=> $this->db->jdate($obj->date_creation),
514 'role' => $obj->role,
515 'fk_product' => $obj->fk_product,
516 'fk_warehouse' => $obj->fk_warehouse,
517 'batch' => $obj->batch,
518 'fk_stock_movement' => $obj->fk_stock_movement
527 $this->error = $this->
db->lasterror();
542 $sql =
'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.
'stock_mouvement as sm';
543 $sql .=
" WHERE sm.origintype = 'mo' and sm.fk_origin = ".$this->id;
551 $obj = $this->
db->fetch_object(
$resql);
559 $this->error = $this->
db->lasterror();
592 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"), null,
'mesgs');
597 $this->
db->rollback();
613 if ($this->status != self::STATUS_DRAFT) {
614 $this->error =
'BadStatus';
625 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'mrp_production WHERE fk_mo = '.$this->id;
626 $this->
db->query($sql);
631 $moline->fk_mo = $this->id;
632 $moline->qty = $this->qty;
633 $moline->fk_product = $this->fk_product;
634 $moline->role =
'toproduce';
635 $moline->position = 1;
637 $resultline = $moline->create($user,
false);
638 if ($resultline <= 0) {
640 $this->error = $moline->error;
641 $this->errors = $moline->errors;
645 if ($this->fk_bom > 0) {
646 include_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
647 $bom =
new Bom($this->
db);
648 $bom->fetch($this->fk_bom);
653 foreach ($bom->lines as $line)
657 $moline->fk_mo = $this->id;
658 if ($line->qty_frozen) {
659 $moline->qty = $line->qty;
661 $moline->qty =
price2num(($line->qty / $bom->qty) * $this->qty / $line->efficiency,
'MS');
663 if ($moline->qty <= 0) {
665 $this->error =
"BadValueForquantityToConsume";
668 $moline->fk_product = $line->fk_product;
669 $moline->role =
'toconsume';
670 $moline->position = $line->position;
671 $moline->qty_frozen = $line->qty_frozen;
672 $moline->disable_stock_change = $line->disable_stock_change;
674 $resultline = $moline->create($user,
false);
675 if ($resultline <= 0) {
677 $this->error = $moline->error;
678 $this->errors = $moline->errors;
693 $this->
db->rollback();
706 public function delete(
User $user, $notrigger =
false)
722 if ($this->status < 0)
724 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
741 global $langs, $conf;
744 if (!empty($conf->global->MRP_MO_ADDON))
748 $file = $conf->global->MRP_MO_ADDON.
".php";
749 $classname = $conf->global->MRP_MO_ADDON;
752 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
753 foreach ($dirmodels as $reldir)
758 $mybool |= @include_once $dir.$file;
761 if ($mybool ===
false)
767 $obj =
new $classname();
768 $numref = $obj->getNextValue($prod, $this);
774 $this->error = $obj->error;
779 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_MRP_MO_ADDON_NotDefined");
793 global $conf, $langs;
795 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
800 if ($this->status == self::STATUS_VALIDATED)
802 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
819 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref)))
826 $this->newref = $num;
829 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
830 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
831 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
832 $sql .=
" date_valid='".$this->db->idate($now).
"',";
833 $sql .=
" fk_user_valid = ".$user->id;
834 $sql .=
" WHERE rowid = ".$this->id;
836 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
841 $this->error = $this->
db->lasterror();
845 if (!$error && !$notrigger)
848 $result = $this->
call_trigger(
'MRP_MO_VALIDATE', $user);
849 if ($result < 0) $error++;
855 $this->oldref = $this->ref;
858 if (preg_match(
'/^[\(]?PROV/i', $this->ref))
861 $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).
"'";
862 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'mrp/".$this->
db->escape($this->ref).
"' and entity = ".$conf->entity;
864 if (!
$resql) { $error++; $this->error = $this->
db->lasterror(); }
869 $dirsource = $conf->mrp->dir_output.
'/'.$oldref;
870 $dirdest = $conf->mrp->dir_output.
'/'.$newref;
871 if (!$error && file_exists($dirsource))
873 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
875 if (@rename($dirsource, $dirdest))
879 $listoffiles =
dol_dir_list($conf->mrp->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
880 foreach ($listoffiles as $fileentry)
882 $dirsource = $fileentry[
'name'];
883 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
884 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
885 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
886 @rename($dirsource, $dirdest);
897 $this->status = self::STATUS_VALIDATED;
905 $this->
db->rollback();
920 if ($this->status <= self::STATUS_DRAFT)
932 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'MRP_MO_UNVALIDATE');
942 public function cancel($user, $notrigger = 0)
945 if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS)
957 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'MRP_MO_CANCEL');
967 public function reopen($user, $notrigger = 0)
970 if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED)
982 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'MRP_MO_REOPEN');
995 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
997 global $conf, $langs, $hookmanager;
999 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
1003 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ManufacturingOrder").
'</u>';
1004 if (isset($this->status)) {
1005 $label .=
' '.$this->getLibStatut(5);
1008 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1010 $url =
dol_buildpath(
'/mrp/mo_card.php', 1).
'?id='.$this->id;
1011 if ($option ==
'production') $url =
dol_buildpath(
'/mrp/mo_production.php', 1).
'?id='.$this->id;
1013 if ($option !=
'nolink')
1016 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1017 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1018 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1022 if (empty($notooltip))
1024 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1026 $label = $langs->trans(
"ShowMo");
1027 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1029 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1030 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1031 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1033 $linkstart =
'<a href="'.$url.
'"';
1034 $linkstart .= $linkclose.
'>';
1037 $result .= $linkstart;
1038 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1039 if ($withpicto != 2) $result .= $this->ref;
1040 $result .= $linkend;
1043 global $action, $hookmanager;
1044 $hookmanager->initHooks(array(
'modao'));
1045 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
1046 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1047 if ($reshook > 0) $result = $hookmanager->resPrint;
1048 else $result .= $hookmanager->resPrint;
1061 return $this->
LibStatut($this->status, $mode);
1075 if (empty($this->labelStatus))
1079 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1080 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ValidatedToProduce');
1081 $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1082 $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1083 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1085 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1086 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
1087 $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv(
'InProgress');
1088 $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv(
'StatusMOProduced');
1089 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
1092 $statusType =
'status'.$status;
1093 if ($status == self::STATUS_VALIDATED) $statusType =
'status1';
1094 if ($status == self::STATUS_INPROGRESS) $statusType =
'status4';
1095 if ($status == self::STATUS_PRODUCED) $statusType =
'status6';
1096 if ($status == self::STATUS_CANCELED) $statusType =
'status9';
1098 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1109 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1110 $sql .=
' fk_user_creat, fk_user_modif';
1111 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1112 $sql .=
' WHERE t.rowid = '.$id;
1113 $result = $this->
db->query($sql);
1116 if ($this->
db->num_rows($result))
1118 $obj = $this->
db->fetch_object($result);
1119 $this->
id = $obj->rowid;
1120 if ($obj->fk_user_author)
1122 $cuser =
new User($this->
db);
1123 $cuser->fetch($obj->fk_user_author);
1124 $this->user_creation = $cuser;
1127 if ($obj->fk_user_valid)
1129 $vuser =
new User($this->
db);
1130 $vuser->fetch($obj->fk_user_valid);
1131 $this->user_validation = $vuser;
1134 if ($obj->fk_user_cloture)
1136 $cluser =
new User($this->
db);
1137 $cluser->fetch($obj->fk_user_cloture);
1138 $this->user_cloture = $cluser;
1141 $this->date_creation = $this->
db->jdate($obj->datec);
1142 $this->date_modification = $this->
db->jdate($obj->datem);
1143 $this->date_validation = $this->
db->jdate($obj->datev);
1146 $this->
db->free($result);
1170 $this->lines = array();
1172 $objectline =
new MoLine($this->
db);
1173 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_mo = '.$this->
id));
1175 if (is_numeric($result))
1177 $this->error = $this->error;
1178 $this->errors = $this->errors;
1181 $this->lines = $result;
1182 return $this->lines;
1197 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1199 global $conf, $langs;
1201 $langs->load(
"mrp");
1207 if ($this->model_pdf) {
1208 $modele = $this->model_pdf;
1209 } elseif (!empty($conf->global->MO_ADDON_PDF)) {
1210 $modele = $conf->global->MO_ADDON_PDF;
1214 $modelpath =
"core/modules/mrp/doc/";
1216 if (empty($modele))
return 1;
1218 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1230 global $conf, $langs;
1246 $this->
db->commit();
1263 global $langs, $hookmanager, $conf, $form;
1265 print '<tr class="liste_titre">';
1266 print '<td>'.$langs->trans(
'Ref').
'</td>';
1267 print '<td class="right">'.$langs->trans(
'Qty').
' <span class="opacitymedium">('.$langs->trans(
"ForAQuantityOf", $this->bom->qty).
')</span></td>';
1268 print '<td class="center">'.$langs->trans(
'QtyFrozen').
'</td>';
1269 print '<td class="center">'.$langs->trans(
'DisableStockChange').
'</td>';
1272 print '<td class="center"></td>';
1276 if (!empty($this->lines))
1278 foreach ($this->lines as $line)
1291 $this->
printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
1313 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
1315 global $langs, $conf;
1317 $this->tpl[
'id'] = $line->id;
1319 $this->tpl[
'label'] =
'';
1320 if (!empty($line->fk_product))
1322 $productstatic =
new Product($this->
db);
1323 $productstatic->fetch($line->fk_product);
1324 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
1331 $this->tpl[
'qty_bom'] = 1;
1332 if (is_object($this->bom) && $this->bom->qty > 1) {
1333 $this->tpl[
'qty_bom'] = $this->bom->qty;
1336 $this->tpl[
'qty'] = $line->qty;
1337 $this->tpl[
'qty_frozen'] = $line->qty_frozen;
1338 $this->tpl[
'disable_stock_change'] = $line->disable_stock_change;
1339 $this->tpl[
'efficiency'] = $line->efficiency;
1341 $tpl = DOL_DOCUMENT_ROOT.
'/mrp/tpl/originproductline.tpl.php';
1342 $res = include $tpl;
1355 $tables = array(
'mrp_mo');
1369 public $element =
'mrp_production';
1374 public $table_element =
'mrp_production';
1379 public $ismultientitymanaged = 0;
1384 public $isextrafieldmanaged = 0;
1386 public $fields = array(
1387 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
1388 'fk_mo' =>array(
'type'=>
'integer',
'label'=>
'Mo',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
1389 'position' =>array(
'type'=>
'integer',
'label'=>
'Position',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>20),
1390 'fk_product' =>array(
'type'=>
'integer',
'label'=>
'Product',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25),
1391 'fk_warehouse' =>array(
'type'=>
'integer',
'label'=>
'Warehouse',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
1392 'qty' =>array(
'type'=>
'real',
'label'=>
'Qty',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
1393 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1394 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1395 'batch' =>array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
1396 'role' =>array(
'type'=>
'varchar(10)',
'label'=>
'Role',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
1397 'fk_mrp_production' =>array(
'type'=>
'integer',
'label'=>
'Fk mrp production',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
1398 'fk_stock_movement' =>array(
'type'=>
'integer',
'label'=>
'StockMovement',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
1399 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>160),
1400 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'Tms',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>165),
1401 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserCreation',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>170),
1402 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModification',
'enabled'=>1,
'visible'=>-1,
'position'=>175),
1403 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
1410 public $fk_warehouse;
1413 public $disable_stock_change;
1416 public $fk_mrp_production;
1417 public $fk_stock_movement;
1418 public $date_creation;
1420 public $fk_user_creat;
1421 public $fk_user_modif;
1431 global $conf, $langs;
1435 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->
fields[
'rowid'])) $this->
fields[
'rowid'][
'visible'] = 0;
1436 if (empty($conf->multicompany->enabled) && isset($this->
fields[
'entity'])) $this->
fields[
'entity'][
'enabled'] = 0;
1439 foreach ($this->
fields as $key => $val)
1441 if (isset($val[
'enabled']) && empty($val[
'enabled']))
1443 unset($this->
fields[$key]);
1448 if (is_object($langs))
1450 foreach ($this->
fields as $key => $val)
1452 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval']))
1454 foreach ($val[
'arrayofkeyval'] as $key2 => $val2)
1456 $this->
fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1472 if (empty($this->qty)) {
1473 $this->error =
'BadValueForQty';
1490 if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
1505 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1515 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1516 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
1517 else $sql .=
' WHERE 1 = 1';
1519 $sqlwhere = array();
1520 if (count($filter) > 0) {
1521 foreach ($filter as $key => $value) {
1522 if ($key ==
't.rowid') {
1523 $sqlwhere[] = $key.
'='.$value;
1524 } elseif (strpos($key,
'date') !==
false) {
1525 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
1526 } elseif ($key ==
'customsql') {
1527 $sqlwhere[] = $value;
1529 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
1533 if (count($sqlwhere) > 0) {
1534 $sql .=
' AND ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
1537 if (!empty($sortfield)) {
1538 $sql .= $this->
db->order($sortfield, $sortorder);
1540 if (!empty($limit)) {
1541 $sql .=
' '.$this->db->plimit($limit, $offset);
1546 $num = $this->
db->num_rows(
$resql);
1548 while ($i < min($limit, $num))
1550 $obj = $this->
db->fetch_object(
$resql);
1552 $record =
new self($this->db);
1553 $record->setVarsFromFetchObj($obj);
1555 $records[$record->id] = $record;
1563 $this->errors[] =
'Error '.$this->db->lasterror();
1564 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1589 public function delete(
User $user, $notrigger =
false)
__construct(DoliDB $db)
Constructor.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
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...
setDraft($user, $notrigger=0)
Set draft status.
fetchLinesCommon($morewhere= '')
Load object in memory from the database.
updateProduction(User $user, $notrigger=true)
Erase and update the line to consume and to produce.
fetchLinesLinked($role, $lineid=0)
Get list of lines linked to current line for a defined role.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getLinesArray()
Create an array of lines.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
LibStatut($status, $mode=0)
Return the status.
getNextNumRef($prod)
Returns the reference to the following non used MO depending on the active numbering module defined i...
printOriginLinesList($restrictlist= '', $selectedLines=array())
Return HTML table table of source object lines TODO Move this and previous function into output html ...
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
update(User $user, $notrigger=false)
Update object into database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load list of objects in memory from the database.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load list of objects in memory from the database.
$conf db
API class for accounts.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
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.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
getLibStatut($mode=0)
Return label of the status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
update(User $user, $notrigger=false)
Update object into database.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
create(User $user, $notrigger=false)
Create object into database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
fetch($id, $ref=null)
Load object in memory from the database.
validate($user, $notrigger=0)
Validate Mo.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetch($id, $ref=null)
Load object in memory from the database.
updateCommon(User $user, $notrigger=false)
Update object into database.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
cancel($user, $notrigger=0)
Set cancel status.
print $_SERVER["PHP_SELF"]
Edit parameters.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
copy_linked_contact($objFrom, $source= 'internal')
Copy contact from one element to current.
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setStatusCommon($user, $status, $notrigger=0, $triggercode= '')
Set to a status.
getFieldList()
Function to concat keys of fields.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
fetch_product()
Load the product with id $this->fk_product into this->product.
reopen($user, $notrigger=0)
Set back to validated status.
info($id)
Load the info information in the object.
__construct(DoliDB $db)
Constructor.
fetchLines()
Load object lines in memory from the database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.