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

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-06-03 11:01:47 +00:00
import ngModule from '../module';
2018-05-23 12:26:51 +00:00
export default class Controller {
2017-11-15 07:41:54 +00:00
constructor($scope, $http, vnApp, $translate) {
this.$ = $scope;
this.$http = $http;
this.vnApp = vnApp;
this.translate = $translate;
2017-11-22 07:59:21 +00:00
this.isEqualizated = undefined;
2017-11-15 07:41:54 +00:00
this.copyData();
}
$onChanges() {
this.copyData();
}
copyData() {
if (this.client)
2017-11-22 07:59:21 +00:00
this.isEqualizated = this.client.isEqualizated;
2017-11-15 07:41:54 +00:00
}
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;
}
2017-11-15 07:41:54 +00:00
return this.$.watcher.submit().then(
() => this.checkEtChanges());
}
checkEtChanges() {
2017-11-22 07:59:21 +00:00
let equals = this.isEqualizated == this.client.isEqualizated;
this.isEqualizated = this.client.isEqualizated;
2017-11-15 07:41:54 +00:00
if (!equals && !this.oldHasToInvoiceByAddress)
2017-11-22 07:59:21 +00:00
this.$.propagateIsEqualizated.show();
else if (!equals)
2019-10-30 15:57:14 +00:00
this.returnDialogEt('accept');
delete this.oldHasToInvoiceByAddress;
2017-11-15 07:41:54 +00:00
}
returnDialogEt(response) {
2019-10-30 15:57:14 +00:00
if (response === 'accept') {
this.$http.patch(`Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.isEqualizated}).then(
2019-11-12 07:51:50 +00:00
() => this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'))
2017-11-15 07:41:54 +00:00
);
}
}
}
2018-05-23 12:26:51 +00:00
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
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
});