Added correct definitions file
This commit is contained in:
parent
20191be5dc
commit
caa09a3c2c
|
@ -15,7 +15,7 @@ declare namespace FG {
|
|||
mail: string;
|
||||
birthday?: Date;
|
||||
roles: Array<string>;
|
||||
permissions?: string[];
|
||||
permissions?: Array<string>;
|
||||
avatar_url?: string;
|
||||
}
|
||||
type Permission = string;
|
||||
|
@ -29,9 +29,9 @@ declare namespace FG {
|
|||
time: Date;
|
||||
amount: number;
|
||||
reversal_id: number;
|
||||
sender_id?: number;
|
||||
receiver_id?: number;
|
||||
author_id?: number;
|
||||
sender_id?: string;
|
||||
receiver_id?: string;
|
||||
author_id?: string;
|
||||
original_id?: number;
|
||||
}
|
||||
interface Drink {
|
||||
|
@ -43,32 +43,26 @@ declare namespace FG {
|
|||
cost_price_pro_volume?: number;
|
||||
cost_price_package_netto?: number;
|
||||
tags: Array<Tag>;
|
||||
type?: DrinkType;
|
||||
volumes: DrinkPriceVolume[];
|
||||
type: DrinkType;
|
||||
volumes: Array<DrinkPriceVolume>;
|
||||
}
|
||||
interface DrinkIngredient {
|
||||
id: number;
|
||||
volume: number;
|
||||
drink_ingredient?: Drink;
|
||||
drink_ingredient_id: number;
|
||||
price: number;
|
||||
}
|
||||
interface DrinkPrice {
|
||||
id: number;
|
||||
price: number;
|
||||
public: boolean;
|
||||
public: bool;
|
||||
description?: string;
|
||||
}
|
||||
interface DrinkMinPrice {
|
||||
percentage: number;
|
||||
//price: ComputedRef<number>;
|
||||
price: number;
|
||||
}
|
||||
interface DrinkPriceVolume {
|
||||
id: number;
|
||||
volume: number;
|
||||
//computed_volume: ComputedRef<number>;
|
||||
min_prices: DrinkMinPrice[];
|
||||
ingredients: Array<DrinkIngredient | ExtraIngredient>;
|
||||
prices: Array<DrinkPrice>;
|
||||
ingredients: Array<Ingredient>;
|
||||
}
|
||||
interface DrinkType {
|
||||
id: number;
|
||||
|
@ -81,8 +75,9 @@ declare namespace FG {
|
|||
}
|
||||
interface Ingredient {
|
||||
id: number;
|
||||
drink_ingredient: DrinkIngredient | null;
|
||||
extra_ingredient: ExtraIngredient | null;
|
||||
volume_id: number;
|
||||
drink_ingredient: DrinkIngredient;
|
||||
extra_ingredient: ExtraIngredient;
|
||||
}
|
||||
interface Tag {
|
||||
id: number;
|
||||
|
|
|
@ -11,7 +11,7 @@ const plugin: FG_Plugin.Plugin = {
|
|||
requiredBackendModules: ['pricelist'],
|
||||
version: '0.0.1',
|
||||
store: new Map<string, Module<DrinkInterface, StateInterface>>([['drink', drink]]),
|
||||
widgets: []
|
||||
widgets: [],
|
||||
// widgets: [
|
||||
// {
|
||||
// priority: 1,
|
||||
|
|
|
@ -15,7 +15,7 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
|
|||
name: 'drinks-pricelist',
|
||||
shortcut: true,
|
||||
meta: { permissions: ['user'] },
|
||||
component: () => import('../pages/Pricelist.vue')
|
||||
component: () => import('../pages/Pricelist.vue'),
|
||||
},
|
||||
{
|
||||
title: 'Einstellungen',
|
||||
|
@ -24,10 +24,10 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
|
|||
name: 'drinks-settings',
|
||||
shortcut: false,
|
||||
meta: { permissions: ['users_edit_other'] },
|
||||
component: () => import('../pages/Settings.vue')
|
||||
}
|
||||
]
|
||||
}
|
||||
component: () => import('../pages/Settings.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default mainRoutes;
|
||||
|
|
|
@ -11,7 +11,7 @@ const state = reactive<{
|
|||
drinks: [],
|
||||
tags: [],
|
||||
drinkTypes: [],
|
||||
extraIngredients: []
|
||||
extraIngredients: [],
|
||||
});
|
||||
|
||||
interface MinPrice extends Omit<FG.DrinkMinPrice, 'price'> {
|
||||
|
@ -37,22 +37,22 @@ class DrinkPriceVolume {
|
|||
this.min_prices = [
|
||||
{
|
||||
percentage: 100,
|
||||
price: create_min_prices(drink, this, 100)
|
||||
price: create_min_prices(drink, this, 100),
|
||||
},
|
||||
{
|
||||
percentage: 250,
|
||||
price: create_min_prices(drink, this, 250)
|
||||
price: create_min_prices(drink, this, 250),
|
||||
},
|
||||
{
|
||||
percentage: 300,
|
||||
price: create_min_prices(drink, this, 300)
|
||||
}
|
||||
price: create_min_prices(drink, this, 300),
|
||||
},
|
||||
];
|
||||
this.volume = computed<number>({
|
||||
get: () => {
|
||||
if (this.ingredients.some(ingredient => !!ingredient.drink_ingredient)) {
|
||||
if (this.ingredients.some((ingredient) => !!ingredient.drink_ingredient)) {
|
||||
let retVal = 0;
|
||||
this.ingredients.forEach(ingredient => {
|
||||
this.ingredients.forEach((ingredient) => {
|
||||
if (ingredient.drink_ingredient?.volume) {
|
||||
retVal += ingredient.drink_ingredient.volume;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class DrinkPriceVolume {
|
|||
return this._volume;
|
||||
}
|
||||
},
|
||||
set: val => (this._volume = val)
|
||||
set: (val) => (this._volume = val),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Drink {
|
|||
cost_price_package_netto,
|
||||
tags,
|
||||
type,
|
||||
volumes
|
||||
volumes,
|
||||
}: FG.Drink) {
|
||||
this.id = id;
|
||||
this.article_id = article_id;
|
||||
|
@ -100,7 +100,7 @@ class Drink {
|
|||
|
||||
return this._cost_price_pro_volume;
|
||||
},
|
||||
set: val => (this._cost_price_pro_volume = val)
|
||||
set: (val) => (this._cost_price_pro_volume = val),
|
||||
});
|
||||
this.tags = tags;
|
||||
this.type = type;
|
||||
|
@ -117,17 +117,17 @@ const actions = {
|
|||
.get('pricelist/drinks')
|
||||
.then((response: AxiosResponse<FG.Drink[]>) => {
|
||||
state.drinks = [];
|
||||
response.data.forEach(drink => {
|
||||
response.data.forEach((drink) => {
|
||||
state.drinks.push(new Drink(drink));
|
||||
});
|
||||
state.drinks.forEach(drink => {
|
||||
const _drink = response.data.find(a => a.id === drink.id);
|
||||
_drink?.volumes.forEach(volume => {
|
||||
state.drinks.forEach((drink) => {
|
||||
const _drink = response.data.find((a) => a.id === drink.id);
|
||||
_drink?.volumes.forEach((volume) => {
|
||||
drink.volumes.push(new DrinkPriceVolume(volume, drink));
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
setPrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) {
|
||||
axios
|
||||
|
@ -136,7 +136,7 @@ const actions = {
|
|||
volume.prices.push(response.data);
|
||||
this.sortPrices(volume);
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
sortPrices(volume: DrinkPriceVolume) {
|
||||
volume.prices.sort((a, b) => {
|
||||
|
@ -149,48 +149,54 @@ 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: DrinkPriceVolume) {
|
||||
axios
|
||||
.put(`pricelist/prices/${price.id}`, price)
|
||||
.then((response: AxiosResponse<FG.DrinkPrice>) => {
|
||||
const index = volume.prices.findIndex(a => a.id === price.id);
|
||||
const index = volume.prices.findIndex((a) => a.id === price.id);
|
||||
if (index > -1) {
|
||||
this.sortPrices(volume);
|
||||
}
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
setVolume(volume: DrinkPriceVolume, drink: Drink) {
|
||||
console.log(volume);
|
||||
axios
|
||||
.post(`pricelist/drinks/${drink.id}/volumes`, { ...volume, volume: volume.volume })
|
||||
.post(`pricelist/drinks/${drink.id}/volumes`, {
|
||||
...volume,
|
||||
volume: volume.volume,
|
||||
})
|
||||
.then((response: AxiosResponse<FG.DrinkPriceVolume>) => {
|
||||
drink.volumes.push(new DrinkPriceVolume(response.data, drink));
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
updateVolume(volume: DrinkPriceVolume, drink: Drink) {
|
||||
axios
|
||||
.put(`pricelist/volumes/${volume.id}`, { ...volume, volume: volume.volume?.value })
|
||||
.catch(err => console.warn(err));
|
||||
.put(`pricelist/volumes/${volume.id}`, {
|
||||
...volume,
|
||||
volume: volume.volume?.value,
|
||||
})
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
deleteVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) {
|
||||
axios
|
||||
.delete(`pricelist/volumes/${volume.id}`)
|
||||
.then(() => {
|
||||
const index = drink.volumes.findIndex(a => a.id === volume.id);
|
||||
const index = drink.volumes.findIndex((a) => a.id === volume.id);
|
||||
if (index > -1) {
|
||||
drink.volumes.splice(index, 1);
|
||||
}
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
getExtraIngredients() {
|
||||
axios
|
||||
|
@ -198,7 +204,7 @@ const actions = {
|
|||
.then((response: AxiosResponse<FG.ExtraIngredient[]>) => {
|
||||
state.extraIngredients = response.data;
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
setIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
|
||||
axios
|
||||
|
@ -206,29 +212,29 @@ const actions = {
|
|||
.then((response: AxiosResponse<FG.Ingredient>) => {
|
||||
volume.ingredients.push(response.data);
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
updateIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
|
||||
axios
|
||||
.put(`pricelist/ingredients/${ingredient.id}`, ingredient)
|
||||
.then((response: AxiosResponse<FG.Ingredient>) => {
|
||||
const index = volume.ingredients.findIndex(a => a.id === response.data.id);
|
||||
const index = volume.ingredients.findIndex((a) => a.id === response.data.id);
|
||||
if (index > -1) {
|
||||
volume.ingredients[index] = response.data;
|
||||
}
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
deleteIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
|
||||
axios
|
||||
.delete(`pricelist/ingredients/${ingredient.id}`)
|
||||
.then(() => {
|
||||
const index = volume.ingredients.findIndex(a => a.id === ingredient.id);
|
||||
const index = volume.ingredients.findIndex((a) => a.id === ingredient.id);
|
||||
if (index > -1) {
|
||||
volume.ingredients.splice(index, 1);
|
||||
}
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
getDrinkTypes() {
|
||||
axios
|
||||
|
@ -236,38 +242,38 @@ const actions = {
|
|||
.then((response: AxiosResponse<FG.DrinkType[]>) => {
|
||||
state.drinkTypes = response.data;
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
setDrink(drink: FG.Drink) {
|
||||
axios
|
||||
.post('pricelist/drinks', drink)
|
||||
.then((response: AxiosResponse<FG.Drink>) => {
|
||||
state.drinks.push(new Drink(response.data));
|
||||
const drink = state.drinks.find(a => a.id === response.data.id);
|
||||
response.data.volumes.forEach(volume => {
|
||||
const drink = state.drinks.find((a) => a.id === response.data.id);
|
||||
response.data.volumes.forEach((volume) => {
|
||||
drink?.volumes.push(new DrinkPriceVolume(volume, drink));
|
||||
});
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
updateDrink(drink: Drink) {
|
||||
axios
|
||||
.put(`pricelist/drinks/${drink.id}`, {
|
||||
...drink,
|
||||
cost_price_pro_volume: drink.cost_price_pro_volume?.value
|
||||
cost_price_pro_volume: drink.cost_price_pro_volume?.value,
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
deleteDrink(drink: Drink) {
|
||||
axios
|
||||
.delete(`pricelist/drinks/${drink.id}`)
|
||||
.then(() => {
|
||||
const index = state.drinks.findIndex(a => a.id === drink.id);
|
||||
const index = state.drinks.findIndex((a) => a.id === drink.id);
|
||||
if (index > -1) {
|
||||
state.drinks.splice(index, 1);
|
||||
}
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
setExtraIngredient(ingredient: FG.ExtraIngredient) {
|
||||
axios
|
||||
|
@ -275,42 +281,42 @@ const actions = {
|
|||
.then((response: AxiosResponse<FG.ExtraIngredient>) => {
|
||||
state.extraIngredients.push(response.data);
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
updateExtraIngredient(ingredient: FG.ExtraIngredient) {
|
||||
axios
|
||||
.put(`pricelist/ingredients/extraIngredients/${ingredient.id}`, ingredient)
|
||||
.then((response: AxiosResponse<FG.ExtraIngredient>) => {
|
||||
const index = state.extraIngredients.findIndex(a => a.id === ingredient.id);
|
||||
const index = state.extraIngredients.findIndex((a) => a.id === ingredient.id);
|
||||
if (index > -1) {
|
||||
state.extraIngredients[index] = response.data;
|
||||
} else {
|
||||
state.extraIngredients.push(response.data);
|
||||
}
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
deleteExtraIngredient(ingredient: FG.ExtraIngredient) {
|
||||
axios
|
||||
.delete(`pricelist/ingredients/extraIngredients/${ingredient.id}`)
|
||||
.then(() => {
|
||||
const index = state.extraIngredients.findIndex(a => a.id === ingredient.id);
|
||||
const index = state.extraIngredients.findIndex((a) => a.id === ingredient.id);
|
||||
if (index > -1) {
|
||||
state.extraIngredients.splice(index, 1);
|
||||
}
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
}
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
};
|
||||
|
||||
const getters = {};
|
||||
|
||||
function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: number) {
|
||||
if (drink.cost_price_pro_volume?.value) {
|
||||
if (volume.ingredients.every(ingredient => !!ingredient.drink_ingredient)) {
|
||||
if (volume.ingredients.every((ingredient) => !!ingredient.drink_ingredient)) {
|
||||
return computed<number>(() => {
|
||||
let retVal = (drink.cost_price_pro_volume?.value || 0) * (volume.volume?.value || 0);
|
||||
volume.ingredients.forEach(ingredient => {
|
||||
volume.ingredients.forEach((ingredient) => {
|
||||
if (ingredient.extra_ingredient) {
|
||||
retVal += ingredient.extra_ingredient.price;
|
||||
}
|
||||
|
@ -328,10 +334,10 @@ function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: n
|
|||
} else {
|
||||
return computed<number>(() => {
|
||||
let retVal = 0;
|
||||
volume.ingredients.forEach(ingredient => {
|
||||
volume.ingredients.forEach((ingredient) => {
|
||||
if (ingredient.drink_ingredient) {
|
||||
const _drink = state.drinks.find(
|
||||
a => a.id === ingredient.drink_ingredient?.drink_ingredient?.id
|
||||
(a) => a.id === ingredient.drink_ingredient?.drink_ingredient?.id
|
||||
);
|
||||
retVal += ingredient.drink_ingredient.volume * (_drink?.cost_price_pro_volume.value || 0);
|
||||
}
|
||||
|
@ -348,5 +354,5 @@ export { create_min_prices, DrinkPriceVolume, MinPrice, Drink };
|
|||
export default {
|
||||
state,
|
||||
actions,
|
||||
getters
|
||||
getters,
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ export interface DrinkInterface {
|
|||
|
||||
const state: DrinkInterface = {
|
||||
drinkTypes: [],
|
||||
drinks: []
|
||||
drinks: [],
|
||||
};
|
||||
|
||||
const mutations: MutationTree<DrinkInterface> = {
|
||||
|
@ -18,7 +18,7 @@ const mutations: MutationTree<DrinkInterface> = {
|
|||
state.drinkTypes = drinkTypes;
|
||||
},
|
||||
setDrinkType(state, drinkType: FG.DrinkType) {
|
||||
const item = state.drinkTypes.find(item => item.id == drinkType.id);
|
||||
const item = state.drinkTypes.find((item) => item.id == drinkType.id);
|
||||
if (item) {
|
||||
item.name = drinkType.name;
|
||||
}
|
||||
|
@ -27,20 +27,20 @@ const mutations: MutationTree<DrinkInterface> = {
|
|||
state.drinkTypes.unshift(drinkType);
|
||||
},
|
||||
removeDrinkType(state, id: number) {
|
||||
const index = state.drinkTypes.findIndex(item => item.id == id);
|
||||
const index = state.drinkTypes.findIndex((item) => item.id == id);
|
||||
state.drinkTypes.splice(index, 1);
|
||||
},
|
||||
setDrinks(state, drinks: FG.Drink[]) {
|
||||
state.drinks = drinks
|
||||
state.drinks = drinks;
|
||||
},
|
||||
setDrink(state, drink: FG.Drink) {
|
||||
const index = state.drinks.findIndex(item => item.id = drink.id)
|
||||
const index = state.drinks.findIndex((item) => (item.id = drink.id));
|
||||
if (index) {
|
||||
state.drinks[index] = drink
|
||||
state.drinks[index] = drink;
|
||||
} else {
|
||||
state.drinks.push(drink)
|
||||
}
|
||||
state.drinks.push(drink);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const actions: ActionTree<DrinkInterface, StateInterface> = {
|
||||
|
@ -50,7 +50,7 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
|
|||
.then((response: AxiosResponse<FG.DrinkType[]>) => {
|
||||
commit('setDrinkTypes', response.data);
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
addDrinkType({ commit }, data) {
|
||||
axios
|
||||
|
@ -58,7 +58,7 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
|
|||
.then((response: AxiosResponse<FG.DrinkType>) => {
|
||||
commit('addDrinkType', response.data);
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
console.warn(err);
|
||||
});
|
||||
},
|
||||
|
@ -68,7 +68,7 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
|
|||
.then(() => {
|
||||
commit('removeDrinkType', data);
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
changeDrinkTypeName({ commit }, drinkType: FG.DrinkType) {
|
||||
axios
|
||||
|
@ -76,22 +76,24 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
|
|||
.then(() => {
|
||||
commit('setDrinkType', drinkType);
|
||||
})
|
||||
.catch(err => console.warn(err));
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
getDrinks({commit}) {
|
||||
axios.get('/pricelist/drinks')
|
||||
getDrinks({ commit }) {
|
||||
axios
|
||||
.get('/pricelist/drinks')
|
||||
.then((response: AxiosResponse<FG.Drink[]>) => {
|
||||
commit('setDrinks', response.data)
|
||||
commit('setDrinks', response.data);
|
||||
})
|
||||
.catch(err => console.warn(err))
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
createDrink({commit}, data) {
|
||||
axios.post('/pricelist/drinks', data)
|
||||
createDrink({ commit }, data) {
|
||||
axios
|
||||
.post('/pricelist/drinks', data)
|
||||
.then((response: AxiosResponse<FG.Drink>) => {
|
||||
commit('setDrink', response.data)
|
||||
commit('setDrink', response.data);
|
||||
})
|
||||
.catch(err => console.warn(err))
|
||||
}
|
||||
.catch((err) => console.warn(err));
|
||||
},
|
||||
};
|
||||
const getters: GetterTree<DrinkInterface, StateInterface> = {};
|
||||
|
||||
|
@ -100,7 +102,7 @@ const schedule: Module<DrinkInterface, StateInterface> = {
|
|||
state,
|
||||
mutations,
|
||||
actions,
|
||||
getters
|
||||
getters,
|
||||
};
|
||||
|
||||
export default schedule;
|
||||
|
|
Loading…
Reference in New Issue