diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index 9585bf7fb..5d6b1f65b 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -565,7 +565,7 @@ export default { fillDates: 'Invoice date and the max date should be filled', invoiceDateLessThanMaxDate: 'Invoice date can not be less than max date', invoiceWithFutureDate: 'Exists an invoice with a future date', - noTicketsToInvoice: 'There are not clients to invoice', + noTicketsToInvoice: 'There are not tickets to invoice', criticalInvoiceError: 'Critical invoicing error, process stopped', }, table: { diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index 30e982ea2..5c60e840d 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -567,7 +567,7 @@ export default { invoiceDateLessThanMaxDate: 'La fecha de la factura no puede ser menor que la fecha máxima', invoiceWithFutureDate: 'Existe una factura con una fecha futura', - noTicketsToInvoice: 'No hay clientes para facturar', + noTicketsToInvoice: 'No existen tickets para facturar', criticalInvoiceError: 'Error crítico en la facturación, proceso detenido', }, table: { diff --git a/src/pages/InvoiceOut/InvoiceOutGlobalForm.vue b/src/pages/InvoiceOut/InvoiceOutGlobalForm.vue index c61b9f7ff..a000d6d4f 100644 --- a/src/pages/InvoiceOut/InvoiceOutGlobalForm.vue +++ b/src/pages/InvoiceOut/InvoiceOutGlobalForm.vue @@ -13,13 +13,8 @@ const { t } = useI18n(); const invoiceOutGlobalStore = useInvoiceOutGlobalStore(); // invoiceOutGlobalStore state and getters -const { - initialDataLoading, - formInitialData, - - invoicing, - status, -} = storeToRefs(invoiceOutGlobalStore); +const { initialDataLoading, formInitialData, invoicing, status } = + storeToRefs(invoiceOutGlobalStore); // invoiceOutGlobalStore actions const { makeInvoice, setStatusValue } = invoiceOutGlobalStore; @@ -32,13 +27,7 @@ const printersOptions = ref([]); const clientsOptions = ref([]); -const formData = ref({ - companyFk: null, - invoiceDate: null, - maxShipped: null, - clientId: null, - printer: null, -}); +const formData = ref({}); const optionsInitialData = computed(() => { return ( diff --git a/src/stores/invoiceOutGlobal.js b/src/stores/invoiceOutGlobal.js index 7151aac5f..9929a0127 100644 --- a/src/stores/invoiceOutGlobal.js +++ b/src/stores/invoiceOutGlobal.js @@ -73,6 +73,9 @@ export const useInvoiceOutGlobalStore = defineStore({ const stringDate = data.issued.substring(0, 10); this.minInvoicingDate = stringDate; this.formInitialData.invoiceDate = stringDate; + + this.minInvoicingDate = new Date(data.issued); + this.formInitialData.invoiceDate = this.minInvoicingDate; } catch (err) { console.error('Error fetching invoice out global initial data'); throw new Error(); @@ -103,12 +106,9 @@ export const useInvoiceOutGlobalStore = defineStore({ if (clientsToInvoice == 'all') params.clientId = undefined; - const addressesResponse = await await axios.post( - 'InvoiceOuts/clientsToInvoice', - params - ); + const { data } = await axios.post('InvoiceOuts/clientsToInvoice', params); - this.addresses = addressesResponse.data; + this.addresses = data; if (!this.addresses || !this.addresses.length > 0) { notify( @@ -118,9 +118,9 @@ export const useInvoiceOutGlobalStore = defineStore({ throw new Error("There aren't addresses to invoice"); } - this.addresses.forEach(async (address) => { + for (const address of this.addresses) { await this.invoiceClient(address, formData); - }); + } } catch (err) { this.handleError(err); } @@ -186,13 +186,10 @@ export const useInvoiceOutGlobalStore = defineStore({ this.status = 'invoicing'; this.invoicing = true; - const invoiceResponse = await axios.post( - 'InvoiceOuts/invoiceClient', - params - ); + const { data } = await axios.post('InvoiceOuts/invoiceClient', params); - if (invoiceResponse.data) { - this.makePdfAndNotify(invoiceResponse.data, address); + if (data) { + await this.makePdfAndNotify(data, address); } this.isInvoicing = false; @@ -203,7 +200,7 @@ export const useInvoiceOutGlobalStore = defineStore({ err.response.status >= 400 && err.response.status < 500 ) { - this.invoiceClientError(address, err.response); + this.invoiceClientError(address, err.response?.data?.error?.message); this.addressIndex++; return; } else { @@ -227,12 +224,11 @@ export const useInvoiceOutGlobalStore = defineStore({ this.nPdfs++; this.nRequests--; } catch (err) { - this.invoiceClientError(client, err, true); + this.invoiceClientError(client, err.response?.data?.error?.message, true); } }, - invoiceClientError(client, response, isWarning) { - const message = response.data?.error?.message || response.message; + invoiceClientError(client, message, isWarning) { this.errors.unshift({ client, message, isWarning }); },