From c362843c8e1c2088b7fd9769bb0bab326be92ac2 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 28 Mar 2021 23:45:35 +0200 Subject: [PATCH] [pricelist] Same cleanup as in backend --- src/flaschengeist.d.ts | 6 +- .../CalculationTable/Ingredients.vue | 2 +- .../components/CalculationTable/NewDrink.vue | 22 +++--- .../{components => pages}/Pricelist.vue | 79 ++++++++----------- src/plugins/pricelist/pages/PricelistP.vue | 15 ---- src/plugins/pricelist/routes/index.ts | 2 +- src/plugins/pricelist/store.ts | 16 ++-- 7 files changed, 58 insertions(+), 84 deletions(-) rename src/plugins/pricelist/{components => pages}/Pricelist.vue (50%) delete mode 100644 src/plugins/pricelist/pages/PricelistP.vue diff --git a/src/flaschengeist.d.ts b/src/flaschengeist.d.ts index a081c23..11cf79d 100644 --- a/src/flaschengeist.d.ts +++ b/src/flaschengeist.d.ts @@ -77,8 +77,8 @@ declare namespace FG { package_size?: number; name: string; volume?: number; - cost_price_pro_volume?: number; - cost_price_package_netto?: number; + cost_per_volume?: number; + cost_per_package?: number; tags?: Array; type?: DrinkType; volumes: Array; @@ -86,7 +86,7 @@ declare namespace FG { interface DrinkIngredient { id: number; volume: number; - drink_ingredient_id: number; + ingredient_id: number; } interface DrinkPrice { id: number; diff --git a/src/plugins/pricelist/components/CalculationTable/Ingredients.vue b/src/plugins/pricelist/components/CalculationTable/Ingredients.vue index 1317056..47838f3 100644 --- a/src/plugins/pricelist/components/CalculationTable/Ingredients.vue +++ b/src/plugins/pricelist/components/CalculationTable/Ingredients.vue @@ -179,7 +179,7 @@ export default defineComponent({ id: -1, drink_ingredient: { id: -1, - drink_ingredient_id: newIngredient.value.id, + ingredient_id: newIngredient.value.id, volume: newIngredientVolume.value, }, extra_ingredient: undefined, diff --git a/src/plugins/pricelist/components/CalculationTable/NewDrink.vue b/src/plugins/pricelist/components/CalculationTable/NewDrink.vue index 75ad58d..320d241 100644 --- a/src/plugins/pricelist/components/CalculationTable/NewDrink.vue +++ b/src/plugins/pricelist/components/CalculationTable/NewDrink.vue @@ -41,14 +41,14 @@ type="number" /> - !!newDrink.value.cost_price_package_netto && + !!newDrink.value.cost_per_package && !!newDrink.value.volume && !!newDrink.value.package_size ); - const cost_price_pro_volume = computed({ + const cost_per_volume = computed({ get: () => { if (calc_price_pro_volume.value) { const retVal = - ((newDrink.value.cost_price_package_netto || 0) / + ((newDrink.value.cost_per_package || 0) / ((newDrink.value.volume || 0) * (newDrink.value.package_size || 0))) * 1.19; // eslint-disable-next-line vue/no-side-effects-in-computed-properties - newDrink.value.cost_price_pro_volume = Math.round(retVal * 1000) / 1000; + newDrink.value.cost_per_volume = Math.round(retVal * 1000) / 1000; } - return newDrink.value.cost_price_pro_volume; + return newDrink.value.cost_per_volume; }, set: (val) => { - newDrink.value.cost_price_pro_volume = val; + newDrink.value.cost_per_volume = val; }, }); @@ -123,7 +123,7 @@ export default defineComponent({ drinkTypes: computed(() => store.drinkTypes), newDrink, calc_price_pro_volume, - cost_price_pro_volume, + cost_per_volume, addDrink, cancelAddDrink, notEmpty, diff --git a/src/plugins/pricelist/components/Pricelist.vue b/src/plugins/pricelist/pages/Pricelist.vue similarity index 50% rename from src/plugins/pricelist/components/Pricelist.vue rename to src/plugins/pricelist/pages/Pricelist.vue index f2a1bfe..1a6c827 100644 --- a/src/plugins/pricelist/components/Pricelist.vue +++ b/src/plugins/pricelist/pages/Pricelist.vue @@ -1,37 +1,39 @@ - - diff --git a/src/plugins/pricelist/routes/index.ts b/src/plugins/pricelist/routes/index.ts index 1ba6d56..3ec87fe 100644 --- a/src/plugins/pricelist/routes/index.ts +++ b/src/plugins/pricelist/routes/index.ts @@ -19,7 +19,7 @@ export const innerRoutes: FG_Plugin.MenuRoute[] = [ route: { path: 'pricelist', name: 'drinks-pricelist', - component: () => import('../pages/PricelistP.vue'), + component: () => import('../pages/Pricelist.vue'), }, }, { diff --git a/src/plugins/pricelist/store.ts b/src/plugins/pricelist/store.ts index 0177ef2..0769f75 100644 --- a/src/plugins/pricelist/store.ts +++ b/src/plugins/pricelist/store.ts @@ -51,8 +51,8 @@ class Drink { package_size, name, volume, - cost_price_pro_volume, - cost_price_package_netto, + cost_per_volume, + cost_per_package, tags, type, }: FG.Drink) { @@ -61,15 +61,13 @@ class Drink { this.package_size = package_size; this.name = name; this.volume = volume; - this.cost_price_package_netto = cost_price_package_netto; - this._cost_price_pro_volume = cost_price_pro_volume; + this.cost_per_package = cost_per_package; + this.cost_per_volume = cost_per_volume; this.cost_price_pro_volume = computed({ get: () => { - if (!!this.volume && !!this.package_size && !!this.cost_price_package_netto) { + if (!!this.volume && !!this.package_size && !!this.cost_per_package) { const retVal = - ((this.cost_price_package_netto || 0) / - ((this.volume || 0) * (this.package_size || 0))) * - 1.19; + ((this.cost_per_package || 0) / ((this.volume || 0) * (this.package_size || 0))) * 1.19; this._cost_price_pro_volume = Math.round(retVal * 1000) / 1000; } @@ -282,7 +280,7 @@ export const usePricelistStore = defineStore({ volume.ingredients.forEach((ingredient) => { if (ingredient.drink_ingredient) { const _drink = usePricelistStore().drinks.find( - (a) => a.id === ingredient.drink_ingredient?.drink_ingredient_id + (a) => a.id === ingredient.drink_ingredient?.ingredient_id ); retVal += ingredient.drink_ingredient.volume *