diff --git a/client/client/src/billing-data/billing-data.html b/client/client/src/billing-data/billing-data.html
index 47f982696..75aeb93be 100644
--- a/client/client/src/billing-data/billing-data.html
+++ b/client/client/src/billing-data/billing-data.html
@@ -59,4 +59,18 @@
+
+
+
+
+ You changes the equivalent tax
+ Do you want to spread the change to their consignees?
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client/client/src/billing-data/billing-data.js b/client/client/src/billing-data/billing-data.js
index df281e8b3..a28aea963 100644
--- a/client/client/src/billing-data/billing-data.js
+++ b/client/client/src/billing-data/billing-data.js
@@ -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'));
+ }
);
}
}
diff --git a/client/client/src/billing-data/locale/es.json b/client/client/src/billing-data/locale/es.json
index f0b6a1213..5706db30e 100644
--- a/client/client/src/billing-data/locale/es.json
+++ b/client/client/src/billing-data/locale/es.json
@@ -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"
}
\ No newline at end of file
diff --git a/services/client/common/methods/client/addressesPropagateRe.js b/services/client/common/methods/client/addressesPropagateRe.js
new file mode 100644
index 000000000..b5aec246c
--- /dev/null
+++ b/services/client/common/methods/client/addressesPropagateRe.js
@@ -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);
+ }
+ };
+}
\ No newline at end of file
diff --git a/services/client/common/methods/client/before-save.js b/services/client/common/methods/client/before-save.js
index 4d9c096ef..e8d892be8 100644
--- a/services/client/common/methods/client/before-save.js
+++ b/services/client/common/methods/client/before-save.js
@@ -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;
}
diff --git a/services/client/common/models/client.js b/services/client/common/models/client.js
index 19c3969a9..9236fdabb 100644
--- a/services/client/common/models/client.js
+++ b/services/client/common/models/client.js
@@ -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