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().isFreezed)
throw new UserError(`You can't create an order for a frozen client`);
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`);
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

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
describe('sale moveToTicket()', () => {
it('should throw an error if the ticket is not editable', async () => {
it('should throw an error if the ticket is not editable', async() => {
let error;
let params = {actualTicketFk: 10};
@ -15,7 +15,7 @@ describe('sale moveToTicket()', () => {
expect(error).toBeDefined();
});
it('should throw an error if the receiving ticket is not editable', async () => {
it('should throw an error if the receiving ticket is not editable', async() => {
let error;
let params = {actualTicketFk: 1, newTicketFk: 10};
@ -29,7 +29,7 @@ describe('sale moveToTicket()', () => {
expect(error).toBeDefined();
});
it('should transfer the sales from one ticket to another', async () => {
it('should transfer the sales from one ticket to another', async() => {
let senderTicketSales = await app.models.Ticket.getSales(11);
let receiverTicketSales = await app.models.Ticket.getSales(13);
@ -53,7 +53,7 @@ describe('sale moveToTicket()', () => {
expect(receiverTicketSales.length).toEqual(2);
});
it('should transfers back the sales', async () => {
it('should transfers back the sales', async() => {
let senderTicketSales = await app.models.Ticket.getSales(13);
let receiverTicketSales = await app.models.Ticket.getSales(11);

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,27 +26,27 @@ 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().isFreezed)
throw new UserError(`You can't create a ticket for a frozen client`);
if (address.client().type().code === 'normal') {
if (address.client().isFreezed)
throw new UserError(`You can't create a ticket for a frozen client`);
if (!address.client().isActive)
throw new UserError(`You can't create a ticket for a inactive client`);
if (!address.client().isActive)
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 clientFk = address.clientFk;
let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
let clientDebt = await Self.rawSql(query, [clientFk]);