@valentine-efagene/qshelter-common 2.0.29 → 2.0.31
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 +20 -0
- package/dist/generated/client/client.d.ts +20 -0
- package/dist/generated/client/commonInputTypes.d.ts +531 -51
- package/dist/generated/client/enums.d.ts +133 -0
- package/dist/generated/client/enums.js +117 -0
- package/dist/generated/client/internal/class.d.ts +44 -0
- package/dist/generated/client/internal/class.js +2 -2
- package/dist/generated/client/internal/prismaNamespace.d.ts +478 -35
- package/dist/generated/client/internal/prismaNamespace.js +139 -36
- package/dist/generated/client/internal/prismaNamespaceBrowser.d.ts +146 -35
- package/dist/generated/client/internal/prismaNamespaceBrowser.js +139 -36
- package/dist/generated/client/models/Contract.d.ts +423 -148
- package/dist/generated/client/models/ContractDocument.d.ts +32 -28
- package/dist/generated/client/models/ContractInstallment.d.ts +30 -26
- package/dist/generated/client/models/ContractPayment.d.ts +44 -40
- package/dist/generated/client/models/ContractPhase.d.ts +539 -121
- package/dist/generated/client/models/ContractPhaseStep.d.ts +208 -108
- package/dist/generated/client/models/ContractPhaseStepApproval.d.ts +32 -28
- package/dist/generated/client/models/ContractPhaseStepDocument.d.ts +1052 -0
- package/dist/generated/client/models/ContractPhaseStepDocument.js +1 -0
- package/dist/generated/client/models/ContractTermination.d.ts +3449 -0
- package/dist/generated/client/models/ContractTermination.js +1 -0
- package/dist/generated/client/models/PaymentMethodPhaseDocument.d.ts +1216 -0
- package/dist/generated/client/models/PaymentMethodPhaseDocument.js +1 -0
- package/dist/generated/client/models/PaymentMethodPhaseStep.d.ts +1187 -0
- package/dist/generated/client/models/PaymentMethodPhaseStep.js +1 -0
- package/dist/generated/client/models/PaymentPlan.d.ts +34 -30
- package/dist/generated/client/models/PropertyPaymentMethodPhase.d.ts +504 -135
- package/dist/generated/client/models/Tenant.d.ts +163 -0
- package/dist/generated/client/models/User.d.ts +586 -0
- package/dist/generated/client/models/index.d.ts +4 -0
- package/dist/generated/client/models/index.js +4 -0
- package/dist/generated/client/models.d.ts +4 -0
- package/package.json +1 -1
- package/prisma/migrations/20260101081428_normalize_schema/migration.sql +119 -0
- package/prisma/migrations/20260101102022_add_contract_termination/migration.sql +69 -0
- package/prisma/schema.prisma +340 -30
package/prisma/schema.prisma
CHANGED
|
@@ -15,6 +15,147 @@ datasource db {
|
|
|
15
15
|
provider = "mysql"
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// ENUMS - Database-enforced value constraints
|
|
20
|
+
// =============================================================================
|
|
21
|
+
|
|
22
|
+
enum PhaseCategory {
|
|
23
|
+
DOCUMENTATION
|
|
24
|
+
PAYMENT
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
enum PhaseType {
|
|
28
|
+
KYC
|
|
29
|
+
VERIFICATION
|
|
30
|
+
DOWNPAYMENT
|
|
31
|
+
MORTGAGE
|
|
32
|
+
BALLOON
|
|
33
|
+
CUSTOM
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
enum PaymentFrequency {
|
|
37
|
+
MONTHLY
|
|
38
|
+
BIWEEKLY
|
|
39
|
+
WEEKLY
|
|
40
|
+
ONE_TIME
|
|
41
|
+
CUSTOM
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
enum ContractStatus {
|
|
45
|
+
DRAFT
|
|
46
|
+
PENDING
|
|
47
|
+
ACTIVE
|
|
48
|
+
COMPLETED
|
|
49
|
+
CANCELLED
|
|
50
|
+
TERMINATED
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
enum PhaseStatus {
|
|
54
|
+
PENDING
|
|
55
|
+
IN_PROGRESS
|
|
56
|
+
AWAITING_APPROVAL
|
|
57
|
+
ACTIVE
|
|
58
|
+
COMPLETED
|
|
59
|
+
SKIPPED
|
|
60
|
+
FAILED
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
enum StepType {
|
|
64
|
+
UPLOAD
|
|
65
|
+
REVIEW
|
|
66
|
+
SIGNATURE
|
|
67
|
+
APPROVAL
|
|
68
|
+
EXTERNAL_CHECK
|
|
69
|
+
WAIT
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
enum StepStatus {
|
|
73
|
+
PENDING
|
|
74
|
+
IN_PROGRESS
|
|
75
|
+
COMPLETED
|
|
76
|
+
FAILED
|
|
77
|
+
SKIPPED
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
enum InstallmentStatus {
|
|
81
|
+
PENDING
|
|
82
|
+
PAID
|
|
83
|
+
OVERDUE
|
|
84
|
+
PARTIALLY_PAID
|
|
85
|
+
WAIVED
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
enum PaymentStatus {
|
|
89
|
+
INITIATED
|
|
90
|
+
PENDING
|
|
91
|
+
COMPLETED
|
|
92
|
+
FAILED
|
|
93
|
+
REFUNDED
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
enum ApprovalDecision {
|
|
97
|
+
APPROVED
|
|
98
|
+
REJECTED
|
|
99
|
+
REQUEST_CHANGES
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// =============================================================================
|
|
103
|
+
// CONTRACT TERMINATION / CANCELLATION ENUMS
|
|
104
|
+
// =============================================================================
|
|
105
|
+
|
|
106
|
+
enum TerminationType {
|
|
107
|
+
BUYER_WITHDRAWAL // Buyer wants to cancel (voluntary)
|
|
108
|
+
SELLER_WITHDRAWAL // Seller/developer cancels
|
|
109
|
+
MUTUAL_AGREEMENT // Both parties agree to terminate
|
|
110
|
+
PAYMENT_DEFAULT // Buyer failed payment obligations
|
|
111
|
+
DOCUMENT_FAILURE // Buyer failed to provide required documents
|
|
112
|
+
FRAUD // Fraudulent activity detected
|
|
113
|
+
FORCE_MAJEURE // External circumstances (disaster, etc.)
|
|
114
|
+
PROPERTY_UNAVAILABLE // Property no longer available
|
|
115
|
+
REGULATORY // Regulatory/legal requirement
|
|
116
|
+
OTHER // Other reasons (with notes)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
enum TerminationStatus {
|
|
120
|
+
REQUESTED // Initial request submitted
|
|
121
|
+
PENDING_REVIEW // Awaiting admin review
|
|
122
|
+
PENDING_REFUND // Approved, awaiting refund processing
|
|
123
|
+
REFUND_IN_PROGRESS // Refund being processed
|
|
124
|
+
REFUND_COMPLETED // Refund completed
|
|
125
|
+
COMPLETED // Termination fully executed (no refund or refund done)
|
|
126
|
+
REJECTED // Termination request rejected
|
|
127
|
+
CANCELLED // Termination request was cancelled
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
enum RefundStatus {
|
|
131
|
+
NOT_APPLICABLE // No refund needed (no payments made)
|
|
132
|
+
PENDING // Refund not yet initiated
|
|
133
|
+
INITIATED // Refund request sent to payment gateway
|
|
134
|
+
PROCESSING // Gateway processing refund
|
|
135
|
+
PARTIAL_COMPLETED // Some refund completed (penalties deducted)
|
|
136
|
+
COMPLETED // Full refund completed
|
|
137
|
+
FAILED // Refund failed (needs manual intervention)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
enum TerminationInitiator {
|
|
141
|
+
BUYER
|
|
142
|
+
SELLER
|
|
143
|
+
ADMIN
|
|
144
|
+
SYSTEM
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
enum CompletionCriterion {
|
|
148
|
+
DOCUMENT_APPROVALS
|
|
149
|
+
PAYMENT_AMOUNT
|
|
150
|
+
STEPS_COMPLETED
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
enum DocumentStatus {
|
|
154
|
+
PENDING
|
|
155
|
+
APPROVED
|
|
156
|
+
REJECTED
|
|
157
|
+
}
|
|
158
|
+
|
|
18
159
|
// =============================================================================
|
|
19
160
|
// USER & AUTH DOMAIN
|
|
20
161
|
// =============================================================================
|
|
@@ -64,6 +205,10 @@ model User {
|
|
|
64
205
|
paymentMethodChangeRequests PaymentMethodChangeRequest[] @relation("ChangeRequestor")
|
|
65
206
|
reviewedChangeRequests PaymentMethodChangeRequest[] @relation("ChangeReviewer")
|
|
66
207
|
|
|
208
|
+
// Contract terminations
|
|
209
|
+
initiatedTerminations ContractTermination[] @relation("TerminationInitiator")
|
|
210
|
+
reviewedTerminations ContractTermination[] @relation("TerminationReviewer")
|
|
211
|
+
|
|
67
212
|
@@index([email])
|
|
68
213
|
@@index([tenantId])
|
|
69
214
|
@@map("users")
|
|
@@ -138,6 +283,9 @@ model Tenant {
|
|
|
138
283
|
paymentMethodChangeRequests PaymentMethodChangeRequest[]
|
|
139
284
|
documentRequirementRules DocumentRequirementRule[]
|
|
140
285
|
|
|
286
|
+
// Contract terminations
|
|
287
|
+
contractTerminations ContractTermination[]
|
|
288
|
+
|
|
141
289
|
@@index([subdomain])
|
|
142
290
|
@@map("tenants")
|
|
143
291
|
}
|
|
@@ -515,11 +663,11 @@ model PaymentPlan {
|
|
|
515
663
|
isActive Boolean @default(true)
|
|
516
664
|
|
|
517
665
|
// Structure configuration
|
|
518
|
-
paymentFrequency
|
|
666
|
+
paymentFrequency PaymentFrequency
|
|
519
667
|
customFrequencyDays Int?
|
|
520
668
|
numberOfInstallments Int // 1 for one-time, 360 for 30yr monthly, etc
|
|
521
|
-
calculateInterestDaily Boolean
|
|
522
|
-
gracePeriodDays Int
|
|
669
|
+
calculateInterestDaily Boolean @default(false)
|
|
670
|
+
gracePeriodDays Int @default(0)
|
|
523
671
|
|
|
524
672
|
createdAt DateTime @default(now())
|
|
525
673
|
updatedAt DateTime @updatedAt
|
|
@@ -608,9 +756,9 @@ model PropertyPaymentMethodPhase {
|
|
|
608
756
|
name String
|
|
609
757
|
description String? @db.Text
|
|
610
758
|
|
|
611
|
-
// Phase classification
|
|
612
|
-
phaseCategory
|
|
613
|
-
phaseType
|
|
759
|
+
// Phase classification (DB-enforced enums)
|
|
760
|
+
phaseCategory PhaseCategory
|
|
761
|
+
phaseType PhaseType
|
|
614
762
|
order Int
|
|
615
763
|
|
|
616
764
|
// Financial configuration (for PAYMENT phases)
|
|
@@ -618,22 +766,64 @@ model PropertyPaymentMethodPhase {
|
|
|
618
766
|
percentOfPrice Float? // e.g., 10.0 for 10% downpayment
|
|
619
767
|
|
|
620
768
|
// Activation rules
|
|
621
|
-
requiresPreviousPhaseCompletion Boolean
|
|
769
|
+
requiresPreviousPhaseCompletion Boolean @default(true)
|
|
622
770
|
minimumCompletionPercentage Float?
|
|
771
|
+
completionCriterion CompletionCriterion?
|
|
623
772
|
|
|
624
|
-
//
|
|
625
|
-
|
|
626
|
-
|
|
773
|
+
// Snapshots for audit (original config at creation time)
|
|
774
|
+
stepDefinitionsSnapshot Json?
|
|
775
|
+
requiredDocumentSnapshot Json?
|
|
627
776
|
|
|
628
777
|
createdAt DateTime @default(now())
|
|
629
778
|
updatedAt DateTime @updatedAt
|
|
630
779
|
|
|
780
|
+
// Normalized child tables (for DOCUMENTATION phases)
|
|
781
|
+
steps PaymentMethodPhaseStep[]
|
|
782
|
+
requiredDocuments PaymentMethodPhaseDocument[]
|
|
783
|
+
|
|
631
784
|
@@index([paymentMethodId])
|
|
632
785
|
@@index([paymentPlanId])
|
|
633
786
|
@@index([phaseCategory])
|
|
634
787
|
@@map("property_payment_method_phases")
|
|
635
788
|
}
|
|
636
789
|
|
|
790
|
+
// Step template within a DOCUMENTATION phase
|
|
791
|
+
model PaymentMethodPhaseStep {
|
|
792
|
+
id String @id @default(cuid())
|
|
793
|
+
phaseId String
|
|
794
|
+
phase PropertyPaymentMethodPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
|
|
795
|
+
|
|
796
|
+
name String
|
|
797
|
+
stepType StepType
|
|
798
|
+
order Int
|
|
799
|
+
|
|
800
|
+
metadata Json?
|
|
801
|
+
createdAt DateTime @default(now())
|
|
802
|
+
updatedAt DateTime @updatedAt
|
|
803
|
+
|
|
804
|
+
@@index([phaseId])
|
|
805
|
+
@@map("payment_method_phase_steps")
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Required document within a DOCUMENTATION phase
|
|
809
|
+
model PaymentMethodPhaseDocument {
|
|
810
|
+
id String @id @default(cuid())
|
|
811
|
+
phaseId String
|
|
812
|
+
phase PropertyPaymentMethodPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
|
|
813
|
+
|
|
814
|
+
documentType String
|
|
815
|
+
isRequired Boolean @default(true)
|
|
816
|
+
description String? @db.Text
|
|
817
|
+
allowedMimeTypes String? // CSV: application/pdf,image/jpeg
|
|
818
|
+
maxSizeBytes Int?
|
|
819
|
+
|
|
820
|
+
metadata Json?
|
|
821
|
+
createdAt DateTime @default(now())
|
|
822
|
+
|
|
823
|
+
@@index([phaseId, documentType])
|
|
824
|
+
@@map("payment_method_phase_documents")
|
|
825
|
+
}
|
|
826
|
+
|
|
637
827
|
// =============================================================================
|
|
638
828
|
// CONTRACT DOMAIN - Unified agreement model (replaces Mortgage, PurchasePlan, etc.)
|
|
639
829
|
// =============================================================================
|
|
@@ -673,9 +863,9 @@ model Contract {
|
|
|
673
863
|
totalPaidToDate Float @default(0)
|
|
674
864
|
totalInterestPaid Float @default(0)
|
|
675
865
|
|
|
676
|
-
// FSM state
|
|
677
|
-
status
|
|
678
|
-
state
|
|
866
|
+
// FSM state (DB-enforced enums)
|
|
867
|
+
status ContractStatus @default(DRAFT)
|
|
868
|
+
state ContractStatus @default(DRAFT) // FSM state for workflow
|
|
679
869
|
currentPhaseId String?
|
|
680
870
|
|
|
681
871
|
// Timing
|
|
@@ -694,6 +884,7 @@ model Contract {
|
|
|
694
884
|
payments ContractPayment[]
|
|
695
885
|
transitions ContractTransition[]
|
|
696
886
|
events ContractEvent[]
|
|
887
|
+
terminations ContractTermination[]
|
|
697
888
|
|
|
698
889
|
// Prequalification that led to this contract (optional)
|
|
699
890
|
prequalification Prequalification?
|
|
@@ -723,13 +914,13 @@ model ContractPhase {
|
|
|
723
914
|
name String
|
|
724
915
|
description String? @db.Text
|
|
725
916
|
|
|
726
|
-
// Phase classification
|
|
727
|
-
phaseCategory
|
|
728
|
-
phaseType
|
|
917
|
+
// Phase classification (DB-enforced enums)
|
|
918
|
+
phaseCategory PhaseCategory
|
|
919
|
+
phaseType PhaseType
|
|
729
920
|
order Int
|
|
730
921
|
|
|
731
|
-
// FSM state for this phase
|
|
732
|
-
status
|
|
922
|
+
// FSM state for this phase (DB-enforced enum)
|
|
923
|
+
status PhaseStatus @default(PENDING)
|
|
733
924
|
|
|
734
925
|
// Financial details (for PAYMENT phases)
|
|
735
926
|
totalAmount Float?
|
|
@@ -737,6 +928,12 @@ model ContractPhase {
|
|
|
737
928
|
remainingAmount Float?
|
|
738
929
|
interestRate Float?
|
|
739
930
|
|
|
931
|
+
// Progress counters (for efficient activation checks)
|
|
932
|
+
approvedDocumentsCount Int @default(0)
|
|
933
|
+
requiredDocumentsCount Int @default(0)
|
|
934
|
+
completedStepsCount Int @default(0)
|
|
935
|
+
totalStepsCount Int @default(0)
|
|
936
|
+
|
|
740
937
|
// Timing
|
|
741
938
|
dueDate DateTime?
|
|
742
939
|
startDate DateTime?
|
|
@@ -745,8 +942,14 @@ model ContractPhase {
|
|
|
745
942
|
completedAt DateTime?
|
|
746
943
|
|
|
747
944
|
// Activation rules
|
|
748
|
-
requiresPreviousPhaseCompletion Boolean
|
|
945
|
+
requiresPreviousPhaseCompletion Boolean @default(true)
|
|
749
946
|
minimumCompletionPercentage Float?
|
|
947
|
+
completionCriterion CompletionCriterion?
|
|
948
|
+
|
|
949
|
+
// Snapshots for audit (effective config at contract creation)
|
|
950
|
+
paymentPlanSnapshot Json?
|
|
951
|
+
stepDefinitionsSnapshot Json?
|
|
952
|
+
requiredDocumentSnapshot Json?
|
|
750
953
|
|
|
751
954
|
createdAt DateTime @default(now())
|
|
752
955
|
updatedAt DateTime @updatedAt
|
|
@@ -771,18 +974,18 @@ model ContractPhaseStep {
|
|
|
771
974
|
phase ContractPhase @relation(fields: [phaseId], references: [id], onDelete: Cascade)
|
|
772
975
|
|
|
773
976
|
name String
|
|
774
|
-
description String?
|
|
775
|
-
stepType
|
|
977
|
+
description String? @db.Text
|
|
978
|
+
stepType StepType
|
|
776
979
|
order Int
|
|
777
980
|
|
|
778
|
-
status
|
|
981
|
+
status StepStatus @default(PENDING)
|
|
779
982
|
|
|
780
983
|
// Assignment
|
|
781
984
|
assigneeId String?
|
|
782
985
|
assignee User? @relation("PhaseStepAssignee", fields: [assigneeId], references: [id])
|
|
783
986
|
|
|
784
|
-
// Required document types for UPLOAD steps
|
|
785
|
-
|
|
987
|
+
// Required document types for UPLOAD steps (normalized)
|
|
988
|
+
requiredDocuments ContractPhaseStepDocument[]
|
|
786
989
|
|
|
787
990
|
// Timing
|
|
788
991
|
dueDate DateTime?
|
|
@@ -799,6 +1002,21 @@ model ContractPhaseStep {
|
|
|
799
1002
|
@@map("contract_phase_steps")
|
|
800
1003
|
}
|
|
801
1004
|
|
|
1005
|
+
// Required documents for a step (normalized from CSV)
|
|
1006
|
+
model ContractPhaseStepDocument {
|
|
1007
|
+
id String @id @default(cuid())
|
|
1008
|
+
stepId String
|
|
1009
|
+
step ContractPhaseStep @relation(fields: [stepId], references: [id], onDelete: Cascade)
|
|
1010
|
+
|
|
1011
|
+
documentType String
|
|
1012
|
+
isRequired Boolean @default(true)
|
|
1013
|
+
|
|
1014
|
+
createdAt DateTime @default(now())
|
|
1015
|
+
|
|
1016
|
+
@@index([stepId, documentType])
|
|
1017
|
+
@@map("contract_phase_step_documents")
|
|
1018
|
+
}
|
|
1019
|
+
|
|
802
1020
|
// Approvals for documentation steps
|
|
803
1021
|
model ContractPhaseStepApproval {
|
|
804
1022
|
id String @id @default(cuid())
|
|
@@ -807,9 +1025,9 @@ model ContractPhaseStepApproval {
|
|
|
807
1025
|
approverId String?
|
|
808
1026
|
approver User? @relation("PhaseStepApprover", fields: [approverId], references: [id])
|
|
809
1027
|
|
|
810
|
-
decision
|
|
811
|
-
comment String?
|
|
812
|
-
decidedAt DateTime
|
|
1028
|
+
decision ApprovalDecision
|
|
1029
|
+
comment String? @db.Text
|
|
1030
|
+
decidedAt DateTime @default(now())
|
|
813
1031
|
|
|
814
1032
|
createdAt DateTime @default(now())
|
|
815
1033
|
|
|
@@ -830,7 +1048,7 @@ model ContractInstallment {
|
|
|
830
1048
|
interestAmount Float @default(0)
|
|
831
1049
|
|
|
832
1050
|
dueDate DateTime
|
|
833
|
-
status
|
|
1051
|
+
status InstallmentStatus @default(PENDING)
|
|
834
1052
|
|
|
835
1053
|
paidAmount Float @default(0)
|
|
836
1054
|
paidDate DateTime?
|
|
@@ -869,7 +1087,7 @@ model ContractPayment {
|
|
|
869
1087
|
lateFeeAmount Float @default(0)
|
|
870
1088
|
|
|
871
1089
|
paymentMethod String // BANK_TRANSFER, CREDIT_CARD, WALLET, CASH, CHECK
|
|
872
|
-
status
|
|
1090
|
+
status PaymentStatus @default(INITIATED)
|
|
873
1091
|
|
|
874
1092
|
reference String? @unique
|
|
875
1093
|
gatewayResponse String? @db.Text // JSON
|
|
@@ -901,7 +1119,7 @@ model ContractDocument {
|
|
|
901
1119
|
uploadedById String?
|
|
902
1120
|
uploadedBy User? @relation("DocumentUploader", fields: [uploadedById], references: [id])
|
|
903
1121
|
|
|
904
|
-
status
|
|
1122
|
+
status DocumentStatus @default(PENDING)
|
|
905
1123
|
|
|
906
1124
|
createdAt DateTime @default(now())
|
|
907
1125
|
updatedAt DateTime @updatedAt
|
|
@@ -942,6 +1160,98 @@ model ContractEvent {
|
|
|
942
1160
|
@@map("contract_events")
|
|
943
1161
|
}
|
|
944
1162
|
|
|
1163
|
+
// =============================================================================
|
|
1164
|
+
// CONTRACT TERMINATION - Full lifecycle for cancellation/termination
|
|
1165
|
+
// =============================================================================
|
|
1166
|
+
// Tracks termination requests from initiation through refund completion.
|
|
1167
|
+
// Industry-standard flow:
|
|
1168
|
+
// 1. Request created (by buyer/seller/admin/system)
|
|
1169
|
+
// 2. Admin reviews (if required by policy)
|
|
1170
|
+
// 3. Financial settlement calculated (refunds, penalties, forfeitures)
|
|
1171
|
+
// 4. Refund processed (if applicable)
|
|
1172
|
+
// 5. Contract marked terminated, unit released
|
|
1173
|
+
// =============================================================================
|
|
1174
|
+
|
|
1175
|
+
model ContractTermination {
|
|
1176
|
+
id String @id @default(cuid())
|
|
1177
|
+
contractId String
|
|
1178
|
+
contract Contract @relation(fields: [contractId], references: [id], onDelete: Cascade)
|
|
1179
|
+
tenantId String
|
|
1180
|
+
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1181
|
+
|
|
1182
|
+
// Request identification
|
|
1183
|
+
requestNumber String @unique // TRM-XXXXXX
|
|
1184
|
+
|
|
1185
|
+
// Who initiated and why
|
|
1186
|
+
initiatedBy TerminationInitiator
|
|
1187
|
+
initiatorId String? // userId if BUYER/SELLER/ADMIN
|
|
1188
|
+
initiator User? @relation("TerminationInitiator", fields: [initiatorId], references: [id])
|
|
1189
|
+
type TerminationType
|
|
1190
|
+
reason String? @db.Text
|
|
1191
|
+
supportingDocs Json? // [{type, url, uploadedAt}]
|
|
1192
|
+
|
|
1193
|
+
// Workflow status
|
|
1194
|
+
status TerminationStatus @default(REQUESTED)
|
|
1195
|
+
requiresApproval Boolean @default(true)
|
|
1196
|
+
autoApproveEligible Boolean @default(false) // Pre-signature, no payments
|
|
1197
|
+
|
|
1198
|
+
// Admin review
|
|
1199
|
+
reviewedBy String?
|
|
1200
|
+
reviewer User? @relation("TerminationReviewer", fields: [reviewedBy], references: [id])
|
|
1201
|
+
reviewedAt DateTime?
|
|
1202
|
+
reviewNotes String? @db.Text
|
|
1203
|
+
rejectionReason String? @db.Text
|
|
1204
|
+
|
|
1205
|
+
// Financial snapshot at time of request
|
|
1206
|
+
contractSnapshot Json // Full contract state snapshot
|
|
1207
|
+
totalContractAmount Float
|
|
1208
|
+
totalPaidToDate Float
|
|
1209
|
+
outstandingBalance Float
|
|
1210
|
+
|
|
1211
|
+
// Settlement calculation
|
|
1212
|
+
refundableAmount Float @default(0) // Amount eligible for refund
|
|
1213
|
+
penaltyAmount Float @default(0) // Penalties/fees to deduct
|
|
1214
|
+
forfeitedAmount Float @default(0) // Amount forfeited (non-refundable deposits)
|
|
1215
|
+
adminFeeAmount Float @default(0) // Processing fees
|
|
1216
|
+
netRefundAmount Float @default(0) // refundableAmount - penaltyAmount - adminFeeAmount
|
|
1217
|
+
settlementNotes String? @db.Text
|
|
1218
|
+
|
|
1219
|
+
// Refund processing
|
|
1220
|
+
refundStatus RefundStatus @default(NOT_APPLICABLE)
|
|
1221
|
+
refundReference String? // Payment gateway reference
|
|
1222
|
+
refundMethod String? // ORIGINAL_METHOD, BANK_TRANSFER, CHECK, WALLET
|
|
1223
|
+
refundAccountDetails Json? // Encrypted bank details if needed
|
|
1224
|
+
refundInitiatedAt DateTime?
|
|
1225
|
+
refundCompletedAt DateTime?
|
|
1226
|
+
refundFailureReason String? @db.Text
|
|
1227
|
+
|
|
1228
|
+
// Property unit handling
|
|
1229
|
+
unitReleasedAt DateTime?
|
|
1230
|
+
unitReservedForId String? // If unit being held for another buyer
|
|
1231
|
+
|
|
1232
|
+
// Timing
|
|
1233
|
+
requestedAt DateTime @default(now())
|
|
1234
|
+
approvedAt DateTime?
|
|
1235
|
+
executedAt DateTime?
|
|
1236
|
+
completedAt DateTime?
|
|
1237
|
+
cancelledAt DateTime?
|
|
1238
|
+
|
|
1239
|
+
// Idempotency and audit
|
|
1240
|
+
idempotencyKey String? @unique
|
|
1241
|
+
metadata Json?
|
|
1242
|
+
|
|
1243
|
+
createdAt DateTime @default(now())
|
|
1244
|
+
updatedAt DateTime @updatedAt
|
|
1245
|
+
|
|
1246
|
+
@@index([contractId])
|
|
1247
|
+
@@index([tenantId])
|
|
1248
|
+
@@index([status])
|
|
1249
|
+
@@index([type])
|
|
1250
|
+
@@index([initiatorId])
|
|
1251
|
+
@@index([requestedAt])
|
|
1252
|
+
@@map("contract_terminations")
|
|
1253
|
+
}
|
|
1254
|
+
|
|
945
1255
|
// =============================================================================
|
|
946
1256
|
// PREQUALIFICATION - Eligibility assessment before contract creation
|
|
947
1257
|
// =============================================================================
|