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

335 lines
9.6 KiB
Vue
Raw Normal View History

2024-04-11 21:04:11 +00:00
<script setup>
2024-09-02 10:14:23 +00:00
import { ref, computed, onMounted, watch } from 'vue';
2024-04-11 21:04:11 +00:00
import { useI18n } from 'vue-i18n';
import TicketDescriptorProxy from 'src/pages/Ticket/Card/TicketDescriptorProxy.vue';
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-10-23 07:49:48 +00:00
import { dashIfEmpty, toCurrency } from 'filters/index';
2024-04-11 21:04:11 +00:00
import useNotify from 'src/composables/useNotify.js';
import axios from 'axios';
2024-08-29 10:38:57 +00:00
import ItemRequestDenyForm from './ItemRequestDenyForm.vue';
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-08-27 12:39:21 +00:00
import VnInput from 'src/components/common/VnInput.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;
2024-08-29 10:38:57 +00:00
const userParams = {
state: 'pending',
daysOnward: 7,
2024-08-29 10:38:57 +00:00
};
2024-09-02 10:14:23 +00:00
const tableRef = ref();
2024-04-16 14:47:15 +00:00
watch(
() => store.data,
(value) => (itemRequestsOptions.value = value)
);
2024-04-11 21:04:11 +00:00
const columns = computed(() => [
{
label: t('item.buyRequest.ticketId'),
2024-08-07 07:53:42 +00:00
name: 'ticketFk',
2024-04-11 21:04:11 +00:00
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'),
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-09-16 12:29:39 +00:00
columnClass: 'shrink',
2024-04-11 21:04:11 +00:00
},
{
label: t('globals.description'),
field: 'description',
name: 'description',
align: 'left',
2024-09-16 12:29:39 +00:00
columnClass: 'expand',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.requester'),
2024-08-07 07:53:42 +00:00
name: 'requesterName',
2024-09-16 12:29:39 +00:00
columnClass: 'shrink',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.requested'),
2024-08-27 12:39:21 +00:00
name: 'quantity',
2024-09-16 12:29:39 +00:00
columnClass: 'shrink',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.price'),
name: 'price',
align: 'left',
2024-07-15 13:00:43 +00:00
format: (row) => toCurrency(row.price),
2024-09-16 12:29:39 +00:00
columnClass: 'shrink',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.attender'),
2024-08-07 07:53:42 +00:00
name: 'attenderName',
2024-04-11 21:04:11 +00:00
align: 'left',
2024-09-16 12:29:39 +00:00
columnClass: 'shrink',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.item'),
name: 'item',
align: 'left',
2024-07-15 13:00:43 +00:00
component: 'input',
2024-09-16 12:29:39 +00:00
columnClass: 'expand',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.achieved'),
name: 'achieved',
align: 'left',
2024-07-15 13:00:43 +00:00
component: 'input',
2024-09-16 12:29:39 +00:00
columnClass: 'shrink',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.concept'),
name: 'concept',
align: 'left',
sortable: true,
2024-07-16 10:15:39 +00:00
component: 'input',
2024-09-16 12:29:39 +00:00
columnClass: 'expand',
2024-04-11 21:04:11 +00:00
},
{
label: t('item.buyRequest.state'),
name: 'state',
2024-08-27 12:39:21 +00:00
format: (row) => getState(row.isOk),
2024-04-11 21:04:11 +00:00
align: 'left',
},
2024-10-01 06:44:08 +00:00
{
align: 'left',
name: 'daysOnward',
label: t('travel.travelList.tableVisibleColumns.daysOnward'),
2024-10-01 06:44:08 +00:00
visible: false,
columnFilter: {
inWhere: false,
},
},
2024-04-11 21:04:11 +00:00
{
2024-08-01 11:20:33 +00:00
align: 'right',
2024-04-11 21:04:11 +00:00
label: '',
2024-09-02 09:08:50 +00:00
name: 'denyOptions',
2024-04-11 21:04:11 +00:00
},
]);
2024-10-23 07:49:48 +00:00
const getBadgeColor = (date) => {
const today = Date.vnNew();
today.setHours(0, 0, 0, 0);
const orderLanded = new Date(date);
orderLanded.setHours(0, 0, 0, 0);
const difference = today - orderLanded;
if (difference == 0) return 'warning';
if (difference < 0) return 'success';
if (difference > 0) return 'alert';
};
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-09-02 10:14:23 +00:00
tableRef.value.reload();
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;
});
2024-04-11 21:04:11 +00:00
</script>
<template>
2024-07-22 11:35:41 +00:00
<VnTable
ref="tableRef"
data-key="itemRequest"
2024-08-07 07:53:42 +00:00
url="ticketRequests/filter"
2024-09-12 07:32:41 +00:00
order="shipped ASC, isOk ASC"
2024-07-22 11:35:41 +00:00
:columns="columns"
2024-08-29 10:38:57 +00:00
:user-params="userParams"
2024-08-13 10:45:30 +00:00
:is-editable="true"
2024-07-22 11:35:41 +00:00
auto-load
2024-08-29 10:38:57 +00:00
:disable-option="{ card: true }"
2024-10-24 12:59:14 +00:00
chip-locale="item.params"
2024-07-22 11:35:41 +00:00
>
2024-10-23 07:49:48 +00:00
<template #column-ticketFk="{ row }">
<span class="link">
{{ row.ticketFk }}
<TicketDescriptorProxy :id="row.ticketFk" />
</span>
</template>
<template #column-shipped="{ row }">
<QTd>
<QBadge
:color="getBadgeColor(row.shipped)"
text-color="black"
class="q-pa-sm"
style="font-size: 14px"
>
{{ toDate(row.shipped) }}
</QBadge>
</QTd>
</template>
2024-08-13 10:45:30 +00:00
<template #column-attenderName="{ row }">
2024-07-22 11:35:41 +00:00
<span class="link" @click.stop>
2024-08-13 10:45:30 +00:00
{{ row.attenderName }}
2024-07-22 11:35:41 +00:00
<WorkerDescriptorProxy :id="row.attenderFk" />
</span>
</template>
2024-08-13 10:45:30 +00:00
<template #column-requesterName="{ row }">
<span class="link" @click.stop>
{{ row.requesterName }}
<WorkerDescriptorProxy :id="row.requesterFk" />
</span>
</template>
2024-08-27 12:39:21 +00:00
<template #column-item="{ row }">
2024-09-02 07:19:49 +00:00
<span>
<VnInput v-model.number="row.itemFk" dense />
2024-08-27 12:39:21 +00:00
</span>
</template>
<template #column-achieved="{ row }">
2024-09-02 07:19:49 +00:00
<span>
2024-08-27 12:39:21 +00:00
<VnInput
type="number"
2024-09-02 07:19:49 +00:00
v-model.number="row.saleQuantity"
:disable="!row.itemFk || row.isOk != null"
@blur="changeQuantity(row)"
2024-08-27 12:39:21 +00:00
@keyup.enter="changeQuantity(row)"
2024-09-02 07:19:49 +00:00
dense
2024-08-27 12:39:21 +00:00
/>
</span>
</template>
<template #column-concept="{ row }">
<span @click.stop disabled="row.isOk != null">
{{ row.itemDescription }}
</span>
</template>
2024-10-01 06:44:08 +00:00
<template #moreFilterPanel="{ params }">
<VnInputNumber
:label="t('params.scopeDays')"
v-model.number="params.scopeDays"
@keyup.enter="(evt) => handleScopeDays(evt.target.value)"
@remove="handleScopeDays()"
class="q-px-xs q-pr-lg"
filled
dense
/>
</template>
2024-09-02 09:08:50 +00:00
<template #column-denyOptions="{ row, rowIndex }">
<QTd class="sticky no-padding">
2024-08-28 09:35:57 +00:00
<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="fill-icon"
@click="showDenyRequestForm(row.id, rowIndex)"
>
<QTooltip>
{{ t('Discard') }}
</QTooltip>
</QIcon>
</QTd>
</template>
2024-07-22 11:35:41 +00:00
</VnTable>
2024-08-29 10:38:57 +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
</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>