From e4851bd178911eefc3a77afd6f5a7d25f5f73da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 15 Mar 2021 23:52:40 +0100 Subject: [PATCH] [pricelist] fixed prices. first steps for volume --- .../pricelist/components/CalculationTable.vue | 285 +++++++----------- .../CalculationTable/PriceTable.vue | 199 ++++++++++++ src/plugins/pricelist/store/altStore.ts | 47 ++- 3 files changed, 338 insertions(+), 193 deletions(-) create mode 100644 src/plugins/pricelist/components/CalculationTable/PriceTable.vue diff --git a/src/plugins/pricelist/components/CalculationTable.vue b/src/plugins/pricelist/components/CalculationTable.vue index 5ce69a9..99e196e 100644 --- a/src/plugins/pricelist/components/CalculationTable.vue +++ b/src/plugins/pricelist/components/CalculationTable.vue @@ -48,120 +48,53 @@ color="accent" round dense - @click="props.expand = !props.expand" + @click=" + props.expand = !props.expand; + console.log(volumes); + " :icon="props.expand ? 'mdi-chevron-up' : 'mdi-chevron-down'" + v-if="volumes.row.cost_price_pro_volume == null" /> - -
-
-
- {{ min_price.percentage }}% -
-
- {{ parseFloat(min_price.price).toFixed(3) }}€ -
+ + {{ props.row.volume }}L + + + + + +
+
+ {{ min_price.percentage }}% +
+
+ {{ parseFloat(min_price.price).toFixed(3) }}€
-
- - - - - -
-
- {{ col.value }} -
+
+ + @@ -221,8 +154,23 @@ icon-right="add" label="Abgabe hinzufügen" size="xs" - @click="addVolume(volumes.value)" - /> + v-if="volumes.row.cost_price_pro_volume" + > + +
+ +
+
+ + +
+
+
@@ -235,8 +183,10 @@ import { defineComponent, onBeforeMount, ref, computed } from '@vue/composition-api'; import store, { calc_min_prices } from '../store/altStore'; import { v4 } from 'uuid'; +import PriceTable from 'src/plugins/pricelist/components/CalculationTable/PriceTable.vue'; export default defineComponent({ name: 'CalculationTable', + components: { PriceTable }, setup(_, { root }) { onBeforeMount(() => { store.actions.getDrinks(); @@ -246,82 +196,82 @@ export default defineComponent({ { name: 'name', label: 'Getränkename', - field: 'name', + field: 'name' }, { name: 'article_id', label: 'Artikelnummer', - field: 'article_id', + field: 'article_id' }, { name: 'drink_type', label: 'Kategorie', field: 'type', - format: (val: FG.DrinkType) => `${val.name}`, + format: (val: FG.DrinkType) => `${val.name}` }, { name: 'volume_package', label: 'Inhalt in l des Gebinde', - field: 'volume', + field: 'volume' }, { name: 'package_size', label: 'Gebindegröße', - field: 'package_size', + field: 'package_size' }, { name: 'cost_price_package_netto', label: 'Preis Netto/Gebinde', field: 'cost_price_package_netto', - format: (val: number | null) => (val ? `${val.toFixed(3)}€` : ''), + format: (val: number | null) => (val ? `${val.toFixed(3)}€` : '') }, { name: 'cost_price_pro_volume', label: 'Preis mit 19%/Liter', field: 'cost_price_pro_volume', - format: (val: number | null) => (val ? `${val.toFixed(3)}€` : ''), + format: (val: number | null) => (val ? `${val.toFixed(3)}€` : '') }, { name: 'volumes', label: 'Preiskalkulation', - field: 'volumes', - }, + field: 'volumes' + } ]; const column_calc = [ { name: 'volume', label: 'Abgabe in l', field: 'volume', - format: (val: number) => `${val} L`, + format: (val: number) => `${val} L` }, { name: 'min_prices', label: 'Minimal Preise', - field: 'min_prices', + field: 'min_prices' }, { name: 'prices', label: 'Preise', - field: 'prices', - }, + field: 'prices' + } ]; const column_prices = [ { name: 'price', label: 'Preis', field: 'price', - format: (val: number) => `${val.toFixed(2)}€`, + format: (val: number) => `${val.toFixed(2)}€` }, { name: 'description', label: 'Beschreibung', - field: 'description', + field: 'description' }, { name: 'public', label: 'Öffentlich', - field: 'public', - }, + field: 'public' + } ]; const visibleColumn = ref([ 'name', @@ -333,56 +283,32 @@ export default defineComponent({ 'prices', 'price', 'description', - 'public', + 'public' ]); - - function deletePrice(row: FG.DrinkPrice) { - console.log(row); - } - const emptyPrice = { - price: 0, - description: '', - public: true, + const emptyVolume = { + id: -1, + volume: 0, + min_prices: [ + { percentage: 100, price: 0 }, + { percentage: 250, price: 0 }, + { percentage: 300, price: 0 } + ], + prices: [], + ingredients: [] }; - const newPrice = ref(emptyPrice); - function addPrice(volume: FG.DrinkPriceVolume) { - store.actions.setPrice({ ...newPrice.value }, volume); - cancelAddPrice(); + const newVolume = ref(emptyVolume); + function addVolume(drink: FG.Drink) { + store.actions.setVolume(newVolume.value, drink); + cancelAddVolume(); } - function cancelAddPrice() { + function cancelAddVolume() { setTimeout(() => { - addPrice.value = emptyPrice; + newVolume.value = emptyVolume; }, 200); } - function updatePrice(price: FG.DrinkPrice, volume: FG.DrinkPriceVolume) { - store.actions.updatePrice(price, volume); - } - function deletePrice(price: FG.DrinkPrice, volume: FG.DrinkPriceVolume) { - console.log(price, volume); - store.actions.deletePrice(price, volume); - } - - function addVolume(table: FG.DrinkPriceVolume[]) { - table.push({ - id: v4(), - volume: null, - min_prices: [ - { - percentage: 100, - price: 0, - }, - { - percentage: 250, - price: 0, - }, - { - percentage: 300, - price: 0, - }, - ], - prices: [], - ingredients: [], - }); + function updateVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) { + console.log(volume); + store.actions.updateVolume(volume, drink); } function addIngredient(ingredients: FG.Ingredient[]) { @@ -390,23 +316,20 @@ export default defineComponent({ } return { - drinks: computed({ get: () => store.state.drinks, set: (val) => console.log(val) }), + drinks: computed(() => store.state.drinks), columns, column_calc, column_prices, visibleColumn, - deletePrice, - newPrice, - addPrice, - updatePrice, - deletePrice, - cancelAddPrice, addVolume, + cancelAddVolume, + newVolume, + updateVolume, addIngredient, calc_min_prices, - console, + console }; - }, + } }); diff --git a/src/plugins/pricelist/components/CalculationTable/PriceTable.vue b/src/plugins/pricelist/components/CalculationTable/PriceTable.vue new file mode 100644 index 0000000..531af12 --- /dev/null +++ b/src/plugins/pricelist/components/CalculationTable/PriceTable.vue @@ -0,0 +1,199 @@ + + + + + diff --git a/src/plugins/pricelist/store/altStore.ts b/src/plugins/pricelist/store/altStore.ts index 5430a8a..d8e7726 100644 --- a/src/plugins/pricelist/store/altStore.ts +++ b/src/plugins/pricelist/store/altStore.ts @@ -6,7 +6,7 @@ import ExtraIngredient = FG.ExtraIngredient; const state = reactive<{ drinks: FG.Drink[]; tags: FG.Tag[]; drinkTypes: FG.DrinkType[] }>({ drinks: [], tags: [], - drinkTypes: [], + drinkTypes: [] }); const actions = { @@ -21,7 +21,7 @@ const actions = { volume.min_prices = [ { percentage: 100, price: (drink.cost_price_pro_volume || 0) * volume.volume * 1 }, { percentage: 250, price: (drink.cost_price_pro_volume || 0) * volume.volume * 2.5 }, - { percentage: 300, price: (drink.cost_price_pro_volume || 0) * volume.volume * 3 }, + { percentage: 300, price: (drink.cost_price_pro_volume || 0) * volume.volume * 3 } ]; if (volume.ingredients.length > 0) { calc_min_prices(volume); @@ -30,16 +30,16 @@ const actions = { }); }); }) - .catch((err) => console.warn(err)); + .catch(err => console.warn(err)); }, setPrice(price: FG.DrinkPrice, volume: FG.DrinkPriceVolume) { axios - .post(`pricelist/prices/volumes/${volume.id}`, price) + .post(`pricelist/volumes/${volume.id}/prices`, price) .then((response: AxiosResponse) => { volume.prices.push(response.data); this.sortPrices(volume); }) - .catch((err) => console.warn(err)); + .catch(err => console.warn(err)); }, sortPrices(volume: FG.DrinkPriceVolume) { volume.prices.sort((a, b) => { @@ -52,29 +52,52 @@ const actions = { axios .delete(`pricelist/prices/${price.id}`) .then(() => { - const index = volume.prices.findIndex((a) => a.id == price.id); + const index = volume.prices.findIndex(a => a.id == price.id); if (index > -1) { volume.prices.splice(index, 1); } }) - .catch((err) => console.warn(err)); + .catch(err => console.warn(err)); }, updatePrice(price: FG.DrinkPrice, volume: FG.DrinkPriceVolume) { axios .put(`pricelist/prices/${price.id}`, price) .then((response: AxiosResponse) => { - const index = volume.prices.findIndex((a) => a.id === price.id); + const index = volume.prices.findIndex(a => a.id === price.id); if (index > -1) { - volume.prices[index] = response.data; + //volume.prices[index] = response.data; this.sortPrices(volume); } }) - .catch((err) => console.log(err)); + .catch(err => console.log(err)); }, + setVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) { + axios + .post(`pricelist/drinks/${drink.id}/volumes`, volume) + .then((response: AxiosResponse) => { + drink.volumes.push(response.data); + }) + .catch(err => console.warn(err)); + }, + updateVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) { + axios + .put(`pricelist/volumes/${volume.id}`, volume) + .then(() => { + //calc_min_prices_by_drink(volume, drink); + }) + .catch(err => console.warn(err)); + } }; const getters = {}; +function calc_min_prices_by_drink(volume: FG.DrinkPriceVolume, drink: FG.Drink) { + volume.min_prices.forEach(min_price => { + min_price.price = + ((drink.cost_price_pro_volume || 0) * volume.volume * min_price.percentage) / 100; + }); +} + function calc_min_prices(row: FG.DrinkPriceVolume) { row.volume = 0; let cost_price = 0; @@ -87,7 +110,7 @@ function calc_min_prices(row: FG.DrinkPriceVolume) { cost_price += ingredient.price; } }); - row.min_prices.forEach((min_price) => { + row.min_prices.forEach(min_price => { min_price.price = (cost_price * min_price.percentage) / 100; }); } @@ -96,5 +119,5 @@ export { calc_min_prices }; export default { state, actions, - getters, + getters };