Administración solo recargo equivalencia

Razón social único
Si no hay comercial, modificar los datos
This commit is contained in:
nelo 2017-06-01 14:39:22 +02:00
parent f4ed484b90
commit b18c2c4966
5 changed files with 71 additions and 17 deletions

View File

@ -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>

View File

@ -1,15 +1,21 @@
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (1,'Account','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (2,'Account','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (3,'Address','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (4,'Address','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (5,'AgencyService','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (6,'AgencyService','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (7,'Client','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (8,'Client','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (9,'ClientObservation','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (10,'ClientObservation','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (11,'ContactChannel','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (12,'ContactChannel','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (13,'Employee','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (14,'PayMethod','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`id`,`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values (15,'PayMethod','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Account','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Account','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Address','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Address','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('AgencyService','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('AgencyService','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','fi','WRITE','DENY','ROLE','$everyone');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','fi','WRITE','ALLOW','ROLE','administrative');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','equalizationTax','WRITE','DENY','ROLE','$everyone');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','equalizationTax','WRITE','ALLOW','ROLE','administrative');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','salesPerson','WRITE','DENY','ROLE','$everyone');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Client','salesPerson','WRITE','ALLOW','ROLE','salesBoss');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('ClientObservation','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('ClientObservation','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('ContactChannel','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('ContactChannel','*','WRITE','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('Employee','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('PayMethod','*','READ','ALLOW','ROLE','employee');
insert into `ACL`(`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) values ('PayMethod','*','WRITE','ALLOW','ROLE','employee');

View File

@ -19,6 +19,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,
@ -38,7 +41,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'
});

View File

@ -46,6 +46,9 @@
"active": {
"type": "boolean"
},
"discount":{
"type": "Number"
},
"credit": {
"type": "Number"
},

View File

@ -1,18 +1,60 @@
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;
}
}