Financial Statements

Overview

The Financial Statements feature allows students to view detailed transactions and balances for their accounts. It ensures that students can access their financial information, including debits, credits, and outstanding balances for the current semester.

Features

  • Session Management: Ensures that the user is logged in and has a valid session.
  • Financial Data Retrieval: Fetches all financial statements for the student.
  • Error Handling: Provides user-friendly error messages in case of issues.
  • Print Capability: Allows users to print their financial statements.

Flow Diagram

+-------------------+
|   User Logs In    |
+-------------------+
          |
          v
+-------------------+
|   Session Check   |
+-------------------+
          |
    +-----+-----+
    |           |
    v           v
+--------+  +-----------------+
| Valid  |  | Invalid Session |
+--------+  +-----------------+
    |               |
    |               v
    |       +-----------------+
    |       | Show Error      |
    |       | Message         |
    |       +-----------------+
    |
    v
+------------------------+
| Fetch Financial        |
| Statements             |
+------------------------+
    |
    +------------+
    |            |
    v            v
+--------+  +-----------------+
| Success |  | Error          |
+--------+  +-----------------+
    |               |
    |               v
    |       +-----------------+
    |       | Show Error      |
    |       | Message         |
    |       +-----------------+
    v
+------------------------+
| Display Financial      |
| Statements             |
+------------------------+
    |
    v
+------------------------+
| Print Financial        |
| Statements             |
+------------------------+

Architecture

Frontend

  • React: Used for building the user interface.
  • Next.js: Server-side rendering and API routes.
  • Tailwind CSS: Styling framework.
  • React-to-print: Library for printing components.
  • Lucide-react: Icon library for UI elements.

Backend

  • Prisma: ORM for database interactions.
  • PostgreSQL: Database to store user, financial statement, and student data.

Technical Implementation

Session Management

  1. User Authentication: The system checks if the user is logged in and has a valid session.
  2. Session Retrieval: If the session is valid, the system retrieves user information, including user ID.

Fetch Financial Data

  1. Fetch Financial Statements: The system retrieves the student's financial statements from the database based on the user ID.
  2. Order by Date: The financial statements are ordered by date in descending order to show the latest transactions first.
  3. Format Data: The financial data is formatted to include proper debit, credit, and balance values.

Error Handling

  1. Invalid User ID: If the user ID is invalid, an error message is displayed.
  2. No Financial Data: If no financial data is found, a message indicating the outstanding balance is shown.
  3. Internal Server Error: In case of any server errors, an appropriate error message is displayed.
  1. Print Button: A print button is provided for users to print their financial statements.
  2. React-to-print: The library is used to handle the printing of the financial statement component.

Component Breakdown

Page Component

  • Session Check: The component first checks if the user has a valid session by calling getSession.
  • Fetch Financial Statements: If the session is valid, it fetches the financial statements for the student using getAllFinancialStatementsByStudentId.
  • Render Financial Statements: The financial statements are passed to a child component for display. If there's an error, an appropriate message is shown.

Financial Statements Retrieval

  • Validate User ID: Checks if the user ID is valid. If not, returns an error.
  • Fetch Student Data: Retrieves student data, including current program level and semester registrations.
  • Fetch Financial Statements: Retrieves financial statements from the database, ordered by date.
  • Format Financial Data: Converts financial amounts from milli-units to standard units for readability.
  • Calculate Totals: Computes the total debit, total credit, and the latest balance.
  • Return Financial Data: Returns the formatted financial data along with totals or an error message if applicable.

Financial Statements Component

  • Display Financial Data: Renders the financial statements in a table format, showing date, debit, credit, and balance for each transaction.
  • Print Functionality: Provides a print button that uses react-to-print to print the financial statements.

Algorithms and Key Processes

Fetching Financial Statements

  1. Session Check: The session is validated to ensure the user is logged in.
  2. Database Query: The system queries the database to fetch financial statements for the student.
  3. Data Formatting: The financial data is formatted to ensure debits, credits, and balances are in a readable format.
  4. Error Handling: If no financial statements are found, a custom error message is generated to inform the student of their outstanding balance.

Printing Financial Statements

  1. Print Button: A button is provided on the UI to trigger the print functionality.
  2. React-to-print Integration: The react-to-print library is used to capture the component and print it as a document.
  3. Document Title: The printed document is titled "Financial Statement" for clarity.

Relational Diagram

+----------+     +-----------+     +---------------+
|   USER   |     |  STUDENT  |     | PROGRAM_LEVEL |
+----------+     +-----------+     +---------------+
| id       |1   1| id        |     | id            |
| name     |-----| userId    |*   1| programName   |
| email    |     | currentPro|-----| feesPerSemes  |
+----------+     | gramLevel |     | ter           |
                 | Id        |     +---------------+
                 +-----------+
                      | 1
                      |
                      | *
    +----------+    +----------------------+
    | SEMESTER |    | SEMESTER_REGISTRATION|
    +----------+    +----------------------+
    | id       |1  *| id                   |
    | isCurrent|----| studentId            |
    +----------+    | semesterId           |
         |          +----------------------+
         |                    | *
         | *                  |
         |                    | 1
+----------------------+      |
| FINANCIAL_STATEMENT  |      |
+----------------------+      |
| id                   |      |
| studentId            |------+
| semesterId           |
| date                 |
| debit                |
| credit               |
| balance              |
+----------------------+

Legend:
1 = One
* = Many
- = Relationship line