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
+1 -1
View File
@@ -156,7 +156,7 @@ History: `FANAVARAN_EARLY_AUTO_SUBMIT_SUCCEEDED`.
"EstimateAmount": 1000,
"PolicyId": 13764408,
"CulpritLicenceNo": "1124242",
"CulpritLicenceIssuDate": "1394/10/13",
"CulpritLicenceIssuDate": "1404/08/20",
"DamagedCount": 1,
"IsLicenseMatchWithVehicleKind": 1,
"HasOtherCulprit": 0,
+1 -1
View File
@@ -56,7 +56,7 @@ because they appear in the defaults below. Hull collision type, culprit type,
authority, damage kind, and cost kind select matching captions from API responses
without numeric fallbacks. Policy accessories are read for the current PolicyId;
ActualPremium is refreshed from that policy's TotalPremium. Expert-entered amounts
and durations remain expert data. `IsLicenseReplaced` stays explicitly 0.
and durations remain expert data. `IsLicenseReplaced` is `1` when licence issue is >10 years before the accident, otherwise `null`.
| Name | Shared seed | Parsian override | Tejaratno | Moallem | Varies? |
|------|-------------|------------------|-----------|---------|---------|
+4 -4
View File
@@ -31,7 +31,7 @@ Built by `buildFanavaranSubmitPayload` then `enrichCarBodyHullBaseClaimPayload`
**Fanavaran has rejected as required (must not be null):**
`CustomerFaultPercent`, `AuthorityCulpritId`, `AccidentTypeId`, `CostSeparationToDmgSections`, `IsOwnerChanged`, `PolicyId`, `ClaimExpertId`, dates/time, `CulpritTypeId`.
**Must be null:** `IsLicenseReplaced` (error if `0` / mapped from ثالث `IsLicenseReplacement`).
**IsLicenseReplaced:** `1` when `CulpritLicenceIssuDate` is more than 10 years before `AccidentDate`; otherwise `null` (never send `0`). Dummy issue date when missing: `1404/08/20`.
| Field | Persian | Type | Null? | Current value / source |
|-------|---------|------|-------|------------------------|
@@ -41,7 +41,7 @@ Built by `buildFanavaranSubmitPayload` then `enrichCarBodyHullBaseClaimPayload`
| AccidentTime | ساعت حادثه | string `HH:mm` | **no** | **user** `statement.accidentTime` if set |
| AnnouncementDate | تاریخ اعلام | string Jalali | **no** | **derived** = AccidentDate |
| AccidentLocationAddress | نشانی محل حادثه | string | **no** | **user** expert review, else **system** `"استان تهران شهر تهران"` |
| AccidentCauseId | علت حادثه | number | **no** | **system** `6` · lookup `accident-causes` |
| AccidentCauseId | علت حادثه | number | **no** | **user/expert** `accidentReason.fanavaran` from blame/claim; fallback **system** `6` · lookup `accident-causes` |
| AccidentCityId | شهر حادثه | number | **no** | **user** expert review, else **system** `701` · lookup `cities` |
| AccidentReportTypeId | نحوه اعلام | number | **no** | **user** expert review, else **system** `155` · lookup `accident-report-type` |
| AccidentTypeId | نوع حادثه بدنه | number | **no** | Reviewed choice, else current `vehicle-hull-accident-types` row caption تصادف(حادثه); no numeric fallback |
@@ -51,11 +51,11 @@ Built by `buildFanavaranSubmitPayload` then `enrichCarBodyHullBaseClaimPayload`
| CustomerFaultPercent | درصد تقصیر بیمه‌گذار | number | **no** | **user** expert review, else **system** `100` |
| CostSeparationToDmgSections | تفکیک هزینه به نقاط | number (ans) | **no** | **system** `0` خیر · lookup `ans` |
| IsOwnerChanged | مالک تغییر یافته؟ | number (ans) | **no** | **system** `0` · lookup `ans` |
| IsLicenseReplaced | گواهینامه تعویضی است؟ | number | **no** | **system** `0` (خیر); use the hull field name |
| IsLicenseReplaced | گواهینامه تعویضی است؟ | number | often null | **derived** `1` if issue date >10y before accident, else `null` (hull name; ثالث uses `IsLicenseReplacement`) |
| ActualPremium | حق بیمه واقعی | number | preferred | **inquiry** hull policy `TotalPremium` via `GET /lookups/body-policy/{PolicyId}` |
| EstimateAmount | برآورد | number | **no** | **user** expert prices / provisional |
| CulpritLicenceNo | شماره گواهینامه | string | **no** | dummy / **user** |
| CulpritLicenceIssuDate | تاریخ صدور گواهینامه | string Jalali | **no** | **system** `"1394/10/13"` |
| CulpritLicenceIssuDate | تاریخ صدور گواهینامه | string Jalali | **no** | **user** `parties.person.driverLicenseDate`; fallback **system** `"1404/08/20"` |
| CulpritLicenceTypeId | نوع گواهینامه | number | sent | tenant `2` · lookup `driving-licence-types` |
| AccidentVehicleUsedId | کاربری خودرو | number | **no** | **inquiry** hull policy `VehicleId` + `VehicleVersionNo` → vehicle GET `UsedId`; no default or expert override. Unresolved inquiry warns in preview and blocks submit. |
| PoliceOfficerId | افسر | number | yes | null; do not copy the shared third-party sample `1` |
@@ -115,7 +115,7 @@ Hull is **first party**. One vehicle, one policy.
| درصد تقصیر بیمه‌گذار | CustomerFaultPercent | number 0–100 | **user** if not 100%; today always 100 |
| تفکیک هزینه به نقاط | CostSeparationToDmgSections | ans | **user** default خیر |
| مالک تغییر یافته؟ | IsOwnerChanged | ans | **user** default خیر |
| گواهینامه تعویضی؟ | IsLicenseReplaced | ans | Currently sent as **0** (خیر) |
| گواهینامه تعویضی؟ | IsLicenseReplaced | ans | `1` if issue >10y before accident, else `null` |
| قطعات آسیب‌دیده | selectedParts | catalog ids | **user** |
### Expert pricing (بدنه)
+230
View File
@@ -0,0 +1,230 @@
# Lookup-backed fields by Fanavaran submission request
Code snapshot: 2026-11-11. This describes the current YARA builders and validation,
not a live acceptance test. Older stage-field/audit documents contain historical
defaults; use the validation implementation as the authority for current checks.
Ordinary codebook names below can be read through
`GET /lookups/fanavaran/{lookup-name}`. These routes use the deployment's active
insurer. Use the same insurer/product/contract as the submission being checked.
Use each row's `Id`, not its Caption or a different provider's code. A valid ID
must also represent the intended meaning, be active when IsActive is supplied,
and satisfy policy/vehicle/person relationships.
Validation labels:
- **Live checked:** current hull outbound validation checks membership/activity
using fresh API responses. A failed lookup or invalid selection blocks the write.
- **Gap:** no equivalent comprehensive third-party outbound membership check.
Some UI selections/inquiries are validated, but defaults and saved values can
still be wrong for the target insurer or current contract.
- **Conditional:** currently null/unset; becomes a concern if populated or required
by a vendor rule. Do not guess an endpoint/code when the source is unconfirmed.
## 1. Third-party base claim — GEN.03
`POST /car/third-party-car-financial-claims`
| Request field | Lookup/source | Current concern |
|---|---|---|
| AccidentCityId | cities | Reviewed selection or default 701; gap |
| AccidentReportTypeId | accident-report-type | Reviewed selection or default 155; gap |
| AccidentCauseId | accident-causes | Builder still starts with fixed 6; supplied accident-reason code is not applied as the outbound ID |
| AccidentVehicleUsedId | vehicle-use-types + actual policy/VIN vehicle UsedId | Vehicle group must match; inquiry/group/default fallbacks remain |
| CulpritTypeId | accident-culprit-type | Derived insurer-driver distinction, currently 337/338; no universal live membership guard |
| CulpritLicenceTypeId | driving-licence-types | Tenant default normally 2; must match the driver's actual licence category |
| CulpritLicenceCityId | cities | Conditional; normally null |
| CulpritLicenceCountryId | countries | Conditional; normally null |
| HasOtherCulprit | ans | Currently 0 |
| IsFatalAccident | yes/no flag | Currently 0; no third-party live codebook validation |
| IsAccidentOutOfBorder | ans / yes-no flag | Currently 0 |
| IsPlaqueChanged | yes/no flag | Currently 0 |
| IsLicenseMatchWithVehicleKind | yes/no flag | Currently 1; this does not validate the actual licence/vehicle relationship |
| IsLicenseReplacement | yes/no flag | Currently 0; hull uses a different field name |
| IsOwnerChanged, CostSeparationToDmgSections, IsSurplusArticleEighthLaw | yes/no flags | Conditional; normally null on third-party |
| CompensationReferenceId | Dedicated source not configured in the local lookup catalogue | Default 167; confirm the vendor's codebook/contract rather than inventing a lookup URL |
| PoliceOfficerId | Dedicated source not configured | Fixed 1 on third-party; needs contract confirmation |
| UnknownCulpritCauseId | No source wired | Conditional; currently null |
TejaratNo's current third-party branch additionally sends:
| Request field | Lookup/source | Concern |
|---|---|---|
| DmgNotifications[].NotifierTypeId | notifier-type | Must be an explicitly reviewed allowed choice |
| DmgNotifications[].NotifierRelationId | notifier-relation | Must represent the notifier's actual relationship |
| DmgNotifications[].NotifierPartyId | Person inquiry / GEN.44 response | Person record ID, not a generic codebook; must identify the correct notifier |
| DmgNotifications[].IsInjuredPartyIdentified | yes/no flag | Conditional; currently null |
Do not apply the TejaratNo DmgNotifications shape to other insurers automatically.
## 2. Third-party damage case — GEN.12
`POST /car/third-party-car-financial-claims/{claimId}/dmg-cases`
| Request field | Lookup/source | Current concern |
|---|---|---|
| VehicleKindId | vehicle-kinds / matched vehicle GET | Model and VehicleGroupId must match; expert selection and caption fallbacks need correct catalogue provenance |
| AccidentVehicleUsedId | vehicle-use-types / vehicle UsedId | Must belong to the selected vehicle's group; default remains possible |
| DmgCaseTypeId | dmg-case-type | Tenant default normally 175; gap |
| DmgHistoryStatus | dmg-history-status | Reviewed choice or default 5214; gap |
| InsuranceCorpId | insurance-corp | Actual damaged vehicle insurer, selected by caption; cached/default tenant provenance can be wrong |
| LicenceTypeId | driving-licence-types | Uses tenant CulpritLicenceTypeId, normally 2; gap |
| LicenceCityId | cities | Conditional; currently null |
| LicenceCountryId | countries | Conditional; currently null |
| DriverIsOwner | yes/no flag | Derived 1/0; must represent the actual driver/owner relationship |
| PlaqueKindId | Vehicle inquiry / GET | Must match actual plate kind; national-plate fallback 8 remains |
| PlaqueSampleId | Vehicle inquiry / GET | Must match actual plate sample; fallback 10 remains |
| PlaqueMiddleCodeId | Vehicle response or static plate-letter mapping | Not the visible plate letter or an unrelated provider code; no configured standalone lookup endpoint |
| PlaqueCityId | Vehicle response | Conditional; no independent membership check |
DriverId and OwnerId are person record IDs. Inquiry acceptance currently requires
RoleId 161 or 166; a different role cannot simply be reused as DriverId. Missing
acceptable people can trigger GEN.44 registration before damage submission.
## 3. Third-party attachments — GEN.07
`POST /car/third-party-car-financial-claims/{claimId}/files`
| Request field | Lookup | Current concern |
|---|---|---|
| FileTypeId | file-types | Configured ClaimFileTypeId; must be active and the correct document category for that insurer |
| Files[].FileTypeId, when this repeated metadata is present | file-types | Must agree with the same document type |
The strict hull lookup guard does not cover third-party file uploads. A historical
successful file type from another insurer is not proof of acceptance here.
## 4. Third-party expertise — GEN.08
`POST /car/third-party-car-financial-claims/{claimId}/expertise`
| Request field | Lookup | Current concern |
|---|---|---|
| InspectionPlaceId | inspection-place | Reviewed selection, otherwise 282; gap |
| DropAmountStatus | drop-amount-status | Fixed 5458; the fetched lookup is not used to select a replacement ID |
| DmgSections[].DmgSectionId | car-components | This is the selected catalogue part ID on submission; a local/shared snapshot can be wrong for the insurer |
| DmgSections[].AccidentLevel | accident-level | Numeric typeOfDamage or fallback 5456; must be a severity ID, not a label |
Readiness checks for these fields primarily check presence. They are not the same
as the fresh API membership/activity validation added to hull writes.
## 5. Hull base claim — GEN.03
`POST /car/vehicle-hull-claims`, also checked for base PUT updates.
| Request field | Lookup | Current handling |
|---|---|---|
| AccidentCityId | cities | Live checked; reviewed/configured selection must exist |
| AccidentReportTypeId | accident-report-type | Live checked |
| AccidentCauseId | accident-causes | Live checked; candidate still starts at 6, so check that its meaning is the actual accident cause |
| AccidentTypeId | vehicle-hull-accident-types | Reviewed choice or response row for تصادف(حادثه); live checked, no numeric fallback |
| CulpritTypeId | vehicle-hull-accident-culprit-type | Reviewed choice or response row for بیمه‌گذار; live checked; third-party 337 is not reused |
| AuthorityCulpritId | detection-accident-culprits | Reviewed choice or matching بیمه‌گذار response row; live checked, no first-row/numeric fallback |
| CulpritLicenceTypeId | driving-licence-types | Live checked; membership does not prove it matches the real driver's licence |
| AccidentVehicleUsedId | vehicle-use-types + exact policy vehicle/version UsedId | Inquiry-derived and live checked; vehicle/group relationship still matters |
| IsLicenseReplaced | ans | `1` if licence issue >10y before accident, else `null` |
| IsOwnerChanged | ans | Currently 0; live checked |
| CostSeparationToDmgSections | ans | Currently 0; live checked |
| IsAccidentOutOfBorder | ans | Currently 0; live checked when non-null |
| IsSurplusArticleEighthLaw | ans | Conditional; live checked when non-null |
| CulpritLicenceCityId | cities | Conditional; live checked when non-null |
| CulpritLicenceCountryId | countries | Conditional; live checked when non-null |
| NotifierTypeId, TejaratNo only | notifier-type | Root field for hull, unlike third-party DmgNotifications; live checked when present |
| NotifierRelationId, TejaratNo only | notifier-relation | Root field; live checked when present |
| GlassBreakReasonId | No lookup source currently wired | Conditional; currently null; verify the provider contract if using a glass-break scenario |
PoliceOfficerId is currently null on hull. CompensationReferenceId and the
third-party-only IsLicenseReplacement are stripped from the hull payload.
ActualPremium comes from the policy response, not a lookup list.
## 6. Hull attachments — GEN.05
`POST /car/vehicle-hull-claims/{claimId}/files`
| Request field | Lookup | Current handling |
|---|---|---|
| FileTypeId | file-types | Configured choice, live checked before upload |
| Files[].FileTypeId, when present | file-types | Live checked as well |
A file type being active does not prove the document belongs in that category.
The returned attachment Id is saved as fileId; it is not FileTypeId.
## 7. Hull expertise — GEN.06
`POST /car/vehicle-hull-claims/{claimId}/expertise`
| Request field | Lookup/source | Current handling |
|---|---|---|
| DmgSections[].AccessoryKindId | car-components | Selected part ID, live checked |
| DmgSections[].VehicleHullAccessoryId | Current hull policy dmg-accessories | Exact matching accessory or that policy's factory bundle; live checked; never a shared fixed record ID |
| DmgSections[].DmgKindId | vehicle-hull-dmg-kind | Response row caption تخریب; live checked, no numeric fallback |
| DmgSections[].DmgSectionCosts[].DmgCostKindId | vehicle-hull-dmg-cost-kinds | Response row caption مجموع لوازم; live checked, no numeric fallback |
| ColorId | Policy vehicle GET ColorId | Inquiry-derived; not independently checked against a colour lookup |
| PlaqueDesignId | No source wired | Conditional; currently null |
| PlaqueCityId | No source wired on hull expertise | Conditional; currently null |
| IsDestruction | Optional flag | Currently null; no live yes/no membership check in the expertise validator |
Get the policy accessory rows using:
`GET /lookups/vehicle-hull-dmg-accessories/{policyId}`
Upstream source:
`GET /car/vehicle-hull-policies/{policyId}/dmg-accessories`
Use the row's Id for VehicleHullAccessoryId. Its PolicyId must be the claim's hull
PolicyId. A factory bundle may legitimately serve several different selected
car-components parts. Its bundle AccessoryKindId is not automatically the part ID
to send for every damaged part.
Hull has no damage-case POST. DmgCaseId, InspectionPlaceId and DropAmountStatus
are not hull expertise fields. AccidentPercent is a percentage, not a lookup ID.
## 8. Person registration — GEN.44, when triggered by either product
`POST /common/other-people`
| Request field | Lookup | Current concern |
|---|---|---|
| CityId | cities | Explicit/inquiry/caption selection, else default 9131 remains |
| GenderId | gender | Inquiry/explicit/caption selection; may remain null |
| MaritalStatus | marital-status | Currently normally null |
| IsIranian | ans | Actual person status, with 1/0 fallbacks |
| NationalityId | countries | Normally null for Iranian people; foreign-nationality mapping needs explicit review |
| PersonKindId | person-kind | Explicit/caption selection, else default 46 remains |
GEN.44 is not covered by the hull base/files/expertise lookup validator. It also
has identity, birthday and mobile validation which can fail without a lookup error.
## Record IDs and headers: related failures, but not ordinary codebooks
| Value | Correct source / relationship |
|---|---|
| Base PolicyId | Correct guilty-party third-party policy, or first-party hull policy; never mix the products |
| Base ClaimExpertId | Staff ThirdPartyClaimExpertId or CarBodyClaimExpertId |
| Expertise ClaimExpertId | Staff ThirdPartyExpertiseClaim or CarBodyExpertiseClaim; different role from base ClaimExpertId |
| Third-party DriverId / OwnerId | Appropriate person inquiry / GEN.44 Id; required accepted roles |
| Hull AccidentCulpritId | Driver inquiry; policy CustomerId is a fallback and may identify a different person |
| NotifierPartyId | Correct notifier person record |
| Nested claimId | Base-create response Id, not ClaimNo |
| Third-party DmgCaseId | That claim's damage-case response Id |
| expertiseId | That claim's expertise response Id |
| fileId | That claim's upload response Id; use file-types only for FileTypeId |
| Location header | Responsible staff locations[].id, else their branch's code |
| ContractId header | Correct product contract; hullContractId where configured |
| CorpId header / authenticationToken | Credentials/scoping for the same insurer as all selected codes |
Amounts, wages, premiums, dates, times, counts, descriptions, licence numbers,
VIN/chassis/motor text, and plain plate digits are not generic lookup IDs. They
can still fail required-field, format, range, identity or cross-field rules.
## Highest-priority remaining checks
Third-party still needs the most attention: base accident/driver codes, damage
vehicle/use/plate codes, DmgCaseTypeId/DmgHistoryStatus, expertise inspection/drop/
severity/part codes, attachment FileTypeId, and GEN.44 defaults. Hull's live checks
prevent missing/inactive IDs but cannot prove that a valid selected code has the
correct business meaning or satisfies every provider rule.
Use stage previews before submission. Hull failures identify lookup fields through
FANAVARAN_HULL_LOOKUP_INVALID; prerequisite failures identify stage and pendingFiles.
Do not confuse a local guard rejecting invalid data with Fanavaran accepting the
whole claim: downstream conditional rules remain authoritative.
@@ -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();