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'.(
$conf->entity > 1 ?
'/'.$conf->entity :
'').
'/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] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bom_bomline_extrafields as extraline ON tl.rowid = extraline.fk_object';
306 $this->export_sql_end[$r] .=
' WHERE 1 = 1';
307 $this->export_sql_end[$r] .=
' AND t.entity IN ('.getEntity(
'bom').
')';
317 $this->import_code[$r] =
'bom_'.$r;
318 $this->import_label[$r] =
'BillOfMaterials';
319 $this->import_icon[$r] = $this->picto;
320 $this->import_entities_array[$r] = array();
321 $this->import_tables_array[$r] = array(
'b' => MAIN_DB_PREFIX.
'bom_bom',
'extra' => MAIN_DB_PREFIX.
'bom_bom_extrafields');
322 $this->import_tables_creator_array[$r] = array(
'b' =>
'fk_user_creat');
323 $this->import_fields_array[$r] = array(
325 'b.label' =>
'Label*',
326 'b.fk_product' =>
'ProductRef*',
327 'b.description' =>
'Description',
328 'b.note_public' =>
'Note',
329 'b.note_private' =>
'NotePrivate',
330 'b.fk_warehouse' =>
'WarehouseRef',
332 'b.efficiency' =>
'Efficiency',
333 'b.duration' =>
'Duration',
334 'b.date_creation' =>
'DateCreation',
335 'b.date_valid' =>
'DateValidation',
336 'b.fk_user_modif' =>
'ModifiedById',
337 'b.fk_user_valid' =>
'ValidatedById',
338 'b.model_pdf' =>
'Model',
339 'b.status' =>
'Status*',
340 'b.bomtype' =>
'Type*'
342 $import_sample = array();
345 $import_extrafield_sample = array();
346 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'bom_bom' AND entity IN (0, ".
$conf->entity.
")";
347 $resql = $this->db->query($sql);
350 while ($obj = $this->db->fetch_object($resql)) {
351 $fieldname =
'extra.'.$obj->name;
352 $fieldlabel = ucfirst($obj->label);
353 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
354 $import_extrafield_sample[$fieldname] = $fieldlabel;
359 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
360 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'bom_bom');
361 $this->import_regex_array[$r] = array(
365 $this->import_updatekeys_array[$r] = array(
'b.ref' =>
'Ref');
366 $this->import_convertvalue_array[$r] = array(
367 'b.fk_product' => array(
368 'rule' =>
'fetchidfromref',
369 'file' =>
'/product/class/product.class.php',
370 'class' =>
'Product',
372 'element' =>
'Product'
374 'b.fk_warehouse' => array(
375 'rule' =>
'fetchidfromref',
376 'file' =>
'/product/stock/class/entrepot.class.php',
377 'class' =>
'Entrepot',
379 'element' =>
'Warehouse'
381 'b.fk_user_valid' => array(
382 'rule' =>
'fetchidfromref',
383 'file' =>
'/user/class/user.class.php',
388 'b.fk_user_modif' => array(
389 'rule' =>
'fetchidfromref',
390 'file' =>
'/user/class/user.class.php',
399 $this->import_code[$r] =
'bom_lines_'.$r;
400 $this->import_label[$r] =
'BillOfMaterialsLines';
401 $this->import_icon[$r] = $this->picto;
402 $this->import_entities_array[$r] = array();
403 $this->import_tables_array[$r] = array(
'bd' => MAIN_DB_PREFIX.
'bom_bomline',
'extra' => MAIN_DB_PREFIX.
'bom_bomline_extrafields');
404 $this->import_fields_array[$r] = array(
405 'bd.fk_bom' =>
'BOM*',
406 'bd.fk_product' =>
'ProductRef',
407 'bd.fk_bom_child' =>
'BOMChild',
408 'bd.description' =>
'Description',
409 'bd.qty' =>
'LineQty',
410 'bd.qty_frozen' =>
'LineIsFrozen',
411 'bd.disable_stock_change' =>
'Disable Stock Change',
412 'bd.efficiency' =>
'Efficiency',
413 'bd.position' =>
'LinePosition'
417 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'bom_bomline' AND entity IN (0, ".
$conf->entity.
")";
418 $resql = $this->db->query($sql);
420 while ($obj = $this->db->fetch_object($resql)) {
421 $fieldname =
'extra.'.$obj->name;
422 $fieldlabel = ucfirst($obj->label);
423 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
428 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'bom_bomline');
429 $this->import_regex_array[$r] = array();
430 $this->import_updatekeys_array[$r] = array(
'bd.fk_bom' =>
'BOM Id',
'bd.fk_product' =>
'ProductRef');
431 $this->import_convertvalue_array[$r] = array(
432 'bd.fk_bom' => array(
433 'rule' =>
'fetchidfromref',
434 'file' =>
'/bom/class/bom.class.php',
439 'bd.fk_product' => array(
440 'rule' =>
'fetchidfromref',
441 'file' =>
'/product/class/product.class.php',
442 'class' =>
'Product',
444 'element' =>
'Product'