diff --git a/import.php b/import.php
index bf7085a..66db65f 100755
--- a/import.php
+++ b/import.php
@@ -1882,8 +1882,9 @@ if ($action == 'previewdatanorm' && $id > 0) {
// Load existing product's copper surcharge for price comparison
$productCopperSurcharge = 0;
$currentSupplierPriceId = 0;
+ $currentSupplierMinQty = 1;
if ($existingProductId > 0) {
- $sqlExisting = "SELECT pf.rowid, pf.fk_soc, pf.unitprice FROM ".MAIN_DB_PREFIX."product_fournisseur_price pf";
+ $sqlExisting = "SELECT pf.rowid, pf.fk_soc, pf.unitprice, pf.quantity FROM ".MAIN_DB_PREFIX."product_fournisseur_price pf";
$sqlExisting .= " WHERE pf.fk_product = ".(int)$existingProductId;
$resExisting = $db->query($sqlExisting);
if ($resExisting) {
@@ -1893,6 +1894,7 @@ if ($action == 'previewdatanorm' && $id > 0) {
if ($objEx->fk_soc == $import->fk_soc) {
$currentDolibarrPrice = (float)$objEx->unitprice;
$currentSupplierPriceId = $objEx->rowid;
+ $currentSupplierMinQty = max(1, $objEx->quantity);
}
}
}
@@ -1966,10 +1968,11 @@ if ($action == 'previewdatanorm' && $id > 0) {
'datanorm_price' => $datanorm->price,
'datanorm_price_unit' => $datanorm->price_unit,
'datanorm_ean' => $datanorm->ean,
- 'purchase_price' => $currentDolibarrPrice, // Current Dolibarr price for comparison
- 'datanorm_purchase_price' => $purchasePrice, // New Datanorm price
+ 'purchase_price' => $currentDolibarrPrice, // Current Dolibarr unit price
+ 'purchase_min_qty' => $currentSupplierMinQty, // Dolibarr minimum quantity
+ 'datanorm_purchase_price' => $purchasePrice, // New Datanorm unit price
'selling_price' => $sellingPrice,
- 'copper_surcharge' => $copperSurchargeForPrice,
+ 'copper_surcharge' => $copperSurchargeForPrice, // Copper surcharge (for price_unit)
'existing_product_id' => $existingProductId,
'action' => $productAction,
'new_ref' => 'NEW-'.$supplierPrefix.'-'.$datanorm->article_number,
@@ -3020,22 +3023,56 @@ if ($action == 'edit' && $import->id > 0) {
}
print '';
- // Invoice price (from ZUGFeRD)
+ // Current Dolibarr price for minimum quantity
print '
';
- print ''.price($match['line_unit_price']).'';
+ 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;
+
+ // Load copper surcharge for this supplier price
+ $dolibarrCopper = !empty($productCopperSurcharge) ? $productCopperSurcharge : 0;
+ if ($dolibarrCopper > 0) {
+ print ''.price($dolibarrTotalForQty).' + '.price($dolibarrCopper).' Cu ';
+ $dolibarrTotalForQty += $dolibarrCopper;
+ }
+
+ print ''.price($dolibarrTotalForQty);
+ if ($dolibarrMinQty > 1) {
+ print '/'.$dolibarrMinQty;
+ }
+ print '';
+
+ // Unit price as secondary info
+ if ($dolibarrMinQty > 1) {
+ print ' ('.price($match['purchase_price']).'/Stk.)';
+ }
+ } else {
+ print '-';
+ }
print ' | ';
- // Datanorm price - show original price and calculated unit price
+ // Datanorm price - show price for minimum quantity
print '';
- if ($match['datanorm_price_unit'] > 1) {
- // Show original price and price unit
- print ''.price($match['datanorm_price']).'/'.$match['datanorm_price_unit'].'';
- print ' = '.price($match['purchase_price']).'';
- } else {
- print ''.price($match['purchase_price']).'';
- }
+ $datanormPriceUnit = max(1, $match['datanorm_price_unit']);
+ $datanormTotalForUnit = $match['datanorm_price'] + ($match['copper_surcharge'] * $datanormPriceUnit);
+
+ // Show breakdown if copper surcharge exists
if ($match['copper_surcharge'] > 0) {
- print ' + '.price($match['copper_surcharge']).' Cu';
+ $copperForUnit = $match['copper_surcharge'] * $datanormPriceUnit;
+ print ''.price($match['datanorm_price']).' + '.price($copperForUnit).' Cu ';
+ }
+
+ // Main price for minimum quantity
+ print ''.price($datanormTotalForUnit);
+ if ($datanormPriceUnit > 1) {
+ print '/'.$datanormPriceUnit;
+ }
+ print '';
+
+ // Unit price as secondary info
+ if ($datanormPriceUnit > 1) {
+ $datanormUnitPrice = $datanormTotalForUnit / $datanormPriceUnit;
+ print ' ('.price($datanormUnitPrice).'/Stk.)';
}
print ' | ';