This commit is contained in:
Carlos Jimenez Ruiz 2019-02-06 18:01:54 +01:00
commit 4f2c567144
9 changed files with 94 additions and 29 deletions

View File

@ -24,7 +24,6 @@ class Controller {
this.$state.go('zone.index');
});
}
console.log('res', response);
}
}

View File

@ -38,6 +38,9 @@
"CreditInsurance": {
"dataSource": "vn"
},
"ClientType": {
"dataSource": "vn"
},
"Defaulter": {
"dataSource": "vn"
},

View File

@ -0,0 +1,24 @@
{
"name": "ClientType",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientType"
}
},
"properties": {
"id": {
"type": "Number",
"id": true
},
"code": {
"type": "String"
},
"type": {
"type": "String"
},
"isCreatedAsServed": {
"type": "Number"
}
}
}

View File

@ -151,7 +151,7 @@
"type": {
"type": "belongsTo",
"model": "ClientType",
"foreignKey": "typeFk"
"foreignKey": "clientTypeFk"
},
"addresses": {
"type": "hasMany",

View File

@ -20,7 +20,22 @@ module.exports = Self => {
});
Self.isEditable = async orderId => {
let exists = await Self.app.models.Order.findOne({where: {id: orderId}, fields: ['isConfirmed']});
let exists = await Self.app.models.Order.findOne({
where: {id: orderId},
fields: ['isConfirmed', 'clientFk'],
include: [
{relation: 'client',
scope: {
include: {
relation: 'type'
}
}
}
]
});
if (exists && exists.client().type().code !== 'normal')
return true;
if (!exists || exists.isConfirmed === 1)
return false;

View File

@ -24,15 +24,23 @@ module.exports = Self => {
where: {id: params.addressFk},
fields: ['clientFk'],
include: [
{relation: 'client'}
{relation: 'client',
scope: {
include: {
relation: 'type'
}
}
}
]
});
if (address.client().type().code === 'normal') {
if (address.client().isFreezed)
throw new UserError(`You can't create an order for a frozen client`);
if (!address.client().isActive)
throw new UserError(`You can't create an order for a inactive client`);
}
query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
[result] = await Self.rawSql(query, [

View File

@ -20,9 +20,25 @@ module.exports = Self => {
});
Self.isEditable = async ticketFk => {
let state = await Self.app.models.TicketState.findOne({where: {ticketFk: ticketFk}});
let state = await Self.app.models.TicketState.findOne({
where: {ticketFk: ticketFk}
});
let alertLevel = state ? state.alertLevel : null;
let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'});
let exists = await Self.app.models.Ticket.findOne({
where: {id: ticketFk},
fields: ['isDeleted', 'clientFk'],
include: [{
relation: 'client',
scope: {
include: {
relation: 'type'
}
}
}]
});
if (exists && exists.client().type().code !== 'normal')
return true;
if (!exists || exists.isDeleted == 1 || (alertLevel && alertLevel > 0))
return false;

View File

@ -26,13 +26,20 @@ module.exports = Self => {
where: {id: params.addressFk},
fields: ['clientFk'],
include: [
{relation: 'client'}
{relation: 'client',
scope: {
include: {
relation: 'type'
}
}
}
]
});
if (!address)
throw new UserError(`This address doesn't exist`);
{if (!address)
throw new UserError(`This address doesn't exist`);}
if (address.client().type().code === 'normal') {
if (address.client().isFreezed)
throw new UserError(`You can't create a ticket for a frozen client`);
@ -40,13 +47,6 @@ module.exports = Self => {
throw new UserError(`You can't create a ticket for a inactive client`);
let clientFk = address.clientFk;
let agency;
if (params.agencyModeFk)
agency = await Self.app.models.AgencyMode.findById(params.agencyModeFk);
else
agency = {code: null};
if (agency.name != 'ABONO') {
let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
let clientDebt = await Self.rawSql(query, [clientFk]);