mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Add filter_by option to customer payment reports
This commit is contained in:
@@ -96,8 +96,7 @@ interface CustomerPaymentExportPDFParams {
|
|||||||
// sales?: string;
|
// sales?: string;
|
||||||
start_date?: string;
|
start_date?: string;
|
||||||
end_date?: string;
|
end_date?: string;
|
||||||
// TODO: Uncomment when BE is ready
|
filter_by?: string;
|
||||||
// filter_by?: string;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { ColumnDef } from '@tanstack/react-table';
|
|||||||
import { formatCurrency, formatDate, formatNumber, cn } from '@/lib/helper';
|
import { formatCurrency, formatDate, formatNumber, cn } from '@/lib/helper';
|
||||||
import {
|
import {
|
||||||
CustomerPaymentReport,
|
CustomerPaymentReport,
|
||||||
CustomerPaymentRow,
|
|
||||||
CustomerPaymentSummary,
|
CustomerPaymentSummary,
|
||||||
} from '@/types/api/report/customer-payment';
|
} from '@/types/api/report/customer-payment';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
@@ -53,33 +52,39 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
);
|
);
|
||||||
// TODO: Uncomment when BE is ready
|
// TODO: Uncomment when BE is ready
|
||||||
// const [filterSales, setFilterSales] = useState<typeof salesOptions>([]);
|
// const [filterSales, setFilterSales] = useState<typeof salesOptions>([]);
|
||||||
const [filterSales, setFilterSales] = useState<typeof salesOptions>([]);
|
|
||||||
const [filterStartDate, setFilterStartDate] = useState('');
|
const [filterStartDate, setFilterStartDate] = useState('');
|
||||||
const [filterEndDate, setFilterEndDate] = useState('');
|
const [filterEndDate, setFilterEndDate] = useState('');
|
||||||
|
|
||||||
const filterModal = useModal();
|
const filterModal = useModal();
|
||||||
|
|
||||||
|
const dataTypeOptions = useMemo(
|
||||||
|
() => [
|
||||||
|
{ value: 'do_date', label: 'Tanggal Jual' },
|
||||||
|
{ value: 'payment_date', label: 'Tanggal Bayar' },
|
||||||
|
{ value: 'realization_date', label: 'Tanggal Realisasi' },
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const [filterByType, setFilterByType] = useState<(typeof dataTypeOptions)[0]>(
|
||||||
|
dataTypeOptions[0]
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
options: customerOptions,
|
options: customerOptions,
|
||||||
setInputValue: setCustomerInputValue,
|
setInputValue: setCustomerInputValue,
|
||||||
isLoadingOptions: isLoadingCustomers,
|
isLoadingOptions: isLoadingCustomers,
|
||||||
loadMore: loadMoreCustomers,
|
loadMore: loadMoreCustomers,
|
||||||
hasMore: hasMoreCustomers,
|
|
||||||
} = useSelect(CustomerApi.basePath, 'id', 'name', 'search');
|
} = useSelect(CustomerApi.basePath, 'id', 'name', 'search');
|
||||||
|
|
||||||
// TODO: Uncomment when BE is ready
|
// TODO: Uncomment when BE is ready
|
||||||
const {
|
// const {
|
||||||
options: salesOptions,
|
// options: salesOptions,
|
||||||
setInputValue: setSalesInputValue,
|
// setInputValue: setSalesInputValue,
|
||||||
isLoadingOptions: isLoadingSales,
|
// isLoadingOptions: isLoadingSales,
|
||||||
loadMore: loadMoreSales,
|
// loadMore: loadMoreSales,
|
||||||
hasMore: hasMoreSales,
|
// hasMore: hasMoreSales,
|
||||||
} = useSelect(UserApi.basePath, 'id', 'name', 'search');
|
// } = useSelect(UserApi.basePath, 'id', 'name', 'search');
|
||||||
|
|
||||||
const dataTypeOptions = useMemo(
|
|
||||||
() => [{ value: 'do_date', label: 'Tanggal Jual' }],
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const getPaymentStatusColor = (notes: string) => {
|
const getPaymentStatusColor = (notes: string) => {
|
||||||
const normalizedValue = notes.toLowerCase();
|
const normalizedValue = notes.toLowerCase();
|
||||||
@@ -125,10 +130,11 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
const handleResetFilters = useCallback(() => {
|
const handleResetFilters = useCallback(() => {
|
||||||
setIsSubmitted(false);
|
setIsSubmitted(false);
|
||||||
setFilterCustomer([]);
|
setFilterCustomer([]);
|
||||||
setFilterSales([]);
|
// setFilterSales([]);
|
||||||
|
setFilterByType(dataTypeOptions[0]);
|
||||||
setFilterStartDate('');
|
setFilterStartDate('');
|
||||||
setFilterEndDate('');
|
setFilterEndDate('');
|
||||||
}, []);
|
}, [dataTypeOptions]);
|
||||||
|
|
||||||
const handleApplyFilters = useCallback(() => {
|
const handleApplyFilters = useCallback(() => {
|
||||||
setIsSubmitted(true);
|
setIsSubmitted(true);
|
||||||
@@ -157,12 +163,7 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}, [
|
}, [filterStartDate, filterEndDate, filterCustomer]);
|
||||||
filterStartDate,
|
|
||||||
filterEndDate,
|
|
||||||
filterCustomer,
|
|
||||||
// filterSales,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const hasFilters = activeFiltersCount > 0;
|
const hasFilters = activeFiltersCount > 0;
|
||||||
|
|
||||||
@@ -180,7 +181,10 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
// filterSales.length > 0
|
// filterSales.length > 0
|
||||||
// ? filterSales.map((v) => String(v.value)).join(',')
|
// ? filterSales.map((v) => String(v.value)).join(',')
|
||||||
// : undefined,
|
// : undefined,
|
||||||
// filter_by: 'do_date' as const,
|
filter_by: filterByType.value as
|
||||||
|
| 'do_date'
|
||||||
|
| 'payment_date'
|
||||||
|
| 'realization_date',
|
||||||
start_date: filterStartDate || undefined,
|
start_date: filterStartDate || undefined,
|
||||||
end_date: filterEndDate || undefined,
|
end_date: filterEndDate || undefined,
|
||||||
page: currentPage,
|
page: currentPage,
|
||||||
@@ -193,8 +197,7 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
([, params]) =>
|
([, params]) =>
|
||||||
FinanceApi.getCustomerPaymentReport(
|
FinanceApi.getCustomerPaymentReport(
|
||||||
params.customer_ids,
|
params.customer_ids,
|
||||||
undefined, // TODO: Change to params.sales_id when BE is ready
|
params.filter_by,
|
||||||
undefined, // TODO: Change to params.filter_by when BE is ready
|
|
||||||
params.start_date,
|
params.start_date,
|
||||||
params.end_date,
|
params.end_date,
|
||||||
params.page,
|
params.page,
|
||||||
@@ -224,6 +227,10 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
// filterSales.length > 0
|
// filterSales.length > 0
|
||||||
// ? filterSales.map((v) => String(v.value)).join(',')
|
// ? filterSales.map((v) => String(v.value)).join(',')
|
||||||
// : undefined,
|
// : undefined,
|
||||||
|
filter_by: filterByType.value as
|
||||||
|
| 'do_date'
|
||||||
|
| 'payment_date'
|
||||||
|
| 'realization_date',
|
||||||
start_date: filterStartDate || undefined,
|
start_date: filterStartDate || undefined,
|
||||||
end_date: filterEndDate || undefined,
|
end_date: filterEndDate || undefined,
|
||||||
limit: 100,
|
limit: 100,
|
||||||
@@ -232,8 +239,7 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
|
|
||||||
const response = await FinanceApi.getCustomerPaymentReport(
|
const response = await FinanceApi.getCustomerPaymentReport(
|
||||||
params.customer_ids,
|
params.customer_ids,
|
||||||
undefined, // TODO: Change to params.sales_id when BE is ready
|
params.filter_by,
|
||||||
undefined, // TODO: Change to params.filter_by when BE is ready
|
|
||||||
params.start_date,
|
params.start_date,
|
||||||
params.end_date,
|
params.end_date,
|
||||||
params.page,
|
params.page,
|
||||||
@@ -243,7 +249,13 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
return isResponseSuccess(response)
|
return isResponseSuccess(response)
|
||||||
? (response.data as unknown as CustomerPaymentReport[])
|
? (response.data as unknown as CustomerPaymentReport[])
|
||||||
: null;
|
: null;
|
||||||
}, [filterCustomer, filterSales, filterStartDate, filterEndDate]);
|
}, [
|
||||||
|
filterCustomer,
|
||||||
|
// filterSales,
|
||||||
|
filterStartDate,
|
||||||
|
filterEndDate,
|
||||||
|
filterByType,
|
||||||
|
]);
|
||||||
|
|
||||||
// ===== EXPORT HANDLERS =====
|
// ===== EXPORT HANDLERS =====
|
||||||
const handleExportExcel = useCallback(async () => {
|
const handleExportExcel = useCallback(async () => {
|
||||||
@@ -297,8 +309,10 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
// : undefined,
|
// : undefined,
|
||||||
start_date: filterStartDate || undefined,
|
start_date: filterStartDate || undefined,
|
||||||
end_date: filterEndDate || undefined,
|
end_date: filterEndDate || undefined,
|
||||||
// TODO: Uncomment when BE is ready
|
filter_by: filterByType.value as
|
||||||
// filter_by: 'do_date' as const,
|
| 'do_date'
|
||||||
|
| 'payment_date'
|
||||||
|
| 'realization_date',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
toast.success('PDF berhasil dibuat dan diunduh.');
|
toast.success('PDF berhasil dibuat dan diunduh.');
|
||||||
@@ -406,7 +420,7 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
footer: () => <div className='font-semibold text-gray-900'>Total</div>,
|
footer: () => <div className='font-semibold text-gray-900'>Total</div>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'do_date_or_payment_date',
|
id: 'trans_date',
|
||||||
header: 'Tanggal Jual/Bayar',
|
header: 'Tanggal Jual/Bayar',
|
||||||
accessorKey: 'trans_date',
|
accessorKey: 'trans_date',
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
@@ -864,17 +878,20 @@ const CustomerPaymentTab = ({ tabId }: CustomerPaymentTabProps) => {
|
|||||||
/>
|
/>
|
||||||
</div> */}
|
</div> */}
|
||||||
|
|
||||||
{/* TODO: Uncomment when BE is ready */}
|
<div>
|
||||||
{/* <div>
|
<SelectInput
|
||||||
<SelectInput
|
label='Filter Berdasarkan'
|
||||||
label='Filter Berdasarkan'
|
placeholder='Pilih Filter Berdasarkan'
|
||||||
placeholder='Pilih Filter Berdasarkan'
|
options={dataTypeOptions}
|
||||||
options={dataTypeOptions}
|
value={filterByType}
|
||||||
value={dataTypeOptions[0]}
|
onChange={(val) => {
|
||||||
isDisabled={true}
|
if (val && !Array.isArray(val)) {
|
||||||
className={{ wrapper: 'w-full' }}
|
setFilterByType(val);
|
||||||
/>
|
}
|
||||||
</div> */}
|
}}
|
||||||
|
className={{ wrapper: 'w-full' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Action Buttons */}
|
{/* Action Buttons */}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ export class FinanceApiService extends BaseApiService<
|
|||||||
customer_ids?: string,
|
customer_ids?: string,
|
||||||
// TODO: Uncomment when BE is ready
|
// TODO: Uncomment when BE is ready
|
||||||
// sales_id?: string,
|
// sales_id?: string,
|
||||||
// filter_by?: 'do_date',
|
filter_by?: 'do_date' | 'payment_date' | 'realization_date',
|
||||||
sales_id?: string,
|
|
||||||
filter_by?: 'do_date' | undefined,
|
|
||||||
start_date?: string,
|
start_date?: string,
|
||||||
end_date?: string,
|
end_date?: string,
|
||||||
page?: number,
|
page?: number,
|
||||||
@@ -31,7 +29,7 @@ export class FinanceApiService extends BaseApiService<
|
|||||||
customer_ids: customer_ids,
|
customer_ids: customer_ids,
|
||||||
// TODO: Uncomment when BE is ready
|
// TODO: Uncomment when BE is ready
|
||||||
// sales_id: sales_id,
|
// sales_id: sales_id,
|
||||||
// filter_by: filter_by,
|
filter_by: filter_by,
|
||||||
start_date: start_date,
|
start_date: start_date,
|
||||||
end_date: end_date,
|
end_date: end_date,
|
||||||
page: page,
|
page: page,
|
||||||
|
|||||||
Reference in New Issue
Block a user