spread equivalent tax in all addresses
This commit is contained in:
parent
245112438e
commit
0925451364
|
@ -59,4 +59,18 @@
|
|||
<button response="CANCEL" translate>No</button>
|
||||
<button response="ACCEPT" translate>Yes, notify</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
<vn-dialog
|
||||
vn-id="propagate-equalizationTax"
|
||||
on-response="$ctrl.returnDialogRE(response)">
|
||||
<tpl-body>
|
||||
<vn-vertical>
|
||||
<vn-one text-center translate>You changes the equivalent tax</vn-one>
|
||||
<vn-one text-center translate>Do you want to spread the change to their consignees?</vn-one>
|
||||
</vn-vertical>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<button response="CANCEL" translate>No</button>
|
||||
<button response="ACCEPT" translate>Yes, propagate</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
|
@ -20,6 +20,7 @@ export default class Controller {
|
|||
this.billData.discount = this.client.discount;
|
||||
this.billData.credit = this.client.credit;
|
||||
this.billData.creditInsurance = this.client.creditInsurance;
|
||||
this.equalizationTax = this.client.equalizationTax;
|
||||
}
|
||||
}
|
||||
submit() {
|
||||
|
@ -36,13 +37,41 @@ export default class Controller {
|
|||
}
|
||||
}
|
||||
);
|
||||
if (!equals)
|
||||
|
||||
if (equals) {
|
||||
this.checkREChanges();
|
||||
} else {
|
||||
this.$.sendMail.show();
|
||||
}
|
||||
}
|
||||
returnDialog(response) {
|
||||
if (response === 'ACCEPT') {
|
||||
this.$http.post(`/mailer/manuscript/payment-update/${this.client.id}`).then(
|
||||
() => this.vnApp.showMessage(this.translate.instant('Notification sent!'))
|
||||
() => {
|
||||
this.vnApp.showMessage(this.translate.instant('Notification sent!'));
|
||||
this.checkREChanges();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.checkREChanges();
|
||||
}
|
||||
}
|
||||
|
||||
checkREChanges() {
|
||||
let equals = this.equalizationTax == this.client.equalizationTax;
|
||||
this.equalizationTax = this.client.equalizationTax;
|
||||
|
||||
if (!equals)
|
||||
this.$.propagateEqualizationTax.show();
|
||||
}
|
||||
|
||||
returnDialogRE(response) {
|
||||
if (response === 'ACCEPT') {
|
||||
this.$http.patch(`/client/api/Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.equalizationTax}).then(
|
||||
res => {
|
||||
if (res.data)
|
||||
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,9 @@
|
|||
"No": "No",
|
||||
"Yes, notify": "Sí, notificar",
|
||||
"Notification sent!": "¡Notificación enviada!",
|
||||
"Notification error": "Error al enviar notificación"
|
||||
"Notification error": "Error al enviar notificación",
|
||||
"You changes the equivalent tax": "Has cambiado el recargo de equivalencia",
|
||||
"Do you want to spread the change to their consignees?" : "¿Deseas propagar el cambio a sus consignatarios?",
|
||||
"Yes, propagate": "Si, propagar",
|
||||
"Equivalent tax spreaded": "Recargo de equivalencia propagado"
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
module.exports = function(Client) {
|
||||
Client.remoteMethod('addressesPropagateRe', {
|
||||
description: 'Change property isEqualizated in all client addresses',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Client id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'data',
|
||||
type: 'Object',
|
||||
required: true,
|
||||
description: 'data with new value',
|
||||
http: {source: 'body'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/addressesPropagateRe`,
|
||||
verb: 'patch'
|
||||
}
|
||||
});
|
||||
|
||||
Client.addressesPropagateRe = (id, data, callback) => {
|
||||
if(data.hasOwnProperty('isEqualizated')) {
|
||||
Client.app.models.Address.updateAll({clientFk: id}, data, (err, info) => {
|
||||
if (err)
|
||||
return callback(err, null);
|
||||
callback(null, true);
|
||||
});
|
||||
} else {
|
||||
callback(null, false);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -3,18 +3,21 @@ module.exports = function(Client) {
|
|||
var CREDIT_CARD = 5;
|
||||
|
||||
Client.observe('before save', function(ctx, next) {
|
||||
if (ctx.instance) {
|
||||
Object.assign(ctx.instance, doIfNullSalesPerson(ctx.instance));
|
||||
if (ctx.currentInstance) {
|
||||
let dataChange = Object.assign({}, ctx.data);
|
||||
Object.assign(ctx.data, doIfNullSalesPerson(ctx.currentInstance));
|
||||
|
||||
if (!ctx.instance.dueDay)
|
||||
ctx.instance.dueDay = 5;
|
||||
if (!ctx.data.dueDay)
|
||||
ctx.data.dueDay = 5;
|
||||
|
||||
if (ctx.instance.equalizationTax && !canMarkEqualizationTax(ctx.instance))
|
||||
generateErrorEqualizationTax();
|
||||
if (dataChange.hasOwnProperty('equalizationTax') && !canMarkEqualizationTax(ctx.data))
|
||||
next(generateErrorEqualizationTax());
|
||||
else
|
||||
next();
|
||||
|
||||
next();
|
||||
} else {
|
||||
Client.findById(ctx.where.id, (_, instance) => {
|
||||
Client.findById(ctx.where.id, (_, instance) => {
|
||||
|
||||
Object.assign(ctx.data, doIfNullSalesPerson(instance));
|
||||
|
||||
if (instance
|
||||
|
@ -22,13 +25,13 @@ module.exports = function(Client) {
|
|||
&& instance.dueDay == ctx.data.dueDay)
|
||||
ctx.data.dueDay = 5;
|
||||
|
||||
if (instance.fi !== undefined && ctx.data.equalizationTax && !canMarkEqualizationTax(instance))
|
||||
if (instance.fi && ctx.data.equalizationTax && !canMarkEqualizationTax(instance)){
|
||||
next(generateErrorEqualizationTax());
|
||||
|
||||
if (instance.equalizationTax !== undefined && instance.equalizationTax && ctx.data.fi && Boolean(canMarkEqualizationTax(ctx.data)))
|
||||
} else if (instance.equalizationTax !== undefined && instance.equalizationTax && ctx.data.fi && canMarkEqualizationTax(ctx.data)){
|
||||
next(generateErrorEqualizationTax());
|
||||
|
||||
next();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -44,8 +47,8 @@ module.exports = function(Client) {
|
|||
}
|
||||
|
||||
function canMarkEqualizationTax(instance) {
|
||||
var firstLetter = instance.fi.toUpperCase().charAt(0);
|
||||
if (firstLetter != "A" && firstLetter != "B")
|
||||
var firstLetter = (instance && instance.fi) ? instance.fi.toUpperCase().charAt(0) : '';
|
||||
if (firstLetter == "A" || firstLetter == "B")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ module.exports = function(Client) {
|
|||
require('../methods/client/filter.js')(Client);
|
||||
require('../methods/client/roles.js')(Client);
|
||||
require('../methods/client/salesperson.js')(Client);
|
||||
require('../methods/client/addressesPropagateRe.js')(Client);
|
||||
|
||||
// Validations
|
||||
|
||||
|
|
Loading…
Reference in New Issue