This commit is contained in:
parent
aa716634db
commit
6ded11a4c2
|
@ -8,7 +8,7 @@ module.exports = Self => {
|
|||
accepts:
|
||||
[
|
||||
{
|
||||
arg: 'singContent',
|
||||
arg: 'signContent',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The sign content'
|
||||
|
@ -39,83 +39,95 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
async function createGestDoc(ticketId, userFk) {
|
||||
if (! await gestDocExists(ticketId)) {
|
||||
const query = `SELECT t.warehouseFk,
|
||||
t.companyFk,
|
||||
c.name,
|
||||
r.id
|
||||
FROM vn.ticket t
|
||||
JOIN vn.client c ON t.clientFk = c.id
|
||||
JOIN vn.route r ON t.routeFk = r.id
|
||||
WHERE t.id = ?`;
|
||||
|
||||
const result = await Self.rawSql(query, [ticketId]);
|
||||
|
||||
const warehouseFk = result[0].warehouseFk;
|
||||
const companyFk = result[0].companyFk;
|
||||
const client = result[0].name;
|
||||
const route = result[0].id;
|
||||
|
||||
const queryDmsType = `SELECT id
|
||||
FROM vn.dmsType
|
||||
WHERE code='Ticket'`;
|
||||
|
||||
const resultDmsType = await Self.rawSql(queryDmsType, []);
|
||||
|
||||
const dmsInsert = `INSERT INTO vn.dms
|
||||
(dmsTypeFk, reference, description, companyFk, warehouseFk, workerFk)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`;
|
||||
|
||||
const resultDms = await Self.rawSql(
|
||||
dmsInsert,
|
||||
[
|
||||
resultDmsType[0].id, ticketId,
|
||||
`Ticket ${ticketId} Cliente ${client} Ruta ${route}`,
|
||||
companyFk, warehouseFk, userFk
|
||||
const models = Self.app.models;
|
||||
if (!await gestDocExists(ticketId)) {
|
||||
const result = await models.Ticket.findOne({
|
||||
where: {
|
||||
id: ticketId
|
||||
},
|
||||
include: [
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['id']
|
||||
}
|
||||
}, {
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}, {
|
||||
relation: 'route',
|
||||
scope: {
|
||||
fields: ['id']
|
||||
}
|
||||
}
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
const warehouseFk = result.warehouseFk;
|
||||
const companyFk = result.companyFk;
|
||||
const client = result.client.name;
|
||||
const route = result.route.id;
|
||||
|
||||
const resultDmsType = await models.DmsType.findOne({
|
||||
where: {
|
||||
code: 'Ticket'
|
||||
}
|
||||
});
|
||||
|
||||
const resultDms = await models.Dms.create({
|
||||
dmsTypeFk: resultDmsType.id,
|
||||
reference: ticketId,
|
||||
description: `Ticket ${ticketId} Cliente ${client} Ruta ${route}`,
|
||||
companyFk: companyFk,
|
||||
warehouseFk: warehouseFk,
|
||||
workerFk: userFk
|
||||
});
|
||||
|
||||
return resultDms.insertId;
|
||||
}
|
||||
|
||||
return 'null';
|
||||
}
|
||||
|
||||
async function gestDocExists(ticket) {
|
||||
const dMSQuery = `SELECT dmsFk as id FROM vn.ticketDms WHERE ticketFk = ?`;
|
||||
const models = Self.app.models;
|
||||
const result = await models.TicketDms.findOne({
|
||||
where: {
|
||||
ticketFk: ticket
|
||||
},
|
||||
fields: ['dmsFk']
|
||||
});
|
||||
|
||||
result = await Self.rawSql(dMSQuery, [ticket]);
|
||||
|
||||
if (result.length < 0)
|
||||
if (result == null)
|
||||
return false;
|
||||
|
||||
const isSigned = await Self.rawSql(
|
||||
`SELECT isSigned FROM vn.ticket WHERE id = ?`, [ticket]
|
||||
);
|
||||
const isSigned = await models.Ticket.findOne({
|
||||
where: {
|
||||
id: ticket
|
||||
},
|
||||
fields: ['isSigned']
|
||||
});
|
||||
|
||||
if (isSigned[0].isSigned)
|
||||
if (isSigned)
|
||||
return true;
|
||||
else
|
||||
deleteFromGestDoc(ticket);
|
||||
}
|
||||
|
||||
async function deleteFromGestDoc(ticket) {
|
||||
await Self.rawSql(
|
||||
`DELETE FROM vn.dms WHERE reference = ?`, [ticket]
|
||||
);
|
||||
await models.Dms.destroyById(ticket);
|
||||
}
|
||||
|
||||
async function dmsRecover(ticket, signContent) {
|
||||
const query = `INSERT INTO vn.dmsRecover (ticketFk, sign) VALUES (?, ?)`;
|
||||
|
||||
await Self.rawSql(query, [ticket, signContent]);
|
||||
const models = Self.app.models;
|
||||
await models.DmsRecover.create({
|
||||
ticketFk: ticket,
|
||||
sign: signContent
|
||||
});
|
||||
}
|
||||
|
||||
async function ticketGestdoc(ticket, dmsFk) {
|
||||
const query = `REPLACE INTO vn.ticketDms(ticketFk, dmsFk)
|
||||
VALUES (?, ?)`;
|
||||
|
||||
await Self.rawSql(query, [ticket, dmsFk]);
|
||||
const models = Self.app.models;
|
||||
models.TicketDms.replaceOrCreate({
|
||||
ticketFk: ticket,
|
||||
dmsFk: dmsFk
|
||||
});
|
||||
|
||||
const queryVnTicketSetState = `CALL vn.ticket_setState(?, ?)`;
|
||||
|
||||
|
@ -123,12 +135,18 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
async function updateGestdoc(file, ticket) {
|
||||
const query = `UPDATE vn.dms SET file=?, contentType = 'image/png' WHERE id=?`;
|
||||
|
||||
await Self.rawSql(query, [file, ticket]);
|
||||
const models = Self.app.models;
|
||||
models.Dms.updateOne({
|
||||
where: {
|
||||
id: ticket
|
||||
},
|
||||
file: file,
|
||||
contentType: 'image/png'
|
||||
});
|
||||
}
|
||||
|
||||
Self.saveSign = async(ctx, signContent, tickets, signedTime, addressFk) => {
|
||||
Self.saveSign = async(ctx, signContent, tickets, signedTime) => {
|
||||
const models = Self.app.models;
|
||||
let tx = await Self.beginTransaction({});
|
||||
try {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
@ -138,10 +156,12 @@ module.exports = Self => {
|
|||
let image = null;
|
||||
|
||||
for (let i = 0; i < tickets.length; i++) {
|
||||
const call = `SELECT alertLevel FROM vn.ticketState WHERE ticketFk = ${tickets[i]}`;
|
||||
const result = await Self.rawSql(call);
|
||||
|
||||
alertLevel = result[0].alertLevel;
|
||||
const alertLevel = await models.TicketState.findOne({
|
||||
where: {
|
||||
ticketFk: tickets[i]
|
||||
},
|
||||
fields: ['alertLevel']
|
||||
});
|
||||
|
||||
signedTime ? signedTime != undefined : signedTime = new Date();
|
||||
|
||||
|
@ -161,7 +181,7 @@ module.exports = Self => {
|
|||
|
||||
fileName = `${id}.png`;
|
||||
image = `${dir}/${fileName}`;
|
||||
}
|
||||
} else
|
||||
|
||||
if (image != null) {
|
||||
if (!fs.existsSync(dir))
|
||||
|
|
Loading…
Reference in New Issue