From 87931e981eb0cbdda7277d687250ae6f6464272b Mon Sep 17 00:00:00 2001 From: data Date: Tue, 3 Mar 2026 08:57:46 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20Totalpreis=20statt=20St=C3=BCckpreis=20f?= =?UTF-8?q?=C3=BCr=20Mindestmengen=20laden=20(v4.3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Code lud unitprice (0,08€) statt price (0,94€) - Berechnete dann 0,08€ × 12 = 0,96€ statt direkt 0,94€ - Führte zu Rundungsfehlern Lösung - RICHTIGE Daten aus DB: - price: Totalpreis für Mindestmenge (0,94€) - quantity: Mindestmenge (12) - unitprice: Wird berechnet, nicht direkt verwendet Beispiel Lüsterklemme: - Vorher: unitprice=0,08€ × 12 = 0,96€ (Rundungsfehler!) - Nachher: price=0,94€ für 12 (korrekt!) MERKEN: IMMER price + quantity holen, NICHT unitprice alleine! Co-Authored-By: Claude Sonnet 4.5 --- import.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/import.php b/import.php index 4182cda..0245ed2 100755 --- a/import.php +++ b/import.php @@ -1893,8 +1893,9 @@ if ($action == 'previewdatanorm' && $id > 0) { $productCopperSurcharge = 0; $currentSupplierPriceId = 0; $currentSupplierMinQty = 1; + $currentSupplierTotalPrice = 0; if ($existingProductId > 0) { - $sqlExisting = "SELECT pf.rowid, pf.fk_soc, pf.unitprice, pf.quantity FROM ".MAIN_DB_PREFIX."product_fournisseur_price pf"; + $sqlExisting = "SELECT pf.rowid, pf.fk_soc, pf.price, pf.quantity FROM ".MAIN_DB_PREFIX."product_fournisseur_price pf"; $sqlExisting .= " WHERE pf.fk_product = ".(int)$existingProductId; $resExisting = $db->query($sqlExisting); if ($resExisting) { @@ -1902,9 +1903,10 @@ if ($action == 'previewdatanorm' && $id > 0) { $existingPriceSuppliers[$objEx->fk_soc] = true; // Load current invoice supplier's Dolibarr price for comparison if ($objEx->fk_soc == $import->fk_soc) { - $currentDolibarrPrice = (float)$objEx->unitprice; - $currentSupplierPriceId = $objEx->rowid; + $currentSupplierTotalPrice = (float)$objEx->price; $currentSupplierMinQty = max(1, $objEx->quantity); + $currentDolibarrPrice = $currentSupplierMinQty > 0 ? $currentSupplierTotalPrice / $currentSupplierMinQty : $currentSupplierTotalPrice; + $currentSupplierPriceId = $objEx->rowid; } } } @@ -1979,6 +1981,7 @@ if ($action == 'previewdatanorm' && $id > 0) { 'datanorm_price_unit' => $datanorm->price_unit, 'datanorm_ean' => $datanorm->ean, 'purchase_price' => $currentDolibarrPrice, // Current Dolibarr unit price + 'purchase_total_price' => $currentSupplierTotalPrice, // Dolibarr total price for min qty 'purchase_min_qty' => $currentSupplierMinQty, // Dolibarr minimum quantity 'purchase_copper_surcharge' => $productCopperSurcharge, // Dolibarr copper surcharge (for min qty) 'datanorm_purchase_price' => $purchasePrice, // New Datanorm unit price @@ -3035,9 +3038,9 @@ if ($action == 'edit' && $import->id > 0) { // Current Dolibarr price for minimum quantity print ''; - if (!empty($match['purchase_price']) && $match['purchase_price'] > 0) { + if (!empty($match['purchase_total_price']) && $match['purchase_total_price'] > 0) { $dolibarrMinQty = !empty($match['purchase_min_qty']) ? $match['purchase_min_qty'] : 1; - $dolibarrMaterialTotal = $match['purchase_price'] * $dolibarrMinQty; + $dolibarrMaterialTotal = $match['purchase_total_price']; $dolibarrCopper = !empty($match['purchase_copper_surcharge']) ? $match['purchase_copper_surcharge'] : 0; // Show breakdown if copper exists