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 isProduction = require('vn-loopback/server/boot/isProduction');
const isProduction = require('vn-loopback/server/boot/isProduction');
module.exports = Self => {
Self.remoteMethodCtx('upload', {

View File

@ -3788,7 +3788,6 @@ INSERT INTO vn.workerTeam(id, team, workerFk)
VALUES
(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)
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 isProduction = require('vn-loopback/server/boot/isProduction');
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) {
// get delivery note
ctx.args.id = id;
@ -22,83 +22,78 @@ module.exports = Self => {
}, 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,
}
]
const configTemplate = {
'N__ALBAR_N': {
type: 'string',
value: id,
},
'CIF_PROVEEDOR': {
type: 'string',
value: ticket.client().fi,
},
'CODIGO_PROVEEDOR': {
type: 'string',
value: ticket.client().id,
},
'NOMBRE_PROVEEDOR': {
type: 'string',
value: ticket.client().name + ' - ' + id,
},
'FECHA_FACTURA': {
type: 'date',
value: ticket.shipped,
},
'TOTAL_FACTURA': {
type: 'Decimal',
value: ticket.totalWithVat,
},
'ESTADO': {
type: 'string',
value: 'Pendiente procesar',
},
'FIRMA_': {
type: 'string',
value: 'Si',
},
'FILTRO_TABLET': {
type: 'string',
value: 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);
}
await models.Docuware.deleteOld(id, fileCabinet, uri);
// 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();
const uploadOptions = models.Docuware.uploadOptions(deliveryNote[0], configTemplate);
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()
},
};
// 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()
// },
// };
try {
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 isProduction = require('vn-loopback/server/boot/isProduction');
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
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);
// // 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 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,
}
]
const configTemplate = {
'N__DOCUMENTO': {
type: 'String',
value: pdaId
},
'ESTADO': {
type: 'String',
value: 'Pendiente procesar'
},
'FIRMA_': {
type: 'String',
value: 'Si'
},
'FILTRO_TABLET': {
type: 'String',
value: 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);
}
await models.Docuware.deleteOld(id, fileCabinet, uri);
// 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()
},
};
const uploadOptions = models.Docuware.uploadOptions(signPda[0], configTemplate);
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);