25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'bom';
42 public $table_element =
'bom_bom';
47 public $ismultientitymanaged = 1;
52 public $isextrafieldmanaged = 1;
57 public $picto =
'bom';
60 const STATUS_DRAFT = 0;
61 const STATUS_VALIDATED = 1;
62 const STATUS_CANCELED = 9;
90 public $fields = array(
91 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
92 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>5),
93 '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',),
94 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>1,
'position'=>30,
'notnull'=>1,
'searchall'=>1,
'showoncombobox'=>
'1',
'autofocusoncreate'=>1),
96 'bomtype' => array(
'type'=>
'integer',
'label'=>
'Type',
'enabled'=>1,
'visible'=>-1,
'position'=>32,
'notnull'=>1,
'default'=>
'0',
'arrayofkeyval'=>array(0=>
'Manufacturing')),
97 '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'),
98 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
99 'qty' => array(
'type'=>
'real',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'default'=>1,
'position'=>55,
'notnull'=>1,
'isameasure'=>
'1',
'css'=>
'maxwidth75imp'),
101 'duration' => array(
'type'=>
'duration',
'label'=>
'EstimatedDuration',
'enabled'=>1,
'visible'=>-1,
'position'=>101,
'notnull'=>-1,
'css'=>
'maxwidth50imp',
'help'=>
'EstimatedDurationDesc'),
102 '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'),
103 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>-2,
'position'=>161,
'notnull'=>-1,),
104 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>-2,
'position'=>162,
'notnull'=>-1,),
105 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300,
'notnull'=>1,),
106 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>501,
'notnull'=>1,),
107 'date_valid' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-2,
'position'=>502,
'notnull'=>0,),
108 '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',),
109 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'picto'=>
'user',
'enabled'=>1,
'visible'=>-2,
'position'=>511,
'notnull'=>-1,),
110 'fk_user_valid' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'picto'=>
'user',
'enabled'=>1,
'visible'=>-2,
'position'=>512,
'notnull'=>0,),
111 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
112 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
113 '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')),
144 public $date_creation;
152 public $fk_user_creat;
157 public $fk_user_modif;
183 public $table_element_line =
'bom_bomline';
188 public $fk_element =
'fk_bom';
193 public $class_element_line =
'BOMLine';
203 protected $childtablesoncascade = array(
'bom_bomline');
208 public $lines = array();
213 public $total_cost = 0;
218 public $unit_cost = 0;
229 global $conf, $langs;
233 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->
fields[
'rowid'])) $this->
fields[
'rowid'][
'visible'] = 0;
234 if (empty($conf->multicompany->enabled) && isset($this->
fields[
'entity'])) $this->
fields[
'entity'][
'enabled'] = 0;
237 foreach ($this->
fields as $key => $val)
239 if (isset($val[
'enabled']) && empty($val[
'enabled']))
241 unset($this->
fields[$key]);
246 foreach ($this->
fields as $key => $val)
248 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval']))
250 foreach ($val[
'arrayofkeyval'] as $key2 => $val2)
252 $this->
fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
267 if ($this->efficiency <= 0 || $this->efficiency > 1) $this->efficiency = 1;
281 global $langs, $hookmanager, $extrafields;
286 $object =
new self($this->db);
291 $result = $object->fetchCommon($fromid);
292 if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
300 unset($object->fk_user_creat);
301 unset($object->import_key);
304 $object->ref = empty($this->
fields[
'ref'][
'default']) ? $langs->trans(
"copy_of_").$object->ref : $this->
fields[
'ref'][
'default'];
305 $object->label = empty($this->
fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->
fields[
'label'][
'default'];
306 $object->status = self::STATUS_DRAFT;
309 if (is_array($object->array_options) && count($object->array_options) > 0)
311 $extrafields->fetch_name_optionals_label($object->table_element);
312 foreach ($object->array_options as $key => $option)
314 $shortkey = preg_replace(
'/options_/',
'', $key);
315 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey]))
318 unset($object->array_options[$key]);
324 $object->context[
'createfromclone'] =
'createfromclone';
325 $result = $object->createCommon($user);
328 $this->error = $object->error;
329 $this->errors = $object->errors;
344 if (property_exists($this,
'socid') && $this->socid == $object->socid)
355 unset($object->context[
'createfromclone']);
362 $this->
db->rollback();
374 public function fetch($id, $ref = null)
378 if ($result > 0 && !empty($this->table_element_line)) $this->
fetchLines();
391 $this->lines = array();
408 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
418 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
419 if ($this->ismultientitymanaged) $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
420 else $sql .=
' WHERE 1 = 1';
423 if (count($filter) > 0) {
424 foreach ($filter as $key => $value) {
425 if ($key ==
't.rowid') {
426 $sqlwhere[] = $key.
'='.$value;
427 } elseif (strpos($key,
'date') !==
false) {
428 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
429 } elseif ($key ==
'customsql') {
430 $sqlwhere[] = $value;
432 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
436 if (count($sqlwhere) > 0) {
437 $sql .=
' AND ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
440 if (!empty($sortfield)) {
441 $sql .= $this->
db->order($sortfield, $sortorder);
443 if (!empty($limit)) {
444 $sql .=
' '.$this->db->plimit($limit, $offset);
451 while ($obj = $this->
db->fetch_object(
$resql))
453 $record =
new self($this->db);
454 $record->setVarsFromFetchObj($obj);
456 $records[$record->id] = $record;
462 $this->errors[] =
'Error '.$this->db->lasterror();
463 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
478 if ($this->efficiency <= 0 || $this->efficiency > 1) $this->efficiency = 1;
490 public function delete(
User $user, $notrigger =
false)
506 if ($this->status < 0)
508 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
524 global $langs, $conf;
527 if (!empty($conf->global->BOM_ADDON))
531 $file = $conf->global->BOM_ADDON.
".php";
532 $classname = $conf->global->BOM_ADDON;
535 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
536 foreach ($dirmodels as $reldir)
541 $mybool |= @include_once $dir.$file;
544 if ($mybool ===
false)
550 $obj =
new $classname();
551 $numref = $obj->getNextValue($prod, $this);
557 $this->error = $obj->error;
562 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOM_ADDON_NotDefined");
576 global $conf, $langs;
578 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
583 if ($this->status == self::STATUS_VALIDATED)
585 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
602 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref)))
612 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
613 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
614 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
615 $sql .=
" date_valid='".$this->db->idate($now).
"',";
616 $sql .=
" fk_user_valid = ".$user->id;
617 $sql .=
" WHERE rowid = ".$this->id;
619 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
624 $this->error = $this->
db->lasterror();
628 if (!$error && !$notrigger)
632 if ($result < 0) $error++;
638 $this->oldref = $this->ref;
641 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;
647 if (!
$resql) { $error++; $this->error = $this->
db->lasterror(); }
652 $dirsource = $conf->bom->dir_output.
'/'.$oldref;
653 $dirdest = $conf->bom->dir_output.
'/'.$newref;
654 if (!$error && file_exists($dirsource))
656 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
658 if (@rename($dirsource, $dirdest))
662 $listoffiles =
dol_dir_list($conf->bom->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
663 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);
680 $this->status = self::STATUS_VALIDATED;
688 $this->
db->rollback();
703 if ($this->status <= self::STATUS_DRAFT)
715 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'BOM_UNVALIDATE');
725 public function cancel($user, $notrigger = 0)
728 if ($this->status != self::STATUS_VALIDATED)
740 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'BOM_CLOSE');
750 public function reopen($user, $notrigger = 0)
753 if ($this->status != self::STATUS_CANCELED)
765 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'BOM_REOPEN');
779 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
781 global $db, $conf, $langs, $hookmanager;
783 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
787 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"BillOfMaterials").
'</u>';
788 if (isset($this->status)) {
789 $label .=
' '.$this->getLibStatut(5);
792 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
794 $url =
dol_buildpath(
'/bom/bom_card.php', 1).
'?id='.$this->id;
796 if ($option !=
'nolink')
799 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
800 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
801 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
805 if (empty($notooltip))
807 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
809 $label = $langs->trans(
"ShowBillOfMaterials");
810 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
812 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
813 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
821 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
823 $linkstart =
'<a href="'.$url.
'"';
824 $linkstart .= $linkclose.
'>';
827 $result .= $linkstart;
828 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
829 if ($withpicto != 2) $result .= $this->ref;
833 global $action, $hookmanager;
834 $hookmanager->initHooks(array(
'bomdao'));
835 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
836 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
837 if ($reshook > 0) $result = $hookmanager->resPrint;
838 else $result .= $hookmanager->resPrint;
851 return $this->
LibStatut($this->status, $mode);
865 if (empty($this->labelStatus))
869 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
870 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
871 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
874 $statusType =
'status'.$status;
875 if ($status == self::STATUS_VALIDATED) $statusType =
'status4';
876 if ($status == self::STATUS_CANCELED) $statusType =
'status6';
878 return dolGetStatus($this->labelStatus[$status], $this->labelStatus[$status],
'', $statusType, $mode);
889 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
890 $sql .=
' fk_user_creat, fk_user_modif';
891 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
892 $sql .=
' WHERE t.rowid = '.$id;
893 $result = $this->
db->query($sql);
896 if ($this->
db->num_rows($result))
898 $obj = $this->
db->fetch_object($result);
899 $this->
id = $obj->rowid;
900 if ($obj->fk_user_author)
902 $cuser =
new User($this->
db);
903 $cuser->fetch($obj->fk_user_author);
904 $this->user_creation = $cuser;
907 if ($obj->fk_user_valid)
909 $vuser =
new User($this->
db);
910 $vuser->fetch($obj->fk_user_valid);
911 $this->user_validation = $vuser;
914 if ($obj->fk_user_cloture)
916 $cluser =
new User($this->
db);
917 $cluser->fetch($obj->fk_user_cloture);
918 $this->user_cloture = $cluser;
921 $this->date_creation = $this->
db->jdate($obj->datec);
922 $this->date_modification = $this->
db->jdate($obj->datem);
923 $this->date_validation = $this->
db->jdate($obj->datev);
926 $this->
db->free($result);
939 $this->lines = array();
942 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_bom = '.$this->
id));
944 if (is_numeric($result))
946 $this->error = $this->error;
947 $this->errors = $this->errors;
950 $this->lines = $result;
966 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
968 global $conf, $langs;
971 $outputlangs->load(
"products");
974 $modele =
'standard';
976 if ($this->model_pdf) {
977 $modele = $this->model_pdf;
978 } elseif (!empty($conf->global->BOM_ADDON_PDF)) {
979 $modele = $conf->global->BOM_ADDON_PDF;
983 $modelpath =
"core/modules/bom/doc/";
985 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
997 $this->ref =
'BOM-123';
998 $this->date = $this->date_creation;
1010 global $conf, $langs;
1026 $this->
db->commit();
1038 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1039 $this->unit_cost = 0;
1040 $this->total_cost = 0;
1042 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
1045 foreach ($this->lines as &$line) {
1047 $result = $tmpproduct->fetch($line->fk_product);
1049 $this->error = $tmpproduct->error;
1052 $line->unit_cost =
price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
1053 if (empty($line->unit_cost)) {
1054 if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0)
1056 $line->unit_cost = $productFournisseur->fourn_unitprice;
1060 $line->total_cost =
price2num($line->qty * $line->unit_cost,
'MT');
1061 $this->total_cost += $line->total_cost;
1064 $this->total_cost =
price2num($this->total_cost,
'MT');
1066 $this->unit_cost =
price2num($this->total_cost / $this->qty,
'MU');
1080 public $element =
'bomline';
1085 public $table_element =
'bom_bomline';
1090 public $ismultientitymanaged = 0;
1095 public $isextrafieldmanaged = 1;
1100 public $picto =
'bomline';
1126 public $fields = array(
1127 'rowid' => array(
'type'=>
'integer',
'label'=>
'LineID',
'enabled'=>1,
'visible'=>-1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
1128 'fk_bom' => array(
'type'=>
'integer:BillOfMaterials:societe/class/bom.class.php',
'label'=>
'BillOfMaterials',
'enabled'=>1,
'visible'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,),
1129 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
1130 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'notnull'=>-1,),
1131 'qty' => array(
'type'=>
'double(24,8)',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'notnull'=>1,
'isameasure'=>
'1',),
1132 'qty_frozen' => array(
'type'=>
'smallint',
'label'=>
'QuantityFrozen',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>105,
'css'=>
'maxwidth50imp',
'help'=>
'QuantityConsumedInvariable'),
1133 'disable_stock_change' => array(
'type'=>
'smallint',
'label'=>
'DisableStockChange',
'enabled'=>1,
'visible'=>1,
'default'=>0,
'position'=>108,
'css'=>
'maxwidth50imp',
'help'=>
'DisableStockChangeHelp'),
1134 'efficiency' => array(
'type'=>
'double(24,8)',
'label'=>
'ManufacturingEfficiency',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'position'=>110,
'notnull'=>1,
'css'=>
'maxwidth50imp',
'help'=>
'ValueOfEfficiencyConsumedMeans'),
1135 'position' => array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>1,
'visible'=>0,
'default'=>0,
'position'=>200,
'notnull'=>1,),
1136 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>1000,
'notnull'=>-1,),
1157 public $description;
1164 public $disable_stock_change;
1181 public $total_cost = 0;
1186 public $unit_cost = 0;
1196 global $conf, $langs;
1200 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->
fields[
'rowid'])) $this->
fields[
'rowid'][
'visible'] = 0;
1201 if (empty($conf->multicompany->enabled) && isset($this->
fields[
'entity'])) $this->
fields[
'entity'][
'enabled'] = 0;
1204 foreach ($this->
fields as $key => $val)
1206 if (isset($val[
'enabled']) && empty($val[
'enabled']))
1208 unset($this->
fields[$key]);
1213 foreach ($this->
fields as $key => $val)
1215 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval']))
1217 foreach ($val[
'arrayofkeyval'] as $key2 => $val2)
1219 $this->
fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
1234 if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1;
1264 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1274 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1275 if ($this->ismultientitymanaged) $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
1276 else $sql .=
' WHERE 1 = 1';
1278 $sqlwhere = array();
1279 if (count($filter) > 0) {
1280 foreach ($filter as $key => $value) {
1281 if ($key ==
't.rowid') {
1282 $sqlwhere[] = $key.
'='.$value;
1283 } elseif (strpos($key,
'date') !==
false) {
1284 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
1285 } elseif ($key ==
'customsql') {
1286 $sqlwhere[] = $value;
1288 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
1292 if (count($sqlwhere) > 0) {
1293 $sql .=
' AND ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
1296 if (!empty($sortfield)) {
1297 $sql .= $this->
db->order($sortfield, $sortorder);
1299 if (!empty($limit)) {
1300 $sql .=
' '.$this->db->plimit($limit, $offset);
1305 $num = $this->
db->num_rows(
$resql);
1307 while ($obj = $this->
db->fetch_object(
$resql))
1309 $record =
new self($this->db);
1310 $record->setVarsFromFetchObj($obj);
1312 $records[$record->id] = $record;
1318 $this->errors[] =
'Error '.$this->db->lasterror();
1319 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
1334 if ($this->efficiency < 0 || $this->efficiency > 1) $this->efficiency = 1;
1346 public function delete(
User $user, $notrigger =
false)
1362 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1364 global $db, $conf, $langs, $hookmanager;
1366 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
1370 $label =
'<u>'.$langs->trans(
"BillOfMaterialsLine").
'</u>';
1372 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1374 $url =
dol_buildpath(
'/bom/bomline_card.php', 1).
'?id='.$this->id;
1376 if ($option !=
'nolink')
1379 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1380 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1381 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1385 if (empty($notooltip))
1387 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1389 $label = $langs->trans(
"ShowBillOfMaterialsLine");
1390 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1392 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1393 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1401 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1403 $linkstart =
'<a href="'.$url.
'"';
1404 $linkstart .= $linkclose.
'>';
1407 $result .= $linkstart;
1408 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1409 if ($withpicto != 2) $result .= $this->ref;
1410 $result .= $linkend;
1413 global $action, $hookmanager;
1414 $hookmanager->initHooks(array(
'bomlinedao'));
1415 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
1416 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1417 if ($reshook > 0) $result = $hookmanager->resPrint;
1418 else $result .= $hookmanager->resPrint;
1431 return $this->
LibStatut($this->status, $mode);
1456 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
1457 $sql .=
' fk_user_creat, fk_user_modif';
1458 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1459 $sql .=
' WHERE t.rowid = '.$id;
1460 $result = $this->
db->query($sql);
1463 if ($this->
db->num_rows($result))
1465 $obj = $this->
db->fetch_object($result);
1466 $this->
id = $obj->rowid;
1467 if ($obj->fk_user_author)
1469 $cuser =
new User($this->
db);
1470 $cuser->fetch($obj->fk_user_author);
1471 $this->user_creation = $cuser;
1474 if ($obj->fk_user_valid)
1476 $vuser =
new User($this->
db);
1477 $vuser->fetch($obj->fk_user_valid);
1478 $this->user_validation = $vuser;
1481 if ($obj->fk_user_cloture)
1483 $cluser =
new User($this->
db);
1484 $cluser->fetch($obj->fk_user_cloture);
1485 $this->user_cloture = $cluser;
1488 $this->date_creation = $this->
db->jdate($obj->datec);
1489 $this->date_modification = $this->
db->jdate($obj->datem);
1490 $this->date_validation = $this->
db->jdate($obj->datev);
1493 $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.
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.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
createFromClone(User $user, $fromid)
Clone an object into another one.
reopen($user, $notrigger=0)
Set cancel status.
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.
$conf db
API class for accounts.
__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.
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.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
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.
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
copy_linked_contact($objFrom, $source= 'internal')
Copy contact from one element to current.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
fetch($id, $ref=null)
Load object in memory from the database.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getLinesArray()
Create an array of lines.
setStatusCommon($user, $status, $notrigger=0, $triggercode= '')
Set to a status.
getFieldList()
Function to concat keys of fields.
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.