Compare commits

...

4 Commits

Author SHA1 Message Date
Tim Gröger ad7ab825c8 [fix] delete picture of drink 2021-11-12 12:01:31 +01:00
Tim Gröger 023127f8be [cleanup] cleanup style 2021-11-12 10:44:18 +01:00
Tim Gröger 951fafd1fa [fix] update minprices if cost_per_volume change 2021-11-12 10:42:52 +01:00
Tim Gröger 482c094511 better drinks dependencies #2
drink_ingredients has name and cost_per_volume
2021-06-30 10:42:42 +02:00
11 changed files with 64 additions and 23 deletions

View File

@ -17,11 +17,11 @@ module.exports = {
project: resolve(__dirname, './tsconfig.json'),
tsconfigRootDir: __dirname,
ecmaVersion: 2019, // Allows for the parsing of modern ECMAScript features
sourceType: 'module' // Allows for the use of imports
sourceType: 'module', // Allows for the use of imports
},
env: {
browser: true
browser: true,
},
// Rules order is important, please avoid shuffling them
@ -70,6 +70,6 @@ module.exports = {
'@typescript-eslint/explicit-module-boundary-types': 'off',
// allow debugger during development only
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
},
};

View File

@ -15,7 +15,7 @@
"main": "src/index.ts",
"types": "src/api.d.ts",
"scripts": {
"format": "prettier --config ./package.json --write '{,!(node_modules)/**/}*.ts'",
"format": "prettier --config ./package.json --write '{,!(node_modules)/**/}*.{ts,vue,js}'",
"lint": "eslint --ext .js,.ts,.vue ./src"
},
"dependencies": {
@ -42,7 +42,7 @@
"prettier": {
"singleQuote": true,
"semi": true,
"printWidth": 120,
"printWidth": 100,
"arrowParens": "always"
}
}

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

@ -5,6 +5,7 @@
:columns="columns"
:rows="drinks"
dense
row-key="id"
:filter="search"
:filter-method="filter"
grid
@ -55,7 +56,7 @@
</div>
</div>
<template #error>
<q-img class="bg-white" style="max-height: 256px" src='no-image.svg' />
<q-img class="bg-white" style="max-height: 256px" src="no-image.svg" />
<div
v-if="!public && !nodetails && editable"
class="absolute-top-right justify-end"
@ -460,6 +461,9 @@ export default defineComponent({
for (const volume of toDeleteObjects.volumes) {
await store.deleteVolume(volume, drink);
}
if (deletePic) {
await deletePicture();
}
if (drink.id > 0) {
await store.updateDrink(drink);
} else {
@ -468,9 +472,6 @@ export default defineComponent({
editDrink.value.id = _drink.id;
}
}
if (deletePic) {
await deletePicture();
}
if (drinkPic instanceof File) {
await savePicture(drinkPic);
}
@ -495,7 +496,7 @@ export default defineComponent({
function image(uuid: string | undefined) {
if (uuid) {
return `${api.defaults.baseURL||''}/pricelist/picture/${uuid}?size=256`;
return `${api.defaults.baseURL || ''}/pricelist/picture/${uuid}?size=256`;
}
return 'no-image.svg';
}

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

@ -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);
}
@ -272,7 +274,7 @@ export default defineComponent({
return <string>imgsrc.value;
}
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';
});

View File

@ -27,7 +27,7 @@
options-cover
/>
<q-btn round icon="mdi-backburger">
<q-tooltip anchor='top middle' self='bottom middle'> Reihenfolge ändern </q-tooltip>
<q-tooltip anchor="top middle" self="bottom middle"> Reihenfolge ändern </q-tooltip>
<q-menu anchor="bottom middle" self="top middle">
<drag v-model="order" class="q-list" ghost-class="ghost" group="people" item-key="id">
<template #item="{ element }">

View File

@ -157,7 +157,7 @@ export default defineComponent({
const search_keys = computed(() => columns_drinks.filter((column) => column.filterable));
function image(uuid: string | undefined) {
if (uuid) {
return `${api.defaults.baseURL||''}/pricelist/picture/${uuid}?size=256`;
return `${api.defaults.baseURL || ''}/pricelist/picture/${uuid}?size=256`;
}
return 'no-image.svg';
}

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;
@ -106,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) {
@ -191,6 +197,21 @@ 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) {
@ -268,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

@ -1,6 +1,11 @@
import { Drink } from '../store';
function filter(rows: Array<Drink>, terms: Search, cols: Array<Col>, cellValue: { (col: Col, row: Drink): string }) {
function filter(
rows: Array<Drink>,
terms: Search,
cols: Array<Col>,
cellValue: { (col: Col, row: Drink): string }
) {
if (terms.value) {
return rows.filter((row) => {
if (!terms.key || terms.key === '') {

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;
@ -36,8 +37,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;
@ -46,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) {