commit
89cbaa3391
@ -523,6 +523,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
$keyforbreak = 'duration';
|
$keyforbreak = 'duration';
|
||||||
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
|
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
|
||||||
|
|
||||||
|
print '<tr><td>'.$langs->trans("TotalCost").'</td><td>'.price($object->total_cost).'</td></tr>';
|
||||||
|
print '<tr><td>'.$langs->trans("UnitCost").'</td><td>'.price($object->unit_cost).'</td></tr>';
|
||||||
|
|
||||||
// Other attributes
|
// Other attributes
|
||||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
|
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))
|
if (!empty($object->table_element_line))
|
||||||
{
|
{
|
||||||
// Show object lines
|
|
||||||
$result = $object->getLinesArray();
|
|
||||||
|
|
||||||
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
|
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
|
||||||
<input type="hidden" name="token" value="' . newToken().'">
|
<input type="hidden" name="token" value="' . newToken().'">
|
||||||
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
|
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
|
||||||
|
|||||||
@ -166,6 +166,16 @@ class BOM extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $lines = array();
|
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);
|
$result = $this->fetchCommon($id, $ref);
|
||||||
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
|
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
|
||||||
|
$this->calculateCosts();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -991,6 +1002,29 @@ class BOM extends CommonObject
|
|||||||
|
|
||||||
return $error;
|
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;
|
public $import_key;
|
||||||
// END MODULEBUILDER PROPERTIES
|
// 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
|
* Constructor
|
||||||
|
|||||||
@ -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 '<input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="'.(GETPOSTISSET("efficiency")?GETPOST("efficiency", 'alpha'):1).'">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
$coldisplay++;
|
||||||
|
print '<td class="bordertop nobottom nowrap linecolcost right">';
|
||||||
|
print ' ';
|
||||||
|
print '</td>';
|
||||||
|
|
||||||
$coldisplay += $colspan;
|
$coldisplay += $colspan;
|
||||||
print '<td class="bordertop nobottom linecoledit center valignmiddle" colspan="'.$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">';
|
print '<input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline" id="addline">';
|
||||||
|
|||||||
@ -60,13 +60,16 @@ if ($conf->global->PRODUCT_USE_UNITS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Qty frozen
|
// 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
|
// 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
|
// 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
|
print '<td class="linecoledit"></td>'; // No width to allow autodim
|
||||||
|
|
||||||
|
|||||||
@ -103,6 +103,11 @@ $coldisplay++;
|
|||||||
echo $line->efficiency;
|
echo $line->efficiency;
|
||||||
print '</td>';
|
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' ) {
|
if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) {
|
||||||
print '<td class="linecoledit center">';
|
print '<td class="linecoledit center">';
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
|
|||||||
@ -70,4 +70,6 @@ ProductQtyToConsumeByMO=Product quantity still to consume by open MO
|
|||||||
ProductQtyToProduceByMO=Product quentity still to produce by open MO
|
ProductQtyToProduceByMO=Product quentity still to produce by open MO
|
||||||
AddNewConsumeLines=Add new line to consume
|
AddNewConsumeLines=Add new line to consume
|
||||||
ProductsToConsume=Products to consume
|
ProductsToConsume=Products to consume
|
||||||
ProductsToProduce=Products to produce
|
ProductsToProduce=Products to produce
|
||||||
|
UnitCost=Unit cost
|
||||||
|
TotalCost=Total cost
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user