diff --git a/back/methods/docuware/10.pdf b/back/methods/docuware/10.pdf new file mode 100644 index 000000000..98a8d2c15 Binary files /dev/null and b/back/methods/docuware/10.pdf differ diff --git a/back/methods/docuware/download.js b/back/methods/docuware/download.js index 489a07e34..717decfcc 100644 --- a/back/methods/docuware/download.js +++ b/back/methods/docuware/download.js @@ -1,6 +1,9 @@ /* eslint max-len: ["error", { "code": 180 }]*/ const got = require('got'); +const axios = require('axios'); const UserError = require('vn-loopback/util/user-error'); +const FormData = require('form-data'); +const fs = require('fs-extra'); module.exports = Self => { Self.remoteMethodCtx('download', { @@ -89,6 +92,7 @@ module.exports = Self => { // get dialog const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options); + console.log(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`); const dialogJson = JSON.parse(dialogResponse.body).Dialog; const dialogId = dialogJson.find(dialogs => dialogs.DisplayName === 'find').Id; @@ -107,9 +111,48 @@ module.exports = Self => { } }; - const stream = got.stream(downloadUri, downloadOptions); + // const stream = got.stream(downloadUri, downloadOptions); - return [stream, contentType, fileName]; + const uploadUri = `${docuwareUrl}/FileCabinets/${fileCabinetId}/Documents?storeDialogId=1f665772-c936-4e13-aa2a-f209b1a7070e`; + const form = new FormData(); + const file = await fs.readFile('back/methods/docuware/10.pdf'); + form.append('file', file, '10.pdf'); + const uploadOptions = { + 'headers': { + 'Cookie': cookie, + } + }; + + const fileData = { + formData: { + 'document': { + value: JSON.stringify({Fields: {}}), + options: { + filename: 'document.json', + contentType: 'application/json', + }, + }, + 'file[]': { + value: fs.createReadStream('back/methods/docuware/10.pdf'), + options: { + filename: '10.pdf', + contentType: null + } + } + } + }; + + Object.assign(uploadOptions, fileData); + try { + const upload = await axios.post(uploadUri, file, uploadOptions); + console.log('UPLOAD FINISHED'); + } catch (e) { + console.log('ERROR CATCHED:', e); + console.log('ERROR CATCHED'); + return; + } + // return [stream, contentType, fileName]; + return; } catch (error) { if (error.code === 'ENOENT') throw new UserError('The DOCUWARE PDF document does not exists'); diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index 805e0b391..1707ff727 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -21,7 +21,7 @@ Add turn Show Delivery Note... @@ -37,7 +37,7 @@ href='api/Docuwares/{{$ctrl.ticket.id}}/download/deliveryClient/findTicket?access_token={{$ctrl.vnToken.token}}' target="_blank" translate> - as PDF + as PDF Docuware Send PDF + + Send PDF Docuware + diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 168002d07..7b7278a80 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -85,7 +85,6 @@ class Controller extends Section { .then(res => this.ticket = res.data) .then(() => { this.isTicketEditable(); - this.hasDocuware(); }); } diff --git a/modules/ticket/front/descriptor-menu/locale/es.yml b/modules/ticket/front/descriptor-menu/locale/es.yml index a2725f485..3f06d4378 100644 --- a/modules/ticket/front/descriptor-menu/locale/es.yml +++ b/modules/ticket/front/descriptor-menu/locale/es.yml @@ -1,6 +1,7 @@ Show Delivery Note...: Ver albarán... Send Delivery Note...: Enviar albarán... as PDF: como PDF +as PDF Docuware: como PDF Docuware as CSV: como CSV as PDF without prices: como PDF sin precios Send PDF: Enviar PDF