refactor
gitea/salix/1959-client_fiscal_data_check_phone There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2019-12-31 10:38:19 +01:00
parent e13d457389
commit b471f51482
5 changed files with 75 additions and 44 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,47 @@
module.exports = Self => {
Self.remoteMethod('byNameOrEmail', {
description: 'Returns the client with the matching phone or email',
accessType: 'READ',
accepts: [{
arg: 'email',
type: 'String',
description: 'Find my matching client email',
required: false
},
{
arg: 'phone',
type: 'String',
description: 'Find my matching client phone',
required: false
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/byNameOrEmail`,
verb: 'GET'
}
});
Self.byNameOrEmail = async(email, phone) => {
const models = Self.app.models;
let match;
match = await Self.findOne({
where: {
email: email
}
});
if (match) return match;
match = await models.UserPhone.findOne({
where: {
phone: phone
}
});
return await Self.findById(match.userFk);
};
};

View File

@ -24,6 +24,7 @@ module.exports = Self => {
require('../methods/client/canBeInvoiced')(Self);
require('../methods/client/uploadFile')(Self);
require('../methods/client/lastActiveTickets')(Self);
require('../methods/client/byNameOrEmail')(Self);
// Validations

View File

@ -148,5 +148,5 @@
vn-id="propagate-isEqualizated"
question="You changed the equalization tax"
message="Do you want to spread the change?"
on-response="$ctrl.returnDialogEt($response)">
on-accept="$ctrl.onAcceptEt()">
</vn-confirm>

View File

@ -1,62 +1,44 @@
import ngModule from '../module';
import Component from 'core/lib/component';
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;
}
export default class Controller extends Component {
onSubmit() {
if (this.isEqualizated != this.client.isEqualizated) {
this.oldHasToInvoiceByAddress = this.client.hasToInvoiceByAddress;
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.$.watcher.submit().then(
() => this.checkEtChanges());
return this.checkEtChanges().then(
() => this.$.watcher.submit());
}
checkEtChanges() {
let equals = this.isEqualizated == this.client.isEqualizated;
this.isEqualizated = this.client.isEqualizated;
const orgData = this.$.watcher.orgData;
const equalizatedHasChanged = orgData.isEqualizated != this.client.isEqualizated;
if (!equals && !this.oldHasToInvoiceByAddress)
if (equalizatedHasChanged && !orgData.hasToInvoiceByAddress)
this.$.propagateIsEqualizated.show();
else if (!equals)
this.returnDialogEt('accept');
else if (equalizatedHasChanged)
return this.onAcceptEt();
delete this.oldHasToInvoiceByAddress;
return this.$q.resolve();
}
returnDialogEt(response) {
if (response === 'accept') {
this.$http.patch(`Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.isEqualizated}).then(
() => this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'))
);
}
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'))
);
}
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
ngModule.component('vnClientFiscalData', {
template: require('./index.html'),
controller: Controller,