diff --git a/backend/src/routes/applications.js b/backend/src/routes/applications.js index cde848c..9eb6f65 100644 --- a/backend/src/routes/applications.js +++ b/backend/src/routes/applications.js @@ -60,8 +60,8 @@ export const applicationRoutes = { options: { plugins: rateLimit, payload: { - // Cancelled-cheque images are base64 data URLs (5MB file ≈ ~6.7MB encoded). - maxBytes: 8 * 1024 * 1024, + // Cancelled-cheque images are base64 data URLs (10MB file ≈ ~13.3MB encoded). + maxBytes: 15 * 1024 * 1024, }, }, async handler(request) { diff --git a/backend/src/schemas/application.js b/backend/src/schemas/application.js index f8ee534..ebbdea4 100644 --- a/backend/src/schemas/application.js +++ b/backend/src/schemas/application.js @@ -59,7 +59,7 @@ export const draftApplicationSchema = z account_number: optionalText(text(z.string().regex(accountPattern))), ifsc: optionalText(text(z.string().regex(ifscPattern))), accepted: z.boolean().optional(), - /** Optional cancelled-cheque image as a data URL, or null to remove. */ + /** Cancelled-cheque image as a data URL (required before sign), or null to remove while drafting. */ cancelled_cheque: z.union([z.string().min(1), z.null()]).optional(), }) .strict(); diff --git a/backend/src/services/admin.js b/backend/src/services/admin.js index 028ee51..dadc1d8 100644 --- a/backend/src/services/admin.js +++ b/backend/src/services/admin.js @@ -310,6 +310,10 @@ export async function getApplication(id) { } : null, pdfUrl: pdfKey ? await getPresignedUrl(String(pdfKey)) : null, + // Short-lived URL for the Download cancelled cheque control next to bank details. + cancelledChequeUrl: application.cancelled_cheque_key + ? await getPresignedUrl(String(application.cancelled_cheque_key)) + : null, emails, audit: audit.map((row) => ({ id: row.id, diff --git a/backend/src/services/applications.js b/backend/src/services/applications.js index e848785..4c400b9 100644 --- a/backend/src/services/applications.js +++ b/backend/src/services/applications.js @@ -10,7 +10,8 @@ import { generateToken, hashToken } from './tokens.js'; import { sendResumeLink } from './mail.js'; import { readUserId } from './userAuth.js'; -const CHEQUE_LIMIT = 5 * 1024 * 1024; +/** Max decoded cancelled-cheque image size (PNG/JPEG). */ +const CHEQUE_LIMIT = 10 * 1024 * 1024; const CODE_FIELDS = ['pan', 'ifsc', 'gstin']; @@ -59,6 +60,8 @@ export function presentApplication(row) { } /** + * Ensures required physician + bank fields are present, and a cancelled cheque + * has been uploaded, before preview or sign. * @param {Record} application */ export function assertCompleteApplication(application) { @@ -74,6 +77,10 @@ export function assertCompleteApplication(application) { throw Boom.badRequest(zodMessage(parsed.error)); } + if (!application.cancelled_cheque_key) { + throw Boom.badRequest('cancelled_cheque: Upload a cancelled cheque image'); + } + return parsed.data; } @@ -265,7 +272,7 @@ export async function saveApplication(request, application, payload, finalize) { const image = readImageDataUrl( chequePayload, CHEQUE_LIMIT, - 'The cancelled cheque image must be 5MB or smaller', + 'The cancelled cheque image must be 10MB or smaller', ); const key = `applications/${application.public_id}/v${application.version}/cancelled-cheque.${image.extension}`; await putObject(key, image.buffer, image.contentType); diff --git a/backend/src/services/applicationsExport.js b/backend/src/services/applicationsExport.js index 9e778cd..6797140 100644 --- a/backend/src/services/applicationsExport.js +++ b/backend/src/services/applicationsExport.js @@ -19,8 +19,8 @@ const SURVEY_LABELS = { /** * `text: true` keeps Excel from turning account numbers and similar ids into * numbers (scientific notation, dropped leading zeros). `basic: true` columns - * are the default report; the full report adds registration, bank and - * consent-statement details. + * are the default report; the full report adds territory (from pppaimt_doctors), + * registration, bank and consent-statement details. * @typedef {{ key: string, header: string, width: number, text?: boolean, basic?: boolean }} ExportColumn * @type {ExportColumn[]} */ @@ -29,6 +29,16 @@ const BASE_COLUMNS = [ { key: 'status', header: 'Status', width: 14, basic: true }, { key: 'email', header: 'Email', width: 30, basic: true }, { key: 'fullName', header: 'Full name', width: 26, basic: true }, + // Territory / TM fields from the imported doctor list (full report only). + { key: 'taskforce', header: 'TASKFORCE', width: 18 }, + { key: 'zbmName', header: 'ZBM Name', width: 22 }, + { key: 'rbmName', header: 'RBM Name', width: 22 }, + { key: 'abmName', header: 'ABM Name', width: 22 }, + { key: 'hq', header: 'HQ', width: 18 }, + { key: 'tmId', header: 'TM ID', width: 12, text: true }, + { key: 'tmName', header: 'TM Name', width: 22 }, + { key: 'tmMailId', header: 'TM Mail ID', width: 28 }, + { key: 'tmMobile', header: 'TM Mobile', width: 16, text: true }, { key: 'age', header: 'Age', width: 8, basic: true }, { key: 'address', header: 'Address', width: 40, basic: true }, { key: 'registrationNo', header: 'Registration no', width: 18, text: true }, @@ -102,7 +112,9 @@ function yesNo(value) { } /** - * PAN and account numbers are only decrypted for the full report. + * Builds one spreadsheet row. PAN and account numbers are decrypted only for + * the full report; territory fields come from the joined doctor list (blank + * when the application email is not in pppaimt_doctors). * @param {Record} record * @param {Set} signedIds * @param {{ full?: boolean }} [options] @@ -116,6 +128,15 @@ export function applicationExportRow(record, signedIds, options = {}) { status: STATUS_LABELS[record.status] ?? text(record.status), email: text(record.email), fullName: text(record.full_name), + taskforce: text(record.doctorTaskforce), + zbmName: text(record.doctorZbmName), + rbmName: text(record.doctorRbmName), + abmName: text(record.doctorAbmName), + hq: text(record.doctorHq), + tmId: text(record.doctorTmId), + tmName: text(record.doctorTmName), + tmMailId: text(record.doctorTmMailId), + tmMobile: text(record.doctorTmMobile), age: typeof record.age === 'number' ? record.age : text(record.age), address: text(record.address), registrationNo: text(record.registration_no), @@ -153,15 +174,18 @@ export function applicationExportRow(record, signedIds, options = {}) { } /** - * Decrypts PAN and account numbers (full report only) before streaming starts, - * so a decryption failure surfaces as an error response instead of a - * truncated file. + * Loads applications in the date range with consent, survey and doctor + * territory fields. Decrypts PAN and account numbers (full report only) while + * mapping rows so a decryption failure surfaces as an error response instead + * of a truncated file. * @param {{ from?: string, to?: string, full?: boolean }} query */ export async function loadApplicationsExport(query) { + // Doctor list is matched on HCP email; left join keeps apps with no match. let request = db('applications') .leftJoin('consents', 'consents.application_id', 'applications.id') .leftJoin('survey_responses', 'survey_responses.application_id', 'applications.id') + .leftJoin('pppaimt_doctors', 'pppaimt_doctors.email', 'applications.email') .select( 'applications.*', 'consents.id as consentId', @@ -171,6 +195,15 @@ export async function loadApplicationsExport(query) { 'consents.answers as consentAnswers', 'survey_responses.status as surveyStatus', 'survey_responses.completed_at as surveyCompletedAt', + 'pppaimt_doctors.taskforce as doctorTaskforce', + 'pppaimt_doctors.zbm_name as doctorZbmName', + 'pppaimt_doctors.rbm_name as doctorRbmName', + 'pppaimt_doctors.abm_name as doctorAbmName', + 'pppaimt_doctors.hq as doctorHq', + 'pppaimt_doctors.tm_id as doctorTmId', + 'pppaimt_doctors.tm_name as doctorTmName', + 'pppaimt_doctors.tm_mail_id as doctorTmMailId', + 'pppaimt_doctors.tm_mobile as doctorTmMobile', ) .orderBy('applications.created_at', 'asc') .orderBy('applications.id', 'asc'); diff --git a/backend/src/services/png.js b/backend/src/services/png.js index acbebd4..0344319 100644 --- a/backend/src/services/png.js +++ b/backend/src/services/png.js @@ -44,7 +44,7 @@ export function readPngDataUrl(image, maxBytes, sizeMessage) { } /** - * Decode a PNG or JPEG data URL for optional document uploads (e.g. cancelled cheque). + * Decode a PNG or JPEG data URL for document uploads (e.g. cancelled cheque). * @param {string} image * @param {number} maxBytes * @param {string} sizeMessage diff --git a/backend/test/applications.test.js b/backend/test/applications.test.js index 507e810..6d35dbe 100644 --- a/backend/test/applications.test.js +++ b/backend/test/applications.test.js @@ -25,6 +25,10 @@ const complete = { accepted: true, }; +/** Minimal PNG data URL used as a cancelled-cheque upload in sign tests. */ +const CHEQUE_PNG = + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=='; + /** * @param {string} url */ @@ -242,7 +246,7 @@ describe('applications', () => { }); }); - it('rejects a signature when the application or consent is incomplete', async () => { + it('rejects a signature when the application or cancelled cheque is incomplete', async () => { const api = await start(); await postEmail(api); const headers = { authorization: `Bearer ${tokenFrom(outbox[0].url)}` }; @@ -261,13 +265,21 @@ describe('applications', () => { headers, payload: complete, }); - const missingConsent = await api.inject({ + const missingCheque = await api.inject({ method: 'POST', url: '/api/applications/me/sign', headers, payload: { type: 'TYPED', typedName: 'Asha Rao' }, }); - expect(missingConsent.statusCode).toBe(400); + expect(missingCheque.statusCode).toBe(400); + expect(missingCheque.result.error.message).toMatch(/cancelled cheque/i); + + await api.inject({ + method: 'PUT', + url: '/api/applications/me', + headers, + payload: { cancelled_cheque: CHEQUE_PNG }, + }); // Ensure auto-approve cannot run so this case stays SUBMITTED. await db('settings') @@ -287,6 +299,7 @@ describe('applications', () => { expect(signed.result.signedPdfUrl).toEqual(expect.any(String)); const row = await db('applications').where({ email }).first(); expect(row.signed_pdf_sha256).toHaveLength(64); + expect(row.cancelled_cheque_key).toBeTruthy(); expect(row.submitted_at).toBeTruthy(); }); @@ -302,6 +315,12 @@ describe('applications', () => { headers, payload: complete, }); + await api.inject({ + method: 'PUT', + url: '/api/applications/me', + headers, + payload: { cancelled_cheque: CHEQUE_PNG }, + }); const png = Buffer.from( 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==', diff --git a/backend/test/applicationsExport.test.js b/backend/test/applicationsExport.test.js index 91ec860..a9363e7 100644 --- a/backend/test/applicationsExport.test.js +++ b/backend/test/applicationsExport.test.js @@ -59,6 +59,19 @@ describe('applications export', () => { }); const [userId] = await db('users').insert({ email: 'asha@example.com', name: 'Asha Rao' }); + await db('pppaimt_doctors').insert({ + email: 'asha@example.com', + hcp_name: 'Asha Rao', + taskforce: 'Respiratory 2', + zbm_name: 'ZBM Example', + rbm_name: 'RBM Example', + abm_name: 'ABM Example', + hq: 'mumbai western', + tm_id: '142621', + tm_name: 'Salim Khan', + tm_mail_id: 'salim.khan1@cipla.com', + tm_mobile: '9987944435', + }); const [applicationId] = await db('applications').insert({ public_id: randomUUID(), user_id: userId, @@ -167,7 +180,7 @@ describe('applications export', () => { it('writes every column for the full report', async () => { const cookie = await seedExport(); - const { response, sheet, cell } = await exportSheet( + const { response, sheet, headers, cell } = await exportSheet( cookie, 'from=2026-10-01&to=2026-10-31&full=true', ); @@ -175,7 +188,18 @@ describe('applications export', () => { expect(response.headers['content-disposition']).toContain('applications-consent-full.xlsx'); expect(sheet.rowCount).toBe(2); expect(sheet.getRow(1).getCell(1).font?.bold).toBe(true); + expect(headers.indexOf('Full name')).toBeLessThan(headers.indexOf('TASKFORCE')); + expect(headers.indexOf('TM Mobile')).toBeLessThan(headers.indexOf('Age')); expect(cell('Status')).toBe('Approved'); + expect(cell('TASKFORCE')).toBe('Respiratory 2'); + expect(cell('ZBM Name')).toBe('ZBM Example'); + expect(cell('RBM Name')).toBe('RBM Example'); + expect(cell('ABM Name')).toBe('ABM Example'); + expect(cell('HQ')).toBe('mumbai western'); + expect(cell('TM ID')).toBe('142621'); + expect(cell('TM Name')).toBe('Salim Khan'); + expect(cell('TM Mail ID')).toBe('salim.khan1@cipla.com'); + expect(cell('TM Mobile')).toBe('9987944435'); expect(cell('PAN')).toBe('ABCDE1234F'); expect(cell('Account number')).toBe('001234567890'); expect(cell('Cheque uploaded')).toBe('Yes'); diff --git a/frontend/src/admin.css b/frontend/src/admin.css index 2b208e6..a332e60 100644 --- a/frontend/src/admin.css +++ b/frontend/src/admin.css @@ -233,6 +233,7 @@ border-radius: 0.55rem; font: inherit; font-weight: 600; + text-decoration: none; cursor: pointer; } @@ -407,6 +408,15 @@ text-decoration: none; } +.admin-cheque-image { + display: block; + width: 100%; + height: auto; + border-radius: 0.5rem; + border: 1px solid #e7e5e4; + background: #fafaf9; +} + input[type='checkbox'].h-4 { width: 1rem; height: 1rem; diff --git a/frontend/src/admin/ApplicationDetailPage.jsx b/frontend/src/admin/ApplicationDetailPage.jsx index 779932c..2da0bf5 100644 --- a/frontend/src/admin/ApplicationDetailPage.jsx +++ b/frontend/src/admin/ApplicationDetailPage.jsx @@ -132,6 +132,28 @@ export default function ApplicationDetailPage() { ))} +
+

Cancelled cheque

+ {application.cancelledChequeUrl ? ( + <> + Cancelled cheque + + Download cancelled cheque + + + ) : ( +

No cancelled cheque uploaded

+ )} +

Signature

{application.signature ? (

diff --git a/frontend/src/admin/ReportsPage.jsx b/frontend/src/admin/ReportsPage.jsx index 01fa2c8..c7cc0b2 100644 --- a/frontend/src/admin/ReportsPage.jsx +++ b/frontend/src/admin/ReportsPage.jsx @@ -154,9 +154,9 @@ export default function ReportsPage() { filename="applications-consent.xlsx" fullReport={{ description: - 'Every application, consent and survey column, filtered by application created date. Includes registration details, full PAN and bank account numbers.', + 'Every application, consent and survey column, filtered by application created date. Includes territory/TM fields from the doctor list, registration details, full PAN and bank account numbers.', filename: 'applications-consent-full.xlsx', - help: 'Tick this only when you need registration, bank or payment details, for example to process honorarium payments. It adds registration number, medical council, PAN, GSTIN, bank account details, cheque status, approval dates and each consent statement.', + help: 'Tick this only when you need registration, bank, payment or territory details, for example to process honorarium payments. It adds TASKFORCE through TM Mobile from the doctor list, registration number, medical council, PAN, GSTIN, bank account details, cheque status, approval dates and each consent statement.', }} /> diff --git a/frontend/src/admin/ReportsPage.test.jsx b/frontend/src/admin/ReportsPage.test.jsx index ac02107..e1ed9c5 100644 --- a/frontend/src/admin/ReportsPage.test.jsx +++ b/frontend/src/admin/ReportsPage.test.jsx @@ -55,7 +55,9 @@ describe('reports page', () => { expect(applications).toContainElement(checkbox); expect(survey.querySelector('input[type="checkbox"]')).toBeNull(); expect(checkbox).not.toBeChecked(); - expect(checkbox).toHaveAccessibleDescription(/only when you need registration, bank or payment details/); + expect(checkbox).toHaveAccessibleDescription( + /only when you need registration, bank, payment or territory details/, + ); const fromDate = applications.querySelector('input[type="date"]'); expect( checkbox.compareDocumentPosition(fromDate) & Node.DOCUMENT_POSITION_FOLLOWING, @@ -67,7 +69,9 @@ describe('reports page', () => { const card = screen.getByRole('form', { name: 'Export Applications with consent' }); fireEvent.click(screen.getByRole('checkbox', { name: 'Full report' })); - expect(card).toHaveTextContent('Includes registration details, full PAN and bank account numbers.'); + expect(card).toHaveTextContent( + 'Includes territory/TM fields from the doctor list, registration details, full PAN and bank account numbers.', + ); fireEvent.click(card.querySelector('button')); await waitFor(() => diff --git a/frontend/src/pages/AgreementPage.jsx b/frontend/src/pages/AgreementPage.jsx index ca36591..29f2183 100644 --- a/frontend/src/pages/AgreementPage.jsx +++ b/frontend/src/pages/AgreementPage.jsx @@ -118,7 +118,8 @@ export function fieldKeyForMessage(message) { text.includes('cheque') || text.includes('png or jpeg') || text.includes('500kb') || - text.includes('5mb') + text.includes('5mb') || + text.includes('10mb') ) { return 'cancelled_cheque'; } @@ -135,10 +136,10 @@ const BANK_TIPS = { account_holder: 'Name as per bank account only', account_number: 'Account number without spaces or hyphens', ifsc: '11-character IFSC code from your cheque book or passbook', - cancelled_cheque: 'Optional. Upload a clear PNG or JPEG of a cancelled cheque (max 5MB)', + cancelled_cheque: 'Upload a clear PNG or JPEG of a cancelled cheque (max 10MB)', }; -const CHEQUE_MAX_BYTES = 5 * 1024 * 1024; +const CHEQUE_MAX_BYTES = 10 * 1024 * 1024; /** * @param {{ message: string }} props @@ -365,6 +366,12 @@ export default function AgreementPage() { return; } + // Cheque is uploaded separately; block review until one is on file. + if (!chequeUrl) { + setFieldErrors({ cancelled_cheque: 'Upload a cancelled cheque image' }); + return; + } + const fields = { ...parsed.data }; delete fields.email; @@ -407,7 +414,7 @@ export default function AgreementPage() { } if (file.size > CHEQUE_MAX_BYTES) { - applyErrorMessage('The cancelled cheque image must be 5MB or smaller'); + applyErrorMessage('The cancelled cheque image must be 10MB or smaller'); return; } @@ -665,7 +672,7 @@ export default function AgreementPage() {

{chequeUrl ? (
diff --git a/frontend/src/pages/AgreementPage.test.jsx b/frontend/src/pages/AgreementPage.test.jsx index b3ff00d..4234274 100644 --- a/frontend/src/pages/AgreementPage.test.jsx +++ b/frontend/src/pages/AgreementPage.test.jsx @@ -86,6 +86,7 @@ describe('agreement page', () => { account_number: '123456789012', ifsc: 'SBIN0001234', accepted: true, + cancelledChequeUrl: 'https://example.com/cheque.jpg', }), }; }