[fix] update minprices if cost_per_volume change
This commit is contained in:
parent
482c094511
commit
951fafd1fa
|
@ -192,6 +192,8 @@ export default defineComponent({
|
||||||
const edit_volumes = ref<Array<DrinkPriceVolume>>([]);
|
const edit_volumes = ref<Array<DrinkPriceVolume>>([]);
|
||||||
function save() {
|
function save() {
|
||||||
(<Drink>edit_drink.value).volumes = edit_volumes.value;
|
(<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);
|
emit('save', <Drink>edit_drink.value, toDeleteObjects.value, drinkPic.value, deletePic.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +274,7 @@ export default defineComponent({
|
||||||
return <string>imgsrc.value;
|
return <string>imgsrc.value;
|
||||||
}
|
}
|
||||||
if (edit_drink.value?.uuid) {
|
if (edit_drink.value?.uuid) {
|
||||||
return `${api.defaults.baseURL||''}/pricelist/picture/${edit_drink.value.uuid}?size=256`;
|
return `${api.defaults.baseURL || ''}/pricelist/picture/${edit_drink.value.uuid}?size=256`;
|
||||||
}
|
}
|
||||||
return 'no-image.svg';
|
return 'no-image.svg';
|
||||||
});
|
});
|
||||||
|
|
28
src/store.ts
28
src/store.ts
|
@ -107,11 +107,16 @@ export const usePricelistStore = defineStore({
|
||||||
if (itm.length > 0) itm[0].name = drinkType.name;
|
if (itm.length > 0) itm[0].name = drinkType.name;
|
||||||
},
|
},
|
||||||
async getExtraIngredients() {
|
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;
|
this.extraIngredients = data;
|
||||||
},
|
},
|
||||||
async setExtraIngredient(ingredient: FG.ExtraIngredient) {
|
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);
|
this.extraIngredients.push(data);
|
||||||
},
|
},
|
||||||
async updateExtraIngredient(ingredient: FG.ExtraIngredient) {
|
async updateExtraIngredient(ingredient: FG.ExtraIngredient) {
|
||||||
|
@ -196,13 +201,16 @@ export const usePricelistStore = defineStore({
|
||||||
this.drinks.forEach((_drink: Drink) => {
|
this.drinks.forEach((_drink: Drink) => {
|
||||||
_drink.volumes.forEach((_volume: DrinkPriceVolume) => {
|
_drink.volumes.forEach((_volume: DrinkPriceVolume) => {
|
||||||
_volume.ingredients.forEach((_ingredient: Ingredient) => {
|
_volume.ingredients.forEach((_ingredient: Ingredient) => {
|
||||||
if (_ingredient.drink_ingredient && _ingredient.drink_ingredient.ingredient_id === drink.id) {
|
if (
|
||||||
_ingredient.drink_ingredient.cost_per_volume = drink.cost_per_volume
|
_ingredient.drink_ingredient &&
|
||||||
_ingredient.drink_ingredient.name = drink.name
|
_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);
|
||||||
},
|
},
|
||||||
|
@ -281,7 +289,9 @@ export const usePricelistStore = defineStore({
|
||||||
this.pricelist_view = data;
|
this.pricelist_view = data;
|
||||||
},
|
},
|
||||||
async getPriceListColumnOrder(userid: string) {
|
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;
|
this.pricelist_columns_order = data;
|
||||||
},
|
},
|
||||||
async updatePriceListColumnOrder(userid: string, data: Array<Order>) {
|
async updatePriceListColumnOrder(userid: string, data: Array<Order>) {
|
||||||
|
|
|
@ -17,7 +17,8 @@ function calc_volume(volume: DrinkPriceVolume) {
|
||||||
function calc_cost_per_volume(drink: Drink) {
|
function calc_cost_per_volume(drink: Drink) {
|
||||||
let retVal = drink._cost_per_volume;
|
let retVal = drink._cost_per_volume;
|
||||||
if (!!drink.volume && !!drink.package_size && !!drink.cost_per_package) {
|
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;
|
return retVal ? Math.round(retVal * 1000) / 1000 : retVal;
|
||||||
|
@ -38,7 +39,7 @@ function helper(volume: DrinkPriceVolume, min_price: number) {
|
||||||
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
|
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;
|
||||||
|
@ -47,7 +48,11 @@ function helper(volume: DrinkPriceVolume, min_price: number) {
|
||||||
return (retVal * min_price) / 100 + extraIngredientPrice;
|
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> = [];
|
const retVal: Array<FG.MinPrices> = [];
|
||||||
volume.min_prices = [];
|
volume.min_prices = [];
|
||||||
if (min_prices) {
|
if (min_prices) {
|
||||||
|
|
Loading…
Reference in New Issue