FasReporting Subsystem Documentation
Version: 1.0
Date: Nov 23, 2025
Table of Contents
- Introduction
- 1.1. System Overview
- 1.2. Key Features
- System Architecture
- 2.1. High-Level Flow
- 2.2. Technology Stack
- Setup & Installation (Developer Guide)
- 3.1. Directory Structure
- 3.2. Dependencies
- 3.3. Configuration
- Core Components & Implementation (Developer Guide)
- 4.1. MongoDB Models
- 4.2. Core Services (
FasReportingNamespace) - 4.3. Asynchronous Jobs (
FasNamespace) - 4.4. Artisan Commands (
FasNamespace) - 4.5. API Controllers
- System Usage (Developer Guide)
- 5.1. Importing Report Templates via API
- 5.2. Compiling Reports via Artisan Command
- 5.3. Retrieving Compiled Reports via API
- Report Template Creation (User Guide)
- 6.1. Introduction to Excel Templates
- 6.2. Template Structure and Rules
- 6.3. Example 1: Profit & Loss Statement Template
- 6.4. Example 2: Trial Balance Template
- Future Enhancements
1. Introduction
1.1. System Overview
The FasReporting subsystem is a robust, template-driven engine for generating standard financial reports within a Laravel application. It is designed to be highly configurable and scalable, offloading the heavy computational work of report generation to a background queue. The system uses MongoDB for its data storage, leveraging its performance for complex accounting queries. The core principle is the separation of report structure (the “template”) from the accounting data (the “General Ledger”). This allows financial analysts and accountants to design and modify report layouts in a familiar tool like Microsoft Excel, without requiring code changes.1.2. Key Features
- Template-Driven: Report layouts are defined in external Excel files, allowing for easy customization.
- Asynchronous Compilation: Report generation is handled by background jobs, ensuring the user interface remains responsive.
- Result Caching: Compiled reports are cached in Redis for near-instant retrieval on subsequent requests.
- MongoDB Optimized: Leverages MongoDB’s aggregation pipeline for efficient calculation of account balances.
- Namespaced & Modular: All components are logically grouped under
FasandFasReportingnamespaces for clean code organization.
2. System Architecture
2.1. High-Level Flow
The reporting process follows these steps:- Template Import: A user uploads an Excel file defining the report structure via a dedicated API endpoint. The system parses this file and saves the template to the
report_templatescollection in MongoDB. - Compilation Trigger: A developer or a system process triggers a report compilation for a specific template, company, and date range using an
artisancommand. - Queue Dispatch: The command dispatches a
CompileReportJobto the configured queue (e.g., Redis). - Background Processing: A queue worker picks up the job and executes the
LineReportService. This service queries the General Ledger, performs all calculations based on the template rules, and assembles the final report data. - Caching: The resulting report data (a JSON array) is stored in the cache with a unique key derived from the company, template, and date range.
- Report Retrieval: A client application (e.g., a frontend UI) fetches the report from a retrieval API. This API first checks the cache; if the report exists, it is returned immediately.
2.2. Technology Stack
- Backend Framework: Laravel 8+
- Database: MongoDB
- Laravel-MongoDB Driver:
jenssegers/laravel-mongodb - Excel Parsing:
maatwebsite/excel - Caching/Queueing: Redis (recommended)
3. Setup & Installation (Developer Guide)
3.1. Directory Structure
The subsystem’s components are organized as follows:3.2. Dependencies
Install the required packages using Composer:3.3. Configuration
- Database: Configure your MongoDB connection in
config/database.phpand.env. - Queue: Set your queue driver to
redisor another persistent driver in your.envfile.
- Queue Worker: Ensure you have a queue worker running to process the jobs:
4. Core Components & Implementation (Developer Guide)
4.1. MongoDB Models
The system relies on three primary models. (Source code forChartOfAccount and GeneralLedgerEntry are standard Eloquent models for MongoDB).
app/Models/ReportTemplate.php
This model represents a report template and its embedded lines.
4.2. Core Services (FasReporting Namespace)
app/Services/FasReporting/LineReportService.php
This is the heart of the engine, responsible for all calculations.
app/Services/FasReporting/ExcelTemplateImporterService.php
This service parses the uploaded Excel file and persists the template.
4.3. Asynchronous Jobs (Fas Namespace)
app/Jobs/Fas/CompileReportJob.php
This job wraps the LineReportService execution so it can be processed in the background.
4.4. Artisan Commands (Fas Namespace)
app/Console/Commands/Fas/CompileReport.php
This command provides a command-line interface to trigger report compilations.
4.5. API Controllers
app/Http/Controllers/Api/ReportTemplateImportController.php
Handles the file upload and initiates the import process.
app/Http/Controllers/Api/ReportRetrievalController.php
Provides an endpoint to fetch the final, cached report.
5. System Usage (Developer Guide)
5.1. Importing Report Templates via API
To create or update a report template, make aPOST request to the import endpoint.
- Endpoint:
POST /api/companies/{companyId}/report-templates/import - Content-Type:
multipart/form-data - Parameters:
template_file(file): The.xlsxor.xlstemplate file.template_name(string): The name for the report (e.g., “Standard P&L”).template_type(string): The type of report. Must be one of:PNL,BALANCE_SHEET,TRIAL_BALANCE.
curl Request:
5.2. Compiling Reports via Artisan Command
Use thefas:report:compile command to generate a report.
Asynchronous (Recommended for Production):
5.3. Retrieving Compiled Reports via API
- Endpoint:
GET /api/reports/{companyId}/{templateId} - Query Parameters:
start_date(string, Y-m-d): The report start date.end_date(string, Y-m-d): The report end date.
curl Request:
6. Report Template Creation (User Guide)
6.1. Introduction to Excel Templates
You can create complex financial report layouts using a simple Excel spreadsheet. The system intelligently interprets the structure of your spreadsheet based on a few rules. Each row in the Excel sheet corresponds to one line in the final report.6.2. Template Structure and Rules
Your Excel file should have columns that map to the following fields. The system does not read headers; it only reads the data starting from the second row (Row 2).| Column | Field Name | Description |
|---|---|---|
| A, B, C… | Indentation | The number of empty cells from the left determines the indentation level (level). One empty cell = level 1, two empty cells = level 2, etc. The first non-empty cell is the line_name. |
| D | Line Name | The text to be displayed for this line. This is automatically inferred from the first non-empty cell. |
| E | Line Key | A unique, uppercase key (e.g., TOTAL_REVENUE) used to reference this line’s calculated amount in other formulas. This is critical for building calculations. |
| F | Account Spec | Defines which GL accounts to sum for this line. Use * as a wildcard (e.g., 4* for all accounts starting with 4). Leave blank for header or formula lines. |
| G | Formula | A calculation based on other Line Key values. Currently supports SUM(). Ex: SUM(KEY1, KEY2, -KEY3). The minus sign (-) subtracts the value. Leave blank if using Account Spec. |
| H | Display Style | (Optional) A CSS class name for styling on the frontend. Common values are bold or underline-top. |
6.3. Example 1: Profit & Loss Statement Template
This example shows how to structure a standard P&L statement. Excel View:| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | (Ignored Header) | Line Key | Account Spec | Formula | Style | |||
| 2 | Revenue | bold | ||||||
| 3 | Sales Revenue | SALES | 4* | |||||
| 4 | Interest Income | INTEREST | 4900 | |||||
| 5 | Total Revenue | TOTAL_REVENUE | SUM(SALES, INTEREST) | bold | ||||
| 6 | ||||||||
| 7 | Cost of Goods Sold | COGS | 5* | |||||
| 8 | Gross Profit | GROSS_PROFIT | SUM(TOTAL_REVENUE, -COGS) | bold | ||||
| 9 | ||||||||
| 10 | Operating Expenses | bold | ||||||
| 11 | Salaries Expense | SALARIES | 6000-6199 | |||||
| 12 | Rent Expense | RENT | 6200 | |||||
| 13 | Total OpEx | TOTAL_OPEX | SUM(SALARIES, RENT) | bold | ||||
| 14 | Net Income | NET_INCOME | SUM(GROSS_PROFIT, -TOTAL_OPEX) | bold |
- Row 3: Has one empty cell in column A.
levelis 1.line_nameis “Sales Revenue”.account_specis4*, so it will sum all accounts starting with 4. Its value is stored with the keySALES. - Row 5:
levelis 0.formulaisSUM(SALES, INTEREST). The system will take the calculated values from rows 3 and 4 and add them together. - Row 8: The formula
SUM(TOTAL_REVENUE, -COGS)calculates Gross Profit by subtracting theCOGSvalue from theTOTAL_REVENUEvalue.
6.4. Example 2: Trial Balance Template
A Trial Balance is simpler and typically doesn’t use formulas, just direct account sums. Excel View:| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | (Ignored Header) | Line Key | Account Spec | Formula | Style | |||
| 2 | Assets | bold | ||||||
| 3 | Cash and Bank | 1* | ||||||
| 4 | Accounts Receivable | 12* | ||||||
| 5 | Liabilities | bold | ||||||
| 6 | Accounts Payable | 2* | ||||||
| 7 | Equity | bold | ||||||
| 8 | Retained Earnings | 3* |
7. Future Enhancements
- Advanced Formula Engine: Extend the formula parser to support more complex operations like
IF,AVG, or nested calculations. - UI for Template Management: Build a web interface for users to upload, manage, and edit report templates directly in the application.
- Real-time Progress: Use WebSockets (e.g., Laravel Echo) to provide real-time updates on report compilation status to the frontend.
- Multi-Period Reports: Add functionality to generate comparative reports (e.g., This Year vs. Last Year) by accepting multiple date ranges.

