BOM : calculate total cost of lines

This commit is contained in:
atm-lena 2022-12-09 17:00:11 +01:00
parent 5573b88df8
commit 7c352c9cef
2 changed files with 6 additions and 5 deletions

View File

@ -1073,7 +1073,8 @@ class BOM extends CommonObject
if ($res>0) {
$bom_child->calculateCosts();
$line->childBom[] = $bom_child;
$this->total_cost += $bom_child->total_cost * $line->qty;
$line->total_cost = price2num( $bom_child->total_cost * $line->qty, 'MT');
$this->total_cost += $line->total_cost;
} else {
$this->error = $bom_child->error;
return -2;

View File

@ -239,13 +239,13 @@ if ($resql) {
// Cost
if (!empty($sub_bom->id)) {
$sub_bom->calculateCosts();
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($sub_bom->total_cost * $sub_bom_line->qty * $line->qty).'</span></td>';
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($sub_bom->total_cost * $sub_bom_line->qty * $line->qty, 'MT').'</span></td>';
$total_cost+= $sub_bom->total_cost * $sub_bom_line->qty * $line->qty;
} elseif ($sub_bom_product->cost_price > 0) {
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty).'</span></td>';
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty, 'MT').'</span></td>';
$total_cost+= $sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty;
} elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty).'</span></td>';
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty, 'MT').'</span></td>';
$total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty;
} else { // Minimum purchase price if cost price and PMP aren't defined
$sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
@ -255,7 +255,7 @@ if ($resql) {
$obj = $object->db->fetch_object($resql_supplier_price);
$line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty;
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price($line_cost).'</span></td>';
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($line_cost, 'MT').'</span></td>';
$total_cost+= $line_cost;
}
}