Invoice out globals corrections

This commit is contained in:
William Buezas 2024-02-12 08:11:44 -03:00
parent 248e02f530
commit df620566ef
4 changed files with 18 additions and 33 deletions

View File

@ -565,7 +565,7 @@ export default {
fillDates: 'Invoice date and the max date should be filled', fillDates: 'Invoice date and the max date should be filled',
invoiceDateLessThanMaxDate: 'Invoice date can not be less than max date', invoiceDateLessThanMaxDate: 'Invoice date can not be less than max date',
invoiceWithFutureDate: 'Exists an invoice with a future 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', criticalInvoiceError: 'Critical invoicing error, process stopped',
}, },
table: { table: {

View File

@ -567,7 +567,7 @@ export default {
invoiceDateLessThanMaxDate: invoiceDateLessThanMaxDate:
'La fecha de la factura no puede ser menor que la fecha máxima', 'La fecha de la factura no puede ser menor que la fecha máxima',
invoiceWithFutureDate: 'Existe una factura con una fecha futura', 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', criticalInvoiceError: 'Error crítico en la facturación, proceso detenido',
}, },
table: { table: {

View File

@ -13,13 +13,8 @@ const { t } = useI18n();
const invoiceOutGlobalStore = useInvoiceOutGlobalStore(); const invoiceOutGlobalStore = useInvoiceOutGlobalStore();
// invoiceOutGlobalStore state and getters // invoiceOutGlobalStore state and getters
const { const { initialDataLoading, formInitialData, invoicing, status } =
initialDataLoading, storeToRefs(invoiceOutGlobalStore);
formInitialData,
invoicing,
status,
} = storeToRefs(invoiceOutGlobalStore);
// invoiceOutGlobalStore actions // invoiceOutGlobalStore actions
const { makeInvoice, setStatusValue } = invoiceOutGlobalStore; const { makeInvoice, setStatusValue } = invoiceOutGlobalStore;
@ -32,13 +27,7 @@ const printersOptions = ref([]);
const clientsOptions = ref([]); const clientsOptions = ref([]);
const formData = ref({ const formData = ref({});
companyFk: null,
invoiceDate: null,
maxShipped: null,
clientId: null,
printer: null,
});
const optionsInitialData = computed(() => { const optionsInitialData = computed(() => {
return ( return (

View File

@ -73,6 +73,9 @@ export const useInvoiceOutGlobalStore = defineStore({
const stringDate = data.issued.substring(0, 10); const stringDate = data.issued.substring(0, 10);
this.minInvoicingDate = stringDate; this.minInvoicingDate = stringDate;
this.formInitialData.invoiceDate = stringDate; this.formInitialData.invoiceDate = stringDate;
this.minInvoicingDate = new Date(data.issued);
this.formInitialData.invoiceDate = this.minInvoicingDate;
} catch (err) { } catch (err) {
console.error('Error fetching invoice out global initial data'); console.error('Error fetching invoice out global initial data');
throw new Error(); throw new Error();
@ -103,12 +106,9 @@ export const useInvoiceOutGlobalStore = defineStore({
if (clientsToInvoice == 'all') params.clientId = undefined; if (clientsToInvoice == 'all') params.clientId = undefined;
const addressesResponse = await await axios.post( const { data } = await axios.post('InvoiceOuts/clientsToInvoice', params);
'InvoiceOuts/clientsToInvoice',
params
);
this.addresses = addressesResponse.data; this.addresses = data;
if (!this.addresses || !this.addresses.length > 0) { if (!this.addresses || !this.addresses.length > 0) {
notify( notify(
@ -118,9 +118,9 @@ export const useInvoiceOutGlobalStore = defineStore({
throw new Error("There aren't addresses to invoice"); 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); await this.invoiceClient(address, formData);
}); }
} catch (err) { } catch (err) {
this.handleError(err); this.handleError(err);
} }
@ -186,13 +186,10 @@ export const useInvoiceOutGlobalStore = defineStore({
this.status = 'invoicing'; this.status = 'invoicing';
this.invoicing = true; this.invoicing = true;
const invoiceResponse = await axios.post( const { data } = await axios.post('InvoiceOuts/invoiceClient', params);
'InvoiceOuts/invoiceClient',
params
);
if (invoiceResponse.data) { if (data) {
this.makePdfAndNotify(invoiceResponse.data, address); await this.makePdfAndNotify(data, address);
} }
this.isInvoicing = false; this.isInvoicing = false;
@ -203,7 +200,7 @@ export const useInvoiceOutGlobalStore = defineStore({
err.response.status >= 400 && err.response.status >= 400 &&
err.response.status < 500 err.response.status < 500
) { ) {
this.invoiceClientError(address, err.response); this.invoiceClientError(address, err.response?.data?.error?.message);
this.addressIndex++; this.addressIndex++;
return; return;
} else { } else {
@ -227,12 +224,11 @@ export const useInvoiceOutGlobalStore = defineStore({
this.nPdfs++; this.nPdfs++;
this.nRequests--; this.nRequests--;
} catch (err) { } catch (err) {
this.invoiceClientError(client, err, true); this.invoiceClientError(client, err.response?.data?.error?.message, true);
} }
}, },
invoiceClientError(client, response, isWarning) { invoiceClientError(client, message, isWarning) {
const message = response.data?.error?.message || response.message;
this.errors.unshift({ client, message, isWarning }); this.errors.unshift({ client, message, isWarning });
}, },