better drinks dependencies #2

drink_ingredients has name and cost_per_volume
This commit is contained in:
Tim Gröger 2021-06-30 10:42:42 +02:00
parent a7765797d1
commit 482c094511
4 changed files with 20 additions and 2 deletions

2
src/api.d.ts vendored
View File

@ -17,6 +17,8 @@ declare namespace FG {
id: number;
volume: number;
ingredient_id: number;
cost_per_volume: number;
name: string;
}
interface DrinkPrice {
id: number;

View File

@ -196,6 +196,8 @@ export default defineComponent({
id: -1,
ingredient_id: newIngredient.value.id,
volume: newIngredientVolume.value,
cost_per_volume: newIngredient.value.cost_per_volume,
name: newIngredient.value.name,
},
extra_ingredient: undefined,
};

View File

@ -1,6 +1,7 @@
import { api } from '@flaschengeist/api';
import { defineStore } from 'pinia';
import { calc_volume, calc_cost_per_volume, calc_all_min_prices } from './utils/utils';
import Ingredient = FG.Ingredient;
interface DrinkPriceVolume extends Omit<FG.DrinkPriceVolume, 'volume'> {
_volume: number;
@ -191,6 +192,18 @@ export const usePricelistStore = defineStore({
});
this.drinks[index] = _drink;
}
if (!!drink.cost_per_volume) {
this.drinks.forEach((_drink: Drink) => {
_drink.volumes.forEach((_volume: DrinkPriceVolume) => {
_volume.ingredients.forEach((_ingredient: Ingredient) => {
if (_ingredient.drink_ingredient && _ingredient.drink_ingredient.ingredient_id === drink.id) {
_ingredient.drink_ingredient.cost_per_volume = drink.cost_per_volume
_ingredient.drink_ingredient.name = drink.name
}
})
})
})
}
calc_all_min_prices(this.drinks, this.min_prices);
},
deleteDrink(drink: Drink) {

View File

@ -36,8 +36,9 @@ function helper(volume: DrinkPriceVolume, min_price: number) {
let extraIngredientPrice = 0;
volume.ingredients.forEach((ingredient) => {
if (ingredient.drink_ingredient) {
const _drink = usePricelistStore().drinks.find((a) => a.id === ingredient.drink_ingredient?.ingredient_id);
retVal += ingredient.drink_ingredient.volume * <number>(<unknown>_drink?.cost_per_volume);
//const _drink = usePricelistStore().drinks.find((a) => a.id === ingredient.drink_ingredient?.ingredient_id);
//retVal += ingredient.drink_ingredient.volume * <number>(<unknown>_drink?.cost_per_volume);
retVal += ingredient.drink_ingredient.volume * ingredient.drink_ingredient.cost_per_volume
}
if (ingredient.extra_ingredient) {
extraIngredientPrice += ingredient.extra_ingredient.price;