From 5d1df48b9af1c1649a56287b418a63d699a2ffd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 2 Apr 2021 14:06:03 +0200 Subject: [PATCH] [pricelist][fix] fixed issues from merge 3eea07987110de9a9246807a4edbcaed0116d95b --- .../pricelist/components/CalculationTable.vue | 26 +++++++-------- .../CalculationTable/Ingredients.vue | 4 +-- .../pricelist/pages/CocktailBuilder.vue | 3 +- src/plugins/pricelist/store.ts | 32 +++++++++++-------- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/plugins/pricelist/components/CalculationTable.vue b/src/plugins/pricelist/components/CalculationTable.vue index 976efed..f841f02 100644 --- a/src/plugins/pricelist/components/CalculationTable.vue +++ b/src/plugins/pricelist/components/CalculationTable.vue @@ -273,10 +273,10 @@ /> - + {{ - drinks_props.row.cost_price_package_netto - ? `${drinks_props.row.cost_price_package_netto.toFixed(2)}€` + drinks_props.row.cost_per_package + ? `${drinks_props.row.cost_per_package.toFixed(2)}€` : 'o.A.' }} - + {{ - drinks_props.row.cost_price_pro_volume - ? `${drinks_props.row.cost_price_pro_volume.toFixed(3)}€` + drinks_props.row.cost_per_volume + ? `${drinks_props.row.cost_per_volume.toFixed(3)}€` : 'o.A.' }} (val ? `${val.toFixed(3)}€` : ''), sortable: true, sort, }, { - name: 'cost_price_pro_volume', + name: 'cost_per_volume', label: 'Preis mit 19%/Liter', - field: 'cost_price_pro_volume', + field: 'cost_per_volume', format: (val: number | null) => (val ? `${val.toFixed(3)}€` : ''), sortable: true, sort: (a: ComputedRef, b: ComputedRef) => sort(a.value, b.value), diff --git a/src/plugins/pricelist/components/CalculationTable/Ingredients.vue b/src/plugins/pricelist/components/CalculationTable/Ingredients.vue index 5909ba4..7a838bc 100644 --- a/src/plugins/pricelist/components/CalculationTable/Ingredients.vue +++ b/src/plugins/pricelist/components/CalculationTable/Ingredients.vue @@ -210,8 +210,8 @@ export default defineComponent({ } const drinks = computed(() => store.drinks.filter((drink) => { - console.log('computed drinks', drink.name, drink.cost_price_pro_volume); - return drink.cost_price_pro_volume; + console.log('computed drinks', drink.name, drink.cost_per_volume); + return drink.cost_per_volume; }) ); const extra_ingredients = computed(() => store.extraIngredients); diff --git a/src/plugins/pricelist/pages/CocktailBuilder.vue b/src/plugins/pricelist/pages/CocktailBuilder.vue index 5c37226..addffcf 100644 --- a/src/plugins/pricelist/pages/CocktailBuilder.vue +++ b/src/plugins/pricelist/pages/CocktailBuilder.vue @@ -48,8 +48,7 @@ export default defineComponent({ (a) => a.id === ingredient.drink_ingredient?.ingredient_id ); retVal += - ingredient.drink_ingredient.volume * - (_drink?.cost_price_pro_volume); + ingredient.drink_ingredient.volume * (_drink?.cost_per_volume); } if (ingredient.extra_ingredient) { extraIngredientPrice += ingredient.extra_ingredient.price; diff --git a/src/plugins/pricelist/store.ts b/src/plugins/pricelist/store.ts index 6b058dc..539ef0d 100644 --- a/src/plugins/pricelist/store.ts +++ b/src/plugins/pricelist/store.ts @@ -13,10 +13,10 @@ interface DrinkPriceVolume extends Omit, 'mi min_prices: MinPrice[]; } -interface Drink extends Omit, 'volumes'> { +interface Drink extends Omit, 'volumes'> { volumes: DrinkPriceVolume[]; - cost_price_pro_volume: WritableComputedRef; - _cost_price_pro_volume?: number; + cost_per_volume: WritableComputedRef; + _cost_per_volume?: number; } class DrinkPriceVolume implements DrinkPriceVolume { @@ -66,18 +66,18 @@ class Drink { this.name = name; this.volume = volume; this.cost_per_package = cost_per_package; - this.cost_per_volume = cost_per_volume; - this.cost_price_pro_volume = computed({ + this._cost_per_volume = cost_per_volume; + this.cost_per_volume = computed({ get: () => { if (!!this.volume && !!this.package_size && !!this.cost_per_package) { const retVal = ((this.cost_per_package || 0) / ((this.volume || 0) * (this.package_size || 0))) * 1.19; - this._cost_price_pro_volume = Math.round(retVal * 1000) / 1000; + this._cost_per_volume = Math.round(retVal * 1000) / 1000; } - return this._cost_price_pro_volume; + return this._cost_per_volume; }, - set: (val) => (this._cost_price_pro_volume = val), + set: (val) => (this._cost_per_volume = val), }); this.tags = tags; this.type = type; @@ -208,7 +208,9 @@ export const usePricelistStore = defineStore({ .catch((err) => console.warn(err)); }, async setDrink(drink: FG.Drink) { - const { data } = await api.post('pricelist/drinks', drink); + const { data } = await api.post('pricelist/drinks', { + ...drink, + }); const _drink = new Drink(data); data.volumes.forEach((volume) => { const _volume = new DrinkPriceVolume(volume); @@ -218,7 +220,11 @@ export const usePricelistStore = defineStore({ this.create_min_prices(); }, async updateDrink(drink: Drink) { - const { data } = await api.put(`pricelist/drinks/${drink.id}`, drink); + console.log(drink); + const { data } = await api.put(`pricelist/drinks/${drink.id}`, { + ...drink, + cost_per_volume: drink._cost_per_volume, + }); const index = this.drinks.findIndex((a) => a.id === data.id); if (index > -1) { const _drink = new Drink(data); @@ -273,10 +279,10 @@ export const usePricelistStore = defineStore({ volume.min_prices = []; this.min_prices.forEach((min_price) => { let computedMinPrice: ComputedRef; - if (drink.cost_price_pro_volume) { + if (drink.cost_per_volume) { computedMinPrice = computed( () => - ((drink.cost_price_pro_volume) * + ((drink.cost_per_volume) * (volume.volume) * min_price) / 100 @@ -292,7 +298,7 @@ export const usePricelistStore = defineStore({ ); retVal += ingredient.drink_ingredient.volume * - (_drink?.cost_price_pro_volume); + (_drink?.cost_per_volume); } if (ingredient.extra_ingredient) { extraIngredientPrice += ingredient.extra_ingredient.price;