refator: cancel request
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
0d785695fe
commit
50ec41dece
|
@ -30,10 +30,14 @@ module.exports = Self => {
|
|||
description: 'The company id to invoice'
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
returns: [{
|
||||
arg: 'clientsAndAddresses',
|
||||
type: ['object']
|
||||
},
|
||||
{
|
||||
arg: 'invoice',
|
||||
type: 'object'
|
||||
}],
|
||||
http: {
|
||||
path: '/clientToInvoice',
|
||||
verb: 'POST'
|
||||
|
@ -94,23 +98,30 @@ module.exports = Self => {
|
|||
|
||||
const invoiceableClients = await getInvoiceableClients(ctx, myOptions);
|
||||
|
||||
if (!invoiceableClients.length) return;
|
||||
if (!invoiceableClients) return;
|
||||
|
||||
const clientAndAddress = invoiceableClients.map(
|
||||
invoiceableClient => [invoiceableClient.id, invoiceableClient.addressFk]
|
||||
const clientsAndAddresses = invoiceableClients.map(invoiceableClient => {
|
||||
return {
|
||||
clientId: invoiceableClient.id,
|
||||
addressId: invoiceableClient.addressFk
|
||||
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return {
|
||||
clientAndAddressIds: clientAndAddress,
|
||||
invoiceDate: args.invoiceDate,
|
||||
maxShipped: args.maxShipped,
|
||||
fromClientId: args.fromClientId,
|
||||
toClientId: args.toClientId,
|
||||
companyFk: args.companyFk,
|
||||
minShipped: minShipped
|
||||
};
|
||||
return [
|
||||
clientsAndAddresses,
|
||||
{
|
||||
invoiceDate: args.invoiceDate,
|
||||
maxShipped: args.maxShipped,
|
||||
fromClientId: args.fromClientId,
|
||||
toClientId: args.toClientId,
|
||||
companyFk: args.companyFk,
|
||||
minShipped: minShipped
|
||||
}
|
||||
];
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('globalInvoicing', {
|
||||
description: 'Make a global invoice of a client',
|
||||
description: 'Make a invoice of a client',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'clientId',
|
||||
|
@ -17,17 +17,20 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'invoiceDate',
|
||||
type: 'date',
|
||||
description: 'The invoice date'
|
||||
description: 'The invoice date',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'maxShipped',
|
||||
type: 'date',
|
||||
description: 'The maximum shipped date'
|
||||
description: 'The maximum shipped date',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'fromClientId',
|
||||
type: 'number',
|
||||
description: 'The minimum client id'
|
||||
description: 'The minimum client id',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'toClientId',
|
||||
|
@ -38,12 +41,14 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'companyFk',
|
||||
type: 'number',
|
||||
description: 'The company id to invoice'
|
||||
description: 'The company id to invoice',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'minShipped',
|
||||
type: 'date',
|
||||
description: 'The company id to invoice'
|
||||
description: 'The company id to invoice',
|
||||
required: true
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
|
@ -72,7 +77,6 @@ module.exports = Self => {
|
|||
const invoicesIds = [];
|
||||
const failedClients = [];
|
||||
try {
|
||||
// const addresses = await models.Address.find({where: {clientFk: args.clientId}}, myOptions);
|
||||
const client = await models.Client.findById(args.clientId, {
|
||||
fields: ['id', 'hasToInvoiceByAddress']
|
||||
}, myOptions);
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
</vn-crud-model>
|
||||
<div
|
||||
class="progress vn-my-md"
|
||||
ng-if="$ctrl.isInvoicing">
|
||||
ng-if="$ctrl.lastClientId">
|
||||
<vn-horizontal>
|
||||
<vn-icon vn-none icon="warning"></vn-icon>
|
||||
{{$ctrl.currentClientId}} {{$ctrl.$t('of')}} {{$ctrl.lastClientId}}
|
||||
<div>
|
||||
{{'Id Client' | translate}}: {{$ctrl.currentClientId}}
|
||||
{{'of' | translate}} {{::$ctrl.lastClientId}}
|
||||
</div>
|
||||
</vn-horizontal>
|
||||
</div>
|
||||
<vn-horizontal>
|
||||
|
@ -66,5 +68,5 @@
|
|||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate vn-focus>Invoice</button>
|
||||
<button vn-id="invoiceButton" response="accept" translate>Invoice</button>{{$ctrl.isInvoicing}}
|
||||
</tpl-buttons>
|
|
@ -6,7 +6,7 @@ class Controller extends Dialog {
|
|||
constructor($element, $, $transclude) {
|
||||
super($element, $, $transclude);
|
||||
|
||||
this.isInvoicing = false;
|
||||
this.lastClientId = null;
|
||||
this.invoice = {
|
||||
maxShipped: new Date()
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ class Controller extends Dialog {
|
|||
this.invoice.companyFk = value;
|
||||
}
|
||||
|
||||
responseHandler(response) {
|
||||
async responseHandler(response) {
|
||||
try {
|
||||
if (response !== 'accept')
|
||||
return super.responseHandler(response);
|
||||
|
@ -57,25 +57,49 @@ class Controller extends Dialog {
|
|||
if (!this.invoice.fromClientId)
|
||||
throw new Error('Choose a valid clients range');
|
||||
|
||||
this.on('close', () => {
|
||||
if (this.canceler) this.canceler.resolve();
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
});
|
||||
|
||||
return this.$http.post(`InvoiceOuts/clientToInvoice`, this.invoice)
|
||||
.then(async res => {
|
||||
const clientAndAddressIds = res.data.clientAndAddressIds;
|
||||
if (!clientAndAddressIds) return super.responseHandler(response);
|
||||
this.lastClientId = clientAndAddressIds[clientAndAddressIds.length - 1][0];
|
||||
this.isInvoicing = true;
|
||||
for (let clientAndAddresId of clientAndAddressIds) {
|
||||
this.currentClientId = clientAndAddresId[0];
|
||||
res.data.clientId = clientAndAddresId[0];
|
||||
res.data.addressId = clientAndAddresId[1];
|
||||
await this.$http.post(`InvoiceOuts/globalInvoicing`, res.data);
|
||||
const clientsAndAddresses = res.data.clientsAndAddresses;
|
||||
const invoice = res.data.invoice;
|
||||
|
||||
if (!clientsAndAddresses.length) return super.responseHandler(response);
|
||||
this.lastClientId = clientsAndAddresses[clientsAndAddresses.length - 1].clientId;
|
||||
this.$.invoiceButton.setAttribute('disabled', true);
|
||||
for (let clientAndAddress of clientsAndAddresses) {
|
||||
this.currentClientId = clientAndAddress.clientId;
|
||||
const params = {
|
||||
clientId: clientAndAddress.clientId,
|
||||
addressId: clientAndAddress.addressId,
|
||||
invoiceDate: invoice.invoiceDate,
|
||||
maxShipped: invoice.maxShipped,
|
||||
fromClientId: invoice.fromClientId,
|
||||
toClientId: invoice.toClientId,
|
||||
companyFk: invoice.companyFk,
|
||||
minShipped: invoice.minShipped,
|
||||
|
||||
};
|
||||
this.canceler = this.$q.defer();
|
||||
const options = {
|
||||
timeout: this.canceler.promise
|
||||
};
|
||||
await this.$http.post(`InvoiceOuts/globalInvoicing`, params, options);
|
||||
}
|
||||
})
|
||||
.then(() => super.responseHandler(response))
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||
.finally(() => this.isInvoicing = false);
|
||||
.finally(() => {
|
||||
this.lastClientId = null;
|
||||
this.$.invoiceButton.removeAttribute('disabled');
|
||||
});
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
this.isInvoicing = false;
|
||||
this.lastClientId = null;
|
||||
this.$.invoiceButton.removeAttribute('disabled');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,4 +7,5 @@ From client: Desde el cliente
|
|||
To client: Hasta el cliente
|
||||
Invoice date and the max date should be filled: La fecha de factura y la fecha límite deben rellenarse
|
||||
Choose a valid clients range: Selecciona un rango válido de clientes
|
||||
of: de
|
||||
of: de
|
||||
Id Client: Id Cliente
|
Loading…
Reference in New Issue