salix-front/src/components/TransferInvoiceForm.vue

225 lines
8.2 KiB
Vue
Raw Normal View History

2024-02-15 14:36:53 +00:00
<script setup>
2024-05-10 05:04:03 +00:00
import { ref, reactive } from 'vue';
2024-02-15 14:36:53 +00:00
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { useQuasar } from 'quasar';
import VnConfirm from 'components/ui/VnConfirm.vue';
2024-02-15 14:36:53 +00:00
import VnRow from 'components/ui/VnRow.vue';
import FetchData from 'components/FetchData.vue';
2024-04-23 11:03:32 +00:00
import VnSelect from 'components/common/VnSelect.vue';
2024-02-21 14:27:32 +00:00
import FormPopup from './FormPopup.vue';
import { useDialogPluginComponent } from 'quasar';
2024-02-15 14:36:53 +00:00
import axios from 'axios';
import useNotify from 'src/composables/useNotify.js';
const $props = defineProps({
invoiceOutData: {
type: Object,
default: () => {},
},
});
const { dialogRef } = useDialogPluginComponent();
const quasar = useQuasar();
2024-02-15 14:36:53 +00:00
const { t } = useI18n();
const router = useRouter();
const { notify } = useNotify();
const checked = ref(true);
2024-02-15 14:36:53 +00:00
const transferInvoiceParams = reactive({
id: $props.invoiceOutData?.id,
});
2024-05-10 05:04:03 +00:00
2024-02-15 14:36:53 +00:00
const rectificativeTypeOptions = ref([]);
const siiTypeInvoiceOutsOptions = ref([]);
const invoiceCorrectionTypesOptions = ref([]);
2024-05-10 05:04:03 +00:00
const selectedClient = (client) => {
transferInvoiceParams.selectedClientData = client;
};
const makeInvoice = async () => {
2024-05-10 05:04:03 +00:00
const hasToInvoiceByAddress =
transferInvoiceParams.selectedClientData.hasToInvoiceByAddress;
const params = {
id: transferInvoiceParams.id,
cplusRectificationTypeFk: transferInvoiceParams.cplusRectificationTypeFk,
invoiceCorrectionTypeFk: transferInvoiceParams.invoiceCorrectionTypeFk,
newClientFk: transferInvoiceParams.newClientFk,
siiTypeInvoiceOutFk: transferInvoiceParams.siiTypeInvoiceOutFk,
2024-06-14 09:44:02 +00:00
makeInvoice: checked.value,
};
2024-02-15 14:36:53 +00:00
try {
2024-05-10 05:04:03 +00:00
if (checked.value && hasToInvoiceByAddress) {
const response = await new Promise((resolve) => {
quasar
.dialog({
component: VnConfirm,
componentProps: {
title: t('Bill destination client'),
message: t('transferInvoiceInfo'),
},
})
.onOk(() => {
resolve(true);
})
.onCancel(() => {
resolve(false);
});
});
2024-05-10 05:04:03 +00:00
if (!response) {
return;
}
}
2024-09-03 13:25:36 +00:00
const { data } = await axios.post('InvoiceOuts/transfer', params);
notify(t('Transferred invoice'), 'positive');
const id = data?.[0];
if (id) router.push({ name: 'InvoiceOutSummary', params: { id } });
2024-02-15 14:36:53 +00:00
} catch (err) {
console.error('Error transfering invoice', err);
}
};
</script>
<template>
<FetchData
url="CplusRectificationTypes"
:filter="{ order: 'description' }"
@on-fetch="
(data) => (
(rectificativeTypeOptions = data),
2024-05-10 05:04:03 +00:00
(transferInvoiceParams.cplusRectificationTypeFk = data.filter(
(type) => type.description == 'I Por diferencias'
)[0].id)
)
"
2024-02-15 14:36:53 +00:00
auto-load
/>
<FetchData
url="SiiTypeInvoiceOuts"
:filter="{ where: { code: { like: 'R%' } } }"
@on-fetch="
(data) => (
(siiTypeInvoiceOutsOptions = data),
2024-05-10 05:04:03 +00:00
(transferInvoiceParams.siiTypeInvoiceOutFk = data.filter(
(type) => type.code == 'R4'
)[0].id)
)
"
2024-02-15 14:36:53 +00:00
auto-load
/>
<FetchData
url="InvoiceCorrectionTypes"
@on-fetch="(data) => (invoiceCorrectionTypesOptions = data)"
auto-load
/>
<QDialog ref="dialogRef">
<FormPopup
2024-07-26 07:27:38 +00:00
@on-submit="makeInvoice()"
:title="t('Transfer invoice')"
:custom-submit-button-label="t('Transfer client')"
:default-cancel-button="false"
>
2024-07-26 07:27:38 +00:00
<template #form-inputs>
<VnRow>
<VnSelect
:label="t('Client')"
:options="clientsOptions"
hide-selected
option-label="name"
option-value="id"
v-model="transferInvoiceParams.newClientFk"
:required="true"
url="Clients"
:fields="['id', 'name', 'hasToInvoiceByAddress']"
auto-load
>
<template #option="scope">
<QItem
v-bind="scope.itemProps"
@click="selectedClient(scope.opt)"
>
<QItemSection>
<QItemLabel>
#{{ scope.opt?.id }} - {{ scope.opt?.name }}
</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
<VnSelect
:label="t('Rectificative type')"
:options="rectificativeTypeOptions"
hide-selected
option-label="description"
option-value="id"
v-model="transferInvoiceParams.cplusRectificationTypeFk"
:required="true"
/>
</VnRow>
2024-07-26 07:27:38 +00:00
<VnRow>
<VnSelect
:label="t('Class')"
:options="siiTypeInvoiceOutsOptions"
hide-selected
option-label="description"
option-value="id"
v-model="transferInvoiceParams.siiTypeInvoiceOutFk"
:required="true"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel>
{{ scope.opt?.code }} -
{{ scope.opt?.description }}
</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
<VnSelect
:label="t('Type')"
:options="invoiceCorrectionTypesOptions"
hide-selected
option-label="description"
option-value="id"
v-model="transferInvoiceParams.invoiceCorrectionTypeFk"
:required="true"
/>
</VnRow>
2024-07-26 07:27:38 +00:00
<VnRow>
<div>
2024-07-26 07:27:38 +00:00
<QCheckbox
:label="t('Bill destination client')"
v-model="checked"
/>
<QIcon name="info" class="cursor-info q-ml-sm" size="sm">
<QTooltip>{{ t('transferInvoiceInfo') }}</QTooltip>
</QIcon>
</div>
</VnRow>
</template>
</FormPopup>
</QDialog>
2024-02-15 14:36:53 +00:00
</template>
<i18n>
en:
checkInfo: New tickets from the destination customer will be generated in the consignee by default.
transferInvoiceInfo: Destination customer is marked to bill in the consignee
2024-05-10 05:04:03 +00:00
confirmTransferInvoice: The destination customer has selected to bill in the consignee, do you want to continue?
2024-02-15 14:36:53 +00:00
es:
Transfer invoice: Transferir factura
Transfer client: Transferir cliente
Client: Cliente
Rectificative type: Tipo rectificativa
Class: Clase
Type: Tipo
Transferred invoice: Factura transferida
Bill destination client: Facturar cliente destino
2024-05-10 05:04:03 +00:00
transferInvoiceInfo: Los nuevos tickets del cliente destino, serán generados en el consignatario por defecto.
confirmTransferInvoice: El cliente destino tiene marcado facturar por consignatario, desea continuar?
2024-02-15 14:36:53 +00:00
</i18n>