Balancereport Documentation
Balance Report Controller Documentation
File: /controllers/balancereportController.php
Purpose: Generates comprehensive balance sheet reports and financial position analysis
Last Updated: December 19, 2024
Total Functions: 22
Lines of Code: 818
---
๐ Overview
The Balance Report Controller provides comprehensive financial reporting and balance sheet analysis for the ERP system. It handles:
- โข Balance sheet generation with assets and liabilities
- โข Financial position reporting by date ranges
- โข Profit and loss calculations
- โข Asset valuation based on different inventory methods
- โข Client and supplier debt analysis
- โข Cash flow tracking (saves, bank accounts)
- โข Capital and withdrawal tracking
- โข Check value calculations for both clients and suppliers
- โข Comprehensive financial analysis with multiple evaluation methods
Primary Functions
- โ Generate balance sheet reports
- โ Calculate profit and loss statements
- โ Track asset valuations
- โ Monitor client/supplier debts
- โ Analyze cash flow positions
- โ Track capital and withdrawals
- โ Calculate check values
- โ Support multiple inventory valuation methods
- โ Date range reporting
- โ Financial position analysis
Related Controllers
- โข sellbillController.php - Sales data for revenue calculations
- โข buyBillController.php - Purchase data for cost calculations
- โข FaidaController.php - Profit reports
- โข FinancialPositionController.php - Financial position
- โข storereportController.php - Inventory valuation
- โข clientController.php - Customer debt analysis
- โข supplierController.php - Supplier debt analysis
- โข expenseController.php - Expense tracking
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `sellbill` | Sales revenue | sellbillid, sellbillaftertotalbill, sellbilldate, conditions | |
| `returnsellbill` | Sales returns | returnsellbillid, returnsellbillaftertotalbill, returnsellbilldate | |
| `sellbillandrutern` | Combined sales/returns | id, sellaftertotalbill, returnaftertotalbill, sellbilldate | |
| `expenses` | Business expenses | expensesid, expensesamount, expensesdate |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `assets` | Fixed assets | assetsid, assetvalue, assetsdate, assetscatid | |
| `storedetail` | Inventory valuation | storedetailid, productid, productquantity, storeid | |
| `product` | Product pricing | productId, productBuyPrice, lastbuyprice, meanbuyprice | |
| `save` | Cash/petty cash | saveid, saveamount, savedate | |
| `bankaccount` | Bank balances | bankaccountid, bankaccountbalance |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `client` | Customer debts | clientid, clientname, clientdebt | |
| `supplier` | Supplier debts | supplierid, suppliername, supplierdebt | |
| `capital` | Company capital | capitalid, capitalamount, capitaldate | |
| `partner` | Partner withdrawals | partnerid, partnermoney, conditions | |
| `kempiala` | Bills of exchange | kempialaId, kempialaValue, kempialaisselling |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `sellbilldetail` | Sales line items | sellbilldetailid, sellbilldetailquantity, buyprice | |
| `returnsellbilldetail` | Return line items | returnsellbilldetailid, returnsellbilldetailquantity | |
| `sellandruternbilldetail` | Combined bill details | id, sellbilldetailquantity, sellbilldetailtype | |
| `datedchecked` | Check tracking | id, checkValue, checktype, checkdate |
๐ง Key Functions
Core Balance Sheet Functions
Main Balance Sheet Display (Lines 242-368)
Purpose: Generates comprehensive balance sheet with assets, liabilities, and equity
Parameters:
- โข
$_REQUEST['from']- Start date for reporting period - โข
$_REQUEST['to']- End date for reporting period
Process Flow:
Key Calculations:
$totalSellCost = $totalSellPrice - $totalReturnSellPrice;
$totalBuyCost = $totalQuantityBuyPrice - $totalQuantityReturnBuyPrice;
$profitFinal = ($totalSellCost - $totalBuyCost) - $totalExpenses;
$forYou = $assetValue + $productPrice + $saveValue + $bankAccountbalance + $notSellingKempialaValue + $clientDebt + $totalclientcheck;
Revenue Calculation Functions
getTotalSellbillByDate($startDate, $endDate) (Lines 378-388)
Purpose: Calculates total sales revenue for date range
Parameters: Start and end dates
Returns: Total sales amount excluding taxes and discounts
getTotalAditionalSellbillByDate($startDate, $endDate) (Lines 391-401)
Purpose: Gets additional sales from combined sell/return bills
Parameters: Start and end dates
Returns: Additional sales revenue
getTotalReturnSellbillByDate($startDate, $endDate) (Lines 404-414)
Purpose: Calculates total sales returns for date range
Parameters: Start and end dates
Returns: Total return amount
getTotalAditionalReturnSellbillByDate($startDate, $endDate) (Lines 417-427)
Purpose: Gets additional returns from combined bills
Parameters: Start and end dates
Returns: Additional return amount
Cost of Goods Sold Functions
getTotalQuantityBuyPriceByDate($startDate, $endDate) (Lines 430-466)
Purpose: Calculates total cost of goods sold for sales
Parameters: Start and end dates
Process Flow:
Discount Calculation Logic:
if ($buyDiscount > 0 && $buyDiscountType == 0) {
$productBuyPrice = $buyPrice - $buyDiscount; // Fixed discount
} elseif ($buyDiscount > 0 && $buyDiscountType == 1) {
$productBuyPrice = $buyPrice - (($buyDiscount / 100) * $buyPrice); // Percentage
}
getTotalQuantityReturnBuyPriceByDate($startDate, $endDate) (Lines 513-555)
Purpose: Calculates cost of returned goods
Parameters: Start and end dates
Returns: Total cost of returned merchandise
Asset Valuation Functions
getTotalAssetByDate($startDate, $endDate) (Lines 622-638)
Purpose: Calculates total fixed asset value by date range
Parameters: Start and end dates
Process: Groups assets by category and sums values
Returns: Total fixed asset value
getTotalProductPrice() (Lines 640-702)
Purpose: Calculates inventory value using configured valuation method
Inventory Valuation Methods:
switch ($Programsettingdata->Inventoryevaluation) {
case "first": $pro_price = (float) $storedetail->productBuyPrice; break;
case "last": $pro_price = (float) $storedetail->lastbuyprice; break;
case "mean": $pro_price = (float) $storedetail->meanbuyprice; break;
case "last_discount": $pro_price = (float) $storedetail->lastbuyprice_withDiscount; break;
case "mean_discount": $pro_price = (float) $storedetail->meanbuyprice_withDiscount; break;
case "generalPrice": $pro_price = (float) $storedetail->overAllAveragePrice; break;
case "tax": $pro_price = (float) $storedetail->lastbuyprice_withTax; break;
case "mean_tax": $pro_price = (float) $storedetail->meanbuyprice_withTax; break;
}
Size/Color Handling:
if($storedetail->hasSizeAndColor == 1) {
$scquantity = R::getCell('select sum(quantity) from sizecolorstoredetail where productid = '.$storedetail->productId);
$productQuantity = $scquantity;
} else {
$productQuantity = $storedetail->productquantity;
}
Cash & Bank Functions
getTotalSaveValue() (Lines 704-712)
Purpose: Gets total petty cash/save value
Returns: Current total in all save accounts
getBankAccountbalance() (Lines 714-723)
Purpose: Calculates total bank account balances
Returns: Sum of all bank account balances
Debt Analysis Functions
getClientDebt() (Lines 799-807)
Purpose: Calculates total customer debt
Returns: Total amount owed by all clients
getSupplierDebt() (Lines 767-775)
Purpose: Calculates total supplier debt
Returns: Total amount owed to all suppliers
clientcheckvalue($startDate, $endDate) (Lines 736-749)
Purpose: Calculates value of checks from clients
Parameters: Date range for check calculation
Returns: Total value of client checks
suppliercheckvalue($startDate, $endDate) (Lines 752-765)
Purpose: Calculates value of checks to suppliers
Parameters: Date range for check calculation
Returns: Total value of supplier checks
Capital & Investment Functions
getCapitalamount() (Lines 777-785)
Purpose: Gets total company capital investment
Returns: Total capital amount
getPartnerwithdrawalvalue($startDate, $endDate) (Lines 787-797)
Purpose: Calculates partner withdrawal amounts
Parameters: Date range (currently not used in query)
Returns: Total partner money withdrawals
Bill of Exchange Functions
getNotSellingKempialaValue() (Lines 725-733)
Purpose: Gets value of bills of exchange not yet sold
Returns: Total value of unsold Kempiala (bills of exchange)
getSellingKempialaValue() (Lines 809-818)
Purpose: Gets value of bills of exchange that have been sold
Returns: Total value of sold Kempiala
Expense Tracking
getTotalExpensesByDate($startDate, $endDate) (Lines 611-620)
Purpose: Calculates total expenses for date range
Parameters: Start and end dates
Returns: Total expense amount
---
๐ Business Logic Flow
Balance Sheet Generation Process
User Request โ Date Validation โ Data Collection
โ
Revenue Calculation โ Cost Calculation โ Expense Calculation
โ
Asset Valuation โ Debt Analysis โ Capital Tracking
โ
Balance Sheet Assembly โ Profit/Loss Calculation โ Display
Financial Position Analysis
Inventory Valuation Logic
Get Product โ Check Size/Color โ Apply Valuation Method โ Calculate Total
โ
FIFO/LIFO โ Last Price โ Mean Price โ With/Without Discount โ With/Without Tax
---
โ ๏ธ Common Issues
Data Accuracy Issues
1. Date range dependency: All calculations depend on accurate date filtering
2. Inventory valuation: Different methods can show significant value differences
3. Currency precision: Financial calculations need proper rounding
Performance Considerations
1. Large date ranges: Extensive periods may cause slow report generation
2. Complex queries: Multiple table joins for cost calculations
3. Real-time calculations: No caching of frequently accessed totals
Business Logic Warnings
1. Incomplete transactions: Pending/draft bills may not be included
2. Multi-currency: No apparent support for foreign currency conversion
3. Tax calculations: Complex tax scenarios may need manual verification
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/include_dao.php- All DAO includes - โข
../public/config.php- Database configuration - โข
../public/authentication.php- User authentication - โข
../library/breadcrumb.php- Navigation support
Database Dependencies
- โข Complete transaction history for accurate calculations
- โข Proper foreign key relationships between tables
- โข Updated product pricing information
- โข Current debt balances for clients and suppliers
External Dependencies
- โข Smarty templating engine for report display
- โข RedBean ORM for some direct queries
- โข Session management for user context
- โข YouTube integration for help videos
Configuration Dependencies
- โข Program settings for inventory valuation method
- โข Proper decimal place configuration
- โข Date format standardization
- โข Multi-language support setup
---
Financial Formula Notes:
- โข Gross Profit = Sales Revenue - Sales Returns - Cost of Goods Sold
- โข Net Profit = Gross Profit - Operating Expenses
- โข Total Assets = Current Assets + Fixed Assets
- โข Balance Check = Total Assets = Total Liabilities + Total Equity
- โข Working Capital = Current Assets - Current Liabilities