feat: refs #7322 add address selection for ticket transfer
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jose Antonio Tubau 2025-01-15 13:38:45 +01:00
parent 372a43b17e
commit 36473d979b
1 changed files with 73 additions and 10 deletions

View File

@ -41,6 +41,9 @@ const ticketSummary = useArrayData('TicketSummary');
const { ticket } = toRefs(props); const { ticket } = toRefs(props);
const ticketId = computed(() => props.ticket.id ?? currentRoute.value.params.id); const ticketId = computed(() => props.ticket.id ?? currentRoute.value.params.id);
const client = ref(); const client = ref();
const address = ref();
const addressesOptions = ref([]);
const selectedClient = ref();
const showTransferDialog = ref(false); const showTransferDialog = ref(false);
const showTurnDialog = ref(false); const showTurnDialog = ref(false);
const showChangeTimeDialog = ref(false); const showChangeTimeDialog = ref(false);
@ -52,6 +55,45 @@ const weight = ref();
const hasDocuwareFile = ref(); const hasDocuwareFile = ref();
const quasar = useQuasar(); const quasar = useQuasar();
const canRestoreTicket = ref(false); const canRestoreTicket = ref(false);
const onClientSelected = async(clientId) =>{
await fetchClient(clientId);
await fetchAddresses(clientId);
};
const fetchClient = async (clientId) => {
const filter = {
include: {
relation: 'defaultAddress',
scope: {
fields: ['id', 'nickname'],
},
},
where: { id: clientId },
};
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get('Clients', { params });
const [client] = data;
selectedClient.value = client;
};
const fetchAddresses = async (clientId) => {
if (!clientId) return;
const filter = {
fields: ['nickname', 'street', 'city', 'id', 'isActive'],
order: ['isDefaultAddress DESC', 'isActive DESC', 'nickname ASC'],
};
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get(`Clients/${clientId}/addresses`, {
params,
});
addressesOptions.value = data;
const { defaultAddress } = selectedClient.value;
address.value = defaultAddress.id;
};
const actions = { const actions = {
clone: async () => { clone: async () => {
const opts = { message: t('Ticket cloned'), type: 'positive' }; const opts = { message: t('Ticket cloned'), type: 'positive' };
@ -260,17 +302,14 @@ async function makeInvoice() {
window.location.reload(); window.location.reload();
} }
async function transferClient(client) { async function transferClient(client, address) {
const params = { const params = {
clientFk: client, clientFk: client,
addressFk: address,
}; };
const { data } = await axios.patch( await axios.patch( `Tickets/${ticketId.value}/transferClient`, params );
`Tickets/${ticketId.value}/transferClient`, window.location.reload();
params
);
if (data) window.location.reload();
} }
async function addTurn(day) { async function addTurn(day) {
@ -446,7 +485,7 @@ async function ticketToRestore() {
</QItem> </QItem>
<QDialog ref="dialogRef" v-model="showTransferDialog"> <QDialog ref="dialogRef" v-model="showTransferDialog">
<FormPopup <FormPopup
@on-submit="transferClient(client)" @on-submit="transferClient(client, address)"
:title="t('Transfer client')" :title="t('Transfer client')"
:custom-submit-button-label="t('Transfer client')" :custom-submit-button-label="t('Transfer client')"
:default-cancel-button="false" :default-cancel-button="false"
@ -454,10 +493,11 @@ async function ticketToRestore() {
<template #form-inputs> <template #form-inputs>
<VnSelect <VnSelect
url="Clients" url="Clients"
:fields="['id', 'name']" :fields="['id', 'name', 'defaultAddressFk']"
v-model="client" v-model="client"
:label="t('Client')" :label="t('Client')"
auto-load auto-load
@update:model-value="() => onClientSelected(client)"
> >
<template #option="scope"> <template #option="scope">
<QItem v-bind="scope.itemProps"> <QItem v-bind="scope.itemProps">
@ -470,6 +510,28 @@ async function ticketToRestore() {
</QItem> </QItem>
</template> </template>
</VnSelect> </VnSelect>
<VnSelect
:disable="!client"
:options="addressesOptions"
:fields="['id', 'nickname']"
option-value="id"
option-label="nickname"
v-model="address"
:label="t('ticketList.addressNickname')"
auto-load
:hint="!client ? t('Select a client to enable') : ''"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel>
{{ `#${scope.opt.id} - ` }}
{{ scope.opt.nickname }}
</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
</template> </template>
</FormPopup> </FormPopup>
</QDialog> </QDialog>
@ -762,7 +824,7 @@ async function ticketToRestore() {
en: en:
addTurn: Add turn addTurn: Add turn
invoiceIds: "Invoices have been generated with the following ids: {invoiceIds}" invoiceIds: "Invoices have been generated with the following ids: {invoiceIds}"
es: es:
Show Delivery Note...: Ver albarán... Show Delivery Note...: Ver albarán...
Send Delivery Note...: Enviar albarán... Send Delivery Note...: Enviar albarán...
@ -814,4 +876,5 @@ es:
Are you sure you want to restore the ticket?: ¿Seguro que quieres restaurar el ticket? Are you sure you want to restore the ticket?: ¿Seguro que quieres restaurar el ticket?
You are going to restore this ticket: Vas a restaurar este ticket You are going to restore this ticket: Vas a restaurar este ticket
Ticket restored: Ticket restaurado Ticket restored: Ticket restaurado
Select a client to enable: Selecciona un cliente para habilitar
</i18n> </i18n>