diff --git a/modules/agency/front/descriptor/index.js b/modules/agency/front/descriptor/index.js index 3986f6edc..c8d6bbc26 100644 --- a/modules/agency/front/descriptor/index.js +++ b/modules/agency/front/descriptor/index.js @@ -24,7 +24,6 @@ class Controller { this.$state.go('zone.index'); }); } - console.log('res', response); } } diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index 2a06866dc..ff4771330 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -38,6 +38,9 @@ "CreditInsurance": { "dataSource": "vn" }, + "ClientType": { + "dataSource": "vn" + }, "Defaulter": { "dataSource": "vn" }, diff --git a/modules/client/back/models/client-type.json b/modules/client/back/models/client-type.json new file mode 100644 index 000000000..a91cc38b6 --- /dev/null +++ b/modules/client/back/models/client-type.json @@ -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" + } + } +} \ No newline at end of file diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index 90144e52b..926c9cde9 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -151,7 +151,7 @@ "type": { "type": "belongsTo", "model": "ClientType", - "foreignKey": "typeFk" + "foreignKey": "clientTypeFk" }, "addresses": { "type": "hasMany", diff --git a/modules/order/back/methods/order/isEditable.js b/modules/order/back/methods/order/isEditable.js index 9ac3c288e..5f1fc7872 100644 --- a/modules/order/back/methods/order/isEditable.js +++ b/modules/order/back/methods/order/isEditable.js @@ -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; diff --git a/modules/order/back/methods/order/new.js b/modules/order/back/methods/order/new.js index 98eb0ce1a..259fb3ea2 100644 --- a/modules/order/back/methods/order/new.js +++ b/modules/order/back/methods/order/new.js @@ -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, [ diff --git a/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js b/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js index 535df182a..1cf540a1b 100644 --- a/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js +++ b/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js @@ -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); diff --git a/modules/ticket/back/methods/ticket/isEditable.js b/modules/ticket/back/methods/ticket/isEditable.js index 427133ef4..95805948a 100644 --- a/modules/ticket/back/methods/ticket/isEditable.js +++ b/modules/ticket/back/methods/ticket/isEditable.js @@ -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; diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index 7cd4eb0c9..c0404e084 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -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]);