3352-docuware #880
|
@ -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': {
|
||||||
alexm marked this conversation as resolved
Outdated
|
|||||||
|
'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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,48 +1,65 @@
|
||||||
const got = require('got');
|
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 UserError = require('vn-loopback/util/user-error');
|
||||||
|
const {promisify} = require('util');
|
||||||
|
const nodeStream = require('stream');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('download', {
|
Self.remoteMethodCtx('download', {
|
||||||
description: 'Download an invoice PDF',
|
description: 'Download an docuware PDF',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'ticketId',
|
arg: 'id',
|
||||||
type: 'number',
|
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: {
|
http: {
|
||||||
path: `/download`,
|
path: `/:id/download`,
|
||||||
verb: 'POST'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.download = async function(ctx, ticketId) {
|
Self.download = async function(ctx, id) {
|
||||||
// const fileCabinet = 'ad2c49df-8976-4941-bb19-9b30685f14a4';
|
// const fileCabinet = 'ad2c49df-8976-4941-bb19-9b30685f14a4';
|
||||||
// hay que crear tambien una busqueda por cada fileCabinet
|
// hay que crear tambien una busqueda por cada fileCabinet
|
||||||
// columnas necesarias. seccion, fileCabinet, DBName, dialog
|
// 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 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({
|
const docuwareInfo = await models.Docuware.findOne({
|
||||||
where: {
|
where: {
|
||||||
name: 'deliveryClient',
|
name: 'deliveryClient',
|
||||||
dialogName: 'findTicket'
|
dialogName: 'findTicket'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(docuwareConfig, docuwareInfo);
|
|
||||||
|
|
||||||
const docuwareUrl = docuwareConfig.url;
|
const docuwareUrl = docuwareConfig.url;
|
||||||
const cookie = docuwareConfig.token;
|
const cookie = docuwareConfig.token;
|
||||||
const fileCabinetName = docuwareInfo.fileCabinetName;
|
const fileCabinetName = docuwareInfo.fileCabinetName;
|
||||||
const find = docuwareInfo.find;
|
const find = docuwareInfo.find;
|
||||||
|
|
||||||
// get fileCabinetId
|
|
||||||
const options = {
|
const options = {
|
||||||
'headers': {
|
'headers': {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
|
@ -50,27 +67,27 @@ module.exports = Self => {
|
||||||
'Cookie': cookie
|
'Cookie': cookie
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// get fileCabinetId
|
||||||
const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options).json();
|
const fileCabinetResponse = await got.get(`${docuwareUrl}/FileCabinets`, options).json();
|
||||||
const fileCabinetId = fileCabinetResponse.FileCabinet.find(dialogs => dialogs.Name === fileCabinetName).Id;
|
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();
|
const dialogResponse = await got.get(`${docuwareUrl}/FileCabinets/${fileCabinetId}/dialogs`, options).json();
|
||||||
alexm marked this conversation as resolved
Outdated
joan
commented
Unused code Unused code
|
|||||||
console.log(dialogResponse);
|
|
||||||
const dialogId = dialogResponse.Dialog.find(dialogs => dialogs.DisplayName === 'find').Id;
|
const dialogId = dialogResponse.Dialog.find(dialogs => dialogs.DisplayName === 'find').Id;
|
||||||
|
|
||||||
console.log(fileCabinetId, dialogId);
|
// get docuwareID
|
||||||
/*
|
|
||||||
// get DocuwareID
|
|
||||||
const docuwareOptions = {
|
const docuwareOptions = {
|
||||||
'headers': {
|
'headers': {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Cookie': cookie
|
'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;
|
const docuwareId = JSON.parse(response.body).Items[0].Id;
|
||||||
|
|
||||||
// download file
|
// 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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -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"/);
|
||||||
|
});
|
||||||
|
});
|
|
@ -47,6 +47,12 @@
|
||||||
"Docuware": {
|
"Docuware": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"DocuwareConfig": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"DocuwareContainer": {
|
||||||
|
"dataSource": "docuwareStorage"
|
||||||
|
},
|
||||||
"EmailUser": {
|
"EmailUser": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "DocuwareContainer",
|
||||||
|
"base": "Container",
|
||||||
|
"acls": [{
|
||||||
|
"accessType": "READ",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}]
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/docuware/download')(Self);
|
require('../methods/docuware/download')(Self);
|
||||||
|
require('../methods/docuware/checkFile')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,6 @@ CREATE TABLE `vn`.`docuware` (
|
||||||
`find` varchar(50) DEFAULT NULL
|
`find` varchar(50) DEFAULT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO `vn`.`docuware`
|
INSERT INTO `vn`.`docuware` (`name`, `fileCabinetName`, `dialogName` , `find`)
|
||||||
(name, fileCabinetName, dialogName , find)
|
VALUES
|
||||||
VALUES('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N');
|
('deliveryClient', 'Albaranes cliente', 'findTicket', 'N__ALBAR_N');
|
||||||
|
|
|
@ -2,8 +2,4 @@ CREATE TABLE `vn`.`docuwareConfig` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
`url` varchar(75) NULL,
|
`url` varchar(75) NULL,
|
||||||
`token` varchar(1000) DEFAULT 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');
|
|
|
@ -2443,3 +2443,11 @@ INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced`
|
||||||
(1103, 500, CURDATE(), CURDATE()),
|
(1103, 500, CURDATE(), CURDATE()),
|
||||||
(1107, 500, CURDATE(), CURDATE()),
|
(1107, 500, CURDATE(), CURDATE()),
|
||||||
(1109, 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');
|
|
@ -83,5 +83,16 @@
|
||||||
"application/octet-stream",
|
"application/octet-stream",
|
||||||
"application/pdf"
|
"application/pdf"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"docuwareStorage": {
|
||||||
|
"name": "docuwareStorage",
|
||||||
|
"connector": "loopback-component-storage",
|
||||||
|
"provider": "filesystem",
|
||||||
|
"root": "./storage/pdfs/docuware",
|
||||||
|
"maxFileSize": "52428800",
|
||||||
|
"allowedContentTypes": [
|
||||||
|
"application/octet-stream",
|
||||||
|
"application/pdf"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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`));
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -3,7 +3,6 @@ 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,14 +20,22 @@
|
||||||
<vn-menu vn-id="showDeliveryNoteMenu">
|
<vn-menu vn-id="showDeliveryNoteMenu">
|
||||||
<vn-list>
|
<vn-list>
|
||||||
<vn-item
|
<vn-item
|
||||||
|
ng-if="!$ctrl.hasDocuware"
|
||||||
ng-click="$ctrl.showPdfDeliveryNote()"
|
ng-click="$ctrl.showPdfDeliveryNote()"
|
||||||
translate>
|
translate>
|
||||||
Show as PDF
|
as PDF
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
<a class="vn-item"
|
||||||
|
ng-if="$ctrl.hasDocuware"
|
||||||
|
href="api/Docuwares/{{$ctrl.ticket.id}}/download?access_token={{$ctrl.vnToken.token}}"
|
||||||
|
target="_blank"
|
||||||
|
translate>
|
||||||
|
as DOCUWARE
|
||||||
|
</a>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="$ctrl.showCsvDeliveryNote()"
|
ng-click="$ctrl.showCsvDeliveryNote()"
|
||||||
translate>
|
translate>
|
||||||
Show as CSV
|
as CSV
|
||||||
</vn-item>
|
</vn-item>
|
||||||
</vn-list>
|
</vn-list>
|
||||||
</vn-menu>
|
</vn-menu>
|
||||||
|
|
|
@ -82,6 +82,7 @@ class Controller extends Section {
|
||||||
return this.$http.get(`Tickets/${this.ticketId}`, {filter})
|
return this.$http.get(`Tickets/${this.ticketId}`, {filter})
|
||||||
.then(res => this.ticket = res.data)
|
.then(res => this.ticket = res.data)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.hasDocuware();
|
||||||
this.canStowaway();
|
this.canStowaway();
|
||||||
this.isTicketEditable();
|
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() {
|
showCsvDeliveryNote() {
|
||||||
this.vnReport.showCsv('delivery-note', {
|
this.vnReport.showCsv('delivery-note', {
|
||||||
recipientId: this.ticket.client.id,
|
recipientId: this.ticket.client.id,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Show Delivery Note...: Ver albarán...
|
Show Delivery Note...: Ver albarán...
|
||||||
Send Delivery Note...: Enviar albarán...
|
Send Delivery Note...: Enviar albarán...
|
||||||
Show as PDF: Ver como PDF
|
as PDF: como PDF
|
||||||
Show as CSV: Ver como CSV
|
as CSV: como CSV
|
||||||
Send PDF: Enviar PDF
|
Send PDF: Enviar PDF
|
||||||
Send CSV: Enviar CSV
|
Send CSV: Enviar CSV
|
||||||
Send CSV Delivery Note: Enviar albarán en CSV
|
Send CSV Delivery Note: Enviar albarán en CSV
|
||||||
|
|
Loading…
Reference in New Issue
Unused code