feat: loans

This commit is contained in:
juancwu 2026-03-14 11:34:21 -04:00
commit ac7296b06e
No known key found for this signature in database
20 changed files with 3191 additions and 4 deletions

25
internal/model/loan.go Normal file
View file

@ -0,0 +1,25 @@
package model
import "time"
type Loan struct {
ID string `db:"id"`
SpaceID string `db:"space_id"`
Name string `db:"name"`
Description string `db:"description"`
OriginalAmountCents int `db:"original_amount_cents"`
InterestRateBps int `db:"interest_rate_bps"`
StartDate time.Time `db:"start_date"`
EndDate *time.Time `db:"end_date"`
IsPaidOff bool `db:"is_paid_off"`
CreatedBy string `db:"created_by"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type LoanWithPaymentSummary struct {
Loan
TotalPaidCents int
RemainingCents int
ReceiptCount int
}

48
internal/model/receipt.go Normal file
View file

@ -0,0 +1,48 @@
package model
import "time"
type FundingSourceType string
const (
FundingSourceBalance FundingSourceType = "balance"
FundingSourceAccount FundingSourceType = "account"
)
type Receipt struct {
ID string `db:"id"`
LoanID string `db:"loan_id"`
SpaceID string `db:"space_id"`
Description string `db:"description"`
TotalAmountCents int `db:"total_amount_cents"`
Date time.Time `db:"date"`
RecurringReceiptID *string `db:"recurring_receipt_id"`
CreatedBy string `db:"created_by"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type ReceiptFundingSource struct {
ID string `db:"id"`
ReceiptID string `db:"receipt_id"`
SourceType FundingSourceType `db:"source_type"`
AccountID *string `db:"account_id"`
AmountCents int `db:"amount_cents"`
LinkedExpenseID *string `db:"linked_expense_id"`
LinkedTransferID *string `db:"linked_transfer_id"`
}
type ReceiptWithSources struct {
Receipt
Sources []ReceiptFundingSource
}
type ReceiptFundingSourceWithAccount struct {
ReceiptFundingSource
AccountName string
}
type ReceiptWithSourcesAndAccounts struct {
Receipt
Sources []ReceiptFundingSourceWithAccount
}

View file

@ -0,0 +1,38 @@
package model
import "time"
type RecurringReceipt struct {
ID string `db:"id"`
LoanID string `db:"loan_id"`
SpaceID string `db:"space_id"`
Description string `db:"description"`
TotalAmountCents int `db:"total_amount_cents"`
Frequency Frequency `db:"frequency"`
StartDate time.Time `db:"start_date"`
EndDate *time.Time `db:"end_date"`
NextOccurrence time.Time `db:"next_occurrence"`
IsActive bool `db:"is_active"`
CreatedBy string `db:"created_by"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type RecurringReceiptSource struct {
ID string `db:"id"`
RecurringReceiptID string `db:"recurring_receipt_id"`
SourceType FundingSourceType `db:"source_type"`
AccountID *string `db:"account_id"`
AmountCents int `db:"amount_cents"`
}
type RecurringReceiptWithSources struct {
RecurringReceipt
Sources []RecurringReceiptSource
}
type RecurringReceiptWithLoan struct {
RecurringReceipt
LoanName string
Sources []RecurringReceiptSource
}