Compare commits
32 Commits
7b1362a9d5
...
1a5e473656
Author | SHA1 | Date |
---|---|---|
Robert Ferrús | 1a5e473656 | |
Carlos Satorres | 56cba385cf | |
Carlos Satorres | aad616ff83 | |
Carlos Satorres | f8c83c8f68 | |
Carlos Satorres | c3ffb31348 | |
Jorge Penadés | b76b1c6d50 | |
Jorge Penadés | 2f77359892 | |
Pablo Natek | 69a34ab0fa | |
Pablo Natek | 1731af13ea | |
Pablo Natek | e479873547 | |
Pablo Natek | 92f699aac3 | |
Pablo Natek | e38c061deb | |
Jon Elias | d75a032d75 | |
Jon Elias | 158f701f1e | |
Carlos Satorres | bf0cc687e1 | |
Carlos Satorres | eea09a9d4a | |
Carlos Satorres | 19fbb836a6 | |
Carlos Satorres | b88dc1c70f | |
Carlos Satorres | b8e782d3a5 | |
Jon Elias | 9e9773578a | |
Jon Elias | f68584b3fa | |
Jorge Penadés | 8ca097d4a9 | |
Jorge Penadés | d57f4fc44a | |
Jorge Penadés | 6f8a005726 | |
Jon Elias | e334152acc | |
Jorge Penadés | 6d4c71d465 | |
Jorge Penadés | a35208d903 | |
Jorge Penadés | ccf9dbde8e | |
Jorge Penadés | 32756dabae | |
Jon Elias | 07849ebeb8 | |
Jon Elias | 4ee6a46bd5 | |
Jorge Penadés | 770c604d6b |
|
@ -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;
|
||||
|
|
|
@ -85,16 +85,11 @@ module.exports = Self => {
|
|||
const updatedClaim = await claim.updateAttributes(args, myOptions);
|
||||
|
||||
const salesPerson = claim.client().salesPersonUser();
|
||||
if (salesPerson) {
|
||||
if (changedPickup && updatedClaim.pickup)
|
||||
await notifyPickUp(ctx, salesPerson.id, claim);
|
||||
|
||||
if (args.claimStateFk) {
|
||||
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
|
||||
await notifyStateChange(ctx, salesPerson.id, claim, newState.description);
|
||||
if (newState.code == 'canceled')
|
||||
await notifyStateChange(ctx, claim.workerFk, claim, newState.description);
|
||||
}
|
||||
if (salesPerson && args.claimStateFk) {
|
||||
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
|
||||
await notifyStateChange(ctx, salesPerson.id, claim, newState.description);
|
||||
if (newState.code == 'canceled')
|
||||
await notifyStateChange(ctx, claim.workerFk, claim, newState.description);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
@ -119,18 +114,4 @@ module.exports = Self => {
|
|||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, workerId, message);
|
||||
}
|
||||
|
||||
async function notifyPickUp(ctx, workerId, claim) {
|
||||
const models = Self.app.models;
|
||||
const url = await models.Url.getUrl();
|
||||
const $t = ctx.req.__; // $translate
|
||||
|
||||
const message = $t('Claim will be picked', {
|
||||
claimId: claim.id,
|
||||
clientName: claim.client().name,
|
||||
claimUrl: `${url}claim/${claim.id}/summary`,
|
||||
claimPickup: $t(claim.pickup)
|
||||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, workerId, message);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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