From f5d19f562fb24350b5b7dfeab75ffbb5375bcd33 Mon Sep 17 00:00:00 2001 From: suryac Date: Tue, 18 Aug 2026 11:35:22 +0530 Subject: [PATCH] fix: limit for select option and dsr pdf generating --- src/api/config.ts | 6 +- src/components/forms/DynamicForm.tsx | 4 +- src/components/forms/LogVisitForm.tsx | 6 +- src/components/forms/fields/WfLookupField.tsx | 3 +- src/components/maps/NearestStoresMap.tsx | 6 +- src/screens/DailySalesReportPage.tsx | 67 ++++++++++++++----- 6 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/api/config.ts b/src/api/config.ts index 6631311..e074658 100644 --- a/src/api/config.ts +++ b/src/api/config.ts @@ -253,7 +253,7 @@ export const SALES_REPORT_SO_NAMES = [ // --- Pipeline Endpoints --- export const PIPELINE = { endpoints: { - nearestStores: '/api/papi2/nearest-stores', + nearestStores: '/api/p/krishna-group/v1/nearest-stores', dailySalesReport: '/api/papi2/daily-sales-report', productiveCallSummary: '/api/papi2/productive-call-summary', salesOfficers: '/api/papi2/sales-officers' @@ -263,3 +263,7 @@ export const PIPELINE = { export const HIDDEN_FORM_FIELDS = [ 'store_code_3', ]; + +export const SELECT_OPTION_LIMIT = 500; +export const PDF_MAX_SKUS_PER_CHUNK = 20; + diff --git a/src/components/forms/DynamicForm.tsx b/src/components/forms/DynamicForm.tsx index abea98a..85935d1 100644 --- a/src/components/forms/DynamicForm.tsx +++ b/src/components/forms/DynamicForm.tsx @@ -17,7 +17,7 @@ import { WfLookupField, RadioField, } from './fields'; -import { ORDER_BOOKING, STORE, DAILY_REPORTS, HIDDEN_FORM_FIELDS } from '../../api/config'; +import { ORDER_BOOKING, STORE, DAILY_REPORTS, HIDDEN_FORM_FIELDS, SELECT_OPTION_LIMIT } from '../../api/config'; export interface DynamicFormProps { client: ZinoClient; @@ -457,7 +457,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId: activityId: ORDER_BOOKING.activities.LOG_VISIT.uid, fieldId: ORDER_BOOKING.activities.LOG_VISIT.fields.selectStore, formData: { ...(chainedPrefillData as any || {}), ...values, ...(schema?.prefill_data as any || {}) }, - limit: 500 + limit: SELECT_OPTION_LIMIT }); const arr = Array.isArray(lookupRes) ? lookupRes : (lookupRes.data || lookupRes.records || []); const row = arr.find((r: any) => String(r.instance_id || r.id) === String(storeId)); diff --git a/src/components/forms/LogVisitForm.tsx b/src/components/forms/LogVisitForm.tsx index 008623a..d4d9a94 100644 --- a/src/components/forms/LogVisitForm.tsx +++ b/src/components/forms/LogVisitForm.tsx @@ -1,7 +1,7 @@ import { useState, useEffect, useCallback, useRef } from 'react'; import type { ZinoClient } from '../../api/client'; import type { FormScreenResponse } from '../../api/types'; -import { ORDER_BOOKING, HIDDEN_FORM_FIELDS } from '../../api/config'; +import { ORDER_BOOKING, HIDDEN_FORM_FIELDS, SELECT_OPTION_LIMIT } from '../../api/config'; import { Button } from '../buttons/Button'; import { Select } from '../reusable/Select'; import { DateField, TimeField, FileInput, TextField } from './fields'; @@ -148,7 +148,7 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }: activityId, fieldId: 'select_store', formData: formDataToSend, - limit: 200, + limit: SELECT_OPTION_LIMIT, }); const arr = Array.isArray(lookupRes) @@ -215,7 +215,7 @@ export function LogVisitForm({ client, onSuccess, onCancel, onActivityChange }: activityId, fieldId: 'daily_log', formData: payload, - limit: 200, + limit: SELECT_OPTION_LIMIT, }); const arr = Array.isArray(dailyLogLookupRes) diff --git a/src/components/forms/fields/WfLookupField.tsx b/src/components/forms/fields/WfLookupField.tsx index f49baad..39be0a3 100644 --- a/src/components/forms/fields/WfLookupField.tsx +++ b/src/components/forms/fields/WfLookupField.tsx @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react'; import type { ZinoClient } from '../../../api/client'; +import { SELECT_OPTION_LIMIT } from '../../../api/config'; import { SelectField } from './SelectField'; export interface WfLookupFieldProps { @@ -38,7 +39,7 @@ export function WfLookupField({ label, required, value, onChange, client, config activityId, fieldId, formData, - limit: 200 + limit: SELECT_OPTION_LIMIT }) .then(res => { if (!mounted) return; diff --git a/src/components/maps/NearestStoresMap.tsx b/src/components/maps/NearestStoresMap.tsx index a6ab6ba..19ff54d 100644 --- a/src/components/maps/NearestStoresMap.tsx +++ b/src/components/maps/NearestStoresMap.tsx @@ -64,11 +64,7 @@ export function NearestStoresMap() { method: 'POST', headers: { 'accept': 'application/json, text/plain, */*', - 'content-type': 'application/json', - 'groupid': '25', - 'orgid': '57', - 'templateid': '189', - 'x-pipeline-version': 'latest' + 'content-type': 'application/json' }, body: JSON.stringify({ latitude: lat, diff --git a/src/screens/DailySalesReportPage.tsx b/src/screens/DailySalesReportPage.tsx index a5b1420..736b508 100644 --- a/src/screens/DailySalesReportPage.tsx +++ b/src/screens/DailySalesReportPage.tsx @@ -5,7 +5,8 @@ import { SALES_REPORT_ROUTES, ROUTE_WISE_DISTRIBUTORS, BASE_URL, - PIPELINE + PIPELINE, + PDF_MAX_SKUS_PER_CHUNK } from '../api/config'; import { Download, Printer } from 'lucide-react'; import jsPDF from 'jspdf'; @@ -73,28 +74,56 @@ export function DailySalesReportPage() { // Meta Info doc.setFontSize(10); - doc.text(`Distributor Name : ${distributor}`, 14, 40); - doc.text(`Date : ${date}`, rightMargin, 40, { align: 'right' }); - const selectedSo = soOptions.find(o => o.value === soEmail); - doc.text(`SO Name : ${selectedSo ? selectedSo.label : soEmail}`, rightMargin, 45, { align: 'right' }); + + let leftY = 40; + if (distributor) { + doc.text(`Distributor Name : ${distributor}`, 14, leftY); + leftY += 5; + } + + let rightY = 40; + if (date) { + doc.text(`Date : ${date}`, rightMargin, rightY, { align: 'right' }); + rightY += 5; + } + + if (soEmail) { + const selectedSo = soOptions.find(o => o.value === soEmail); + doc.text(`SO Name : ${selectedSo ? selectedSo.label : soEmail}`, rightMargin, rightY, { align: 'right' }); + rightY += 5; + } }; - // Split headers into chunks to avoid jspdf-autotable's horizontal page break bugs - // This allows us to keep the 2-tier header perfectly intact and break at heading boundaries. - const MAX_SKUS_PER_CHUNK = 14; + // Split headers into chunks of exactly PDF_MAX_SKUS_PER_CHUNK, even if it means splitting a brand. const headerChunks: any[][] = []; let currentChunk: any[] = []; let currentSkuCount = 0; reportData?.response?.headers?.forEach((h: any) => { - const skus = h.skus || []; - if (currentSkuCount + skus.length > MAX_SKUS_PER_CHUNK && currentSkuCount > 0) { - headerChunks.push(currentChunk); - currentChunk = []; - currentSkuCount = 0; + const allSkus = h.skus || []; + if (allSkus.length === 0) return; + + let remainingSkus = [...allSkus]; + + while (remainingSkus.length > 0) { + const availableSpace = PDF_MAX_SKUS_PER_CHUNK - currentSkuCount; + + // Take as many SKUs as we can fit in the current chunk + const skusToTake = remainingSkus.splice(0, availableSpace); + + currentChunk.push({ + ...h, + skus: skusToTake + }); + + currentSkuCount += skusToTake.length; + + if (currentSkuCount >= PDF_MAX_SKUS_PER_CHUNK) { + headerChunks.push(currentChunk); + currentChunk = []; + currentSkuCount = 0; + } } - currentChunk.push(h); - currentSkuCount += skus.length; }); if (currentChunk.length > 0) { headerChunks.push(currentChunk); @@ -299,10 +328,12 @@ export function DailySalesReportPage() {
-
Distributor Name : {distributor}
+
+ {distributor &&
Distributor Name : {distributor}
} +
-
Date : {date}
-
SO Name : {soOptions.find(o => o.value === soEmail)?.label || soEmail}
+ {date &&
Date : {date}
} + {soEmail &&
SO Name : {soOptions.find(o => o.value === soEmail)?.label || soEmail}
}