#5926 - Worker/PDA docuware #2482

Open
jsegarra wants to merge 40 commits from 5926_pda_worker_docuware into dev
4 changed files with 96 additions and 121 deletions
Showing only changes of commit 11381258cc - Show all commits

View File

@ -1,5 +1,5 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
// const isProduction = require('vn-loopback/server/boot/isProduction'); const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('upload', { Self.remoteMethodCtx('upload', {

View File

@ -3788,7 +3788,6 @@ INSERT INTO vn.workerTeam(id, team, workerFk)
VALUES VALUES
(8, 1, 19); (8, 1, 19);
INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment)
INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment)
VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL); VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL);

View File

@ -3,7 +3,7 @@ const {models} = require('vn-loopback/server/server');
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const isProduction = require('vn-loopback/server/boot/isProduction'); const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => { module.exports = Self => {
Self.docuwareUpload = async({ctx, tabletFk, ids: ticketIds, myOptions, uri, docuwareOptions, dialogId}) => { Self.docuwareUpload = async({ctx, tabletFk, ids: ticketIds, myOptions, uri, dialogId}) => {
for (id of ticketIds) { for (id of ticketIds) {
// get delivery note // get delivery note
ctx.args.id = id; ctx.args.id = id;
@ -22,83 +22,78 @@ module.exports = Self => {
}, myOptions); }, myOptions);
// upload file // upload file
const templateJson = { const configTemplate = {
'Fields': [
{ 'N__ALBAR_N': {
'FieldName': 'N__ALBAR_N', type: 'string',
'ItemElementName': 'string', value: id,
'Item': id, },
}, 'CIF_PROVEEDOR': {
{ type: 'string',
'FieldName': 'CIF_PROVEEDOR', value: ticket.client().fi,
'ItemElementName': 'string', },
'Item': ticket.client().fi, 'CODIGO_PROVEEDOR': {
}, type: 'string',
{ value: ticket.client().id,
'FieldName': 'CODIGO_PROVEEDOR', },
'ItemElementName': 'string', 'NOMBRE_PROVEEDOR': {
'Item': ticket.client().id, type: 'string',
}, value: ticket.client().name + ' - ' + id,
{ },
'FieldName': 'NOMBRE_PROVEEDOR', 'FECHA_FACTURA': {
'ItemElementName': 'string', type: 'date',
'Item': ticket.client().name + ' - ' + id, value: ticket.shipped,
}, },
{ 'TOTAL_FACTURA': {
'FieldName': 'FECHA_FACTURA', type: 'Decimal',
'ItemElementName': 'date', value: ticket.totalWithVat,
'Item': ticket.shipped, },
}, 'ESTADO': {
{ type: 'string',
'FieldName': 'TOTAL_FACTURA', value: 'Pendiente procesar',
'ItemElementName': 'Decimal', },
'Item': ticket.totalWithVat, 'FIRMA_': {
}, type: 'string',
{ value: 'Si',
'FieldName': 'ESTADO', },
'ItemElementName': 'string', 'FILTRO_TABLET': {
'Item': 'Pendiente procesar', type: 'string',
}, value: tabletFk,
{ }
'FieldName': 'FIRMA_',
'ItemElementName': 'string',
'Item': 'Si',
},
{
'FieldName': 'FILTRO_TABLET',
'ItemElementName': 'string',
'Item': tabletFk,
}
]
}; };
if (!isProduction(false)) if (!isProduction(false))
throw new UserError('Action not allowed on the test environment'); throw new UserError('Action not allowed on the test environment');
// delete old // delete old
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false); await models.Docuware.deleteOld(id, fileCabinet, uri);
if (docuwareFile) {
const deleteJson = { // const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}] // if (docuwareFile) {
}; // const deleteJson = {
const deleteUri = `${uri}/${docuwareFile.id}/Fields`; // 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
await axios.put(deleteUri, deleteJson, docuwareOptions.headers); // };
} // const deleteUri = `${uri}/${docuwareFile.id}/Fields`;
// await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
// }
const uploadUri = `${uri}?StoreDialogId=${dialogId}`; const uploadUri = `${uri}?StoreDialogId=${dialogId}`;
const FormData = require('form-data'); const uploadOptions = models.Docuware.uploadOptions(deliveryNote[0], configTemplate);
const data = new FormData();
data.append('document', JSON.stringify(templateJson), 'schema.json'); // const FormData = require('form-data');
data.append('file[]', deliveryNote[0], 'file.pdf'); // const data = new FormData();
const uploadOptions = {
headers: { // data.append('document', JSON.stringify(templateJson), 'schema.json');
'Content-Type': 'multipart/form-data', // data.append('file[]', deliveryNote[0], 'file.pdf');
'X-File-ModifiedDate': Date.vnNew(), // const uploadOptions = {
'Cookie': docuwareOptions.headers.headers.Cookie, // headers: {
...data.getHeaders() // 'Content-Type': 'multipart/form-data',
}, // 'X-File-ModifiedDate': Date.vnNew(),
}; // 'Cookie': docuwareOptions.headers.headers.Cookie,
// ...data.getHeaders()
// },
// };
try { try {
await axios.post(uploadUri, data, uploadOptions); await axios.post(uploadUri, data, uploadOptions);

View File

@ -3,79 +3,60 @@ const {models} = require('vn-loopback/server/server');
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const isProduction = require('vn-loopback/server/boot/isProduction'); const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => { module.exports = Self => {
Self.docuwareUpload = async({ctx, tabletFk, ids: id, myOptions, uri, docuwareOptions, dialogId}) => { Self.docuwareUpload = async({ctx, tabletFk, ids: id, myOptions, uri, fileCabinet, dialogId}) => {
// get delivery note // get delivery note
const pdaId = id[0]; const pdaId = id[0];
ctx.args.id = pdaId; ctx.args.id = pdaId;
delete ctx.args.ids; delete ctx.args.ids;
// get ticket data // // get ticket data
const pda = await models.DeviceProduction.findById(pdaId, myOptions); // const pda = await models.DeviceProduction.findById(pdaId, myOptions);
const user = await models.UserConfig.find({where: {tabletFk}, fields: ['userFk']}, myOptions); // const user = await models.UserConfig.find({where: {tabletFk}, fields: ['userFk']}, myOptions);
// upload file // upload file
const signPda = await models.Worker.signPdaPdf(ctx, const signPda = await models.Worker.signPdaPdf(ctx,
pdaId pdaId
, myOptions); , myOptions);
const templateJson = { const configTemplate = {
'Fields': [ 'N__DOCUMENTO': {
{ type: 'String',
'FieldName': 'N__DOCUMENTO', value: pdaId
'ItemElementName': 'string', },
'Item': id, 'ESTADO': {
}, type: 'String',
{ value: 'Pendiente procesar'
'FieldName': 'ESTADO', },
'ItemElementName': 'string', 'FIRMA_': {
'Item': 'Pendiente procesar', type: 'String',
}, value: 'Si'
{ },
'FieldName': 'FIRMA_', 'FILTRO_TABLET': {
'ItemElementName': 'string', type: 'String',
'Item': 'Si', value: tabletFk
}, }
{
'FieldName': 'FILTRO_TABLET',
'ItemElementName': 'string',
'Item': tabletFk,
}
]
}; };
if (!isProduction(false)) if (!isProduction(false))
throw new UserError('Action not allowed on the test environment'); throw new UserError('Action not allowed on the test environment');
// delete old // delete old
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false); await models.Docuware.deleteOld(id, fileCabinet, uri);
if (docuwareFile) { // const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
const deleteJson = { // if (docuwareFile) {
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}] // const deleteJson = {
}; // 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
const deleteUri = `${uri}/${docuwareFile.id}/Fields`; // };
await axios.put(deleteUri, deleteJson, docuwareOptions.headers); // const deleteUri = `${uri}/${docuwareFile.id}/Fields`;
} // await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
// }
const uploadUri = `${uri}?StoreDialogId=${dialogId}`; const uploadUri = `${uri}?StoreDialogId=${dialogId}`;
const FormData = require('form-data'); const uploadOptions = models.Docuware.uploadOptions(signPda[0], configTemplate);
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 { try {
await axios.post(uploadUri, data, uploadOptions); await axios.post(uploadUri, data, uploadOptions);
} catch (err) { } catch (err) {
const $t = ctx.req.__; const $t = ctx.req.__;
const message = $t('Failed to upload delivery note', {id}); const message = $t('Failed to upload delivery note', {id});
if (uploaded.length)
await models.TicketTracking.setDelivered(ctx, uploaded, myOptions);
throw new UserError(message); throw new UserError(message);
} }
uploaded.push(id); uploaded.push(id);