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