26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'bom';
44 public $table_element =
'bom_bom';
49 public $ismultientitymanaged = 1;
54 public $isextrafieldmanaged = 1;
59 public $picto =
'bom';
62 const STATUS_DRAFT = 0;
63 const STATUS_VALIDATED = 1;
64 const STATUS_CANCELED = 9;
97 public $fields = array(
98 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
99 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>5),
100 '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'),
101 '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'),
102 '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'),
104 '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'),
105 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
106 'qty' => array(
'type'=>
'real',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'default'=>1,
'position'=>55,
'notnull'=>1,
'isameasure'=>
'1',
'css'=>
'maxwidth75imp'),
108 'duration' => array(
'type'=>
'duration',
'label'=>
'EstimatedDuration',
'enabled'=>1,
'visible'=>-1,
'position'=>101,
'notnull'=>-1,
'css'=>
'maxwidth50imp',
'help'=>
'EstimatedDurationDesc'),
109 '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'),
110 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>-2,
'position'=>161,
'notnull'=>-1,),
111 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>-2,
'position'=>162,
'notnull'=>-1,),
112 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300,
'notnull'=>1,),
113 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
114 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,
'notnull'=>0,),
115 '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'),
116 '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'),
117 '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'),
118 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
119 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
120 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>1,
'visible'=>2,
'position'=>1000,
'notnull'=>1,
'default'=>0,
'index'=>1,
'arrayofkeyval'=>array(0=>
'Draft', 1=>
'Enabled', 9=>
'Disabled')),
151 public $date_creation;
159 public $fk_user_creat;
164 public $fk_user_modif;
190 public $table_element_line =
'bom_bomline';
195 public $fk_element =
'fk_bom';
200 public $class_element_line =
'BOMLine';
210 protected $childtablesoncascade = array(
'bom_bomline');
215 public $lines = array();
220 public $total_cost = 0;
225 public $unit_cost = 0;
236 global $conf, $langs;
240 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
241 $this->fields[
'rowid'][
'visible'] = 0;
243 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
244 $this->fields[
'entity'][
'enabled'] = 0;
248 foreach ($this->fields as $key => $val) {
249 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
250 unset($this->fields[$key]);
255 foreach ($this->fields as $key => $val) {
256 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
257 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
258 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
273 if ($this->efficiency <= 0 || $this->efficiency > 1) {
274 $this->efficiency = 1;
289 global $langs, $hookmanager, $extrafields;
294 $object =
new self($this->db);
299 $result = $object->fetchCommon($fromid);
300 if ($result > 0 && !empty($object->table_element_line)) {
301 $object->fetchLines();
310 unset($object->fk_user_creat);
311 unset($object->import_key);
314 $object->ref = empty($this->fields[
'ref'][
'default']) ? $langs->trans(
"copy_of_").$object->ref : $this->fields[
'ref'][
'default'];
315 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
316 $object->status = self::STATUS_DRAFT;
319 if (is_array($object->array_options) && count($object->array_options) > 0) {
320 $extrafields->fetch_name_optionals_label($object->table_element);
321 foreach ($object->array_options as $key => $option) {
322 $shortkey = preg_replace(
'/options_/',
'', $key);
323 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
325 unset($object->array_options[$key]);
331 $object->context[
'createfromclone'] =
'createfromclone';
332 $result = $object->createCommon($user);
335 $this->error = $object->error;
336 $this->errors = $object->errors;
348 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
359 unset($object->context[
'createfromclone']);
366 $this->
db->rollback();
378 public function fetch($id, $ref =
null)
382 if ($result > 0 && !empty($this->table_element_line)) {
397 $this->lines = array();
414 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
424 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
425 if ($this->ismultientitymanaged) {
426 $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
428 $sql .=
' WHERE 1 = 1';
432 if (count($filter) > 0) {
433 foreach ($filter as $key => $value) {
434 if ($key ==
't.rowid') {
435 $sqlwhere[] = $key.
" = ".((int) $value);
436 } elseif (strpos($key,
'date') !==
false) {
437 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
438 } elseif ($key ==
'customsql') {
439 $sqlwhere[] = $value;
441 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
445 if (count($sqlwhere) > 0) {
446 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
449 if (!empty($sortfield)) {
450 $sql .= $this->
db->order($sortfield, $sortorder);
452 if (!empty($limit)) {
453 $sql .= $this->
db->plimit($limit, $offset);
460 while ($obj = $this->
db->fetch_object(
$resql)) {
461 $record =
new self($this->db);
462 $record->setVarsFromFetchObj($obj);
464 $records[$record->id] = $record;
470 $this->errors[] =
'Error '.$this->db->lasterror();
471 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
486 if ($this->efficiency <= 0 || $this->efficiency > 1) {
487 $this->efficiency = 1;
500 public function delete(
User $user, $notrigger =
false)
516 if ($this->status < 0) {
517 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
533 global $langs, $conf;
536 if (!empty($conf->global->BOM_ADDON)) {
539 $file = $conf->global->BOM_ADDON.
".php";
540 $classname = $conf->global->BOM_ADDON;
543 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
544 foreach ($dirmodels as $reldir) {
548 $mybool |= @include_once $dir.$file;
551 if ($mybool ===
false) {
556 $obj =
new $classname();
557 $numref = $obj->getNextValue($prod, $this);
562 $this->error = $obj->error;
567 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOM_ADDON_NotDefined");
581 global $conf, $langs;
583 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
588 if ($this->status == self::STATUS_VALIDATED) {
589 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
606 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
615 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
616 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
617 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
618 $sql .=
" date_valid='".$this->db->idate($now).
"',";
619 $sql .=
" fk_user_valid = ".((int) $user->id);
620 $sql .=
" WHERE rowid = ".((int) $this->
id);
622 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
626 $this->error = $this->
db->lasterror();
630 if (!$error && !$notrigger) {
640 $this->oldref = $this->ref;
643 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
645 $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).
"'";
646 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->
db->escape($this->
ref).
"' and entity = ".$conf->entity;
649 $error++; $this->error = $this->
db->lasterror();
655 $dirsource = $conf->bom->dir_output.
'/'.$oldref;
656 $dirdest = $conf->bom->dir_output.
'/'.$newref;
657 if (!$error && file_exists($dirsource)) {
658 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
660 if (@rename($dirsource, $dirdest)) {
663 $listoffiles =
dol_dir_list($conf->bom->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
664 foreach ($listoffiles as $fileentry) {
665 $dirsource = $fileentry[
'name'];
666 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
667 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
668 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
669 @rename($dirsource, $dirdest);
679 $this->status = self::STATUS_VALIDATED;
686 $this->
db->rollback();
701 if ($this->status <= self::STATUS_DRAFT) {
712 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'BOM_UNVALIDATE');
722 public function cancel($user, $notrigger = 0)
725 if ($this->status != self::STATUS_VALIDATED) {
736 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'BOM_CLOSE');
746 public function reopen($user, $notrigger = 0)
749 if ($this->status != self::STATUS_CANCELED) {
760 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'BOM_REOPEN');
774 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
776 global $db, $conf, $langs, $hookmanager;
778 if (!empty($conf->dol_no_mouse_hover)) {
784 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"BillOfMaterials").
'</u>';
785 if (isset($this->status)) {
786 $label .=
' '.$this->getLibStatut(5);
789 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
790 if (isset($this->label)) {
791 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
793 if (!empty($this->fk_product) && $this->fk_product > 0) {
794 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
796 $resultFetch = $product->fetch($this->fk_product);
797 if ($resultFetch > 0) {
798 $label .=
"<br><b>".$langs->trans(
"Product").
'</b>: '.$product->ref.
' - '.$product->label;
803 $url = DOL_URL_ROOT.
'/bom/bom_card.php?id='.$this->id;
805 if ($option !=
'nolink') {
807 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
808 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
809 $add_save_lastsearch_values = 1;
811 if ($add_save_lastsearch_values) {
812 $url .=
'&save_lastsearch_values=1';
817 if (empty($notooltip)) {
818 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
819 $label = $langs->trans(
"ShowBillOfMaterials");
820 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
822 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
823 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
825 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
828 $linkstart =
'<a href="'.$url.
'"';
829 $linkstart .= $linkclose.
'>';
832 $result .= $linkstart;
834 $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);
836 if ($withpicto != 2) {
837 $result .= $this->ref;
842 global $action, $hookmanager;
843 $hookmanager->initHooks(array(
'bomdao'));
844 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
845 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
847 $result = $hookmanager->resPrint;
849 $result .= $hookmanager->resPrint;
863 return $this->
LibStatut($this->status, $mode);
877 if (empty($this->labelStatus)) {
880 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
881 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
882 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
885 $statusType =
'status'.$status;
886 if ($status == self::STATUS_VALIDATED) {
887 $statusType =
'status4';
889 if ($status == self::STATUS_CANCELED) {
890 $statusType =
'status6';
893 return dolGetStatus($this->labelStatus[$status], $this->labelStatus[$status],
'', $statusType, $mode);
904 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
905 $sql .=
' fk_user_creat, fk_user_modif';
906 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
907 $sql .=
' WHERE t.rowid = '.((int) $id);
908 $result = $this->
db->query($sql);
910 if ($this->
db->num_rows($result)) {
911 $obj = $this->
db->fetch_object($result);
912 $this->
id = $obj->rowid;
914 $this->user_creation_id = $obj->fk_user_creat;
915 $this->user_modification_id = $obj->fk_user_modif;
916 $this->date_creation = $this->
db->jdate($obj->datec);
917 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
920 $this->
db->free($result);
933 $this->lines = array();
936 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_bom = '.((
int) $this->
id)));
938 if (is_numeric($result)) {
939 $this->error = $objectline->error;
940 $this->errors = $objectline->errors;
943 $this->lines = $result;
959 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
961 global $conf, $langs;
964 $outputlangs->load(
"products");
967 $modele =
'standard';
969 if ($this->model_pdf) {
970 $modele = $this->model_pdf;
971 } elseif (!empty($conf->global->BOM_ADDON_PDF)) {
972 $modele = $conf->global->BOM_ADDON_PDF;
976 $modelpath =
"core/modules/bom/doc/";
978 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
990 $this->
ref =
'BOM-123';
991 $this->date = $this->date_creation;
1003 global $conf, $langs;
1019 $this->
db->commit();
1032 global $hookmanager;
1034 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1035 $this->unit_cost = 0;
1036 $this->total_cost = 0;
1038 $parameters=array();
1039 $reshook = $hookmanager->executeHooks(
'calculateCostsBom', $parameters, $this);
1043 return $hookmanager->resPrint;
1046 if (is_array($this->lines) && count($this->lines)) {
1047 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1051 foreach ($this->lines as &$line) {
1052 $tmpproduct->cost_price = 0;
1053 $tmpproduct->pmp = 0;
1055 if (empty($line->fk_bom_child)) {
1056 $result = $tmpproduct->fetch($line->fk_product,
'',
'',
'', 0, 1, 1);
1058 $this->error = $tmpproduct->error;
1061 $line->unit_cost =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1062 if ((empty($line->unit_cost)) && ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0)) {
1063 if ($productFournisseur->fourn_remise_percent !=
"0") {
1064 $line->unit_cost = $productFournisseur->fourn_unitprice_with_discount;
1066 $line->unit_cost = $productFournisseur->fourn_unitprice;
1070 $line->total_cost =
price2num($line->qty * $line->unit_cost,
'MT');
1072 $this->total_cost += $line->total_cost;
1074 $bom_child=
new BOM($this->
db);
1075 $res = $bom_child->fetch($line->fk_bom_child);
1077 $bom_child->calculateCosts();
1078 $line->childBom[] = $bom_child;
1079 $line->total_cost =
price2num($bom_child->total_cost * $line->qty,
'MT');
1080 $this->total_cost += $line->total_cost;
1082 $this->error = $bom_child->error;
1088 $this->total_cost =
price2num($this->total_cost,
'MT');
1089 if ($this->qty > 0) {
1090 $this->unit_cost =
price2num($this->total_cost / $this->qty,
'MU');
1091 } elseif ($this->qty < 0) {
1092 $this->unit_cost =
price2num($this->total_cost * $this->qty,
'MU');
1123 if (! empty($this->lines)) {
1124 foreach ($this->lines as $line) {
1125 if (! empty($line->childBom)) {
1126 foreach ($line->childBom as $childBom) $childBom->getNetNeeds($TNetNeeds, $line->qty*$qty);
1128 if (empty($TNetNeeds[$line->fk_product])) {
1129 $TNetNeeds[$line->fk_product] = 0;
1131 $TNetNeeds[$line->fk_product] += $line->qty*$qty;
1147 if (! empty($this->lines)) {
1148 foreach ($this->lines as $line) {
1149 if (! empty($line->childBom)) {
1150 foreach ($line->childBom as $childBom) {
1151 $TNetNeeds[$childBom->id][
'bom'] = $childBom;
1152 $TNetNeeds[$childBom->id][
'parentid'] = $this->id;
1153 $TNetNeeds[$childBom->id][
'qty'] = $line->qty*$qty;
1154 $TNetNeeds[$childBom->id][
'level'] = $level;
1155 $childBom->getNetNeedsTree($TNetNeeds, $line->qty*$qty, $level+1);
1158 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'qty'] += $line->qty * $qty;
1159 $TNetNeeds[$this->id][
'product'][$line->fk_product][
'level'] = $level;
1177 if ($level > 1000) {
1181 if (empty($bom_id)) $bom_id=$this->id;
1183 $sql =
'SELECT l.fk_bom, b.label
1184 FROM '.MAIN_DB_PREFIX.
'bom_bomline l
1185 INNER JOIN '.MAIN_DB_PREFIX.$this->table_element.
' b ON b.rowid = l.fk_bom
1186 WHERE fk_bom_child = '.((int) $bom_id);
1190 while ($res = $this->
db->fetch_object(
$resql)) {
1191 $TParentBom[$res->fk_bom] = $res->fk_bom;
1207 public $element =
'bomline';
1212 public $table_element =
'bom_bomline';
1217 public $ismultientitymanaged = 0;
1222 public $isextrafieldmanaged = 1;
1227 public $picto =
'bomline';
1253 public $fields = array(
1254 'rowid' => array(
'type'=>
'integer',
'label'=>
'LineID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
1255 'fk_bom' => array(
'type'=>
'integer:BillOfMaterials:societe/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,),
1256 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
1257 'fk_bom_child' => array(
'type'=>
'integer:BOM:bom/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>-1,
'position'=>40,
'notnull'=>-1,),
1258 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
1259 'qty' => array(
'type'=>
'double(24,8)',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'notnull'=>1,
'isameasure'=>
'1',),
1260 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1261 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1262 'efficiency' => array(
'type'=>
'double(24,8)',
'label'=>
'ManufacturingEfficiency',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'position'=>110,
'notnull'=>1,
'css'=>
'maxwidth50imp',
'help'=>
'ValueOfEfficiencyConsumedMeans'),
1263 'position' => array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>1,
'visible'=>0,
'default'=>0,
'position'=>200,
'notnull'=>1,),
1264 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
1285 public $fk_bom_child;
1290 public $description;
1297 public $disable_stock_change;
1314 public $total_cost = 0;
1319 public $unit_cost = 0;
1325 public $childBom = array();
1335 global $conf, $langs;
1339 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
1340 $this->fields[
'rowid'][
'visible'] = 0;
1342 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
1343 $this->fields[
'entity'][
'enabled'] = 0;
1347 foreach ($this->fields as $key => $val) {
1348 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
1349 unset($this->fields[$key]);
1354 foreach ($this->fields as $key => $val) {
1355 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
1356 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
1357 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1372 if ($this->efficiency < 0 || $this->efficiency > 1) {
1373 $this->efficiency = 1;
1404 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1414 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1415 if ($this->ismultientitymanaged) {
1416 $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
1418 $sql .=
' WHERE 1 = 1';
1421 $sqlwhere = array();
1422 if (count($filter) > 0) {
1423 foreach ($filter as $key => $value) {
1424 if ($key ==
't.rowid') {
1425 $sqlwhere[] = $key.
" = ".((int) $value);
1426 } elseif (strpos($key,
'date') !==
false) {
1427 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
1428 } elseif ($key ==
'customsql') {
1429 $sqlwhere[] = $value;
1431 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
1435 if (count($sqlwhere) > 0) {
1436 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
1439 if (!empty($sortfield)) {
1440 $sql .= $this->
db->order($sortfield, $sortorder);
1442 if (!empty($limit)) {
1443 $sql .= $this->
db->plimit($limit, $offset);
1448 $num = $this->
db->num_rows(
$resql);
1450 while ($obj = $this->
db->fetch_object(
$resql)) {
1451 $record =
new self($this->db);
1452 $record->setVarsFromFetchObj($obj);
1454 $records[$record->id] = $record;
1460 $this->errors[] =
'Error '.$this->db->lasterror();
1461 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1476 if ($this->efficiency < 0 || $this->efficiency > 1) {
1477 $this->efficiency = 1;
1490 public function delete(
User $user, $notrigger =
false)
1506 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1508 global $db, $conf, $langs, $hookmanager;
1510 if (!empty($conf->dol_no_mouse_hover)) {
1516 $label =
'<u>'.$langs->trans(
"BillOfMaterialsLine").
'</u>';
1518 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1520 $url = DOL_URL_ROOT.
'/bom/bomline_card.php?id='.$this->id;
1522 if ($option !=
'nolink') {
1524 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1525 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1526 $add_save_lastsearch_values = 1;
1528 if ($add_save_lastsearch_values) {
1529 $url .=
'&save_lastsearch_values=1';
1534 if (empty($notooltip)) {
1535 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1536 $label = $langs->trans(
"ShowBillOfMaterialsLine");
1537 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1539 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1540 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1542 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1545 $linkstart =
'<a href="'.$url.
'"';
1546 $linkstart .= $linkclose.
'>';
1549 $result .= $linkstart;
1551 $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);
1553 if ($withpicto != 2) {
1554 $result .= $this->ref;
1556 $result .= $linkend;
1559 global $action, $hookmanager;
1560 $hookmanager->initHooks(array(
'bomlinedao'));
1561 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1562 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1564 $result = $hookmanager->resPrint;
1566 $result .= $hookmanager->resPrint;
1580 return $this->
LibStatut($this->status, $mode);
1605 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1606 $sql .=
' fk_user_creat, fk_user_modif';
1607 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1608 $sql .=
' WHERE t.rowid = '.((int) $id);
1609 $result = $this->
db->query($sql);
1611 if ($this->
db->num_rows($result)) {
1612 $obj = $this->
db->fetch_object($result);
1613 $this->
id = $obj->rowid;
1614 $this->user_creation_id = $obj->fk_user_creat;
1615 $this->user_modification_id = $obj->fk_user_modif;
1616 $this->date_creation = $this->
db->jdate($obj->datec);
1617 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
1619 $this->
db->free($result);