added dsr option according to the database

This commit is contained in:
suryacp23 2026-07-30 13:17:10 +05:30
parent f8b6de86f2
commit d1ef7f4838
2 changed files with 58 additions and 25 deletions

View File

@ -217,16 +217,17 @@ export const SALES_REPORT_ROUTES = [
'West-4' 'West-4'
]; ];
export const SALES_REPORT_DISTRIBUTORS = [ export const ROUTE_WISE_DISTRIBUTORS: Record<string, string[]> = {
'Banashree Multi Millet Flour', "Krishna": ["Banashree Multi Millet Flour"],
'Shiva nandi Enterprises', "East-1": ["Shiva nandi Enterprises"],
'BPK & Co', "East-2": ["BPK & Co"],
'Gaviranga', "East-3": ["BPK & Co"],
'Bhagwan Enterprises', "East-4": ["Gaviranga "],
'Shreshtaa Trading Co', "West-1": ["Bhagwan Enterprises"],
'Rajarajeshwari Enterprises', "West-2": ["Shreshtaa Trading Co "],
'Byraveshwara Trading Co' "West-3": ["Rajarajeshwari Enterprises "],
]; "West-4": ["Byraveshwara Trading Co"],
};
export const SALES_REPORT_SO_NAMES = [ export const SALES_REPORT_SO_NAMES = [
'Surya C' 'Surya C'
@ -236,6 +237,8 @@ export const SALES_REPORT_SO_NAMES = [
export const PIPELINE = { export const PIPELINE = {
endpoints: { endpoints: {
nearestStores: '/api/papi2/nearest-stores', nearestStores: '/api/papi2/nearest-stores',
dailySalesReport: '/api/papi2/daily-sales-report' dailySalesReport: '/api/papi2/daily-sales-report',
productiveCallSummary: '/api/papi2/productive-call-summary',
salesOfficers: '/api/papi2/sales-officers'
} }
}; };

View File

@ -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 { Card, Input, Select } from '../components/reusable';
import { Button } from '../components/buttons'; import { Button } from '../components/buttons';
import { import {
SALES_REPORT_ROUTES, SALES_REPORT_ROUTES,
SALES_REPORT_DISTRIBUTORS, ROUTE_WISE_DISTRIBUTORS,
SALES_REPORT_SO_NAMES BASE_URL,
PIPELINE
} from '../api/config'; } from '../api/config';
import { Download, Printer } from 'lucide-react'; import { Download, Printer } from 'lucide-react';
import jsPDF from 'jspdf'; import jsPDF from 'jspdf';
@ -15,12 +16,36 @@ export function DailySalesReportPage() {
const [date, setDate] = useState(''); const [date, setDate] = useState('');
const [route, setRoute] = useState(''); const [route, setRoute] = useState('');
const [distributor, setDistributor] = 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 [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [reportData, setReportData] = useState<any>(null); const [reportData, setReportData] = useState<any>(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 downloadPDF = () => {
const doc = new jsPDF('landscape'); const doc = new jsPDF('landscape');
const pageWidth = doc.internal.pageSize.getWidth(); const pageWidth = doc.internal.pageSize.getWidth();
@ -49,7 +74,8 @@ export function DailySalesReportPage() {
doc.setFontSize(10); doc.setFontSize(10);
doc.text(`Distributor Name : ${distributor}`, 14, 40); doc.text(`Distributor Name : ${distributor}`, 14, 40);
doc.text(`Date : ${date}`, rightMargin, 40, { align: 'right' }); doc.text(`Date : ${date}`, rightMargin, 40, { align: 'right' });
doc.text(`SO Name : ${soName}`, rightMargin, 45, { align: 'right' }); const selectedSo = soOptions.find(o => o.value === soEmail);
doc.text(`SO Name : ${selectedSo ? selectedSo.label : soEmail}`, rightMargin, 45, { align: 'right' });
// Table // Table
autoTable(doc, { autoTable(doc, {
@ -93,7 +119,8 @@ export function DailySalesReportPage() {
doc.setFontSize(10); doc.setFontSize(10);
doc.text(`Distributor Name : ${distributor}`, 14, 40); doc.text(`Distributor Name : ${distributor}`, 14, 40);
doc.text(`Date : ${date}`, rightMargin, 40, { align: 'right' }); doc.text(`Date : ${date}`, rightMargin, 40, { align: 'right' });
doc.text(`SO Name : ${soName}`, rightMargin, 45, { align: 'right' }); const selectedSo = soOptions.find(o => o.value === soEmail);
doc.text(`SO Name : ${selectedSo ? selectedSo.label : soEmail}`, rightMargin, 45, { align: 'right' });
// Table // Table
autoTable(doc, { autoTable(doc, {
@ -149,7 +176,7 @@ export function DailySalesReportPage() {
date, date,
route, route,
distributor, distributor,
so_name: soName, so_name: soEmail,
}); });
setReportData(data); setReportData(data);
@ -175,20 +202,23 @@ export function DailySalesReportPage() {
<Select <Select
label="Route" label="Route"
value={route} value={route}
onChange={(e) => setRoute(e.target.value)} onChange={(e) => {
options={[{ value: '', label: 'Select Route' }, ...SALES_REPORT_ROUTES]} setRoute(e.target.value);
setDistributor('');
}}
options={[{ value: '', label: 'Select Route' }, ...SALES_REPORT_ROUTES.map(r => ({ value: r, label: r }))]}
/> />
<Select <Select
label="Distributor" label="Distributor"
value={distributor} value={distributor}
onChange={(e) => setDistributor(e.target.value)} onChange={(e) => setDistributor(e.target.value)}
options={[{ value: '', label: 'Select Distributor' }, ...SALES_REPORT_DISTRIBUTORS]} options={[{ value: '', label: 'Select Distributor' }, ...(route ? (ROUTE_WISE_DISTRIBUTORS[route] || []) : []).map(d => ({ value: d, label: d }))]}
/> />
<Select <Select
label="SO Name" label="SO Name"
value={soName} value={soEmail}
onChange={(e) => setSoName(e.target.value)} onChange={(e) => setSoEmail(e.target.value)}
options={[{ value: '', label: 'Select SO Name' }, ...SALES_REPORT_SO_NAMES]} options={[{ value: '', label: 'Select SO Name' }, ...soOptions]}
/> />
{error && <div className="text-xs text-ruby-600 font-medium">{error}</div>} {error && <div className="text-xs text-ruby-600 font-medium">{error}</div>}
@ -222,7 +252,7 @@ export function DailySalesReportPage() {
<div>Distributor Name : {distributor}</div> <div>Distributor Name : {distributor}</div>
<div className="text-right flex flex-col gap-1.5"> <div className="text-right flex flex-col gap-1.5">
<div>Date : {date}</div> <div>Date : {date}</div>
<div>SO Name : {soName}</div> <div>SO Name : {soOptions.find(o => o.value === soEmail)?.label || soEmail}</div>
</div> </div>
</div> </div>