feat: refs #6739 transferInvoice new checkbox and functionality #352
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
|
@ -21,6 +21,8 @@ const $props = defineProps({
|
|||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const { notify } = useNotify();
|
||||
const checked = ref(true);
|
||||
let skip = 0;
|
||||
|
||||
const transferInvoiceParams = reactive({
|
||||
id: $props.invoiceOutData?.id,
|
||||
|
@ -36,15 +38,74 @@ const closeForm = () => {
|
|||
if (closeButton.value) closeButton.value.click();
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchClients();
|
||||
});
|
||||
|
||||
const fetchClients = async () => {
|
||||
try {
|
||||
const filter = {
|
||||
skip: skip,
|
||||
order: 'id DESC',
|
||||
limit: 10,
|
||||
};
|
||||
jon marked this conversation as resolved
Outdated
|
||||
const { data } = await axios.get('http://localhost:9000/api/Clients/filter', {
|
||||
params: {
|
||||
filter: serializeFilter(filter),
|
||||
jon marked this conversation as resolved
Outdated
alexm
commented
No se debe poner en el código nada referente al entorno (en este caso local). Como esta hecho abajo: De todas maneras, para tablas grandes, como es este caso de Client, es mejor usar la propiedad No se debe poner en el código nada referente al entorno (en este caso local). Como esta hecho abajo:
` const { data } = await axios.post('InvoiceOuts/transferInvoice', params);`
Se debe poner directamente el modulo al que se hace la petición porque axios ya tiene puesto que dependiendo del entorno apunte a (local/dev/test/master)
De todas maneras, para tablas grandes, como es este caso de Client, es mejor usar la propiedad `url` del componente `VnSelect` así el propio componente ya se encarga de la paginación
|
||||
},
|
||||
});
|
||||
clientsOptions.value = [...clientsOptions.value, ...data];
|
||||
skip += 10;
|
||||
} catch (error) {
|
||||
console.error('Error fetching clients:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const serializeFilter = (filter) => {
|
||||
let serializedFilter = '{';
|
||||
for (const key in filter) {
|
||||
jon marked this conversation as resolved
Outdated
alexm
commented
Al usar la propiedad Al usar la propiedad `url` de `VnSelect` se evita este código
|
||||
serializedFilter += `"${key}":${JSON.stringify(filter[key])},`;
|
||||
}
|
||||
serializedFilter = serializedFilter.slice(0, -1);
|
||||
serializedFilter += '}';
|
||||
return serializedFilter;
|
||||
};
|
||||
|
||||
const handleScroll = async () => {
|
||||
const selectEl = document.querySelector('.vn-select');
|
||||
if (selectEl.scrollTop + selectEl.clientHeight >= selectEl.scrollHeight) {
|
||||
jon marked this conversation as resolved
Outdated
alexm
commented
Al usar la propiedad Al usar la propiedad `url` de `VnSelect` se evita este código
|
||||
await fetchClients();
|
||||
}
|
||||
};
|
||||
alexm
commented
data.?id data.?id
Data puede que sea null
|
||||
|
||||
const transferInvoice = async () => {
|
||||
try {
|
||||
const { data } = await axios.post(
|
||||
'InvoiceOuts/transferInvoice',
|
||||
transferInvoiceParams
|
||||
const clientDetails = await axios.get(
|
||||
`Clients/${transferInvoiceParams.newClientFk}`
|
||||
);
|
||||
notify(t('Transferred invoice'), 'positive');
|
||||
closeForm();
|
||||
alexm
commented
Y closeForm si lo querias? o no hace falta? Y closeForm si lo querias? o no hace falta?
|
||||
router.push('InvoiceOutSummary', { id: data.id });
|
||||
const hasToInvoiceByAddress = clientDetails.data.hasToInvoiceByAddress;
|
||||
|
||||
if (checked.value && hasToInvoiceByAddress) {
|
||||
const confirmed = confirm(t('confirmationInfo'));
|
||||
|
||||
if (confirmed) {
|
||||
const { data } = await axios.post(
|
||||
'InvoiceOuts/transferInvoice',
|
||||
transferInvoiceParams
|
||||
jon marked this conversation as resolved
Outdated
alexm
commented
Al componente VnSelect si le pides el campo Al componente VnSelect si le pides el campo `hasToInvoiceByAddress` en el fields ya te lo devuelve y no hace falta volver a pedir los datos del cliente
|
||||
);
|
||||
notify(t('Transferred invoice'), 'positive');
|
||||
closeForm();
|
||||
router.push('InvoiceOutSummary', { id: data.id });
|
||||
}
|
||||
} else {
|
||||
const { data } = await axios.post(
|
||||
'InvoiceOuts/transferInvoice',
|
||||
transferInvoiceParams
|
||||
);
|
||||
notify(t('Transferred invoice'), 'positive');
|
||||
closeForm();
|
||||
router.push('InvoiceOutSummary', { id: data.id });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error transfering invoice', err);
|
||||
}
|
||||
|
@ -61,13 +122,23 @@ const transferInvoice = async () => {
|
|||
<FetchData
|
||||
url="CplusRectificationTypes"
|
||||
:filter="{ order: 'description' }"
|
||||
@on-fetch="(data) => (rectificativeTypeOptions = data)"
|
||||
@on-fetch="
|
||||
(data) => (
|
||||
(rectificativeTypeOptions = data),
|
||||
(transferInvoiceParams.cplusRectificationTypeFk = data[1].id)
|
||||
)
|
||||
"
|
||||
jon marked this conversation as resolved
Outdated
alexm
commented
Esta parte hacerla como se ha hecho en salix, filtrando por code si se puede y sino por description Esta parte hacerla como se ha hecho en salix, filtrando por code si se puede y sino por description
|
||||
auto-load
|
||||
/>
|
||||
<FetchData
|
||||
url="SiiTypeInvoiceOuts"
|
||||
:filter="{ where: { code: { like: 'R%' } } }"
|
||||
@on-fetch="(data) => (siiTypeInvoiceOutsOptions = data)"
|
||||
@on-fetch="
|
||||
(data) => (
|
||||
(siiTypeInvoiceOutsOptions = data),
|
||||
(transferInvoiceParams.siiTypeInvoiceOutFk = data[3].id)
|
||||
)
|
||||
"
|
||||
jon marked this conversation as resolved
Outdated
alexm
commented
Esta parte hacerla como se ha hecho en salix, filtrando por code si se puede y sino por description Esta parte hacerla como se ha hecho en salix, filtrando por code si se puede y sino por description
|
||||
auto-load
|
||||
/>
|
||||
<FetchData
|
||||
|
@ -92,6 +163,7 @@ const transferInvoice = async () => {
|
|||
option-value="id"
|
||||
v-model="transferInvoiceParams.newClientFk"
|
||||
:required="true"
|
||||
@scroll="handleScroll"
|
||||
>
|
||||
<template #option="scope">
|
||||
<QItem v-bind="scope.itemProps">
|
||||
|
@ -152,11 +224,22 @@ const transferInvoice = async () => {
|
|||
/>
|
||||
</div>
|
||||
</VnRow>
|
||||
<VnRow class="row q-gutter-md q-mb-md">
|
||||
<div>
|
||||
<QCheckbox :label="t('Bill destination client')" v-model="checked" />
|
||||
<QIcon name="info" class="cursor-info q-ml-sm" size="sm">
|
||||
<QTooltip>{{ t('checkInfo') }}</QTooltip>
|
||||
</QIcon>
|
||||
</div>
|
||||
</VnRow>
|
||||
</template>
|
||||
</FormPopup>
|
||||
</template>
|
||||
|
||||
<i18n>
|
||||
en:
|
||||
checkInfo: New tickets from the destination customer will be generated in the consignee by default.
|
||||
confirmationInfo: Destination customer is marked to bill in the consignee, do you want to continue?
|
||||
es:
|
||||
Transfer invoice: Transferir factura
|
||||
Transfer client: Transferir cliente
|
||||
|
@ -165,4 +248,7 @@ es:
|
|||
Class: Clase
|
||||
Type: Tipo
|
||||
Transferred invoice: Factura transferida
|
||||
Bill destination client: Facturar cliente destino
|
||||
checkInfo: Los nuevos tickets del cliente destino, serán generados en el consignatario por defecto.
|
||||
confirmationInfo: El cliente destino tiene marcado facturar por consignatario, desea continuar?
|
||||
</i18n>
|
||||
|
|
cambiar a makeInvoice