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

82 lines
2.3 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)
this.returnDialogEt('ACCEPT');
delete this.oldHasToInvoiceByAddress;
2017-11-15 07:41:54 +00:00
}
returnDialogEt(response) {
if (response === 'ACCEPT') {
2017-11-22 07:59:21 +00:00
this.$http.patch(`/client/api/Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.isEqualizated}).then(
2017-11-15 07:41:54 +00:00
res => {
if (res.data)
2017-11-15 07:41:54 +00:00
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
}
);
}
}
setLocation() {
const location = this.$.postcode.selection;
if (!location || !location.town) return;
const town = location.town;
const province = town.province;
const country = province.country;
this.client.city = location.town.name;
this.client.provinceFk = province.id;
this.client.countryFk = country.id;
}
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
});