From 69434caa5224f5f41963d0c707c0c676858e884f Mon Sep 17 00:00:00 2001 From: Bernat Date: Tue, 28 May 2019 11:26:54 +0200 Subject: [PATCH] #1470 update fixtures, client.dms gestdoc --- back/models/dms.json | 7 ++ back/models/dmsType.json | 4 + .../{10004-mother => 10040-mother}/00-acl.sql | 0 .../00-clest.sql | 0 .../00-clientDms.sql | 0 .../00-dmsView.sql | 0 .../00-mandateType.sql | 0 .../00-sample.sql | 0 .../00-tarifaComponentes.sql | 0 .../00-ticket.sql | 0 .../01-claimState.sql | 0 .../01-componentRate.sql | 0 .../01-viewTicket.sql | 0 db/changes/10050-pentecostes/00-ACL.sql | 2 + .../10050-pentecostes/00-clientesgestdoc.sql | 19 +++++ .../10050-pentecostes/01-clienteesGestdoc.sql | 9 +++ .../01-gesttipData.sql | 0 .../01-tarifaComponentesData.sql | 0 db/dump/fixtures.sql | 8 +- .../createWithInsurance.js | 2 +- modules/client/back/methods/dms/removes.js | 35 +++++++++ .../client/back/methods/dms/removes.spec.js | 29 ++++++++ modules/client/back/models/client-dms.js | 3 + modules/client/back/models/client-dms.json | 16 ++-- modules/client/front/dms/index.html | 74 +++++++++++++++++++ modules/client/front/dms/index.js | 71 ++++++++++++++++++ modules/client/front/dms/locale/es.yml | 9 +++ modules/client/front/dms/style.scss | 6 ++ modules/client/front/index.js | 1 + modules/client/front/routes.json | 9 ++- .../ticket/back/models/component-rate.json | 3 + 31 files changed, 294 insertions(+), 13 deletions(-) rename db/changes/{10004-mother => 10040-mother}/00-acl.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-clest.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-clientDms.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-dmsView.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-mandateType.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-sample.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-tarifaComponentes.sql (100%) rename db/changes/{10004-mother => 10040-mother}/00-ticket.sql (100%) rename db/changes/{10004-mother => 10040-mother}/01-claimState.sql (100%) rename db/changes/{10004-mother => 10040-mother}/01-componentRate.sql (100%) rename db/changes/{10004-mother => 10040-mother}/01-viewTicket.sql (100%) create mode 100644 db/changes/10050-pentecostes/00-ACL.sql create mode 100644 db/changes/10050-pentecostes/00-clientesgestdoc.sql create mode 100644 db/changes/10050-pentecostes/01-clienteesGestdoc.sql rename db/changes/{10005-pentecostes => 10050-pentecostes}/01-gesttipData.sql (100%) rename db/changes/{10005-pentecostes => 10050-pentecostes}/01-tarifaComponentesData.sql (100%) create mode 100644 modules/client/back/methods/dms/removes.js create mode 100644 modules/client/back/methods/dms/removes.spec.js create mode 100644 modules/client/back/models/client-dms.js create mode 100644 modules/client/front/dms/index.html create mode 100644 modules/client/front/dms/index.js create mode 100644 modules/client/front/dms/locale/es.yml create mode 100644 modules/client/front/dms/style.scss diff --git a/back/models/dms.json b/back/models/dms.json index d5ec4b8b73..dc421a7a12 100644 --- a/back/models/dms.json +++ b/back/models/dms.json @@ -1,3 +1,4 @@ + { "name": "Dms", "description": "Documental Managment system", @@ -22,6 +23,12 @@ "description": { "type": "string" }, + "hardCopyNumber": { + "type": "Number" + }, + "hasFile": { + "type": "boolean" + }, "created": { "type": "Date" } diff --git a/back/models/dmsType.json b/back/models/dmsType.json index 9efc92cf52..b51c810acd 100644 --- a/back/models/dmsType.json +++ b/back/models/dmsType.json @@ -20,6 +20,10 @@ "path": { "type": "string", "required": true + }, + "code": { + "type": "string", + "required": true } }, "relations": { diff --git a/db/changes/10004-mother/00-acl.sql b/db/changes/10040-mother/00-acl.sql similarity index 100% rename from db/changes/10004-mother/00-acl.sql rename to db/changes/10040-mother/00-acl.sql diff --git a/db/changes/10004-mother/00-clest.sql b/db/changes/10040-mother/00-clest.sql similarity index 100% rename from db/changes/10004-mother/00-clest.sql rename to db/changes/10040-mother/00-clest.sql diff --git a/db/changes/10004-mother/00-clientDms.sql b/db/changes/10040-mother/00-clientDms.sql similarity index 100% rename from db/changes/10004-mother/00-clientDms.sql rename to db/changes/10040-mother/00-clientDms.sql diff --git a/db/changes/10004-mother/00-dmsView.sql b/db/changes/10040-mother/00-dmsView.sql similarity index 100% rename from db/changes/10004-mother/00-dmsView.sql rename to db/changes/10040-mother/00-dmsView.sql diff --git a/db/changes/10004-mother/00-mandateType.sql b/db/changes/10040-mother/00-mandateType.sql similarity index 100% rename from db/changes/10004-mother/00-mandateType.sql rename to db/changes/10040-mother/00-mandateType.sql diff --git a/db/changes/10004-mother/00-sample.sql b/db/changes/10040-mother/00-sample.sql similarity index 100% rename from db/changes/10004-mother/00-sample.sql rename to db/changes/10040-mother/00-sample.sql diff --git a/db/changes/10004-mother/00-tarifaComponentes.sql b/db/changes/10040-mother/00-tarifaComponentes.sql similarity index 100% rename from db/changes/10004-mother/00-tarifaComponentes.sql rename to db/changes/10040-mother/00-tarifaComponentes.sql diff --git a/db/changes/10004-mother/00-ticket.sql b/db/changes/10040-mother/00-ticket.sql similarity index 100% rename from db/changes/10004-mother/00-ticket.sql rename to db/changes/10040-mother/00-ticket.sql diff --git a/db/changes/10004-mother/01-claimState.sql b/db/changes/10040-mother/01-claimState.sql similarity index 100% rename from db/changes/10004-mother/01-claimState.sql rename to db/changes/10040-mother/01-claimState.sql diff --git a/db/changes/10004-mother/01-componentRate.sql b/db/changes/10040-mother/01-componentRate.sql similarity index 100% rename from db/changes/10004-mother/01-componentRate.sql rename to db/changes/10040-mother/01-componentRate.sql diff --git a/db/changes/10004-mother/01-viewTicket.sql b/db/changes/10040-mother/01-viewTicket.sql similarity index 100% rename from db/changes/10004-mother/01-viewTicket.sql rename to db/changes/10040-mother/01-viewTicket.sql diff --git a/db/changes/10050-pentecostes/00-ACL.sql b/db/changes/10050-pentecostes/00-ACL.sql new file mode 100644 index 0000000000..d578266051 --- /dev/null +++ b/db/changes/10050-pentecostes/00-ACL.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` ( `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ( 'ClientDms', 'remove', 'WRITE', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` ( `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ( 'ClientDms', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10050-pentecostes/00-clientesgestdoc.sql b/db/changes/10050-pentecostes/00-clientesgestdoc.sql new file mode 100644 index 0000000000..3e7a023c91 --- /dev/null +++ b/db/changes/10050-pentecostes/00-clientesgestdoc.sql @@ -0,0 +1,19 @@ +ALTER TABLE `vn2008`.`clientes_gestdoc` +DROP FOREIGN KEY `clientes_gestdoc_ibfk_3`; +ALTER TABLE `vn2008`.`clientes_gestdoc` +DROP PRIMARY KEY, +ADD PRIMARY KEY (`gest_doc_id`); + + +ALTER TABLE `vn2008`.`clientes_gestdoc` +DROP INDEX `fk_clientes_gestdoc_1_idx` ; + +ALTER TABLE `vn2008`.`clientes_gestdoc` +ADD INDEX `fk_clientes_gestdoc_1_idx` (`Id_Cliente` ASC); + +ALTER TABLE `vn2008`.`clientes_gestdoc` +ADD CONSTRAINT `fk_clientes_gestdoc_3` + FOREIGN KEY (`Id_Cliente`) + REFERENCES `vn2008`.`Clientes` (`id_cliente`) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/db/changes/10050-pentecostes/01-clienteesGestdoc.sql b/db/changes/10050-pentecostes/01-clienteesGestdoc.sql new file mode 100644 index 0000000000..294a39577f --- /dev/null +++ b/db/changes/10050-pentecostes/01-clienteesGestdoc.sql @@ -0,0 +1,9 @@ +ALTER TABLE `vn2008`.`clientes_gestdoc` +ADD INDEX `fk_clientes_gestdoc_1_idx` (`Id_Cliente` ASC); + +ALTER TABLE `vn2008`.`clientes_gestdoc` +ADD CONSTRAINT `fk_clientes_gestdoc_3` + FOREIGN KEY (`Id_Cliente`) + REFERENCES `vn2008`.`Clientes` (`id_cliente`) + ON DELETE RESTRICT + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/changes/10005-pentecostes/01-gesttipData.sql b/db/changes/10050-pentecostes/01-gesttipData.sql similarity index 100% rename from db/changes/10005-pentecostes/01-gesttipData.sql rename to db/changes/10050-pentecostes/01-gesttipData.sql diff --git a/db/changes/10005-pentecostes/01-tarifaComponentesData.sql b/db/changes/10050-pentecostes/01-tarifaComponentesData.sql similarity index 100% rename from db/changes/10005-pentecostes/01-tarifaComponentesData.sql rename to db/changes/10050-pentecostes/01-tarifaComponentesData.sql diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 47202d7df1..a35c905289 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1457,8 +1457,9 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `c INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) VALUES - (1, 14, '1.pdf', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()), - (2, 5, '2.pdf', 5, 1, 442, 1, TRUE, 'Client:101', 'Client:101 dms for the client', CURDATE()); + (1, 14, '1.pdf', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()), + (2, 5, '2.pdf', 5, 1, 442, 1, TRUE, 'Client:101', 'Client:101 dms for the client', CURDATE()), + (3, 5, '3.pdf', 5, 1, 442, NULL, TRUE, 'Client: 101', 'Client:101 readme', CURDATE()); INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`) VALUES @@ -1466,4 +1467,5 @@ INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`) INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`) VALUES - (101, 2); \ No newline at end of file + (101, 2), + (101, 3); \ No newline at end of file diff --git a/modules/client/back/methods/credit-classification/createWithInsurance.js b/modules/client/back/methods/credit-classification/createWithInsurance.js index 5836db2783..66e11d2711 100644 --- a/modules/client/back/methods/credit-classification/createWithInsurance.js +++ b/modules/client/back/methods/credit-classification/createWithInsurance.js @@ -22,7 +22,7 @@ module.exports = Self => { } }); - Self.createWithInsurance = async (data, ctx) => { + Self.createWithInsurance = async(data, ctx) => { let transaction = await Self.beginTransaction({}); try { diff --git a/modules/client/back/methods/dms/removes.js b/modules/client/back/methods/dms/removes.js new file mode 100644 index 0000000000..c3aeeed525 --- /dev/null +++ b/modules/client/back/methods/dms/removes.js @@ -0,0 +1,35 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('removes', { + description: 'Delete an client dms', + accessType: 'WRITE', + accepts: { + arg: 'dmsId', + type: 'number', + required: true, + description: 'dms identifier', + }, + returns: { + type: 'string', + root: true + }, + http: { + path: `/removes`, + verb: 'POST' + } + }); + + Self.removes = async dmsId => { + if (!dmsId) + throw new UserError('There is nothing to delete'); + + let targetClientDms = await Self.app.models.ClientDms.findOne({where: {dmsFk: dmsId}}); + let targetDms = await Self.app.models.Dms.findById(dmsId); + let trashDmsType = await Self.app.models.DmsType.findOne({where: {code: 'trash'}}); + + await targetClientDms.destroy(); + await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id); + }; +}; + diff --git a/modules/client/back/methods/dms/removes.spec.js b/modules/client/back/methods/dms/removes.spec.js new file mode 100644 index 0000000000..a5d653f7ee --- /dev/null +++ b/modules/client/back/methods/dms/removes.spec.js @@ -0,0 +1,29 @@ +const app = require('vn-loopback/server/server'); + +describe('Client dms stuff', () => { + let dmsToRestore; + let dmsTypeToRestore; + afterAll(async done => { + await app.models.ClientDms.create(dmsToRestore); + await dmsTypeToRestore.save(); + + done(); + }); + + + it('should delete a dms from a client and update the dmsType to trash', async() => { + const dmsId = 2; + + dmsToRestore = await app.models.ClientDms.findOne({where: {dmsFk: dmsId}}); + dmsTypeToRestore = await app.models.Dms.findById(dmsToRestore.dmsFk); + + await app.models.ClientDms.removes(dmsId); + + let destroyedDms = await app.models.ClientDms.findOne({where: {dmsFk: dmsId}}); + + let alteredDmsType = await app.models.Dms.findById(dmsId); + + expect(destroyedDms).toBeNull(); + expect(alteredDmsType.dmsTypeFk).toEqual(13); + }); +}); diff --git a/modules/client/back/models/client-dms.js b/modules/client/back/models/client-dms.js new file mode 100644 index 0000000000..ef74b3c393 --- /dev/null +++ b/modules/client/back/models/client-dms.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/dms/removes')(Self); +}; diff --git a/modules/client/back/models/client-dms.json b/modules/client/back/models/client-dms.json index 31fc830060..c919c22233 100644 --- a/modules/client/back/models/client-dms.json +++ b/modules/client/back/models/client-dms.json @@ -1,25 +1,24 @@ { "name": "ClientDms", "base": "Loggable", - "log": { - "model": "ClientLog", - "relation": "ticket", + "log": { + "model":"ClientLog", + "relation": "client", "showField": "dmsFk" - }, + }, "options": { "mysql": { "table": "clientDms" } }, "properties": { - "clientFk": { + "dmsFk": { "type": "Number", "id": true, "required": true }, - "dmsFk": { + "clientFk": { "type": "Number", - "id": true, "required": true } }, @@ -35,4 +34,5 @@ "foreignKey": "dmsFk" } } -} \ No newline at end of file +} + diff --git a/modules/client/front/dms/index.html b/modules/client/front/dms/index.html new file mode 100644 index 0000000000..df8bcfcb6a --- /dev/null +++ b/modules/client/front/dms/index.html @@ -0,0 +1,74 @@ + + + + + + + + + File + Description + Reference + Hard copy + Worker + Created + + + + + + + {{::document.dmsFk}} + + {{::document.dms.description}} + + {{::document.dms.reference}} + {{::document.dms.hardCopyNumber | dashIfEmpty}} + + + {{::document.dms.worker.user.nickname | dashIfEmpty}} + + + {{::document.dms.created | dateTime:'dd/MM/yyyy HH:mm'}} + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/client/front/dms/index.js b/modules/client/front/dms/index.js new file mode 100644 index 0000000000..9a3c274b75 --- /dev/null +++ b/modules/client/front/dms/index.js @@ -0,0 +1,71 @@ +import ngModule from '../module'; +import './style.scss'; + +class Controller { + constructor($stateParams, $scope, vnToken, $http, vnApp, $translate) { + this.$stateParams = $stateParams; + this.$ = $scope; + this.accessToken = vnToken.token; + this.$http = $http; + this.vnApp = vnApp; + this.$translate = $translate; + this.filter = { + include: { + relation: 'dms', + scope: { + fields: ['dmsTypeFk', 'workerFk', 'file', 'created', 'description', 'reference', 'hardCopyNumber'], + include: [{ + relation: 'dmsType', + scope: { + fields: ['name'] + } + }, + { + relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + }, + } + }] + }, + } + }; + } + + showWorkerDescriptor(event, workerFk) { + event.preventDefault(); + event.stopImmediatePropagation(); + this.$.workerDescriptor.parent = event.target; + this.$.workerDescriptor.workerFk = workerFk; + this.$.workerDescriptor.show(); + } + + showDeleteConfirm(dmsId) { + this.selectedDms = dmsId; + this.$.confirm.show(); + } + + deleteDms(response) { + if (response === 'ACCEPT') { + let dmsId = this.selectedDms; + let query = `/client/api/ClientDms/removes`; + + this.$http.post(query, {dmsId}).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.model.refresh(); + }); + } + } +} + +Controller.$inject = ['$stateParams', '$scope', 'vnToken', '$http', 'vnApp', '$translate']; + +ngModule.component('vnClientDms', { + template: require('./index.html'), + controller: Controller, +}); diff --git a/modules/client/front/dms/locale/es.yml b/modules/client/front/dms/locale/es.yml new file mode 100644 index 0000000000..0994c7d868 --- /dev/null +++ b/modules/client/front/dms/locale/es.yml @@ -0,0 +1,9 @@ +Type: Tipo +File management: GestiĆ³n documental +File: Fichero +Hard copy: Copia +This file will be deleted: Este fichero va a ser borrado +Are you sure?: Estas seguro? +File deleted: Fichero eliminado +Remove file: Eliminar fichero +Download file: Descargar fichero \ No newline at end of file diff --git a/modules/client/front/dms/style.scss b/modules/client/front/dms/style.scss new file mode 100644 index 0000000000..a6758e2e61 --- /dev/null +++ b/modules/client/front/dms/style.scss @@ -0,0 +1,6 @@ +vn-client-risk-index { + .totalBox { + display: table; + float: right; + } +} \ No newline at end of file diff --git a/modules/client/front/index.js b/modules/client/front/index.js index d6a910c869..b124aab7bf 100644 --- a/modules/client/front/index.js +++ b/modules/client/front/index.js @@ -35,4 +35,5 @@ import './sample/create'; import './web-payment'; import './log'; import './sms'; +import './dms'; diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index a927d0aa73..8f01f57710 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -24,7 +24,8 @@ {"state": "client.card.creditInsurance.index", "icon": "icon-solunion"}, {"state": "client.card.contact", "icon": "contact_phone"}, {"state": "client.card.sample.index", "icon": "mail"}, - {"state": "client.card.webPayment", "icon": "icon-onlinepayment"} + {"state": "client.card.webPayment", "icon": "icon-onlinepayment"}, + {"state": "client.card.dms", "icon": "cloud_download"} ] } ], @@ -314,6 +315,12 @@ "state": "client.card.log", "component": "vn-client-log", "description": "Log" + }, + { + "url": "/dms", + "state": "client.card.dms", + "component": "vn-client-dms", + "description": "File management" } ] } diff --git a/modules/ticket/back/models/component-rate.json b/modules/ticket/back/models/component-rate.json index 6e796cbb20..3a69c6eb6c 100644 --- a/modules/ticket/back/models/component-rate.json +++ b/modules/ticket/back/models/component-rate.json @@ -26,6 +26,9 @@ }, "componentTypeRate": { "type": "Number" + }, + "code": { + "type": "String" } }, "relations": {