update method search

This commit is contained in:
wayanrivan
2025-05-06 17:45:25 +07:00
parent 4d0d6fd039
commit f0ed1cebe6
4 changed files with 162 additions and 61 deletions

View File

@ -270,19 +270,49 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
});
}
// ✅ Declare formattedFilter early
const formattedFilter: any = {
"Transactions.transaction_date": {
from: `${startdate} 00:00:00`,
to: `${enddate} 23:59:59`
}
};
if (transactioncode) {
formattedFilter["$or"] = [
{ "Transactions.code": { like: `%${transactioncode}%` } },
{ "Transactions.msisdn": { like: `${transactioncode}` } },
{ "origin_customer.fullname": { like: `${transactioncode}` } }
];
if (Array.isArray(filter)) {
let searchType = '';
let codeValue = '';
// Ambil code dan searchtype dulu
filter.forEach((f: any) => {
if (f.id === 'code' && f.value) {
codeValue = f.value;
}
if (f.id === 'searchtype' && f.value) {
searchType = f.value;
}
if (f.id === 'transaction_date' && f.value?.from && f.value?.to) {
startdate = f.value.from;
enddate = f.value.to;
formattedFilter["Transactions.transaction_date"] = {
from: `${startdate} 00:00:00`,
to: `${enddate} 23:59:59`
};
}
});
// Terapkan berdasarkan searchtype + code
if (searchType && codeValue) {
if (searchType === "msisdn") {
formattedFilter["origin_customer.msisdn"] = { like: `%${codeValue}%` };
} else if (searchType === "fullname") {
formattedFilter["origin_customer.fullname"] = { like: `%${codeValue}%` };
} else if (searchType === "trxid") {
formattedFilter["Transactions.code"] = { like: `%${codeValue}%` };
}
}
}
// Handle approval status filter