update method search
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user