feat(salix): refs #5926 #6321 ruse core methods
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2024-05-30 12:31:28 +02:00
parent 294fbdcbeb
commit 11381258cc
4 changed files with 96 additions and 121 deletions

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': {
'FieldName': 'CIF_PROVEEDOR', type: 'string',
'ItemElementName': 'string', value: ticket.client().fi,
'Item': ticket.client().fi,
}, },
{ 'CODIGO_PROVEEDOR': {
'FieldName': 'CODIGO_PROVEEDOR', type: 'string',
'ItemElementName': 'string', value: ticket.client().id,
'Item': ticket.client().id,
}, },
{ 'NOMBRE_PROVEEDOR': {
'FieldName': 'NOMBRE_PROVEEDOR', type: 'string',
'ItemElementName': 'string', value: ticket.client().name + ' - ' + id,
'Item': ticket.client().name + ' - ' + id,
}, },
{ 'FECHA_FACTURA': {
'FieldName': 'FECHA_FACTURA', type: 'date',
'ItemElementName': 'date', value: ticket.shipped,
'Item': ticket.shipped,
}, },
{ 'TOTAL_FACTURA': {
'FieldName': 'TOTAL_FACTURA', type: 'Decimal',
'ItemElementName': 'Decimal', value: ticket.totalWithVat,
'Item': ticket.totalWithVat,
}, },
{ 'ESTADO': {
'FieldName': 'ESTADO', type: 'string',
'ItemElementName': 'string', value: 'Pendiente procesar',
'Item': 'Pendiente procesar',
}, },
{ 'FIRMA_': {
'FieldName': 'FIRMA_', type: 'string',
'ItemElementName': 'string', value: 'Si',
'Item': 'Si',
}, },
{ 'FILTRO_TABLET': {
'FieldName': 'FILTRO_TABLET', type: 'string',
'ItemElementName': 'string', value: tabletFk,
'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': {
'FieldName': 'ESTADO', type: 'String',
'ItemElementName': 'string', value: 'Pendiente procesar'
'Item': 'Pendiente procesar',
}, },
{ 'FIRMA_': {
'FieldName': 'FIRMA_', type: 'String',
'ItemElementName': 'string', value: 'Si'
'Item': 'Si',
}, },
{ 'FILTRO_TABLET': {
'FieldName': 'FILTRO_TABLET', type: 'String',
'ItemElementName': 'string', value: tabletFk
'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);