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