27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
29require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstation.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
44 public $module =
'bom';
49 public $element =
'bom';
54 public $table_element =
'bom_bom';
59 public $ismultientitymanaged = 1;
64 public $isextrafieldmanaged = 1;
69 public $picto =
'bom';
72 const STATUS_DRAFT = 0;
73 const STATUS_VALIDATED = 1;
74 const STATUS_CANCELED = 9;
107 public $fields = array(
108 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
109 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>5),
110 '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'),
111 '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'),
112 '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'),
114 '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'),
115 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
116 'qty' => array(
'type'=>
'real',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'default'=>1,
'position'=>55,
'notnull'=>1,
'isameasure'=>
'1',
'css'=>
'maxwidth50imp right'),
118 'duration' => array(
'type'=>
'duration',
'label'=>
'EstimatedDuration',
'enabled'=>1,
'visible'=>-1,
'position'=>101,
'notnull'=>-1,
'css'=>
'maxwidth50imp',
'help'=>
'EstimatedDurationDesc'),
119 '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'),
120 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>-2,
'position'=>161,
'notnull'=>-1,),
121 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>-2,
'position'=>162,
'notnull'=>-1,),
122 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300,
'notnull'=>1,),
123 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
124 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,
'notnull'=>0,),
125 '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'),
126 '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'),
127 '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'),
128 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
129 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
130 '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')),
161 public $date_creation;
173 public $fk_user_creat;
178 public $fk_user_modif;
183 public $fk_user_valid;
188 public $fk_warehouse;
215 public $table_element_line =
'bom_bomline';
220 public $fk_element =
'fk_bom';
225 public $class_element_line =
'BOMLine';
235 protected $childtablesoncascade = array(
'bom_bomline');
240 public $lines = array();
245 public $total_cost = 0;
250 public $unit_cost = 0;
260 global $conf, $langs;
264 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
265 $this->fields[
'rowid'][
'visible'] = 0;
267 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
268 $this->fields[
'entity'][
'enabled'] = 0;
272 foreach ($this->fields as $key => $val) {
273 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
274 unset($this->fields[$key]);
279 foreach ($this->fields as $key => $val) {
280 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
281 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
282 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
297 if ($this->efficiency <= 0 || $this->efficiency > 1) {
298 $this->efficiency = 1;
313 global $langs, $hookmanager, $extrafields;
318 $object =
new self($this->db);
323 $result = $object->fetchCommon($fromid);
324 if ($result > 0 && !empty($object->table_element_line)) {
325 $object->fetchLines();
334 unset($object->fk_user_creat);
335 unset($object->import_key);
338 $object->ref = empty($this->fields[
'ref'][
'default']) ? $langs->trans(
"copy_of_").$object->ref : $this->fields[
'ref'][
'default'];
339 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
340 $object->status = self::STATUS_DRAFT;
343 if (is_array($object->array_options) && count($object->array_options) > 0) {
344 $extrafields->fetch_name_optionals_label($object->table_element);
345 foreach ($object->array_options as $key => $option) {
346 $shortkey = preg_replace(
'/options_/',
'', $key);
347 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
349 unset($object->array_options[$key]);
355 $object->context[
'createfromclone'] =
'createfromclone';
356 $result = $object->createCommon($user);
359 $this->error = $object->error;
360 $this->errors = $object->errors;
372 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
383 unset($object->context[
'createfromclone']);
390 $this->db->rollback();
402 public function fetch($id, $ref =
null)
406 if ($result > 0 && !empty($this->table_element_line)) {
421 $this->lines = array();
436 $this->lines = array();
438 $objectlineclassname = get_class($this).
'Line';
439 if (!class_exists($objectlineclassname)) {
440 $this->error =
'Error, class '.$objectlineclassname.
' not found during call of fetchLinesCommon';
444 $objectline =
new $objectlineclassname($this->db);
446 $sql =
"SELECT ".$objectline->getFieldList(
'l');
447 $sql .=
" FROM ".$this->db->prefix().$objectline->table_element.
" as l";
448 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product as p ON p.rowid = l.fk_product";
449 $sql .=
" WHERE l.fk_".$this->db->escape($this->element).
" = ".((int) $this->
id);
450 $sql .=
" AND p.fk_product_type = ". ((int) $typeproduct);
451 if (isset($objectline->fields[
'position'])) {
452 $sql .= $this->db->order(
'position',
'ASC');
455 $resql = $this->db->query($sql);
457 $num_rows = $this->db->num_rows($resql);
459 while ($i < $num_rows) {
460 $obj = $this->db->fetch_object($resql);
462 $newline =
new $objectlineclassname($this->db);
463 $newline->setVarsFromFetchObj($obj);
465 $this->lines[] = $newline;
472 $this->error = $this->db->lasterror();
473 $this->errors[] = $this->error;
490 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
500 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
501 if ($this->ismultientitymanaged) {
502 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
504 $sql .=
' WHERE 1 = 1';
508 if (count($filter) > 0) {
509 foreach ($filter as $key => $value) {
510 if ($key ==
't.rowid') {
511 $sqlwhere[] = $key.
" = ".((int) $value);
512 } elseif (strpos($key,
'date') !==
false) {
513 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
514 } elseif ($key ==
'customsql') {
515 $sqlwhere[] = $value;
517 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
521 if (count($sqlwhere) > 0) {
522 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
525 if (!empty($sortfield)) {
526 $sql .= $this->db->order($sortfield, $sortorder);
528 if (!empty($limit)) {
529 $sql .= $this->db->plimit($limit, $offset);
532 $resql = $this->db->query($sql);
534 $num = $this->db->num_rows($resql);
536 while ($obj = $this->db->fetch_object($resql)) {
537 $record =
new self($this->db);
538 $record->setVarsFromFetchObj($obj);
540 $records[$record->id] = $record;
542 $this->db->free($resql);
546 $this->errors[] =
'Error '.$this->db->lasterror();
547 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
562 if ($this->efficiency <= 0 || $this->efficiency > 1) {
563 $this->efficiency = 1;
576 public function delete(
User $user, $notrigger =
false)
598 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)
600 global $mysoc, $conf, $langs, $user;
602 $logtext =
"::addLine bomid=$this->id, qty=$qty, fk_product=$fk_product, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
603 $logtext .=
", fk_bom_child=$fk_bom_child, import_key=$import_key";
604 dol_syslog(get_class($this).$logtext, LOG_DEBUG);
606 if ($this->
statut == self::STATUS_DRAFT) {
607 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
613 if (empty($qty_frozen)) {
616 if (empty($disable_stock_change)) {
617 $disable_stock_change = 0;
619 if (empty($efficiency)) {
622 if (empty($fk_bom_child)) {
623 $fk_bom_child =
null;
625 if (empty($import_key)) {
628 if (empty($position)) {
640 $rankToUse = $position;
641 if ($rankToUse <= 0 or $rankToUse > $rangMax) {
642 $rankToUse = $rangMax + 1;
644 foreach ($this->lines as $bl) {
645 if ($bl->position >= $rankToUse) {
653 $line =
new BOMLine($this->db);
655 $line->context = $this->context;
657 $line->fk_bom = $this->id;
658 $line->fk_product = $fk_product;
660 $line->qty_frozen = $qty_frozen;
661 $line->disable_stock_change = $disable_stock_change;
662 $line->efficiency = $efficiency;
663 $line->fk_bom_child = $fk_bom_child;
664 $line->import_key = $import_key;
665 $line->position = $rankToUse;
666 $line->fk_unit = $fk_unit;
667 $line->fk_default_workstation = $fk_default_workstation;
669 if (is_array($array_options) && count($array_options) > 0) {
670 $line->array_options = $array_options;
673 $result = $line->create($user);
681 dol_syslog(get_class($this).
"::addLine error=".$this->error, LOG_ERR);
682 $this->db->rollback();
686 dol_syslog(get_class($this).
"::addLine status of BOM must be Draft to allow use of ->addLine()", LOG_ERR);
705 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)
707 global $mysoc, $conf, $langs, $user;
709 $logtext =
"::updateLine bomid=$this->id, qty=$qty, qty_frozen=$qty_frozen, disable_stock_change=$disable_stock_change, efficiency=$efficiency";
710 $logtext .=
", import_key=$import_key";
711 dol_syslog(get_class($this).$logtext, LOG_DEBUG);
713 if ($this->
statut == self::STATUS_DRAFT) {
714 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
720 if (empty($qty_frozen)) {
723 if (empty($disable_stock_change)) {
724 $disable_stock_change = 0;
726 if (empty($efficiency)) {
729 if (empty($import_key)) {
732 if (empty($position)) {
743 $line =
new BOMLine($this->db);
744 $line->fetch($rowid);
745 $line->fetch_optionals();
747 $staticLine = clone $line;
748 $line->oldcopy = $staticLine;
749 $line->context = $this->context;
752 $rankToUse = (int) $position;
753 if ($rankToUse != $line->oldcopy->position) {
754 foreach ($this->lines as $bl) {
755 if ($bl->position >= $rankToUse AND $bl->position < ($line->oldcopy->position + 1)) {
759 if ($bl->position <= $rankToUse AND $bl->position > ($line->oldcopy->position)) {
767 $line->fk_bom = $this->id;
769 $line->qty_frozen = $qty_frozen;
770 $line->disable_stock_change = $disable_stock_change;
771 $line->efficiency = $efficiency;
772 $line->import_key = $import_key;
773 $line->position = $rankToUse;
774 if (!empty($fk_unit)) {
775 $line->fk_unit = $fk_unit;
778 if (is_array($array_options) && count($array_options) > 0) {
780 foreach ($array_options as $key => $value) {
781 $line->array_options[$key] = $array_options[$key];
785 $result = $line->update($user);
793 dol_syslog(get_class($this).
"::addLine error=".$this->error, LOG_ERR);
794 $this->db->rollback();
798 dol_syslog(get_class($this).
"::addLine status of BOM must be Draft to allow use of ->addLine()", LOG_ERR);
813 if ($this->status < 0) {
814 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
821 $line =
new BOMLine($this->db);
822 $line->fetch($idline);
823 $line->fetch_optionals();
825 $staticLine = clone $line;
826 $line->oldcopy = $staticLine;
827 $line->context = $this->context;
829 $result = $line->delete($user, $notrigger);
832 foreach ($this->lines as $bl) {
833 if ($bl->position > ($line->oldcopy->position)) {
845 dol_syslog(get_class($this).
"::addLine error=".$this->error, LOG_ERR);
846 $this->db->rollback();
860 global $langs, $conf;
863 if (!empty($conf->global->BOM_ADDON)) {
866 $file = $conf->global->BOM_ADDON.
".php";
867 $classname = $conf->global->BOM_ADDON;
870 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
871 foreach ($dirmodels as $reldir) {
875 $mybool |= @include_once $dir.$file;
878 if ($mybool ===
false) {
883 $obj =
new $classname();
884 $numref = $obj->getNextValue($prod, $this);
889 $this->error = $obj->error;
894 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOM_ADDON_NotDefined");
908 global $conf, $langs;
910 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
915 if ($this->status == self::STATUS_VALIDATED) {
916 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
933 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
942 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
943 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
944 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
945 $sql .=
" date_valid='".$this->db->idate($now).
"',";
946 $sql .=
" fk_user_valid = ".((int) $user->id);
947 $sql .=
" WHERE rowid = ".((int) $this->
id);
949 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
950 $resql = $this->db->query($sql);
953 $this->error = $this->db->lasterror();
957 if (!$error && !$notrigger) {
967 $this->oldref = $this->ref;
970 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
972 $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).
"'";
973 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
974 $resql = $this->db->query($sql);
976 $error++; $this->error = $this->db->lasterror();
978 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bom/".$this->db->escape($this->newref).
"'";
979 $sql .=
" WHERE filepath = 'bom/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
980 $resql = $this->db->query($sql);
982 $error++; $this->error = $this->db->lasterror();
988 $dirsource = $conf->bom->dir_output.
'/'.$oldref;
989 $dirdest = $conf->bom->dir_output.
'/'.$newref;
990 if (!$error && file_exists($dirsource)) {
991 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
993 if (@rename($dirsource, $dirdest)) {
996 $listoffiles =
dol_dir_list($conf->bom->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
997 foreach ($listoffiles as $fileentry) {
998 $dirsource = $fileentry[
'name'];
999 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1000 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1001 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1002 @rename($dirsource, $dirdest);
1012 $this->status = self::STATUS_VALIDATED;
1016 $this->db->commit();
1019 $this->db->rollback();
1034 if ($this->status <= self::STATUS_DRAFT) {
1045 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'BOM_UNVALIDATE');
1055 public function cancel($user, $notrigger = 0)
1058 if ($this->status != self::STATUS_VALIDATED) {
1069 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'BOM_CLOSE');
1079 public function reopen($user, $notrigger = 0)
1082 if ($this->status != self::STATUS_CANCELED) {
1093 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'BOM_REOPEN');
1104 global $conf, $langs, $user;
1106 $langs->loadLangs([
'product',
'mrp']);
1110 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1111 return [
'optimize' => $langs->trans(
"ShowBillOfMaterials")];
1113 $picto =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"BillOfMaterials").
'</u>';
1114 if (isset($this->status)) {
1115 $picto .=
' '.$this->getLibStatut(5);
1117 $datas[
'picto'] = $picto;
1118 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1119 if (isset($this->label)) {
1120 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1122 if (!empty($this->fk_product) && $this->fk_product > 0) {
1123 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1124 $product =
new Product($this->db);
1125 $resultFetch = $product->fetch($this->fk_product);
1126 if ($resultFetch > 0) {
1127 $datas[
'product'] =
"<br><b>".$langs->trans(
"Product").
'</b>: '.$product->ref.
' - '.$product->label;
1144 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1146 global $db, $conf, $langs, $hookmanager;
1148 if (!empty($conf->dol_no_mouse_hover)) {
1155 'objecttype' => $this->element,
1156 'option' => $option,
1158 $classfortooltip =
'classfortooltip';
1161 $classfortooltip =
'classforajaxtooltip';
1162 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1168 $url = DOL_URL_ROOT.
'/bom/bom_card.php?id='.$this->id;
1170 if ($option !=
'nolink') {
1172 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1173 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1174 $add_save_lastsearch_values = 1;
1176 if ($add_save_lastsearch_values) {
1177 $url .=
'&save_lastsearch_values=1';
1182 if (empty($notooltip)) {
1183 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1184 $label = $langs->trans(
"ShowBillOfMaterials");
1185 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1187 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1188 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1190 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1193 $linkstart =
'<a href="'.$url.
'"';
1194 $linkstart .= $linkclose.
'>';
1197 $result .= $linkstart;
1199 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1201 if ($withpicto != 2) {
1202 $result .= $this->ref;
1204 $result .= $linkend;
1207 global $action, $hookmanager;
1208 $hookmanager->initHooks(array(
'bomdao'));
1209 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1210 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1212 $result = $hookmanager->resPrint;
1214 $result .= $hookmanager->resPrint;
1228 return $this->
LibStatut($this->status, $mode);
1242 if (empty($this->labelStatus)) {
1245 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1246 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
1247 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
1250 $statusType =
'status'.$status;
1251 if ($status == self::STATUS_VALIDATED) {
1252 $statusType =
'status4';
1254 if ($status == self::STATUS_CANCELED) {
1255 $statusType =
'status6';
1258 return dolGetStatus($this->labelStatus[$status], $this->labelStatus[$status],
'', $statusType, $mode);
1269 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1270 $sql .=
' fk_user_creat, fk_user_modif';
1271 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1272 $sql .=
' WHERE t.rowid = '.((int) $id);
1273 $result = $this->db->query($sql);
1275 if ($this->db->num_rows($result)) {
1276 $obj = $this->db->fetch_object($result);
1277 $this->
id = $obj->rowid;
1279 $this->user_creation_id = $obj->fk_user_creat;
1280 $this->user_modification_id = $obj->fk_user_modif;
1281 $this->date_creation = $this->db->jdate($obj->datec);
1282 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
1285 $this->db->free($result);
1298 $this->lines = array();
1300 $objectline =
new BOMLine($this->db);
1301 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_bom = '.((
int) $this->
id)));
1303 if (is_numeric($result)) {
1304 $this->error = $objectline->error;
1305 $this->errors = $objectline->errors;
1308 $this->lines = $result;
1309 return $this->lines;
1324 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1326 global $conf, $langs;
1328 $langs->load(
"mrp");
1329 $outputlangs->load(
"products");
1334 if ($this->model_pdf) {
1335 $modele = $this->model_pdf;
1336 } elseif (!empty($conf->global->BOM_ADDON_PDF)) {
1337 $modele = $conf->global->BOM_ADDON_PDF;
1341 $modelpath =
"core/modules/bom/doc/";
1342 if (!empty($modele)) {
1343 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1358 $this->
ref =
'BOM-123';
1359 $this->date = $this->date_creation;
1371 global $conf, $langs;
1387 $this->db->commit();
1400 global $conf, $hookmanager;
1402 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1403 $this->unit_cost = 0;
1404 $this->total_cost = 0;
1406 $parameters=array();
1407 $reshook = $hookmanager->executeHooks(
'calculateCostsBom', $parameters, $this);
1410 return $hookmanager->resPrint;
1413 if (is_array($this->lines) && count($this->lines)) {
1414 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1416 $tmpproduct =
new Product($this->db);
1418 foreach ($this->lines as &$line) {
1419 $tmpproduct->cost_price = 0;
1420 $tmpproduct->pmp = 0;
1421 $result = $tmpproduct->fetch($line->fk_product,
'',
'',
'', 0, 1, 1);
1423 if ($tmpproduct->type == $tmpproduct::TYPE_PRODUCT) {
1424 if (empty($line->fk_bom_child)) {
1426 $this->error = $tmpproduct->error;
1429 $line->unit_cost =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1430 if (empty($line->unit_cost)) {
1431 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
1432 if ($productFournisseur->fourn_remise_percent !=
"0") {
1433 $line->unit_cost = $productFournisseur->fourn_unitprice_with_discount;
1435 $line->unit_cost = $productFournisseur->fourn_unitprice;
1440 $line->total_cost =
price2num($line->qty * $line->unit_cost,
'MT');
1442 $this->total_cost += $line->total_cost;
1444 $bom_child =
new BOM($this->db);
1445 $res = $bom_child->fetch($line->fk_bom_child);
1447 $bom_child->calculateCosts();
1448 $line->childBom[] = $bom_child;
1449 $this->total_cost +=
price2num($bom_child->total_cost * $line->qty,
'MT');
1450 $this->total_cost += $line->total_cost;
1452 $this->error = $bom_child->error;
1461 if (isModEnabled(
'workstation') && !empty($tmpproduct->fk_default_workstation)) {
1463 $res = $workstation->fetch($tmpproduct->fk_default_workstation);
1465 if ($res > 0) $line->total_cost =
price2num($qtyhourforline * ($workstation->thm_operator_estimated + $workstation->thm_machine_estimated),
'MT');
1467 $this->error = $workstation->error;
1471 $defaultdurationofservice = $tmpproduct->duration;
1473 $qtyhourservice = 0;
1474 if (preg_match(
'/^(\d+)([a-z]+)$/', $defaultdurationofservice, $reg)) {
1478 if ($qtyhourservice) {
1479 $line->total_cost =
price2num($qtyhourforline / $qtyhourservice * $tmpproduct->cost_price,
'MT');
1481 $line->total_cost =
price2num($line->qty * $tmpproduct->cost_price,
'MT');
1485 $this->total_cost += $line->total_cost;
1489 $this->total_cost =
price2num($this->total_cost,
'MT');
1491 if ($this->qty > 0) {
1492 $this->unit_cost =
price2num($this->total_cost / $this->qty,
'MU');
1493 } elseif ($this->qty < 0) {
1494 $this->unit_cost =
price2num($this->total_cost * $this->qty,
'MU');
1527 if (!empty($this->lines)) {
1528 foreach ($this->lines as $line) {
1529 if (!empty($line->childBom)) {
1530 foreach ($line->childBom as $childBom) $childBom->getNetNeeds($TNetNeeds, $line->qty*$qty);
1532 if (empty($TNetNeeds[$line->fk_product])) {
1533 $TNetNeeds[$line->fk_product] = 0;
1535 $TNetNeeds[$line->fk_product] += $line->qty*$qty;
1551 if (!empty($this->lines)) {
1552 foreach ($this->lines as $line) {
1553 if (!empty($line->childBom)) {
1554 foreach ($line->childBom as $childBom) {
1555 $TNetNeeds[$childBom->id][
'bom'] = $childBom;
1556 $TNetNeeds[$childBom->id][
'parentid'] = $this->id;
1557 $TNetNeeds[$childBom->id][
'qty'] = $line->qty*$qty;
1558 $TNetNeeds[$childBom->id][
'level'] = $level;
1559 $childBom->getNetNeedsTree($TNetNeeds, $line->qty*$qty, $level+1);
1562 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'qty'] += $line->qty * $qty;
1563 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'level'] = $level;
1581 if ($level > 1000) {
1585 if (empty($bom_id)) $bom_id=$this->id;
1587 $sql =
'SELECT l.fk_bom, b.label
1588 FROM '.MAIN_DB_PREFIX.
'bom_bomline l
1589 INNER JOIN '.MAIN_DB_PREFIX.$this->table_element.
' b ON b.rowid = l.fk_bom
1590 WHERE fk_bom_child = '.((int) $bom_id);
1592 $resql = $this->db->query($sql);
1593 if (!empty($resql)) {
1594 while ($res = $this->db->fetch_object($resql)) {
1595 $TParentBom[$res->fk_bom] = $res->fk_bom;
1612 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1615 $prod->fetch($this->fk_product);
1617 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1618 $return .=
'<div class="info-box info-box-sm">';
1619 $return .=
'<span class="info-box-icon bg-infobox-action">';
1621 $return .=
'</span>';
1622 $return .=
'<div class="info-box-content">';
1623 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() :
'').
'</span>';
1624 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1625 if (property_exists($this,
'fields') && !empty($this->fields[
'bomtype'][
'arrayofkeyval'])) {
1626 $return .=
'<br><span class="info-box-label opacitymedium">'.$langs->trans(
"Type").
' : </span>';
1627 if ($this->bomtype == 0) {
1628 $return .=
'<span class="info-box-label">'.$this->fields[
'bomtype'][
'arrayofkeyval'][0].
'</span>';
1630 $return .=
'<span class="info-box-label">'.$this->fields[
'bomtype'][
'arrayofkeyval'][1].
'</span>';
1633 if (property_exists($this,
'fk_product') && !is_null($this->fk_product)) {
1634 $return .=
'<br><span class="info-box-label">'.$prod->getNomUrl(1).
'</span>';
1636 if (method_exists($this,
'getLibStatut')) {
1637 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1640 $return .=
'</div>';
1641 $return .=
'</div>';
1642 $return .=
'</div>';
1656 public $element =
'bomline';
1661 public $table_element =
'bom_bomline';
1666 public $ismultientitymanaged = 0;
1671 public $isextrafieldmanaged = 1;
1676 public $picto =
'bomline';
1702 public $fields = array(
1703 'rowid' => array(
'type'=>
'integer',
'label'=>
'LineID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
1704 'fk_bom' => array(
'type'=>
'integer:BillOfMaterials:societe/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,),
1705 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
1706 'fk_bom_child' => array(
'type'=>
'integer:BOM:bom/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>-1,
'position'=>40,
'notnull'=>-1,),
1707 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
1708 'qty' => array(
'type'=>
'double(24,8)',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'notnull'=>1,
'isameasure'=>
'1',),
1709 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1710 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1711 'efficiency' => array(
'type'=>
'double(24,8)',
'label'=>
'ManufacturingEfficiency',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'position'=>110,
'notnull'=>1,
'css'=>
'maxwidth50imp',
'help'=>
'ValueOfEfficiencyConsumedMeans'),
1712 'fk_unit' => array(
'type'=>
'integer',
'label'=>
'Unit',
'enabled'=>1,
'visible'=>1,
'position'=>120,
'notnull'=>-1,),
1713 'position' => array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>1,
'visible'=>0,
'default'=>0,
'position'=>200,
'notnull'=>1,),
1714 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
1715 'fk_default_workstation' =>array(
'type'=>
'integer',
'label'=>
'DefaultWorkstation',
'enabled'=>1,
'visible'=>1,
'notnull'=>0,
'position'=>1050)
1736 public $fk_bom_child;
1741 public $description;
1756 public $disable_stock_change;
1777 public $total_cost = 0;
1782 public $unit_cost = 0;
1787 public $childBom = array();
1797 public $fk_default_workstation;
1808 global $conf, $langs;
1812 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
1813 $this->fields[
'rowid'][
'visible'] = 0;
1815 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
1816 $this->fields[
'entity'][
'enabled'] = 0;
1820 foreach ($this->fields as $key => $val) {
1821 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
1822 unset($this->fields[$key]);
1827 foreach ($this->fields as $key => $val) {
1828 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1829 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
1830 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1845 if ($this->efficiency < 0 || $this->efficiency > 1) {
1846 $this->efficiency = 1;
1877 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1887 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1888 if ($this->ismultientitymanaged) {
1889 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
1891 $sql .=
' WHERE 1 = 1';
1894 $sqlwhere = array();
1895 if (count($filter) > 0) {
1896 foreach ($filter as $key => $value) {
1897 if ($key ==
't.rowid') {
1898 $sqlwhere[] = $key.
" = ".((int) $value);
1899 } elseif (strpos($key,
'date') !==
false) {
1900 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
1901 } elseif ($key ==
'customsql') {
1902 $sqlwhere[] = $value;
1904 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
1908 if (count($sqlwhere) > 0) {
1909 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
1912 if (!empty($sortfield)) {
1913 $sql .= $this->db->order($sortfield, $sortorder);
1915 if (!empty($limit)) {
1916 $sql .= $this->db->plimit($limit, $offset);
1919 $resql = $this->db->query($sql);
1921 $num = $this->db->num_rows($resql);
1923 while ($obj = $this->db->fetch_object($resql)) {
1924 $record =
new self($this->db);
1925 $record->setVarsFromFetchObj($obj);
1927 $records[$record->id] = $record;
1929 $this->db->free($resql);
1933 $this->errors[] =
'Error '.$this->db->lasterror();
1934 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1949 if ($this->efficiency < 0 || $this->efficiency > 1) {
1950 $this->efficiency = 1;
1963 public function delete(
User $user, $notrigger =
false)
1979 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1981 global $db, $conf, $langs, $hookmanager;
1983 if (!empty($conf->dol_no_mouse_hover)) {
1989 $label =
'<u>'.$langs->trans(
"BillOfMaterialsLine").
'</u>';
1991 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1993 $url = DOL_URL_ROOT.
'/bom/bomline_card.php?id='.$this->id;
1995 if ($option !=
'nolink') {
1997 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1998 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1999 $add_save_lastsearch_values = 1;
2001 if ($add_save_lastsearch_values) {
2002 $url .=
'&save_lastsearch_values=1';
2007 if (empty($notooltip)) {
2008 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2009 $label = $langs->trans(
"ShowBillOfMaterialsLine");
2010 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2012 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2013 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2015 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
2018 $linkstart =
'<a href="'.$url.
'"';
2019 $linkstart .= $linkclose.
'>';
2022 $result .= $linkstart;
2024 $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);
2026 if ($withpicto != 2) {
2027 $result .= $this->ref;
2029 $result .= $linkend;
2032 global $action, $hookmanager;
2033 $hookmanager->initHooks(array(
'bomlinedao'));
2034 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2035 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2037 $result = $hookmanager->resPrint;
2039 $result .= $hookmanager->resPrint;
2053 return $this->
LibStatut($this->status, $mode);
2078 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
2079 $sql .=
' fk_user_creat, fk_user_modif';
2080 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
2081 $sql .=
' WHERE t.rowid = '.((int) $id);
2082 $result = $this->db->query($sql);
2084 if ($this->db->num_rows($result)) {
2085 $obj = $this->db->fetch_object($result);
2086 $this->
id = $obj->rowid;
2087 $this->user_creation_id = $obj->fk_user_creat;
2088 $this->user_modification_id = $obj->fk_user_modif;
2089 $this->date_creation = $this->db->jdate($obj->datec);
2090 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
2092 $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.
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.
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.
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.
print $langs trans("Ref").' m m m statut
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)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_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.