culprit licence bug fixed , and handled some default values

This commit is contained in:
2026-11-12 11:23:40 +03:30
parent 8b9dabc9f2
commit e215dbdc03
12 changed files with 353 additions and 21 deletions
@@ -299,8 +299,10 @@ import {
pickFanavaranRecordId,
} from './fanavaran-other-people';
import {
FANAVARAN_DUMMY_LICENCE_ISSU_DATE,
resolveDriverFromParty,
resolveDriverIsOwner,
resolveFanavaranIsLicenseReplaced,
resolveFanavaranLicenceIssuDate,
resolveFanavaranLicenceNo,
resolveOwnerFromParty,
@@ -1835,7 +1837,8 @@ export class ClaimRequestManagementService {
result.CulpritLicenceCityId = null;
result.CulpritLicenceCountryId = null;
result.CulpritLicenceForeignCityName = null;
result.CulpritLicenceIssuDate = '1394/10/13';
// Overwritten later from person.driverLicenseDate when present.
result.CulpritLicenceIssuDate = FANAVARAN_DUMMY_LICENCE_ISSU_DATE;
// Must never be empty/null.
result.CulpritLicenceNo = FANAVARAN_DUMMY_LICENCE_NO;
result.DamagedCount = 1;
@@ -1865,7 +1868,8 @@ export class ClaimRequestManagementService {
result.PreviousPolicyEndDate = '';
result.StatusChangeDate = null;
result.TrackingCode = null;
result.IsLicenseReplacement = 0;
// ثالث field name; hull remaps to IsLicenseReplaced. Filled after licence date.
result.IsLicenseReplacement = null;
result.UnknownCulpritCauseId = null;
}
@@ -1892,9 +1896,13 @@ export class ClaimRequestManagementService {
this.fanavaranPayloadDefaultsWithoutExpertIds(
this.TEJARATNO_FANAVARAN_DEFAULTS as unknown as Record<string, unknown>,
);
const accidentCauseFromCase = Number(input.accidentReason?.fanavaran);
const result: Record<string, unknown> = {
...lookupDefaults,
AccidentCauseId: FANAVARAN_DEFAULT_ACCIDENT_CAUSE_ID,
AccidentCauseId:
Number.isFinite(accidentCauseFromCase) && accidentCauseFromCase > 0
? accidentCauseFromCase
: FANAVARAN_DEFAULT_ACCIDENT_CAUSE_ID,
};
if (!input.accidentReason) {
@@ -2641,6 +2649,12 @@ export class ClaimRequestManagementService {
);
input.payload.CulpritLicenceIssuDate =
resolveFanavaranLicenceIssuDate(driverIdentity);
const licenseReplaced = resolveFanavaranIsLicenseReplaced(
input.payload.CulpritLicenceIssuDate,
input.payload.AccidentDate,
);
input.payload.IsLicenseReplaced = licenseReplaced;
input.payload.IsLicenseReplacement = licenseReplaced;
input.payload.CustomerFaultPercent =
FANAVARAN_DEFAULT_HULL_CUSTOMER_FAULT_PERCENT;
@@ -4741,6 +4755,12 @@ export class ClaimRequestManagementService {
);
payload.CulpritLicenceIssuDate =
resolveFanavaranLicenceIssuDate(culpritDriver);
const licenseReplaced = resolveFanavaranIsLicenseReplaced(
payload.CulpritLicenceIssuDate,
payload.AccidentDate,
);
payload.IsLicenseReplacement = licenseReplaced;
payload.IsLicenseReplaced = licenseReplaced;
if (blameCase.type !== BlameRequestType.CAR_BODY) {
payload.CulpritTypeId = resolveThirdPartyCulpritTypeId(
culpritParty as any,
@@ -34,15 +34,25 @@ describe("fanavaran hull base claim", () => {
expect(fanavaranHullNestedClaimId({ ClaimNo: 2268 })).toBeNull();
});
it("sends IsLicenseReplaced as 0 using the hull field name", () => {
it("sets IsLicenseReplaced to 1 when licence issue is more than 10 years before accident", () => {
const hull = toFanavaranHullBaseClaimPayload({
PolicyId: 1,
IsLicenseReplacement: 0,
AccidentDate: "1405/08/20",
CulpritLicenceIssuDate: "1394/10/13",
});
expect(hull.IsLicenseReplaced).toBe(0);
expect(hull.IsLicenseReplaced).toBe(1);
expect(hull).not.toHaveProperty("IsLicenseReplacement");
});
it("sets IsLicenseReplaced to null when licence issue is within 10 years", () => {
const hull = toFanavaranHullBaseClaimPayload({
PolicyId: 1,
AccidentDate: "1405/08/20",
CulpritLicenceIssuDate: "1401/08/02",
});
expect(hull.IsLicenseReplaced).toBeNull();
});
it("strips ثالث-only fields from a live hull create echo", () => {
const hull = toFanavaranHullBaseClaimPayload({
AccidentCauseId: 6,
@@ -58,6 +68,7 @@ describe("fanavaran hull base claim", () => {
ClaimNo: 2268,
CompensationReferenceId: 167,
CulpritLicenceNo: "9705463515",
CulpritLicenceIssuDate: "1404/08/20",
CulpritTypeId: 337,
CustomerFaultPercent: 100,
DamagedCount: 1,
@@ -74,7 +85,7 @@ describe("fanavaran hull base claim", () => {
expect(hull.PolicyId).toBe(13764408);
expect(hull.AccidentTypeId).toBeNull();
expect(hull.IsLicenseReplaced).toBe(0);
expect(hull.IsLicenseReplaced).toBeNull();
expect(hull.CostSeparationToDmgSections).toBe(0);
expect(hull.IsOwnerChanged).toBe(0);
expect(hull.CulpritTypeId).toBeNull();
@@ -1,5 +1,6 @@
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
import { TEJARAT_NOTIFIER_FIELDS } from "src/fanavaran/tejarat-notifier";
import { resolveFanavaranIsLicenseReplaced } from "./fanavaran-party-roles";
/** GEN.03 VHUD input fields. Do not send ثالث-only keys (DamagedCount, HasOtherCulprit, plaques, …). */
export const FANAVARAN_HULL_BASE_CLAIM_KEYS = [
@@ -50,7 +51,7 @@ export const FANAVARAN_HULL_BASE_CLAIM_KEYS = [
/** Select the current API row for the default collision scenario. */
export const FANAVARAN_HULL_ACCIDENT_TYPE_CAPTION = "تصادف(حادثه)";
/** GEN.03 ans (0=خیر). Used for CostSeparationToDmgSections, IsOwnerChanged, IsLicenseReplaced. */
/** GEN.03 ans (0=خیر). Used for CostSeparationToDmgSections, IsOwnerChanged. */
export const FANAVARAN_HULL_ANS_NO = 0;
export const FANAVARAN_HULL_CULPRIT_TYPE_CAPTION = "بيمه گذار";
@@ -124,8 +125,18 @@ export function toFanavaranHullBaseClaimPayload(
const next: Record<string, unknown> = {};
for (const key of FANAVARAN_HULL_BASE_CLAIM_KEYS) {
if (key === "IsLicenseReplaced") {
// Hull GEN.03: explicitly send خیر. Keep the hull field name.
next[key] = FANAVARAN_HULL_ANS_NO;
// Fanavaran conditional: >10y since issue → 1; else null (never 0).
if (
Object.prototype.hasOwnProperty.call(built, key) &&
(built[key] === 1 || built[key] === null)
) {
next[key] = built[key];
} else {
next[key] = resolveFanavaranIsLicenseReplaced(
built.CulpritLicenceIssuDate,
built.AccidentDate,
);
}
continue;
}
if (key === "AccidentTypeId") {
@@ -97,7 +97,7 @@ describe("hull live lookup submission checks", () => {
AuthorityCulpritId: 806,
CulpritLicenceTypeId: 807,
AccidentVehicleUsedId: 808,
IsLicenseReplaced: 0,
IsLicenseReplaced: null,
};
const url = "https://example.test/car/vehicle-hull-claims";
await service.postFanavaranJson(url, payload, "parsian");
@@ -6,6 +6,7 @@ import {
formatFanavaranLicenceIssuDate,
resolveDriverFromParty,
resolveDriverIsOwner,
resolveFanavaranIsLicenseReplaced,
resolveFanavaranLicenceIssuDate,
resolveFanavaranLicenceNo,
resolveOwnerFromParty,
@@ -73,6 +74,19 @@ describe("fanavaran-party-roles", () => {
expect(resolveFanavaranLicenceIssuDate(driver)).toBe(
FANAVARAN_DUMMY_LICENCE_ISSU_DATE,
);
expect(FANAVARAN_DUMMY_LICENCE_ISSU_DATE).toBe("1404/08/20");
});
it("marks licence replaced only when issue date is more than 10 years before accident", () => {
expect(
resolveFanavaranIsLicenseReplaced("1394/10/13", "1405/08/20"),
).toBe(1);
expect(
resolveFanavaranIsLicenseReplaced("1401/08/02", "1405/08/20"),
).toBeNull();
expect(
resolveFanavaranIsLicenseReplaced("1404/08/20", "1405/08/20"),
).toBeNull();
});
it("marks DriverIsOwner false when driver and owner differ", () => {
@@ -7,8 +7,54 @@ import {
} from "./fanavaran-driver-inquiry";
import type { FanavaranClaimProduct } from "./fanavaran-claim-product";
/** Fanavaran dummy licence issue date when the user did not supply one. */
export const FANAVARAN_DUMMY_LICENCE_ISSU_DATE = "1394/10/13";
/**
* Fanavaran dummy licence issue date when `person.driverLicenseDate` is missing.
* Kept recent so hull `IsLicenseReplaced` stays null (see 10-year rule).
*/
export const FANAVARAN_DUMMY_LICENCE_ISSU_DATE = "1404/08/20";
/** Years since issue after which hull/third-party "licence replaced?" becomes yes (1). */
export const FANAVARAN_LICENCE_REPLACED_AFTER_YEARS = 10;
/**
* True when `issueDate` is more than `years` before `referenceDate` (Jalali).
* Used for Fanavaran IsLicenseReplaced / IsLicenseReplacement.
*/
export function isJalaliDateOlderThanYears(
issueDate: unknown,
referenceDate: unknown,
years: number,
): boolean {
const issue = parseJalaliDateParts(issueDate);
const reference = parseJalaliDateParts(referenceDate);
if (!issue || !reference) return false;
let age = reference.year - issue.year;
if (
reference.month < issue.month ||
(reference.month === issue.month && reference.day < issue.day)
) {
age -= 1;
}
return age > years;
}
/**
* Hull `IsLicenseReplaced` / ثالث `IsLicenseReplacement`:
* - licence issue more than 10 years before accident → `1`
* - otherwise → `null` (never send `0`)
*/
export function resolveFanavaranIsLicenseReplaced(
licenceIssuDate: unknown,
accidentDate: unknown,
): 1 | null {
return isJalaliDateOlderThanYears(
licenceIssuDate,
accidentDate,
FANAVARAN_LICENCE_REPLACED_AFTER_YEARS,
)
? 1
: null;
}
export type FanavaranRoleIdentity = {
nationalCode: string | null;
@@ -202,7 +202,7 @@ describe("Expert Fanavaran stage fields", () => {
CulpritTypeId: 301,
AuthorityCulpritId: 8,
CustomerFaultPercent: 0,
IsLicenseReplaced: 0,
IsLicenseReplaced: null,
});
expect(payload.DamagedCount).toBeUndefined();
expect(payload.IsLicenseReplacement).toBeUndefined();