From e0929c1f79ce2b34729bb7ab16e6f7ede4989c94 Mon Sep 17 00:00:00 2001 From: JULLIEN Baptiste Date: Fri, 12 Apr 2024 01:31:30 +0200 Subject: [PATCH 1/2] Calculate price correctly when changed --- .../panel/products/reappro/+page.svelte | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/frontend/src/routes/panel/products/reappro/+page.svelte b/frontend/src/routes/panel/products/reappro/+page.svelte index 338a8a8..de0999a 100644 --- a/frontend/src/routes/panel/products/reappro/+page.svelte +++ b/frontend/src/routes/panel/products/reappro/+page.svelte @@ -140,22 +140,24 @@ // Calculate from displayedValues.item_price_calc, displayedValues.amount_of_bundle and TVA if (newItem.amount_of_bundle === 0 || newItem.amount_per_bundle === 0) return; - displayedValues.item_price_ht = formatPrice( - displayedValues.item_price_calc / (1 + (newItem.tva ?? 0) / 10000) - ); - if (displayedValues.bundle_cost_ht === "Prix d'un lot HT") { newItem.bundle_cost_ht = Math.round( (displayedValues.item_price_calc * newItem.amount_per_bundle) / (1 + newItem.tva / 10000) ); + displayedValues.bundle_cost_ht = formatPrice(newItem.bundle_cost_ht); } - displayedValues.bundle_cost_ht = formatPrice(newItem.bundle_cost_ht); if (displayedValues.bundle_cost_ttc === "Prix d'un lot TTC") { newItem.bundle_cost_ttc = Math.round( - displayedValues.item_price_calc * newItem.amount_per_bundle - ); - } - displayedValues.bundle_cost_ttc = formatPrice(newItem.bundle_cost_ttc); + displayedValues.item_price_calc * newItem.amount_per_bundle + ); + displayedValues.bundle_cost_ttc = formatPrice(newItem.bundle_cost_ttc); + } else { + newItem.bundle_cost_ttc = Math.round(newItem.bundle_cost_ht * (1 + newItem.tva / 10000)); + newItem.bundle_cost_float_ttc = newItem.bundle_cost_ht * (1 + newItem.tva / 10000); + displayedValues.bundle_cost_ttc = formatPrice(newItem.bundle_cost_ttc); + } + displayedValues.item_price_ht = formatPrice(newItem.bundle_cost_ht * newItem.amount_of_bundle); + displayedValues.item_price = formatPrice(newItem.bundle_cost_ttc * newItem.amount_of_bundle); } @@ -292,7 +294,6 @@ newItem.tva = item.last_tva ?? 0; newItem.item_id = item.id; searchName = ''; - updatePrices(); }} > {item.name} @@ -379,6 +380,7 @@