FIX : Fixing total errors
This commit is contained in:
parent
08d830f450
commit
36068d4279
@ -1064,26 +1064,41 @@ class BOM extends CommonObject
|
||||
$tmpproduct->cost_price = 0;
|
||||
$tmpproduct->pmp = 0;
|
||||
|
||||
$result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading
|
||||
if ($result < 0) {
|
||||
$this->error = $tmpproduct->error;
|
||||
return -1;
|
||||
}
|
||||
$line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
|
||||
if (empty($line->unit_cost)) {
|
||||
if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
|
||||
$line->unit_cost = $productFournisseur->fourn_unitprice;
|
||||
if(empty($line->fk_bom_child)){
|
||||
$result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading
|
||||
if ($result < 0) {
|
||||
$this->error = $tmpproduct->error;
|
||||
return -1;
|
||||
}
|
||||
$line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
|
||||
if (empty($line->unit_cost)) {
|
||||
if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
|
||||
$line->unit_cost = $productFournisseur->fourn_unitprice;
|
||||
}
|
||||
}
|
||||
|
||||
$line->total_cost = price2num($line->qty * $line->unit_cost, 'MT');
|
||||
|
||||
$this->total_cost += $line->total_cost;
|
||||
} else {
|
||||
$bom_child= new BOM($this->db);
|
||||
$res = $bom_child->fetch($line->fk_bom_child);
|
||||
if($res>0){
|
||||
$bom_child->calculateCosts();
|
||||
$this->total_cost += $bom_child->total_cost;
|
||||
} else {
|
||||
$this->error = $bom_child->error;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
$line->total_cost = price2num($line->qty * $line->unit_cost, 'MT');
|
||||
|
||||
$this->total_cost += $line->total_cost;
|
||||
}
|
||||
|
||||
$this->total_cost = price2num($this->total_cost, 'MT');
|
||||
if ($this->qty) {
|
||||
if ($this->qty > 0) {
|
||||
$this->unit_cost = price2num($this->total_cost / $this->qty, 'MU');
|
||||
} elseif ($this->qty < 0) {
|
||||
$this->unit_cost = price2num($this->total_cost * $this->qty, 'MU');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,27 +232,22 @@ if ($resql) {
|
||||
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($obj->fk_bom_child)) {
|
||||
$bom = new BOM($object->db);
|
||||
$bom->fetch($obj->fk_bom_child);
|
||||
$bom->calculateCosts();
|
||||
$bom->total_cost * $line->qty;
|
||||
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($bom->total_cost * $line->qty).'</td>';
|
||||
$total_cost+= $bom->total_cost * $line->qty;
|
||||
} elseif ($sub_bom_product->cost_price > 0) {
|
||||
if ($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 * $line->qty).'</td>';
|
||||
$total_cost+= $sub_bom_product->cost_price * $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.'">'.price($sub_bom_product->pmp * $line->qty).'</td>';
|
||||
$total_cost.= $sub_bom_product->pmp * $line->qty;
|
||||
} else { // Minimum purchase price if cost price and PMP aren't defined
|
||||
$sql_supplier_price = 'SELECT MIN(price) AS min_price 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;
|
||||
$resql_supplier_price = $object->db->query($sql_supplier_price);
|
||||
if ($resql_supplier_price) {
|
||||
$obj = $object->db->fetch_object($resql_supplier_price);
|
||||
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($obj->min_price * $line->qty).'</td>';
|
||||
$total_cost+= $obj->min_price * $line->qty;
|
||||
$line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty;
|
||||
|
||||
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($line_cost).'</td>';
|
||||
$total_cost+= $line_cost;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user