2024-04-11 21:04:11 +00:00
|
|
|
<script setup>
|
|
|
|
import { onMounted, ref, computed } from 'vue';
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
|
|
|
import FetchData from 'components/FetchData.vue';
|
|
|
|
import TicketDescriptorProxy from 'src/pages/Ticket/Card/TicketDescriptorProxy.vue';
|
|
|
|
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
|
2024-04-12 11:07:33 +00:00
|
|
|
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
|
2024-04-11 21:04:11 +00:00
|
|
|
import VnInput from 'src/components/common/VnInput.vue';
|
2024-04-12 11:07:33 +00:00
|
|
|
import ItemRequestDenyForm from './ItemRequestDenyForm.vue';
|
2024-04-11 21:04:11 +00:00
|
|
|
|
|
|
|
import { toDateFormat } from 'src/filters/date';
|
|
|
|
import { toCurrency } from 'filters/index';
|
|
|
|
import useNotify from 'src/composables/useNotify.js';
|
|
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
const { notify } = useNotify();
|
|
|
|
|
2024-04-12 11:07:33 +00:00
|
|
|
const denyFormRef = ref(null);
|
|
|
|
const denyRequestId = ref(null);
|
2024-04-11 21:04:11 +00:00
|
|
|
const itemRequestsOptions = ref([]);
|
|
|
|
|
|
|
|
const columns = computed(() => [
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.ticketId'),
|
|
|
|
name: 'id',
|
|
|
|
field: 'id',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.shipped'),
|
|
|
|
field: 'shipped',
|
|
|
|
name: 'shipped',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('globals.description'),
|
|
|
|
field: 'description',
|
|
|
|
name: 'description',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.requester'),
|
|
|
|
name: 'requester',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.requested'),
|
|
|
|
field: 'quantity',
|
|
|
|
name: 'requested',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.price'),
|
|
|
|
field: 'price',
|
|
|
|
name: 'price',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
format: (val) => toCurrency(val),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.attender'),
|
|
|
|
field: 'attender',
|
|
|
|
name: 'attender',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.item'),
|
|
|
|
field: 'item',
|
|
|
|
name: 'item',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.achieved'),
|
|
|
|
field: 'achieved',
|
|
|
|
name: 'achieved',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.concept'),
|
|
|
|
field: 'concept',
|
|
|
|
name: 'concept',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: t('item.buyRequest.state'),
|
|
|
|
field: 'state',
|
|
|
|
name: 'state',
|
|
|
|
align: 'left',
|
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '',
|
|
|
|
name: 'action',
|
|
|
|
align: 'left',
|
|
|
|
columnFilter: null,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
const getDateQBadgeColor = (date) => {
|
|
|
|
let today = Date.vnNew();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
let timeTicket = new Date(date);
|
|
|
|
timeTicket.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
let comparation = today - timeTicket;
|
|
|
|
|
|
|
|
if (comparation == 0) return 'warning';
|
|
|
|
if (comparation < 0) return 'negative';
|
|
|
|
};
|
|
|
|
|
|
|
|
const changeQuantity = async (request) => {
|
|
|
|
console.log('change quantity request:: ', request);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (request.saleFk) {
|
|
|
|
const params = {
|
|
|
|
quantity: request.saleQuantity,
|
|
|
|
};
|
|
|
|
|
|
|
|
await axios.patch(`Sales/${request.saleFk}`, params);
|
|
|
|
notify(t('globals.dataSaved', 'positive'));
|
|
|
|
confirmRequest(request);
|
|
|
|
} else confirmRequest(request);
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Error changing quantity:: ', error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const confirmRequest = async (request) => {
|
|
|
|
console.log('confirm request:: ', request);
|
|
|
|
try {
|
|
|
|
if (request.itemFk && request.saleQuantity) {
|
|
|
|
const params = {
|
|
|
|
itemFk: request.itemFk,
|
|
|
|
quantity: request.saleQuantity,
|
|
|
|
};
|
|
|
|
|
|
|
|
const { data } = await axios.post(
|
|
|
|
`TicketRequests/${request.id}/confirm`,
|
|
|
|
params
|
|
|
|
);
|
|
|
|
|
|
|
|
request.itemDescription = data.concept;
|
|
|
|
request.isOk = true;
|
|
|
|
notify(t('globals.dataSaved', 'positive'));
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Error confirming request:: ', error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-04-12 11:07:33 +00:00
|
|
|
const getState = (isOk) => {
|
|
|
|
if (isOk === null) return 'Pending';
|
|
|
|
else if (isOk) return 'Accepted';
|
|
|
|
else return 'Denied';
|
|
|
|
};
|
|
|
|
|
|
|
|
const showDenyRequestForm = (requestId) => {
|
|
|
|
denyRequestId.value = requestId;
|
|
|
|
denyFormRef.value.show();
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDenyAccept = (_, responseData) => {
|
|
|
|
console.log('response data:: ', responseData);
|
|
|
|
};
|
|
|
|
|
2024-04-11 21:04:11 +00:00
|
|
|
onMounted(async () => {});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<FetchData
|
|
|
|
url="TicketRequests/filter"
|
|
|
|
:filter="{ order: ['shippedDate ASC', 'isOk ASC'] }"
|
|
|
|
auto-load
|
|
|
|
@on-fetch="(data) => (itemRequestsOptions = data)"
|
|
|
|
/>
|
|
|
|
<!-- TODO:: ADD SEARCHBAR -->
|
|
|
|
<QPage class="column items-center q-pa-md">
|
|
|
|
<QTable
|
|
|
|
:rows="itemRequestsOptions"
|
|
|
|
:columns="columns"
|
|
|
|
row-key="id"
|
|
|
|
:pagination="{ rowsPerPage: 0 }"
|
|
|
|
class="full-width q-mt-md"
|
|
|
|
:no-data-label="t('globals.noResults')"
|
|
|
|
>
|
|
|
|
<template #body-cell-id="{ row }">
|
|
|
|
<QTd>
|
|
|
|
<QBtn flat color="primary"> {{ row.id }}</QBtn>
|
|
|
|
<TicketDescriptorProxy :id="row.id" />
|
|
|
|
</QTd>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
<QBtn flat dense color="primary"> {{ row.attenderName }}</QBtn>
|
|
|
|
<WorkerDescriptorProxy :id="row.attenderFk" />
|
|
|
|
</QTd>
|
|
|
|
</template>
|
|
|
|
<template #body-cell-item="{ row }">
|
|
|
|
<QTd>
|
|
|
|
<VnInput
|
|
|
|
class="dense"
|
|
|
|
v-model.number="row.itemFk"
|
|
|
|
type="number"
|
|
|
|
:disable="row.isOk != null"
|
|
|
|
/>
|
|
|
|
</QTd>
|
|
|
|
</template>
|
|
|
|
<template #body-cell-achieved="{ row }">
|
|
|
|
<QTd>
|
|
|
|
<VnInput
|
|
|
|
class="dense"
|
|
|
|
v-model.number="row.saleQuantity"
|
|
|
|
@change="changeQuantity(row)"
|
|
|
|
type="number"
|
|
|
|
:disable="!row.itemFk || row.isOk != null"
|
|
|
|
/>
|
|
|
|
</QTd>
|
|
|
|
</template>
|
2024-04-12 11:07:33 +00:00
|
|
|
<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 }">
|
|
|
|
<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"
|
|
|
|
class="cursor-pointer"
|
|
|
|
@click="showDenyRequestForm(row.id)"
|
|
|
|
>
|
|
|
|
<QTooltip>
|
|
|
|
{{ t('Discard') }}
|
|
|
|
</QTooltip>
|
|
|
|
</QIcon>
|
|
|
|
</QTd>
|
|
|
|
</template>
|
2024-04-11 21:04:11 +00:00
|
|
|
</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-04-11 21:04:11 +00:00
|
|
|
</QPage>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<i18n>
|
2024-04-12 11:07:33 +00:00
|
|
|
es:
|
|
|
|
Discard: Descartar
|
2024-04-11 21:04:11 +00:00
|
|
|
</i18n>
|