refs #5712 feat(workerDms): docuware download
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
b60cd2539a
commit
c23d8282eb
|
@ -17,18 +17,16 @@ module.exports = Self => {
|
|||
required: true,
|
||||
description: 'The fileCabinet name'
|
||||
},
|
||||
{
|
||||
arg: 'signed',
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
description: 'If pdf is necessary to be signed'
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
required: false,
|
||||
description: 'The filter'
|
||||
}
|
||||
},
|
||||
{
|
||||
arg: 'signed',
|
||||
type: 'boolean',
|
||||
description: 'If pdf is necessary to be signed'
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
|
@ -40,7 +38,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.checkFile = async function(id, fileCabinet, signed, filter) {
|
||||
Self.checkFile = async function(id, fileCabinet, filter, signed) {
|
||||
const models = Self.app.models;
|
||||
const action = 'find';
|
||||
|
||||
|
@ -50,7 +48,8 @@ module.exports = Self => {
|
|||
action: action
|
||||
}
|
||||
});
|
||||
console.log(id, fileCabinet, signed, filter);
|
||||
console.log('ENTRY');
|
||||
console.log(filter, signed);
|
||||
if (!filter) {
|
||||
filter = {
|
||||
condition: [
|
||||
|
@ -67,13 +66,18 @@ module.exports = Self => {
|
|||
]
|
||||
};
|
||||
}
|
||||
if (signed) {
|
||||
filter.condition.push({
|
||||
DBName: 'ESTADO',
|
||||
Value: ['Firmado']
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const options = await Self.getOptions();
|
||||
|
||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
||||
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
||||
console.log('FILTER', filter);
|
||||
|
||||
const response = await axios.post(
|
||||
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
||||
|
@ -81,13 +85,8 @@ module.exports = Self => {
|
|||
options.headers
|
||||
);
|
||||
const [documents] = response.data.Items;
|
||||
console.log(response);
|
||||
console.log(response.data);
|
||||
if (!documents) return false;
|
||||
|
||||
const state = documents.Fields.find(field => field.FieldName == 'ESTADO');
|
||||
if (signed && state.Item != 'Firmado') return false;
|
||||
|
||||
return {id: documents.Id};
|
||||
} catch (error) {
|
||||
return false;
|
||||
|
|
|
@ -83,13 +83,13 @@ module.exports = Self => {
|
|||
const fileCabinetId = await Self.getFileCabinet(code);
|
||||
const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
|
||||
|
||||
const {data} = await axios.post(
|
||||
const data = await axios.post(
|
||||
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
||||
filter,
|
||||
options.headers
|
||||
);
|
||||
|
||||
return parser(data, parse);
|
||||
console.log(data.data);
|
||||
return parser(data.data, parse);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ const axios = require('axios');
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('download', {
|
||||
Self.remoteMethod('download', {
|
||||
description: 'Download an docuware PDF',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
|
@ -16,8 +16,12 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'fileCabinet',
|
||||
type: 'string',
|
||||
description: 'The file cabinet',
|
||||
http: {source: 'path'}
|
||||
description: 'The file cabinet'
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: 'The filter'
|
||||
}
|
||||
],
|
||||
returns: [
|
||||
|
@ -36,16 +40,15 @@ module.exports = Self => {
|
|||
}
|
||||
],
|
||||
http: {
|
||||
path: `/:id/download/:fileCabinet`,
|
||||
path: `/:id/download`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.download = async function(ctx, id, fileCabinet, filter) {
|
||||
Self.download = async function(id, fileCabinet, filter) {
|
||||
const models = Self.app.models;
|
||||
|
||||
// REVIEW
|
||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true);
|
||||
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, filter);
|
||||
if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists');
|
||||
|
||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
||||
|
|
|
@ -16,11 +16,6 @@ module.exports = Self => {
|
|||
arg: 'fileCabinet',
|
||||
type: 'string',
|
||||
description: 'The file cabinet'
|
||||
},
|
||||
{
|
||||
arg: 'dialog',
|
||||
type: 'string',
|
||||
description: 'The dialog'
|
||||
}
|
||||
],
|
||||
returns: [],
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
INSERT INTO `vn`.`docuware`
|
||||
(code, fileCabinetName, `action`, dialogName, findById)
|
||||
VALUES('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO');
|
||||
INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById)
|
||||
VALUES
|
||||
('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO');
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('docuwareDownload', {
|
||||
description: 'Download a ticket delivery note document',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
description: 'The document 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'}
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/:id/docuwareDownload`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.docuwareDownload = async function(ctx, id) {
|
||||
const filter = {
|
||||
condition: [
|
||||
{
|
||||
DBName: docuwareInfo.findById,
|
||||
Value: [id]
|
||||
},
|
||||
{
|
||||
DBName: 'ESTADO',
|
||||
Value: ['Firmado']
|
||||
}
|
||||
],
|
||||
sortOrder: [
|
||||
{
|
||||
Field: 'FILENAME',
|
||||
Direction: 'Desc'
|
||||
}
|
||||
]
|
||||
};
|
||||
return await Self.app.models.Docuware.download(id, 'deliveryNote', filter);
|
||||
};
|
||||
};
|
|
@ -36,13 +36,12 @@
|
|||
translate>
|
||||
as PDF without prices
|
||||
</vn-item>
|
||||
<a class="vn-item"
|
||||
<vn-item
|
||||
ng-if="$ctrl.hasDocuwareFile"
|
||||
href='api/Docuwares/{{$ctrl.ticket.id}}/download/deliveryNote?access_token={{$ctrl.vnToken.token}}'
|
||||
target="_blank"
|
||||
ng-click="$ctrl.docuwareDownload()"
|
||||
translate>
|
||||
as PDF signed
|
||||
</a>
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.showCsvDeliveryNote()"
|
||||
translate>
|
||||
|
|
|
@ -336,6 +336,10 @@ class Controller extends Section {
|
|||
this.vnApp.showSuccess(this.$t('PDF sent!'));
|
||||
});
|
||||
}
|
||||
|
||||
docuwareDownload() {
|
||||
this.vnFile.download(`api/Ticket/${this.ticket.id}/docuwareDownload`);
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
|
||||
|
|
|
@ -32,7 +32,6 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.docuwareDownload = async function(ctx, id) {
|
||||
// CHECK ROLE?
|
||||
const filter = {
|
||||
condition: [
|
||||
{
|
||||
|
@ -41,6 +40,6 @@ module.exports = Self => {
|
|||
}
|
||||
]
|
||||
};
|
||||
return await Self.app.models.Docuware.download(ctx, id, 'hr', false, filter);
|
||||
return await Self.app.models.Docuware.download(id, 'hr', filter);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -59,12 +59,11 @@ module.exports = Self => {
|
|||
// Get docuware info
|
||||
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
||||
const docuwareParse = {
|
||||
'Document ID': 'dmsFk',
|
||||
'Filename': 'dmsFk',
|
||||
'Tipo Documento': 'description',
|
||||
'Stored on': 'created',
|
||||
};
|
||||
const workerDocuware = await models.Docuware.getById('hr', 'BONO MOLA XAVIER', docuwareParse);// worker.lastName + worker.firstName);
|
||||
|
||||
for (document of workerDocuware) {
|
||||
const defaultData = {
|
||||
file: document.dmsFk + '.png',
|
||||
|
|
|
@ -60,19 +60,31 @@
|
|||
<vn-td shrink-datetime>
|
||||
{{::document.created | date:'dd/MM/yyyy HH:mm'}}
|
||||
</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-td expand>
|
||||
<vn-icon-button title="{{'Download file' | translate}}"
|
||||
icon="cloud_download"
|
||||
ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-icon-button ui-sref="worker.card.dms.edit({dmsId: {{::document.dmsFk}}})"
|
||||
icon="edit"
|
||||
title="{{'Edit file' | translate}}">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
icon="delete"
|
||||
ng-click="confirm.show($index)"
|
||||
title="{{'Remove file' | translate}}"
|
||||
tabindex="-1">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-td expand>
|
||||
<vn-icon-button title="{{'Download file' | translate}}"
|
||||
icon="cloud_download"
|
||||
ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button ui-sref="worker.card.dms.edit({dmsId: {{::document.dmsFk}}})"
|
||||
icon="edit"
|
||||
title="{{'Edit file' | translate}}">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
icon="delete"
|
||||
ng-click="confirm.show($index)"
|
||||
|
|
Loading…
Reference in New Issue