55 $this->rights_class =
'bom';
59 $this->family =
"products";
61 $this->module_position =
'65';
66 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
68 $this->
description =
"Module to define your Bills Of Materials (BOM). Can be used for Manufacturing Resource Planning by the module Manufacturing Orders (MO)";
70 $this->descriptionlong =
"Bill of Materials definitions. They can be used to make Manufacturing Resource Planning";
73 $this->version =
'dolibarr';
78 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
85 $this->module_parts = array(
104 $this->dirs = array(
"/bom/temp");
107 $this->config_page_url = array(
"bom.php");
110 $this->hidden =
false;
112 $this->depends = array(
'modProduct');
113 $this->requiredby = array(
'modMrp');
114 $this->conflictwith = array();
115 $this->langfiles = array(
"mrp");
117 $this->need_dolibarr_version = array(9, 0);
118 $this->warnings_activation = array();
119 $this->warnings_activation_ext = array();
128 $this->
const = array(
129 1 => array(
'BOM_ADDON_PDF',
'chaine',
'generic_bom_odt',
'Name of PDF model of BOM', 0),
130 2 => array(
'BOM_ADDON',
'chaine',
'mod_bom_standard',
'Name of numbering rules of BOM', 0),
131 3 => array(
'BOM_ADDON_PDF_ODT_PATH',
'chaine',
'DOL_DATA_ROOT/doctemplates/boms',
'', 0)
140 if (!isset($conf->bom) || !isset($conf->bom->enabled)) {
142 $conf->bom->enabled = 0;
147 $this->tabs = array();
176 $this->dictionaries = array();
181 $this->boxes = array(
182 0 => array(
'file' =>
'box_boms.php',
'note' =>
'',
'enabledbydefaulton' =>
'Home')
188 $this->cronjobs = array(
197 $this->rights = array();
200 $this->rights[$r][0] = $this->numero + $r;
201 $this->rights[$r][1] =
'Read bom of Bom';
202 $this->rights[$r][3] = 0;
203 $this->rights[$r][4] =
'read';
204 $this->rights[$r][5] =
'';
207 $this->rights[$r][0] = $this->numero + $r;
208 $this->rights[$r][1] =
'Create/Update bom of Bom';
209 $this->rights[$r][3] = 0;
210 $this->rights[$r][4] =
'write';
211 $this->rights[$r][5] =
'';
214 $this->rights[$r][0] = $this->numero + $r;
215 $this->rights[$r][1] =
'Delete bom of Bom';
216 $this->rights[$r][3] = 0;
217 $this->rights[$r][4] =
'delete';
218 $this->rights[$r][5] =
'';
222 $this->menu = array();
278 $this->export_code[$r] = $this->rights_class.
'_'.$r;
279 $this->export_label[$r] =
'BomAndBomLines';
280 $this->export_permission[$r] = array(array(
"bom",
"read"));
281 $this->export_icon[$r] =
'bom';
282 $keyforclass =
'BOM';
283 $keyforclassfile =
'/bom/class/bom.class.php';
284 $keyforelement =
'bom';
285 include DOL_DOCUMENT_ROOT.
'/core/commonfieldsinexport.inc.php';
286 $keyforclass =
'BOMLine';
287 $keyforclassfile =
'/bom/class/bom.class.php';
288 $keyforelement =
'bomline';
290 include DOL_DOCUMENT_ROOT.
'/core/commonfieldsinexport.inc.php';
291 unset($this->export_fields_array[$r][
'tl.fk_bom']);
292 $keyforselect =
'bom_bom';
293 $keyforaliasextra =
'extra';
294 $keyforelement =
'bom';
295 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
296 $keyforselect =
'bom_bomline';
297 $keyforaliasextra =
'extraline';
298 $keyforelement =
'bomline';
299 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
300 $this->export_dependencies_array[$r] = array(
'bomline' =>
'tl.rowid');
301 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
302 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'bom_bom as t';
303 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bom_bom_extrafields as extra on (t.rowid = extra.fk_object)';
304 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bom_bomline as tl ON tl.fk_bom = t.rowid';
305 $this->export_sql_end[$r] .=
' WHERE 1 = 1';
306 $this->export_sql_end[$r] .=
' AND t.entity IN ('.getEntity(
'bom').
')';
316 $this->import_code[$r] =
'bom_'.$r;
317 $this->import_label[$r] =
'BillOfMaterials';
318 $this->import_icon[$r] = $this->picto;
319 $this->import_entities_array[$r] = array();
320 $this->import_tables_array[$r] = array(
'b' => MAIN_DB_PREFIX.
'bom_bom',
'extra' => MAIN_DB_PREFIX.
'bom_bom_extrafields');
321 $this->import_tables_creator_array[$r] = array(
'b' =>
'fk_user_creat');
322 $this->import_fields_array[$r] = array(
324 'b.label' =>
'Label*',
325 'b.fk_product' =>
'ProductRef*',
326 'b.description' =>
'Description',
327 'b.note_public' =>
'Note',
328 'b.note_private' =>
'NotePrivate',
329 'b.fk_warehouse' =>
'WarehouseRef',
331 'b.efficiency' =>
'Efficiency',
332 'b.duration' =>
'Duration',
333 'b.date_creation' =>
'DateCreation',
334 'b.date_valid' =>
'DateValidation',
335 'b.fk_user_modif' =>
'ModifiedById',
336 'b.fk_user_valid' =>
'ValidatedById',
337 'b.model_pdf' =>
'Model',
338 'b.status' =>
'Status*',
339 'b.bomtype' =>
'Type*'
341 $import_sample = array();
344 $import_extrafield_sample = array();
345 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'bom_bom' AND entity IN (0, ".$conf->entity.
")";
346 $resql = $this->db->query($sql);
349 while ($obj = $this->db->fetch_object($resql)) {
350 $fieldname =
'extra.'.$obj->name;
351 $fieldlabel = ucfirst($obj->label);
352 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
353 $import_extrafield_sample[$fieldname] = $fieldlabel;
358 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
359 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'bom_bom');
360 $this->import_regex_array[$r] = array(
364 $this->import_updatekeys_array[$r] = array(
'b.ref' =>
'Ref');
365 $this->import_convertvalue_array[$r] = array(
366 'b.fk_product' => array(
367 'rule' =>
'fetchidfromref',
368 'file' =>
'/product/class/product.class.php',
369 'class' =>
'Product',
371 'element' =>
'Product'
373 'b.fk_warehouse' => array(
374 'rule' =>
'fetchidfromref',
375 'file' =>
'/product/stock/class/entrepot.class.php',
376 'class' =>
'Entrepot',
378 'element' =>
'Warehouse'
380 'b.fk_user_valid' => array(
381 'rule' =>
'fetchidfromref',
382 'file' =>
'/user/class/user.class.php',
387 'b.fk_user_modif' => array(
388 'rule' =>
'fetchidfromref',
389 'file' =>
'/user/class/user.class.php',
398 $this->import_code[$r] =
'bom_lines_'.$r;
399 $this->import_label[$r] =
'BillOfMaterialsLines';
400 $this->import_icon[$r] = $this->picto;
401 $this->import_entities_array[$r] = array();
402 $this->import_tables_array[$r] = array(
'bd' => MAIN_DB_PREFIX.
'bom_bomline',
'extra' => MAIN_DB_PREFIX.
'bom_bomline_extrafields');
403 $this->import_fields_array[$r] = array(
404 'bd.fk_bom' =>
'BOM*',
405 'bd.fk_product' =>
'ProductRef',
406 'bd.fk_bom_child' =>
'BOMChild',
407 'bd.description' =>
'Description',
408 'bd.qty' =>
'LineQty',
409 'bd.qty_frozen' =>
'LineIsFrozen',
410 'bd.disable_stock_change' =>
'Disable Stock Change',
411 'bd.efficiency' =>
'Efficiency',
412 'bd.position' =>
'LinePosition'
416 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'bom_bomline' AND entity IN (0, ".$conf->entity.
")";
417 $resql = $this->db->query($sql);
419 while ($obj = $this->db->fetch_object($resql)) {
420 $fieldname =
'extra.'.$obj->name;
421 $fieldlabel = ucfirst($obj->label);
422 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
427 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'bom_bomline');
428 $this->import_regex_array[$r] = array();
429 $this->import_updatekeys_array[$r] = array(
'bd.fk_bom' =>
'BOM Id',
'bd.fk_product' =>
'ProductRef');
430 $this->import_convertvalue_array[$r] = array(
431 'bd.fk_bom' => array(
432 'rule' =>
'fetchidfromref',
433 'file' =>
'/bom/class/bom.class.php',
438 'bd.fk_product' => array(
439 'rule' =>
'fetchidfromref',
440 'file' =>
'/product/class/product.class.php',
441 'class' =>
'Product',
443 'element' =>
'Product'