better drinks dependencies #2
drink_ingredients has name and cost_per_volume
This commit is contained in:
parent
a7765797d1
commit
482c094511
|
@ -17,6 +17,8 @@ declare namespace FG {
|
||||||
id: number;
|
id: number;
|
||||||
volume: number;
|
volume: number;
|
||||||
ingredient_id: number;
|
ingredient_id: number;
|
||||||
|
cost_per_volume: number;
|
||||||
|
name: string;
|
||||||
}
|
}
|
||||||
interface DrinkPrice {
|
interface DrinkPrice {
|
||||||
id: number;
|
id: number;
|
||||||
|
|
|
@ -196,6 +196,8 @@ export default defineComponent({
|
||||||
id: -1,
|
id: -1,
|
||||||
ingredient_id: newIngredient.value.id,
|
ingredient_id: newIngredient.value.id,
|
||||||
volume: newIngredientVolume.value,
|
volume: newIngredientVolume.value,
|
||||||
|
cost_per_volume: newIngredient.value.cost_per_volume,
|
||||||
|
name: newIngredient.value.name,
|
||||||
},
|
},
|
||||||
extra_ingredient: undefined,
|
extra_ingredient: undefined,
|
||||||
};
|
};
|
||||||
|
|
13
src/store.ts
13
src/store.ts
|
@ -1,6 +1,7 @@
|
||||||
import { api } from '@flaschengeist/api';
|
import { api } from '@flaschengeist/api';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { calc_volume, calc_cost_per_volume, calc_all_min_prices } from './utils/utils';
|
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'> {
|
interface DrinkPriceVolume extends Omit<FG.DrinkPriceVolume, 'volume'> {
|
||||||
_volume: number;
|
_volume: number;
|
||||||
|
@ -191,6 +192,18 @@ export const usePricelistStore = defineStore({
|
||||||
});
|
});
|
||||||
this.drinks[index] = _drink;
|
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);
|
calc_all_min_prices(this.drinks, this.min_prices);
|
||||||
},
|
},
|
||||||
deleteDrink(drink: Drink) {
|
deleteDrink(drink: Drink) {
|
||||||
|
|
|
@ -36,8 +36,9 @@ function helper(volume: DrinkPriceVolume, min_price: number) {
|
||||||
let extraIngredientPrice = 0;
|
let extraIngredientPrice = 0;
|
||||||
volume.ingredients.forEach((ingredient) => {
|
volume.ingredients.forEach((ingredient) => {
|
||||||
if (ingredient.drink_ingredient) {
|
if (ingredient.drink_ingredient) {
|
||||||
const _drink = usePricelistStore().drinks.find((a) => a.id === ingredient.drink_ingredient?.ingredient_id);
|
//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 * <number>(<unknown>_drink?.cost_per_volume);
|
||||||
|
retVal += ingredient.drink_ingredient.volume * ingredient.drink_ingredient.cost_per_volume
|
||||||
}
|
}
|
||||||
if (ingredient.extra_ingredient) {
|
if (ingredient.extra_ingredient) {
|
||||||
extraIngredientPrice += ingredient.extra_ingredient.price;
|
extraIngredientPrice += ingredient.extra_ingredient.price;
|
||||||
|
|
Loading…
Reference in New Issue