Invoice list should display according to the selected date range in Collection module.

This commit is contained in:
Kartik Sharma 2025-11-14 15:39:40 +05:30
parent 314dd67118
commit b399977946
4 changed files with 180 additions and 119 deletions

View File

@ -29,14 +29,14 @@ const CollectionList = ({ fromDate, toDate, isPending, searchString }) => {
const searchDebounce = useDebounce(searchString, 500); const searchDebounce = useDebounce(searchString, 500);
const { data, isLoading, isError, error } = useCollections( const { data, isLoading, isError, error } = useCollections(
ITEMS_PER_PAGE, selectedProject,
currentPage, searchDebounce,
localToUtc(fromDate), localToUtc(fromDate),
localToUtc(toDate), localToUtc(toDate),
isPending, ITEMS_PER_PAGE,
currentPage,
true, true,
selectedProject, isPending
searchDebounce
); );
const { setProcessedPayment, setAddPayment, setViewCollection } = const { setProcessedPayment, setAddPayment, setViewCollection } =
useCollectionContext(); useCollectionContext();

View File

@ -2,39 +2,80 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { CollectionRepository } from "../repositories/ColllectionRepository"; import { CollectionRepository } from "../repositories/ColllectionRepository";
import showToast from "../services/toastService"; import showToast from "../services/toastService";
// export const useCollections = (
// pageSize,
// pageNumber,
// fromDate,
// toDate,
// isPending,
// isActive,
// projectId,
// searchString
// ) => {
// return useQuery({
// queryKey: [
// "collections",
// pageSize,
// pageNumber,
// fromDate,
// toDate,
// isPending,
// isActive,
// projectId,
// searchString,
// ],
// queryFn: async () => {
// const response = await CollectionRepository.getCollections(
// pageSize,
// pageNumber,
// fromDate,
// toDate,
// isPending,
// isActive,
// projectId,
// searchString
// );
// return response.data;
// },
// keepPreviousData: true,
// staleTime: 1000 * 60 * 1,
// });
// };
export const useCollections = ( export const useCollections = (
pageSize, projectId,
pageNumber, searchString,
fromDate, fromDate,
toDate, toDate,
isPending, pageSize,
pageNumber,
isActive, isActive,
projectId, isPending
searchString
) => { ) => {
return useQuery({ return useQuery({
queryKey: [ queryKey: [
"collections", "collections",
pageSize,
pageNumber,
fromDate,
toDate,
isPending,
isActive,
projectId, projectId,
searchString, searchString,
fromDate,
toDate,
pageSize,
pageNumber,
isActive,
isPending,
], ],
queryFn: async () => { queryFn: async () => {
const response = await CollectionRepository.getCollections( const response = await CollectionRepository.getCollections(
pageSize, projectId,
pageNumber, searchString,
fromDate, fromDate,
toDate, toDate,
isPending, pageSize,
pageNumber,
isActive, isActive,
projectId, isPending
searchString
); );
return response.data; return response.data;
}, },
@ -44,7 +85,6 @@ export const useCollections = (
}); });
}; };
export const useCollection = (collectionId) => { export const useCollection = (collectionId) => {
return useQuery({ return useQuery({
queryKey: ["collection", collectionId], queryKey: ["collection", collectionId],

View File

@ -117,7 +117,8 @@ const CollectionPage = () => {
{/* Left side: Date Picker + Show Pending (stacked on mobile) */} {/* Left side: Date Picker + Show Pending (stacked on mobile) */}
<div className="col-12 col-md-6 d-flex flex-column flex-md-row flex-wrap align-items-start align-md-items-center gap-2 gap-md-3 mb-3 mb-md-0"> <div className="col-12 col-md-6 d-flex flex-column flex-md-row flex-wrap align-items-start align-md-items-center gap-2 gap-md-3 mb-3 mb-md-0">
<FormProvider {...methods}> <FormProvider {...methods}>
<DateRangePicker1 howManyDay={180} /> <DateRangePicker1 howManyDay={180} startField="fromDate"
endField="toDate" />
</FormProvider> </FormProvider>
<div className="form-check form-switch d-flex align-items-center mt-1"> <div className="form-check form-switch d-flex align-items-center mt-1">

View File

@ -7,17 +7,37 @@ export const CollectionRepository = {
updateCollection: (id, data) => { updateCollection: (id, data) => {
api.put(`/api/Collection/invoice/edit/${id}`, data) api.put(`/api/Collection/invoice/edit/${id}`, data)
}, },
getCollections: (pageSize, pageNumber,fromDate,toDate, isPending,isActive,projectId, searchString) => { // getCollections: (pageSize, pageNumber,fromDate,toDate, isPending,isActive,projectId, searchString) => {
let url = `/api/Collection/invoice/list?pageSize=${pageSize}&pageNumber=${pageNumber}&isPending=${isPending}&isActive=${isActive}&searchString=${searchString}`; // let url = `/api/Collection/invoice/list?pageSize=${pageSize}&pageNumber=${pageNumber}&isPending=${isPending}&isActive=${isActive}&searchString=${searchString}`;
// const params = [];
// if (fromDate) params.push(`fromDate=${fromDate}`);
// if (toDate) params.push(`toDate=${toDate}`);
// if(projectId) params.push(`projectId=${projectId}`)
// if (params.length > 0) {
// url += `&${params.join("&")}`;
// }
// return api.get(url);
// },
getCollections: (projectId, searchString, fromDate, toDate, pageSize, pageNumber, isActive, isPending) => {
let url = `/api/Collection/invoice/list`;
const params = []; const params = [];
if (fromDate) params.push(`fromDate=${fromDate}`);
if (toDate) params.push(`toDate=${toDate}`); if (projectId) params.push(`projectId=${projectId}`);
if(projectId) params.push(`projectId=${projectId}`) if (searchString) params.push(`search=${searchString}`);
if (fromDate) params.push(`dateFrom=${fromDate}`);
if (toDate) params.push(`dateTo=${toDate}`);
if (pageSize) params.push(`pageSize=${pageSize}`);
if (pageNumber) params.push(`pageNumber=${pageNumber}`);
if (isActive) params.push(`isActive=${isActive}`);
if (isPending) params.push(`isPending=${isPending}`);
if (params.length > 0) { if (params.length > 0) {
url += `&${params.join("&")}`; url += "?" + params.join("&");
} }
return api.get(url); return api.get(url);
}, },