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->cost_price = 0;
|
||||||
$tmpproduct->pmp = 0;
|
$tmpproduct->pmp = 0;
|
||||||
|
|
||||||
$result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading
|
if(empty($line->fk_bom_child)){
|
||||||
if ($result < 0) {
|
$result = $tmpproduct->fetch($line->fk_product, '', '', '', 0, 1, 1); // We discard selling price and language loading
|
||||||
$this->error = $tmpproduct->error;
|
if ($result < 0) {
|
||||||
return -1;
|
$this->error = $tmpproduct->error;
|
||||||
}
|
return -1;
|
||||||
$line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
|
}
|
||||||
if (empty($line->unit_cost)) {
|
$line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
|
||||||
if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
|
if (empty($line->unit_cost)) {
|
||||||
$line->unit_cost = $productFournisseur->fourn_unitprice;
|
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');
|
$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');
|
$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>';
|
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
|
// Cost price if it's defined
|
||||||
if (!empty($obj->fk_bom_child)) {
|
if ($sub_bom_product->cost_price > 0) {
|
||||||
$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) {
|
|
||||||
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_product->cost_price * $line->qty).'</td>';
|
||||||
$total_cost+= $sub_bom_product->cost_price * $line->qty;
|
$total_cost+= $sub_bom_product->cost_price * $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 * $line->qty).'</td>';
|
||||||
$total_cost.= $sub_bom_product->pmp * $line->qty;
|
$total_cost.= $sub_bom_product->pmp * $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 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);
|
||||||
print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($obj->min_price * $line->qty).'</td>';
|
$line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty;
|
||||||
$total_cost+= $obj->min_price * $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