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