27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstation.class.php';
48 public $module =
'bom';
53 public $element =
'bom';
58 public $table_element =
'bom_bom';
63 public $ismultientitymanaged = 1;
68 public $isextrafieldmanaged = 1;
73 public $picto =
'bom';
76 const STATUS_DRAFT = 0;
77 const STATUS_VALIDATED = 1;
78 const STATUS_CANCELED = 9;
111 public $fields = array(
112 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
113 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>5),
114 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>1,
'noteditable'=>1,
'visible'=>4,
'position'=>10,
'notnull'=>1,
'default'=>
'(PROV)',
'index'=>1,
'searchall'=>1,
'comment'=>
"Reference of BOM",
'showoncombobox'=>
'1',
'csslist'=>
'nowraponall'),
115 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>1,
'position'=>30,
'notnull'=>1,
'searchall'=>1,
'showoncombobox'=>
'2',
'autofocusoncreate'=>1,
'css'=>
'minwidth300 maxwidth400',
'csslist'=>
'tdoverflowmax200'),
116 'bomtype' => array(
'type'=>
'integer',
'label'=>
'Type',
'enabled'=>1,
'visible'=>1,
'position'=>33,
'notnull'=>1,
'default'=>
'0',
'arrayofkeyval'=>array(0=>
'Manufacturing', 1=>
'Disassemble'),
'css'=>
'minwidth175',
'csslist'=>
'minwidth175 center'),
118 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php:1:((finished:is:null) or (finished:!=:0))',
'label'=>
'Product',
'picto'=>
'product',
'enabled'=>1,
'visible'=>1,
'position'=>35,
'notnull'=>1,
'index'=>1,
'help'=>
'ProductBOMHelp',
'css'=>
'maxwidth500',
'csslist'=>
'tdoverflowmax100'),
119 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
120 'qty' => array(
'type'=>
'real',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'default'=>1,
'position'=>55,
'notnull'=>1,
'isameasure'=>
'1',
'css'=>
'maxwidth50imp right'),
122 'duration' => array(
'type'=>
'duration',
'label'=>
'EstimatedDuration',
'enabled'=>1,
'visible'=>-1,
'position'=>101,
'notnull'=>-1,
'css'=>
'maxwidth50imp',
'help'=>
'EstimatedDurationDesc'),
123 'fk_warehouse' => array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php:0',
'label'=>
'WarehouseForProduction',
'picto'=>
'stock',
'enabled'=>1,
'visible'=>-1,
'position'=>102,
'css'=>
'maxwidth500',
'csslist'=>
'tdoverflowmax100'),
124 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>-2,
'position'=>161,
'notnull'=>-1,),
125 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>-2,
'position'=>162,
'notnull'=>-1,),
126 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300,
'notnull'=>1,),
127 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
128 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,
'notnull'=>0,),
129 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserCreation',
'picto'=>
'user',
'enabled'=>1,
'visible'=>-2,
'position'=>510,
'notnull'=>1,
'foreignkey'=>
'user.rowid',
'csslist'=>
'tdoverflowmax100'),
130 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'picto'=>
'user',
'enabled'=>1,
'visible'=>-2,
'position'=>511,
'notnull'=>-1,
'csslist'=>
'tdoverflowmax100'),
131 'fk_user_valid' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'picto'=>
'user',
'enabled'=>1,
'visible'=>-2,
'position'=>512,
'notnull'=>0,
'csslist'=>
'tdoverflowmax100'),
132 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
133 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
134 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>1,
'visible'=>2,
'position'=>1000,
'notnull'=>1,
'default'=>0,
'index'=>1,
'arrayofkeyval'=>array(0=>
'Draft', 1=>
'Enabled', 9=>
'Disabled')),
165 public $date_creation;
177 public $fk_user_creat;
182 public $fk_user_modif;
187 public $fk_user_valid;
192 public $fk_warehouse;
219 public $table_element_line =
'bom_bomline';
224 public $fk_element =
'fk_bom';
229 public $class_element_line =
'BOMLine';
239 protected $childtablesoncascade = array(
'bom_bomline');
244 public $lines = array();
249 public $total_cost = 0;
254 public $unit_cost = 0;
264 global $conf, $langs;
268 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
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);
301 if ($this->efficiency <= 0 || $this->efficiency > 1) {
302 $this->efficiency = 1;
317 global $langs, $hookmanager, $extrafields;
322 $object =
new self($this->db);
327 $result = $object->fetchCommon($fromid);
328 if ($result > 0 && !empty($object->table_element_line)) {
329 $object->fetchLines();
338 unset($object->fk_user_creat);
339 unset($object->import_key);
342 $object->ref = empty($this->fields[
'ref'][
'default']) ? $langs->trans(
"copy_of_").$object->ref : $this->fields[
'ref'][
'default'];
343 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
344 $object->status = self::STATUS_DRAFT;
347 if (is_array($object->array_options) && count($object->array_options) > 0) {
348 $extrafields->fetch_name_optionals_label($object->table_element);
349 foreach ($object->array_options as $key => $option) {
350 $shortkey = preg_replace(
'/options_/',
'', $key);
351 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
353 unset($object->array_options[$key]);
359 $object->context[
'createfromclone'] =
'createfromclone';
360 $result = $object->createCommon($user);
363 $this->error = $object->error;
364 $this->errors = $object->errors;
376 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
387 unset($object->context[
'createfromclone']);
394 $this->db->rollback();
406 public function fetch($id, $ref =
null)
410 if ($result > 0 && !empty($this->table_element_line)) {
425 $this->lines = array();
440 $this->lines = array();
442 $objectlineclassname = get_class($this).
'Line';
443 if (!class_exists($objectlineclassname)) {
444 $this->error =
'Error, class '.$objectlineclassname.
' not found during call of fetchLinesCommon';
448 $objectline =
new $objectlineclassname($this->db);
450 $sql =
"SELECT ".$objectline->getFieldList(
'l');
451 $sql .=
" FROM ".$this->db->prefix().$objectline->table_element.
" as l";
452 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product as p ON p.rowid = l.fk_product";
453 $sql .=
" WHERE l.fk_".$this->db->escape($this->element).
" = ".((int) $this->
id);
454 $sql .=
" AND p.fk_product_type = ". ((int) $typeproduct);
455 if (isset($objectline->fields[
'position'])) {
456 $sql .= $this->db->order(
'position',
'ASC');
459 $resql = $this->db->query(
$sql);
461 $num_rows = $this->db->num_rows($resql);
463 while ($i < $num_rows) {
464 $obj = $this->db->fetch_object($resql);
466 $newline =
new $objectlineclassname($this->db);
467 $newline->setVarsFromFetchObj($obj);
469 $this->lines[] = $newline;
476 $this->error = $this->db->lasterror();
477 $this->errors[] = $this->error;
494 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
504 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
505 if ($this->ismultientitymanaged) {
506 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
508 $sql .=
' WHERE 1 = 1';
512 if (count($filter) > 0) {
513 foreach ($filter as $key => $value) {
514 if ($key ==
't.rowid') {
515 $sqlwhere[] = $key.
" = ".((int) $value);
516 } elseif (strpos($key,
'date') !==
false) {
517 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
518 } elseif ($key ==
'customsql') {
519 $sqlwhere[] = $value;
521 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
525 if (count($sqlwhere) > 0) {
526 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
529 if (!empty($sortfield)) {
530 $sql .= $this->db->order($sortfield, $sortorder);
532 if (!empty($limit)) {
533 $sql .= $this->db->plimit($limit, $offset);
536 $resql = $this->db->query(
$sql);
538 $num = $this->db->num_rows($resql);
540 while ($obj = $this->db->fetch_object($resql)) {
541 $record =
new self($this->db);
542 $record->setVarsFromFetchObj($obj);
544 $records[$record->id] = $record;
546 $this->db->free($resql);
550 $this->errors[] =
'Error '.$this->db->lasterror();
551 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
566 if ($this->efficiency <= 0 || $this->efficiency > 1) {
567 $this->efficiency = 1;
580 public function delete(
User $user, $notrigger =
false)
602 public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child =
null, $import_key =
null, $fk_unit =
'', $array_options = 0, $fk_default_workstation =
null)
604 global $mysoc, $conf, $langs, $user;
606 $logtext =
"::addLine bomid=$this->id, qty=$qty, fk_product=$fk_product, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
607 $logtext .=
", fk_bom_child=$fk_bom_child, import_key=$import_key";
608 dol_syslog(get_class($this).$logtext, LOG_DEBUG);
610 if ($this->statut == self::STATUS_DRAFT) {
611 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
617 if (empty($qty_frozen)) {
620 if (empty($disable_stock_change)) {
621 $disable_stock_change = 0;
623 if (empty($efficiency)) {
626 if (empty($fk_bom_child)) {
627 $fk_bom_child =
null;
629 if (empty($import_key)) {
632 if (empty($position)) {
644 $rankToUse = $position;
645 if ($rankToUse <= 0 or $rankToUse > $rangMax) {
646 $rankToUse = $rangMax + 1;
648 foreach ($this->lines as $bl) {
649 if ($bl->position >= $rankToUse) {
657 $line =
new BOMLine($this->db);
659 $line->context = $this->context;
661 $line->fk_bom = $this->id;
662 $line->fk_product = $fk_product;
664 $line->qty_frozen = $qty_frozen;
665 $line->disable_stock_change = $disable_stock_change;
666 $line->efficiency = $efficiency;
667 $line->fk_bom_child = $fk_bom_child;
668 $line->import_key = $import_key;
669 $line->position = $rankToUse;
670 $line->fk_unit = $fk_unit;
671 $line->fk_default_workstation = $fk_default_workstation;
673 if (is_array($array_options) && count($array_options) > 0) {
674 $line->array_options = $array_options;
677 $result = $line->create($user);
685 dol_syslog(get_class($this).
"::addLine error=".$this->error, LOG_ERR);
686 $this->db->rollback();
690 dol_syslog(get_class($this).
"::addLine status of BOM must be Draft to allow use of ->addLine()", LOG_ERR);
709 public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key =
null, $fk_unit = 0, $array_options = 0)
711 global $mysoc, $conf, $langs, $user;
713 $logtext =
"::updateLine bomid=$this->id, qty=$qty, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
714 $logtext .=
", import_key=$import_key";
715 dol_syslog(get_class($this).$logtext, LOG_DEBUG);
717 if ($this->statut == self::STATUS_DRAFT) {
718 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
724 if (empty($qty_frozen)) {
727 if (empty($disable_stock_change)) {
728 $disable_stock_change = 0;
730 if (empty($efficiency)) {
733 if (empty($import_key)) {
736 if (empty($position)) {
747 $line =
new BOMLine($this->db);
748 $line->fetch($rowid);
749 $line->fetch_optionals();
751 $staticLine = clone $line;
752 $line->oldcopy = $staticLine;
753 $line->context = $this->context;
756 $rankToUse = (int) $position;
757 if ($rankToUse != $line->oldcopy->position) {
758 foreach ($this->lines as $bl) {
759 if ($bl->position >= $rankToUse AND $bl->position < ($line->oldcopy->position + 1)) {
763 if ($bl->position <= $rankToUse AND $bl->position > ($line->oldcopy->position)) {
771 $line->fk_bom = $this->id;
773 $line->qty_frozen = $qty_frozen;
774 $line->disable_stock_change = $disable_stock_change;
775 $line->efficiency = $efficiency;
776 $line->import_key = $import_key;
777 $line->position = $rankToUse;
778 if (!empty($fk_unit)) {
779 $line->fk_unit = $fk_unit;
782 if (is_array($array_options) && count($array_options) > 0) {
784 foreach ($array_options as $key => $value) {
785 $line->array_options[$key] = $array_options[$key];
789 $result = $line->update($user);
797 dol_syslog(get_class($this).
"::addLine error=".$this->error, LOG_ERR);
798 $this->db->rollback();
802 dol_syslog(get_class($this).
"::addLine status of BOM must be Draft to allow use of ->addLine()", LOG_ERR);
817 if ($this->status < 0) {
818 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
825 $line =
new BOMLine($this->db);
826 $line->fetch($idline);
827 $line->fetch_optionals();
829 $staticLine = clone $line;
830 $line->oldcopy = $staticLine;
831 $line->context = $this->context;
833 $result = $line->delete($user, $notrigger);
836 foreach ($this->lines as $bl) {
837 if ($bl->position > ($line->oldcopy->position)) {
849 dol_syslog(get_class($this).
"::addLine error=".$this->error, LOG_ERR);
850 $this->db->rollback();
864 global $langs, $conf;
867 if (!empty($conf->global->BOM_ADDON)) {
870 $file = $conf->global->BOM_ADDON.
".php";
871 $classname = $conf->global->BOM_ADDON;
874 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
875 foreach ($dirmodels as $reldir) {
879 $mybool |= @include_once $dir.$file;
882 if ($mybool ===
false) {
887 $obj =
new $classname();
888 $numref = $obj->getNextValue($prod, $this);
893 $this->error = $obj->error;
898 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOM_ADDON_NotDefined");
912 global $conf, $langs;
914 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
919 if ($this->status == self::STATUS_VALIDATED) {
920 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
937 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
946 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
947 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
948 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
949 $sql .=
" date_valid='".$this->db->idate($now).
"',";
950 $sql .=
" fk_user_valid = ".((int) $user->id);
951 $sql .=
" WHERE rowid = ".((int) $this->
id);
953 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
954 $resql = $this->db->query(
$sql);
957 $this->error = $this->db->lasterror();
961 if (!$error && !$notrigger) {
971 $this->oldref = $this->ref;
974 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
976 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'bom/".$this->db->escape($this->newref).
"'";
977 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
978 $resql = $this->db->query(
$sql);
980 $error++; $this->error = $this->db->lasterror();
986 $dirsource = $conf->bom->dir_output.
'/'.$oldref;
987 $dirdest = $conf->bom->dir_output.
'/'.$newref;
988 if (!$error && file_exists($dirsource)) {
989 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
991 if (@rename($dirsource, $dirdest)) {
994 $listoffiles =
dol_dir_list($conf->bom->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
995 foreach ($listoffiles as $fileentry) {
996 $dirsource = $fileentry[
'name'];
997 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
998 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
999 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1000 @rename($dirsource, $dirdest);
1010 $this->status = self::STATUS_VALIDATED;
1014 $this->db->commit();
1017 $this->db->rollback();
1032 if ($this->status <= self::STATUS_DRAFT) {
1043 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'BOM_UNVALIDATE');
1053 public function cancel($user, $notrigger = 0)
1056 if ($this->status != self::STATUS_VALIDATED) {
1067 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'BOM_CLOSE');
1077 public function reopen($user, $notrigger = 0)
1080 if ($this->status != self::STATUS_CANCELED) {
1091 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'BOM_REOPEN');
1102 global $conf, $langs, $user;
1104 $langs->loadLangs([
'product',
'mrp']);
1108 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1109 return [
'optimize' => $langs->trans(
"ShowBillOfMaterials")];
1111 $picto =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"BillOfMaterials").
'</u>';
1112 if (isset($this->status)) {
1113 $picto .=
' '.$this->getLibStatut(5);
1115 $datas[
'picto'] = $picto;
1116 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1117 if (isset($this->label)) {
1118 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1120 if (!empty($this->fk_product) && $this->fk_product > 0) {
1121 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1122 $product =
new Product($this->db);
1123 $resultFetch = $product->fetch($this->fk_product);
1124 if ($resultFetch > 0) {
1125 $datas[
'product'] =
"<br><b>".$langs->trans(
"Product").
'</b>: '.$product->ref.
' - '.$product->label;
1142 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1144 global $db, $conf, $langs, $hookmanager;
1146 if (!empty($conf->dol_no_mouse_hover)) {
1153 'objecttype' => $this->element,
1154 'option' => $option,
1156 $classfortooltip =
'classfortooltip';
1159 $classfortooltip =
'classforajaxtooltip';
1160 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1166 $url = DOL_URL_ROOT.
'/bom/bom_card.php?id='.$this->id;
1168 if ($option !=
'nolink') {
1170 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1171 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1172 $add_save_lastsearch_values = 1;
1174 if ($add_save_lastsearch_values) {
1175 $url .=
'&save_lastsearch_values=1';
1180 if (empty($notooltip)) {
1181 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1182 $label = $langs->trans(
"ShowBillOfMaterials");
1183 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1185 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1186 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1188 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1191 $linkstart =
'<a href="'.$url.
'"';
1192 $linkstart .= $linkclose.
'>';
1195 $result .= $linkstart;
1197 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1199 if ($withpicto != 2) {
1200 $result .= $this->ref;
1202 $result .= $linkend;
1205 global $action, $hookmanager;
1206 $hookmanager->initHooks(array(
'bomdao'));
1207 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1208 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1210 $result = $hookmanager->resPrint;
1212 $result .= $hookmanager->resPrint;
1226 return $this->
LibStatut($this->status, $mode);
1240 if (empty($this->labelStatus)) {
1243 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1244 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
1245 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
1248 $statusType =
'status'.$status;
1249 if ($status == self::STATUS_VALIDATED) {
1250 $statusType =
'status4';
1252 if ($status == self::STATUS_CANCELED) {
1253 $statusType =
'status6';
1256 return dolGetStatus($this->labelStatus[$status], $this->labelStatus[$status],
'', $statusType, $mode);
1267 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1268 $sql .=
' fk_user_creat, fk_user_modif';
1269 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1270 $sql .=
' WHERE t.rowid = '.((int) $id);
1271 $result = $this->db->query(
$sql);
1273 if ($this->db->num_rows($result)) {
1274 $obj = $this->db->fetch_object($result);
1275 $this->
id = $obj->rowid;
1277 $this->user_creation_id = $obj->fk_user_creat;
1278 $this->user_modification_id = $obj->fk_user_modif;
1279 $this->date_creation = $this->db->jdate($obj->datec);
1280 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
1283 $this->db->free($result);
1296 $this->lines = array();
1298 $objectline =
new BOMLine($this->db);
1299 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_bom = '.((
int) $this->
id)));
1301 if (is_numeric($result)) {
1302 $this->error = $objectline->error;
1303 $this->errors = $objectline->errors;
1306 $this->lines = $result;
1307 return $this->lines;
1322 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1324 global $conf, $langs;
1326 $langs->load(
"mrp");
1327 $outputlangs->load(
"products");
1332 if ($this->model_pdf) {
1333 $modele = $this->model_pdf;
1334 } elseif (!empty($conf->global->BOM_ADDON_PDF)) {
1335 $modele = $conf->global->BOM_ADDON_PDF;
1339 $modelpath =
"core/modules/bom/doc/";
1340 if (!empty($modele)) {
1341 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1356 $this->
ref =
'BOM-123';
1357 $this->date = $this->date_creation;
1369 global $conf, $langs;
1385 $this->db->commit();
1398 global $conf, $hookmanager;
1400 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1401 $this->unit_cost = 0;
1402 $this->total_cost = 0;
1404 $parameters=array();
1405 $reshook = $hookmanager->executeHooks(
'calculateCostsBom', $parameters, $this);
1408 return $hookmanager->resPrint;
1411 if (is_array($this->lines) && count($this->lines)) {
1412 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1414 $tmpproduct =
new Product($this->db);
1416 foreach ($this->lines as &$line) {
1417 $tmpproduct->cost_price = 0;
1418 $tmpproduct->pmp = 0;
1419 $result = $tmpproduct->fetch($line->fk_product,
'',
'',
'', 0, 1, 1);
1421 if ($tmpproduct->type == $tmpproduct::TYPE_PRODUCT) {
1422 if (empty($line->fk_bom_child)) {
1424 $this->error = $tmpproduct->error;
1427 $line->unit_cost =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1428 if (empty($line->unit_cost)) {
1429 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
1430 if ($productFournisseur->fourn_remise_percent !=
"0") {
1431 $line->unit_cost = $productFournisseur->fourn_unitprice_with_discount;
1433 $line->unit_cost = $productFournisseur->fourn_unitprice;
1438 $line->total_cost =
price2num($line->qty * $line->unit_cost,
'MT');
1440 $this->total_cost += $line->total_cost;
1442 $bom_child =
new BOM($this->db);
1443 $res = $bom_child->fetch($line->fk_bom_child);
1445 $bom_child->calculateCosts();
1446 $line->childBom[] = $bom_child;
1447 $this->total_cost +=
price2num($bom_child->total_cost * $line->qty,
'MT');
1448 $this->total_cost += $line->total_cost;
1450 $this->error = $bom_child->error;
1459 if (
isModEnabled(
'workstation') && !empty($tmpproduct->fk_default_workstation)) {
1461 $res = $workstation->fetch($tmpproduct->fk_default_workstation);
1463 if ($res > 0) $line->total_cost =
price2num($qtyhourforline * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated),
'MT');
1465 $this->error = $workstation->error;
1469 $defaultdurationofservice = $tmpproduct->duration;
1471 $qtyhourservice = 0;
1472 if (preg_match(
'/^(\d+)([a-z]+)$/', $defaultdurationofservice, $reg)) {
1476 if ($qtyhourservice) {
1477 $line->total_cost =
price2num($qtyhourforline / $qtyhourservice * $tmpproduct->cost_price,
'MT');
1479 $line->total_cost =
price2num($line->qty * $tmpproduct->cost_price,
'MT');
1483 $this->total_cost += $line->total_cost;
1487 $this->total_cost =
price2num($this->total_cost,
'MT');
1489 if ($this->qty > 0) {
1490 $this->unit_cost =
price2num($this->total_cost / $this->qty,
'MU');
1491 } elseif ($this->qty < 0) {
1492 $this->unit_cost =
price2num($this->total_cost * $this->qty,
'MU');
1525 if (!empty($this->lines)) {
1526 foreach ($this->lines as $line) {
1527 if (!empty($line->childBom)) {
1528 foreach ($line->childBom as $childBom) $childBom->getNetNeeds($TNetNeeds, $line->qty*$qty);
1530 if (empty($TNetNeeds[$line->fk_product])) {
1531 $TNetNeeds[$line->fk_product] = 0;
1533 $TNetNeeds[$line->fk_product] += $line->qty*$qty;
1549 if (!empty($this->lines)) {
1550 foreach ($this->lines as $line) {
1551 if (!empty($line->childBom)) {
1552 foreach ($line->childBom as $childBom) {
1553 $TNetNeeds[$childBom->id][
'bom'] = $childBom;
1554 $TNetNeeds[$childBom->id][
'parentid'] = $this->id;
1555 $TNetNeeds[$childBom->id][
'qty'] = $line->qty*$qty;
1556 $TNetNeeds[$childBom->id][
'level'] = $level;
1557 $childBom->getNetNeedsTree($TNetNeeds, $line->qty*$qty, $level+1);
1560 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'qty'] += $line->qty * $qty;
1561 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'level'] = $level;
1579 if ($level > 1000) {
1583 if (empty($bom_id)) $bom_id=$this->id;
1585 $sql =
'SELECT l.fk_bom, b.label
1586 FROM '.MAIN_DB_PREFIX.
'bom_bomline l
1587 INNER JOIN '.MAIN_DB_PREFIX.$this->table_element.
' b ON b.rowid = l.fk_bom
1588 WHERE fk_bom_child = '.((int) $bom_id);
1590 $resql = $this->db->query(
$sql);
1591 if (!empty($resql)) {
1592 while ($res = $this->db->fetch_object($resql)) {
1593 $TParentBom[$res->fk_bom] = $res->fk_bom;
1610 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1613 $prod->fetch($this->fk_product);
1615 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1616 $return .=
'<div class="info-box info-box-sm">';
1617 $return .=
'<span class="info-box-icon bg-infobox-action">';
1619 $return .=
'</span>';
1620 $return .=
'<div class="info-box-content">';
1621 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() :
'').
'</span>';
1622 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1623 if (property_exists($this,
'fields') && !empty($this->fields[
'bomtype'][
'arrayofkeyval'])) {
1624 $return .=
'<br><span class="info-box-label opacitymedium">'.$langs->trans(
"Type").
' : </span>';
1625 if ($this->bomtype == 0) {
1626 $return .=
'<span class="info-box-label">'.$this->fields[
'bomtype'][
'arrayofkeyval'][0].
'</span>';
1628 $return .=
'<span class="info-box-label">'.$this->fields[
'bomtype'][
'arrayofkeyval'][1].
'</span>';
1631 if (property_exists($this,
'fk_product') && !is_null($this->fk_product)) {
1632 $return .=
'<br><span class="info-box-label">'.$prod->getNomUrl(1).
'</span>';
1634 if (method_exists($this,
'getLibStatut')) {
1635 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1638 $return .=
'</div>';
1639 $return .=
'</div>';
1640 $return .=
'</div>';
1654 public $element =
'bomline';
1659 public $table_element =
'bom_bomline';
1664 public $ismultientitymanaged = 0;
1669 public $isextrafieldmanaged = 1;
1674 public $picto =
'bomline';
1700 public $fields = array(
1701 'rowid' => array(
'type'=>
'integer',
'label'=>
'LineID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
1702 'fk_bom' => array(
'type'=>
'integer:BillOfMaterials:societe/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,),
1703 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
1704 'fk_bom_child' => array(
'type'=>
'integer:BOM:bom/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>-1,
'position'=>40,
'notnull'=>-1,),
1705 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
1706 'qty' => array(
'type'=>
'double(24,8)',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'notnull'=>1,
'isameasure'=>
'1',),
1707 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1708 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1709 'efficiency' => array(
'type'=>
'double(24,8)',
'label'=>
'ManufacturingEfficiency',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'position'=>110,
'notnull'=>1,
'css'=>
'maxwidth50imp',
'help'=>
'ValueOfEfficiencyConsumedMeans'),
1710 'fk_unit' => array(
'type'=>
'integer',
'label'=>
'Unit',
'enabled'=>1,
'visible'=>1,
'position'=>120,
'notnull'=>-1,),
1711 'position' => array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>1,
'visible'=>0,
'default'=>0,
'position'=>200,
'notnull'=>1,),
1712 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
1713 'fk_default_workstation' =>array(
'type'=>
'integer',
'label'=>
'DefaultWorkstation',
'enabled'=>1,
'visible'=>1,
'notnull'=>0,
'position'=>1050)
1734 public $fk_bom_child;
1739 public $description;
1746 public $disable_stock_change;
1763 public $total_cost = 0;
1768 public $unit_cost = 0;
1774 public $childBom = array();
1779 public $fk_default_workstation;
1790 global $conf, $langs;
1794 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
1795 $this->fields[
'rowid'][
'visible'] = 0;
1797 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
1798 $this->fields[
'entity'][
'enabled'] = 0;
1802 foreach ($this->fields as $key => $val) {
1803 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
1804 unset($this->fields[$key]);
1809 foreach ($this->fields as $key => $val) {
1810 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1811 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
1812 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1827 if ($this->efficiency < 0 || $this->efficiency > 1) {
1828 $this->efficiency = 1;
1859 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1869 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1870 if ($this->ismultientitymanaged) {
1871 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
1873 $sql .=
' WHERE 1 = 1';
1876 $sqlwhere = array();
1877 if (count($filter) > 0) {
1878 foreach ($filter as $key => $value) {
1879 if ($key ==
't.rowid') {
1880 $sqlwhere[] = $key.
" = ".((int) $value);
1881 } elseif (strpos($key,
'date') !==
false) {
1882 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
1883 } elseif ($key ==
'customsql') {
1884 $sqlwhere[] = $value;
1886 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
1890 if (count($sqlwhere) > 0) {
1891 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
1894 if (!empty($sortfield)) {
1895 $sql .= $this->db->order($sortfield, $sortorder);
1897 if (!empty($limit)) {
1898 $sql .= $this->db->plimit($limit, $offset);
1901 $resql = $this->db->query(
$sql);
1903 $num = $this->db->num_rows($resql);
1905 while ($obj = $this->db->fetch_object($resql)) {
1906 $record =
new self($this->db);
1907 $record->setVarsFromFetchObj($obj);
1909 $records[$record->id] = $record;
1911 $this->db->free($resql);
1915 $this->errors[] =
'Error '.$this->db->lasterror();
1916 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1931 if ($this->efficiency < 0 || $this->efficiency > 1) {
1932 $this->efficiency = 1;
1945 public function delete(
User $user, $notrigger =
false)
1961 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1963 global $db, $conf, $langs, $hookmanager;
1965 if (!empty($conf->dol_no_mouse_hover)) {
1971 $label =
'<u>'.$langs->trans(
"BillOfMaterialsLine").
'</u>';
1973 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1975 $url = DOL_URL_ROOT.
'/bom/bomline_card.php?id='.$this->id;
1977 if ($option !=
'nolink') {
1979 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1980 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1981 $add_save_lastsearch_values = 1;
1983 if ($add_save_lastsearch_values) {
1984 $url .=
'&save_lastsearch_values=1';
1989 if (empty($notooltip)) {
1990 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1991 $label = $langs->trans(
"ShowBillOfMaterialsLine");
1992 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1994 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1995 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1997 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
2000 $linkstart =
'<a href="'.$url.
'"';
2001 $linkstart .= $linkclose.
'>';
2004 $result .= $linkstart;
2006 $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);
2008 if ($withpicto != 2) {
2009 $result .= $this->ref;
2011 $result .= $linkend;
2014 global $action, $hookmanager;
2015 $hookmanager->initHooks(array(
'bomlinedao'));
2016 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2017 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2019 $result = $hookmanager->resPrint;
2021 $result .= $hookmanager->resPrint;
2035 return $this->
LibStatut($this->status, $mode);
2060 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
2061 $sql .=
' fk_user_creat, fk_user_modif';
2062 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
2063 $sql .=
' WHERE t.rowid = '.((int) $id);
2064 $result = $this->db->query(
$sql);
2066 if ($this->db->num_rows($result)) {
2067 $obj = $this->db->fetch_object($result);
2068 $this->
id = $obj->rowid;
2069 $this->user_creation_id = $obj->fk_user_creat;
2070 $this->user_modification_id = $obj->fk_user_modif;
2071 $this->date_creation = $this->db->jdate($obj->datec);
2072 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
2074 $this->db->free($result);
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
fetchLines()
Load object lines in memory from the database.
__construct(DoliDB $db)
Constructor.
calculateCosts()
BOM costs calculation based on cost_price or pmp of each BOM line.
info($id)
Load the info information in the object.
getLibStatut($mode=0)
Return label of the status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
validate($user, $notrigger=0)
Validate bom.
reopen($user, $notrigger=0)
Set cancel status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
cancel($user, $notrigger=0)
Set cancel status.
create(User $user, $notrigger=false)
Create object into database.
LibStatut($status, $mode=0)
Return the status.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getTooltipContentArray($params)
getTooltipContentArray
fetchLinesbytypeproduct($typeproduct=0)
Load object lines in memory from the database by type of product.
createFromClone(User $user, $fromid)
Clone an object into another one.
fetch($id, $ref=null)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
getNetNeeds(&$TNetNeeds=array(), $qty=0)
Get Net needs by product.
addLine($fk_product, $qty, $qty_frozen=0, $disable_stock_change=0, $efficiency=1.0, $position=-1, $fk_bom_child=null, $import_key=null, $fk_unit='', $array_options=0, $fk_default_workstation=null)
Add an BOM line into database (linked to BOM)
getNextNumRef($prod)
Returns the reference to the following non used BOM depending on the active numbering module defined ...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getLinesArray()
Create an array of lines.
setDraft($user, $notrigger=0)
Set draft status.
updateLine($rowid, $qty, $qty_frozen=0, $disable_stock_change=0, $efficiency=1.0, $position=-1, $import_key=null, $fk_unit=0, $array_options=0)
Update an BOM line into database.
update(User $user, $notrigger=false)
Update object into database.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getParentBomTreeRecursive(&$TParentBom, $bom_id='', $level=1)
Recursively retrieves all parent bom in the tree that leads to the $bom_id bom.
getNetNeedsTree(&$TNetNeeds=array(), $qty=0, $level=0)
Get Net needs Tree by product or bom.
create(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.
fetch($id, $ref=null)
Load object in memory from the database.
getLibStatut($mode=0)
Return label of the status.
update(User $user, $notrigger=false)
Update object into database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
info($id)
Load the info information in the object.
LibStatut($status, $mode=0)
Return the 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.
getFieldList($alias='')
Function to concat keys of fields.
setErrorsFromObject($object)
setErrorsFromObject
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.
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.
fetch_product()
Load the product with id $this->fk_product into this->product.
updateCommon(User $user, $notrigger=false)
Update object into database.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
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 predefined suppliers products.
Class to manage products or services.
Class to manage Dolibarr users.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
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)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.