-
+ No details found
+ {/* Try adjusting your search or filter to find what you're looking for.
*/}
+
+ ) : (
+ {
onPageSizeChange: handlePageSizeChange,
}}
renderCell={(value, ri, ci) => {
- if (ci === 3) {
- return {value};
+ if (ci === 5) { // Status column
+ return {formatStatus(filteredRows[ri]?.status)};
}
- if (ci === 5) {
+ if (ci === 6) {
const submission = filteredRows[ri];
const disabled = !submission;
return (
@@ -536,7 +551,8 @@ const History = () => {
}
return value;
}}
- />
+ />
+ )}
diff --git a/ipi-survey-platform/src/pages/Overview/Overview.jsx b/ipi-survey-platform/src/pages/Overview/Overview.jsx
index 7866374..8120201 100644
--- a/ipi-survey-platform/src/pages/Overview/Overview.jsx
+++ b/ipi-survey-platform/src/pages/Overview/Overview.jsx
@@ -1,7 +1,7 @@
// src/pages/Overview/Overview.jsx
import React, { useState, useEffect, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
-import { getSubmissions } from '@/services/submissions/submissionService';
+import { getSubmissions, getSubmissionHistoryByEstablishment } from '@/services/submissions/submissionService';
import HeaderBar from '@/components/layout/HeaderBar';
import Table from '@/components/common/Table';
import DetailedOverview from '@/components/overview/DetailedOverview';
@@ -29,6 +29,7 @@ const Overview = () => {
const [submissions, setSubmissions] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
+ const establishmentId = 41; // You might want to get this from your auth context or props
const [pagination, setPagination] = useState({
currentPage: 1,
pageSize: 10,
@@ -41,10 +42,11 @@ const Overview = () => {
const fetchSubmissions = async () => {
try {
setLoading(true);
- const response = await getSubmissions(1, 1000); // Get all records
- setSubmissions(response.data);
+ // Use getSubmissionHistoryByEstablishment instead of getSubmissions
+ const response = await getSubmissionHistoryByEstablishment(establishmentId);
+ setSubmissions(response.data || []);
} catch (err) {
- setError('Failed to load submissions');
+ setError('Failed to load submission history');
console.error('Error:', err);
} finally {
setLoading(false);
@@ -52,7 +54,7 @@ const Overview = () => {
};
fetchSubmissions();
- }, []);
+ }, [establishmentId]);
const filteredRows = React.useMemo(() => {
const normalizedTerm = searchTerm.trim().toLowerCase();
@@ -91,7 +93,7 @@ const Overview = () => {
`${record.quarter} ${record.year}`,
10, // Always show 10 for Total Products
record.product_count || 0, // Show actual submitted products count
- `-`, // Total cost not in API
+ record.total_cost !== undefined ? record.total_cost : '-', // Show total cost from API or '-' if not available
record.status,
formatDate(record.created_at),
'View Details',
@@ -116,7 +118,7 @@ const Overview = () => {
const downloadCsv = React.useCallback(() => {
if (!filteredRows.length) return;
- const headers = ['Year', 'Quarter', 'Submission Window', 'Total Products', 'Products Submitted', 'Total Cost (AED)', 'Status', 'Date Submitted'];
+ const headers = ['Year', 'Quarter', 'Submission Window', 'Total Products', 'Products Submitted', 'Total Cost (AED)', 'Status', 'Date Submitted', 'Action'];
const csvRows = [headers.join(',')];
filteredRows.forEach((record) => {
@@ -126,7 +128,7 @@ const Overview = () => {
`${record.quarter} ${record.year}`,
10, // Always show 10 for Total Products in CSV
record.product_count || 0, // Show actual submitted products count
- '-', // Total cost not in API
+ record.total_cost !== undefined ? record.total_cost : '-', // Show total cost from API or '-' if not available
record.status,
formatDate(record.created_at)
].map((value) => `"${String(value).replace(/"/g, '""')}"`).join(','));
diff --git a/ipi-survey-platform/src/services/submissions/submissionService.js b/ipi-survey-platform/src/services/submissions/submissionService.js
index 9c929a5..e85b5cd 100644
--- a/ipi-survey-platform/src/services/submissions/submissionService.js
+++ b/ipi-survey-platform/src/services/submissions/submissionService.js
@@ -2,7 +2,7 @@ import { getRequest, postRequest } from '@/services/api/CommonService';
import resolveEstablishmentId from '@/services/utils/establishment';
const endpoint = '/submissions';
-const QUARTER_PERIODS_ENDPOINT = 'https://ipi.venbait.in/api/getQuarterPeriods';
+const QUARTER_PERIODS_ENDPOINT = '/getQuarterPeriods';
// Add this new function to fetch submissions with pagination
export const getSubmissions = async (page = 1, limit = 100, config = {}) => {
@@ -68,7 +68,7 @@ export const getQuarterPeriods = async (currentYear, currentQuarter) => {
export const getPreviousForecastData = async (establishmentId, quarter, year, productId) => {
try {
const response = await getRequest(
- `https://ipi.venbait.in/api/submissions/getPreviousForecastData`,
+ '/submissions/getPreviousForecastData',
{
params: {
establishment_id: establishmentId,
@@ -87,11 +87,28 @@ export const getPreviousForecastData = async (establishmentId, quarter, year, pr
}
};
+export const getSubmissionHistoryByEstablishment = async (establishmentId, config = {}) => {
+ try {
+ if (!establishmentId) {
+ throw new Error('Establishment ID is required to fetch submission history');
+ }
+ const response = await getRequest(
+ `/submissions/history/${establishmentId}`,
+ config
+ );
+ return response.data;
+ } catch (error) {
+ console.error('Error fetching submission history by establishment ID:', error);
+ throw error;
+ }
+};
+
export default {
getSubmissions,
submitSurvey,
fetchSubmissionHistory,
fetchSubmissionDetail,
getQuarterPeriods,
- getPreviousForecastData
+ getPreviousForecastData,
+ getSubmissionHistoryByEstablishment
};
\ No newline at end of file