diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index aedef905b7b..887a319aefe 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -523,6 +523,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $keyforbreak = 'duration'; include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; + print ''.$langs->trans("TotalCost").''.price($object->total_cost).''; + print ''.$langs->trans("UnitCost").''.price($object->unit_cost).''; + // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; @@ -542,9 +545,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (!empty($object->table_element_line)) { - // Show object lines - $result = $object->getLinesArray(); - print '
diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index b53e2a7bc88..c2779429ebc 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -166,6 +166,16 @@ class BOM extends CommonObject */ public $lines = array(); + /** + * @var int Calculated cost for the BOM + */ + public $total_cost = 0; + + /** + * @var int Calculated cost for 1 unit of the product in BOM + */ + public $unit_cost = 0; + /** @@ -324,6 +334,7 @@ class BOM extends CommonObject { $result = $this->fetchCommon($id, $ref); if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines(); + $this->calculateCosts(); return $result; } @@ -991,6 +1002,29 @@ class BOM extends CommonObject return $error; } + + /** + * BOM costs calculation based on cost_price or pmp of each BOM line + * @return void + */ + public function calculateCosts() + { + include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; + $this->unit_cost = 0; + $this->total_cost = 0; + + foreach ($this->lines as &$line) { + $tmpproduct = new Product($this->db); + $tmpproduct->fetch($line->fk_product); + + $line->unit_cost = (!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp; // TODO : add option to work with cost_price or pmp + $line->total_cost = price2num($line->qty * $line->unit_cost, 'MT'); + $this->total_cost += $line->total_cost; + } + + $this->total_cost = price2num($this->total_cost, 'MT'); + $this->unit_cost = price2num($this->total_cost / $this->qty, 'MU'); + } } @@ -1072,6 +1106,16 @@ class BOMLine extends CommonObjectLine public $import_key; // END MODULEBUILDER PROPERTIES + /** + * @var int Calculated cost for the BOM line + */ + public $total_cost = 0; + + /** + * @var int Line unit cost based on product cost price or pmp + */ + public $unit_cost = 0; + /** * Constructor diff --git a/htdocs/bom/tpl/objectline_create.tpl.php b/htdocs/bom/tpl/objectline_create.tpl.php index 445466a27a1..66bcf0cece5 100644 --- a/htdocs/bom/tpl/objectline_create.tpl.php +++ b/htdocs/bom/tpl/objectline_create.tpl.php @@ -133,6 +133,11 @@ print ''; print ''; print ''; +$coldisplay++; +print ''; +print ' '; +print ''; + $coldisplay += $colspan; print ''; print ''; diff --git a/htdocs/bom/tpl/objectline_title.tpl.php b/htdocs/bom/tpl/objectline_title.tpl.php index 138a0b9aa58..ce440dbaab6 100644 --- a/htdocs/bom/tpl/objectline_title.tpl.php +++ b/htdocs/bom/tpl/objectline_title.tpl.php @@ -60,13 +60,16 @@ if ($conf->global->PRODUCT_USE_UNITS) } // Qty frozen -print ''.$form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")).''; +print ''.$form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")).''; // Disable stock change -print ''.$form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')).''; +print ''.$form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')).''; // Efficiency -print ''.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')).''; +print ''.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')).''; + +// Cost +print ''.$langs->trans('CostPrice').''; print ''; // No width to allow autodim diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 16aa5382f53..ad2c2d3e4c6 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -103,6 +103,11 @@ $coldisplay++; echo $line->efficiency; print ''; +print ''; +$coldisplay++; +echo price($line->total_cost); +print ''; + if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) { print ''; $coldisplay++; diff --git a/htdocs/langs/en_US/mrp.lang b/htdocs/langs/en_US/mrp.lang index 41be1d993b8..4e653e04409 100644 --- a/htdocs/langs/en_US/mrp.lang +++ b/htdocs/langs/en_US/mrp.lang @@ -70,4 +70,6 @@ ProductQtyToConsumeByMO=Product quantity still to consume by open MO ProductQtyToProduceByMO=Product quentity still to produce by open MO AddNewConsumeLines=Add new line to consume ProductsToConsume=Products to consume -ProductsToProduce=Products to produce \ No newline at end of file +ProductsToProduce=Products to produce +UnitCost=Unit cost +TotalCost=Total cost