@@ -323,6 +323,8 @@ pub struct CreditFacility {
323
323
pub activated_at : Option < DateTime < Utc > > ,
324
324
#[ builder( setter( strip_option) , default ) ]
325
325
pub matures_at : Option < DateTime < Utc > > ,
326
+ #[ builder( default ) ]
327
+ pub defaults_at : Option < DateTime < Utc > > ,
326
328
327
329
#[ es_entity( nested) ]
328
330
#[ builder( default ) ]
@@ -500,7 +502,9 @@ impl CreditFacility {
500
502
}
501
503
502
504
pub fn is_defaulted ( & self ) -> bool {
503
- false
505
+ let now = crate :: time:: now ( ) ;
506
+ self . defaults_at
507
+ . is_some_and ( |defaults_at| now > defaults_at)
504
508
}
505
509
506
510
pub fn status ( & self ) -> CreditFacilityStatus {
@@ -563,6 +567,10 @@ impl CreditFacility {
563
567
564
568
self . activated_at = Some ( activated_at) ;
565
569
self . matures_at = Some ( self . terms . duration . maturity_date ( activated_at) ) ;
570
+ self . defaults_at = self
571
+ . terms
572
+ . interest_overdue_duration
573
+ . map ( |d| d. end_date ( self . matures_at . expect ( "No 'matures_at' date set" ) ) ) ;
566
574
let tx_id = LedgerTxId :: new ( ) ;
567
575
self . events . push ( CreditFacilityEvent :: Activated {
568
576
ledger_tx_id : tx_id,
@@ -1158,12 +1166,18 @@ impl TryFromEvents<CreditFacilityEvent> for CreditFacility {
1158
1166
. approval_process_id ( * approval_process_id)
1159
1167
}
1160
1168
CreditFacilityEvent :: Activated { activated_at, .. } => {
1161
- builder = builder. activated_at ( * activated_at) . matures_at (
1162
- terms
1163
- . expect ( "terms should be set" )
1164
- . duration
1165
- . maturity_date ( * activated_at) ,
1166
- )
1169
+ let matures_at = terms
1170
+ . expect ( "terms should be set" )
1171
+ . duration
1172
+ . maturity_date ( * activated_at) ;
1173
+ let defaults_at = terms
1174
+ . expect ( "terms should be set" )
1175
+ . interest_overdue_duration
1176
+ . map ( |d| d. end_date ( matures_at) ) ;
1177
+ builder = builder
1178
+ . activated_at ( * activated_at)
1179
+ . matures_at ( matures_at)
1180
+ . defaults_at ( defaults_at)
1167
1181
}
1168
1182
CreditFacilityEvent :: ApprovalProcessConcluded { .. } => ( ) ,
1169
1183
CreditFacilityEvent :: DisbursalInitiated { .. } => ( ) ,
0 commit comments