added horizon pob reports
This commit is contained in:
parent
3d347e3e45
commit
c97d136068
|
|
@ -156,6 +156,7 @@ export function getMenuItems({ permissions = [], roles = [], domain = '', email
|
||||||
icon: LuFileText,
|
icon: LuFileText,
|
||||||
children: [
|
children: [
|
||||||
child('horizon-field-work', 'Monthly Field Work Report', '/horizonreport/fieldwork'),
|
child('horizon-field-work', 'Monthly Field Work Report', '/horizonreport/fieldwork'),
|
||||||
|
...(fullAccess ? [child('horizon-pob', 'POB Report', '/horizonreport/pob')] : []),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ const AdherencePobDriveReport = lazy(() => import('@/views/adherencepobdriverepo
|
||||||
const IvaReportPage = lazy(() => import('@/views/ivareport/ReportPage'));
|
const IvaReportPage = lazy(() => import('@/views/ivareport/ReportPage'));
|
||||||
const InsightsGlossaryForm = lazy(() => import('@/views/insights/GlossaryForm'));
|
const InsightsGlossaryForm = lazy(() => import('@/views/insights/GlossaryForm'));
|
||||||
const HorizonFieldWorkReport = lazy(() => import('@/views/horizonreport/Report'));
|
const HorizonFieldWorkReport = lazy(() => import('@/views/horizonreport/Report'));
|
||||||
|
const HorizonPobReport = lazy(() => import('@/views/horizonreport/PobReport'));
|
||||||
|
|
||||||
function moduleRoutes(config) {
|
function moduleRoutes(config) {
|
||||||
const routes = [
|
const routes = [
|
||||||
|
|
@ -252,6 +253,7 @@ export const routes = [
|
||||||
{ path: '/ivareport/drbrandwise', element: <IvaReportPage key="drbrandwise" tab="drbrandwise" /> },
|
{ path: '/ivareport/drbrandwise', element: <IvaReportPage key="drbrandwise" tab="drbrandwise" /> },
|
||||||
{ path: '/ivareport/skuwise', element: <IvaReportPage key="skuwise" tab="skuwise" /> },
|
{ path: '/ivareport/skuwise', element: <IvaReportPage key="skuwise" tab="skuwise" /> },
|
||||||
{ path: '/horizonreport/fieldwork', element: <HorizonFieldWorkReport /> },
|
{ path: '/horizonreport/fieldwork', element: <HorizonFieldWorkReport /> },
|
||||||
|
{ path: '/horizonreport/pob', element: <HorizonPobReport /> },
|
||||||
{ path: '/coming-soon', element: <ComingSoon /> },
|
{ path: '/coming-soon', element: <ComingSoon /> },
|
||||||
{ path: '*', element: <ComingSoon /> },
|
{ path: '*', element: <ComingSoon /> },
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -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 (
|
||||||
|
<Container fluid>
|
||||||
|
<PageMetaData title={TITLE} />
|
||||||
|
<div className="card mt-3">
|
||||||
|
<div className="card-body">
|
||||||
|
<h4 className="page-title">{TITLE}</h4>
|
||||||
|
<div className="alert alert-danger mb-0" role="alert">You do not have access to this report.</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container fluid>
|
||||||
|
<PageMetaData title={TITLE} />
|
||||||
|
<div className="card mt-3">
|
||||||
|
<div className="card-body">
|
||||||
|
<h4 className="page-title mb-0">{TITLE}</h4>
|
||||||
|
{error ? <div className="alert alert-danger mt-3" role="alert">{error}</div> : null}
|
||||||
|
{message ? <div className="alert alert-success mt-3" role="alert">{message}</div> : null}
|
||||||
|
<Form onSubmit={handleFetch} className="row g-2 align-items-end mt-2">
|
||||||
|
<div className="col-md-3">
|
||||||
|
<Form.Label htmlFor="horizon-pob-from">From</Form.Label>
|
||||||
|
<Form.Control id="horizon-pob-from" type="date" value={from} onChange={(event) => changeFrom(event.target.value)} />
|
||||||
|
</div>
|
||||||
|
<div className="col-md-3">
|
||||||
|
<Form.Label htmlFor="horizon-pob-to">To</Form.Label>
|
||||||
|
<Form.Control id="horizon-pob-to" type="date" value={to} onChange={(event) => changeTo(event.target.value)} />
|
||||||
|
</div>
|
||||||
|
<div className="col-auto">
|
||||||
|
{filePath ? (
|
||||||
|
<Button type="button" variant="primary" onClick={handleDownload}>Download</Button>
|
||||||
|
) : (
|
||||||
|
<Button type="submit" variant="primary" disabled={fetching}>
|
||||||
|
{fetching ? 'Fetching...' : 'Fetch'}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue