From d03ca01b73f2899c80a14972bd7de43794d5df5e Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Apr 2023 14:57:56 +0200 Subject: [PATCH 01/11] =?UTF-8?q?refs=20#5128=20a=C3=B1adida=20subseccion?= =?UTF-8?q?=20"Gesti=C3=B3n=20de=20cr=C3=A9dito"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/231401/00-aclClientInforma.sql | 3 + db/changes/231401/00-clientInforma.sql | 16 ++ modules/client/back/model-config.json | 3 + .../client/back/models/client-informa.json | 42 +++++ modules/client/back/models/client.js | 56 ++++++- modules/client/back/models/client.json | 8 +- .../client/front/credit-management/index.html | 91 +++++++++++ .../client/front/credit-management/index.js | 32 ++++ .../front/credit-management/index.spec.js | 38 +++++ .../front/credit-management/locale/es.yml | 2 + modules/client/front/index.js | 2 + modules/client/front/locale/es.yml | 1 + modules/client/front/routes.json | 13 +- modules/client/front/summary/index.html | 145 ++++++++++-------- modules/client/front/summary/locale/es.yml | 3 + 15 files changed, 383 insertions(+), 72 deletions(-) create mode 100644 db/changes/231401/00-aclClientInforma.sql create mode 100644 db/changes/231401/00-clientInforma.sql create mode 100644 modules/client/back/models/client-informa.json create mode 100644 modules/client/front/credit-management/index.html create mode 100644 modules/client/front/credit-management/index.js create mode 100644 modules/client/front/credit-management/index.spec.js create mode 100644 modules/client/front/credit-management/locale/es.yml diff --git a/db/changes/231401/00-aclClientInforma.sql b/db/changes/231401/00-aclClientInforma.sql new file mode 100644 index 000000000..6222d2632 --- /dev/null +++ b/db/changes/231401/00-aclClientInforma.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES ('ClientInforma', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('ClientInforma', '*', 'WRITE', 'ALLOW', 'ROLE', 'financial'); diff --git a/db/changes/231401/00-clientInforma.sql b/db/changes/231401/00-clientInforma.sql new file mode 100644 index 000000000..25405ef4d --- /dev/null +++ b/db/changes/231401/00-clientInforma.sql @@ -0,0 +1,16 @@ +ALTER TABLE `vn`.`client` ADD rating INT UNSIGNED DEFAULT NULL NULL COMMENT 'información proporcionada por Informa'; +ALTER TABLE `vn`.`client` ADD recommendedCredit INT UNSIGNED DEFAULT NULL NULL COMMENT 'información proporcionada por Informa'; + +CREATE TABLE `vn`.`clientInforma` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `clientFk` int(11) NOT NULL, + `rating` int(10) unsigned DEFAULT NULL, + `recommendedCredit` int(10) unsigned DEFAULT NULL, + `workerFk` int(10) unsigned NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `informaWorkers_fk_idx` (`workerFk`), + KEY `informaClientFk` (`clientFk`), + CONSTRAINT `informa_ClienteFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `informa_workers_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE +) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index b466aa5a1..1e06ea1c0 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -32,6 +32,9 @@ "ClientConsumptionQueue": { "dataSource": "vn" }, + "ClientInforma": { + "dataSource": "vn" + }, "ClientLog": { "dataSource": "vn" }, diff --git a/modules/client/back/models/client-informa.json b/modules/client/back/models/client-informa.json new file mode 100644 index 000000000..0c652484e --- /dev/null +++ b/modules/client/back/models/client-informa.json @@ -0,0 +1,42 @@ +{ + "name": "ClientInforma", + "base": "Loggable", + "log": { + "model":"ClientLog", + "relation": "client", + "showField": "clientFk" + }, + "options": { + "mysql": { + "table": "clientInforma" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "rating": { + "type": "number" + }, + "recommendedCredit": { + "type": "number" + }, + "created": { + "type": "date" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "clientFk" + } + } +} diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index c41085b79..579c6a8d4 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -280,6 +280,10 @@ module.exports = Self => { if (changes.credit !== undefined) await Self.changeCredit(ctx, finalState, changes); + // Credit management changes + if (orgData.rating != changes.rating || orgData.recommendedCredit != changes.recommendedCredit) + await Self.changeCreditManagement(ctx, finalState, changes); + const oldInstance = {}; if (!ctx.isNewInstance) { const newProps = Object.keys(changes); @@ -441,6 +445,55 @@ module.exports = Self => { }, ctx.options); }; + Self.changeCreditManagement = async function changeCreditManagement(ctx, finalState, changes) { + const models = Self.app.models; + const userId = ctx.options.accessToken.userId; + + // const isFinancialBoss = await models.Account.hasRole(userId, 'financialBoss', ctx.options); + // if (!isFinancialBoss) { + // const lastCredit = await models.ClientCredit.findOne({ + // where: { + // clientFk: finalState.id + // }, + // order: 'id DESC' + // }, ctx.options); + + // const lastAmount = lastCredit && lastCredit.amount; + // const lastWorkerId = lastCredit && lastCredit.workerFk; + // const lastWorkerIsFinancialBoss = await models.Account.hasRole(lastWorkerId, 'financialBoss', ctx.options); + + // if (lastAmount == 0 && lastWorkerIsFinancialBoss) + // throw new UserError(`You can't change the credit set to zero from a financialBoss`); + + // const creditLimits = await models.ClientCreditLimit.find({ + // fields: ['roleFk'], + // where: { + // maxAmount: {gte: changes.credit} + // } + // }, ctx.options); + + // const requiredRoles = []; + // for (limit of creditLimits) + // requiredRoles.push(limit.roleFk); + + // const userRequiredRoles = await models.RoleMapping.count({ + // roleId: {inq: requiredRoles}, + // principalType: 'USER', + // principalId: userId + // }, ctx.options); + + // if (userRequiredRoles <= 0) + // throw new UserError(`You don't have enough privileges to set this credit amount`); + // } + + await models.ClientInforma.create({ + clientFk: finalState.id, + rating: changes.rating, + recommendedCredit: changes.recommendedCredit, + workerFk: userId + }, ctx.options); + }; + const app = require('vn-loopback/server/server'); app.on('started', function() { const account = app.models.Account; @@ -474,7 +527,8 @@ module.exports = Self => { oldInstance: {name: oldData.name, active: oldData.active}, newInstance: {name: changes.name, active: changes.active} }; - await Self.app.models.ClientLog.create(logRecord); + console.log(logRecord); + // await Self.app.models.ClientLog.create(logRecord); } } }); diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index 21db28eaf..6ad617687 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -145,6 +145,12 @@ }, "hasElectronicInvoice": { "type": "boolean" + }, + "rating": { + "type": "number" + }, + "recommendedCredit": { + "type": "number" } }, @@ -260,4 +266,4 @@ } } } -} \ No newline at end of file +} diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html new file mode 100644 index 000000000..78cc6edb5 --- /dev/null +++ b/modules/client/front/credit-management/index.html @@ -0,0 +1,91 @@ + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + Since + Employee + Rating + Recommended credit + + + + + {{::clientInforma.created | date:'dd/MM/yyyy HH:mm'}} + + + {{::clientInforma.worker.user.nickname}} + + + {{::clientInforma.rating}} + {{::clientInforma.recommendedCredit}} + + + + + + + + + diff --git a/modules/client/front/credit-management/index.js b/modules/client/front/credit-management/index.js new file mode 100644 index 000000000..856acd27b --- /dev/null +++ b/modules/client/front/credit-management/index.js @@ -0,0 +1,32 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.filter = { + include: [{ + relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + } + } + }], + }; + } + onSubmit() { + this.$.watcher.submit() + .then(() => this.$state.reload()); + } +} + +ngModule.vnComponent('vnClientCreditManagement', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/client/front/credit-management/index.spec.js b/modules/client/front/credit-management/index.spec.js new file mode 100644 index 000000000..0f6460a03 --- /dev/null +++ b/modules/client/front/credit-management/index.spec.js @@ -0,0 +1,38 @@ +import './index'; + +describe('client unpaid', () => { + describe('Component vnClientUnpaid', () => { + let controller; + + beforeEach(ngModule('client')); + + beforeEach(inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnClientUnpaid', {$element}); + })); + + describe('setDefaultDate()', () => { + it(`should not set today date if has dated`, () => { + const hasData = true; + const yesterday = Date.vnNew(); + yesterday.setDate(yesterday.getDate() - 1); + + controller.clientUnpaid = { + dated: yesterday + }; + controller.setDefaultDate(hasData); + + expect(controller.clientUnpaid.dated).toEqual(yesterday); + }); + + it(`should set today if not has dated`, () => { + const hasData = true; + + controller.clientUnpaid = {}; + controller.setDefaultDate(hasData); + + expect(controller.clientUnpaid.dated).toBeDefined(); + }); + }); + }); +}); diff --git a/modules/client/front/credit-management/locale/es.yml b/modules/client/front/credit-management/locale/es.yml new file mode 100644 index 000000000..8743a1fb9 --- /dev/null +++ b/modules/client/front/credit-management/locale/es.yml @@ -0,0 +1,2 @@ +Recommended credit: Crédito recomendado +Rating: Clasificación diff --git a/modules/client/front/index.js b/modules/client/front/index.js index ff767bc9e..c7e39ea5d 100644 --- a/modules/client/front/index.js +++ b/modules/client/front/index.js @@ -47,3 +47,5 @@ import './defaulter'; import './notification'; import './unpaid'; import './extended-list'; +import './credit-management'; + diff --git a/modules/client/front/locale/es.yml b/modules/client/front/locale/es.yml index adbca8dbf..f14070f9e 100644 --- a/modules/client/front/locale/es.yml +++ b/modules/client/front/locale/es.yml @@ -64,3 +64,4 @@ Compensation Account: Cuenta para compensar Amount to return: Cantidad a devolver Delivered amount: Cantidad entregada Unpaid: Impagado +Credit management: Gestión de crédito diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index 406ca07d7..1a9b963e9 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -34,7 +34,8 @@ {"state": "client.card.contact", "icon": "contact_phone"}, {"state": "client.card.webPayment", "icon": "icon-onlinepayment"}, {"state": "client.card.dms.index", "icon": "cloud_upload"}, - {"state": "client.card.unpaid", "icon": "icon-defaulter"} + {"state": "client.card.unpaid", "icon": "icon-defaulter"}, + {"state": "client.card.creditManagement", "icon": "contact_support"} ] } ] @@ -416,7 +417,8 @@ "state": "client.notification", "component": "vn-client-notification", "description": "Notifications" - }, { + }, + { "url": "/unpaid", "state": "client.card.unpaid", "component": "vn-client-unpaid", @@ -428,6 +430,13 @@ "state": "client.extendedList", "component": "vn-client-extended-list", "description": "Extended list" + }, + { + "url": "/credit-management", + "state": "client.card.creditManagement", + "component": "vn-client-credit-management", + "acl": ["financial"], + "description": "Credit management" } ] } diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index ed4b89ee4..b8f88fa3c 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -22,75 +22,75 @@

- Basic data

-

Basic data

- - - - - - {{$ctrl.summary.salesPersonUser.name}} -

- Fiscal address

-

Fiscal address

- - - - - -

- Fiscal data

-

Fiscal data

- Billing data

-

Billing data

- - -

- Address @@ -201,10 +201,10 @@ ng-show="!$ctrl.isEmployee"> Address

- -

- Web access

-

Web access

- @@ -236,52 +236,61 @@

Business data

- - - - -
-

Financial information

- + + Financial information + + + + info="Invoices minus payments plus orders not yet invoiced"> - - - - - + +
@@ -341,7 +350,7 @@ class="link"> {{::ticket.refFk}} - {{::ticket.ticketState.state.name}} @@ -355,8 +364,8 @@ - - @@ -397,4 +406,4 @@ ticket="$ctrl.selectedTicket" model="model"> - \ No newline at end of file + diff --git a/modules/client/front/summary/locale/es.yml b/modules/client/front/summary/locale/es.yml index b6233d4b3..ca6e96fef 100644 --- a/modules/client/front/summary/locale/es.yml +++ b/modules/client/front/summary/locale/es.yml @@ -20,3 +20,6 @@ Invoices minus payments: Facturas menos recibos Deviated invoices minus payments: Facturas fuera de plazo menos recibos Go to the client: Ir al cliente Latest tickets: Últimos tickets +Rating: Clasificación +Value from 1 to 20. The higher the better value: Valor del 1 al 20. Cuanto más alto mejor valoración +Go to grafana: Ir a grafana From 4c18efa5894cea23d3600d8c7711deabd46ead49 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 14 Apr 2023 13:05:57 +0200 Subject: [PATCH 02/11] =?UTF-8?q?refs=20#5128=20creado=20m=C3=A9todo=20set?= =?UTF-8?q?Rating?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../00-aclClientInforma.sql | 0 .../{231401 => 231601}/00-clientInforma.sql | 2 +- .../client/back/methods/client/setRating.js | 62 +++++++++++++++++++ modules/client/back/models/client-methods.js | 1 + modules/client/back/models/client.js | 40 +----------- .../client/front/credit-management/index.html | 5 +- modules/client/front/locale/es.yml | 2 + modules/client/front/routes.json | 14 +++-- 8 files changed, 81 insertions(+), 45 deletions(-) rename db/changes/{231401 => 231601}/00-aclClientInforma.sql (100%) rename db/changes/{231401 => 231601}/00-clientInforma.sql (85%) create mode 100644 modules/client/back/methods/client/setRating.js diff --git a/db/changes/231401/00-aclClientInforma.sql b/db/changes/231601/00-aclClientInforma.sql similarity index 100% rename from db/changes/231401/00-aclClientInforma.sql rename to db/changes/231601/00-aclClientInforma.sql diff --git a/db/changes/231401/00-clientInforma.sql b/db/changes/231601/00-clientInforma.sql similarity index 85% rename from db/changes/231401/00-clientInforma.sql rename to db/changes/231601/00-clientInforma.sql index 25405ef4d..9bf757fc3 100644 --- a/db/changes/231401/00-clientInforma.sql +++ b/db/changes/231601/00-clientInforma.sql @@ -13,4 +13,4 @@ CREATE TABLE `vn`.`clientInforma` ( KEY `informaClientFk` (`clientFk`), CONSTRAINT `informa_ClienteFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `informa_workers_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='información proporcionada por Informa, se actualiza desde el hook de client (salix)'; diff --git a/modules/client/back/methods/client/setRating.js b/modules/client/back/methods/client/setRating.js new file mode 100644 index 000000000..06e7ebf1e --- /dev/null +++ b/modules/client/back/methods/client/setRating.js @@ -0,0 +1,62 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('setRating', { + description: 'Change role and hasGrant if user has setRating', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The user id', + http: {source: 'path'} + }, + { + arg: 'rating', + type: 'number' + }, + { + arg: 'recommendedCredit', + type: 'number' + } + ], + http: { + path: `/:id/setRating`, + verb: 'POST' + } + }); + + Self.setRating = async function(ctx, id, rating, recommendedCredit, options) { + const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const isFinancial = await models.Account.hasRole(userId, 'financial', myOptions); + if (!isFinancial) + throw new UserError(`You don't have enough privileges`); + + const client = await Self.findById(id, null, myOptions); + const clientUpdated = await client.updateAttributes({ + rating: rating, + recommendedCredit: recommendedCredit + }, myOptions); + + if (tx) await tx.commit(); + + return clientUpdated; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js index 3538dbeb8..3b1a588ac 100644 --- a/modules/client/back/models/client-methods.js +++ b/modules/client/back/models/client-methods.js @@ -47,4 +47,5 @@ module.exports = Self => { require('../methods/client/consumptionSendQueued')(Self); require('../methods/client/filter')(Self); require('../methods/client/getClientOrSupplierReference')(Self); + require('../methods/client/setRating')(Self); }; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 579c6a8d4..94c583dcc 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -447,44 +447,8 @@ module.exports = Self => { Self.changeCreditManagement = async function changeCreditManagement(ctx, finalState, changes) { const models = Self.app.models; - const userId = ctx.options.accessToken.userId; - - // const isFinancialBoss = await models.Account.hasRole(userId, 'financialBoss', ctx.options); - // if (!isFinancialBoss) { - // const lastCredit = await models.ClientCredit.findOne({ - // where: { - // clientFk: finalState.id - // }, - // order: 'id DESC' - // }, ctx.options); - - // const lastAmount = lastCredit && lastCredit.amount; - // const lastWorkerId = lastCredit && lastCredit.workerFk; - // const lastWorkerIsFinancialBoss = await models.Account.hasRole(lastWorkerId, 'financialBoss', ctx.options); - - // if (lastAmount == 0 && lastWorkerIsFinancialBoss) - // throw new UserError(`You can't change the credit set to zero from a financialBoss`); - - // const creditLimits = await models.ClientCreditLimit.find({ - // fields: ['roleFk'], - // where: { - // maxAmount: {gte: changes.credit} - // } - // }, ctx.options); - - // const requiredRoles = []; - // for (limit of creditLimits) - // requiredRoles.push(limit.roleFk); - - // const userRequiredRoles = await models.RoleMapping.count({ - // roleId: {inq: requiredRoles}, - // principalType: 'USER', - // principalId: userId - // }, ctx.options); - - // if (userRequiredRoles <= 0) - // throw new UserError(`You don't have enough privileges to set this credit amount`); - // } + const loopBackContext = LoopBackContext.getCurrentContext(); + const userId = loopBackContext.active.accessToken.userId; await models.ClientInforma.create({ clientFk: finalState.id, diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html index 78cc6edb5..85ecb1f96 100644 --- a/modules/client/front/credit-management/index.html +++ b/modules/client/front/credit-management/index.html @@ -1,11 +1,11 @@ - + + save="post">
@@ -37,6 +37,7 @@ + Date: Tue, 18 Apr 2023 09:09:09 +0200 Subject: [PATCH 03/11] refs #5128 add testBack --- .../client/back/methods/client/setRating.js | 2 +- .../methods/client/specs/setRating.spec.js | 43 +++++++++++++++++++ modules/client/back/models/client.js | 2 +- .../front/credit-management/index.spec.js | 38 ---------------- 4 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 modules/client/back/methods/client/specs/setRating.spec.js delete mode 100644 modules/client/front/credit-management/index.spec.js diff --git a/modules/client/back/methods/client/setRating.js b/modules/client/back/methods/client/setRating.js index 06e7ebf1e..a57cdbd1c 100644 --- a/modules/client/back/methods/client/setRating.js +++ b/modules/client/back/methods/client/setRating.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('setRating', { - description: 'Change role and hasGrant if user has setRating', + description: 'Change rating and recommendedCredit of a client', accepts: [ { arg: 'id', diff --git a/modules/client/back/methods/client/specs/setRating.spec.js b/modules/client/back/methods/client/specs/setRating.spec.js new file mode 100644 index 000000000..a7d0fb03a --- /dev/null +++ b/modules/client/back/methods/client/specs/setRating.spec.js @@ -0,0 +1,43 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +describe('Client setRating()', () => { + const financialId = 73; + const activeCtx = { + accessToken: {userId: financialId}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + const ctx = {req: activeCtx}; + + beforeAll(async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should change rating and recommendedCredit', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const clientId = 1101; + const newRating = 10; + const newRecommendedCredit = 20; + + const updatedClient = await models.Client.setRating(ctx, clientId, newRating, newRecommendedCredit, options); + + expect(updatedClient.rating).toEqual(newRating); + expect(updatedClient.recommendedCredit).toEqual(newRecommendedCredit); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 94c583dcc..5cabd1877 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -281,7 +281,7 @@ module.exports = Self => { await Self.changeCredit(ctx, finalState, changes); // Credit management changes - if (orgData.rating != changes.rating || orgData.recommendedCredit != changes.recommendedCredit) + if (orgData?.rating != changes.rating || orgData?.recommendedCredit != changes.recommendedCredit) await Self.changeCreditManagement(ctx, finalState, changes); const oldInstance = {}; diff --git a/modules/client/front/credit-management/index.spec.js b/modules/client/front/credit-management/index.spec.js deleted file mode 100644 index 0f6460a03..000000000 --- a/modules/client/front/credit-management/index.spec.js +++ /dev/null @@ -1,38 +0,0 @@ -import './index'; - -describe('client unpaid', () => { - describe('Component vnClientUnpaid', () => { - let controller; - - beforeEach(ngModule('client')); - - beforeEach(inject($componentController => { - const $element = angular.element(''); - controller = $componentController('vnClientUnpaid', {$element}); - })); - - describe('setDefaultDate()', () => { - it(`should not set today date if has dated`, () => { - const hasData = true; - const yesterday = Date.vnNew(); - yesterday.setDate(yesterday.getDate() - 1); - - controller.clientUnpaid = { - dated: yesterday - }; - controller.setDefaultDate(hasData); - - expect(controller.clientUnpaid.dated).toEqual(yesterday); - }); - - it(`should set today if not has dated`, () => { - const hasData = true; - - controller.clientUnpaid = {}; - controller.setDefaultDate(hasData); - - expect(controller.clientUnpaid.dated).toBeDefined(); - }); - }); - }); -}); From c5225cb632ff25209da783fdf620e306690863e9 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Apr 2023 09:23:19 +0200 Subject: [PATCH 04/11] =?UTF-8?q?refs=20#5128=20borrado=20=20c=C3=B3digo?= =?UTF-8?q?=20innecesario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/client/back/models/client.js | 2 -- modules/client/front/credit-management/index.html | 9 --------- 2 files changed, 11 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 5cabd1877..10307a0d0 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -491,8 +491,6 @@ module.exports = Self => { oldInstance: {name: oldData.name, active: oldData.active}, newInstance: {name: changes.name, active: changes.active} }; - console.log(logRecord); - // await Self.app.models.ClientLog.create(logRecord); } } }); diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html index 85ecb1f96..f1267c317 100644 --- a/modules/client/front/credit-management/index.html +++ b/modules/client/front/credit-management/index.html @@ -78,15 +78,6 @@
- - From b3e7cedd1e8f9051bb298f51b370d1cc7f71310b Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Apr 2023 09:49:12 +0200 Subject: [PATCH 05/11] =?UTF-8?q?refs=20#5128=20borrada=20l=C3=ADnea=20por?= =?UTF-8?q?=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/client/back/models/client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 10307a0d0..14854d214 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -491,6 +491,7 @@ module.exports = Self => { oldInstance: {name: oldData.name, active: oldData.active}, newInstance: {name: changes.name, active: changes.active} }; + await Self.app.models.ClientLog.create(logRecord); } } }); From 3c334a9f014c20b25f1520d9f0201bc30ec33790 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Apr 2023 15:16:59 +0200 Subject: [PATCH 06/11] =?UTF-8?q?refs=20#5128=20fix=20e2e:=20manejado=20qu?= =?UTF-8?q?e=20pueda=20haver=20m=C3=A1s=20de=201=20men=C3=BA=20desplegable?= =?UTF-8?q?=20en=20el=20card?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/helpers/extensions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 7d80c69ee..1fcbfd616 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -156,14 +156,14 @@ let actions = { await this.waitForSpinnerLoad(); }, - accessToSection: async function(state) { + accessToSection: async function(state, name = 'Others') { await this.waitForSelector('vn-left-menu'); let nested = await this.evaluate(state => { return document.querySelector(`vn-left-menu li li > a[ui-sref="${state}"]`) != null; }, state); if (nested) { - let selector = 'vn-left-menu vn-item-section > vn-icon[icon=keyboard_arrow_down]'; + let selector = `vn-left-menu li[name="${name}"]`; await this.evaluate(selector => { document.querySelector(selector).scrollIntoViewIfNeeded(); }, selector); From 187ba032d249f10f50f6c86475f81e414cd58874 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 19 Apr 2023 14:43:15 +0200 Subject: [PATCH 07/11] refs #5128 rol por ACL --- db/changes/231601/00-client_setRatingAcl.sql | 65 +++++++++++++++++++ .../client/back/methods/client/setRating.js | 9 +-- .../client/front/credit-management/index.html | 1 + 3 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 db/changes/231601/00-client_setRatingAcl.sql diff --git a/db/changes/231601/00-client_setRatingAcl.sql b/db/changes/231601/00-client_setRatingAcl.sql new file mode 100644 index 000000000..211a407ab --- /dev/null +++ b/db/changes/231601/00-client_setRatingAcl.sql @@ -0,0 +1,65 @@ +DELETE FROM `salix`.`ACL` WHERE id=7; + +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + ('Client', 'setRating', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'setRating', 'WRITE', 'ALLOW', 'ROLE', 'financial'); + +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + ('Client', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'addressesPropagateRe', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'canBeInvoiced', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'canCreateTicket', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'consumption', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'createAddress', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'createWithUser', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'extendedListFilter', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'getAverageInvoiced', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'getCard', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'getDebt', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'getMana', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'transactions', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'hasCustomerRole', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'isValidClient', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'lastActiveTickets', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'sendSms', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'setPassword', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'summary', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'updateAddress', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'updateFiscalData', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'updateUser', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'uploadFile', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'campaignMetricsPdf', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'campaignMetricsEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'clientWelcomeHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'clientWelcomeEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'printerSetupHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'printerSetupEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'sepaCoreEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'letterDebtorPdf', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'letterDebtorStHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'letterDebtorStEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'letterDebtorNdHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'letterDebtorNdEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'clientDebtStatementPdf', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'clientDebtStatementHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'clientDebtStatementEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'creditRequestPdf', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'creditRequestHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'creditRequestEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'incotermsAuthorizationPdf', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'incotermsAuthorizationHtml', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'incotermsAuthorizationEmail', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'consumptionSendQueued', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'filter', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'getClientOrSupplierReference', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'upsert', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'create', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'replaceById', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'updateAttributes', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'updateAttributes', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'deleteById', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'replaceOrCreate', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'updateAll', '*', 'ALLOW', 'ROLE', 'employee'), + ('Client', 'upsertWithWhere', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/modules/client/back/methods/client/setRating.js b/modules/client/back/methods/client/setRating.js index a57cdbd1c..21ac0c914 100644 --- a/modules/client/back/methods/client/setRating.js +++ b/modules/client/back/methods/client/setRating.js @@ -1,8 +1,7 @@ -const UserError = require('vn-loopback/util/user-error'); - module.exports = Self => { Self.remoteMethodCtx('setRating', { description: 'Change rating and recommendedCredit of a client', + accessType: 'WRITE', accepts: [ { arg: 'id', @@ -27,8 +26,6 @@ module.exports = Self => { }); Self.setRating = async function(ctx, id, rating, recommendedCredit, options) { - const models = Self.app.models; - const userId = ctx.req.accessToken.userId; let tx; const myOptions = {}; @@ -41,10 +38,6 @@ module.exports = Self => { } try { - const isFinancial = await models.Account.hasRole(userId, 'financial', myOptions); - if (!isFinancial) - throw new UserError(`You don't have enough privileges`); - const client = await Self.findById(id, null, myOptions); const clientUpdated = await client.updateAttributes({ rating: rating, diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html index f1267c317..8acd030f2 100644 --- a/modules/client/front/credit-management/index.html +++ b/modules/client/front/credit-management/index.html @@ -4,6 +4,7 @@ url="Clients" data="$ctrl.client" id-value="$ctrl.$params.id" + insert-mode="true" form="form" save="post"> From 6fbb734a34a358c950f4a9406078cf5e0f197a25 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 19 Apr 2023 14:43:23 +0200 Subject: [PATCH 08/11] quitado salto de linea --- modules/client/front/credit-management/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html index 8acd030f2..29f600697 100644 --- a/modules/client/front/credit-management/index.html +++ b/modules/client/front/credit-management/index.html @@ -38,7 +38,6 @@ - Date: Wed, 19 Apr 2023 15:21:59 +0200 Subject: [PATCH 09/11] refs #5128 intentando poner icono grafana --- modules/client/front/credit-management/index.html | 4 ---- modules/client/front/summary/index.html | 12 +++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/client/front/credit-management/index.html b/modules/client/front/credit-management/index.html index 29f600697..d7456fd06 100644 --- a/modules/client/front/credit-management/index.html +++ b/modules/client/front/credit-management/index.html @@ -31,10 +31,6 @@ disabled="!watcher.dataChanged()" label="Save"> - - diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index b8f88fa3c..223f9117a 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -1,3 +1,6 @@ + + + -

