Compare commits
	
		
			No commits in common. "7f33a44d94b792cfb88dd500f11e74eab95dc705" and "f5c6bcff6f482a3fc919ab7cb359e5098b0a4496" have entirely different histories.
		
	
	
		
			7f33a44d94
			...
			f5c6bcff6f
		
	
		| 
						 | 
				
			
			@ -23,13 +23,11 @@ declare namespace FG {
 | 
			
		|||
  interface DrinkPrice {
 | 
			
		||||
    id: number;
 | 
			
		||||
    price: number;
 | 
			
		||||
    volume: Array<DrinkPriceVolume>;
 | 
			
		||||
    public: boolean;
 | 
			
		||||
    description?: string;
 | 
			
		||||
  }
 | 
			
		||||
  interface DrinkPriceVolume {
 | 
			
		||||
    id: number;
 | 
			
		||||
    drink: Array<Drink>;
 | 
			
		||||
    volume: number;
 | 
			
		||||
    min_prices: Array<MinPrices>;
 | 
			
		||||
    prices: Array<DrinkPrice>;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -169,7 +169,7 @@
 | 
			
		|||
 | 
			
		||||
<script lang="ts">
 | 
			
		||||
import DrinkPriceVolumes from '../components/CalculationTable/DrinkPriceVolumes.vue';
 | 
			
		||||
import { defineComponent, onBeforeMount, ComputedRef, computed, ref } from 'vue';
 | 
			
		||||
import { defineComponent, onMounted, ComputedRef, computed, ref } from 'vue';
 | 
			
		||||
import { Drink, usePricelistStore, DrinkPriceVolume } from '../store';
 | 
			
		||||
import MinPriceSetting from '../components/MinPriceSetting.vue';
 | 
			
		||||
import { api, hasPermission } from '@flaschengeist/api';
 | 
			
		||||
| 
						 | 
				
			
			@ -206,7 +206,7 @@ export default defineComponent({
 | 
			
		|||
  setup(props) {
 | 
			
		||||
    const store = usePricelistStore();
 | 
			
		||||
 | 
			
		||||
    onBeforeMount(() => {
 | 
			
		||||
    onMounted(() => {
 | 
			
		||||
      //void store.getDrinks();
 | 
			
		||||
      onRequest({
 | 
			
		||||
        pagination: pagination.value,
 | 
			
		||||
| 
						 | 
				
			
			@ -404,17 +404,16 @@ export default defineComponent({
 | 
			
		|||
          offset: startRow,
 | 
			
		||||
          limit: fetchCount,
 | 
			
		||||
          descending,
 | 
			
		||||
          search_name: props.filter?.value,
 | 
			
		||||
          search_key: props.filter?.key,
 | 
			
		||||
          search_name: props.filter.value,
 | 
			
		||||
          search_key: props.filter.key,
 | 
			
		||||
        });
 | 
			
		||||
        pagination.value.page = page;
 | 
			
		||||
        pagination.value.rowsPerPage = rowsPerPage;
 | 
			
		||||
        pagination.value.sortBy = sortBy;
 | 
			
		||||
        pagination.value.descending = descending;
 | 
			
		||||
        console.log('result', result.count);
 | 
			
		||||
        if (result.count) pagination.value.rowsNumber = result.count;
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.warn(error);
 | 
			
		||||
        //..
 | 
			
		||||
      }
 | 
			
		||||
      loading.value = false;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,7 +43,7 @@
 | 
			
		|||
      </div>
 | 
			
		||||
      <div class="q-pa-sm">
 | 
			
		||||
        <div v-for="(price, index) in volume.prices" :key="price.id">
 | 
			
		||||
          <div v-if="isPublic(price, volume)" class="fit row justify-around q-py-sm">
 | 
			
		||||
          <div class="fit row justify-around q-py-sm">
 | 
			
		||||
            <div
 | 
			
		||||
              v-if="!editable || !hasPermission(PERMISSIONS.EDIT_PRICE)"
 | 
			
		||||
              class="text-body1 col-3"
 | 
			
		||||
| 
						 | 
				
			
			@ -294,15 +294,6 @@ export default defineComponent({
 | 
			
		|||
      emit('update:modelValue', volumes.value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function isPublic(price: FG.DrinkPrice, drink) {
 | 
			
		||||
      console.log('drink', drink);
 | 
			
		||||
      if (props.public) {
 | 
			
		||||
        console.log(price);
 | 
			
		||||
        return price.public;
 | 
			
		||||
      }
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const isUnderMinPrice = computed(() => {
 | 
			
		||||
      if (volumes.value) {
 | 
			
		||||
        const this_volume = volumes.value.find((a) => a.id === volume.value);
 | 
			
		||||
| 
						 | 
				
			
			@ -337,7 +328,6 @@ export default defineComponent({
 | 
			
		|||
      isUnderMinPrice,
 | 
			
		||||
      hasPermission,
 | 
			
		||||
      PERMISSIONS,
 | 
			
		||||
      isPublic,
 | 
			
		||||
    };
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,13 +5,11 @@
 | 
			
		|||
    :rows="drinks"
 | 
			
		||||
    :visible-columns="visibleColumns"
 | 
			
		||||
    :filter="search"
 | 
			
		||||
    :filter-method="filter"
 | 
			
		||||
    dense
 | 
			
		||||
    v-model:pagination="pagination"
 | 
			
		||||
    :pagination="pagination"
 | 
			
		||||
    :fullscreen="fullscreen"
 | 
			
		||||
    @request="onRequest"
 | 
			
		||||
  >
 | 
			
		||||
    <!--
 | 
			
		||||
    :filter-method="filter"-->
 | 
			
		||||
    <template #top-right>
 | 
			
		||||
      <div class="row justify-end q-gutter-sm">
 | 
			
		||||
        <search-input v-model="search" :keys="options" />
 | 
			
		||||
| 
						 | 
				
			
			@ -111,11 +109,11 @@ export default defineComponent({
 | 
			
		|||
      if (!props.public) {
 | 
			
		||||
        user.value = useMainStore().currentUser.userid;
 | 
			
		||||
        void store.getPriceListColumnOrder(user.value);
 | 
			
		||||
        void store.getDrinks();
 | 
			
		||||
        void store.getPriceCalcColumn(user.value);
 | 
			
		||||
      } else {
 | 
			
		||||
        user.value = '';
 | 
			
		||||
      }
 | 
			
		||||
      onRequest({ pagination: pagination.value, filter: { limit: 10 } });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const _order = ref<Array<Order>>([
 | 
			
		||||
| 
						 | 
				
			
			@ -172,9 +170,7 @@ export default defineComponent({
 | 
			
		|||
      {
 | 
			
		||||
        name: 'name',
 | 
			
		||||
        label: 'Name',
 | 
			
		||||
        //field: 'name',
 | 
			
		||||
        field: 'volume',
 | 
			
		||||
        format: (val: FG.DrinkPriceVolume) => val.drink.name,
 | 
			
		||||
        field: 'name',
 | 
			
		||||
        sortable: true,
 | 
			
		||||
        filterable: true,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
| 
						 | 
				
			
			@ -182,22 +178,20 @@ export default defineComponent({
 | 
			
		|||
      {
 | 
			
		||||
        name: 'type',
 | 
			
		||||
        label: 'Kategorie',
 | 
			
		||||
        //field: 'type',
 | 
			
		||||
        field: 'volume',
 | 
			
		||||
        field: 'type',
 | 
			
		||||
        sortable: true,
 | 
			
		||||
        filterable: true,
 | 
			
		||||
        format: (val: FG.DrinkPriceVolume) => val.drink.type.name,
 | 
			
		||||
        format: (val: FG.DrinkType) => val.name,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        name: 'tags',
 | 
			
		||||
        label: 'Tags',
 | 
			
		||||
        //field: 'tags',
 | 
			
		||||
        field: 'volume',
 | 
			
		||||
        field: 'tags',
 | 
			
		||||
        filterable: true,
 | 
			
		||||
 | 
			
		||||
        format: (val: FG.DrinkPriceVolume) => {
 | 
			
		||||
        format: (val: Array<FG.Tag>) => {
 | 
			
		||||
          let retVal = '';
 | 
			
		||||
          val.drink.tags.forEach((tag, index) => {
 | 
			
		||||
          val.forEach((tag, index) => {
 | 
			
		||||
            if (index >= val.length - 1 && index > 0) {
 | 
			
		||||
              retVal += ', ';
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -209,11 +203,10 @@ export default defineComponent({
 | 
			
		|||
      {
 | 
			
		||||
        name: 'volume',
 | 
			
		||||
        label: 'Inhalt',
 | 
			
		||||
        //field: 'volume',
 | 
			
		||||
        field: 'volume',
 | 
			
		||||
        filterable: true,
 | 
			
		||||
        sortable: true,
 | 
			
		||||
        format: (val: FG.DrinkPriceVolume) => `${val.volume.toFixed(3)}L`,
 | 
			
		||||
        format: (val: number) => `${val.toFixed(3)}L`,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        name: 'price',
 | 
			
		||||
| 
						 | 
				
			
			@ -304,48 +297,9 @@ export default defineComponent({
 | 
			
		|||
      label: '',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    interface PaginationInterface {
 | 
			
		||||
      sortBy: string;
 | 
			
		||||
      descending: boolean;
 | 
			
		||||
      page: number;
 | 
			
		||||
      rowsPerPage: number;
 | 
			
		||||
      rowsNumber: number;
 | 
			
		||||
    }
 | 
			
		||||
    async function onRequest(props: { pagination: PaginationInterface; filter?: Search }) {
 | 
			
		||||
      const { page, rowsPerPage, sortBy, descending } = props.pagination;
 | 
			
		||||
      loading.value = true;
 | 
			
		||||
      //console.log('search_keys', search_keys);
 | 
			
		||||
      const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage;
 | 
			
		||||
      const startRow = (page - 1) * rowsPerPage;
 | 
			
		||||
      console.log('descending', descending);
 | 
			
		||||
      try {
 | 
			
		||||
        const result = await store.getPricelist({
 | 
			
		||||
          offset: startRow,
 | 
			
		||||
          limit: fetchCount,
 | 
			
		||||
          descending: descending ? true : undefined,
 | 
			
		||||
          search_name: props.filter?.value,
 | 
			
		||||
          search_key: props.filter?.key,
 | 
			
		||||
          sortBy: sortBy,
 | 
			
		||||
        });
 | 
			
		||||
        pagination.value.page = page;
 | 
			
		||||
        pagination.value.rowsPerPage = rowsPerPage;
 | 
			
		||||
        pagination.value.sortBy = sortBy;
 | 
			
		||||
        pagination.value.descending = descending;
 | 
			
		||||
        console.log('result', result);
 | 
			
		||||
        if (result) pagination.value.rowsNumber = result;
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.warn(error);
 | 
			
		||||
      }
 | 
			
		||||
      loading.value = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const loading = ref(false);
 | 
			
		||||
    const pagination = ref({
 | 
			
		||||
      sortBy: 'name',
 | 
			
		||||
      rowsPerPage: 10,
 | 
			
		||||
      rowsNumber: 10,
 | 
			
		||||
      descending: false,
 | 
			
		||||
      page: 1,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const fullscreen = ref(false);
 | 
			
		||||
| 
						 | 
				
			
			@ -360,8 +314,6 @@ export default defineComponent({
 | 
			
		|||
      filter,
 | 
			
		||||
      pagination,
 | 
			
		||||
      fullscreen,
 | 
			
		||||
      loading,
 | 
			
		||||
      onRequest,
 | 
			
		||||
    };
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										51
									
								
								src/store.ts
								
								
								
								
							
							
						
						
									
										51
									
								
								src/store.ts
								
								
								
								
							| 
						 | 
				
			
			@ -76,7 +76,6 @@ export const usePricelistStore = defineStore({
 | 
			
		|||
  state: () => ({
 | 
			
		||||
    drinkTypes: [] as Array<FG.DrinkType>,
 | 
			
		||||
    drinks: [] as Array<Drink>,
 | 
			
		||||
    pricelist: [] as Array<FG.DrinkPrice>,
 | 
			
		||||
    extraIngredients: [] as Array<FG.ExtraIngredient>,
 | 
			
		||||
    min_prices: [] as Array<number>,
 | 
			
		||||
    tags: [] as Array<FG.Tag>,
 | 
			
		||||
| 
						 | 
				
			
			@ -181,12 +180,9 @@ export const usePricelistStore = defineStore({
 | 
			
		|||
    }) {
 | 
			
		||||
      if (!filter) filter = { limit: 10 };
 | 
			
		||||
      console.log('filter_api', filter);
 | 
			
		||||
      const { data } = await api.get<{ drinks: Array<FG.Drink>; count: number }>(
 | 
			
		||||
        'pricelist/drinks',
 | 
			
		||||
        {
 | 
			
		||||
          params: filter,
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
      const { data } = await api.get<Array<FG.Drink>>('pricelist/drinks', {
 | 
			
		||||
        params: filter,
 | 
			
		||||
      });
 | 
			
		||||
      const drinks = [];
 | 
			
		||||
      data.drinks.forEach((drink) => {
 | 
			
		||||
        const _drink = new Drink(drink);
 | 
			
		||||
| 
						 | 
				
			
			@ -199,25 +195,12 @@ export const usePricelistStore = defineStore({
 | 
			
		|||
      calc_all_min_prices(drinks, this.min_prices);
 | 
			
		||||
      return drinks;
 | 
			
		||||
    },
 | 
			
		||||
    async getPricelist(filter: {
 | 
			
		||||
      limit?: number;
 | 
			
		||||
      offset?: number;
 | 
			
		||||
      descending?: boolean;
 | 
			
		||||
      search_name?: string;
 | 
			
		||||
      search_key?: string;
 | 
			
		||||
      sortBy?: string;
 | 
			
		||||
    }) {
 | 
			
		||||
      const { data } = await api.get<{ pricelist: Array<FG.DrinkPrice>; count: number }>(
 | 
			
		||||
        'pricelist/list',
 | 
			
		||||
        {
 | 
			
		||||
          params: filter,
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
      this.pricelist = [];
 | 
			
		||||
      console.log(data);
 | 
			
		||||
      this.pricelist = data.pricelist;
 | 
			
		||||
      console.log(this.pricelist);
 | 
			
		||||
      return data.count;
 | 
			
		||||
    sortPrices(volume: DrinkPriceVolume) {
 | 
			
		||||
      volume.prices.sort((a, b) => {
 | 
			
		||||
        if (a.price > b.price) return 1;
 | 
			
		||||
        if (b.price > a.price) return -1;
 | 
			
		||||
        return 0;
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
    async deletePrice(price: FG.DrinkPrice) {
 | 
			
		||||
      await api.delete(`pricelist/prices/${price.id}`);
 | 
			
		||||
| 
						 | 
				
			
			@ -361,7 +344,7 @@ export const usePricelistStore = defineStore({
 | 
			
		|||
    },
 | 
			
		||||
  },
 | 
			
		||||
  getters: {
 | 
			
		||||
    /*pricelist() {
 | 
			
		||||
    pricelist() {
 | 
			
		||||
      const retVal: Array<Pricelist> = [];
 | 
			
		||||
      this.drinks.forEach((drink) => {
 | 
			
		||||
        drink.volumes.forEach((volume) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -379,20 +362,6 @@ export const usePricelistStore = defineStore({
 | 
			
		|||
        });
 | 
			
		||||
      });
 | 
			
		||||
      return retVal;
 | 
			
		||||
    },*/
 | 
			
		||||
    computed_pricelist() {
 | 
			
		||||
      const retVal: Array<Pricelist> = [];
 | 
			
		||||
      this.pricelist.forEach((price) => {
 | 
			
		||||
        retVal.push({
 | 
			
		||||
          name: price.volume.drink.name,
 | 
			
		||||
          type: <FG.DrinkType>price.volume.drink.type,
 | 
			
		||||
          tags: <Array<FG.Tag>>price.volume.drink.tags,
 | 
			
		||||
          volume: <number>price.volume.volume,
 | 
			
		||||
          public: price.public,
 | 
			
		||||
          price: price.price,
 | 
			
		||||
          description: <string>price.description,
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue