Start working on bom cost

This commit is contained in:
Maxime Kohlhaas 2020-03-24 10:32:31 +01:00
parent b0f3fba71a
commit bcbccf0c83
5 changed files with 33 additions and 3 deletions

View File

@ -68,6 +68,7 @@ if (empty($action) && empty($id) && empty($ref)) $action = 'view';
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
$object->calculateCosts();
// Security check - Protection if external user
//if ($user->socid > 0) accessforbidden();
@ -523,6 +524,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$keyforbreak = 'duration';
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
print '<td>Coût total</td><td>'.price($object->total_cost).'</td>';
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

View File

@ -912,6 +912,7 @@ class BOM extends CommonObject
else
{
$this->lines = $result;
$this->calculateCosts();
return $this->lines;
}
}
@ -991,6 +992,19 @@ class BOM extends CommonObject
return $error;
}
public function calculateCosts() {
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
$this->total_cost = 0;
foreach ($this->lines as &$line) {
$tmpproduct = new Product($this->db);
$tmpproduct->fetch($line->fk_product);
$line->unit_cost = $tmpproduct->cost_price; // TODO : add option to work with cost_price or pmp
$line->total_cost = price2num($line->qty * $line->unit_cost);
$this->total_cost += $line->total_cost;
}
}
}

View File

@ -133,6 +133,11 @@ print '<td class="bordertop nobottom nowrap linecollost right">';
print '<input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="'.(GETPOSTISSET("efficiency")?GETPOST("efficiency", 'alpha'):1).'">';
print '</td>';
$coldisplay++;
print '<td class="bordertop nobottom nowrap linecolcost right">';
print '&nbsp;';
print '</td>';
$coldisplay += $colspan;
print '<td class="bordertop nobottom linecoledit center valignmiddle" colspan="'.$colspan.'">';
print '<input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline" id="addline">';

View File

@ -60,13 +60,16 @@ if ($conf->global->PRODUCT_USE_UNITS)
}
// Qty frozen
print '<td class="linecolqty right">'.$form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")).'</td>';
print '<td class="linecolqtyfrozen right">'.$form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")).'</td>';
// Disable stock change
print '<td class="linecolqty right">'.$form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')).'</td>';
print '<td class="linecoldisablestockchange right">'.$form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')).'</td>';
// Efficiency
print '<td class="linecollost right">'.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')).'</td>';
print '<td class="linecolefficiency right">'.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')).'</td>';
// Cost
print '<td class="linecolcost right">'.$langs->trans('CostPrice').'</td>';
print '<td class="linecoledit"></td>'; // No width to allow autodim

View File

@ -103,6 +103,11 @@ $coldisplay++;
echo $line->efficiency;
print '</td>';
print '<td class="linecolcost nowrap right">';
$coldisplay++;
echo price($line->total_cost);
print '</td>';
if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) {
print '<td class="linecoledit center">';
$coldisplay++;