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'
];
export const SALES_REPORT_DISTRIBUTORS = [
'Banashree Multi Millet Flour',
'Shiva nandi Enterprises',
'BPK & Co',
'Gaviranga',
'Bhagwan Enterprises',
'Shreshtaa Trading Co',
'Rajarajeshwari Enterprises',
'Byraveshwara Trading Co'
];
export const ROUTE_WISE_DISTRIBUTORS: Record<string, string[]> = {
"Krishna": ["Banashree Multi Millet Flour"],
"East-1": ["Shiva nandi Enterprises"],
"East-2": ["BPK & Co"],
"East-3": ["BPK & Co"],
"East-4": ["Gaviranga "],
"West-1": ["Bhagwan Enterprises"],
"West-2": ["Shreshtaa Trading Co "],
"West-3": ["Rajarajeshwari Enterprises "],
"West-4": ["Byraveshwara Trading Co"],
};
export const SALES_REPORT_SO_NAMES = [
'Surya C'
@ -236,6 +237,8 @@ export const SALES_REPORT_SO_NAMES = [
export const PIPELINE = {
endpoints: {
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 { Button } from '../components/buttons';
import {
SALES_REPORT_ROUTES,
SALES_REPORT_DISTRIBUTORS,
SALES_REPORT_SO_NAMES
ROUTE_WISE_DISTRIBUTORS,
BASE_URL,
PIPELINE
} from '../api/config';
import { Download, Printer } from 'lucide-react';
import jsPDF from 'jspdf';
@ -15,12 +16,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<string | null>(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 doc = new jsPDF('landscape');
const pageWidth = doc.internal.pageSize.getWidth();
@ -49,7 +74,8 @@ export function DailySalesReportPage() {
doc.setFontSize(10);
doc.text(`Distributor Name : ${distributor}`, 14, 40);
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
autoTable(doc, {
@ -93,7 +119,8 @@ export function DailySalesReportPage() {
doc.setFontSize(10);
doc.text(`Distributor Name : ${distributor}`, 14, 40);
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
autoTable(doc, {
@ -149,7 +176,7 @@ export function DailySalesReportPage() {
date,
route,
distributor,
so_name: soName,
so_name: soEmail,
});
setReportData(data);
@ -175,20 +202,23 @@ export function DailySalesReportPage() {
<Select
label="Route"
value={route}
onChange={(e) => setRoute(e.target.value)}
options={[{ value: '', label: 'Select Route' }, ...SALES_REPORT_ROUTES]}
onChange={(e) => {
setRoute(e.target.value);
setDistributor('');
}}
options={[{ value: '', label: 'Select Route' }, ...SALES_REPORT_ROUTES.map(r => ({ value: r, label: r }))]}
/>
<Select
label="Distributor"
value={distributor}
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
label="SO Name"
value={soName}
onChange={(e) => setSoName(e.target.value)}
options={[{ value: '', label: 'Select SO Name' }, ...SALES_REPORT_SO_NAMES]}
value={soEmail}
onChange={(e) => setSoEmail(e.target.value)}
options={[{ value: '', label: 'Select SO Name' }, ...soOptions]}
/>
{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 className="text-right flex flex-col gap-1.5">
<div>Date : {date}</div>
<div>SO Name : {soName}</div>
<div>SO Name : {soOptions.find(o => o.value === soEmail)?.label || soEmail}</div>
</div>
</div>