Item Fixed prices #307

Merged
jsegarra merged 17 commits from :feature/FixedPrices into dev 2024-04-24 07:39:23 +00:00
4 changed files with 1655 additions and 1146 deletions
Showing only changes of commit 00dfa171b0 - Show all commits

View File

@ -1097,6 +1097,7 @@ item:
diary: Diary
tags: Tags
create: Create
fixedPrice: Fixed prices
descriptor:
item: Item
buyer: Buyer
@ -1124,6 +1125,9 @@ item:
stemMultiplier: Multiplier
producer: Producer
landed: Landed
fixedPrice:
itemId: Item ID
groupingPrice: Grouping price
components:
topbar: {}
userPanel:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,492 @@
<script setup>
import { onMounted, ref, computed, reactive, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import FetchData from 'components/FetchData.vue';
import FetchedTags from 'components/ui/FetchedTags.vue';
import TableVisibleColumns from 'src/components/common/TableVisibleColumns.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
import ItemDescriptorProxy from '../Item/Card/ItemDescriptorProxy.vue';
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
import { useStateStore } from 'stores/useStateStore';
import { toDateFormat } from 'src/filters/date.js';
import { useSession } from 'composables/useSession';
import { dashIfEmpty } from 'src/filters';
import { useVnConfirm } from 'composables/useVnConfirm';
import { useState } from 'src/composables/useState';
import { toCurrency } from 'filters/index';
import axios from 'axios';
const router = useRouter();
const { getTokenMultimedia } = useSession();
const token = getTokenMultimedia();
const stateStore = useStateStore();
const { t } = useI18n();
const { openConfirmationModal } = useVnConfirm();
const state = useState();
const paginateRef = ref(null);
const user = state.getUser();
const fixedPrices = ref([]);
const warehousesOptions = ref([]);
const itemsWithNameOptions = ref([]);
const exprBuilder = (param, value) => {
switch (param) {
case 'category':
return { 'ic.name': value };
case 'buyerFk':
return { 'it.workerFk': value };
case 'grouping':
return { 'b.grouping': value };
case 'packing':
return { 'b.packing': value };
case 'origin':
return { 'ori.code': value };
case 'typeFk':
return { 'i.typeFk': value };
case 'intrastat':
return { 'intr.description': value };
case 'name':
return { 'i.name': { like: `%${value}%` } };
case 'producer':
return { 'pr.name': { like: `%${value}%` } };
case 'id':
case 'size':
case 'subname':
case 'isActive':
case 'weightByPiece':
case 'stemMultiplier':
case 'stems':
return { [`i.${param}`]: value };
}
};
const params = reactive({});
const applyColumnFilter = async (col) => {
try {
const paramKey = col.columnFilter?.filterParamKey || col.field;
params[paramKey] = col.columnFilter.filterValue;
await paginateRef.value.addFilter(null, params);
} catch (err) {
console.error('Error applying column filter', err);
}
};
const getInputEvents = (col) => {
return col.columnFilter.type === 'select'
? { 'update:modelValue': () => applyColumnFilter(col) }
: {
'keyup.enter': () => applyColumnFilter(col),
};
};
const upsertPrice = (price, resetMinPrice) => {
// if (resetMinPrice) delete price['minPrice'];
// const requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
// for (const field of requiredFields) if (price[field] == undefined) return;
// const query = 'FixedPrices/upsertFixedPrice';
// this.$http.patch(query, price).then((res) => {
// this.vnApp.showSuccess(this.$t('Data saved!'));
// Object.assign(price, res.data);
// });
};
const columns = computed(() => [
{
label: t('item.fixedPrice.itemId'),
name: 'itemId',
// field: 'id',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
},
{
label: t('globals.description'),
field: 'name',
name: 'description',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
},
{
label: t('item.fixedPrice.groupingPrice'),
field: 'rate2',
name: 'groupingPrice',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
format: (val) => toCurrency(val),
},
{
label: t('item.list.packing'),
field: 'packing',
name: 'packing',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
format: (val) => dashIfEmpty(val),
},
{
label: t('item.list.stems'),
field: 'stems',
name: 'stems',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
},
{
label: t('item.list.size'),
field: 'size',
name: 'size',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
},
{
label: t('item.list.typeName'),
field: 'typeName',
name: 'typeName',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnSelectFilter,
// filterParamKey: 'typeFk',
// type: 'select',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// options: itemTypesOptions.value,
// 'option-value': 'id',
// 'option-label': 'name',
// dense: true,
// },
// },
},
{
label: t('item.list.category'),
field: 'category',
name: 'category',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnSelectFilter,
// type: 'select',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// options: itemCategoriesOptions.value,
// 'option-value': 'name',
// 'option-label': 'name',
// dense: true,
// },
// },
},
{
label: t('item.list.intrastat'),
field: 'intrastat',
name: 'intrastat',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnSelectFilter,
// type: 'select',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// options: intrastatOptions.value,
// 'option-value': 'description',
// 'option-label': 'description',
// dense: true,
// },
// },
},
{
label: t('item.list.origin'),
field: 'origin',
name: 'origin',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnSelectFilter,
// type: 'select',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// options: originsOptions.value,
// 'option-value': 'code',
// 'option-label': 'code',
// dense: true,
// },
// },
},
{
label: t('item.list.userName'),
field: 'userName',
name: 'userName',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnSelectFilter,
// filterParamKey: 'buyerFk',
// type: 'select',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// options: buyersOptions.value,
// 'option-value': 'id',
// 'option-label': 'nickname',
// dense: true,
// },
// },
},
{
label: t('item.list.weightByPiece'),
field: 'weightByPiece',
name: 'weightByPiece',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
format: (val) => dashIfEmpty(val),
},
{
label: t('item.list.stemMultiplier'),
field: 'stemMultiplier',
name: 'stemMultiplier',
align: 'left',
sortable: true,
jsegarra marked this conversation as resolved
Review

Mismo objeto

Mismo objeto
Review

Cambiado

Commit: dce48b536d

Cambiado Commit: https://gitea.verdnatura.es/verdnatura/salix-front/commit/dce48b536d536ab01a401422662ce14533085f42
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
format: (val) => dashIfEmpty(val),
},
{
label: t('item.list.isActive'),
field: 'isActive',
name: 'isActive',
align: 'left',
sortable: true,
// columnFilter: null,
},
{
label: t('item.list.producer'),
field: 'producer',
name: 'producer',
align: 'left',
sortable: true,
// columnFilter: {
// component: VnInput,
// type: 'text',
// filterValue: null,
// event: getInputEvents,
// attrs: {
// dense: true,
// },
// },
format: (val) => dashIfEmpty(val),
},
{
label: t('item.list.landed'),
field: 'landed',
name: 'landed',
align: 'left',
sortable: true,
format: (val) => dashIfEmpty(toDateFormat(val)),
// columnFilter: null,
},
{
label: '',
name: 'actions',
align: 'left',
// columnFilter: null,
},
]);
const redirectToItemCreate = () => {
router.push({ name: 'ItemCreate' });
};
const redirectToItemSummary = (id) => {
router.push({ name: 'ItemSummary', params: { id } });
};
const cloneItem = async (itemFk) => {
// try {
// const { data } = await axios.post(`Items/${itemFk}/clone`);
// if (!data) return;
// router.push({ name: 'ItemTags', params: { id: data.id } });
// } catch (err) {
// console.error('Error cloning item', err);
// }
};
onMounted(async () => {
stateStore.rightDrawer = true;
});
onUnmounted(() => (stateStore.rightDrawer = false));
</script>
<template>
<FetchData
url="FixedPrices/filter"
:filter="{ order: ['itemFk'] }"
:params="{ warehouseFk: user.warehouseFk }"
auto-load
@on-fetch="(data) => (fixedPrices = data)"
/>
<FetchData
url="Warehouses"
:filter="{ order: ['name'] }"
auto-load
@on-fetch="(data) => (warehousesOptions = data)"
/>
<FetchData
url="Items/withName"
:filter="{ fields: ['id', 'name'], order: 'id DESC' }"
auto-load
@on-fetch="(data) => (itemsWithNameOptions = data)"
/>
<QPage class="column items-center q-pa-md">
<QTable
:rows="fixedPrices"
:columns="columns"
row-key="id"
:pagination="{ rowsPerPage: 0 }"
class="full-width q-mt-md"
:no-data-label="t('globals.noResults')"
@row-click="(_, row) => redirectToItemSummary(row.id)"
>
<!-- <template #top-row="{ cols }">
<QTr>
<QTd
v-for="(col, index) in cols"
:key="index"
style="max-width: 100px"
>
<component
:is="col.columnFilter.component"
v-if="col.columnFilter"
v-model="col.columnFilter.filterValue"
v-bind="col.columnFilter.attrs"
v-on="col.columnFilter.event(col)"
dense
/>
</QTd>
</QTr>
</template> -->
<template #body-cell-itemId="{ row }">
<QTd>
<VnSelectFilter
:options="itemsWithNameOptions"
hide-selected
option-label="id"
option-value="id"
v-model="row.itemFk"
@update:model-value="upsertPrice(row, true)"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel> #{{ scope.opt?.id }} </QItemLabel>
<QItemLabel caption>{{ scope.opt?.name }}</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelectFilter>
</QTd>
</template>
<template #body-cell-description="{ row }">
<QTd class="col">
<span>{{ row.name }} {{ row.subName }}</span>
<fetched-tags :item="row" :max-length="6" />
</QTd>
</template>
</QTable>
<QPageSticky :offset="[20, 20]">
<QBtn @click="redirectToItemCreate()" color="primary" fab icon="add" />
<QTooltip class="text-no-wrap">
{{ t('New item') }}
</QTooltip>
</QPageSticky>
</QPage>
</template>
<i18n>
es:
New item: Nuevo artículo
All it's properties will be copied: Todas sus propiedades serán copiadas
Do you want to clone this item?: ¿Desea clonar este artículo?
Clone: Clonar
Preview: Vista previa
</i18n>

View File

@ -10,7 +10,7 @@ export default {
component: RouterView,
redirect: { name: 'ItemMain' },
menus: {
main: ['ItemList'],
main: ['ItemList', 'ItemFixedPrice'],
card: [],
},
children: [
@ -29,6 +29,15 @@ export default {
},
component: () => import('src/pages/Item/ItemList.vue'),
},
{
path: 'fixed-price',
name: 'ItemFixedPrice',
meta: {
title: 'fixedPrice',
icon: 'vn:fixedPrice',
},
component: () => import('src/pages/Item/ItemFixedPrice.vue'),
},
{
path: 'create',
name: 'ItemCreate',