Ajout ligne BOM enfant dans mo_card action "create"

This commit is contained in:
atm-lena
2022-02-07 16:06:25 +01:00
parent 19fdf3dc18
commit 5c862435a8

View File

@@ -32,12 +32,30 @@ $qtytoconsumeforline = $this->tpl['qty'] / ( ! empty($this->tpl['efficiency']) ?
}*/
$qtytoconsumeforline = price2num($qtytoconsumeforline, 'MS');
$tmpproduct = new Product($this->db);
$tmpproduct->fetch($line->fk_product);
$tmpbom = new BOM($this->db);
$res = $tmpbom->fetch($line->fk_bom_child);
?>
<!-- BEGIN PHP TEMPLATE originproductline.tpl.php -->
<?php
print '<tr class="oddeven'.(empty($this->tpl['strike']) ? '' : ' strikefordisabled').'">';
print '<td>'.$this->tpl['label'].'</td>';
print '<td>';
if($res){
print $tmpproduct->getNomUrl(1);
print ' '.$langs->trans("or").' ';
print $tmpbom->getNomUrl(1);
print ' <a class="collapse_bom" id="collapse-'.$line->id.'" href="#">';
print (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? img_picto('', 'folder') : img_picto('', 'folder-open'));
print '</a>';
} else{
print $this->tpl['label'];
}
print '</td>';
//print '<td>'.$this->tpl['label'].'</td>';
print '<td class="right">'.$this->tpl['qty'].(($this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? ' / '.$form->textwithpicto($this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline : '').'</td>';
print '<td class="center">'.(empty($this->tpl['stock']) ? 0 : price2num($this->tpl['stock'], 'MS'));
if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['stock'] < $this->tpl['seuil_stock_alerte'])) {
@@ -61,5 +79,83 @@ print '<td class="center">';
//print '<input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'>';
print '</td>';
print '</tr>'."\n";
// Select of all the sub-BOM lines
$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
$sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
$resql = $this->db->query($sql);
if ($resql) {
// Loop on all the sub-BOM lines if they exist
while ($obj = $this->db->fetch_object($resql)) {
$sub_bom_product = new Product($this->db);
$sub_bom_product->fetch($obj->fk_product);
$sub_bom_product->load_stock();
$sub_bom = new BOM($this->db);
$sub_bom->fetch($obj->fk_bom_child);
$sub_bom_line = new BOMLine($this->db);
$sub_bom_line->fetch($obj->rowid);
//If hidden conf is set, we show directly all the sub-BOM lines
if (!empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
} else {
print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
}
// Product OR BOM
print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
if (!empty($obj->fk_bom_child)) {
print $sub_bom_product->getNomUrl(1);
print ' '.$langs->trans('or').' ';
print $sub_bom->getNomUrl(1);
} else {
print $sub_bom_product->getNomUrl(1);
print '</td>';
}
// Qty
if ($sub_bom_line->qty_frozen > 0) {
print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
} else {
print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).'</td>';
}
// Stock réel
if ($sub_bom_product->stock_reel > 0) {
print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">'.$sub_bom_product->stock_reel.'</td>';
} else {
print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">&nbsp;</td>';
}
// Stock virtuel
if ($sub_bom_product->stock_theorique > 0) {
print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">'.$sub_bom_product->stock_theorique.'</td>';
} else {
print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">&nbsp;</td>';
}
// Frozen qty
if ($sub_bom_line->qty_frozen > 0) {
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">'.$langs->trans('Yes').'</td>';
} else {
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">&nbsp;</td>';
}
// Disable stock change
if ($sub_bom_line->disable_stock_change > 0) {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.yn($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></td>';
print '<td></td>';
print '<td></td>';
}
}
?>
<!-- END PHP TEMPLATE originproductline.tpl.php -->