From 66cdff21047038b0c19c61bb7e5280414ae86cef Mon Sep 17 00:00:00 2001 From: data Date: Tue, 3 Mar 2026 08:49:21 +0100 Subject: [PATCH] fix: Einfache Preisberechnung mit Kupferzuschlag aus Dolibarr (v4.3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Komplizierte Logik mit copper_surcharge aus Datanorm (immer 0) - Kupferzuschlag wurde nicht korrekt aus Dolibarr-Extrafields geladen Lösung - EINFACH: 1. Dolibarr-Preis = unitprice × quantity + kupferzuschlag 2. Datanorm-Preis = price + kupferzuschlag (aus Dolibarr!) 3. Beide Preise für Mindestmenge anzeigen Beispiel NYM-J 3x1,5: - Dolibarr: 0,52€ × 100 + 45,30€ = 97,30€/100 - Datanorm: 18,20€ + 45,30€ = 63,50€/100 - Differenz: -34,7% Beispiel Klemme: - Dolibarr: 0,08€ × 100 = 8,00€/100 - Datanorm: 94,25€/100 - Differenz: +1.078% Co-Authored-By: Claude Sonnet 4.5 --- import.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/import.php b/import.php index 66db65f..2cde227 100755 --- a/import.php +++ b/import.php @@ -1970,9 +1970,10 @@ if ($action == 'previewdatanorm' && $id > 0) { 'datanorm_ean' => $datanorm->ean, 'purchase_price' => $currentDolibarrPrice, // Current Dolibarr unit price '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 'selling_price' => $sellingPrice, - 'copper_surcharge' => $copperSurchargeForPrice, // Copper surcharge (for price_unit) + 'copper_surcharge' => $copperSurchargeForPrice, // Copper surcharge (per unit) 'existing_product_id' => $existingProductId, 'action' => $productAction, 'new_ref' => 'NEW-'.$supplierPrefix.'-'.$datanorm->article_number, @@ -3027,16 +3028,17 @@ if ($action == 'edit' && $import->id > 0) { print ''; if (!empty($match['purchase_price']) && $match['purchase_price'] > 0) { $dolibarrMinQty = !empty($match['purchase_min_qty']) ? $match['purchase_min_qty'] : 1; - $dolibarrTotalForQty = $match['purchase_price'] * $dolibarrMinQty; + $dolibarrMaterialTotal = $match['purchase_price'] * $dolibarrMinQty; + $dolibarrCopper = !empty($match['purchase_copper_surcharge']) ? $match['purchase_copper_surcharge'] : 0; - // Load copper surcharge for this supplier price - $dolibarrCopper = !empty($productCopperSurcharge) ? $productCopperSurcharge : 0; + // Show breakdown if copper exists if ($dolibarrCopper > 0) { - print ''.price($dolibarrTotalForQty).' + '.price($dolibarrCopper).' Cu
'; - $dolibarrTotalForQty += $dolibarrCopper; + print ''.price($dolibarrMaterialTotal).' + '.price($dolibarrCopper).' Cu
'; } - print ''.price($dolibarrTotalForQty); + // Total price for minimum quantity + $dolibarrTotal = $dolibarrMaterialTotal + $dolibarrCopper; + print ''.price($dolibarrTotal); if ($dolibarrMinQty > 1) { print '/'.$dolibarrMinQty; } @@ -3044,7 +3046,8 @@ if ($action == 'edit' && $import->id > 0) { // Unit price as secondary info if ($dolibarrMinQty > 1) { - print '
('.price($match['purchase_price']).'/Stk.)'; + $dolibarrUnitPrice = $dolibarrTotal / $dolibarrMinQty; + print '
('.price($dolibarrUnitPrice).'/Stk.)'; } } else { print '-'; @@ -3054,16 +3057,17 @@ if ($action == 'edit' && $import->id > 0) { // Datanorm price - show price for minimum quantity print ''; $datanormPriceUnit = max(1, $match['datanorm_price_unit']); - $datanormTotalForUnit = $match['datanorm_price'] + ($match['copper_surcharge'] * $datanormPriceUnit); + $datanormMaterialTotal = $match['datanorm_price']; // Material price for price_unit + $datanormCopper = !empty($match['purchase_copper_surcharge']) ? $match['purchase_copper_surcharge'] : 0; - // Show breakdown if copper surcharge exists - if ($match['copper_surcharge'] > 0) { - $copperForUnit = $match['copper_surcharge'] * $datanormPriceUnit; - print ''.price($match['datanorm_price']).' + '.price($copperForUnit).' Cu
'; + // Show breakdown if copper exists + if ($datanormCopper > 0) { + print ''.price($datanormMaterialTotal).' + '.price($datanormCopper).' Cu
'; } - // Main price for minimum quantity - print ''.price($datanormTotalForUnit); + // Total price for minimum quantity (Datanorm material + Dolibarr copper) + $datanormTotal = $datanormMaterialTotal + $datanormCopper; + print ''.price($datanormTotal); if ($datanormPriceUnit > 1) { print '/'.$datanormPriceUnit; } @@ -3071,7 +3075,7 @@ if ($action == 'edit' && $import->id > 0) { // Unit price as secondary info if ($datanormPriceUnit > 1) { - $datanormUnitPrice = $datanormTotalForUnit / $datanormPriceUnit; + $datanormUnitPrice = $datanormTotal / $datanormPriceUnit; print '
('.price($datanormUnitPrice).'/Stk.)'; } print '';