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();
|
2017-05-31 10:56:37 +00:00
|
|
|
}
|
2018-05-28 10:22:35 +00:00
|
|
|
|
2018-10-08 11:09:30 +00:00
|
|
|
onSubmit() {
|
|
|
|
let shouldNotify = false;
|
2018-05-28 10:22:35 +00:00
|
|
|
|
2018-10-08 11:09:30 +00:00
|
|
|
if (this.hasPaymethodChanges())
|
|
|
|
shouldNotify = true;
|
2018-05-28 10:22:35 +00:00
|
|
|
|
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!'));
|
2018-07-10 12:13:47 +00:00
|
|
|
});
|
2017-06-07 13:28:42 +00:00
|
|
|
}
|
2018-05-28 10:22:35 +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
|
|
|
|
2018-07-10 12:13:47 +00:00
|
|
|
return payMethod || iban || dueDay;
|
2017-05-31 10:56:37 +00:00
|
|
|
}
|
2018-10-17 10:49:18 +00:00
|
|
|
|
2019-11-28 11:54:34 +00:00
|
|
|
onAddEntityClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.newBankEntity = {
|
|
|
|
countryFk: Number.parseInt(this.client.countryFk)
|
|
|
|
};
|
|
|
|
this.$.bankEntityDialog.show();
|
2018-10-17 10:49:18 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:54:34 +00:00
|
|
|
onBankEntityAccept() {
|
|
|
|
return this.$http.post(`BankEntities`, this.newBankEntity)
|
|
|
|
.then(res => this.client.bankEntityFk = res.data.id);
|
2018-10-17 10:49:18 +00:00
|
|
|
}
|
2018-11-07 08:17:07 +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;
|
|
|
|
}
|
|
|
|
|
2018-11-07 08:17:07 +00:00
|
|
|
autofillBic() {
|
2019-10-09 22:47:29 +00:00
|
|
|
if (!this.client || !this.client.iban) return;
|
2018-11-07 08:17:07 +00:00
|
|
|
|
|
|
|
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;
|
2018-11-07 08:17:07 +00:00
|
|
|
|
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)
|
2018-11-22 11:10:43 +00:00
|
|
|
this.client.bankEntityFk = response.data[0].id;
|
2018-11-22 14:17:35 +00:00
|
|
|
else if (!hasData)
|
|
|
|
this.client.bankEntityFk = null;
|
2018-11-07 08:17:07 +00:00
|
|
|
});
|
|
|
|
}
|
2017-05-31 10:56:37 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 11:01:47 +00:00
|
|
|
ngModule.component('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
|
|
|
});
|