From eaf0ee3d6389483954440d04bb3b888a9c28b1ea Mon Sep 17 00:00:00 2001 From: suryacp23 Date: Thu, 30 Jul 2026 13:09:35 +0530 Subject: [PATCH] based on the dsr option is fetched from the backend --- src/api/config.ts | 3 +- src/screens/DailySalesReportPage.tsx | 49 +++++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/api/config.ts b/src/api/config.ts index d9aed87..031989d 100644 --- a/src/api/config.ts +++ b/src/api/config.ts @@ -245,6 +245,7 @@ export const PIPELINE = { endpoints: { nearestStores: '/api/papi2/nearest-stores', dailySalesReport: '/api/papi2/daily-sales-report', - productiveCallSummary: '/api/papi2/productive-call-summary' + productiveCallSummary: '/api/papi2/productive-call-summary', + salesOfficers: '/api/papi2/sales-officers' } }; diff --git a/src/screens/DailySalesReportPage.tsx b/src/screens/DailySalesReportPage.tsx index 402baf2..084dfd1 100644 --- a/src/screens/DailySalesReportPage.tsx +++ b/src/screens/DailySalesReportPage.tsx @@ -1,10 +1,11 @@ -import { useState, type FormEvent } from 'react'; +import { useState, useEffect, type FormEvent } from 'react'; import { Card, Input, Select } from '../components/reusable'; import { Button } from '../components/buttons/Button'; import { SALES_REPORT_ROUTES, ROUTE_WISE_DISTRIBUTORS, - SALES_REPORT_SO_NAMES + BASE_URL, + PIPELINE } from '../api/config'; import { Download, Printer } from 'lucide-react'; import jsPDF from 'jspdf'; @@ -14,12 +15,36 @@ export function DailySalesReportPage() { const [date, setDate] = useState(''); const [route, setRoute] = useState(''); const [distributor, setDistributor] = useState(''); - const [soName, setSoName] = useState(''); + const [soEmail, setSoEmail] = useState(''); + const [soOptions, setSoOptions] = useState<{value: string, label: string}[]>([]); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [reportData, setReportData] = useState(null); + useEffect(() => { + async function fetchSOs() { + try { + const res = await fetch(`${BASE_URL}${PIPELINE.endpoints.salesOfficers}`, { + headers: { + 'TemplateID': '194', + 'X-Pipeline-Version': 'latest', + 'OrgID': '57', + 'GroupID': '25', + 'Content-Type': 'application/json' + } + }); + const data = await res.json(); + if (data?.response?.options) { + setSoOptions(data.response.options); + } + } catch (err) { + console.error('Failed to fetch SOs', err); + } + } + fetchSOs(); + }, []); + const downloadPDF = () => { const doc = new jsPDF({ orientation: 'landscape' }); const pageWidth = doc.internal.pageSize.getWidth(); @@ -48,7 +73,8 @@ export function DailySalesReportPage() { doc.setFontSize(10); doc.text(`Distributor Name : ${distributor}`, 14, 40); doc.text(`Date : ${date}`, rightX, 40, { align: 'right' }); - doc.text(`SO Name : ${soName}`, rightX, 45, { align: 'right' }); + const selectedSo = soOptions.find(o => o.value === soEmail); + doc.text(`SO Name : ${selectedSo ? selectedSo.label : soEmail}`, rightX, 45, { align: 'right' }); // Table autoTable(doc, { @@ -90,7 +116,8 @@ export function DailySalesReportPage() { doc.setFontSize(10); doc.text(`Distributor Name : ${distributor}`, 14, 40); doc.text(`Date : ${date}`, rightX, 40, { align: 'right' }); - doc.text(`SO Name : ${soName}`, rightX, 45, { align: 'right' }); + const selectedSo = soOptions.find(o => o.value === soEmail); + doc.text(`SO Name : ${selectedSo ? selectedSo.label : soEmail}`, rightX, 45, { align: 'right' }); // Table autoTable(doc, { @@ -124,7 +151,7 @@ export function DailySalesReportPage() { setError(null); setReportData(null); try { - const res = await fetch('https://sandbox.getzino.in/api/papi2/daily-sales-report', { + const res = await fetch(`${BASE_URL}${PIPELINE.endpoints.dailySalesReport}`, { method: 'POST', headers: { 'TemplateID': '157', @@ -135,7 +162,7 @@ export function DailySalesReportPage() { date, route, distributor, - so_name: soName, + so_name: soEmail, }) }); @@ -181,9 +208,9 @@ export function DailySalesReportPage() { />