8144-devToTest_2444 #3137
|
@ -6,25 +6,27 @@ BLOCK1: BEGIN
|
|||
DECLARE vShipped DATE;
|
||||
DECLARE vPreviousShipped DATE;
|
||||
DECLARE vDone boolean;
|
||||
DECLARE cur cursor for
|
||||
|
||||
SELECT clientFk, firstShipped
|
||||
FROM bs.clientNewBorn;
|
||||
|
||||
DECLARE cur CURSOR FOR
|
||||
SELECT clientFk, firstShipped
|
||||
FROM bs.clientNewBorn;
|
||||
|
||||
DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
SET vDone := FALSE;
|
||||
|
||||
DELETE FROM bs.clientNewBorn WHERE isModified = FALSE;
|
||||
|
||||
INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped)
|
||||
SELECT c.id, MAX(t.shipped), MAX(t.shipped)
|
||||
FROM vn.client c
|
||||
JOIN vn.ticket t on t.clientFk = c.id
|
||||
LEFT JOIN clientNewBorn cb on cb.clientFk = c.id
|
||||
WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null
|
||||
GROUP BY c.id;
|
||||
INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped)
|
||||
SELECT c.id, DATE(MAX(t.shipped)), DATE(MAX(t.shipped))
|
||||
FROM vn.client c
|
||||
JOIN vn.ticket t ON t.clientFk = c.id
|
||||
LEFT JOIN clientNewBorn cb ON cb.clientFk = c.id
|
||||
WHERE t.shipped BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR
|
||||
AND util.VN_CURDATE()
|
||||
AND cb.isModified IS NULL
|
||||
GROUP BY c.id;
|
||||
|
||||
OPEN cur;
|
||||
|
||||
LOOP1: LOOP
|
||||
SET vDone := FALSE;
|
||||
FETCH cur INTO vClientFk, vShipped;
|
||||
|
|
|
@ -74,7 +74,8 @@ module.exports = Self => {
|
|||
pm.name payMethod,
|
||||
r.finished IS NULL hasRecovery,
|
||||
dp.id departmentFk,
|
||||
dp.name departmentName
|
||||
dp.name departmentName,
|
||||
dp.notificationEmail departmentEmail
|
||||
FROM defaulter d
|
||||
JOIN client c ON c.id = d.clientFk
|
||||
JOIN country cn ON cn.id = c.countryFk
|
||||
|
|
|
@ -47,7 +47,7 @@ module.exports = Self => {
|
|||
await models.Mail.create({
|
||||
subject: $t('Comment added to client', {clientFk: defaulter.clientFk}),
|
||||
body: body,
|
||||
receiver: `${defaulter.salesPersonName}@verdnatura.es`,
|
||||
receiver: `${defaulter.departmentEmail}`,
|
||||
replyTo: `${user.name}@verdnatura.es`
|
||||
}, myOptions);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,11 @@ module.exports = Self => {
|
|||
arg: 'state',
|
||||
type: 'string',
|
||||
description: `Search request by request state`
|
||||
},
|
||||
{
|
||||
arg: 'myTeam',
|
||||
type: 'boolean',
|
||||
description: `Team partners`
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
|
@ -75,6 +80,8 @@ module.exports = Self => {
|
|||
const conn = Self.dataSource.connector;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {};
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -82,6 +89,21 @@ module.exports = Self => {
|
|||
if (ctx.args.mine)
|
||||
ctx.args.attenderFk = userId;
|
||||
|
||||
const teamMembersId = [];
|
||||
if (args.myTeam != null) {
|
||||
const worker = await models.Worker.findById(userId, {
|
||||
include: {
|
||||
relation: 'collegues'
|
||||
}
|
||||
}, myOptions);
|
||||
const collegues = worker.collegues() || [];
|
||||
for (let collegue of collegues)
|
||||
teamMembersId.push(collegue.collegueFk);
|
||||
|
||||
if (teamMembersId.length == 0)
|
||||
teamMembersId.push(userId);
|
||||
}
|
||||
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
|
@ -113,6 +135,11 @@ module.exports = Self => {
|
|||
return {'w.id': value};
|
||||
case 'salesPersonFk':
|
||||
return {'c.salesPersonFk': value};
|
||||
case 'myTeam':
|
||||
if (value)
|
||||
return {'tr.requesterFk': {inq: teamMembersId}};
|
||||
else
|
||||
return {'tr.requesterFk': {nin: teamMembersId}};
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -49,9 +49,12 @@ module.exports = Self => {
|
|||
where: {originalTicketFk: id}
|
||||
}, myOptions);
|
||||
|
||||
const hasRefund = !!ticketRefunds?.length;
|
||||
|
||||
const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted);
|
||||
|
||||
if (ticketRefunds?.length && !allDeleted) {
|
||||
if (!hasRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions);
|
||||
if (hasRefund && !allDeleted) {
|
||||
const notDeleted = [];
|
||||
for (const refund of ticketRefunds)
|
||||
if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id);
|
||||
|
|
|
@ -113,5 +113,27 @@ describe('ticket setDeleted()', () => {
|
|||
|
||||
expect(error.message).not.toContain('Tickets with associated refunds');
|
||||
});
|
||||
|
||||
it('should delete the refund - original ticket relation', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const ticketId = 24;
|
||||
const refundTicket = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options);
|
||||
|
||||
expect(refundTicket).toBeTruthy();
|
||||
|
||||
await models.Ticket.setDeleted(ctx, ticketId, options);
|
||||
const removedRefundTicket = await models.TicketRefund.findOne({
|
||||
where: {refundTicketFk: ticketId}},
|
||||
options);
|
||||
|
||||
expect(removedRefundTicket).toBeNull();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue