@valentine-efagene/qshelter-common 2.0.93 → 2.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/client/browser.d.ts +16 -16
- package/dist/generated/client/client.d.ts +16 -16
- package/dist/generated/client/commonInputTypes.d.ts +72 -72
- package/dist/generated/client/enums.d.ts +13 -13
- package/dist/generated/client/enums.js +10 -10
- package/dist/generated/client/internal/class.d.ts +32 -32
- package/dist/generated/client/internal/class.js +2 -2
- package/dist/generated/client/internal/prismaNamespace.d.ts +328 -321
- package/dist/generated/client/internal/prismaNamespace.js +57 -50
- package/dist/generated/client/internal/prismaNamespaceBrowser.d.ts +73 -66
- package/dist/generated/client/internal/prismaNamespaceBrowser.js +57 -50
- package/dist/generated/client/models/Application.d.ts +5439 -0
- package/dist/generated/client/models/Application.js +1 -0
- package/dist/generated/client/models/ApplicationDocument.d.ts +1409 -0
- package/dist/generated/client/models/ApplicationDocument.js +1 -0
- package/dist/generated/client/models/ApplicationEvent.d.ts +1254 -0
- package/dist/generated/client/models/ApplicationEvent.js +1 -0
- package/dist/generated/client/models/ApplicationPayment.d.ts +2030 -0
- package/dist/generated/client/models/ApplicationPayment.js +1 -0
- package/dist/generated/client/models/ApplicationPhase.d.ts +2243 -0
- package/dist/generated/client/models/ApplicationPhase.js +1 -0
- package/dist/generated/client/models/ApplicationRefund.d.ts +2560 -0
- package/dist/generated/client/models/ApplicationRefund.js +1 -0
- package/dist/generated/client/models/ApplicationTermination.d.ts +3446 -0
- package/dist/generated/client/models/ApplicationTermination.js +1 -0
- package/dist/generated/client/models/DocumentationPhase.d.ts +13 -13
- package/dist/generated/client/models/OfferLetter.d.ts +97 -97
- package/dist/generated/client/models/PaymentInstallment.d.ts +1660 -0
- package/dist/generated/client/models/PaymentInstallment.js +1 -0
- package/dist/generated/client/models/PaymentMethodChangeRequest.d.ts +103 -103
- package/dist/generated/client/models/PaymentPhase.d.ts +135 -41
- package/dist/generated/client/models/PaymentPlan.d.ts +259 -30
- package/dist/generated/client/models/PropertyPaymentMethod.d.ts +77 -77
- package/dist/generated/client/models/PropertyTransferRequest.d.ts +213 -213
- package/dist/generated/client/models/PropertyUnit.d.ts +53 -53
- package/dist/generated/client/models/QuestionnairePhase.d.ts +11 -11
- package/dist/generated/client/models/Tenant.d.ts +323 -323
- package/dist/generated/client/models/User.d.ts +1329 -1329
- package/dist/generated/client/models/index.d.ts +8 -8
- package/dist/generated/client/models/index.js +8 -8
- package/dist/generated/client/models.d.ts +8 -8
- package/package.json +1 -1
- package/prisma/migrations/20260112041159_add_flexible_term_configuration/migration.sql +11 -0
- package/prisma/migrations/20260112080730_rename_contract_to_application/migration.sql +529 -0
- package/prisma/schema.prisma +123 -108
- package/prisma/schema.prisma.backup +2601 -0
package/prisma/schema.prisma
CHANGED
|
@@ -51,14 +51,14 @@ enum PaymentFrequency {
|
|
|
51
51
|
CUSTOM
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
enum
|
|
54
|
+
enum ApplicationStatus {
|
|
55
55
|
DRAFT
|
|
56
56
|
PENDING
|
|
57
57
|
ACTIVE
|
|
58
58
|
COMPLETED
|
|
59
59
|
CANCELLED
|
|
60
60
|
TERMINATED
|
|
61
|
-
TRANSFERRED //
|
|
61
|
+
TRANSFERRED // Application was transferred to a different property
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
enum TransferRequestStatus {
|
|
@@ -213,9 +213,9 @@ enum OfferLetterStatus {
|
|
|
213
213
|
CANCELLED
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
enum
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
enum ApplicationEventType {
|
|
217
|
+
APPLICATION_CREATED
|
|
218
|
+
APPLICATION_STATE_CHANGED
|
|
219
219
|
PHASE_ACTIVATED
|
|
220
220
|
PHASE_COMPLETED
|
|
221
221
|
STEP_COMPLETED
|
|
@@ -227,14 +227,14 @@ enum ContractEventType {
|
|
|
227
227
|
PAYMENT_COMPLETED
|
|
228
228
|
PAYMENT_FAILED
|
|
229
229
|
INSTALLMENTS_GENERATED
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
APPLICATION_SIGNED
|
|
231
|
+
APPLICATION_TERMINATED
|
|
232
|
+
APPLICATION_TRANSFERRED
|
|
233
233
|
UNDERWRITING_COMPLETED
|
|
234
234
|
OFFER_LETTER_GENERATED
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
enum
|
|
237
|
+
enum ApplicationEventGroup {
|
|
238
238
|
STATE_CHANGE
|
|
239
239
|
PAYMENT
|
|
240
240
|
DOCUMENT
|
|
@@ -346,22 +346,22 @@ model User {
|
|
|
346
346
|
|
|
347
347
|
// Relations to other domains
|
|
348
348
|
properties Property[]
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
349
|
+
applications Application[] @relation("ApplicationBuyer")
|
|
350
|
+
soldApplications Application[] @relation("ApplicationSeller")
|
|
351
|
+
applicationPayments ApplicationPayment[] @relation("ApplicationPayer")
|
|
352
352
|
|
|
353
353
|
// Documentation step assignments and approvals
|
|
354
354
|
assignedSteps DocumentationStep[] @relation("DocumentationStepAssignee")
|
|
355
355
|
stepApprovals DocumentationStepApproval[] @relation("DocumentationStepApprover")
|
|
356
|
-
uploadedDocs
|
|
356
|
+
uploadedDocs ApplicationDocument[] @relation("DocumentUploader")
|
|
357
357
|
|
|
358
358
|
// Payment method changes
|
|
359
359
|
paymentMethodChangeRequests PaymentMethodChangeRequest[] @relation("ChangeRequestor")
|
|
360
360
|
reviewedChangeRequests PaymentMethodChangeRequest[] @relation("ChangeReviewer")
|
|
361
361
|
|
|
362
362
|
// Contract terminations
|
|
363
|
-
initiatedTerminations
|
|
364
|
-
reviewedTerminations
|
|
363
|
+
initiatedTerminations ApplicationTermination[] @relation("TerminationInitiator")
|
|
364
|
+
reviewedTerminations ApplicationTermination[] @relation("TerminationReviewer")
|
|
365
365
|
|
|
366
366
|
// Offer letters
|
|
367
367
|
offerLettersGenerated OfferLetter[] @relation("OfferLetterGenerator")
|
|
@@ -377,9 +377,9 @@ model User {
|
|
|
377
377
|
approvalRequestsReviewed ApprovalRequest[] @relation("ApprovalReviewer")
|
|
378
378
|
|
|
379
379
|
// Contract refunds
|
|
380
|
-
requestedRefunds
|
|
381
|
-
approvedRefunds
|
|
382
|
-
processedRefunds
|
|
380
|
+
requestedRefunds ApplicationRefund[] @relation("RefundRequester")
|
|
381
|
+
approvedRefunds ApplicationRefund[] @relation("RefundApprover")
|
|
382
|
+
processedRefunds ApplicationRefund[] @relation("RefundProcessor")
|
|
383
383
|
|
|
384
384
|
@@index([email])
|
|
385
385
|
@@index([tenantId])
|
|
@@ -496,7 +496,7 @@ model Tenant {
|
|
|
496
496
|
properties Property[]
|
|
497
497
|
paymentPlans PaymentPlan[]
|
|
498
498
|
paymentMethods PropertyPaymentMethod[]
|
|
499
|
-
|
|
499
|
+
applications Application[]
|
|
500
500
|
|
|
501
501
|
// RBAC: Tenant-scoped roles and permissions
|
|
502
502
|
roles Role[]
|
|
@@ -509,7 +509,7 @@ model Tenant {
|
|
|
509
509
|
documentRequirementRules DocumentRequirementRule[]
|
|
510
510
|
|
|
511
511
|
// Contract terminations
|
|
512
|
-
contractTerminations
|
|
512
|
+
contractTerminations ApplicationTermination[]
|
|
513
513
|
|
|
514
514
|
// Offer letters and templates
|
|
515
515
|
documentTemplates DocumentTemplate[]
|
|
@@ -531,7 +531,7 @@ model Tenant {
|
|
|
531
531
|
approvalRequests ApprovalRequest[]
|
|
532
532
|
|
|
533
533
|
// Contract refunds
|
|
534
|
-
contractRefunds
|
|
534
|
+
contractRefunds ApplicationRefund[]
|
|
535
535
|
|
|
536
536
|
@@index([subdomain])
|
|
537
537
|
@@map("tenants")
|
|
@@ -929,7 +929,7 @@ model PropertyUnit {
|
|
|
929
929
|
updatedAt DateTime @updatedAt
|
|
930
930
|
|
|
931
931
|
// Relations
|
|
932
|
-
|
|
932
|
+
applications Application[]
|
|
933
933
|
|
|
934
934
|
// Transfer requests targeting this unit
|
|
935
935
|
transferRequests PropertyTransferRequest[]
|
|
@@ -968,10 +968,20 @@ model PaymentPlan {
|
|
|
968
968
|
// Structure configuration
|
|
969
969
|
paymentFrequency PaymentFrequency
|
|
970
970
|
customFrequencyDays Int?
|
|
971
|
-
numberOfInstallments Int // 1 for one-time, 360 for 30yr monthly
|
|
971
|
+
numberOfInstallments Int? // Fixed number (1 for one-time, 360 for 30yr monthly) - NULL if flexible
|
|
972
972
|
calculateInterestDaily Boolean @default(false)
|
|
973
973
|
gracePeriodDays Int @default(0)
|
|
974
974
|
|
|
975
|
+
// Flexible term configuration (for user-selectable duration like mortgages)
|
|
976
|
+
// If these are set, numberOfInstallments is ignored and user selects within range
|
|
977
|
+
allowFlexibleTerm Boolean @default(false) // true = user can select term within range
|
|
978
|
+
minTermMonths Int? // e.g., 60 (5 years minimum)
|
|
979
|
+
maxTermMonths Int? // e.g., 360 (30 years maximum)
|
|
980
|
+
termStepMonths Int? // e.g., 12 (increments of 1 year) - NULL = any month allowed
|
|
981
|
+
|
|
982
|
+
// Age-based constraints (for mortgage eligibility)
|
|
983
|
+
maxAgeAtMaturity Int? // e.g., 65 - user's age + term cannot exceed this
|
|
984
|
+
|
|
975
985
|
// Fund collection behavior
|
|
976
986
|
// true = we collect funds via wallet/gateway (e.g., downpayment)
|
|
977
987
|
// false = external payment, we only track/reconcile (e.g., bank mortgage)
|
|
@@ -1017,7 +1027,7 @@ model PropertyPaymentMethod {
|
|
|
1017
1027
|
// Phases that make up this method (templates)
|
|
1018
1028
|
phases PropertyPaymentMethodPhase[]
|
|
1019
1029
|
// Contracts using this method
|
|
1020
|
-
|
|
1030
|
+
applications Application[]
|
|
1021
1031
|
|
|
1022
1032
|
// Payment method change tracking
|
|
1023
1033
|
changeRequestsFrom PaymentMethodChangeRequest[] @relation("ChangeFromMethod")
|
|
@@ -1261,12 +1271,12 @@ model PaymentMethodPhaseField {
|
|
|
1261
1271
|
// =============================================================================
|
|
1262
1272
|
// CONTRACT DOMAIN - Unified agreement model (replaces Mortgage, PurchasePlan, etc.)
|
|
1263
1273
|
// =============================================================================
|
|
1264
|
-
//
|
|
1265
|
-
// that creates
|
|
1274
|
+
// Application is the canonical agreement. "Mortgage" is just a product configuration
|
|
1275
|
+
// that creates an Application with specific phases (documentation, downpayment, long-term payment).
|
|
1266
1276
|
// Phases can be QUESTIONNAIRE, DOCUMENTATION, or PAYMENT.
|
|
1267
1277
|
// =============================================================================
|
|
1268
1278
|
|
|
1269
|
-
model
|
|
1279
|
+
model Application {
|
|
1270
1280
|
id String @id @default(cuid())
|
|
1271
1281
|
tenantId String
|
|
1272
1282
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
@@ -1274,25 +1284,25 @@ model Contract {
|
|
|
1274
1284
|
propertyUnitId String
|
|
1275
1285
|
propertyUnit PropertyUnit @relation(fields: [propertyUnitId], references: [id], onDelete: Cascade)
|
|
1276
1286
|
buyerId String
|
|
1277
|
-
buyer User @relation("
|
|
1287
|
+
buyer User @relation("ApplicationBuyer", fields: [buyerId], references: [id], onDelete: Cascade)
|
|
1278
1288
|
sellerId String?
|
|
1279
|
-
seller User? @relation("
|
|
1289
|
+
seller User? @relation("ApplicationSeller", fields: [sellerId], references: [id])
|
|
1280
1290
|
paymentMethodId String? // PropertyPaymentMethod used to create this contract
|
|
1281
1291
|
paymentMethod PropertyPaymentMethod? @relation(fields: [paymentMethodId], references: [id])
|
|
1282
1292
|
|
|
1283
1293
|
// Contract identification
|
|
1284
|
-
|
|
1294
|
+
applicationNumber String @unique
|
|
1285
1295
|
title String
|
|
1286
1296
|
description String? @db.Text
|
|
1287
|
-
|
|
1297
|
+
applicationType String // Admin-defined: MORTGAGE, INSTALLMENT, RENT_TO_OWN, CASH, LEASE, etc.
|
|
1288
1298
|
|
|
1289
1299
|
// Contract value (negotiated from unit price)
|
|
1290
1300
|
totalAmount Float
|
|
1291
1301
|
|
|
1292
1302
|
// FSM state (DB-enforced enum)
|
|
1293
|
-
status
|
|
1303
|
+
status ApplicationStatus @default(DRAFT)
|
|
1294
1304
|
currentPhaseId String?
|
|
1295
|
-
currentPhase
|
|
1305
|
+
currentPhase ApplicationPhase? @relation("CurrentPhase", fields: [currentPhaseId], references: [id])
|
|
1296
1306
|
|
|
1297
1307
|
// Timing
|
|
1298
1308
|
nextPaymentDueDate DateTime?
|
|
@@ -1305,10 +1315,10 @@ model Contract {
|
|
|
1305
1315
|
updatedAt DateTime @updatedAt
|
|
1306
1316
|
|
|
1307
1317
|
// Relations
|
|
1308
|
-
phases
|
|
1309
|
-
documents
|
|
1310
|
-
payments
|
|
1311
|
-
terminations
|
|
1318
|
+
phases ApplicationPhase[]
|
|
1319
|
+
documents ApplicationDocument[]
|
|
1320
|
+
payments ApplicationPayment[]
|
|
1321
|
+
terminations ApplicationTermination[]
|
|
1312
1322
|
offerLetters OfferLetter[]
|
|
1313
1323
|
|
|
1314
1324
|
// Payment method change requests for this contract
|
|
@@ -1316,19 +1326,19 @@ model Contract {
|
|
|
1316
1326
|
|
|
1317
1327
|
// Transfer tracking - when a contract is transferred to a different property
|
|
1318
1328
|
transferredFromId String? @unique // Source contract if this was created via transfer
|
|
1319
|
-
transferredFrom
|
|
1320
|
-
transferredTo
|
|
1329
|
+
transferredFrom Application? @relation("ApplicationTransfer", fields: [transferredFromId], references: [id])
|
|
1330
|
+
transferredTo Application? @relation("ApplicationTransfer")
|
|
1321
1331
|
|
|
1322
1332
|
// Transfer requests where this contract is the source
|
|
1323
|
-
outgoingTransferRequests PropertyTransferRequest[] @relation("
|
|
1333
|
+
outgoingTransferRequests PropertyTransferRequest[] @relation("SourceApplication")
|
|
1324
1334
|
// Transfer requests where this contract is the target (created after approval)
|
|
1325
|
-
incomingTransferRequests PropertyTransferRequest[] @relation("
|
|
1335
|
+
incomingTransferRequests PropertyTransferRequest[] @relation("TargetApplication")
|
|
1326
1336
|
|
|
1327
1337
|
// Audit trail
|
|
1328
|
-
events
|
|
1338
|
+
events ApplicationEvent[]
|
|
1329
1339
|
|
|
1330
1340
|
// Refund requests
|
|
1331
|
-
refunds
|
|
1341
|
+
refunds ApplicationRefund[]
|
|
1332
1342
|
|
|
1333
1343
|
@@index([tenantId])
|
|
1334
1344
|
@@index([propertyUnitId])
|
|
@@ -1337,19 +1347,19 @@ model Contract {
|
|
|
1337
1347
|
@@index([paymentMethodId])
|
|
1338
1348
|
@@index([status])
|
|
1339
1349
|
@@index([currentPhaseId])
|
|
1340
|
-
@@map("
|
|
1350
|
+
@@map("applications")
|
|
1341
1351
|
}
|
|
1342
1352
|
|
|
1343
1353
|
// =============================================================================
|
|
1344
1354
|
// CONTRACT REFUNDS - Track refund requests for overpayments or cancellations
|
|
1345
1355
|
// =============================================================================
|
|
1346
|
-
model
|
|
1356
|
+
model ApplicationRefund {
|
|
1347
1357
|
id String @id @default(cuid())
|
|
1348
1358
|
tenantId String
|
|
1349
1359
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1350
1360
|
|
|
1351
|
-
|
|
1352
|
-
|
|
1361
|
+
applicationId String
|
|
1362
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1353
1363
|
|
|
1354
1364
|
amount Float
|
|
1355
1365
|
reason String @db.Text
|
|
@@ -1388,11 +1398,11 @@ model ContractRefund {
|
|
|
1388
1398
|
createdAt DateTime @default(now())
|
|
1389
1399
|
updatedAt DateTime @updatedAt
|
|
1390
1400
|
|
|
1391
|
-
@@index([
|
|
1401
|
+
@@index([applicationId])
|
|
1392
1402
|
@@index([status])
|
|
1393
1403
|
@@index([tenantId])
|
|
1394
1404
|
@@index([requestedById])
|
|
1395
|
-
@@map("
|
|
1405
|
+
@@map("application_refunds")
|
|
1396
1406
|
}
|
|
1397
1407
|
|
|
1398
1408
|
// Phase within a contract - can be DOCUMENTATION or PAYMENT type
|
|
@@ -1400,7 +1410,7 @@ model ContractRefund {
|
|
|
1400
1410
|
// =============================================================================
|
|
1401
1411
|
// CONTRACT PHASE - Base model with polymorphic extensions
|
|
1402
1412
|
// =============================================================================
|
|
1403
|
-
//
|
|
1413
|
+
// ApplicationPhase is the base table with shared fields only.
|
|
1404
1414
|
// Each phase has exactly ONE extension table based on phaseCategory:
|
|
1405
1415
|
// - QUESTIONNAIRE → QuestionnairePhase
|
|
1406
1416
|
// - DOCUMENTATION → DocumentationPhase
|
|
@@ -1408,10 +1418,10 @@ model ContractRefund {
|
|
|
1408
1418
|
// This eliminates nullable field pollution and makes the schema self-documenting.
|
|
1409
1419
|
// =============================================================================
|
|
1410
1420
|
|
|
1411
|
-
model
|
|
1421
|
+
model ApplicationPhase {
|
|
1412
1422
|
id String @id @default(cuid())
|
|
1413
|
-
|
|
1414
|
-
|
|
1423
|
+
applicationId String
|
|
1424
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1415
1425
|
|
|
1416
1426
|
// Admin-defined naming
|
|
1417
1427
|
name String
|
|
@@ -1444,16 +1454,16 @@ model ContractPhase {
|
|
|
1444
1454
|
paymentPhase PaymentPhase?
|
|
1445
1455
|
|
|
1446
1456
|
// Payments can be linked to any phase type (for tracking)
|
|
1447
|
-
payments
|
|
1457
|
+
payments ApplicationPayment[]
|
|
1448
1458
|
|
|
1449
|
-
// Back-relation for
|
|
1450
|
-
|
|
1459
|
+
// Back-relation for applications where this is the current phase
|
|
1460
|
+
currentForApplications Application[] @relation("CurrentPhase")
|
|
1451
1461
|
|
|
1452
|
-
@@index([
|
|
1462
|
+
@@index([applicationId])
|
|
1453
1463
|
@@index([phaseCategory])
|
|
1454
1464
|
@@index([status])
|
|
1455
1465
|
@@index([order])
|
|
1456
|
-
@@map("
|
|
1466
|
+
@@map("application_phases")
|
|
1457
1467
|
}
|
|
1458
1468
|
|
|
1459
1469
|
// =============================================================================
|
|
@@ -1465,7 +1475,7 @@ model ContractPhase {
|
|
|
1465
1475
|
model QuestionnairePhase {
|
|
1466
1476
|
id String @id @default(cuid())
|
|
1467
1477
|
phaseId String @unique
|
|
1468
|
-
phase
|
|
1478
|
+
phase ApplicationPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
|
|
1469
1479
|
|
|
1470
1480
|
// Progress tracking
|
|
1471
1481
|
completedFieldsCount Int @default(0)
|
|
@@ -1499,7 +1509,7 @@ model QuestionnairePhase {
|
|
|
1499
1509
|
model DocumentationPhase {
|
|
1500
1510
|
id String @id @default(cuid())
|
|
1501
1511
|
phaseId String @unique
|
|
1502
|
-
phase
|
|
1512
|
+
phase ApplicationPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
|
|
1503
1513
|
|
|
1504
1514
|
// Current step pointer for UX and orchestration
|
|
1505
1515
|
currentStepId String?
|
|
@@ -1539,7 +1549,7 @@ model DocumentationPhase {
|
|
|
1539
1549
|
model PaymentPhase {
|
|
1540
1550
|
id String @id @default(cuid())
|
|
1541
1551
|
phaseId String @unique
|
|
1542
|
-
phase
|
|
1552
|
+
phase ApplicationPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
|
|
1543
1553
|
|
|
1544
1554
|
// Payment plan reference
|
|
1545
1555
|
paymentPlanId String?
|
|
@@ -1550,6 +1560,11 @@ model PaymentPhase {
|
|
|
1550
1560
|
paidAmount Float @default(0)
|
|
1551
1561
|
interestRate Float @default(0)
|
|
1552
1562
|
|
|
1563
|
+
// User-selected term (for flexible-term plans like mortgages)
|
|
1564
|
+
// These are set when user selects their preferred term at application time
|
|
1565
|
+
selectedTermMonths Int? // User's chosen term (e.g., 240 for 20 years)
|
|
1566
|
+
numberOfInstallments Int? // Calculated from selectedTermMonths and frequency
|
|
1567
|
+
|
|
1553
1568
|
// Fund collection behavior
|
|
1554
1569
|
// true = we collect funds via wallet/gateway (e.g., downpayment)
|
|
1555
1570
|
// false = external payment, we only track/reconcile (e.g., bank mortgage)
|
|
@@ -1565,7 +1580,7 @@ model PaymentPhase {
|
|
|
1565
1580
|
updatedAt DateTime @updatedAt
|
|
1566
1581
|
|
|
1567
1582
|
// Child records
|
|
1568
|
-
installments
|
|
1583
|
+
installments PaymentInstallment[]
|
|
1569
1584
|
|
|
1570
1585
|
@@index([phaseId])
|
|
1571
1586
|
@@index([paymentPlanId])
|
|
@@ -1628,18 +1643,18 @@ model QuestionnaireField {
|
|
|
1628
1643
|
// =============================================================================
|
|
1629
1644
|
// Tracks all significant events in a contract's lifecycle for audit, compliance,
|
|
1630
1645
|
// and debugging. Unlike DomainEvent (which is for inter-service communication),
|
|
1631
|
-
//
|
|
1646
|
+
// ApplicationEvent is purely for historical tracking and state machine transitions.
|
|
1632
1647
|
// =============================================================================
|
|
1633
|
-
model
|
|
1648
|
+
model ApplicationEvent {
|
|
1634
1649
|
id String @id @default(cuid())
|
|
1635
|
-
|
|
1636
|
-
|
|
1650
|
+
applicationId String
|
|
1651
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1637
1652
|
|
|
1638
1653
|
// Event classification
|
|
1639
|
-
eventType
|
|
1640
|
-
eventGroup
|
|
1654
|
+
eventType ApplicationEventType
|
|
1655
|
+
eventGroup ApplicationEventGroup?
|
|
1641
1656
|
|
|
1642
|
-
// For state transitions (optional - only populated for
|
|
1657
|
+
// For state transitions (optional - only populated for APPLICATION_STATE_CHANGED events)
|
|
1643
1658
|
fromState String?
|
|
1644
1659
|
toState String?
|
|
1645
1660
|
trigger String?
|
|
@@ -1654,11 +1669,11 @@ model ContractEvent {
|
|
|
1654
1669
|
// Timing
|
|
1655
1670
|
occurredAt DateTime @default(now())
|
|
1656
1671
|
|
|
1657
|
-
@@index([
|
|
1672
|
+
@@index([applicationId])
|
|
1658
1673
|
@@index([eventType])
|
|
1659
1674
|
@@index([eventGroup])
|
|
1660
1675
|
@@index([occurredAt])
|
|
1661
|
-
@@map("
|
|
1676
|
+
@@map("application_events")
|
|
1662
1677
|
}
|
|
1663
1678
|
|
|
1664
1679
|
// Steps within a DOCUMENTATION phase (FSM for document collection/approval)
|
|
@@ -1747,7 +1762,7 @@ model DocumentationStepApproval {
|
|
|
1747
1762
|
}
|
|
1748
1763
|
|
|
1749
1764
|
// Installments within a PAYMENT phase
|
|
1750
|
-
model
|
|
1765
|
+
model PaymentInstallment {
|
|
1751
1766
|
id String @id @default(cuid())
|
|
1752
1767
|
paymentPhaseId String
|
|
1753
1768
|
paymentPhase PaymentPhase @relation(fields: [paymentPhaseId], references: [id], onDelete: Cascade)
|
|
@@ -1772,25 +1787,25 @@ model ContractInstallment {
|
|
|
1772
1787
|
createdAt DateTime @default(now())
|
|
1773
1788
|
updatedAt DateTime @updatedAt
|
|
1774
1789
|
|
|
1775
|
-
payments
|
|
1790
|
+
payments ApplicationPayment[]
|
|
1776
1791
|
|
|
1777
1792
|
@@index([paymentPhaseId])
|
|
1778
1793
|
@@index([dueDate])
|
|
1779
1794
|
@@index([status])
|
|
1780
|
-
@@map("
|
|
1795
|
+
@@map("payment_installments")
|
|
1781
1796
|
}
|
|
1782
1797
|
|
|
1783
1798
|
// Unified payment record for contracts
|
|
1784
|
-
model
|
|
1799
|
+
model ApplicationPayment {
|
|
1785
1800
|
id String @id @default(cuid())
|
|
1786
|
-
|
|
1787
|
-
|
|
1801
|
+
applicationId String
|
|
1802
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1788
1803
|
phaseId String?
|
|
1789
|
-
phase
|
|
1804
|
+
phase ApplicationPhase? @relation(fields: [phaseId], references: [id])
|
|
1790
1805
|
installmentId String?
|
|
1791
|
-
installment
|
|
1806
|
+
installment PaymentInstallment? @relation(fields: [installmentId], references: [id])
|
|
1792
1807
|
payerId String?
|
|
1793
|
-
payer User? @relation("
|
|
1808
|
+
payer User? @relation("ApplicationPayer", fields: [payerId], references: [id])
|
|
1794
1809
|
|
|
1795
1810
|
amount Float
|
|
1796
1811
|
principalAmount Float @default(0)
|
|
@@ -1807,20 +1822,20 @@ model ContractPayment {
|
|
|
1807
1822
|
createdAt DateTime @default(now())
|
|
1808
1823
|
updatedAt DateTime @updatedAt
|
|
1809
1824
|
|
|
1810
|
-
@@index([
|
|
1825
|
+
@@index([applicationId])
|
|
1811
1826
|
@@index([phaseId])
|
|
1812
1827
|
@@index([installmentId])
|
|
1813
1828
|
@@index([payerId])
|
|
1814
1829
|
@@index([status])
|
|
1815
1830
|
@@index([reference])
|
|
1816
|
-
@@map("
|
|
1831
|
+
@@map("application_payments")
|
|
1817
1832
|
}
|
|
1818
1833
|
|
|
1819
1834
|
// Contract documents (owned by contract, linked to phases/steps as needed)
|
|
1820
|
-
model
|
|
1835
|
+
model ApplicationDocument {
|
|
1821
1836
|
id String @id @default(cuid())
|
|
1822
|
-
|
|
1823
|
-
|
|
1837
|
+
applicationId String
|
|
1838
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1824
1839
|
phaseId String? // Optional link to specific phase
|
|
1825
1840
|
stepId String? // Optional link to specific step
|
|
1826
1841
|
|
|
@@ -1835,12 +1850,12 @@ model ContractDocument {
|
|
|
1835
1850
|
createdAt DateTime @default(now())
|
|
1836
1851
|
updatedAt DateTime @updatedAt
|
|
1837
1852
|
|
|
1838
|
-
@@index([
|
|
1853
|
+
@@index([applicationId])
|
|
1839
1854
|
@@index([phaseId])
|
|
1840
1855
|
@@index([stepId])
|
|
1841
1856
|
@@index([type])
|
|
1842
1857
|
@@index([status])
|
|
1843
|
-
@@map("
|
|
1858
|
+
@@map("application_documents")
|
|
1844
1859
|
}
|
|
1845
1860
|
|
|
1846
1861
|
// =============================================================================
|
|
@@ -1882,8 +1897,8 @@ model OfferLetter {
|
|
|
1882
1897
|
id String @id @default(cuid())
|
|
1883
1898
|
tenantId String
|
|
1884
1899
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1885
|
-
|
|
1886
|
-
|
|
1900
|
+
applicationId String
|
|
1901
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1887
1902
|
|
|
1888
1903
|
// Template used (optional - documents-service may handle default selection)
|
|
1889
1904
|
templateId String?
|
|
@@ -1925,7 +1940,7 @@ model OfferLetter {
|
|
|
1925
1940
|
updatedAt DateTime @updatedAt
|
|
1926
1941
|
|
|
1927
1942
|
@@index([tenantId])
|
|
1928
|
-
@@index([
|
|
1943
|
+
@@index([applicationId])
|
|
1929
1944
|
@@index([type])
|
|
1930
1945
|
@@index([status])
|
|
1931
1946
|
@@map("offer_letters")
|
|
@@ -1943,10 +1958,10 @@ model OfferLetter {
|
|
|
1943
1958
|
// 5. Contract marked terminated, unit released
|
|
1944
1959
|
// =============================================================================
|
|
1945
1960
|
|
|
1946
|
-
model
|
|
1961
|
+
model ApplicationTermination {
|
|
1947
1962
|
id String @id @default(cuid())
|
|
1948
|
-
|
|
1949
|
-
|
|
1963
|
+
applicationId String
|
|
1964
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
1950
1965
|
tenantId String
|
|
1951
1966
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1952
1967
|
|
|
@@ -1974,8 +1989,8 @@ model ContractTermination {
|
|
|
1974
1989
|
rejectionReason String? @db.Text
|
|
1975
1990
|
|
|
1976
1991
|
// Financial snapshot at time of request
|
|
1977
|
-
|
|
1978
|
-
|
|
1992
|
+
applicationSnapshot Json // Full contract state snapshot
|
|
1993
|
+
totalApplicationAmount Float
|
|
1979
1994
|
totalPaidToDate Float
|
|
1980
1995
|
outstandingBalance Float
|
|
1981
1996
|
|
|
@@ -2014,13 +2029,13 @@ model ContractTermination {
|
|
|
2014
2029
|
createdAt DateTime @default(now())
|
|
2015
2030
|
updatedAt DateTime @updatedAt
|
|
2016
2031
|
|
|
2017
|
-
@@index([
|
|
2032
|
+
@@index([applicationId])
|
|
2018
2033
|
@@index([tenantId])
|
|
2019
2034
|
@@index([status])
|
|
2020
2035
|
@@index([type])
|
|
2021
2036
|
@@index([initiatorId])
|
|
2022
2037
|
@@index([requestedAt])
|
|
2023
|
-
@@map("
|
|
2038
|
+
@@map("application_terminations")
|
|
2024
2039
|
}
|
|
2025
2040
|
|
|
2026
2041
|
// =============================================================================
|
|
@@ -2045,8 +2060,8 @@ model PaymentMethodChangeRequest {
|
|
|
2045
2060
|
id String @id @default(cuid())
|
|
2046
2061
|
tenantId String
|
|
2047
2062
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
2048
|
-
|
|
2049
|
-
|
|
2063
|
+
applicationId String
|
|
2064
|
+
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
|
|
2050
2065
|
|
|
2051
2066
|
// The change being requested
|
|
2052
2067
|
fromPaymentMethodId String
|
|
@@ -2087,7 +2102,7 @@ model PaymentMethodChangeRequest {
|
|
|
2087
2102
|
updatedAt DateTime @updatedAt
|
|
2088
2103
|
|
|
2089
2104
|
@@index([tenantId])
|
|
2090
|
-
@@index([
|
|
2105
|
+
@@index([applicationId])
|
|
2091
2106
|
@@index([status])
|
|
2092
2107
|
@@index([requestorId])
|
|
2093
2108
|
@@map("payment_method_change_requests")
|
|
@@ -2104,7 +2119,7 @@ model PaymentMethodChangeRequest {
|
|
|
2104
2119
|
// =============================================================================
|
|
2105
2120
|
|
|
2106
2121
|
enum DocumentRequirementContext {
|
|
2107
|
-
|
|
2122
|
+
APPLICATION_PHASE // During a contract phase
|
|
2108
2123
|
PAYMENT_METHOD_CHANGE // When changing payment method mid-contract
|
|
2109
2124
|
}
|
|
2110
2125
|
|
|
@@ -2118,7 +2133,7 @@ model DocumentRequirementRule {
|
|
|
2118
2133
|
|
|
2119
2134
|
// Scoping (which situations this rule applies to)
|
|
2120
2135
|
// For PREQUALIFICATION: paymentMethodId
|
|
2121
|
-
// For
|
|
2136
|
+
// For APPLICATION_PHASE: phaseType
|
|
2122
2137
|
// For PAYMENT_METHOD_CHANGE: fromMethodId + toMethodId
|
|
2123
2138
|
paymentMethodId String?
|
|
2124
2139
|
paymentMethod PropertyPaymentMethod? @relation("RulePaymentMethod", fields: [paymentMethodId], references: [id])
|
|
@@ -2445,8 +2460,8 @@ model PropertyTransferRequest {
|
|
|
2445
2460
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
2446
2461
|
|
|
2447
2462
|
// Source contract being transferred
|
|
2448
|
-
|
|
2449
|
-
|
|
2463
|
+
sourceApplicationId String
|
|
2464
|
+
sourceApplication Application @relation("SourceApplication", fields: [sourceApplicationId], references: [id], onDelete: Cascade)
|
|
2450
2465
|
|
|
2451
2466
|
// Target property unit
|
|
2452
2467
|
targetPropertyUnitId String
|
|
@@ -2479,8 +2494,8 @@ model PropertyTransferRequest {
|
|
|
2479
2494
|
refundedAt DateTime?
|
|
2480
2495
|
|
|
2481
2496
|
// Result - new contract created after approval
|
|
2482
|
-
|
|
2483
|
-
|
|
2497
|
+
targetApplicationId String?
|
|
2498
|
+
targetApplication Application? @relation("TargetApplication", fields: [targetApplicationId], references: [id])
|
|
2484
2499
|
|
|
2485
2500
|
// Timestamps
|
|
2486
2501
|
createdAt DateTime @default(now())
|
|
@@ -2489,7 +2504,7 @@ model PropertyTransferRequest {
|
|
|
2489
2504
|
updatedAt DateTime @updatedAt
|
|
2490
2505
|
|
|
2491
2506
|
@@index([tenantId])
|
|
2492
|
-
@@index([
|
|
2507
|
+
@@index([sourceApplicationId])
|
|
2493
2508
|
@@index([targetPropertyUnitId])
|
|
2494
2509
|
@@index([requestedById])
|
|
2495
2510
|
@@index([status])
|
|
@@ -2505,7 +2520,7 @@ enum ApprovalRequestType {
|
|
|
2505
2520
|
PROPERTY_UPDATE // Property/unit listing update requiring approval
|
|
2506
2521
|
USER_WORKFLOW // User workflow step approval
|
|
2507
2522
|
CREDIT_CHECK // Credit check result review
|
|
2508
|
-
|
|
2523
|
+
APPLICATION_TERMINATION // Contract termination approval
|
|
2509
2524
|
REFUND_APPROVAL // Refund request approval
|
|
2510
2525
|
}
|
|
2511
2526
|
|