salix/modules/client/front/billing-data/index.js

78 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2017-06-03 11:01:47 +00:00
import ngModule from '../module';
2019-11-28 11:54:34 +00:00
import Section from 'salix/components/section';
2017-05-23 08:58:17 +00:00
2019-11-28 11:54:34 +00:00
export default class Controller extends Section {
2018-10-17 10:49:18 +00:00
get client() {
return this._client;
}
set client(value) {
this._client = value;
if (!value) return;
2019-02-12 12:26:52 +00:00
if (!value.bankEntityFk)
this.autofillBic();
}
2018-10-08 11:09:30 +00:00
onSubmit() {
let shouldNotify = false;
2018-10-08 11:09:30 +00:00
if (this.hasPaymethodChanges())
shouldNotify = true;
2019-11-28 11:54:34 +00:00
this.$.watcher.submit().then(() => {
2018-10-08 11:09:30 +00:00
if (shouldNotify)
2019-11-28 11:54:34 +00:00
this.vnApp.showMessage(this.$t('Notification sent!'));
});
2017-06-07 13:28:42 +00:00
}
2018-10-08 11:09:30 +00:00
hasPaymethodChanges() {
2019-11-28 11:54:34 +00:00
let orgData = this.$.watcher.orgData;
2018-10-08 11:09:30 +00:00
let payMethod = orgData.payMethodFk != this.client.payMethodFk;
let iban = orgData.iban != this.client.iban;
let dueDay = orgData.dueDay != this.client.dueDay;
2017-10-04 11:32:26 +00:00
return payMethod || iban || dueDay;
}
2018-10-17 10:49:18 +00:00
onAccept(data) {
this.client.bankEntityFk = data.id;
2018-10-17 10:49:18 +00:00
}
2018-11-23 07:44:19 +00:00
get ibanCountry() {
if (!this.client || !this.client.iban) return false;
let countryCode = this.client.iban.substr(0, 2);
return countryCode;
}
autofillBic() {
2019-10-09 22:47:29 +00:00
if (!this.client || !this.client.iban) return;
let bankEntityId = parseInt(this.client.iban.substr(4, 4));
let filter = {where: {id: bankEntityId}};
2018-11-23 07:44:19 +00:00
if (this.ibanCountry != 'ES') return;
2019-11-28 11:54:34 +00:00
this.$http.get(`BankEntities`, {filter}).then(response => {
2018-11-22 14:17:35 +00:00
const hasData = response.data && response.data[0];
if (hasData)
this.client.bankEntityFk = response.data[0].id;
2018-11-22 14:17:35 +00:00
else if (!hasData)
this.client.bankEntityFk = null;
});
}
}
ngModule.vnComponent('vnClientBillingData', {
2018-05-23 12:26:51 +00:00
template: require('./index.html'),
2017-06-03 11:01:47 +00:00
controller: Controller,
2017-05-23 08:58:17 +00:00
bindings: {
client: '<'
}
2017-06-03 11:01:47 +00:00
});