feat(ocr) - schema updated, allowed payment model to allow both - claim and ocr data

This commit is contained in:
2025-09-03 23:05:23 +05:30
parent 155f338a15
commit 399c47dcfd
7 changed files with 166 additions and 160 deletions

View File

@@ -101,3 +101,41 @@ export const formatDateToHumanReadable = (
year: "numeric", // e.g., "2023", "2025"
}).format(date);
};
/**
* Convert any OCR numeric-ish value into a number.
* Handles string | number | null | undefined gracefully.
*/
export function toNum(val: string | number | null | undefined): number {
if (val == null || val === "") return 0;
if (typeof val === "number") return val;
const parsed = Number(val);
return isNaN(parsed) ? 0 : parsed;
}
/**
* Convert any OCR string-like value into a safe string.
*/
export function toStr(val: string | number | null | undefined): string {
if (val == null) return "";
return String(val).trim();
}
/**
* Convert OCR date strings like "070825" (MMDDYY) into a JS Date object.
* Example: "070825" → 2025-08-07.
*/
export function convertOCRDate(input: string | number | null | undefined): Date {
const raw = toStr(input);
if (!/^\d{6}$/.test(raw)) {
throw new Error(`Invalid OCR date format: ${raw}`);
}
const month = parseInt(raw.slice(0, 2), 10) - 1;
const day = parseInt(raw.slice(2, 4), 10);
const year2 = parseInt(raw.slice(4, 6), 10);
const year = year2 < 50 ? 2000 + year2 : 1900 + year2;
return new Date(year, month, day);
}