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

50 lines
1.6 KiB
JavaScript

import ngModule from '../module';
import Component from 'core/lib/component';
export default class Controller extends Component {
onSubmit() {
const orgData = this.$.watcher.orgData;
if (orgData.isEqualizated != this.client.isEqualizated)
this.client.hasToInvoiceByAddress = false;
if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked) {
const serializedParams = {email: this.client.email, phone: 111};
const query = `Clients/byNameOrEmail?filter=${serializedParams}`;
this.$http.get(query).then(res => {
console.log(res);
});
}
return this.checkEtChanges().then(
() => this.$.watcher.submit());
}
checkEtChanges() {
const orgData = this.$.watcher.orgData;
const equalizatedHasChanged = orgData.isEqualizated != this.client.isEqualizated;
if (equalizatedHasChanged && !orgData.hasToInvoiceByAddress)
this.$.propagateIsEqualizated.show();
else if (equalizatedHasChanged)
return this.onAcceptEt();
return this.$q.resolve();
}
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'))
);
}
}
ngModule.component('vnClientFiscalData', {
template: require('./index.html'),
controller: Controller,
require: {card: '^vnClientCard'},
bindings: {
client: '<'
}
});