Changes between Version 8 and Version 9 of App
- Timestamp:
- 09/08/25 19:00:35 (11 hours ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
App
v8 v9 1 **SQL Views** 1 = SQL Views = 2 2 3 The application uses SQL VIEWs to simplify common queries and improve maintainability :3 The application uses SQL VIEWs to simplify common queries and improve maintainability. 4 4 5 `invoice_summary` 5 == v_invoice_analytics == 6 6 7 - **Purpose**: Shows invoice info with client and company names 8 - **What it does**: Joins Invoice, Client, and Tenant tables to display invoice details with client name and company name 9 - **Usage**: Makes it easier to see which client each invoice belongs to without writing complex JOINs 7 '''Purpose''': Shows invoice info with client and company names plus business calculations 8 9 '''What it does''': Joins Invoice, Client, and Tenant tables and calculates days overdue, payment status, and value categories 10 11 '''Usage''': Makes it easier to see which client each invoice belongs to and get business insights without writing complex queries 10 12 11 13 {{{ 12 SELECT * FROM invoice_summaryWHERE invoice_status = 'PENDING';14 SELECT * FROM v_invoice_analytics WHERE invoice_status = 'PENDING'; 13 15 }}} 14 16 15 `client_totals` 17 == v_client_financial_summary == 16 18 17 - **Purpose**: Shows total amounts for each client 18 - **What it does**: Groups invoices by client and calculates total paid, pending, overdue amounts 19 - **Usage**: Provides a quick overview of each client's financial status 19 '''Purpose''': Shows total amounts for each client with risk analysis 20 21 '''What it does''': Groups invoices by client and calculates total paid, pending, overdue amounts plus payment behavior and risk levels 22 23 '''Usage''': Provides a complete overview of each client's financial status and payment history 20 24 21 25 {{{ 22 SELECT * FROM client_totalsORDER BY total_invoiced DESC;26 SELECT * FROM v_client_financial_summary ORDER BY total_invoiced DESC; 23 27 }}} 24 28 25 API Integration 29 = API Integration = 26 30 27 31 The views are used in API endpoints to provide simplified data access: 28 32 29 - `src/app/api/clients/summary/route.ts`: Uses `client_totals` view for client financial summaries 30 - `src/app/api/invoices/totals/route.ts`: Uses `invoice_summary` view for invoice analytics 33 src/app/api/clients/summary/route.ts: Uses v_client_financial_summary view for detailed client analytics 31 34 32 Benefits35 src/app/api/invoices/totals/route.ts: Uses v_invoice_analytics view for invoice analytics 33 36 34 - **Simpler queries**: No need to write complex JOINs every time 35 - **Consistent data**: Same calculation logic everywhere 36 - **Easier to maintain**: Change the view, all queries get updated 37 - **Better performance**: Database can optimize the view 37 = Benefits = 38 38 39 The views are implemented in `sql/03_business_views.sql`. 39 '''Simpler queries''': No need to write complex JOINs every time 40 40 41 '''Consistent data''': Same calculation logic everywhere 41 42 43 '''Easier to maintain''': Change the view, all queries get updated 44 45 '''Better performance''': Database can optimize the view 46 47 The views are implemented in: 48 sql/03_business_views.sql 42 49 **Transactions** 43 50