Merge branch 'dev' of https://git.verdnatura.es/salix into dev
* 'dev' of https://git.verdnatura.es/salix: validation client credit - refact validate client credit AutoLoad items with "scroll" (1st version)
This commit is contained in:
commit
9f7170f773
|
@ -56,6 +56,10 @@ export default class DropDown {
|
|||
}
|
||||
this.$timeout(() => {
|
||||
this._activeOption = value;
|
||||
// AutoLoad items with "scroll" (1st version):
|
||||
if (value && value >= this.items.length - 3) {
|
||||
this.loadItems();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ var app = require('../../server/server');
|
|||
|
||||
module.exports = function(Client) {
|
||||
var models = app.models;
|
||||
|
||||
var loopBackContext = require('loopback-context');
|
||||
// Methods
|
||||
|
||||
require('../methods/client/activate.js')(Client);
|
||||
|
@ -69,20 +69,22 @@ module.exports = function(Client) {
|
|||
done();
|
||||
});
|
||||
}
|
||||
/*
|
||||
|
||||
Client.validateAsync('credit', validateCredit, {
|
||||
message: 'No tienes privilegios para modificar el crédito'
|
||||
});
|
||||
function validateCredit(err, done) {
|
||||
// FIXME: Id del usuario actual
|
||||
let userId = 1;
|
||||
|
||||
let ctx = loopBackContext.getCurrentContext();
|
||||
let accessToken = ctx && ctx.get('accessToken');
|
||||
let userId = accessToken.userId;
|
||||
let self = this;
|
||||
|
||||
// Comprueba si el rol del usuario puede asignar esa cantidad
|
||||
|
||||
// para ello mira que roles pueden asignar la cantidad que el usuario ha indicado
|
||||
let filter = {
|
||||
fields: ['roleFk'],
|
||||
where: {
|
||||
maxAmount: {gt: this.credit}
|
||||
maxAmount: {gt: self.credit}
|
||||
}
|
||||
};
|
||||
models.ClientCreditLimit.find(filter,
|
||||
|
@ -102,47 +104,52 @@ module.exports = function(Client) {
|
|||
(_, res) => roleCb(_, res));
|
||||
}
|
||||
function roleCb(_, count) {
|
||||
//si el usuario no tiene alguno de los roles no continua
|
||||
if (!(count > 0)) {
|
||||
err();
|
||||
done();
|
||||
} else
|
||||
validate();
|
||||
validate(); //si tiene el rol hay que validar que el último movimiento no fuese crédito 0 insertado por gerencia
|
||||
}
|
||||
|
||||
// Si se puso a 0 por gerencia, solo gerencia puede aumentarlo
|
||||
|
||||
function validate() {
|
||||
let query = 'SELECT MAX(created) created FROM ClientCredit WHERE clientFk = ?';
|
||||
Client.dataSource.connector.execute (query, [this.id],
|
||||
let query = 'SELECT * FROM ClientCredit WHERE clientFk = ? ORDER BY created DESC LIMIT 1';
|
||||
Client.dataSource.connector.execute (query, [self.id],
|
||||
(_, res) => maxCb(_, res));
|
||||
}
|
||||
|
||||
function maxCb(_, instances) {
|
||||
if (instances.length !== 1) {
|
||||
done();
|
||||
//console.log('maxCb', instances);
|
||||
if(!instances){
|
||||
err();
|
||||
return;
|
||||
}
|
||||
|
||||
let filter = {
|
||||
fields: ['amount', 'employeeFk', 'employee'],
|
||||
where: {
|
||||
clientFk: this.id,
|
||||
created: instances[0].created
|
||||
},
|
||||
include: {
|
||||
relation: 'employee',
|
||||
scope: {
|
||||
fields: ['userFk']
|
||||
}
|
||||
}
|
||||
};
|
||||
models.ClientCredit.findOne(filter,
|
||||
(_, res) => clientCreditCb(_, res));
|
||||
if (instances.length !== 1 || instances[0].employeeFk == userId || instances[0].amount > 0) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
//el ultimo registro tiene valor 0, hay que comprobar que no fue editado por un gerente
|
||||
let sql = `SELECT count(distinct r.id) as hasManagerRole
|
||||
FROM ClientCredit cc
|
||||
JOIN Employee em ON (em.id = cc.employeeFk)
|
||||
JOIN Account ac ON (ac.id = em.userFk)
|
||||
JOIN RoleMapping rm ON (rm.principalId = ac.id)
|
||||
JOIN Role r on (r.id = rm.roleId)
|
||||
WHERE rm.principalType = 'USER'
|
||||
AND cc.employeeFk = ${instances[0].employeeFk}
|
||||
AND r.\`name\` = 'manager'`;
|
||||
|
||||
Client.dataSource.connector.execute(sql, [], (_, res) => clientCreditCb(_, res));
|
||||
}
|
||||
function clientCreditCb(_, instance) {
|
||||
if (instance.amount == 0 && instance.employee.userFk != userId)
|
||||
|
||||
function clientCreditCb(_, instance) {
|
||||
if (!instance || (instance.length && instance[0].hasManagerRole > 0 ))
|
||||
err();
|
||||
done();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
Loading…
Reference in New Issue