Skip to content

Support loan/credit#341

Open
FilipHarald wants to merge 15 commits intoafadil:mainfrom
FilipHarald:feat/loans
Open

Support loan/credit#341
FilipHarald wants to merge 15 commits intoafadil:mainfrom
FilipHarald:feat/loans

Conversation

@FilipHarald
Copy link
Contributor

@FilipHarald FilipHarald commented Aug 6, 2025

resolves #340

This pull request implements a comprehensive loan tracking system for portfolio management, separating actual equity from borrowed funds and ensuring transparent financial reporting across backend, frontend, and UI layers. The changes span database schema updates, new activity types, calculation logic, and documentation, culminating in a fully operational 4-metric financial dashboard and accurate performance metrics.

Backend & Database Enhancements

  • Added new columns (outstanding_loans, portfolio_equity, outstanding_loans_base) to the daily_account_valuation and holdings_snapshots tables to support loan tracking. [1] [2]
  • Introduced new activity types for loan operations (LOAN_TAKEN, LOAN_REPAID) in activities_constants.rs and updated activity mapping and models to support these types. [1] [2] [3]

Documentation & Implementation Planning

  • Added detailed implementation summaries in SUMMARY.md and TODO.md, outlining the four key portfolio metrics, architectural flow, UI changes, backend logic, and a phased rollout plan. [1] [2]

Key Features Delivered

  • Built a 4-metric financial system: Portfolio Equity, Outstanding Loans, Total Value, and Net Deposit, with full historical tracking and API support.
  • Fixed performance calculations throughout the backend to use portfolio_equity instead of total_value, ensuring users see true investment returns excluding borrowed funds. [1] [2]

Frontend & UI Integration

  • Updated TypeScript interfaces and data hooks for new metrics, and enhanced dashboard chart components to visualize all four metrics with proper styling, tooltips, and toggling logic. [1] [2]

System-wide Consistency & Stability

  • Ensured all components (goal tracking, account summaries, dashboard balances, exports, and database queries) consistently use the correct financial values, with smart fallback logic and backward compatibility. [1] [2]

References:
[1] [2] [3] [4] [5] [6] [7]

✅ Phase 2: Frontend Data Integration - COMPLETE
- Updated AccountValuation TypeScript interface with portfolioEquity and outstandingLoans fields
- Made new fields optional for backward compatibility with account pages
- Fixed test files to include new fields with default values
- Verified all hooks and data flow work seamlessly

✅ Phase 3: UI Implementation - COMPLETE
- Enhanced HistoryChart component with 4-metric visualization system
- Default view: Portfolio Equity (green, on top) + Outstanding Loans (red, negative)
- Hover view: Total Value (orange) + Net Deposit (grey, dotted)
- Conditional rendering for backward compatibility
- Refined styling with optimal visual hierarchy:
  * Portfolio Equity: Green success color, solid line, gradient fill, rendered on top
  * Outstanding Loans: Red destructive color, solid line, red background, negative values
  * Total Value: Orange color, solid line, orange background, hover-only
  * Net Deposit: Grey color, dotted line (only dotted), hover-only
- Dynamic tooltips with color-coded indicators
- Outstanding Loans correctly visualized as negative financial impact

Technical Implementation:
- Adaptive chart system detects loan data availability
- Zero breaking changes to existing account page functionality
- Proper data transformation (loans as negative values for visualization)
- Maintained privacy mode integration
- TypeScript compilation passes successfully

Users can now clearly see their true financial position with actual equity
separated from borrowed funds in an intuitive, professional interface.
@FilipHarald
Copy link
Contributor Author

Image

@FilipHarald FilipHarald marked this pull request as ready for review August 17, 2025 09:53
@FilipHarald
Copy link
Contributor Author

@afadil I've now tested it with my own data, including upgrading for my legacy-DB. But it would be great to test it with more comprehensive DBs. Do you have some test-data? I connected on Discord with you for that.

I would love to have feedback on if you think this is a good idea, or what could be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove me before merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove me before merge

- Fixed broken CSV quote import functionality that appeared to work but didn't import quotes
- Root causes identified and resolved:
  * Only importing 10 sample quotes instead of all quotes from CSV
  * UI showing fake success without waiting for async completion
  * ValidationStatus enum case mismatch (frontend 'Valid' vs backend 'valid')
  * React state timing issues causing double-click requirement
  * Status pill color issues (red instead of green)

Technical fixes:
- Frontend: Fixed useQuoteImport hook to import all quotes, proper async handling
- Backend: Added comprehensive logging across Tauri commands, service, and repository layers
- UI: Fixed Badge components, status enums, auto tab switching with useEffect
- Types: Updated TypeScript enums to match Rust backend expectations

Result: 53 historical quotes (2013-2022) successfully imported for 0P0000ULAP.ST
Database confirmed: MANUAL|53 quotes added alongside existing YAHOO|3393 quotes

All CSV quote import workflows now function correctly with single-click validation.
This reverts commit 9ad0228.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: track loans

1 participant