Income Statements

Overview

The Income Statement feature in the system is designed to generate a comprehensive report of revenue and expenses for a specific month or range of months within a given year. This feature fetches transactions for the specified period, categorizes them into revenue and expenses, and calculates the total values for each category, along with the net income.

Components and Flow

  1. API Endpoints:

    • Fetch Income Statement Data:
      • Retrieves income statement data for a specific month and year.
      • Method: GET
      • Endpoint: /finance/reports/income-statement
  2. Database Models:

    • Transactions Table:
      • Stores information about financial transactions, including date, amount, account, category, and student ID.
    • Categories Table:
      • Stores information about transaction categories, including name and type.
    • Accounts Table:
      • Stores information about accounts, including names.
  3. Implementation Details:

    • fetchIncomeStatementData Function:

      • Fetches all transactions for the specified period.
      • Fetches categories and accounts to get names and types.
      • Aggregates transactions into revenue and expenses based on categories.
      • Calculates the total values for each category and the net income.
      • Returns the aggregated data in a structured format.
    • IncomeStatement Component:

      • Displays the income statement data.
      • Uses React state to manage loading and data.
      • Fetches income statement data on component mount or when filters change.

Flow Diagram (Tree-like and Linear)

Users/Clients
    |
    +---> API Endpoints
             |
             +---> Fetch Income Statement Data (GET /finance/reports/income-statement)
                        |
                        +---> Fetch Income Statement Data Function
                                    |
                                    +---> Fetch Transactions from DB
                                    |          |
                                    |          +---> Transactions Table
                                    |
                                    +---> Fetch Categories from DB
                                    |          |
                                    |          +---> Categories Table
                                    |
                                    +---> Fetch Accounts from DB
                                    |          |
                                    |          +---> Accounts Table
                                    |
                                    +---> Process Transactions
                                    |          |
                                    |          +---> Aggregate by Category
                                    |          |          |
                                    |          |          +---> Classify as Revenue or Expense
                                    |          |                    |
                                    |          |                    +---> Update Revenue Records
                                    |          |                    +---> Update Expense Records
                                    |
                                    +---> Calculate Totals
                                    |          |
                                    |          +---> Total Revenue
                                    |          +---> Total Expenses
                                    |          +---> Net Income
                                    |
                                    +---> Return Income Statement Data

Components

  • IncomeStatement Component:
    • Props: None
    • State:
      • selectedMonth: Selected month for the report.
      • selectedMonthRange: Selected range of months for the report.
      • selectedYear: Selected year for the report.
      • incomeStatement: The income statement data object.
      • loading: Boolean indicating loading state.
    • Effect:
      • Fetches income statement data on component mount or when filters change.
    • Render:
      • Displays loading spinner while data is being fetched.
      • Displays income statement data once fetched.

Example Usage

Interface
    |
    +---> IncomeStatement Component
               |
               +---> State Management
                          |
                          +---> selectedMonth: number | null
                          +---> selectedMonthRange: [number | null, number | null]
                          +---> selectedYear: number | null
                          +---> incomeStatement: IncomeStatementData | null
                          +---> loading: boolean
               |
               +---> Effect
                          |
                          +---> Fetch income statement data on mount or filter change
               |
               +---> Render
                          |
                          +---> Display loading spinner while fetching data
                          +---> Display income statement data once fetched