update filter
This commit is contained in:
@ -159,12 +159,12 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => {
|
||||
|
||||
|
||||
switch (row.status) {
|
||||
case 'C': return 'COMPLETE';
|
||||
case 'F': return 'FAILED';
|
||||
case 'O': return 'ON PROCESS';
|
||||
case "P" : return 'PENDING';
|
||||
case "P": return 'PENDING';
|
||||
case 'R': return 'ROLLBACK';
|
||||
case 'S': return 'REVERSAL';
|
||||
default: return 'UNKNOWN';
|
||||
@ -276,40 +276,16 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
|
||||
let enddate = today.toISOString().split('T')[0];
|
||||
let transactioncode = '';
|
||||
let approvalstatus = '';
|
||||
let searchType = '';
|
||||
let codeValue = '';
|
||||
|
||||
if (Array.isArray(filter)) {
|
||||
filter.forEach((f: any) => {
|
||||
// console.log(f.id);
|
||||
if (f.id === 'transaction_date' && f.value?.from && f.value?.to) {
|
||||
startdate = f.value.from;
|
||||
enddate = f.value.to;
|
||||
}
|
||||
|
||||
if (f.id === 'code' && f.value) {
|
||||
transactioncode = f.value;
|
||||
}
|
||||
|
||||
if (f.id === 'status_approve' && f.value) {
|
||||
approvalstatus = f.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ✅ Declare formattedFilter early
|
||||
const formattedFilter: any = {
|
||||
"Transactions.transaction_date": {
|
||||
from: `${startdate} 00:00:00`,
|
||||
to: `${enddate} 23:59:59`
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
@ -318,29 +294,35 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
|
||||
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`
|
||||
};
|
||||
if (f.id === 'status_approve' && f.value) {
|
||||
approvalstatus = f.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Terapkan berdasarkan searchtype + code
|
||||
if (searchType && codeValue) {
|
||||
if (searchType === "msisdn") {
|
||||
formattedFilter["Transactions.origin_msisdn"] = { like: `%${codeValue}%` };
|
||||
} else if (searchType === "fullname") {
|
||||
formattedFilter["Transactions.origin_name"] = { like: `%${codeValue}%` };
|
||||
} else if (searchType === "trxid") {
|
||||
formattedFilter["Transactions.code"] = { like: `%${codeValue}%` };
|
||||
}
|
||||
// 💡 Build formattedFilter only after values are finalized
|
||||
const formattedFilter: any = {};
|
||||
|
||||
// ✅ Only add transaction_date filter if searchType is NOT filled
|
||||
if (!searchType) {
|
||||
formattedFilter["Transactions.transaction_date"] = {
|
||||
from: `${startdate} 00:00:00`,
|
||||
to: `${enddate} 23:59:59`
|
||||
};
|
||||
}
|
||||
|
||||
// ✅ Apply searchType filters if both searchType and codeValue exist
|
||||
if (searchType && codeValue) {
|
||||
if (searchType === "msisdn") {
|
||||
formattedFilter["Transactions.origin_msisdn"] = { like: `%${codeValue}%` };
|
||||
} else if (searchType === "fullname") {
|
||||
formattedFilter["Transactions.origin_name"] = { like: `%${codeValue}%` };
|
||||
} else if (searchType === "trxid") {
|
||||
formattedFilter["Transactions.code"] = { like: `%${codeValue}%` };
|
||||
}
|
||||
}
|
||||
|
||||
// Handle approval status filter
|
||||
// ✅ Handle approval status
|
||||
formattedFilter["Transactions.status_approve"] = approvalstatus
|
||||
? approvalstatus
|
||||
: { in: ["W", "Y", "N"] };
|
||||
@ -365,7 +347,7 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction', error);
|
||||
return { data: [], totalCount: 0 }; // Fail-safe fallback
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -300,24 +300,15 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const today = new Date();
|
||||
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||
|
||||
let startdate = firstDayOfMonth.toISOString().split('T')[0];
|
||||
let enddate = today.toISOString().split('T')[0];
|
||||
let startdate: string | undefined;
|
||||
let enddate: string | undefined;
|
||||
let transactioncode = '';
|
||||
let type = '';
|
||||
|
||||
// ✅ Declare formattedFilter early
|
||||
const formattedFilter: any = {
|
||||
"Transactions.transaction_date": {
|
||||
from: `${startdate} 00:00:00`,
|
||||
to: `${enddate} 23:59:59`
|
||||
}
|
||||
};
|
||||
let searchType = '';
|
||||
let codeValue = '';
|
||||
|
||||
if (Array.isArray(filter)) {
|
||||
let searchType = '';
|
||||
let codeValue = '';
|
||||
|
||||
// Ambil code dan searchtype dulu
|
||||
// Ambil semua value dari filter terlebih dahulu
|
||||
filter.forEach((f: any) => {
|
||||
if (f.id === 'code' && f.value) {
|
||||
codeValue = f.value;
|
||||
@ -327,21 +318,40 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
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`
|
||||
// };
|
||||
// }
|
||||
if (f.id === 'transaction_date' && f.value?.from && f.value?.to) {
|
||||
startdate = f.value.from;
|
||||
enddate = f.value.to;
|
||||
}
|
||||
|
||||
if (f.id === 'kind' && f.value) {
|
||||
type = f.value;
|
||||
}
|
||||
});
|
||||
|
||||
// Terapkan berdasarkan searchtype + code
|
||||
// Kalau tidak ada searchType, baru pakai tanggal
|
||||
if (!searchType) {
|
||||
if (!startdate || !enddate) {
|
||||
startdate = firstDayOfMonth.toISOString().split('T')[0];
|
||||
enddate = today.toISOString().split('T')[0];
|
||||
}
|
||||
} else {
|
||||
// Kosongkan supaya tidak digunakan di bawah
|
||||
startdate = undefined;
|
||||
enddate = undefined;
|
||||
}
|
||||
|
||||
// Build formattedFilter setelah semua nilai diketahui
|
||||
const formattedFilter: any = {};
|
||||
|
||||
// Tambahkan filter tanggal HANYA jika tidak ada searchType
|
||||
if (startdate && enddate) {
|
||||
formattedFilter["Transactions.transaction_date"] = {
|
||||
from: `${startdate} 00:00:00`,
|
||||
to: `${enddate} 23:59:59`
|
||||
};
|
||||
}
|
||||
|
||||
// Tambahkan filter berdasarkan searchType
|
||||
if (searchType && codeValue) {
|
||||
if (searchType === "msisdn") {
|
||||
formattedFilter["origin_customer.msisdn"] = { like: `%${codeValue}%` };
|
||||
@ -351,29 +361,31 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
formattedFilter["Transactions.code"] = { like: `%${codeValue}%` };
|
||||
}
|
||||
}
|
||||
|
||||
// Tambahkan filter jenis transaksi jika ada
|
||||
if (type) {
|
||||
formattedFilter["Transactions.kind"] = type;
|
||||
}
|
||||
|
||||
const response = await GetData(`${API_URL}/transaction/history`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: "Transactions.created_at",
|
||||
order_direction: 'DESC',
|
||||
filter: JSON.stringify(formattedFilter)
|
||||
});
|
||||
|
||||
if (!response || !response.data) {
|
||||
console.warn('No data received:', response);
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
|
||||
setTransaction(response.data.list);
|
||||
return { data: response.data.list, totalCount: response.data.total_count };
|
||||
}
|
||||
|
||||
|
||||
if (type) {
|
||||
formattedFilter["Transactions.kind"] = type;
|
||||
}
|
||||
|
||||
const response = await GetData(`${API_URL}/transaction/history`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: "Transactions.created_at",
|
||||
order_direction: 'DESC',
|
||||
filter: JSON.stringify(formattedFilter)
|
||||
});
|
||||
|
||||
if (!response || !response.data) {
|
||||
console.warn('No data received:', response);
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
|
||||
setTransaction(response.data.list);
|
||||
return { data: response.data.list, totalCount: response.data.total_count };
|
||||
return { data: [], totalCount: 0 };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction', error);
|
||||
@ -382,6 +394,7 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<ManageTransactionContext.Provider
|
||||
value={{
|
||||
|
||||
Reference in New Issue
Block a user