FIX : Fixed sub bom costs problems
This commit is contained in:
parent
3305965c85
commit
34d2e0b8b4
@ -518,7 +518,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
// Common attributes
|
// Common attributes
|
||||||
$keyforbreak = 'duration';
|
$keyforbreak = 'duration';
|
||||||
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
|
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
|
||||||
|
$object->calculateCosts();
|
||||||
print '<tr><td>'.$form->textwithpicto($langs->trans("TotalCost"), $langs->trans("BOMTotalCost")).'</td><td>'.price($object->total_cost).'</td></tr>';
|
print '<tr><td>'.$form->textwithpicto($langs->trans("TotalCost"), $langs->trans("BOMTotalCost")).'</td><td>'.price($object->total_cost).'</td></tr>';
|
||||||
print '<tr><td>'.$langs->trans("UnitCost").'</td><td>'.price($object->unit_cost).'</td></tr>';
|
print '<tr><td>'.$langs->trans("UnitCost").'</td><td>'.price($object->unit_cost).'</td></tr>';
|
||||||
|
|
||||||
|
|||||||
@ -1085,7 +1085,7 @@ class BOM extends CommonObject
|
|||||||
$res = $bom_child->fetch($line->fk_bom_child);
|
$res = $bom_child->fetch($line->fk_bom_child);
|
||||||
if ($res>0) {
|
if ($res>0) {
|
||||||
$bom_child->calculateCosts();
|
$bom_child->calculateCosts();
|
||||||
$this->total_cost += $bom_child->total_cost;
|
$this->total_cost += $bom_child->total_cost * $line->qty;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $bom_child->error;
|
$this->error = $bom_child->error;
|
||||||
return -2;
|
return -2;
|
||||||
|
|||||||
@ -180,6 +180,7 @@ if ($action == 'selectlines') {
|
|||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
// Select of all the sub-BOM lines
|
// Select of all the sub-BOM lines
|
||||||
|
// From this pont to the end of the file, we only take care of sub-BOM lines
|
||||||
$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
|
$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
|
||||||
$sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
|
$sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
|
||||||
$resql = $object->db->query($sql);
|
$resql = $object->db->query($sql);
|
||||||
@ -191,7 +192,9 @@ if ($resql) {
|
|||||||
$sub_bom_product->fetch($obj->fk_product);
|
$sub_bom_product->fetch($obj->fk_product);
|
||||||
|
|
||||||
$sub_bom = new BOM($object->db);
|
$sub_bom = new BOM($object->db);
|
||||||
$sub_bom->fetch($obj->fk_bom_child);
|
if(!empty($obj->fk_bom_child)){
|
||||||
|
$sub_bom->fetch($obj->fk_bom_child);
|
||||||
|
}
|
||||||
|
|
||||||
$sub_bom_line = new BOMLine($object->db);
|
$sub_bom_line = new BOMLine($object->db);
|
||||||
$sub_bom_line->fetch($obj->rowid);
|
$sub_bom_line->fetch($obj->rowid);
|
||||||
@ -233,20 +236,23 @@ if ($resql) {
|
|||||||
// Efficiency
|
// Efficiency
|
||||||
print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
|
print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
|
||||||
|
|
||||||
// Cost price if it's defined
|
if(!empty($sub_bom->id)){
|
||||||
if ($sub_bom_product->cost_price > 0) {
|
$sub_bom->calculateCosts();
|
||||||
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($sub_bom_product->cost_price * $line->qty).'</td>';
|
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($sub_bom->total_cost * $sub_bom_line->qty * $line->qty).'</td>';
|
||||||
$total_cost+= $sub_bom_product->cost_price * $line->qty;
|
$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.'">'.price($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty).'</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
|
} 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.'">'.price($sub_bom_product->pmp * $line->qty).'</td>';
|
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty).'</td>';
|
||||||
$total_cost.= $sub_bom_product->pmp * $line->qty;
|
$total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty;
|
||||||
} else { // Minimum purchase price if cost price and PMP aren't defined
|
} 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';
|
$sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
|
||||||
$sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id;
|
$sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id;
|
||||||
$resql_supplier_price = $object->db->query($sql_supplier_price);
|
$resql_supplier_price = $object->db->query($sql_supplier_price);
|
||||||
if ($resql_supplier_price) {
|
if ($resql_supplier_price) {
|
||||||
$obj = $object->db->fetch_object($resql_supplier_price);
|
$obj = $object->db->fetch_object($resql_supplier_price);
|
||||||
$line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty;
|
$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.'">'.price($line_cost).'</td>';
|
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($line_cost).'</td>';
|
||||||
$total_cost+= $line_cost;
|
$total_cost+= $line_cost;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user