0
0
Fork 0
salix-front-mindshore-fork2/src/pages/Item/ItemRequest.vue

373 lines
11 KiB
Vue
Raw Normal View History

2024-04-11 21:04:11 +00:00
<script setup>
2024-04-16 14:47:15 +00:00
import { ref, computed, onMounted, onBeforeMount, watch } from 'vue';
2024-04-11 21:04:11 +00:00
import { useI18n } from 'vue-i18n';
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
2024-04-15 11:46:26 +00:00
import { useStateStore } from 'stores/useStateStore';
2024-04-16 14:47:15 +00:00
import { useArrayData } from 'composables/useArrayData';
2024-04-11 21:04:11 +00:00
import { toCurrency } from 'filters/index';
import useNotify from 'src/composables/useNotify.js';
import axios from 'axios';
2024-07-15 13:00:43 +00:00
import { toDate } from 'src/filters';
2024-07-22 11:35:41 +00:00
import VnTable from 'components/VnTable/VnTable.vue';
2024-04-11 21:04:11 +00:00
const { t } = useI18n();
const { notify } = useNotify();
2024-04-15 11:46:26 +00:00
const stateStore = useStateStore();
let filterParams = ref({});
2024-04-12 11:07:33 +00:00
const denyFormRef = ref(null);
const denyRequestId = ref(null);
2024-04-12 19:50:41 +00:00
const denyRequestIndex = ref(null);
2024-04-11 21:04:11 +00:00
const itemRequestsOptions = ref([]);
2024-04-16 14:47:15 +00:00
const arrayData = useArrayData('ItemRequests', {
url: 'TicketRequests/filter',
userParams: filterParams,
order: ['shippedDate ASC', 'isOk ASC'],
});
const store = arrayData.store;
watch(
() => store.data,
(value) => (itemRequestsOptions.value = value)
);
2024-04-11 21:04:11 +00:00
const columns = computed(() => [
{
label: t('item.buyRequest.ticketId'),
name: 'id',
field: 'id',
align: 'left',
2024-07-15 13:00:43 +00:00
isId: true,
chip: {
condition: () => true,
},
cardVisible: true,
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.shipped'),
field: 'shipped',
name: 'shipped',
align: 'left',
2024-07-15 13:00:43 +00:00
component: 'date',
columnField: {
component: null,
},
format: (row, dashIfEmpty) => dashIfEmpty(toDate(row.shipped)),
2024-04-11 21:04:11 +00:00
},
{
label: t('globals.description'),
field: 'description',
name: 'description',
align: 'left',
},
{
label: t('item.buyRequest.requester'),
2024-07-22 11:35:41 +00:00
field: 'requesterName',
name: 'requesterFk',
2024-04-11 21:04:11 +00:00
align: 'left',
},
{
label: t('item.buyRequest.requested'),
field: 'quantity',
name: 'requested',
align: 'left',
},
{
label: t('item.buyRequest.price'),
field: 'price',
name: 'price',
align: 'left',
2024-07-15 13:00:43 +00:00
format: (row) => toCurrency(row.price),
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.attender'),
field: 'attender',
name: 'attender',
align: 'left',
},
{
label: t('item.buyRequest.item'),
field: 'item',
name: 'item',
align: 'left',
2024-07-15 13:00:43 +00:00
component: 'input',
2024-08-01 11:20:33 +00:00
visible: false,
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.achieved'),
field: 'achieved',
name: 'achieved',
align: 'left',
2024-07-15 13:00:43 +00:00
component: 'input',
2024-08-01 11:20:33 +00:00
visible: false,
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.concept'),
field: 'concept',
name: 'concept',
align: 'left',
sortable: true,
2024-07-16 10:15:39 +00:00
component: 'input',
2024-08-01 11:20:33 +00:00
visible: false,
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.state'),
field: 'state',
name: 'state',
align: 'left',
},
{
2024-08-01 11:20:33 +00:00
align: 'right',
2024-04-11 21:04:11 +00:00
label: '',
2024-08-01 11:20:33 +00:00
name: 'tableActions',
actions: [
{
title: t('Client ticket list'),
icon: 'thumb_down',
action: onDenyAccept,
isPrimary: true,
},
],
2024-04-11 21:04:11 +00:00
},
]);
const changeQuantity = async (request) => {
try {
if (request.saleFk) {
const params = {
quantity: request.saleQuantity,
};
await axios.patch(`Sales/${request.saleFk}`, params);
2024-04-16 14:47:15 +00:00
notify(t('globals.dataSaved'), 'positive');
2024-04-11 21:04:11 +00:00
confirmRequest(request);
} else confirmRequest(request);
} catch (error) {
2024-04-12 19:50:41 +00:00
console.error('Error changing quantity:: ', error);
2024-04-11 21:04:11 +00:00
}
};
const confirmRequest = async (request) => {
try {
if (request.itemFk && request.saleQuantity) {
const params = {
itemFk: request.itemFk,
quantity: request.saleQuantity,
2024-05-07 11:38:25 +00:00
attenderFk: request.attenderFk,
2024-04-11 21:04:11 +00:00
};
const { data } = await axios.post(
`TicketRequests/${request.id}/confirm`,
params
);
request.itemDescription = data.concept;
request.isOk = true;
2024-04-16 14:47:15 +00:00
notify(t('globals.dataSaved'), 'positive');
2024-04-11 21:04:11 +00:00
}
} catch (error) {
2024-04-12 19:50:41 +00:00
console.error('Error confirming request:: ', error);
2024-04-11 21:04:11 +00:00
}
};
2024-04-12 11:07:33 +00:00
const getState = (isOk) => {
2024-04-18 12:19:15 +00:00
if (isOk === null) return t('Pending');
else if (isOk) return t('Accepted');
else return t('Denied');
2024-04-12 11:07:33 +00:00
};
2024-04-12 19:50:41 +00:00
const showDenyRequestForm = (requestId, rowIndex) => {
2024-04-12 11:07:33 +00:00
denyRequestId.value = requestId;
2024-04-12 19:50:41 +00:00
denyRequestIndex.value = rowIndex;
2024-04-12 11:07:33 +00:00
denyFormRef.value.show();
};
const onDenyAccept = (_, responseData) => {
2024-04-12 19:50:41 +00:00
itemRequestsOptions.value[denyRequestIndex.value].isOk = responseData.isOk;
itemRequestsOptions.value[denyRequestIndex.value].attenderFk =
responseData.attenderFk;
itemRequestsOptions.value[denyRequestIndex.value].response = responseData.response;
denyRequestId.value = null;
denyRequestIndex.value = null;
2024-04-12 11:07:33 +00:00
};
2024-04-15 11:46:26 +00:00
onMounted(async () => {
2024-04-16 14:47:15 +00:00
await arrayData.fetch({ append: false });
2024-04-15 11:46:26 +00:00
stateStore.rightDrawer = true;
});
onBeforeMount(() => {
const today = Date.vnNew();
today.setHours(0, 0, 0, 0);
const nextWeek = Date.vnNew();
nextWeek.setHours(23, 59, 59, 59);
nextWeek.setDate(nextWeek.getDate() + 7);
filterParams.value = {
from: today,
to: nextWeek,
state: 'pending',
};
});
2024-04-11 21:04:11 +00:00
</script>
<template>
2024-07-22 11:35:41 +00:00
<!-- <FetchData
2024-05-06 13:00:18 +00:00
url="Workers"
:filter="{ where: { role: 'buyer' } }"
order="id"
@on-fetch="(data) => (workersOptions = data)"
auto-load
/>
<VnSearchbar
data-key="ItemRequests"
url="TicketRequests/filter"
:label="t('globals.search')"
:info="t('You can search by Id or alias')"
:redirect="false"
/>
<RightMenu>
<template #right-panel>
2024-04-15 11:46:26 +00:00
<ItemRequestFilter data-key="ItemRequests" />
</template>
</RightMenu>
2024-04-11 21:04:11 +00:00
<QPage class="column items-center q-pa-md">
2024-04-16 14:47:15 +00:00
<QTable
:rows="itemRequestsOptions"
:columns="columns"
row-key="id"
:pagination="{ rowsPerPage: 0 }"
class="full-width q-mt-md"
:no-data-label="t('globals.noResults')"
2024-04-11 21:04:11 +00:00
>
2024-04-16 14:47:15 +00:00
<template #body-cell-id="{ row }">
<QTd>
<QBtn flat color="primary"> {{ row.ticketFk }}</QBtn>
<TicketDescriptorProxy :id="row.ticketFk" />
</QTd>
2024-04-11 21:04:11 +00:00
</template>
2024-04-16 14:47:15 +00:00
<template #body-cell-shipped="{ row }">
<QTd>
<QBadge
v-if="getDateQBadgeColor(row.shipped)"
:color="getDateQBadgeColor(row.shipped)"
text-color="black"
class="q-ma-none"
dense
style="font-size: 14px"
>
{{ toDateFormat(row.shipped) }}
</QBadge>
<span v-else>{{ toDateFormat(row.shipped) }}</span>
</QTd>
</template>
<template #body-cell-requester="{ row }">
<QTd>
<QBtn flat dense color="primary"> {{ row.requesterName }}</QBtn>
<WorkerDescriptorProxy :id="row.requesterFk" />
</QTd>
</template>
<template #body-cell-attender="{ row }">
<QTd>
2024-05-06 13:00:18 +00:00
<VnSelect
v-model="row.attenderFk"
:options="workersOptions"
hide-selected
option-label="firstName"
option-value="id"
dense
/>
2024-04-16 14:47:15 +00:00
</QTd>
</template>
<template #body-cell-item="{ row }">
<QTd>
<VnInput
v-model.number="row.itemFk"
type="number"
:disable="row.isOk != null"
2024-04-16 14:49:59 +00:00
dense
2024-04-16 14:47:15 +00:00
/>
</QTd>
</template>
<template #body-cell-achieved="{ row }">
<QTd>
<VnInput
v-model.number="row.saleQuantity"
@blur="changeQuantity(row)"
2024-04-16 14:47:15 +00:00
type="number"
:disable="!row.itemFk || row.isOk != null"
2024-04-16 14:49:59 +00:00
dense
2024-04-16 14:47:15 +00:00
/>
</QTd>
</template>
<template #body-cell-concept="{ row }">
<QTd>
<QBtn flat dense color="primary"> {{ row.itemDescription }}</QBtn>
<ItemDescriptorProxy :id="row.itemFk" />
</QTd>
</template>
<template #body-cell-state="{ row }">
<QTd>
<span>{{ getState(row.isOk) }}</span>
</QTd>
</template>
<template #body-cell-action="{ row, rowIndex }">
<QTd>
<QIcon
v-if="row.response?.length"
name="insert_drive_file"
color="primary"
size="sm"
>
<QTooltip>
{{ row.response }}
</QTooltip>
</QIcon>
<QIcon
v-if="row.isOk == null"
name="thumb_down"
color="primary"
size="sm"
2024-04-24 12:28:20 +00:00
class="fill-icon"
2024-04-16 14:47:15 +00:00
@click="showDenyRequestForm(row.id, rowIndex)"
>
<QTooltip>
{{ t('Discard') }}
</QTooltip>
</QIcon>
</QTd>
</template>
</QTable>
2024-04-12 11:07:33 +00:00
<QDialog ref="denyFormRef" transition-show="scale" transition-hide="scale">
<ItemRequestDenyForm
:request-id="denyRequestId"
@on-data-saved="onDenyAccept"
/>
</QDialog>
2024-07-22 11:35:41 +00:00
</QPage> -->
<VnTable
ref="tableRef"
data-key="itemRequest"
url="ticketRequests"
order="id DESC"
:columns="columns"
auto-load
>
<template #column-attender="{ row }">
<span class="link" @click.stop>
{{ row.attenderFk }}
<WorkerDescriptorProxy :id="row.attenderFk" />
</span>
</template>
</VnTable>
2024-04-11 21:04:11 +00:00
</template>
<i18n>
2024-04-12 11:07:33 +00:00
es:
Discard: Descartar
2024-04-15 11:46:26 +00:00
You can search by Id or alias: Buscar peticiones por identificador o alias
2024-04-18 12:19:15 +00:00
Denied: Denegada
Accepted: Aceptada
Pending: Pendiente
2024-04-11 21:04:11 +00:00
</i18n>