NEW : Add sub-BOM lines on BOM card

This commit is contained in:
Adrien Raze 2021-08-20 13:37:28 +02:00
parent f4d4733b15
commit 6de7d9b0af
3 changed files with 71 additions and 2 deletions

View File

@ -140,6 +140,7 @@ if (empty($reshook)) {
// Set if we used free entry or predefined product
$idprod = (int) GETPOST('idprod', 'int');
$bom_child = (int) GETPOST('bom_select', 'int');
$qty = price2num(GETPOST('qty', 'alpha'), 'MS');
$qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
$disable_stock_change = GETPOST('disable_stock_change', 'int');
@ -163,6 +164,7 @@ if (empty($reshook)) {
$bomline = new BOMLine($db);
$bomline->fk_bom = $id;
$bomline->fk_product = $idprod;
$bomline->fk_bom_child = $bom_child;
$bomline->qty = $qty;
$bomline->qty_frozen = (int) $qty_frozen;
$bomline->disable_stock_change = (int) $disable_stock_change;
@ -574,18 +576,25 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
<script>
let select_product_val;
let current_bom_id = <?php echo $object->id?>;
//On change on the bom select
$('#idprod').on('change', function () {
select_product_val = $('#idprod').select2().val();
//Ajax to set all options without reloading the page
$.ajax({
url: 'script/interface.php'
, method: 'POST'
, dataType: 'text'
, data: {
action: 'select_BOM'
, select_product_val: ""+select_product_val
, select_product_val: select_product_val
, current_bom_id: current_bom_id
}
}).done(function (data) {
//To remove all options of the bom select on change
$('#bom_select').get(0).length = 0;
//To set options for the bom select on change
let options = JSON.parse(data)
for (let key in options) {
let opt = new Option(options[key], key);

View File

@ -1132,6 +1132,7 @@ class BOMLine extends CommonObjectLine
'rowid' => array('type'=>'integer', 'label'=>'LineID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
'fk_bom' => array('type'=>'integer:BillOfMaterials:societe/class/bom.class.php', 'label'=>'BillOfMaterials', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1,),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
'fk_bom_child' => array('type'=>'integer:BOM:bom/class/bom.class.php', 'label'=>'BillOfMaterials', 'enabled'=>1, 'visible'=>-1, 'position'=>40, 'notnull'=>-1,),
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'notnull'=>-1,),
'qty' => array('type'=>'double(24,8)', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'position'=>100, 'notnull'=>1, 'isameasure'=>'1',),
'qty_frozen' => array('type'=>'smallint', 'label'=>'QuantityFrozen', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>105, 'css'=>'maxwidth50imp', 'help'=>'QuantityConsumedInvariable'),
@ -1156,6 +1157,11 @@ class BOMLine extends CommonObjectLine
*/
public $fk_product;
/**
* @var int Id of parent bom
*/
public $fk_bom_child;
/**
* @var string description
*/

View File

@ -80,11 +80,21 @@ print '<div id="line_'.$line->id.'"></div>';
$coldisplay++;
$tmpproduct = new Product($object->db);
$tmpproduct->fetch($line->fk_product);
$tmpbom = new BOM($object->db);
$res = $tmpbom->fetch($line->fk_bom_child);
if (!empty($tmpbom->id)){
print '<a class="collapse_bom" id="bom' . $tmpbom->id . '" href="#">' . (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? '(+)' : '(-)') . '&nbsp;</a>';
}
print $tmpproduct->getNomUrl(1);
print ' - '.$tmpproduct->label;
print '</td>';
print '<td id="bom_id"></td>';
if ($res > 0) {
print '<td id="bom_id">'.$tmpbom->getNomUrl(1).'</td>';
} else {
print '<td id="bom_id">&nbsp;</td>';
}
print '<td class="linecolqty nowrap right">';
$coldisplay++;
echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
@ -168,6 +178,50 @@ if ($action == 'selectlines') {
print '</tr>';
$sql = 'SELECT rowid, fk_bom_child, fk_product FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
$sql.= ' WHERE fk_bom = '.$tmpbom->id;
$resql = $object->db->query($sql);
if ($resql){
while ($obj = $object->db->fetch_object($resql)){
$sub_bom_product = new Product($object->db);
$sub_bom_product->fetch($obj->fk_product);
$sub_bom = new BOM($object->db);
$sub_bom->fetch($obj->fk_bom_child);
$sub_bom_line = new BOMLine($object->db);
$sub_bom_line->fetch($obj->rowid);
print '<tr id="sub_bom_'.$sub_bom_line->id.'">';
print '<td id="sub_bom_product_'.$sub_bom_line->id.'">'.$sub_bom_product->getNomUrl(1).'</td>';
if ($sub_bom_line->fk_bom_child > 0) {
print '<td id="sub_bom_bom_'.$sub_bom_line->id.'">'.$sub_bom->getNomUrl(1).'</td>';
} else {
print '<td id="sub_bom_bom_'.$sub_bom_line->id.'">&nbsp;</td>';
}
print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
if ($sub_bom_line->qty_frozen > 0) {
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$sub_bom_line->qty_frozen.'</td>';
} else {
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
}
if ($sub_bom_line->disable_stock_change > 0) {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
} else {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
}
print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($sub_bom_line->total_cost).'</td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
}
}
//Line extrafield
if (!empty($extrafields)) {
print $line->showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"', 'colspan'=>$coldisplay), '', '', 1, 'line');