@@ -34,7 +34,8 @@ public static string Serialize(Account account)
3434 account . Funds . Select ( f => new FundNode ( f . Id , f . Name , f . ParentId ) ) . ToList ( ) ,
3535 account . Categories . Select ( c => new CategoryNode ( c . Id , c . Name , c . ParentId ) ) . ToList ( ) ,
3636 account . SavingCategories . Select ( s => new SavingCategoryNode ( s . Id , s . Name , s . ParentId , s . GoalAmount , s . AlertThreshold , s . NotifyOnMilestone , s . InitialAmount ) ) . ToList ( ) ,
37- account . Periods . Select ( ToNode ) . ToList ( ) ) ;
37+ account . Periods . Select ( ToNode ) . ToList ( ) ,
38+ account . ContributionCategories . Select ( c => new ContributionCategoryNode ( c . Id , c . Name ) ) . ToList ( ) ) ;
3839 return JsonSerializer . Serialize ( node , Json ) ;
3940 }
4041
@@ -64,6 +65,8 @@ public static Account Deserialize(string payload)
6465 SetField ( account , "_funds" , node . Funds . Select ( f => Build ( new Fund ( f . Name , f . ParentId ) , f . Id ) ) . ToList ( ) ) ;
6566 SetField ( account , "_categories" , node . Categories . Select ( c => Build ( new Category ( c . Name , c . ParentId ) , c . Id ) ) . ToList ( ) ) ;
6667 SetField ( account , "_savingCategories" , node . SavingCategories . Select ( ToEntity ) . ToList ( ) ) ;
68+ SetField ( account , "_contributionCategories" ,
69+ ( node . ContributionCategories ?? [ ] ) . Select ( c => Build ( new ContributionCategory ( c . Name ) , c . Id ) ) . ToList ( ) ) ;
6770 SetField ( account , "_periods" , node . Periods . Select ( p => ToEntity ( p , node . Currency ) ) . ToList ( ) ) ;
6871 return account ;
6972 }
@@ -73,7 +76,7 @@ public static Account Deserialize(string payload)
7376 private static PeriodNode ToNode ( Period p ) => new (
7477 p . Id , p . Currency , p . From , p . To , p . Status , p . CarriedIn . Amount ,
7578 p . InitialBalances . Select ( b => new InitialBalanceNode ( b . Id , b . FundId , b . Amount . Amount , b . Informative ) ) . ToList ( ) ,
76- p . Contributions . Select ( c => new ContributionNode ( c . Id , c . MemberId , c . Paid . Amount ) ) . ToList ( ) ,
79+ p . Contributions . Select ( c => new ContributionNode ( c . Id , c . MemberId , c . Paid . Amount , c . CategoryId , c . FundId , c . Date ) ) . ToList ( ) ,
7780 p . Budgets . Select ( b => new BudgetNode ( b . Id , b . CategoryId , b . Allocated . Amount , b . AlertThreshold , b . NotifyOnEveryExpense ) ) . ToList ( ) ,
7881 p . Expenses . Select ( e => new ExpenseNode ( e . Id , e . CategoryId , e . Amount . Amount , e . Date , e . MemberId , e . FundId , e . Note , e . SourceSavingCategoryId ) ) . ToList ( ) ,
7982 p . SavingAllocations . Select ( a => new SavingAllocationNode ( a . Id , a . SavingCategoryId , a . Amount . Amount , a . Date , a . Note , a . SourceExpenseId , a . BudgetCategoryId , a . TransferPairId ) ) . ToList ( ) ,
@@ -103,7 +106,7 @@ private static Period ToEntity(PeriodNode n, string currency)
103106 if ( n . Status == PeriodStatus . Closed ) p . Close ( ) ;
104107
105108 SetField ( p , "_initialBalances" , n . InitialBalances . Select ( b => Build ( new InitialBalance ( b . FundId , M ( b . Amount ) , b . Informative ) , b . Id ) ) . ToList ( ) ) ;
106- SetField ( p , "_contributions" , n . Contributions . Where ( c => c . MemberId != Period . CarryoverSource ) . Select ( c => Build ( new Contribution ( c . MemberId , M ( c . Paid ) ) , c . Id ) ) . ToList ( ) ) ;
109+ SetField ( p , "_contributions" , n . Contributions . Where ( c => c . MemberId != Period . CarryoverSource ) . Select ( c => Build ( new Contribution ( c . MemberId , M ( c . Paid ) , c . CategoryId , c . FundId , c . Date ) , c . Id ) ) . ToList ( ) ) ;
107110 SetField ( p , "_budgets" , n . Budgets . Select ( b => Build ( new Budget ( b . CategoryId , M ( b . Allocated ) , b . AlertThreshold , b . NotifyOnEveryExpense ) , b . Id ) ) . ToList ( ) ) ;
108111 SetField ( p , "_expenses" , n . Expenses . Select ( e => Build ( new Expense ( e . CategoryId , M ( e . Amount ) , e . Date , e . MemberId , e . FundId , e . Note , e . SourceSavingCategoryId ) , e . Id ) ) . ToList ( ) ) ;
109112 SetField ( p , "_savingAllocations" , n . SavingAllocations . Select ( a => Build ( new SavingAllocation ( a . SavingCategoryId , M ( a . Amount ) , a . Date , a . Note , a . SourceExpenseId , a . BudgetCategoryId , a . TransferPairId ) , a . Id ) ) . ToList ( ) ) ;
@@ -142,9 +145,11 @@ private static FieldInfo FindField(Type? type, string name)
142145
143146 private record AccountNode ( Guid Id , string Name , string Currency , Guid OwnerUserId ,
144147 List < MemberNode > Members , List < FundNode > Funds , List < CategoryNode > Categories ,
145- List < SavingCategoryNode > SavingCategories , List < PeriodNode > Periods ) ;
148+ List < SavingCategoryNode > SavingCategories , List < PeriodNode > Periods ,
149+ List < ContributionCategoryNode > ? ContributionCategories = null ) ;
146150
147151 private record MemberNode ( Guid Id , Guid UserId , string DisplayName ) ;
152+ private record ContributionCategoryNode ( Guid Id , string Name ) ;
148153 private record FundNode ( Guid Id , string Name , Guid ? ParentId ) ;
149154 private record CategoryNode ( Guid Id , string Name , Guid ? ParentId ) ;
150155 private record SavingCategoryNode ( Guid Id , string Name , Guid ? ParentId , decimal ? GoalAmount , decimal AlertThreshold , bool NotifyOnMilestone , decimal InitialAmount ) ;
@@ -155,7 +160,8 @@ private record PeriodNode(Guid Id, string Currency, DateOnly From, DateOnly To,
155160 List < ExternalTransferNode > ? ExternalTransfers = null ) ;
156161
157162 private record InitialBalanceNode ( Guid Id , Guid FundId , decimal Amount , bool Informative ) ;
158- private record ContributionNode ( Guid Id , Guid MemberId , decimal Paid ) ;
163+ private record ContributionNode ( Guid Id , Guid MemberId , decimal Paid ,
164+ Guid CategoryId = default , Guid FundId = default , DateOnly Date = default ) ;
159165 private record BudgetNode ( Guid Id , Guid CategoryId , decimal Allocated , decimal AlertThreshold , bool NotifyOnEveryExpense ) ;
160166 private record ExpenseNode ( Guid Id , Guid CategoryId , decimal Amount , DateOnly Date , Guid MemberId , Guid FundId , string ? Note , Guid ? SourceSavingCategoryId ) ;
161167 private record SavingAllocationNode ( Guid Id , Guid SavingCategoryId , decimal Amount , DateOnly Date , string ? Note , Guid ? SourceExpenseId , Guid ? BudgetCategoryId = null , Guid ? TransferPairId = null ) ;
0 commit comments