feat(docuware): start download docuware
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
9ec8eb6e16
commit
651c92698f
|
@ -0,0 +1,88 @@
|
||||||
|
const got = require('got');
|
||||||
|
const {createWriteStream} = require('fs');
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('download', {
|
||||||
|
description: 'Download an invoice PDF',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'ticketId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The invoiceable ticket id'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/download`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.download = 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 [docuwareConfig] = await Self.rawSql(`SELECT * FROM vn.docuwareConfig;`);
|
||||||
|
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',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Cookie': cookie
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options).json();
|
||||||
|
const fileCabinetId = fileCabinetResponse.FileCabinet.find(dialogs => dialogs.Name === fileCabinetName).Id;
|
||||||
|
|
||||||
|
// get dialogs
|
||||||
|
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
|
||||||
|
const docuwareOptions = {
|
||||||
|
'headers': {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Cookie': cookie
|
||||||
|
},
|
||||||
|
'body': JSON.stringify({'Condition': [{DBName: find, Value: [ticketId]}]})
|
||||||
|
};
|
||||||
|
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 file = await got.stream(downloadUrl, downloadOptions).pipe(createWriteStream(`${ticketId}_${docuwareId}.pdf`));
|
||||||
|
|
||||||
|
// return [file, 'application/pdf', `filename="${ticketId}_${docuwareId}.pdf"`];*/
|
||||||
|
};
|
||||||
|
};
|
|
@ -44,6 +44,9 @@
|
||||||
"DmsType": {
|
"DmsType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"Docuware": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"EmailUser": {
|
"EmailUser": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/docuware/download')(Self);
|
||||||
|
};
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"name": "Docuware",
|
||||||
|
"description": "Docuware sections",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "docuware"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true,
|
||||||
|
"description": "Identifier"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"fileCabinetName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"dialogName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"find": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acls": [
|
||||||
|
{
|
||||||
|
"property": "*",
|
||||||
|
"accessType": "*",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO salix.ACL
|
||||||
|
(model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES('Docuware', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1,11 @@
|
||||||
|
CREATE TABLE `vn`.`docuware` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`name` varchar(50) NULL,
|
||||||
|
`fileCabinetName` varchar(50) NULL,
|
||||||
|
`dialogName` varchar(255) DEFAULT NULL,
|
||||||
|
`find` varchar(50) DEFAULT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`docuware`
|
||||||
|
(name, fileCabinetName, dialogName , find)
|
||||||
|
VALUES('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N');
|
|
@ -0,0 +1,9 @@
|
||||||
|
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');
|
|
@ -0,0 +1,65 @@
|
||||||
|
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`));
|
||||||
|
};
|
||||||
|
};
|
|
@ -3,6 +3,7 @@ module.exports = Self => {
|
||||||
require('../methods/invoiceOut/summary')(Self);
|
require('../methods/invoiceOut/summary')(Self);
|
||||||
require('../methods/invoiceOut/getTickets')(Self);
|
require('../methods/invoiceOut/getTickets')(Self);
|
||||||
require('../methods/invoiceOut/download')(Self);
|
require('../methods/invoiceOut/download')(Self);
|
||||||
|
require('../methods/invoiceOut/docuware')(Self);
|
||||||
require('../methods/invoiceOut/delete')(Self);
|
require('../methods/invoiceOut/delete')(Self);
|
||||||
require('../methods/invoiceOut/book')(Self);
|
require('../methods/invoiceOut/book')(Self);
|
||||||
require('../methods/invoiceOut/createPdf')(Self);
|
require('../methods/invoiceOut/createPdf')(Self);
|
||||||
|
|
|
@ -20,6 +20,11 @@
|
||||||
translate>
|
translate>
|
||||||
Show as PDF
|
Show as PDF
|
||||||
</a>
|
</a>
|
||||||
|
<vn-item
|
||||||
|
ng-click="$ctrl.downloadDocuware()"
|
||||||
|
translate>
|
||||||
|
Show as DOCUWARE
|
||||||
|
</vn-item>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="$ctrl.showCsvInvoice()"
|
ng-click="$ctrl.showCsvInvoice()"
|
||||||
translate>
|
translate>
|
||||||
|
|
|
@ -88,6 +88,19 @@ 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) {
|
sendPdfInvoice($data) {
|
||||||
if (!$data.email)
|
if (!$data.email)
|
||||||
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
||||||
|
|
Loading…
Reference in New Issue