feat(ticket_descriptor-menu): docuware implemented
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
06255e0a07
commit
0f4649c50f
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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"`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -50,9 +50,6 @@
|
|||
"DocuwareConfig": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"DocuwareContainer": {
|
||||
"dataSource": "docuwareStorage"
|
||||
},
|
||||
"EmailUser": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "DocuwareContainer",
|
||||
"base": "Container",
|
||||
"acls": [{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}]
|
||||
}
|
|
@ -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');
|
|
@ -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');
|
||||
('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word');
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,144 +1,138 @@
|
|||
|
||||
<vn-icon-button
|
||||
icon="more_vert"
|
||||
vn-popover="menu">
|
||||
icon="more_vert"
|
||||
vn-popover="menu">
|
||||
</vn-icon-button>
|
||||
<vn-menu vn-id="menu">
|
||||
<vn-list>
|
||||
<vn-item class="dropdown"
|
||||
vn-click-stop="showInvoiceMenu.show($event, 'left')"
|
||||
name="showInvoicePdf"
|
||||
translate>
|
||||
Show invoice...
|
||||
<vn-list>
|
||||
<vn-item class="dropdown"
|
||||
vn-click-stop="showInvoiceMenu.show($event, 'left')"
|
||||
name="showInvoicePdf"
|
||||
translate>
|
||||
Show invoice...
|
||||
<vn-menu vn-id="showInvoiceMenu">
|
||||
<vn-list>
|
||||
<a class="vn-item"
|
||||
href="api/InvoiceOuts/{{$ctrl.id}}/download?access_token={{$ctrl.vnToken.token}}"
|
||||
target="_blank"
|
||||
name="showInvoicePdf"
|
||||
translate>
|
||||
Show as PDF
|
||||
</a>
|
||||
<vn-item
|
||||
ng-click="$ctrl.showCsvInvoice()"
|
||||
translate>
|
||||
Show as CSV
|
||||
</vn-item>
|
||||
</vn-list>
|
||||
</vn-menu>
|
||||
</vn-item>
|
||||
<vn-item class="dropdown"
|
||||
vn-click-stop="sendInvoiceMenu.show($event, 'left')"
|
||||
name="sendInvoice"
|
||||
translate>
|
||||
Send invoice...
|
||||
|
||||
<vn-menu vn-id="showInvoiceMenu">
|
||||
<vn-list>
|
||||
<a class="vn-item"
|
||||
href="api/InvoiceOuts/{{$ctrl.id}}/download?access_token={{$ctrl.vnToken.token}}"
|
||||
target="_blank"
|
||||
name="showInvoicePdf"
|
||||
translate>
|
||||
Show as PDF
|
||||
</a>
|
||||
<vn-item
|
||||
ng-click="$ctrl.downloadDocuware()"
|
||||
translate>
|
||||
Show as DOCUWARE
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.showCsvInvoice()"
|
||||
translate>
|
||||
Show as CSV
|
||||
</vn-item>
|
||||
</vn-list>
|
||||
</vn-menu>
|
||||
</vn-item>
|
||||
<vn-item class="dropdown"
|
||||
vn-click-stop="sendInvoiceMenu.show($event, 'left')"
|
||||
name="sendInvoice"
|
||||
translate>
|
||||
Send invoice...
|
||||
|
||||
<vn-menu vn-id="sendInvoiceMenu">
|
||||
<vn-list>
|
||||
<vn-item
|
||||
ng-click="sendPdfConfirmation.show({email: $ctrl.invoiceOut.client.email})"
|
||||
translate>
|
||||
Send PDF
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="sendCsvConfirmation.show({email: $ctrl.invoiceOut.client.email})"
|
||||
translate>
|
||||
Send CSV
|
||||
</vn-item>
|
||||
</vn-list>
|
||||
</vn-menu>
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="deleteConfirmation.show()"
|
||||
vn-acl="invoicing"
|
||||
vn-acl-action="remove"
|
||||
name="deleteInvoice"
|
||||
translate>
|
||||
Delete Invoice
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="bookConfirmation.show()"
|
||||
vn-acl="invoicing"
|
||||
vn-acl-action="remove"
|
||||
name="bookInvoice"
|
||||
translate>
|
||||
Book invoice
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="createInvoicePdfConfirmation.show()"
|
||||
ng-show="$ctrl.hasInvoicing || !$ctrl.invoiceOut.hasPdf"
|
||||
name="regenerateInvoice"
|
||||
translate>
|
||||
{{!$ctrl.invoiceOut.hasPdf ? 'Generate PDF invoice': 'Regenerate PDF invoice'}}
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.showExportationLetter()"
|
||||
ng-show="$ctrl.invoiceOut.serial == 'E'"
|
||||
translate>
|
||||
Show CITES letter
|
||||
</vn-item>
|
||||
</vn-list>
|
||||
<vn-menu vn-id="sendInvoiceMenu">
|
||||
<vn-list>
|
||||
<vn-item
|
||||
ng-click="sendPdfConfirmation.show({email: $ctrl.invoiceOut.client.email})"
|
||||
translate>
|
||||
Send PDF
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="sendCsvConfirmation.show({email: $ctrl.invoiceOut.client.email})"
|
||||
translate>
|
||||
Send CSV
|
||||
</vn-item>
|
||||
</vn-list>
|
||||
</vn-menu>
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="deleteConfirmation.show()"
|
||||
vn-acl="invoicing"
|
||||
vn-acl-action="remove"
|
||||
name="deleteInvoice"
|
||||
translate>
|
||||
Delete Invoice
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="bookConfirmation.show()"
|
||||
vn-acl="invoicing"
|
||||
vn-acl-action="remove"
|
||||
name="bookInvoice"
|
||||
translate>
|
||||
Book invoice
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="createInvoicePdfConfirmation.show()"
|
||||
ng-show="$ctrl.hasInvoicing || !$ctrl.invoiceOut.hasPdf"
|
||||
name="regenerateInvoice"
|
||||
translate>
|
||||
{{!$ctrl.invoiceOut.hasPdf ? 'Generate PDF invoice': 'Regenerate PDF invoice'}}
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.showExportationLetter()"
|
||||
ng-show="$ctrl.invoiceOut.serial == 'E'"
|
||||
translate>
|
||||
Show CITES letter
|
||||
</vn-item>
|
||||
</vn-list>
|
||||
</vn-menu>
|
||||
<vn-confirm
|
||||
vn-id="deleteConfirmation"
|
||||
on-accept="$ctrl.deleteInvoiceOut()"
|
||||
question="Are you sure you want to delete this invoice?">
|
||||
vn-id="deleteConfirmation"
|
||||
on-accept="$ctrl.deleteInvoiceOut()"
|
||||
question="Are you sure you want to delete this invoice?">
|
||||
</vn-confirm>
|
||||
<vn-confirm
|
||||
vn-id="bookConfirmation"
|
||||
on-accept="$ctrl.bookInvoiceOut()"
|
||||
question="Are you sure you want to book this invoice?">
|
||||
vn-id="bookConfirmation"
|
||||
on-accept="$ctrl.bookInvoiceOut()"
|
||||
question="Are you sure you want to book this invoice?">
|
||||
</vn-confirm>
|
||||
<vn-client-descriptor-popover
|
||||
vn-id="clientDescriptor">
|
||||
vn-id="clientDescriptor">
|
||||
</vn-client-descriptor-popover>
|
||||
|
||||
<!-- Create invoice PDF confirmation dialog -->
|
||||
<vn-confirm
|
||||
vn-id="createInvoicePdfConfirmation"
|
||||
on-accept="$ctrl.createPdfInvoice()"
|
||||
question="Are you sure you want to generate/regenerate the PDF invoice?"
|
||||
message="Generate PDF invoice document">
|
||||
vn-id="createInvoicePdfConfirmation"
|
||||
on-accept="$ctrl.createPdfInvoice()"
|
||||
question="Are you sure you want to generate/regenerate the PDF invoice?"
|
||||
message="Generate PDF invoice document">
|
||||
</vn-confirm>
|
||||
|
||||
<!-- Send PDF invoice confirmation popup -->
|
||||
<vn-dialog
|
||||
vn-id="sendPdfConfirmation"
|
||||
on-accept="$ctrl.sendPdfInvoice($data)"
|
||||
message="Send PDF invoice">
|
||||
<tpl-body>
|
||||
<span translate>Are you sure you want to send it?</span>
|
||||
<vn-textfield vn-one
|
||||
label="Email"
|
||||
ng-model="sendPdfConfirmation.data.email">
|
||||
</vn-textfield>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Confirm</button>
|
||||
</tpl-buttons>
|
||||
vn-id="sendPdfConfirmation"
|
||||
on-accept="$ctrl.sendPdfInvoice($data)"
|
||||
message="Send PDF invoice">
|
||||
<tpl-body>
|
||||
<span translate>Are you sure you want to send it?</span>
|
||||
<vn-textfield vn-one
|
||||
label="Email"
|
||||
ng-model="sendPdfConfirmation.data.email">
|
||||
</vn-textfield>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Confirm</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
|
||||
<!-- Send CSV invoice confirmation popup -->
|
||||
<vn-dialog
|
||||
vn-id="sendCsvConfirmation"
|
||||
on-accept="$ctrl.sendCsvInvoice($data)"
|
||||
message="Send CSV invoice">
|
||||
<tpl-body>
|
||||
<span translate>Are you sure you want to send it?</span>
|
||||
<vn-textfield vn-one
|
||||
label="Email"
|
||||
ng-model="sendCsvConfirmation.data.email">
|
||||
</vn-textfield>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Confirm</button>
|
||||
</tpl-buttons>
|
||||
vn-id="sendCsvConfirmation"
|
||||
on-accept="$ctrl.sendCsvInvoice($data)"
|
||||
message="Send CSV invoice">
|
||||
<tpl-body>
|
||||
<span translate>Are you sure you want to send it?</span>
|
||||
<vn-textfield vn-one
|
||||
label="Email"
|
||||
ng-model="sendCsvConfirmation.data.email">
|
||||
</vn-textfield>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Confirm</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
|
@ -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`));
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
</vn-item>
|
||||
<a class="vn-item"
|
||||
ng-if="$ctrl.hasDocuware"
|
||||
href="api/Docuwares/{{$ctrl.ticket.id}}/download?access_token={{$ctrl.vnToken.token}}"
|
||||
href='api/Docuwares/{{$ctrl.ticket.id}}/download/deliveryClient/findTicket?access_token={{$ctrl.vnToken.token}}'
|
||||
target="_blank"
|
||||
translate>
|
||||
as DOCUWARE
|
||||
as PDF
|
||||
</a>
|
||||
<vn-item
|
||||
ng-click="$ctrl.showCsvDeliveryNote()"
|
||||
|
|
|
@ -82,9 +82,9 @@ 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();
|
||||
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;
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue