Merge
This commit is contained in:
commit
80e6b0c666
|
@ -21,9 +21,10 @@
|
|||
<vn-textfield vn-one label="Vencimiento" field="bill.client.dueDay"></vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textfield vn-one label="Descuento" field="bill.client.discount"></vn-textfield>
|
||||
<vn-textfield vn-one label="Crédito" field="bill.client.credit"></vn-textfield>
|
||||
<vn-textfield vn-one label="Crédito asegurado" field="bill.client.creditInsurance"></vn-textfield>
|
||||
<vn-check vn-three label="Recargo de equivalencia" field="bill.client.surcharge"></vn-check>
|
||||
<vn-check vn-three label="Recargo de equivalencia" field="bill.client.equalizationTax"></vn-check>
|
||||
</vn-horizontal>
|
||||
</vn-vertical>
|
||||
</vn-card>
|
||||
|
|
|
@ -20,7 +20,7 @@ class billingData {
|
|||
|
||||
copyData() {
|
||||
if (this.client) {
|
||||
this.payId = this.client.payMethod ? this.client.payMethod.id : null;
|
||||
this.payId = this.client.payMethodFk || null;
|
||||
this.dueDay = this.client.dueDay ? this.client.dueDay : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ module.exports = function(Client) {
|
|||
Client.validatesPresenceOf('socialName', {
|
||||
message: 'Debe especificarse la razón social'
|
||||
});
|
||||
Client.validatesUniquenessOf('socialName', {
|
||||
message: 'La razón social debe ser única'
|
||||
});
|
||||
Client.validatesFormatOf('postcode', {
|
||||
message: 'El código postal solo debe contener números',
|
||||
allowNull: true,
|
||||
|
@ -30,7 +33,7 @@ module.exports = function(Client) {
|
|||
Client.validatesFormatOf('email', {
|
||||
message: 'Correo electrónico inválido',
|
||||
allowNull: true,
|
||||
with: /^[\w|\.|\-]+@\w[\w|\.|\-]*\w$/
|
||||
with: /^[\w|\.|\-]+@\w[\w|\.|\-]*\w(,[\w|\.|\-]+@\w[\w|\.|\-]*\w)*$/
|
||||
});
|
||||
Client.validatesLengthOf('postcode', {
|
||||
allowNull: true,
|
||||
|
@ -41,7 +44,6 @@ module.exports = function(Client) {
|
|||
allowBlank: true,
|
||||
max: 23
|
||||
});
|
||||
|
||||
Client.validate('payMethod', hasSalesMan, {
|
||||
message: 'No se puede cambiar la forma de pago si no hay comercial asignado'
|
||||
});
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
"active": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"discount":{
|
||||
"type": "Number"
|
||||
},
|
||||
"credit": {
|
||||
"type": "Number"
|
||||
},
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
module.exports = function(ClientObservation) {
|
||||
|
||||
let loopBackContext = require('loopback-context');
|
||||
|
||||
ClientObservation.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
|
||||
function isEnabled(err) {
|
||||
if (!this.text) err();
|
||||
|
@ -6,7 +9,15 @@ module.exports = function(ClientObservation) {
|
|||
|
||||
ClientObservation.observe('before save', function(ctx, next) {
|
||||
ctx.instance.created = Date();
|
||||
ctx.instance.employeeFk = 20;
|
||||
next();
|
||||
let currentUser = loopBackContext.getCurrentContext();
|
||||
let userId = currentUser.get('currentUser');
|
||||
let app = require('../../server/server');
|
||||
let employee = app.models.Employee;
|
||||
employee.findOne({where: {userFk: userId}}, function (err, user){
|
||||
if (user){
|
||||
ctx.instance.employeeFk = user.id;
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,17 +1,59 @@
|
|||
|
||||
module.exports = function(Client) {
|
||||
var CREDIT_CARD = 5;
|
||||
|
||||
Client.observe('before save', function(ctx, next) {
|
||||
if (ctx.instance) {
|
||||
Object.assign(ctx.instance, doIfNullSalesPerson(ctx.instance));
|
||||
|
||||
if (!ctx.instance.dueDay)
|
||||
ctx.instance.dueDay = 5;
|
||||
|
||||
if(ctx.instance.equalizationTax && !canMarkEqualizationTax(ctx.instance))
|
||||
generateErrorEqualizationTax();
|
||||
|
||||
next();
|
||||
} else {
|
||||
Client.findById(ctx.where.id, function(err, instance) {
|
||||
Object.assign(ctx.data, doIfNullSalesPerson(instance));
|
||||
|
||||
if (instance
|
||||
&& instance.payMethodFk != ctx.data.payMethodFk
|
||||
&& instance.dueDay == ctx.data.dueDay)
|
||||
ctx.data.dueDay = 5;
|
||||
|
||||
if(instance.fi !== undefined && ctx.data.equalizationTax && !canMarkEqualizationTax(instance))
|
||||
next(generateErrorEqualizationTax());
|
||||
|
||||
if(instance.equalizationTax !== undefined && instance.equalizationTax && ctx.data.fi && !!canMarkEqualizationTax(ctx.data))
|
||||
next(generateErrorEqualizationTax());
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function doIfNullSalesPerson(instance){
|
||||
var data = {};
|
||||
if(instance.salesPerson === null){
|
||||
data.credit = 0;
|
||||
data.discount = 0;
|
||||
data.payMethodFk = CREDIT_CARD;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function canMarkEqualizationTax(instance){
|
||||
var firstLetter = instance.fi.toUpperCase().charAt(0);
|
||||
if(firstLetter != "A" && firstLetter != "B")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function generateErrorEqualizationTax(){
|
||||
var error = new Error();
|
||||
error.message = "No se puede marcar el recargo de equivalencia";
|
||||
error.status = 500;
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"loopback-boot": "^2.6.5",
|
||||
"loopback-component-explorer": "^2.7.0",
|
||||
"loopback-connector-mysql": "^3.0.0",
|
||||
"loopback-context": "^3.1.0",
|
||||
"loopback-datasource-juggler": "^2.54.1",
|
||||
"serve-favicon": "^2.0.1",
|
||||
"strong-error-handler": "^1.2.1"
|
||||
|
|
|
@ -22,10 +22,20 @@
|
|||
"helmet#noSniff": {},
|
||||
"helmet#noCache": {
|
||||
"enabled": false
|
||||
},
|
||||
"loopback-context#per-request": {
|
||||
"params": {
|
||||
"enableHttpContext": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"session": {},
|
||||
"auth": {},
|
||||
"auth": {
|
||||
"loopback#token": {}
|
||||
},
|
||||
"auth:after": {
|
||||
"./middleware/currentUser": {}
|
||||
},
|
||||
"parse": {},
|
||||
"routes": {
|
||||
"loopback#rest": {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = function(options) {
|
||||
return function storeCurrentUser(req, res, next) {
|
||||
if (!req.accessToken) {
|
||||
return next();
|
||||
}
|
||||
let LoopBackContext = require('loopback-context');
|
||||
let loopbackContext = LoopBackContext.getCurrentContext();
|
||||
if (loopbackContext) {
|
||||
loopbackContext.set('currentUser', req.accessToken.userId);
|
||||
}
|
||||
next();
|
||||
};
|
||||
};
|
|
@ -11,9 +11,9 @@ module.exports = function (app) {
|
|||
|
||||
app.get('/acl', function(req, res){
|
||||
let token = req.cookies.vnToken;
|
||||
validateToken(token, function(isValid) {
|
||||
validateToken(token, function(isValid, token) {
|
||||
if (isValid)
|
||||
sendUserRole(res);
|
||||
sendUserRole(res, token);
|
||||
else
|
||||
sendACL(res, {});
|
||||
});
|
||||
|
@ -44,11 +44,8 @@ module.exports = function (app) {
|
|||
function validateToken(tokenId, cb) {
|
||||
app.models.AccessToken.findById(tokenId, function(err, token) {
|
||||
if (token) {
|
||||
if(token.userId){
|
||||
app.currentUser = {id: token.userId};
|
||||
}
|
||||
token.validate (function (err, isValid) {
|
||||
cb(isValid === true);
|
||||
cb(isValid === true, token);
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -56,11 +53,11 @@ module.exports = function (app) {
|
|||
});
|
||||
}
|
||||
|
||||
function sendUserRole(res){
|
||||
if(app.currentUser && app.currentUser.id){
|
||||
function sendUserRole(res, token){
|
||||
if(token.userId){
|
||||
let query = {
|
||||
"where": {
|
||||
"principalId": `${app.currentUser.id}`,
|
||||
"principalId": token.userId,
|
||||
"principalType": "USER"
|
||||
},
|
||||
"include": [{
|
||||
|
@ -68,29 +65,26 @@ module.exports = function (app) {
|
|||
"scope": {
|
||||
"fields": ["name"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"relation": "user",
|
||||
"scope": {
|
||||
"fields": ["id", "username"]
|
||||
}
|
||||
}]
|
||||
};
|
||||
app.models.RoleMapping.belongsTo(app.models.User, {foreignKey: 'principalId', as: 'user'});
|
||||
};
|
||||
app.models.RoleMapping.find(query, function(err, roles){
|
||||
if(roles){
|
||||
let acl = {
|
||||
var acl = {
|
||||
userProfile: {},
|
||||
roles: {}
|
||||
};
|
||||
acl.userProfile = roles[0].user();
|
||||
Object.keys(roles).forEach(function(_, i){
|
||||
if(roles[i].roleId){
|
||||
let rol = roles[i].role();
|
||||
acl.roles[rol.name] = true;
|
||||
}
|
||||
});
|
||||
sendACL(res, acl);
|
||||
app.models.User.findById(token.userId, function(_, userProfile){
|
||||
//acl.userProfile = userProfile;
|
||||
acl.userProfile.id = userProfile.id;
|
||||
acl.userProfile.username = userProfile.username;
|
||||
sendACL(res, acl);
|
||||
});
|
||||
}
|
||||
else
|
||||
sendACL(res, {});
|
||||
|
|
Loading…
Reference in New Issue