refactor
gitea/salix/1959-client_fiscal_data_check_phone There was a failure building this commit
Details
gitea/salix/1959-client_fiscal_data_check_phone There was a failure building this commit
Details
This commit is contained in:
parent
e13d457389
commit
b471f51482
File diff suppressed because one or more lines are too long
|
@ -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);
|
||||
};
|
||||
};
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue