[pricelist][fix] fixed issues from merge 3eea079871

This commit is contained in:
Tim Gröger 2021-04-02 14:06:03 +02:00
parent 7289a1724d
commit 5d1df48b9a
4 changed files with 35 additions and 30 deletions

View File

@ -273,10 +273,10 @@
/> />
</q-popup-edit> </q-popup-edit>
</q-td> </q-td>
<q-td key="cost_price_package_netto" :props="drinks_props"> <q-td key="cost_per_package" :props="drinks_props">
{{ {{
drinks_props.row.cost_price_package_netto drinks_props.row.cost_per_package
? `${drinks_props.row.cost_price_package_netto.toFixed(2)}` ? `${drinks_props.row.cost_per_package.toFixed(2)}`
: 'o.A.' : 'o.A.'
}} }}
<q-popup-edit <q-popup-edit
@ -286,7 +286,7 @@
) )
" "
v-slot="scope" v-slot="scope"
v-model="drinks_props.row.cost_price_package_netto" v-model="drinks_props.row.cost_per_package"
buttons buttons
label-cancel="Abbrechen" label-cancel="Abbrechen"
label-set="Speichern" label-set="Speichern"
@ -305,16 +305,16 @@
/> />
</q-popup-edit> </q-popup-edit>
</q-td> </q-td>
<q-td key="cost_price_pro_volume" :props="drinks_props"> <q-td key="cost_per_volume" :props="drinks_props">
{{ {{
drinks_props.row.cost_price_pro_volume drinks_props.row.cost_per_volume
? `${drinks_props.row.cost_price_pro_volume.toFixed(3)}` ? `${drinks_props.row.cost_per_volume.toFixed(3)}`
: 'o.A.' : 'o.A.'
}} }}
<q-popup-edit <q-popup-edit
v-if=" v-if="
!( !(
!!drinks_props.row.cost_price_package_netto && !!drinks_props.row.cost_per_package &&
!!drinks_props.row.volume && !!drinks_props.row.volume &&
!!drinks_props.row.package_size !!drinks_props.row.package_size
) && ) &&
@ -323,7 +323,7 @@
) )
" "
v-slot="scope" v-slot="scope"
v-model="drinks_props.row.cost_price_pro_volume" v-model="drinks_props.row.cost_per_volume"
buttons buttons
label-cancel="Abbrechen" label-cancel="Abbrechen"
label-set="Speichern" label-set="Speichern"
@ -467,17 +467,17 @@ export default defineComponent({
sort, sort,
}, },
{ {
name: 'cost_price_package_netto', name: 'cost_per_package',
label: 'Preis Netto/Gebinde', label: 'Preis Netto/Gebinde',
field: 'cost_price_package_netto', field: 'cost_per_package',
format: (val: number | null) => (val ? `${val.toFixed(3)}` : ''), format: (val: number | null) => (val ? `${val.toFixed(3)}` : ''),
sortable: true, sortable: true,
sort, sort,
}, },
{ {
name: 'cost_price_pro_volume', name: 'cost_per_volume',
label: 'Preis mit 19%/Liter', label: 'Preis mit 19%/Liter',
field: 'cost_price_pro_volume', field: 'cost_per_volume',
format: (val: number | null) => (val ? `${val.toFixed(3)}` : ''), format: (val: number | null) => (val ? `${val.toFixed(3)}` : ''),
sortable: true, sortable: true,
sort: (a: ComputedRef, b: ComputedRef) => sort(a.value, b.value), sort: (a: ComputedRef, b: ComputedRef) => sort(a.value, b.value),

View File

@ -210,8 +210,8 @@ export default defineComponent({
} }
const drinks = computed(() => const drinks = computed(() =>
store.drinks.filter((drink) => { store.drinks.filter((drink) => {
console.log('computed drinks', drink.name, drink.cost_price_pro_volume); console.log('computed drinks', drink.name, drink.cost_per_volume);
return drink.cost_price_pro_volume; return drink.cost_per_volume;
}) })
); );
const extra_ingredients = computed(() => store.extraIngredients); const extra_ingredients = computed(() => store.extraIngredients);

View File

@ -48,8 +48,7 @@ export default defineComponent({
(a) => a.id === ingredient.drink_ingredient?.ingredient_id (a) => a.id === ingredient.drink_ingredient?.ingredient_id
); );
retVal += retVal +=
ingredient.drink_ingredient.volume * ingredient.drink_ingredient.volume * <number>(<unknown>_drink?.cost_per_volume);
<number>(<unknown>_drink?.cost_price_pro_volume);
} }
if (ingredient.extra_ingredient) { if (ingredient.extra_ingredient) {
extraIngredientPrice += ingredient.extra_ingredient.price; extraIngredientPrice += ingredient.extra_ingredient.price;

View File

@ -13,10 +13,10 @@ interface DrinkPriceVolume extends Omit<Omit<FG.DrinkPriceVolume, 'volume'>, 'mi
min_prices: MinPrice[]; min_prices: MinPrice[];
} }
interface Drink extends Omit<Omit<FG.Drink, 'cost_price_pro_volume'>, 'volumes'> { interface Drink extends Omit<Omit<FG.Drink, 'cost_per_volume'>, 'volumes'> {
volumes: DrinkPriceVolume[]; volumes: DrinkPriceVolume[];
cost_price_pro_volume: WritableComputedRef<number | undefined>; cost_per_volume: WritableComputedRef<number | undefined>;
_cost_price_pro_volume?: number; _cost_per_volume?: number;
} }
class DrinkPriceVolume implements DrinkPriceVolume { class DrinkPriceVolume implements DrinkPriceVolume {
@ -66,18 +66,18 @@ class Drink {
this.name = name; this.name = name;
this.volume = volume; this.volume = volume;
this.cost_per_package = cost_per_package; this.cost_per_package = cost_per_package;
this.cost_per_volume = cost_per_volume; this._cost_per_volume = cost_per_volume;
this.cost_price_pro_volume = computed({ this.cost_per_volume = computed({
get: () => { get: () => {
if (!!this.volume && !!this.package_size && !!this.cost_per_package) { if (!!this.volume && !!this.package_size && !!this.cost_per_package) {
const retVal = const retVal =
((this.cost_per_package || 0) / ((this.volume || 0) * (this.package_size || 0))) * 1.19; ((this.cost_per_package || 0) / ((this.volume || 0) * (this.package_size || 0))) * 1.19;
this._cost_price_pro_volume = Math.round(retVal * 1000) / 1000; this._cost_per_volume = Math.round(retVal * 1000) / 1000;
} }
return this._cost_price_pro_volume; return this._cost_per_volume;
}, },
set: (val) => (this._cost_price_pro_volume = val), set: (val) => (this._cost_per_volume = val),
}); });
this.tags = tags; this.tags = tags;
this.type = type; this.type = type;
@ -208,7 +208,9 @@ export const usePricelistStore = defineStore({
.catch((err) => console.warn(err)); .catch((err) => console.warn(err));
}, },
async setDrink(drink: FG.Drink) { async setDrink(drink: FG.Drink) {
const { data } = await api.post<FG.Drink>('pricelist/drinks', drink); const { data } = await api.post<FG.Drink>('pricelist/drinks', {
...drink,
});
const _drink = new Drink(data); const _drink = new Drink(data);
data.volumes.forEach((volume) => { data.volumes.forEach((volume) => {
const _volume = new DrinkPriceVolume(volume); const _volume = new DrinkPriceVolume(volume);
@ -218,7 +220,11 @@ export const usePricelistStore = defineStore({
this.create_min_prices(); this.create_min_prices();
}, },
async updateDrink(drink: Drink) { async updateDrink(drink: Drink) {
const { data } = await api.put<FG.Drink>(`pricelist/drinks/${drink.id}`, drink); console.log(drink);
const { data } = await api.put<FG.Drink>(`pricelist/drinks/${drink.id}`, {
...drink,
cost_per_volume: drink._cost_per_volume,
});
const index = this.drinks.findIndex((a) => a.id === data.id); const index = this.drinks.findIndex((a) => a.id === data.id);
if (index > -1) { if (index > -1) {
const _drink = new Drink(data); const _drink = new Drink(data);
@ -273,10 +279,10 @@ export const usePricelistStore = defineStore({
volume.min_prices = []; volume.min_prices = [];
this.min_prices.forEach((min_price) => { this.min_prices.forEach((min_price) => {
let computedMinPrice: ComputedRef; let computedMinPrice: ComputedRef;
if (drink.cost_price_pro_volume) { if (drink.cost_per_volume) {
computedMinPrice = computed<number>( computedMinPrice = computed<number>(
() => () =>
(<number>(<unknown>drink.cost_price_pro_volume) * (<number>(<unknown>drink.cost_per_volume) *
<number>(<unknown>volume.volume) * <number>(<unknown>volume.volume) *
min_price) / min_price) /
100 100
@ -292,7 +298,7 @@ export const usePricelistStore = defineStore({
); );
retVal += retVal +=
ingredient.drink_ingredient.volume * ingredient.drink_ingredient.volume *
<number>(<unknown>_drink?.cost_price_pro_volume); <number>(<unknown>_drink?.cost_per_volume);
} }
if (ingredient.extra_ingredient) { if (ingredient.extra_ingredient) {
extraIngredientPrice += ingredient.extra_ingredient.price; extraIngredientPrice += ingredient.extra_ingredient.price;