fanavaran car body and third_party lookup codings applied

This commit is contained in:
2026-09-06 10:45:40 +03:30
parent 5f714e1456
commit 02edd0b2ca
5 changed files with 160 additions and 2 deletions

View File

@@ -94,6 +94,52 @@ export function insuranceLineIdForProduct(
: FANAVARAN_THIRD_PARTY_LINE_ID;
}
export function insuranceLineLabel(
insuranceLineId: number,
): "CAR_BODY" | "THIRD_PARTY" | null {
if (insuranceLineId === FANAVARAN_CAR_BODY_LINE_ID) return "CAR_BODY";
if (insuranceLineId === FANAVARAN_THIRD_PARTY_LINE_ID) return "THIRD_PARTY";
return null;
}
export function plaqueLetterFromMiddleCode(code: unknown): string | null {
const id = parseFanavaranId(code);
if (id === null) return null;
const found = Object.entries(FANAVARAN_PLATE_LETTER_CODE).find(
([, value]) => value === id,
);
return found?.[0] ?? null;
}
export type AppPlaque = {
leftTwoDigits: string;
serialLetter: string;
threeDigits: string;
rightTwoDigits: string;
};
export function toAppPlaque(
vehicle: Record<string, unknown> | null,
): AppPlaque | null {
if (!vehicle) return null;
const leftTwoDigits = normalizePlaquePart(
vehicle.PlaqueLeftNo ?? vehicle.plaqueLeftNo,
);
const threeDigits = normalizePlaquePart(
vehicle.PlaqueRightNo ?? vehicle.plaqueRightNo,
);
const rightTwoDigits = normalizePlaquePart(
vehicle.PlaqueSerial ?? vehicle.plaqueSerial,
);
const serialLetter = plaqueLetterFromMiddleCode(
vehicle.PlaqueMiddleCodeId ?? vehicle.plaqueMiddleCodeId,
);
if (!leftTwoDigits || !serialLetter || !threeDigits || !rightTwoDigits) {
return null;
}
return { leftTwoDigits, serialLetter, threeDigits, rightTwoDigits };
}
export function toEnglishDigits(value: unknown): string {
return String(value ?? "")
.split("")