From 3aeb2adb56bc5e4db554f02001748c9b9aacfc8f Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 16 Feb 2022 14:57:47 +0100 Subject: [PATCH] feat(ticket): docuware pdf --- back/methods/docuware/checkFile.js | 80 +++++++++++ back/methods/docuware/download.js | 104 ++++++++++---- back/methods/docuware/specs/checkFile.spec.js | 129 ++++++++++++++++++ back/methods/docuware/specs/download.spec.js | 28 ++++ back/model-config.json | 6 + back/models/docuware-config.json | 32 +++++ back/models/docuware-container.json | 10 ++ back/models/docuware.js | 1 + db/changes/10420-valentines/00-docuware.sql | 6 +- .../10420-valentines/00-docuwareConfig.sql | 6 +- db/dump/fixtures.sql | 8 ++ loopback/server/datasources.json | 11 ++ .../back/methods/invoiceOut/docuware.js | 65 --------- modules/invoiceOut/back/models/invoice-out.js | 1 - .../ticket/front/descriptor-menu/index.html | 12 +- modules/ticket/front/descriptor-menu/index.js | 8 ++ .../front/descriptor-menu/locale/es.yml | 4 +- 17 files changed, 408 insertions(+), 103 deletions(-) create mode 100644 back/methods/docuware/checkFile.js create mode 100644 back/methods/docuware/specs/checkFile.spec.js create mode 100644 back/methods/docuware/specs/download.spec.js create mode 100644 back/models/docuware-config.json create mode 100644 back/models/docuware-container.json delete mode 100644 modules/invoiceOut/back/methods/invoiceOut/docuware.js diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js new file mode 100644 index 000000000..7dc1993f0 --- /dev/null +++ b/back/methods/docuware/checkFile.js @@ -0,0 +1,80 @@ +const got = require('got'); +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('checkFile', { + description: 'Download an docuware PDF', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'String', + description: 'The invoice id', + http: {source: 'path'} + } + ], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/:id/checkFile`, + verb: 'GET' + } + }); + + Self.checkFile = async function(ctx, id) { + // const fileCabinet = 'ad2c49df-8976-4941-bb19-9b30685f14a4'; + // hay que crear tambien una busqueda por cada fileCabinet + // columnas necesarias. seccion, fileCabinet, DBName, dialog + + const models = Self.app.models; + const docuwareConfig = await models.DocuwareConfig.findOne(); + const docuwareInfo = await models.Docuware.findOne({ + where: { + name: 'deliveryClient', + dialogName: 'findTicket' + } + }); + + const docuwareUrl = docuwareConfig.url; + const cookie = docuwareConfig.token; + const fileCabinetName = docuwareInfo.fileCabinetName; + const find = docuwareInfo.find; + + const options = { + 'headers': { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Cookie': cookie + } + }; + // get fileCabinetId + const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options).json(); + const fileCabinetId = fileCabinetResponse.FileCabinet.find(dialogs => dialogs.Name === fileCabinetName).Id; + + // get dialog + const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options).json(); + const dialogId = dialogResponse.Dialog.find(dialogs => dialogs.DisplayName === 'find').Id; + + // get docuwareID + const docuwareOptions = { + 'headers': { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Cookie': cookie + }, + 'body': JSON.stringify({'Condition': [{DBName: find, Value: [id]}]}) + }; + const response = await got.post( + `${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, + docuwareOptions + ); + try { + JSON.parse(response.body).Items[0].Id; + return true; + } catch (error) { + return false; + } + }; +}; diff --git a/back/methods/docuware/download.js b/back/methods/docuware/download.js index 01e552d2d..a2a95fcd1 100644 --- a/back/methods/docuware/download.js +++ b/back/methods/docuware/download.js @@ -1,48 +1,65 @@ const got = require('got'); -const {createWriteStream} = require('fs'); +const fs = require('fs-extra'); +const path = require('path'); const UserError = require('vn-loopback/util/user-error'); +const {promisify} = require('util'); +const nodeStream = require('stream'); module.exports = Self => { Self.remoteMethodCtx('download', { - description: 'Download an invoice PDF', + description: 'Download an docuware PDF', accessType: 'READ', accepts: [ { - arg: 'ticketId', + arg: 'id', type: 'number', - description: 'The invoiceable ticket id' - }, + description: 'The ticket id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } ], - returns: { - type: 'object', - root: true - }, http: { - path: `/download`, - verb: 'POST' + path: `/:id/download`, + verb: 'GET' } }); - Self.download = async function(ctx, ticketId) { + Self.download = async function(ctx, id) { // const fileCabinet = 'ad2c49df-8976-4941-bb19-9b30685f14a4'; // hay que crear tambien una busqueda por cada fileCabinet // columnas necesarias. seccion, fileCabinet, DBName, dialog + /* const myUserId = ctx.req.accessToken.userId; + if (!myUserId) + throw new UserError(`You don't have enough privileges`);*/ + const models = Self.app.models; - const [docuwareConfig] = await Self.rawSql(`SELECT * FROM vn.docuwareConfig;`); + const docuwareConfig = await models.DocuwareConfig.findOne(); const docuwareInfo = await models.Docuware.findOne({ where: { name: 'deliveryClient', dialogName: 'findTicket' } }); - console.log(docuwareConfig, docuwareInfo); const docuwareUrl = docuwareConfig.url; const cookie = docuwareConfig.token; const fileCabinetName = docuwareInfo.fileCabinetName; const find = docuwareInfo.find; - // get fileCabinetId const options = { 'headers': { 'Accept': 'application/json', @@ -50,27 +67,27 @@ module.exports = Self => { 'Cookie': cookie } }; - + // get fileCabinetId const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options).json(); const fileCabinetId = fileCabinetResponse.FileCabinet.find(dialogs => dialogs.Name === fileCabinetName).Id; - // get dialogs + // get dialog const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options).json(); - console.log(dialogResponse); const dialogId = dialogResponse.Dialog.find(dialogs => dialogs.DisplayName === 'find').Id; - console.log(fileCabinetId, dialogId); - /* - // get DocuwareID + // get docuwareID const docuwareOptions = { 'headers': { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Cookie': cookie }, - 'body': JSON.stringify({'Condition': [{DBName: find, Value: [ticketId]}]}) + 'body': JSON.stringify({'Condition': [{DBName: find, Value: [0]}]}) }; - const response = await got.post(`${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, docuwareOptions); + const response = await got.post( + `${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, + docuwareOptions + ); const docuwareId = JSON.parse(response.body).Items[0].Id; // download file @@ -81,8 +98,45 @@ module.exports = Self => { } }; - const file = await got.stream(downloadUrl, downloadOptions).pipe(createWriteStream(`${ticketId}_${docuwareId}.pdf`)); + try { + // save file + const ticket = await models.Ticket.findById(id); - // return [file, 'application/pdf', `filename="${ticketId}_${docuwareId}.pdf"`];*/ + const shipped = ticket.shipped; + const year = shipped.getFullYear().toString(); + const month = (shipped.getMonth() + 1).toString(); + const day = shipped.getDate().toString(); + const fileName = `${year}${id}.pdf`; + + const container = await models.DocuwareContainer.container(year); + const rootPath = container.client.root; + const src = path.join(rootPath, year, month, day); + const fileSrc = path.join(src, fileName); + + await fs.mkdir(src, {recursive: true}); + + const pipeline = promisify(nodeStream.pipeline); + await pipeline( + got.stream(downloadUrl, downloadOptions), + fs.createWriteStream(fileSrc) + ); + + // open file + const file = { + path: fileSrc, + contentType: 'application/pdf', + name: fileName + }; + + await fs.access(file.path); + let stream = fs.createReadStream(file.path); + + return [stream, file.contentType, `filename="${file.name}"`]; + } catch (error) { + if (error.code === 'ENOENT') + throw new UserError('The DOCUWARE PDF document does not exists'); + + throw error; + } }; }; diff --git a/back/methods/docuware/specs/checkFile.spec.js b/back/methods/docuware/specs/checkFile.spec.js new file mode 100644 index 000000000..7cb2ae6f9 --- /dev/null +++ b/back/methods/docuware/specs/checkFile.spec.js @@ -0,0 +1,129 @@ +const app = require('vn-loopback/server/server'); + +describe('image upload()', () => { + describe('as buyer', () => { + const buyerId = 35; + const workerId = 1106; + const itemId = 4; + + it('should try to upload a file for the collection "catalog" and throw a privileges error', async() => { + const ctx = {req: {accessToken: {userId: buyerId}}, + args: { + id: workerId, + collection: 'user' + } + }; + + let error; + try { + await app.models.Image.upload(ctx); + } catch (err) { + error = err; + } + + expect(error.message).toEqual(`You don't have enough privileges`); + }); + + it('should call to the TempContainer upload method for the collection "catalog"', async() => { + const containerModel = app.models.TempContainer; + spyOn(containerModel, 'upload'); + + const ctx = {req: {accessToken: {userId: buyerId}}, + args: { + id: itemId, + collection: 'catalog' + } + }; + + try { + await app.models.Image.upload(ctx); + } catch (err) { } + + expect(containerModel.upload).toHaveBeenCalled(); + }); + }); + + describe('as marketing', () => { + const marketingId = 51; + const workerId = 1106; + const itemId = 4; + + it('should be able to call to the TempContainer upload method for the collection "user"', async() => { + const containerModel = app.models.TempContainer; + spyOn(containerModel, 'upload'); + + const ctx = {req: {accessToken: {userId: marketingId}}, + args: { + id: workerId, + collection: 'user' + } + }; + + try { + await app.models.Image.upload(ctx); + } catch (err) { } + + expect(containerModel.upload).toHaveBeenCalled(); + }); + + it('should be able to call to the TempContainer upload method for the collection "catalog"', async() => { + const containerModel = app.models.TempContainer; + spyOn(containerModel, 'upload'); + + const ctx = {req: {accessToken: {userId: marketingId}}, + args: { + id: itemId, + collection: 'catalog' + } + }; + + try { + await app.models.Image.upload(ctx); + } catch (err) { } + + expect(containerModel.upload).toHaveBeenCalled(); + }); + }); + + describe('as hhrr', () => { + const hhrrId = 37; + const workerId = 1106; + const itemId = 4; + + it('should upload a file for the collection "user" and call to the TempContainer upload method', async() => { + const containerModel = app.models.TempContainer; + spyOn(containerModel, 'upload'); + + const ctx = {req: {accessToken: {userId: hhrrId}}, + args: { + id: itemId, + collection: 'user' + } + }; + + try { + await app.models.Image.upload(ctx); + } catch (err) { } + + expect(containerModel.upload).toHaveBeenCalled(); + }); + + it('should try to upload a file for the collection "catalog" and throw a privilege error', async() => { + const ctx = {req: {accessToken: {userId: hhrrId}}, + args: { + id: workerId, + collection: 'catalog' + } + }; + + let error; + try { + await app.models.Image.upload(ctx); + } catch (err) { + error = err; + } + + expect(error.message).toEqual(`You don't have enough privileges`); + }); + }); +}); diff --git a/back/methods/docuware/specs/download.spec.js b/back/methods/docuware/specs/download.spec.js new file mode 100644 index 000000000..4bdf800b4 --- /dev/null +++ b/back/methods/docuware/specs/download.spec.js @@ -0,0 +1,28 @@ +const models = require('vn-loopback/server/server').models; +const fs = require('fs-extra'); + +describe('image download()', () => { + const userId = 9; + const invoiceId = 1; + const ctx = { + req: { + + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + } + }; + + it('should return the downloaded file name', async() => { + spyOn(models.DocuwareContainer, 'container').and.returnValue({ + client: {root: '/path'} + }); + spyOn(fs, 'createReadStream').and.returnValue(new Promise(resolve => resolve('streamObject'))); + spyOn(fs, 'access').and.returnValue(true); + spyOn(models.InvoiceOut, 'createPdf').and.returnValue(new Promise(resolve => resolve(true))); + + const result = await models.InvoiceOut.download(ctx, invoiceId); + + expect(result[1]).toEqual('application/pdf'); + expect(result[2]).toMatch(/filename="\d{4}T1111111.pdf"/); + }); +}); diff --git a/back/model-config.json b/back/model-config.json index 7be2174e6..f1b662354 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -47,6 +47,12 @@ "Docuware": { "dataSource": "vn" }, + "DocuwareConfig": { + "dataSource": "vn" + }, + "DocuwareContainer": { + "dataSource": "docuwareStorage" + }, "EmailUser": { "dataSource": "vn" }, diff --git a/back/models/docuware-config.json b/back/models/docuware-config.json new file mode 100644 index 000000000..8ca76d8ba --- /dev/null +++ b/back/models/docuware-config.json @@ -0,0 +1,32 @@ +{ + "name": "DocuwareConfig", + "description": "Docuware config", + "base": "VnModel", + "options": { + "mysql": { + "table": "docuwareConfig" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "url": { + "type": "string" + }, + "token": { + "type": "string" + } + }, + "acls": [ + { + "property": "*", + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/back/models/docuware-container.json b/back/models/docuware-container.json new file mode 100644 index 000000000..8180695c1 --- /dev/null +++ b/back/models/docuware-container.json @@ -0,0 +1,10 @@ +{ + "name": "DocuwareContainer", + "base": "Container", + "acls": [{ + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} \ No newline at end of file diff --git a/back/models/docuware.js b/back/models/docuware.js index 8a6b0cd93..8fd8065ed 100644 --- a/back/models/docuware.js +++ b/back/models/docuware.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/docuware/download')(Self); + require('../methods/docuware/checkFile')(Self); }; diff --git a/db/changes/10420-valentines/00-docuware.sql b/db/changes/10420-valentines/00-docuware.sql index dd915ddcd..ca4b0a114 100644 --- a/db/changes/10420-valentines/00-docuware.sql +++ b/db/changes/10420-valentines/00-docuware.sql @@ -6,6 +6,6 @@ CREATE TABLE `vn`.`docuware` ( `find` varchar(50) DEFAULT NULL ); -INSERT INTO `vn`.`docuware` -(name, fileCabinetName, dialogName , find) -VALUES('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N'); +INSERT INTO `vn`.`docuware` (`name`, `fileCabinetName`, `dialogName` , `find`) + VALUES + ('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N'); diff --git a/db/changes/10420-valentines/00-docuwareConfig.sql b/db/changes/10420-valentines/00-docuwareConfig.sql index 0ef190cb7..c2c78c67e 100644 --- a/db/changes/10420-valentines/00-docuwareConfig.sql +++ b/db/changes/10420-valentines/00-docuwareConfig.sql @@ -2,8 +2,4 @@ CREATE TABLE `vn`.`docuwareConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `url` varchar(75) NULL, `token` varchar(1000) DEFAULT NULL -); - -INSERT INTO `vn`.`docuwareConfig` -(url, token) -VALUES('https://verdnatura.docuware.cloud/docuware/platform/', '.DWPLATFORMAUTH=66C7DCD2B9365EF974AFEB43F61715152082EF39C649CB1506F9ACC34DD54C5B34944DDFBF97EAE5C5147063850B16B3B9FFFB2232FDD03F35B51B1305D5E1E7DB833F6AC560C739E40778932C8BCC64DA7ECE64B0B1F71A3DB986B3710DFA4C061776F9C61DDAA60EF30F7F37FB8733BF4B1830F98102E403E4E751F13F31B582AEDF5B33A25346E10CA34A8559F0CD6ACA39A7379AC67BE061CD27531D02675123FB0D254426E306EC6FA49DED7CF30EBBAD8365BE60D7E919D4AD2EB8F9CD94424DFCD95151C0F6DD3EE8569A7CA4A30D1A3F42DA9DD368A33955A4AFE9CB4FCCC230801BC645AA87A68EC33F6BD165D5A0F02B63D5D832AF936B9398EC428D4ACD41E56848A2CDF797C99226BB2AC48EB5F9C1C5D8C1C7F6A7F67F455ABAC1DBC7443521876B588F369CAE6EC81747BA3134F7EE2662DA296FC2C16528B0AB4839EEE6EE79A82AA3888E4AB53FEC6FFAD26A592ABD76441AFCD634097D0B0B57E16A510D0E6F769710C6F4BDB1476CCDE0967788B90A67BADFB7E37B1F7F60C879A0E9D75AD2BA6647FC11477305B44512AF408845E6099CF64B7A3D77EE; ApplicationGatewayAffinity=c5fad6cb3332163516d49258a1ebf52c; ApplicationGatewayAffinityCORS=c5fad6cb3332163516d49258a1ebf52c; DWPLATFORMBROWSERID=C2173B1A1FE42B449AA12C8465561991BA4664AFA9F44D4C9DD8748FF92EFEBF629E4A75860747C4D8290F70344385CCAFE3EAFD8814CF44F452275C95E89D19D35A178D0BCC6930EF07AC7CF91672F7CB43C2B54CDFAE52BDF17C467FFFE3411FE0D792E4F513726F295648DDE627DF2C6288C89086E2DE6916E4B0A5291AA7C269015A5328147783EC15FB8EF43EE5DAE5A6CD3D318570670234176CAE7B19D9812D3F09D731C5A27A621B39D0564C81774FA993160AAAD833CC75634445B7B47C5A2E26004FF914606B5B0CB897A694F26AD5E80A1EE0D3B7BA4881F8A570'); +); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 07eaf23fd..7c7709716 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2443,3 +2443,11 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (1103, 500, CURDATE(), CURDATE()), (1107, 500, CURDATE(), CURDATE()), (1109, 500, CURDATE(), CURDATE()); + +INSERT INTO `vn`.`docuwareConfig` (`url`, `token`) + VALUES + ('https://verdnatura.docuware.cloud/docuware/platform', '.DWPLATFORMAUTH=66C7DCD2B9365EF974AFEB43F61715152082EF39C649CB1506F9ACC34DD54C5B34944DDFBF97EAE5C5147063850B16B3B9FFFB2232FDD03F35B51B1305D5E1E7DB833F6AC560C739E40778932C8BCC64DA7ECE64B0B1F71A3DB986B3710DFA4C061776F9C61DDAA60EF30F7F37FB8733BF4B1830F98102E403E4E751F13F31B582AEDF5B33A25346E10CA34A8559F0CD6ACA39A7379AC67BE061CD27531D02675123FB0D254426E306EC6FA49DED7CF30EBBAD8365BE60D7E919D4AD2EB8F9CD94424DFCD95151C0F6DD3EE8569A7CA4A30D1A3F42DA9DD368A33955A4AFE9CB4FCCC230801BC645AA87A68EC33F6BD165D5A0F02B63D5D832AF936B9398EC428D4ACD41E56848A2CDF797C99226BB2AC48EB5F9C1C5D8C1C7F6A7F67F455ABAC1DBC7443521876B588F369CAE6EC81747BA3134F7EE2662DA296FC2C16528B0AB4839EEE6EE79A82AA3888E4AB53FEC6FFAD26A592ABD76441AFCD634097D0B0B57E16A510D0E6F769710C6F4BDB1476CCDE0967788B90A67BADFB7E37B1F7F60C879A0E9D75AD2BA6647FC11477305B44512AF408845E6099CF64B7A3D77EE; ApplicationGatewayAffinity=c5fad6cb3332163516d49258a1ebf52c; ApplicationGatewayAffinityCORS=c5fad6cb3332163516d49258a1ebf52c; DWPLATFORMBROWSERID=C2173B1A1FE42B449AA12C8465561991BA4664AFA9F44D4C9DD8748FF92EFEBF629E4A75860747C4D8290F70344385CCAFE3EAFD8814CF44F452275C95E89D19D35A178D0BCC6930EF07AC7CF91672F7CB43C2B54CDFAE52BDF17C467FFFE3411FE0D792E4F513726F295648DDE627DF2C6288C89086E2DE6916E4B0A5291AA7C269015A5328147783EC15FB8EF43EE5DAE5A6CD3D318570670234176CAE7B19D9812D3F09D731C5A27A621B39D0564C81774FA993160AAAD833CC75634445B7B47C5A2E26004FF914606B5B0CB897A694F26AD5E80A1EE0D3B7BA4881F8A570'); + +INSERT INTO `vn`.`docuware` (`name`, `fileCabinetName`, `dialogName` , `find`) + VALUES + ('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N'); \ No newline at end of file diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 0df03882c..27921c78a 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -83,5 +83,16 @@ "application/octet-stream", "application/pdf" ] + }, + "docuwareStorage": { + "name": "docuwareStorage", + "connector": "loopback-component-storage", + "provider": "filesystem", + "root": "./storage/pdfs/docuware", + "maxFileSize": "52428800", + "allowedContentTypes": [ + "application/octet-stream", + "application/pdf" + ] } } \ No newline at end of file diff --git a/modules/invoiceOut/back/methods/invoiceOut/docuware.js b/modules/invoiceOut/back/methods/invoiceOut/docuware.js deleted file mode 100644 index aa58aaed1..000000000 --- a/modules/invoiceOut/back/methods/invoiceOut/docuware.js +++ /dev/null @@ -1,65 +0,0 @@ -const got = require('got'); -const {createWriteStream} = require('fs'); -const UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.remoteMethodCtx('docuware', { - description: 'Download an invoice PDF', - accessType: 'READ', - accepts: [ - { - arg: 'ticketId', - type: 'number', - description: 'The invoiceable ticket id' - }, - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/docuware`, - verb: 'POST' - } - }); - - Self.docuware = async function(ctx, ticketId) { - // const fileCabinet = 'ad2c49df-8976-4941-bb19-9b30685f14a4'; - // hay que crear tambien una busqueda por cada fileCabinet - // columnas necesarias. seccion, fileCabinet, DBName, dialog - const models = Self.app.models; - const docuwareInfo = await models.Docuware.findOne({ - where: { - name: 'albaran' - } - }); - console.log(docuwareInfo); - const fileCabinet = docuwareInfo.fileCabinet; - const find = docuwareInfo.find; - const dialog = docuwareInfo.dialog; - const docuwareUrl = `https://verdnatura.docuware.cloud/docuware/platform/FileCabinets/${fileCabinet}`; - const cookie = '.DWPLATFORMAUTH=66C7DCD2B9365EF974AFEB43F61715152082EF39C649CB1506F9ACC34DD54C5B34944DDFBF97EAE5C5147063850B16B3B9FFFB2232FDD03F35B51B1305D5E1E7DB833F6AC560C739E40778932C8BCC64DA7ECE64B0B1F71A3DB986B3710DFA4C061776F9C61DDAA60EF30F7F37FB8733BF4B1830F98102E403E4E751F13F31B582AEDF5B33A25346E10CA34A8559F0CD6ACA39A7379AC67BE061CD27531D02675123FB0D254426E306EC6FA49DED7CF30EBBAD8365BE60D7E919D4AD2EB8F9CD94424DFCD95151C0F6DD3EE8569A7CA4A30D1A3F42DA9DD368A33955A4AFE9CB4FCCC230801BC645AA87A68EC33F6BD165D5A0F02B63D5D832AF936B9398EC428D4ACD41E56848A2CDF797C99226BB2AC48EB5F9C1C5D8C1C7F6A7F67F455ABAC1DBC7443521876B588F369CAE6EC81747BA3134F7EE2662DA296FC2C16528B0AB4839EEE6EE79A82AA3888E4AB53FEC6FFAD26A592ABD76441AFCD634097D0B0B57E16A510D0E6F769710C6F4BDB1476CCDE0967788B90A67BADFB7E37B1F7F60C879A0E9D75AD2BA6647FC11477305B44512AF408845E6099CF64B7A3D77EE; ApplicationGatewayAffinity=c5fad6cb3332163516d49258a1ebf52c; ApplicationGatewayAffinityCORS=c5fad6cb3332163516d49258a1ebf52c; DWPLATFORMBROWSERID=C2173B1A1FE42B449AA12C8465561991BA4664AFA9F44D4C9DD8748FF92EFEBF629E4A75860747C4D8290F70344385CCAFE3EAFD8814CF44F452275C95E89D19D35A178D0BCC6930EF07AC7CF91672F7CB43C2B54CDFAE52BDF17C467FFFE3411FE0D792E4F513726F295648DDE627DF2C6288C89086E2DE6916E4B0A5291AA7C269015A5328147783EC15FB8EF43EE5DAE5A6CD3D318570670234176CAE7B19D9812D3F09D731C5A27A621B39D0564C81774FA993160AAAD833CC75634445B7B47C5A2E26004FF914606B5B0CB897A694F26AD5E80A1EE0D3B7BA4881F8A570'; - - // get DocuwareID - const dialogOptions = { - 'headers': { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Cookie': cookie - }, - 'body': JSON.stringify({'Condition': [{DBName: find, Value: [ticketId]}]}) - }; - const response = await got.post(`${docuwareUrl}/Query/DialogExpression?dialogId=${dialog}`, dialogOptions); - const docuwareId = JSON.parse(response.body).Items[0].Id; - - // download file - const downloadUrl = `${docuwareUrl}/Documents/${docuwareId}/FileDownload?targetFileType=Auto&keepAnnotations=false`; - const downloadOptions = { - 'headers': { - 'Cookie': cookie - } - }; - - await got.stream(downloadUrl, downloadOptions).pipe(createWriteStream(`${ticketId}_${docuwareId}.pdf`)); - }; -}; diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index 3da5aedc6..3b2822ada 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -3,7 +3,6 @@ module.exports = Self => { require('../methods/invoiceOut/summary')(Self); require('../methods/invoiceOut/getTickets')(Self); require('../methods/invoiceOut/download')(Self); - require('../methods/invoiceOut/docuware')(Self); require('../methods/invoiceOut/delete')(Self); require('../methods/invoiceOut/book')(Self); require('../methods/invoiceOut/createPdf')(Self); diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index ae5642cf3..87a821746 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -20,14 +20,22 @@ - Show as PDF + as PDF + + as DOCUWARE + - Show as CSV + as CSV diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 9d4381f7c..6abdfcce6 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -82,6 +82,7 @@ class Controller extends Section { return this.$http.get(`Tickets/${this.ticketId}`, {filter}) .then(res => this.ticket = res.data) .then(() => { + this.hasDocuware(); this.canStowaway(); this.isTicketEditable(); }); @@ -122,6 +123,13 @@ class Controller extends Section { }); } + hasDocuware() { + this.$http.get(`Docuwares/${this.id}/checkFile`) + .then(res => { + this.hasDocuware = res.data; + }); + } + showCsvDeliveryNote() { this.vnReport.showCsv('delivery-note', { recipientId: this.ticket.client.id, diff --git a/modules/ticket/front/descriptor-menu/locale/es.yml b/modules/ticket/front/descriptor-menu/locale/es.yml index 1f4ee710c..4a61556db 100644 --- a/modules/ticket/front/descriptor-menu/locale/es.yml +++ b/modules/ticket/front/descriptor-menu/locale/es.yml @@ -1,7 +1,7 @@ Show Delivery Note...: Ver albarán... Send Delivery Note...: Enviar albarán... -Show as PDF: Ver como PDF -Show as CSV: Ver como CSV +as PDF: como PDF +as CSV: como CSV Send PDF: Enviar PDF Send CSV: Enviar CSV Send CSV Delivery Note: Enviar albarán en CSV