[fix] update minprices if cost_per_volume change

This commit is contained in:
Tim Gröger 2021-11-12 10:42:52 +01:00
parent 482c094511
commit 951fafd1fa
3 changed files with 30 additions and 13 deletions

View File

@ -192,6 +192,8 @@ export default defineComponent({
const edit_volumes = ref<Array<DrinkPriceVolume>>([]);
function save() {
(<Drink>edit_drink.value).volumes = edit_volumes.value;
edit_drink.value.cost_per_volume = calc_cost_per_volume(edit_drink.value);
edit_drink.value._cost_per_volume = edit_drink.value.cost_per_volume;
emit('save', <Drink>edit_drink.value, toDeleteObjects.value, drinkPic.value, deletePic.value);
}

View File

@ -107,11 +107,16 @@ export const usePricelistStore = defineStore({
if (itm.length > 0) itm[0].name = drinkType.name;
},
async getExtraIngredients() {
const { data } = await api.get<Array<FG.ExtraIngredient>>('pricelist/ingredients/extraIngredients');
const { data } = await api.get<Array<FG.ExtraIngredient>>(
'pricelist/ingredients/extraIngredients'
);
this.extraIngredients = data;
},
async setExtraIngredient(ingredient: FG.ExtraIngredient) {
const { data } = await api.post<FG.ExtraIngredient>('pricelist/ingredients/extraIngredients', ingredient);
const { data } = await api.post<FG.ExtraIngredient>(
'pricelist/ingredients/extraIngredients',
ingredient
);
this.extraIngredients.push(data);
},
async updateExtraIngredient(ingredient: FG.ExtraIngredient) {
@ -196,13 +201,16 @@ export const usePricelistStore = defineStore({
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
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);
},
@ -281,7 +289,9 @@ export const usePricelistStore = defineStore({
this.pricelist_view = data;
},
async getPriceListColumnOrder(userid: string) {
const { data } = await api.get<Array<Order>>(`pricelist/users/${userid}/pricecalc_columns_order`);
const { data } = await api.get<Array<Order>>(
`pricelist/users/${userid}/pricecalc_columns_order`
);
this.pricelist_columns_order = data;
},
async updatePriceListColumnOrder(userid: string, data: Array<Order>) {

View File

@ -17,7 +17,8 @@ function calc_volume(volume: DrinkPriceVolume) {
function calc_cost_per_volume(drink: Drink) {
let retVal = drink._cost_per_volume;
if (!!drink.volume && !!drink.package_size && !!drink.cost_per_package) {
retVal = ((drink.cost_per_package || 0) / ((drink.volume || 0) * (drink.package_size || 0))) * 1.19;
retVal =
((drink.cost_per_package || 0) / ((drink.volume || 0) * (drink.package_size || 0))) * 1.19;
}
return retVal ? Math.round(retVal * 1000) / 1000 : retVal;
@ -38,7 +39,7 @@ function helper(volume: DrinkPriceVolume, min_price: number) {
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);
retVal += ingredient.drink_ingredient.volume * ingredient.drink_ingredient.cost_per_volume
retVal += ingredient.drink_ingredient.volume * ingredient.drink_ingredient.cost_per_volume;
}
if (ingredient.extra_ingredient) {
extraIngredientPrice += ingredient.extra_ingredient.price;
@ -47,7 +48,11 @@ function helper(volume: DrinkPriceVolume, min_price: number) {
return (retVal * min_price) / 100 + extraIngredientPrice;
}
function calc_min_prices(volume: DrinkPriceVolume, cost_per_volume: number | undefined, min_prices: Array<number>) {
function calc_min_prices(
volume: DrinkPriceVolume,
cost_per_volume: number | undefined,
min_prices: Array<number>
) {
const retVal: Array<FG.MinPrices> = [];
volume.min_prices = [];
if (min_prices) {