71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
export default class Controller {
|
|
constructor($scope, $http, vnApp, $translate) {
|
|
this.$ = $scope;
|
|
this.$http = $http;
|
|
this.vnApp = vnApp;
|
|
this.translate = $translate;
|
|
this.isEqualizated = undefined;
|
|
this.copyData();
|
|
}
|
|
|
|
$onChanges() {
|
|
this.copyData();
|
|
}
|
|
|
|
copyData() {
|
|
if (this.client)
|
|
this.isEqualizated = this.client.isEqualizated;
|
|
}
|
|
|
|
buyerHaspermissions() {
|
|
if (!this.client) return true;
|
|
return !this.client.isTaxDataChecked;
|
|
}
|
|
|
|
onSubmit() {
|
|
if (this.isEqualizated != this.client.isEqualizated) {
|
|
this.oldHasToInvoiceByAddress = this.client.hasToInvoiceByAddress;
|
|
this.client.hasToInvoiceByAddress = false;
|
|
}
|
|
|
|
return this.$.watcher.submit().then(
|
|
() => this.checkEtChanges());
|
|
}
|
|
|
|
checkEtChanges() {
|
|
let equals = this.isEqualizated == this.client.isEqualizated;
|
|
this.isEqualizated = this.client.isEqualizated;
|
|
|
|
if (!equals && !this.oldHasToInvoiceByAddress)
|
|
this.$.propagateIsEqualizated.show();
|
|
else if (!equals)
|
|
this.returnDialogEt('ACCEPT');
|
|
|
|
delete this.oldHasToInvoiceByAddress;
|
|
}
|
|
|
|
returnDialogEt(response) {
|
|
if (response === 'ACCEPT') {
|
|
this.$http.patch(`/client/api/Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.isEqualizated}).then(
|
|
res => {
|
|
if (res.data)
|
|
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
|
|
|
ngModule.component('vnClientFiscalData', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
require: {card: '^vnClientCard'},
|
|
bindings: {
|
|
client: '<'
|
|
}
|
|
});
|