forked from verdnatura/salix-front
feat: refs #6739 transferInvoice new checkbox and functionality
This commit is contained in:
parent
e3a36c0ab1
commit
5ed2a82194
|
@ -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,
|
||||
};
|
||||
const { data } = await axios.get('http://localhost:9000/api/Clients/filter', {
|
||||
params: {
|
||||
filter: serializeFilter(filter),
|
||||
},
|
||||
});
|
||||
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) {
|
||||
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) {
|
||||
await fetchClients();
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
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
|
||||
);
|
||||
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)
|
||||
)
|
||||
"
|
||||
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)
|
||||
)
|
||||
"
|
||||
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>
|
||||
|
|
Loading…
Reference in New Issue