Business data

+ +
+

Business data

+ + +
+
From ec9a5722c21f17508d95204af1fda9326bd42316 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Apr 2023 13:58:49 +0200 Subject: [PATCH 10/11] =?UTF-8?q?refs=20#5128=20a=C3=B1adido=20icono=20de?= =?UTF-8?q?=20grafana?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/client/front/summary/index.html | 14 +++----------- modules/client/front/summary/style.scss | 9 +++++++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index 223f9117a..1b58d42cc 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -238,14 +238,7 @@
- -
-

Business data

- - -
-
+

Business data

@@ -264,9 +257,8 @@

- - Financial information + + Billing data

Date: Thu, 20 Apr 2023 15:17:49 +0200 Subject: [PATCH 11/11] borrado acl innecesario --- db/changes/231601/00-client_setRatingAcl.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/changes/231601/00-client_setRatingAcl.sql b/db/changes/231601/00-client_setRatingAcl.sql index 211a407ab..b041b131a 100644 --- a/db/changes/231601/00-client_setRatingAcl.sql +++ b/db/changes/231601/00-client_setRatingAcl.sql @@ -2,7 +2,6 @@ DELETE FROM `salix`.`ACL` WHERE id=7; INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) VALUES - ('Client', 'setRating', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Client', 'setRating', 'WRITE', 'ALLOW', 'ROLE', 'financial'); INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)