diff --git a/back/methods/docuware/specs/upload.spec.js b/back/methods/docuware/specs/upload.spec.js index 866499b66..7b794cbb9 100644 --- a/back/methods/docuware/specs/upload.spec.js +++ b/back/methods/docuware/specs/upload.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; describe('docuware upload()', () => { const userId = 9; - const ticketIds = [10]; + const ids = [10]; const ctx = { - args: {ticketIds}, + args: {ids}, req: { getLocale: () => { return 'en'; @@ -32,7 +32,7 @@ describe('docuware upload()', () => { const options = {transaction: tx}; const user = await models.UserConfig.findById(userId, null, options); await user.updateAttribute('tabletFk', 'Tablet1', options); - await models.Docuware.upload(ctx, ticketIds, fileCabinetName, options); + await models.Docuware.upload(ctx, ids, fileCabinetName, options); await tx.rollback(); } catch (e) { @@ -50,7 +50,7 @@ describe('docuware upload()', () => { let error; try { const options = {transaction: tx}; - await models.Docuware.upload(ctx, ticketIds, fileCabinetName, options); + await models.Docuware.upload(ctx, ids, fileCabinetName, options); await tx.rollback(); } catch (e) { diff --git a/back/methods/docuware/upload.js b/back/methods/docuware/upload.js index 4f212e186..454f45f83 100644 --- a/back/methods/docuware/upload.js +++ b/back/methods/docuware/upload.js @@ -1,4 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); +// const isProduction = require('vn-loopback/server/boot/isProduction'); module.exports = Self => { Self.remoteMethodCtx('upload', { @@ -45,7 +46,7 @@ module.exports = Self => { throw new UserError('This user does not have an assigned tablet'); const docuwareOptions = await Self.getOptions(); - const {modelFk} = await Self.getDocuware({code: fileCabinet, action}); + const {modelFk} = await Self.getDocuware({where: {code: fileCabinet, action}}); const modelIsValid = await Self.app.models.Module.findOne({where: {code: modelFk}}); if (!modelIsValid) @@ -58,6 +59,9 @@ module.exports = Self => { const uri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents`; + // if (!isProduction(false)) + // throw new UserError('Action not allowed on the test environment'); + await Self.app.models[model].docuwareUpload({ctx, tabletFk, ids, myOptions, uri, docuwareOptions, dialogId}); return models.TicketTracking.setDelivered(ctx, ids, myOptions); diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index fd940d8a6..821b2fa1f 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -315,4 +315,6 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`) FROM mysql.roles_mapping WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost; +INSERT INTO vn.docuware (code,fileCabinetName,`action`,dialogName,findById,dmsTypeFk,modelFk) + VALUES ('hr','RRHH','store','Archivar','N__DOCUMENTO',3,'worker'); FLUSH PRIVILEGES; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 18ccd79d0..da94c8c2f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3796,8 +3796,7 @@ UPDATE vn.locker SET workerFk = 1110 WHERE id = 147; -- Auto-generated SQL script #202405201318 UPDATE vn.userConfig SET tabletFk='Tablet1' - WHERE userFk=5; - + WHERE userFk=9; -- Auto-generated SQL script #202405201207 UPDATE vn.docuware diff --git a/db/versions/11062-tealArborvitae/00-firstScript.sql b/db/versions/11062-tealArborvitae/00-firstScript.sql index f619e8906..a245845d8 100644 --- a/db/versions/11062-tealArborvitae/00-firstScript.sql +++ b/db/versions/11062-tealArborvitae/00-firstScript.sql @@ -1,9 +1,11 @@ -- Place your SQL code here - -ALTER TABLE vn.docuwareTablet ADD fileCabinet varchar(100) NULL; ALTER TABLE vn.docuware ADD modelFk VARCHAR(45) DEFAULT NULL NULL; ALTER TABLE vn.docuware ADD CONSTRAINT docuware_module_FK FOREIGN KEY (modelFk) REFERENCES salix.module(code); +ALTER TABLE vn.docuwareTablet ADD fileCabinet varchar(100) NULL; +-- Auto-generated SQL script #202405221107 + + -- Auto-generated SQL script #202405201951 INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) VALUES ('Worker','isPDASigned','READ','ALLOW','ROLE','hr'); diff --git a/e2e/tests.js b/e2e/tests.js index 829056f4c..4d9302921 100644 --- a/e2e/tests.js +++ b/e2e/tests.js @@ -36,20 +36,7 @@ async function test() { const jasmine = new Jasmine(); const specFiles = [ - `./e2e/paths/01*/*[sS]pec.js`, - `./e2e/paths/02*/*[sS]pec.js`, - `./e2e/paths/03*/*[sS]pec.js`, - `./e2e/paths/04*/*[sS]pec.js`, `./e2e/paths/05*/*[sS]pec.js`, - `./e2e/paths/06*/*[sS]pec.js`, - `./e2e/paths/07*/*[sS]pec.js`, - `./e2e/paths/08*/*[sS]pec.js`, - `./e2e/paths/09*/*[sS]pec.js`, - `./e2e/paths/10*/*[sS]pec.js`, - `./e2e/paths/11*/*[sS]pec.js`, - `./e2e/paths/12*/*[sS]pec.js`, - `./e2e/paths/13*/*[sS]pec.js`, - `./e2e/paths/**/*[sS]pec.js` ]; jasmine.loadConfig({ diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 32f245454..38221e742 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -315,7 +315,7 @@ class Controller extends Section { if (!force) return this.$.pdfToTablet.show(); - return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ticketIds: [this.id]}) + return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ids: [this.id]}) .then(() => { this.vnApp.showSuccess(this.$t('PDF sent!')); }); diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 489f677a3..2056e29dc 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -11,12 +11,12 @@ export default class Controller extends Section { sendDocuware() { const checkedTickets = this.checked; - let ticketIds = []; + let ids = []; for (let ticket of checkedTickets) - ticketIds.push(ticket.id); + ids.push(ticket.id); - return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ticketIds}) + return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ids}) .then(res => { let state = res.data; for (let ticket of checkedTickets) { diff --git a/modules/worker/back/methods/worker/docuwareUpload.js b/modules/worker/back/methods/worker/docuwareUpload.js index 37602729b..7be8ccd66 100644 --- a/modules/worker/back/methods/worker/docuwareUpload.js +++ b/modules/worker/back/methods/worker/docuwareUpload.js @@ -3,115 +3,82 @@ const {models} = require('vn-loopback/server/server'); const UserError = require('vn-loopback/util/user-error'); const isProduction = require('vn-loopback/server/boot/isProduction'); module.exports = Self => { - Self.docuwareUpload = async({ctx, tabletFk, ids: workerId, myOptions, uri, docuwareOptions, dialogId}) => { - if (!Array.isArray(workerId)) workerId = [workerId]; - for (id of ticketIds) { - // get delivery note - ctx.args.id = id; - const deliveryNote = await models.Ticket.deliveryNotePdf(ctx, { - id, - type: 'deliveryNote' - }, myOptions); - // get ticket data - const ticket = await models.Ticket.findById(id, { - include: [{ - relation: 'client', - scope: { - fields: ['id', 'name', 'fi'] - } - }] - }, myOptions); + Self.docuwareUpload = async({ctx, tabletFk, ids: id, myOptions, uri, docuwareOptions, dialogId}) => { + // get delivery note + const pdaId = id[0]; + ctx.args.id = pdaId; + delete ctx.args.ids; + // get ticket data + const pda = await models.DeviceProduction.findById(pdaId, myOptions); + const user = await models.UserConfig.find({where: {tabletFk}, fields: ['userFk']}, myOptions); - // upload file - const templateJson = { - 'Fields': [ - { - 'FieldName': 'N__ALBAR_N', - 'ItemElementName': 'string', - 'Item': id, - }, - { - 'FieldName': 'CIF_PROVEEDOR', - 'ItemElementName': 'string', - 'Item': ticket.client().fi, - }, - { - 'FieldName': 'CODIGO_PROVEEDOR', - 'ItemElementName': 'string', - 'Item': ticket.client().id, - }, - { - 'FieldName': 'NOMBRE_PROVEEDOR', - 'ItemElementName': 'string', - 'Item': ticket.client().name + ' - ' + id, - }, - { - 'FieldName': 'FECHA_FACTURA', - 'ItemElementName': 'date', - 'Item': ticket.shipped, - }, - { - 'FieldName': 'TOTAL_FACTURA', - 'ItemElementName': 'Decimal', - 'Item': ticket.totalWithVat, - }, - { - 'FieldName': 'ESTADO', - 'ItemElementName': 'string', - 'Item': 'Pendiente procesar', - }, - { - 'FieldName': 'FIRMA_', - 'ItemElementName': 'string', - 'Item': 'Si', - }, - { - 'FieldName': 'FILTRO_TABLET', - 'ItemElementName': 'string', - 'Item': tabletFk, - } - ] - }; - - if (!isProduction(false)) - throw new UserError('Action not allowed on the test environment'); - - // delete old - const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false); - if (docuwareFile) { - const deleteJson = { - 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}] - }; - const deleteUri = `${uri}/${docuwareFile.id}/Fields`; - await axios.put(deleteUri, deleteJson, docuwareOptions.headers); - } - - const uploadUri = `${uri}?StoreDialogId=${dialogId}`; - const FormData = require('form-data'); - const data = new FormData(); - - data.append('document', JSON.stringify(templateJson), 'schema.json'); - data.append('file[]', deliveryNote[0], 'file.pdf'); - const uploadOptions = { - headers: { - 'Content-Type': 'multipart/form-data', - 'X-File-ModifiedDate': Date.vnNew(), - 'Cookie': docuwareOptions.headers.headers.Cookie, - ...data.getHeaders() + // upload file + const signPda = await models.Worker.signPdaPdf(ctx, + pdaId + , myOptions); + const templateJson = { + 'Fields': [ + { + 'FieldName': 'N__DOCUMENTO', + 'ItemElementName': 'string', + 'Item': id, }, - }; + { + 'FieldName': 'ESTADO', + 'ItemElementName': 'string', + 'Item': 'Pendiente procesar', + }, + { + 'FieldName': 'FIRMA_', + 'ItemElementName': 'string', + 'Item': 'Si', + }, + { + 'FieldName': 'FILTRO_TABLET', + 'ItemElementName': 'string', + 'Item': tabletFk, + } + ] + }; - try { - await axios.post(uploadUri, data, uploadOptions); - } catch (err) { - const $t = ctx.req.__; - const message = $t('Failed to upload delivery note', {id}); - if (uploaded.length) - await models.TicketTracking.setDelivered(ctx, uploaded, myOptions); - throw new UserError(message); - } - uploaded.push(id); + if (!isProduction(false)) + throw new UserError('Action not allowed on the test environment'); + + // delete old + const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false); + if (docuwareFile) { + const deleteJson = { + 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}] + }; + const deleteUri = `${uri}/${docuwareFile.id}/Fields`; + await axios.put(deleteUri, deleteJson, docuwareOptions.headers); } + + const uploadUri = `${uri}?StoreDialogId=${dialogId}`; + const FormData = require('form-data'); + const data = new FormData(); + + data.append('document', JSON.stringify(templateJson), 'schema.json'); + data.append('file[]', signPda[0], 'file.pdf'); + const uploadOptions = { + headers: { + 'Content-Type': 'multipart/form-data', + 'X-File-ModifiedDate': Date.vnNew(), + 'Cookie': docuwareOptions.headers.headers.Cookie, + ...data.getHeaders() + }, + }; + + try { + await axios.post(uploadUri, data, uploadOptions); + } catch (err) { + const $t = ctx.req.__; + const message = $t('Failed to upload delivery note', {id}); + if (uploaded.length) + await models.TicketTracking.setDelivered(ctx, uploaded, myOptions); + throw new UserError(message); + } + uploaded.push(id); }; }; diff --git a/print/templates/reports/sign-pda/sign-pda.js b/print/templates/reports/sign-pda/sign-pda.js index 844982ad0..79d7d0148 100755 --- a/print/templates/reports/sign-pda/sign-pda.js +++ b/print/templates/reports/sign-pda/sign-pda.js @@ -6,7 +6,6 @@ module.exports = { async serverPrefetch() { this.device = await this.findOneFromDef('device', [this.id]); }, - data() {}, computed: { }, methods: {