25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'bom';
43 public $table_element =
'bom_bom';
48 public $ismultientitymanaged = 1;
53 public $isextrafieldmanaged = 1;
58 public $picto =
'bom';
61 const STATUS_DRAFT = 0;
62 const STATUS_VALIDATED = 1;
63 const STATUS_CANCELED = 9;
96 public $fields = array(
97 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
98 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>5),
99 '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'),
100 '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'),
101 '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'),
103 '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'),
104 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
105 'qty' => array(
'type'=>
'real',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'default'=>1,
'position'=>55,
'notnull'=>1,
'isameasure'=>
'1',
'css'=>
'maxwidth75imp'),
107 'duration' => array(
'type'=>
'duration',
'label'=>
'EstimatedDuration',
'enabled'=>1,
'visible'=>-1,
'position'=>101,
'notnull'=>-1,
'css'=>
'maxwidth50imp',
'help'=>
'EstimatedDurationDesc'),
108 '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'),
109 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>-2,
'position'=>161,
'notnull'=>-1,),
110 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>-2,
'position'=>162,
'notnull'=>-1,),
111 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300,
'notnull'=>1,),
112 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
113 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,
'notnull'=>0,),
114 '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'),
115 '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'),
116 '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'),
117 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
118 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
119 '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')),
150 public $date_creation;
158 public $fk_user_creat;
163 public $fk_user_modif;
189 public $table_element_line =
'bom_bomline';
194 public $fk_element =
'fk_bom';
199 public $class_element_line =
'BOMLine';
209 protected $childtablesoncascade = array(
'bom_bomline');
214 public $lines = array();
219 public $total_cost = 0;
224 public $unit_cost = 0;
235 global $conf, $langs;
239 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
240 $this->fields[
'rowid'][
'visible'] = 0;
242 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
243 $this->fields[
'entity'][
'enabled'] = 0;
247 foreach ($this->fields as $key => $val) {
248 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
249 unset($this->fields[$key]);
254 foreach ($this->fields as $key => $val) {
255 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
256 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
257 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
272 if ($this->efficiency <= 0 || $this->efficiency > 1) {
273 $this->efficiency = 1;
288 global $langs, $hookmanager, $extrafields;
293 $object =
new self($this->db);
298 $result = $object->fetchCommon($fromid);
299 if ($result > 0 && !empty($object->table_element_line)) {
300 $object->fetchLines();
309 unset($object->fk_user_creat);
310 unset($object->import_key);
313 $object->ref = empty($this->fields[
'ref'][
'default']) ? $langs->trans(
"copy_of_").$object->ref : $this->fields[
'ref'][
'default'];
314 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
315 $object->status = self::STATUS_DRAFT;
318 if (is_array($object->array_options) && count($object->array_options) > 0) {
319 $extrafields->fetch_name_optionals_label($object->table_element);
320 foreach ($object->array_options as $key => $option) {
321 $shortkey = preg_replace(
'/options_/',
'', $key);
322 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
324 unset($object->array_options[$key]);
330 $object->context[
'createfromclone'] =
'createfromclone';
331 $result = $object->createCommon($user);
334 $this->error = $object->error;
335 $this->errors = $object->errors;
347 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
358 unset($object->context[
'createfromclone']);
365 $this->
db->rollback();
377 public function fetch($id, $ref = null)
381 if ($result > 0 && !empty($this->table_element_line)) {
396 $this->lines = array();
413 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
423 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
424 if ($this->ismultientitymanaged) {
425 $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
427 $sql .=
' WHERE 1 = 1';
431 if (count($filter) > 0) {
432 foreach ($filter as $key => $value) {
433 if ($key ==
't.rowid') {
434 $sqlwhere[] = $key.
" = ".((int) $value);
435 } elseif (strpos($key,
'date') !==
false) {
436 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
437 } elseif ($key ==
'customsql') {
438 $sqlwhere[] = $value;
440 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
444 if (count($sqlwhere) > 0) {
445 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
448 if (!empty($sortfield)) {
449 $sql .= $this->
db->order($sortfield, $sortorder);
451 if (!empty($limit)) {
452 $sql .= $this->
db->plimit($limit, $offset);
459 while ($obj = $this->
db->fetch_object(
$resql)) {
460 $record =
new self($this->db);
461 $record->setVarsFromFetchObj($obj);
463 $records[$record->id] = $record;
469 $this->errors[] =
'Error '.$this->db->lasterror();
470 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
485 if ($this->efficiency <= 0 || $this->efficiency > 1) {
486 $this->efficiency = 1;
499 public function delete(
User $user, $notrigger =
false)
515 if ($this->status < 0) {
516 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
532 global $langs, $conf;
535 if (!empty($conf->global->BOM_ADDON)) {
538 $file = $conf->global->BOM_ADDON.
".php";
539 $classname = $conf->global->BOM_ADDON;
542 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
543 foreach ($dirmodels as $reldir) {
547 $mybool |= @include_once $dir.$file;
550 if ($mybool ===
false) {
555 $obj =
new $classname();
556 $numref = $obj->getNextValue($prod, $this);
561 $this->error = $obj->error;
566 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOM_ADDON_NotDefined");
580 global $conf, $langs;
582 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
587 if ($this->status == self::STATUS_VALIDATED) {
588 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
605 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
614 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
615 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
616 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
617 $sql .=
" date_valid='".$this->db->idate($now).
"',";
618 $sql .=
" fk_user_valid = ".((int) $user->id);
619 $sql .=
" WHERE rowid = ".((int) $this->
id);
621 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
625 $this->error = $this->
db->lasterror();
629 if (!$error && !$notrigger) {
639 $this->oldref = $this->ref;
642 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
644 $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).
"'";
645 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->
db->escape($this->
ref).
"' and entity = ".$conf->entity;
648 $error++; $this->error = $this->
db->lasterror();
654 $dirsource = $conf->bom->dir_output.
'/'.$oldref;
655 $dirdest = $conf->bom->dir_output.
'/'.$newref;
656 if (!$error && file_exists($dirsource)) {
657 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
659 if (@rename($dirsource, $dirdest)) {
662 $listoffiles =
dol_dir_list($conf->bom->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
663 foreach ($listoffiles as $fileentry) {
664 $dirsource = $fileentry[
'name'];
665 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
666 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
667 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
668 @rename($dirsource, $dirdest);
678 $this->status = self::STATUS_VALIDATED;
685 $this->
db->rollback();
700 if ($this->status <= self::STATUS_DRAFT) {
711 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'BOM_UNVALIDATE');
721 public function cancel($user, $notrigger = 0)
724 if ($this->status != self::STATUS_VALIDATED) {
735 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'BOM_CLOSE');
745 public function reopen($user, $notrigger = 0)
748 if ($this->status != self::STATUS_CANCELED) {
759 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'BOM_REOPEN');
773 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
775 global $db, $conf, $langs, $hookmanager;
777 if (!empty($conf->dol_no_mouse_hover)) {
783 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"BillOfMaterials").
'</u>';
784 if (isset($this->status)) {
785 $label .=
' '.$this->getLibStatut(5);
788 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
789 if (isset($this->label)) {
790 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
792 if (!empty($this->fk_product) && $this->fk_product > 0) {
793 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
795 $resultFetch = $product->fetch($this->fk_product);
796 if ($resultFetch > 0) {
797 $label .=
"<br><b>".$langs->trans(
"Product").
'</b>: '.$product->ref.
' - '.$product->label;
802 $url = DOL_URL_ROOT.
'/bom/bom_card.php?id='.$this->id;
804 if ($option !=
'nolink') {
806 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
807 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
808 $add_save_lastsearch_values = 1;
810 if ($add_save_lastsearch_values) {
811 $url .=
'&save_lastsearch_values=1';
816 if (empty($notooltip)) {
817 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
818 $label = $langs->trans(
"ShowBillOfMaterials");
819 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
821 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
822 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
824 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
827 $linkstart =
'<a href="'.$url.
'"';
828 $linkstart .= $linkclose.
'>';
831 $result .= $linkstart;
833 $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);
835 if ($withpicto != 2) {
836 $result .= $this->ref;
841 global $action, $hookmanager;
842 $hookmanager->initHooks(array(
'bomdao'));
843 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
844 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
846 $result = $hookmanager->resPrint;
848 $result .= $hookmanager->resPrint;
862 return $this->
LibStatut($this->status, $mode);
876 if (empty($this->labelStatus)) {
879 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
880 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
881 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
884 $statusType =
'status'.$status;
885 if ($status == self::STATUS_VALIDATED) {
886 $statusType =
'status4';
888 if ($status == self::STATUS_CANCELED) {
889 $statusType =
'status6';
892 return dolGetStatus($this->labelStatus[$status], $this->labelStatus[$status],
'', $statusType, $mode);
903 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
904 $sql .=
' fk_user_creat, fk_user_modif';
905 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
906 $sql .=
' WHERE t.rowid = '.((int) $id);
907 $result = $this->
db->query($sql);
909 if ($this->
db->num_rows($result)) {
910 $obj = $this->
db->fetch_object($result);
911 $this->
id = $obj->rowid;
913 $this->user_creation_id = $obj->fk_user_creat;
914 $this->user_modification_id = $obj->fk_user_modif;
915 $this->date_creation = $this->
db->jdate($obj->datec);
916 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
919 $this->
db->free($result);
932 $this->lines = array();
935 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_bom = '.((
int) $this->
id)));
937 if (is_numeric($result)) {
938 $this->error = $objectline->error;
939 $this->errors = $objectline->errors;
942 $this->lines = $result;
958 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
960 global $conf, $langs;
963 $outputlangs->load(
"products");
966 $modele =
'standard';
968 if ($this->model_pdf) {
969 $modele = $this->model_pdf;
970 } elseif (!empty($conf->global->BOM_ADDON_PDF)) {
971 $modele = $conf->global->BOM_ADDON_PDF;
975 $modelpath =
"core/modules/bom/doc/";
977 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
989 $this->
ref =
'BOM-123';
990 $this->date = $this->date_creation;
1002 global $conf, $langs;
1018 $this->
db->commit();
1031 global $hookmanager;
1033 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1034 $this->unit_cost = 0;
1035 $this->total_cost = 0;
1037 $parameters=array();
1038 $reshook = $hookmanager->executeHooks(
'calculateCostsBom', $parameters, $this);
1042 return $hookmanager->resPrint;
1045 if (is_array($this->lines) && count($this->lines)) {
1046 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1050 foreach ($this->lines as &$line) {
1051 $tmpproduct->cost_price = 0;
1052 $tmpproduct->pmp = 0;
1054 if (empty($line->fk_bom_child)) {
1055 $result = $tmpproduct->fetch($line->fk_product,
'',
'',
'', 0, 1, 1);
1057 $this->error = $tmpproduct->error;
1060 $line->unit_cost =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1061 if (empty($line->unit_cost)) {
1062 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
1063 $line->unit_cost = $productFournisseur->fourn_unitprice;
1067 $line->total_cost =
price2num($line->qty * $line->unit_cost,
'MT');
1069 $this->total_cost += $line->total_cost;
1071 $bom_child=
new BOM($this->
db);
1072 $res = $bom_child->fetch($line->fk_bom_child);
1074 $bom_child->calculateCosts();
1075 $line->childBom[] = $bom_child;
1076 $this->total_cost += $bom_child->total_cost * $line->qty;
1078 $this->error = $bom_child->error;
1084 $this->total_cost =
price2num($this->total_cost,
'MT');
1085 if ($this->qty > 0) {
1086 $this->unit_cost =
price2num($this->total_cost / $this->qty,
'MU');
1087 } elseif ($this->qty < 0) {
1088 $this->unit_cost =
price2num($this->total_cost * $this->qty,
'MU');
1119 if (! empty($this->lines)) {
1120 foreach ($this->lines as $line) {
1121 if (! empty($line->childBom)) {
1122 foreach ($line->childBom as $childBom) $childBom->getNetNeeds($TNetNeeds, $line->qty*$qty);
1124 if (empty($TNetNeeds[$line->fk_product])) {
1125 $TNetNeeds[$line->fk_product] = 0;
1127 $TNetNeeds[$line->fk_product] += $line->qty*$qty;
1143 if (! empty($this->lines)) {
1144 foreach ($this->lines as $line) {
1145 if (! empty($line->childBom)) {
1146 foreach ($line->childBom as $childBom) {
1147 $TNetNeeds[$childBom->id][
'bom'] = $childBom;
1148 $TNetNeeds[$childBom->id][
'parentid'] = $this->id;
1149 $TNetNeeds[$childBom->id][
'qty'] = $line->qty*$qty;
1150 $TNetNeeds[$childBom->id][
'level'] = $level;
1151 $childBom->getNetNeedsTree($TNetNeeds, $line->qty*$qty, $level+1);
1154 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'qty'] += $line->qty * $qty;
1155 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'level'] = $level;
1173 if ($level > 1000) {
1177 if (empty($bom_id)) $bom_id=$this->id;
1179 $sql =
'SELECT l.fk_bom, b.label
1180 FROM '.MAIN_DB_PREFIX.
'bom_bomline l
1181 INNER JOIN '.MAIN_DB_PREFIX.$this->table_element.
' b ON b.rowid = l.fk_bom
1182 WHERE fk_bom_child = '.((int) $bom_id);
1186 while ($res = $this->
db->fetch_object(
$resql)) {
1187 $TParentBom[$res->fk_bom] = $res->fk_bom;
1203 public $element =
'bomline';
1208 public $table_element =
'bom_bomline';
1213 public $ismultientitymanaged = 0;
1218 public $isextrafieldmanaged = 1;
1223 public $picto =
'bomline';
1249 public $fields = array(
1250 'rowid' => array(
'type'=>
'integer',
'label'=>
'LineID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
1251 'fk_bom' => array(
'type'=>
'integer:BillOfMaterials:societe/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,),
1252 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
1253 'fk_bom_child' => array(
'type'=>
'integer:BOM:bom/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>-1,
'position'=>40,
'notnull'=>-1,),
1254 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
1255 'qty' => array(
'type'=>
'double(24,8)',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'notnull'=>1,
'isameasure'=>
'1',),
1256 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1257 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1258 'efficiency' => array(
'type'=>
'double(24,8)',
'label'=>
'ManufacturingEfficiency',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'position'=>110,
'notnull'=>1,
'css'=>
'maxwidth50imp',
'help'=>
'ValueOfEfficiencyConsumedMeans'),
1259 'position' => array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>1,
'visible'=>0,
'default'=>0,
'position'=>200,
'notnull'=>1,),
1260 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
1281 public $fk_bom_child;
1286 public $description;
1293 public $disable_stock_change;
1310 public $total_cost = 0;
1315 public $unit_cost = 0;
1321 public $childBom = array();
1331 global $conf, $langs;
1335 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
1336 $this->fields[
'rowid'][
'visible'] = 0;
1338 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
1339 $this->fields[
'entity'][
'enabled'] = 0;
1343 foreach ($this->fields as $key => $val) {
1344 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
1345 unset($this->fields[$key]);
1350 foreach ($this->fields as $key => $val) {
1351 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1352 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
1353 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1368 if ($this->efficiency < 0 || $this->efficiency > 1) {
1369 $this->efficiency = 1;
1400 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1410 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1411 if ($this->ismultientitymanaged) {
1412 $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
1414 $sql .=
' WHERE 1 = 1';
1417 $sqlwhere = array();
1418 if (count($filter) > 0) {
1419 foreach ($filter as $key => $value) {
1420 if ($key ==
't.rowid') {
1421 $sqlwhere[] = $key.
" = ".((int) $value);
1422 } elseif (strpos($key,
'date') !==
false) {
1423 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
1424 } elseif ($key ==
'customsql') {
1425 $sqlwhere[] = $value;
1427 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
1431 if (count($sqlwhere) > 0) {
1432 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
1435 if (!empty($sortfield)) {
1436 $sql .= $this->
db->order($sortfield, $sortorder);
1438 if (!empty($limit)) {
1439 $sql .= $this->
db->plimit($limit, $offset);
1444 $num = $this->
db->num_rows(
$resql);
1446 while ($obj = $this->
db->fetch_object(
$resql)) {
1447 $record =
new self($this->db);
1448 $record->setVarsFromFetchObj($obj);
1450 $records[$record->id] = $record;
1456 $this->errors[] =
'Error '.$this->db->lasterror();
1457 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1472 if ($this->efficiency < 0 || $this->efficiency > 1) {
1473 $this->efficiency = 1;
1486 public function delete(
User $user, $notrigger =
false)
1502 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1504 global $db, $conf, $langs, $hookmanager;
1506 if (!empty($conf->dol_no_mouse_hover)) {
1512 $label =
'<u>'.$langs->trans(
"BillOfMaterialsLine").
'</u>';
1514 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1516 $url = DOL_URL_ROOT.
'/bom/bomline_card.php?id='.$this->id;
1518 if ($option !=
'nolink') {
1520 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1521 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1522 $add_save_lastsearch_values = 1;
1524 if ($add_save_lastsearch_values) {
1525 $url .=
'&save_lastsearch_values=1';
1530 if (empty($notooltip)) {
1531 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1532 $label = $langs->trans(
"ShowBillOfMaterialsLine");
1533 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1535 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1536 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1538 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1541 $linkstart =
'<a href="'.$url.
'"';
1542 $linkstart .= $linkclose.
'>';
1545 $result .= $linkstart;
1547 $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);
1549 if ($withpicto != 2) {
1550 $result .= $this->ref;
1552 $result .= $linkend;
1555 global $action, $hookmanager;
1556 $hookmanager->initHooks(array(
'bomlinedao'));
1557 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1558 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1560 $result = $hookmanager->resPrint;
1562 $result .= $hookmanager->resPrint;
1576 return $this->
LibStatut($this->status, $mode);
1601 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1602 $sql .=
' fk_user_creat, fk_user_modif';
1603 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1604 $sql .=
' WHERE t.rowid = '.((int) $id);
1605 $result = $this->
db->query($sql);
1607 if ($this->
db->num_rows($result)) {
1608 $obj = $this->
db->fetch_object($result);
1609 $this->
id = $obj->rowid;
1610 $this->user_creation_id = $obj->fk_user_creat;
1611 $this->user_modification_id = $obj->fk_user_modif;
1612 $this->date_creation = $this->
db->jdate($obj->datec);
1613 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
1615 $this->
db->free($result);
create(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getLibStatut($mode=0)
Return label of the status.
getNetNeedsTree(&$TNetNeeds=array(), $qty=0, $level=0)
Get Net needs Tree by product or bom.
fetch($id, $ref=null)
Load object in memory from the database.
calculateCosts()
BOM costs calculation based on cost_price or pmp of each BOM line.
getNextNumRef($prod)
Returns the reference to the following non used BOM depending on the active numbering module defined ...
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchLinesCommon($morewhere= '')
Load object in memory from the database.
$conf db
API class for accounts.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
createFromClone(User $user, $fromid)
Clone an object into another one.
reopen($user, $notrigger=0)
Set cancel status.
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
Class to manage Dolibarr users.
cancel($user, $notrigger=0)
Set cancel status.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.
getLibStatut($mode=0)
Return label of the status.
LibStatut($status, $mode=0)
Return the status.
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.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
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.
__construct(DoliDB $db)
Constructor.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
validate($user, $notrigger=0)
Validate bom.
getNetNeeds(&$TNetNeeds=array(), $qty=0)
Get Net needs by product.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
create(User $user, $notrigger=false)
Create object into database.
update(User $user, $notrigger=false)
Update object into database.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
getFieldList($alias= '')
Function to concat keys of fields.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
update(User $user, $notrigger=false)
Update object into database.
setDraft($user, $notrigger=0)
Set draft status.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
info($id)
Load the info information in the object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
LibStatut($status, $mode=0)
Return the status.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
getParentBomTreeRecursive(&$TParentBom, $bom_id= '', $level=1)
Recursively retrieves all parent bom in the tree that leads to the $bom_id bom.
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.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetchLines()
Load object lines in memory from the database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load the info information in the object.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
fetch($id, $ref=null)
Load object in memory from the database.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getLinesArray()
Create an array of lines.
setStatusCommon($user, $status, $notrigger=0, $triggercode= '')
Set to a status.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
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.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load list of objects in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
Class to manage predefined suppliers products.
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.