4090-global_invoincing #1135
|
@ -30,10 +30,14 @@ module.exports = Self => {
|
||||||
description: 'The company id to invoice'
|
description: 'The company id to invoice'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: [{
|
||||||
type: 'object',
|
arg: 'clientsAndAddresses',
|
||||||
root: true
|
type: ['object']
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'invoice',
|
||||||
|
type: 'object'
|
||||||
|
}],
|
||||||
http: {
|
http: {
|
||||||
path: '/clientToInvoice',
|
path: '/clientToInvoice',
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
|
@ -94,23 +98,30 @@ module.exports = Self => {
|
||||||
|
|
||||||
const invoiceableClients = await getInvoiceableClients(ctx, myOptions);
|
const invoiceableClients = await getInvoiceableClients(ctx, myOptions);
|
||||||
|
|
||||||
if (!invoiceableClients.length) return;
|
if (!invoiceableClients) return;
|
||||||
|
|
||||||
const clientAndAddress = invoiceableClients.map(
|
const clientsAndAddresses = invoiceableClients.map(invoiceableClient => {
|
||||||
invoiceableClient => [invoiceableClient.id, invoiceableClient.addressFk]
|
return {
|
||||||
|
clientId: invoiceableClient.id,
|
||||||
|
addressId: invoiceableClient.addressFk
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return {
|
return [
|
||||||
clientAndAddressIds: clientAndAddress,
|
clientsAndAddresses,
|
||||||
invoiceDate: args.invoiceDate,
|
{
|
||||||
maxShipped: args.maxShipped,
|
invoiceDate: args.invoiceDate,
|
||||||
fromClientId: args.fromClientId,
|
maxShipped: args.maxShipped,
|
||||||
toClientId: args.toClientId,
|
fromClientId: args.fromClientId,
|
||||||
companyFk: args.companyFk,
|
toClientId: args.toClientId,
|
||||||
minShipped: minShipped
|
companyFk: args.companyFk,
|
||||||
};
|
minShipped: minShipped
|
||||||
|
}
|
||||||
|
];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('globalInvoicing', {
|
Self.remoteMethodCtx('globalInvoicing', {
|
||||||
description: 'Make a global invoice of a client',
|
description: 'Make a invoice of a client',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'clientId',
|
arg: 'clientId',
|
||||||
|
@ -17,17 +17,20 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'invoiceDate',
|
arg: 'invoiceDate',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'The invoice date'
|
description: 'The invoice date',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'maxShipped',
|
arg: 'maxShipped',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'The maximum shipped date'
|
description: 'The maximum shipped date',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'fromClientId',
|
arg: 'fromClientId',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The minimum client id'
|
description: 'The minimum client id',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'toClientId',
|
arg: 'toClientId',
|
||||||
|
@ -38,12 +41,14 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'companyFk',
|
arg: 'companyFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The company id to invoice'
|
description: 'The company id to invoice',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'minShipped',
|
arg: 'minShipped',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'The company id to invoice'
|
description: 'The company id to invoice',
|
||||||
|
required: true
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -72,7 +77,6 @@ module.exports = Self => {
|
||||||
const invoicesIds = [];
|
const invoicesIds = [];
|
||||||
const failedClients = [];
|
const failedClients = [];
|
||||||
try {
|
try {
|
||||||
// const addresses = await models.Address.find({where: {clientFk: args.clientId}}, myOptions);
|
|
||||||
const client = await models.Client.findById(args.clientId, {
|
const client = await models.Client.findById(args.clientId, {
|
||||||
fields: ['id', 'hasToInvoiceByAddress']
|
fields: ['id', 'hasToInvoiceByAddress']
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
|
@ -16,10 +16,12 @@
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<div
|
<div
|
||||||
class="progress vn-my-md"
|
class="progress vn-my-md"
|
||||||
ng-if="$ctrl.isInvoicing">
|
ng-if="$ctrl.lastClientId">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-icon vn-none icon="warning"></vn-icon>
|
<div>
|
||||||
{{$ctrl.currentClientId}} {{$ctrl.$t('of')}} {{$ctrl.lastClientId}}
|
{{'Id Client' | translate}}: {{$ctrl.currentClientId}}
|
||||||
|
{{'of' | translate}} {{::$ctrl.lastClientId}}
|
||||||
|
</div>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
</div>
|
</div>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
@ -66,5 +68,5 @@
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
<tpl-buttons>
|
<tpl-buttons>
|
||||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
<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>
|
</tpl-buttons>
|
|
@ -6,7 +6,7 @@ class Controller extends Dialog {
|
||||||
constructor($element, $, $transclude) {
|
constructor($element, $, $transclude) {
|
||||||
super($element, $, $transclude);
|
super($element, $, $transclude);
|
||||||
|
|
||||||
this.isInvoicing = false;
|
this.lastClientId = null;
|
||||||
this.invoice = {
|
this.invoice = {
|
||||||
maxShipped: new Date()
|
maxShipped: new Date()
|
||||||
};
|
};
|
||||||
|
@ -46,7 +46,7 @@ class Controller extends Dialog {
|
||||||
this.invoice.companyFk = value;
|
this.invoice.companyFk = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
responseHandler(response) {
|
async responseHandler(response) {
|
||||||
try {
|
try {
|
||||||
if (response !== 'accept')
|
if (response !== 'accept')
|
||||||
return super.responseHandler(response);
|
return super.responseHandler(response);
|
||||||
|
@ -57,25 +57,49 @@ class Controller extends Dialog {
|
||||||
if (!this.invoice.fromClientId)
|
if (!this.invoice.fromClientId)
|
||||||
throw new Error('Choose a valid clients range');
|
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)
|
return this.$http.post(`InvoiceOuts/clientToInvoice`, this.invoice)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
const clientAndAddressIds = res.data.clientAndAddressIds;
|
const clientsAndAddresses = res.data.clientsAndAddresses;
|
||||||
if (!clientAndAddressIds) return super.responseHandler(response);
|
const invoice = res.data.invoice;
|
||||||
this.lastClientId = clientAndAddressIds[clientAndAddressIds.length - 1][0];
|
|
||||||
this.isInvoicing = true;
|
if (!clientsAndAddresses.length) return super.responseHandler(response);
|
||||||
for (let clientAndAddresId of clientAndAddressIds) {
|
this.lastClientId = clientsAndAddresses[clientsAndAddresses.length - 1].clientId;
|
||||||
this.currentClientId = clientAndAddresId[0];
|
this.$.invoiceButton.setAttribute('disabled', true);
|
||||||
res.data.clientId = clientAndAddresId[0];
|
for (let clientAndAddress of clientsAndAddresses) {
|
||||||
res.data.addressId = clientAndAddresId[1];
|
this.currentClientId = clientAndAddress.clientId;
|
||||||
await this.$http.post(`InvoiceOuts/globalInvoicing`, res.data);
|
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(() => super.responseHandler(response))
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||||
.finally(() => this.isInvoicing = false);
|
.finally(() => {
|
||||||
|
this.lastClientId = null;
|
||||||
|
this.$.invoiceButton.removeAttribute('disabled');
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.vnApp.showError(this.$t(e.message));
|
this.vnApp.showError(this.$t(e.message));
|
||||||
this.isInvoicing = false;
|
this.lastClientId = null;
|
||||||
|
this.$.invoiceButton.removeAttribute('disabled');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,5 @@ From client: Desde el cliente
|
||||||
To client: Hasta 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
|
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
|
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