2017-06-03 11:01:47 +00:00
|
|
|
import ngModule from '../module';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
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() {
|
2018-12-11 12:16:33 +00:00
|
|
|
if (this.client)
|
2017-11-22 07:59:21 +00:00
|
|
|
this.isEqualizated = this.client.isEqualizated;
|
2017-11-15 07:41:54 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 09:54:02 +00:00
|
|
|
buyerHaspermissions() {
|
|
|
|
if (!this.client) return true;
|
|
|
|
return !this.client.isTaxDataChecked;
|
|
|
|
}
|
|
|
|
|
2019-06-13 11:08:11 +00:00
|
|
|
onSubmit() {
|
2018-12-11 12:16:33 +00:00
|
|
|
if (this.isEqualizated != this.client.isEqualizated) {
|
|
|
|
this.oldHasToInvoiceByAddress = this.client.hasToInvoiceByAddress;
|
2018-07-18 10:00:06 +00:00
|
|
|
this.client.hasToInvoiceByAddress = false;
|
2018-12-11 12:16:33 +00:00
|
|
|
}
|
2018-07-18 10:00:06 +00:00
|
|
|
|
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
|
|
|
|
2018-12-11 12:16:33 +00:00
|
|
|
if (!equals && !this.oldHasToInvoiceByAddress)
|
2017-11-22 07:59:21 +00:00
|
|
|
this.$.propagateIsEqualizated.show();
|
2018-12-11 12:16:33 +00:00
|
|
|
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 => {
|
2018-12-11 12:16:33 +00:00
|
|
|
if (res.data)
|
2017-11-15 07:41:54 +00:00
|
|
|
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-06-13 11:08:11 +00:00
|
|
|
|
2019-08-02 06:27:55 +00:00
|
|
|
get postcodeSelection() {
|
|
|
|
return this._postcodeSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
set postcodeSelection(selection) {
|
|
|
|
const hasValue = this._postcodeSelection;
|
|
|
|
this._postcodeSelection = selection;
|
|
|
|
|
|
|
|
if (!selection || !hasValue) return;
|
|
|
|
|
|
|
|
const town = selection.town;
|
2019-06-13 11:08:11 +00:00
|
|
|
const province = town.province;
|
|
|
|
|
2019-08-02 06:27:55 +00:00
|
|
|
this.address.city = town.name;
|
|
|
|
this.address.provinceFk = province.id;
|
2019-06-13 11:08:11 +00:00
|
|
|
}
|
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,
|
2018-07-03 09:13:33 +00:00
|
|
|
require: {card: '^vnClientCard'},
|
2017-01-31 13:13:06 +00:00
|
|
|
bindings: {
|
|
|
|
client: '<'
|
2017-02-07 11:58:25 +00:00
|
|
|
}
|
2017-06-03 11:01:47 +00:00
|
|
|
});
|