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

90 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-06-03 11:01:47 +00:00
import ngModule from '../module';
2019-12-31 09:38:19 +00:00
import Component from 'core/lib/component';
2019-12-31 09:38:19 +00:00
export default class Controller extends Component {
onSubmit() {
2019-12-31 09:38:19 +00:00
const orgData = this.$.watcher.orgData;
2020-02-04 10:25:15 +00:00
delete this.client.despiteOfClient;
if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked)
this.checkExistingClient();
else this.save();
}
2019-12-31 09:38:19 +00:00
2020-02-04 10:25:15 +00:00
checkExistingClient() {
const filterObj = {
where: {
and: [
{or: [{email: this.client.email}, {phone: this.client.phone}]},
{id: {neq: this.client.id}}
]
}
};
2020-02-04 10:25:15 +00:00
const $t = this.$translate.instant;
const filter = encodeURIComponent(JSON.stringify(filterObj));
const query = `Clients/findOne?filter=${filter}`;
this.$http.get(query).then(res => {
2020-02-27 12:33:40 +00:00
const params = {clientId: res.data.id};
const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters');
this.client.despiteOfClient = params.clientId;
this.$.confirmDuplicatedClient.question = question;
this.$.confirmDuplicatedClient.show();
}).catch(error => {
if (error.status == 404)
this.save();
2020-02-04 10:25:15 +00:00
});
2017-11-15 07:41:54 +00:00
}
2020-02-04 10:25:15 +00:00
checkEtChanges(orgData) {
2019-12-31 09:38:19 +00:00
const equalizatedHasChanged = orgData.isEqualizated != this.client.isEqualizated;
2020-02-04 10:25:15 +00:00
const hasToInvoiceByAddress = orgData.hasToInvoiceByAddress || this.client.hasToInvoiceByAddress;
2017-11-15 07:41:54 +00:00
2020-02-04 10:25:15 +00:00
if (equalizatedHasChanged && hasToInvoiceByAddress)
2017-11-22 07:59:21 +00:00
this.$.propagateIsEqualizated.show();
2019-12-31 09:38:19 +00:00
else if (equalizatedHasChanged)
return this.onAcceptEt();
2019-12-31 09:38:19 +00:00
return this.$q.resolve();
2017-11-15 07:41:54 +00:00
}
2019-12-31 09:38:19 +00:00
onAcceptEt() {
const query = `Clients/${this.client.id}/addressesPropagateRe`;
return this.$http.patch(query, {isEqualizated: this.client.isEqualizated}).then(
() => this.vnApp.showMessage(this.$translate.instant('Equivalent tax spreaded'))
);
2017-11-15 07:41:54 +00:00
}
2020-02-04 10:25:15 +00:00
onAcceptDuplication() {
this.save();
return true;
}
save() {
const orgData = this.$.watcher.orgData;
const clonedOrgData = JSON.parse(JSON.stringify(orgData));
return this.$.watcher.submit().then(
() => this.checkEtChanges(clonedOrgData));
}
onChangeEqualizated(value) {
const orgData = this.$.watcher.orgData;
if (value === true)
this.client.hasToInvoiceByAddress = false;
else if (orgData.hasToInvoiceByAddress)
this.client.hasToInvoiceByAddress = true;
this.$.$apply();
}
2017-11-15 07:41:54 +00:00
}
2017-06-03 11:01:47 +00:00
ngModule.component('vnClientFiscalData', {
2018-05-23 12:26:51 +00:00
template: require('./index.html'),
controller: Controller,
require: {card: '^vnClientCard'},
bindings: {
client: '<'
}
2017-06-03 11:01:47 +00:00
});