fix: kit discount amount + price sync no auto-insert + repackaging kit detection
Kit discount: v_disc_amt is per-kit, not per-unit — remove division by v_cantitate_web so discount lines compute correctly (e.g. -2 x 5 = -10). Price sync: stop auto-inserting missing articles into price policies (was inserting with wrong proc_tvav from GoMag). Log warning instead. Kit detection: extend to single-component repackagings (cantitate_roa > 1) in both PL/SQL package and price sync/validation services. Add repackaging kit pricing test for separate_line and distributed modes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,9 @@
|
||||
-- 20.03.2026 - dual policy vanzare/productie, kit pricing distributed/separate_line, SKU→CODMAT via ARTICOLE_TERTI
|
||||
-- 20.03.2026 - kit discount deferred cross-kit (separate_line, merge-on-collision)
|
||||
-- 20.03.2026 - merge_or_insert_articol: merge cantitati cand kit+individual au acelasi articol/pret
|
||||
-- 20.03.2026 - kit pricing extins pt reambalari single-component (cantitate_roa > 1)
|
||||
-- 21.03.2026 - diagnostic detaliat discount kit (id_pol, id_art, codmat in eroare)
|
||||
-- 21.03.2026 - fix discount amount: v_disc_amt e per-kit, nu se imparte la v_cantitate_web
|
||||
-- ====================================================================
|
||||
CREATE OR REPLACE PACKAGE PACK_IMPORT_COMENZI AS
|
||||
|
||||
@@ -262,6 +265,7 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
|
||||
-- Variabile kit pricing
|
||||
v_kit_count NUMBER := 0;
|
||||
v_max_cant_roa NUMBER := 1;
|
||||
v_kit_comps t_kit_components;
|
||||
v_sum_list_prices NUMBER;
|
||||
v_discount_total NUMBER;
|
||||
@@ -366,15 +370,17 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
v_found_mapping := FALSE;
|
||||
|
||||
-- Numara randurile ARTICOLE_TERTI pentru a detecta kituri (>1 rand = set compus)
|
||||
SELECT COUNT(*) INTO v_kit_count
|
||||
SELECT COUNT(*), NVL(MAX(at.cantitate_roa), 1)
|
||||
INTO v_kit_count, v_max_cant_roa
|
||||
FROM articole_terti at
|
||||
WHERE at.sku = v_sku
|
||||
AND at.activ = 1
|
||||
AND at.sters = 0;
|
||||
|
||||
IF v_kit_count > 1 AND p_kit_mode IS NOT NULL THEN
|
||||
IF ((v_kit_count > 1) OR (v_kit_count = 1 AND v_max_cant_roa > 1))
|
||||
AND p_kit_mode IS NOT NULL THEN
|
||||
-- ============================================================
|
||||
-- KIT PRICING: set compus cu >1 componente, mod activ
|
||||
-- KIT PRICING: set compus (>1 componente) sau reambalare (cantitate_roa>1), mod activ
|
||||
-- Prima trecere: colecteaza componente + preturi din politici
|
||||
-- ============================================================
|
||||
v_found_mapping := TRUE;
|
||||
@@ -573,7 +579,7 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
END IF;
|
||||
|
||||
IF v_disc_amt != 0 THEN
|
||||
v_unit_pret := v_disc_amt / v_cantitate_web;
|
||||
v_unit_pret := v_disc_amt;
|
||||
|
||||
-- Search for existing entry with same (ptva, pret) to merge qty
|
||||
v_kit_disc_found := FALSE;
|
||||
@@ -707,7 +713,10 @@ CREATE OR REPLACE PACKAGE BODY PACK_IMPORT_COMENZI AS
|
||||
WHEN OTHERS THEN
|
||||
v_articole_eroare := v_articole_eroare + 1;
|
||||
g_last_error := g_last_error || CHR(10) ||
|
||||
'Eroare linie discount kit TVA=' || v_kit_disc_list(j).ptva || '%: ' || SQLERRM;
|
||||
'Eroare linie discount kit TVA=' || v_kit_disc_list(j).ptva ||
|
||||
'% id_pol=' || NVL(p_kit_discount_id_pol, p_id_pol) ||
|
||||
' id_art=' || v_disc_artid ||
|
||||
' codmat=' || p_kit_discount_codmat || ': ' || SQLERRM;
|
||||
END;
|
||||
END LOOP;
|
||||
END IF;
|
||||
|
||||
Reference in New Issue
Block a user