Skip to content

Commit

Permalink
Merge pull request #78 from CETEN-OpenBar/fixTvaupdateprice
Browse files Browse the repository at this point in the history
Fix tvaupdateprice
  • Loading branch information
BaptTF committed Apr 12, 2024
2 parents 4cd5e8a + 93081c2 commit e484308
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions frontend/src/routes/panel/products/reappro/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
amount_of_bundle: string;
amount_per_bundle: string;
bundle_cost_ht: string;
tva: number;
tva: string;
bundle_cost_ttc: string;
};
Expand All @@ -52,7 +52,7 @@
amount_of_bundle: 'Nombre de lots',
amount_per_bundle: 'Nombre de produits par lots',
bundle_cost_ht: "Prix d'un lot HT",
tva: 0,
tva: "0",
bundle_cost_ttc: "Prix d'un lot TTC"
};
Expand Down Expand Up @@ -119,7 +119,7 @@
amount_of_bundle: 'Nombre de lots',
amount_per_bundle: 'Nombre de produits par lots',
bundle_cost_ht: "Prix d'un lot HT",
tva: 0,
tva: "0",
bundle_cost_ttc: "Prix d'un lot TTC"
};
newItem = {
Expand All @@ -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);
}
</script>

Expand Down Expand Up @@ -288,11 +290,10 @@
item.prices.coutant / (1 + (item.last_tva ?? 0) / 10000)
);
displayedValues.item_price_calc = item.prices.coutant;
displayedValues.tva = item.last_tva ?? 0;
displayedValues.tva = (item.last_tva ?? 0).toString();
newItem.tva = item.last_tva ?? 0;
newItem.item_id = item.id;
searchName = '';
updatePrices();
}}
>
{item.name}
Expand Down Expand Up @@ -379,6 +380,7 @@
<div class="flex flex-col">
<select
class="rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent"
id="tva"
on:change={(e) => {
// @ts-ignore
newItem.tva = parseInt(e.target?.value);
Expand All @@ -403,7 +405,7 @@
placeholder={displayedValues.bundle_cost_ttc}
on:change={(e) => {
newItem.bundle_cost_ht = Math.round(
// @ts-ignore
// @ts-ignore
parsePrice(e.target?.value) / (1 + (newItem.tva ?? 0) / 10000)
);
// @ts-ignore
Expand All @@ -427,7 +429,7 @@
t.unshift(newItem);
n.unshift(displayedValues.name);
newRestock.items = t;
nameList = nameList;
nameList = n;
displayedValues = {
name: 'Nom du produit',
item_price_calc: 0,
Expand All @@ -436,9 +438,9 @@
amount_of_bundle: 'Nombre de lots',
amount_per_bundle: 'Nombre de produits par lots',
bundle_cost_ht: "Prix d'un lot HT",
tva: 0,
tva: "0",
bundle_cost_ttc: "Prix d'un lot TTC"
};
};
newItem = {
item_id: '',
amount_of_bundle: 0,
Expand Down

0 comments on commit e484308

Please sign in to comment.