diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js index 7dc1993f0..a674707fc 100644 --- a/back/methods/docuware/checkFile.js +++ b/back/methods/docuware/checkFile.js @@ -1,16 +1,27 @@ const got = require('got'); -const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('checkFile', { - description: 'Download an docuware PDF', + description: 'Check if exist docuware file', accessType: 'READ', accepts: [ { arg: 'id', - type: 'String', - description: 'The invoice id', + type: 'number', + description: 'The id', http: {source: 'path'} + }, + { + arg: 'fileCabinet', + type: 'string', + required: true, + description: 'The fileCabinet name' + }, + { + arg: 'dialog', + type: 'string', + required: true, + description: 'The dialog name' } ], returns: { @@ -19,21 +30,21 @@ module.exports = Self => { }, http: { path: `/:id/checkFile`, - verb: 'GET' + verb: 'POST' } }); - 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 + Self.checkFile = async function(ctx, id, fileCabinet, dialog) { + const myUserId = ctx.req.accessToken.userId; + if (!myUserId) + return false; const models = Self.app.models; const docuwareConfig = await models.DocuwareConfig.findOne(); const docuwareInfo = await models.Docuware.findOne({ where: { - name: 'deliveryClient', - dialogName: 'findTicket' + name: fileCabinet, + dialogName: dialog } }); @@ -41,7 +52,6 @@ module.exports = Self => { const cookie = docuwareConfig.token; const fileCabinetName = docuwareInfo.fileCabinetName; const find = docuwareInfo.find; - const options = { 'headers': { 'Accept': 'application/json', @@ -49,29 +59,32 @@ 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 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 condtions = { + condition: [ + { + DBName: find, + Value: [id] + } + ] }; - const response = await got.post( - `${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, - docuwareOptions - ); + try { + // get fileCabinetId + const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options); + const fileCabinetJson = JSON.parse(fileCabinetResponse.body).FileCabinet; + const fileCabinetId = fileCabinetJson.find(dialogs => dialogs.Name === fileCabinetName).Id; + + // get dialog + const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options); + const dialogJson = JSON.parse(dialogResponse.body).Dialog; + const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id; + + // get docuwareID + Object.assign(options, {'body': JSON.stringify(condtions)}); + const response = await got.post( + `${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, options); 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 a2a95fcd1..75789d187 100644 --- a/back/methods/docuware/download.js +++ b/back/methods/docuware/download.js @@ -1,9 +1,6 @@ +/* eslint max-len: ["error", { "code": 180 }]*/ const got = require('got'); -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', { @@ -13,7 +10,19 @@ module.exports = Self => { { arg: 'id', type: 'number', - description: 'The ticket id', + description: 'The id', + http: {source: 'path'} + }, + { + arg: 'fileCabinet', + type: 'string', + description: 'The id', + http: {source: 'path'} + }, + { + arg: 'dialog', + type: 'string', + description: 'The id', http: {source: 'path'} } ], @@ -24,34 +33,31 @@ module.exports = Self => { root: true }, { arg: 'Content-Type', - type: 'String', + type: 'string', http: {target: 'header'} }, { arg: 'Content-Disposition', - type: 'String', + type: 'string', http: {target: 'header'} } ], http: { - path: `/:id/download`, + path: `/:id/download/:fileCabinet/:dialog`, verb: 'GET' } }); - 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; + Self.download = async function(ctx, id, fileCabinet, dialog) { + const myUserId = ctx.req.accessToken.userId; if (!myUserId) - throw new UserError(`You don't have enough privileges`);*/ + throw new UserError(`You don't have enough privileges`); const models = Self.app.models; const docuwareConfig = await models.DocuwareConfig.findOne(); const docuwareInfo = await models.Docuware.findOne({ where: { - name: 'deliveryClient', - dialogName: 'findTicket' + name: fileCabinet, + dialogName: dialog } }); @@ -59,7 +65,6 @@ module.exports = Self => { const cookie = docuwareConfig.token; const fileCabinetName = docuwareInfo.fileCabinetName; const find = docuwareInfo.find; - const options = { 'headers': { 'Accept': 'application/json', @@ -67,71 +72,44 @@ 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 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: [0]}]}) - }; - const response = await got.post( - `${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, - docuwareOptions - ); - const docuwareId = JSON.parse(response.body).Items[0].Id; - - // download file - const downloadUrl = `${docuwareUrl}/FileCabinets/${fileCabinetId}/Documents/${docuwareId}/FileDownload?targetFileType=Auto&keepAnnotations=false`; - const downloadOptions = { - 'headers': { - 'Cookie': cookie - } + const condtions = { + condition: [ + { + DBName: find, + Value: [id] + } + ] }; try { - // save file - const ticket = await models.Ticket.findById(id); + // get fileCabinetId + const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options); + const fileCabinetJson = JSON.parse(fileCabinetResponse.body).FileCabinet; + const fileCabinetId = fileCabinetJson.find(dialogs => dialogs.Name === fileCabinetName).Id; - 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`; + // get dialog + const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options); + const dialogJson = JSON.parse(dialogResponse.body).Dialog; + const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id; - 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); + // get docuwareID + Object.assign(options, {'body': JSON.stringify(condtions)}); + const response = await got.post(`${docuwareUrl}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, options); + const docuwareId = JSON.parse(response.body).Items[0].Id; - 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 + // download & save file + const fileName = `filename="${id}.pdf"`; + const contentType = 'application/pdf'; + const downloadUri = `${docuwareUrl}/FileCabinets/${fileCabinetId}/Documents/${docuwareId}/FileDownload?targetFileType=Auto&keepAnnotations=false`; + const downloadOptions = { + 'headers': { + 'Cookie': cookie + } }; - await fs.access(file.path); - let stream = fs.createReadStream(file.path); + const stream = got.stream(downloadUri, downloadOptions); - return [stream, file.contentType, `filename="${file.name}"`]; + return [stream, contentType, fileName]; } catch (error) { if (error.code === 'ENOENT') throw new UserError('The DOCUWARE PDF document does not exists'); diff --git a/back/methods/docuware/specs/checkFile.spec.js b/back/methods/docuware/specs/checkFile.spec.js index 7cb2ae6f9..2ebde0df4 100644 --- a/back/methods/docuware/specs/checkFile.spec.js +++ b/back/methods/docuware/specs/checkFile.spec.js @@ -1,129 +1,64 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; +const got = require('got'); -describe('image upload()', () => { - describe('as buyer', () => { - const buyerId = 35; - const workerId = 1106; - const itemId = 4; +describe('docuware download()', () => { + const ticketId = 1; + const userId = 9; + const ctx = { + req: { - 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' - } - }; + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + } + }; - let error; - try { - await app.models.Image.upload(ctx); - } catch (err) { - error = err; - } + const fileCabinetName = 'deliveryClientTest'; + const dialogDisplayName = 'find'; + const dialogName = 'findTest'; - expect(error.message).toEqual(`You don't have enough privileges`); - }); + const gotGetResponse = { + body: JSON.stringify( + { + FileCabinet: [ + {Id: 12, Name: fileCabinetName} + ], + Dialog: [ + {Id: 34, DisplayName: dialogDisplayName} + ] + }) + }; - it('should call to the TempContainer upload method for the collection "catalog"', async() => { - const containerModel = app.models.TempContainer; - spyOn(containerModel, 'upload'); + it('should return exist file in docuware', async() => { + const gotPostResponse = { + body: JSON.stringify( + { + Items: [ + {Id: 56} + ], + }) + }; - const ctx = {req: {accessToken: {userId: buyerId}}, - args: { - id: itemId, - collection: 'catalog' - } - }; + spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse))); + spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse))); - try { - await app.models.Image.upload(ctx); - } catch (err) { } + const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName); - expect(containerModel.upload).toHaveBeenCalled(); - }); + expect(result).toEqual(true); }); - describe('as marketing', () => { - const marketingId = 51; - const workerId = 1106; - const itemId = 4; + it('should return not exist file in docuware', async() => { + const gotPostResponse = { + body: JSON.stringify( + { + Items: [], + }) + }; - it('should be able to call to the TempContainer upload method for the collection "user"', async() => { - const containerModel = app.models.TempContainer; - spyOn(containerModel, 'upload'); + spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse))); + spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse))); - const ctx = {req: {accessToken: {userId: marketingId}}, - args: { - id: workerId, - collection: 'user' - } - }; + const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName); - 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`); - }); + expect(result).toEqual(false); }); }); diff --git a/back/methods/docuware/specs/download.spec.js b/back/methods/docuware/specs/download.spec.js index 4bdf800b4..436063fd8 100644 --- a/back/methods/docuware/specs/download.spec.js +++ b/back/methods/docuware/specs/download.spec.js @@ -1,9 +1,10 @@ const models = require('vn-loopback/server/server').models; -const fs = require('fs-extra'); +const got = require('got'); +const stream = require('stream'); -describe('image download()', () => { +describe('docuware download()', () => { const userId = 9; - const invoiceId = 1; + const ticketId = 1; const ctx = { req: { @@ -13,16 +14,37 @@ describe('image download()', () => { }; 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 fileCabinetName = 'deliveryClientTest'; + const dialogDisplayName = 'find'; + const dialogName = 'findTest'; + const gotGetResponse = { + body: JSON.stringify( + { + FileCabinet: [ + {Id: 12, Name: fileCabinetName} + ], + Dialog: [ + {Id: 34, DisplayName: dialogDisplayName} + ] + }) + }; - const result = await models.InvoiceOut.download(ctx, invoiceId); + const gotPostResponse = { + body: JSON.stringify( + { + Items: [ + {Id: 56} + ], + }) + }; + + spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse))); + spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse))); + spyOn(got, 'stream').and.returnValue(new stream.PassThrough({objectMode: true})); + + const result = await models.Docuware.download(ctx, ticketId, fileCabinetName, dialogName); expect(result[1]).toEqual('application/pdf'); - expect(result[2]).toMatch(/filename="\d{4}T1111111.pdf"/); + expect(result[2]).toEqual(`filename="${ticketId}.pdf"`); }); }); diff --git a/back/model-config.json b/back/model-config.json index f1b662354..4c79d565b 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -50,9 +50,6 @@ "DocuwareConfig": { "dataSource": "vn" }, - "DocuwareContainer": { - "dataSource": "docuwareStorage" - }, "EmailUser": { "dataSource": "vn" }, diff --git a/back/models/docuware-container.json b/back/models/docuware-container.json deleted file mode 100644 index 8180695c1..000000000 --- a/back/models/docuware-container.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "DocuwareContainer", - "base": "Container", - "acls": [{ - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - }] -} \ No newline at end of file diff --git a/db/changes/10420-valentines/00-docuware.sql b/db/changes/10420-valentines/00-docuware.sql index ca4b0a114..e5311252d 100644 --- a/db/changes/10420-valentines/00-docuware.sql +++ b/db/changes/10420-valentines/00-docuware.sql @@ -8,4 +8,4 @@ CREATE TABLE `vn`.`docuware` ( INSERT INTO `vn`.`docuware` (`name`, `fileCabinetName`, `dialogName` , `find`) VALUES - ('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N'); + ('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N'); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7c7709716..74568ebc7 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2444,10 +2444,6 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced` (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 + ('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word'); \ No newline at end of file diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 27921c78a..0df03882c 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -83,16 +83,5 @@ "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/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html index 070da18e1..345e67d95 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.html +++ b/modules/invoiceOut/front/descriptor-menu/index.html @@ -1,144 +1,138 @@ +icon="more_vert" +vn-popover="menu"> - - - Show invoice... + + + Show invoice... + + + + Show as PDF + + + Show as CSV + + + + + + Send invoice... - - - - Show as PDF - - - Show as DOCUWARE - - - Show as CSV - - - - - - Send invoice... - - - - - Send PDF - - - Send CSV - - - - - - Delete Invoice - - - Book invoice - - - {{!$ctrl.invoiceOut.hasPdf ? 'Generate PDF invoice': 'Regenerate PDF invoice'}} - - - Show CITES letter - - + + + + Send PDF + + + Send CSV + + + + + + Delete Invoice + + + Book invoice + + + {{!$ctrl.invoiceOut.hasPdf ? 'Generate PDF invoice': 'Regenerate PDF invoice'}} + + + Show CITES letter + + +vn-id="deleteConfirmation" +on-accept="$ctrl.deleteInvoiceOut()" +question="Are you sure you want to delete this invoice?"> +vn-id="bookConfirmation" +on-accept="$ctrl.bookInvoiceOut()" +question="Are you sure you want to book this invoice?"> +vn-id="clientDescriptor"> +vn-id="createInvoicePdfConfirmation" +on-accept="$ctrl.createPdfInvoice()" +question="Are you sure you want to generate/regenerate the PDF invoice?" +message="Generate PDF invoice document"> - - Are you sure you want to send it? - - - - - - - +vn-id="sendPdfConfirmation" +on-accept="$ctrl.sendPdfInvoice($data)" +message="Send PDF invoice"> + + Are you sure you want to send it? + + + + + + + - - Are you sure you want to send it? - - - - - - - +vn-id="sendCsvConfirmation" +on-accept="$ctrl.sendCsvInvoice($data)" +message="Send CSV invoice"> + + Are you sure you want to send it? + + + + + + + \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index f6855795a..7738845f9 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -88,19 +88,6 @@ class Controller extends Section { }); } - downloadDocuware() { - const options = { - ticketId: 3367050 - }; - - return this.$http.post(`Docuwares/download`, options) - .then(() => { - const snackbarMessage = this.$t( - `The invoice PDF document has been downloaded`); - this.vnApp.showSuccess(snackbarMessage); - }); - } - sendPdfInvoice($data) { if (!$data.email) return this.vnApp.showError(this.$t(`The email can't be empty`)); diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index 87a821746..2439bfb64 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -27,10 +27,10 @@ - as DOCUWARE + as PDF this.ticket = res.data) .then(() => { - this.hasDocuware(); this.canStowaway(); this.isTicketEditable(); + this.hasDocuware(); }); } @@ -124,7 +124,11 @@ class Controller extends Section { } hasDocuware() { - this.$http.get(`Docuwares/${this.id}/checkFile`) + const params = { + fileCabinet: 'deliveryClient', + dialog: 'findTicket' + }; + this.$http.post(`Docuwares/${this.id}/checkFile`, params) .then(res => { this.hasDocuware = res.data; }); diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 288c7508b..0a80d0884 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -206,7 +206,8 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { it('should make a query and show a success snackbar', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.whenGET(`Tickets/16`).respond(); + $httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond(); + $httpBackend.whenGET(`Tickets/${ticket.id}`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond(); controller.createPdfInvoice(); $httpBackend.flush(); @@ -275,4 +276,12 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { }); }); }); + + describe('hasDocuware()', () => { + it('should call hasDocuware method', () => { + $httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond(); + controller.hasDocuware(); + $httpBackend.flush(); + }); + }); });