From 12316fb44bf246ee062becd5bf32c5f668120129 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 Jul 2024 07:32:42 +0200 Subject: [PATCH] fix(client_filter): add recovery --- .../client/back/methods/defaulter/filter.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index ac9504ec2..9f2d4b340 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -60,7 +60,7 @@ module.exports = Self => { DISTINCT c.id clientFk, c.name clientName, c.salesPersonFk, - c.businessTypeFk, + c.businessTypeFk = 'worker' isWorker, u.name salesPersonName, d.amount, co.created, @@ -71,14 +71,19 @@ module.exports = Self => { d.defaulterSinced, cn.name country, c.countryFk, - pm.name payMethod - FROM vn.defaulter d - JOIN vn.client c ON c.id = d.clientFk - JOIN vn.country cn ON cn.id = c.countryFk - JOIN vn.payMethod pm ON pm.id = c.payMethodFk - LEFT JOIN vn.clientObservation co ON co.clientFk = c.id + pm.name payMethod, + r.finished IS NULL hasRecovery + FROM defaulter d + JOIN client c ON c.id = d.clientFk + JOIN country cn ON cn.id = c.countryFk + JOIN payMethod pm ON pm.id = c.payMethodFk + LEFT JOIN clientObservation co ON co.clientFk = c.id LEFT JOIN account.user u ON u.id = c.salesPersonFk LEFT JOIN account.user uw ON uw.id = co.workerFk + LEFT JOIN ( + SELECT MAX(started), clientFk, finished + FROM recovery + ) r ON r.clientFk = c.id WHERE d.created = ? AND d.amount > 0