From 8080b89c4624798b0ceea68d1d7f10df6da7dde4 Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Wed, 4 Feb 2026 11:27:29 +0700 Subject: [PATCH] modify query getTopUpCashlessInternal and add indexing --- application/modules/cashin/cahsin.model.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/application/modules/cashin/cahsin.model.js b/application/modules/cashin/cahsin.model.js index 27dd041..912643c 100644 --- a/application/modules/cashin/cahsin.model.js +++ b/application/modules/cashin/cahsin.model.js @@ -334,7 +334,12 @@ const getSalesKMT = async (trx, code, date, invoice) => { .where('tdpr.c_status', '=', 'S') .whereNotNull('tdsi.c_return_sap') .whereRaw( - `tdskm.c_sales_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)` + `NOT EXISTS ( + SELECT 1 + FROM payment.t_d_cash_in_detail cid + WHERE cid.c_reservation_no = tdskm.c_sales_no + AND cid.b_reversal IS NOT TRUE + )` ); return res; @@ -398,7 +403,12 @@ const getTopUpCashlessInternal = async (trx, code, date, invoice) => { .where('tdpr.c_status', '=', 'S') .whereNotNull('tdsi.c_return_sap') .whereRaw( - `tdskm.c_topup_no NOT IN (SELECT c_reservation_no FROM payment.t_d_cash_in_detail WHERE b_reversal IS NOT TRUE)` + `NOT EXISTS ( + SELECT 1 + FROM payment.t_d_cash_in_detail cid + WHERE cid.c_reservation_no = tdskm.c_topup_no + AND cid.b_reversal IS NOT TRUE + )` ); return res;