From c97d136068bfe5cc2a8b4946ffc3bfea1fc99c61 Mon Sep 17 00:00:00 2001 From: Abhijit Date: Tue, 1 Dec 2026 13:01:01 +0530 Subject: [PATCH] added horizon pob reports --- src/layouts/menu.js | 1 + src/routes/index.jsx | 2 + src/views/horizonreport/PobReport.jsx | 122 ++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/views/horizonreport/PobReport.jsx diff --git a/src/layouts/menu.js b/src/layouts/menu.js index 2622f81..a376dbd 100644 --- a/src/layouts/menu.js +++ b/src/layouts/menu.js @@ -156,6 +156,7 @@ export function getMenuItems({ permissions = [], roles = [], domain = '', email icon: LuFileText, children: [ child('horizon-field-work', 'Monthly Field Work Report', '/horizonreport/fieldwork'), + ...(fullAccess ? [child('horizon-pob', 'POB Report', '/horizonreport/pob')] : []), ], }); } diff --git a/src/routes/index.jsx b/src/routes/index.jsx index ff84e47..fe2e9df 100644 --- a/src/routes/index.jsx +++ b/src/routes/index.jsx @@ -104,6 +104,7 @@ const AdherencePobDriveReport = lazy(() => import('@/views/adherencepobdriverepo const IvaReportPage = lazy(() => import('@/views/ivareport/ReportPage')); const InsightsGlossaryForm = lazy(() => import('@/views/insights/GlossaryForm')); const HorizonFieldWorkReport = lazy(() => import('@/views/horizonreport/Report')); +const HorizonPobReport = lazy(() => import('@/views/horizonreport/PobReport')); function moduleRoutes(config) { const routes = [ @@ -252,6 +253,7 @@ export const routes = [ { path: '/ivareport/drbrandwise', element: }, { path: '/ivareport/skuwise', element: }, { path: '/horizonreport/fieldwork', element: }, + { path: '/horizonreport/pob', element: }, { path: '/coming-soon', element: }, { path: '*', element: }, ], diff --git a/src/views/horizonreport/PobReport.jsx b/src/views/horizonreport/PobReport.jsx new file mode 100644 index 0000000..dbcb3c2 --- /dev/null +++ b/src/views/horizonreport/PobReport.jsx @@ -0,0 +1,122 @@ +import { useState } from 'react'; +import { Button, Container, Form } from 'react-bootstrap'; +import { isSuccess, signedGet } from '@/api/client'; +import { useAuth } from '@/auth/AuthProvider'; +import PageMetaData from '@/components/PageMetaData'; +import { downloadRemoteFile } from '@/helpers/csv'; + +const TITLE = 'POB Report'; +const REPORT_TIMEOUT = 120000; + +export default function HorizonPobReport() { + const { domain, permissions, user } = useAuth(); + const designationName = String(user?.designation || '').trim().toUpperCase(); + const allowed = domain === 'horizon' && (permissions.includes('all_data_access') || designationName === 'HO'); + const [from, setFrom] = useState(''); + const [to, setTo] = useState(''); + const [filePath, setFilePath] = useState(''); + const [fetching, setFetching] = useState(false); + const [error, setError] = useState(''); + const [message, setMessage] = useState(''); + + const changeFrom = (value) => { + setFrom(value); + setFilePath(''); + setMessage(''); + }; + + const changeTo = (value) => { + setTo(value); + setFilePath(''); + setMessage(''); + }; + + const handleFetch = async (event) => { + event.preventDefault(); + if (!from || !to) { + setError('Please select a from date and a to date'); + setMessage(''); + setFilePath(''); + return; + } + if (from > to) { + setError('From date must be on or before the to date'); + setMessage(''); + setFilePath(''); + return; + } + setFetching(true); + setError(''); + setMessage(''); + setFilePath(''); + try { + const response = await signedGet('reports', 'horizon_reports/pob_report', { from, to }, { timeout: REPORT_TIMEOUT }); + const path = response?.data?.file_path || ''; + if (!isSuccess(response) || response.data?.access === false || !path) { + setError(response?.message || 'No file returned for the selected dates'); + return; + } + setFilePath(path); + } catch (err) { + setError(err.message || 'Unable to fetch the POB report'); + } finally { + setFetching(false); + } + }; + + const handleDownload = async () => { + setError(''); + try { + await downloadRemoteFile(filePath, 'pob-report.xlsx'); + setMessage('POB report downloaded'); + } catch (err) { + setError(err.message || 'Unable to download the POB report'); + } + }; + + if (!allowed) { + return ( + + +
+
+

{TITLE}

+
You do not have access to this report.
+
+
+
+ ); + } + + return ( + + +
+
+

{TITLE}

+ {error ?
{error}
: null} + {message ?
{message}
: null} +
+
+ From + changeFrom(event.target.value)} /> +
+
+ To + changeTo(event.target.value)} /> +
+
+ {filePath ? ( + + ) : ( + + )} +
+
+
+
+
+ ); +}