FinancialPosition Documentation

Financial Position Controller Documentation

File: /controllers/FinancialPositionController.php

Purpose: Provides comprehensive financial position analysis and real-time balance sheet reporting

Last Updated: December 19, 2024

Total Functions: 21

Lines of Code: 696

---

๐Ÿ“‹ Overview

The Financial Position Controller provides real-time financial position analysis and comprehensive balance sheet reporting for the ERP system. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Asset Tables

Table NamePurposeKey Columns
`storedetail`Inventory assetsstoredetailid, productid, productquantity, storeid
`product`Product pricingproductId, productBuyPrice, lastbuyprice, meanbuyprice, overAllAveragePrice
`assets`Fixed assetsassetsid, assetvalue, assetsdate, assetscatid
`productserial`Serial number inventoryid, buybilldetailid, don, del
`sizecolorstoredetail`Size/color inventoryid, productid, quantity, storeid, sizeid, colorid
### Financial Tables

Table NamePurposeKey Columns
`bankaccount`Bank balancesbankaccountid, accountbeginingbalance, bankaccountbalance
`save`Petty cash accountssaveid, savecurrentvalue, savecurrentvalueInMainCurrency
`capital`Company capitalcapitalid, capitalamount, capitaldate
`partner`Partner investmentspartnerid, partnermoney, conditions
### Debt & Receivables Tables

Table NamePurposeKey Columns
`client`Customer debtsclientid, clientname, clientdebt
`supplier`Supplier debtssupplierid, suppliername, suppliercurrentDebt
`kempiala`Bills of exchangekempialaId, kempialaValue, kempialadate, kempialaisselling
`datedchecked`Check trackingid, checkValue, checktype, checkdate
### Configuration Tables

Table NamePurposeKey Columns
`programsettings`System settingsid, Inventoryevaluation, currency_settings
`buybilldetail`Purchase detailsbuybilldetailid, buybilldetailprice, payedtax
`buybill`Purchase headersbuybillid, buybilldate, conditions
---

๐Ÿ”ง Key Functions

Core Financial Position Functions

Main Financial Position Display (Lines 189-277)

Purpose: Generates complete financial position statement with all components

Process Flow:

โ”Œโ”€ Load Settings โ”€โ”€โ”€โ”€โ”
Get evaluation
Current + Fixed
Current debts
Capital + Profits
โ””โ”€ Display Report โ”€โ”€โ”˜

Asset Calculation Functions

totalproduct() (Lines 453-545)

Purpose: Calculates total inventory value using configured evaluation method

Returns: Total inventory value based on system settings

Inventory Evaluation Methods:

switch ($Programsetting->Inventoryevaluation) {
    case "first": $buyprice = (float) $storedata->productBuyPrice; break;
    case "last": $buyprice = (float) $storedata->lastbuyprice; break;
    case "mean": $buyprice = (float) $storedata->meanbuyprice; break;
    case "last_discount": $buyprice = (float) $storedata->lastbuyprice_withDiscount; break;
    case "mean_discount": $buyprice = (float) $storedata->meanbuyprice_withDiscount; break;
    case "generalPrice": $buyprice = (float) $storedata->overAllAveragePrice; break;
}

Size/Color Inventory Handling:

if($storedata->hasSizeAndColor == 1) {
    $scquantity = R::getCell('select sum(quantity) from sizecolorstoredetail where productid = '.$storedata->productid);
    $quantity = $scquantity;
} else {
    $quantity = $storedata->productquantity;
}

productserialvalue() (Lines 286-293)

Purpose: Calculates inventory value based on serial numbers for specific products

Returns: Total value of serialized inventory including taxes

Calculation Formula:

SELECT sum((buybilldetailprice * don) + ((buybilldetailprice * don * payedtax) / 100))
FROM productserial
LEFT JOIN buybilldetail ON buybilldetail.buybilldetailid = productserial.buybilldetailid
WHERE productserial.don > 0 AND productserial.del = 0

calculateFixedassets() (Lines 651-663)

Purpose: Calculates total fixed assets value

Returns: Sum of all fixed assets grouped by category

Currentassets() (Lines 678-695)

Purpose: Calculates total current assets

Components:

Formula:

$totalCurrentassets = $totalaccount + $totalclientdebt + $totalcollection + $totalprice + $savevaluex;

Cash & Bank Functions

Bankaccount() (Lines 296-305)

Purpose: Calculates total bank account balances

Returns: Sum of all bank account beginning balances

savevalue() (Lines 548-560)

Purpose: Calculates total petty cash value with multi-currency support

Returns: Total save value in main currency

Multi-Currency Support:

foreach ($allsavedata as $savedata) {
    $savevaluex += $savedata->savecurrentvalueInMainCurrency; // Converted to main currency
}

Debt & Receivables Functions

clientdebt() (Lines 308-317)

Purpose: Calculates total customer debt (accounts receivable)

Returns: Sum of all client debts

supplierdebt() (Lines 320-329)

Purpose: Calculates total supplier debt (accounts payable)

Returns: Sum of all supplier current debts

clientcheckvalue() (Lines 363-375)

Purpose: Calculates value of checks received from clients

Returns: Total value of client checks not yet collected

suppliercheckvalue() (Lines 402-414)

Purpose: Calculates value of checks issued to suppliers

Returns: Total value of supplier checks not yet paid

Bills of Exchange Functions

kempilavalue() (Lines 332-360)

Purpose: Calculates value of active bills of exchange

Process Flow:

โ”Œโ”€ Get Available โ”€โ”€โ”€โ”€โ”
Bills not expired
Bills past due
Available only
โ””โ”€ Return Value โ”€โ”€โ”€โ”€โ”˜

Logic:

$allavailabledata = $myKempialaEx->queryAlllavilablekempila2(0, $today);
$allexpiredata = $myKempialaEx->queryAllexpierkempila2(0, $today);
$totalkempilavalue = $totalavailablekempila; // Only available, not expired

collection() (Lines 665-675)

Purpose: Calculates total collection items (checks + bills of exchange)

Returns: Combined value of kempiala and client checks

Capital & Equity Functions

allcapitalvalue() (Lines 605-615)

Purpose: Calculates total company capital investment

Returns: Sum of all capital contributions

partnervalue() (Lines 377-399)

Purpose: Calculates partner investment/withdrawal balance

Returns: Net partner money using direct SQL query

Query:

SELECT sum(partnermoney) FROM partner WHERE partner.conditions = 0

Profits() (Lines 594-602)

Purpose: Calculates current profit/loss position

Formula:

$totalProfits = round(($forYou - $totalCurrentliabilities - $totalallmoney), 2);
// Where: forYou = Total Assets, totalCurrentliabilities = Current Liabilities, totalallmoney = Capital

Propertyrights() (Lines 617-624)

Purpose: Calculates total property rights (equity)

Components: Capital + Retained Earnings (Profits)

Liability Functions

Currentliabilities() (Lines 575-582)

Purpose: Calculates total current liabilities

Components:

Formula:

$totalCurrentliabilities = $totalsuppliercheck + $totalsupplierdebt;

Summary Functions

totalmoneyforyou() (Lines 564-571)

Purpose: Calculates total assets (fixed + current)

Formula: Fixed Assets + Current Assets

totaltoyou() (Lines 627-633)

Purpose: Calculates total liabilities + equity

Formula: Current Liabilities + Property Rights

allmoney() (Lines 584-591)

Purpose: Calculates total capital (company + partners)

Formula: Capital Amount + Partner Money

---

๐Ÿ”„ Business Logic Flow

Financial Position Analysis Process

System Start โ†’ Load Configuration โ†’ Calculate Components
     โ†“
Current Assets Calculation โ†’ Fixed Assets Calculation
     โ†“
Current Liabilities Calculation โ†’ Equity Calculation
     โ†“
Profit/Loss Calculation โ†’ Balance Verification โ†’ Report Display

Asset Valuation Logic

โ”‚ โ””โ”€ General Price
โ””โ”€ Calculate Total Value

Balance Sheet Structure

โ”œโ”€ Cash (Bank + Save)
โ”‚ โ”œโ”€ Inventory โ”‚ โ””โ”€ Supplier Checks
โ”‚ โ”œโ”€ Client Debt โ””โ”€ Equity
โ”œโ”€ Client Checks
โ”‚ โ””โ”€ Bills of Exchange โ”‚ โ”œโ”€ Partner Money
โ””โ”€ Fixed Assets โ”‚ โ””โ”€ Retained Earnings
โ””โ”€ Asset Categories โ””โ”€ Total Equity

---

โš ๏ธ Common Issues

Data Accuracy Issues

1. Real-time calculations: No caching may cause performance issues with large datasets

2. Currency conversion: Multi-currency support may have conversion rate delays

3. Inventory valuation: Different methods can show significant differences

Performance Considerations

1. Complex queries: Multiple table joins for real-time calculations

2. No caching: All values calculated on each request

3. Large inventory: Size/color variants require additional processing

Business Logic Warnings

1. Balance verification: No automatic balance checking between assets and liabilities

2. Date sensitivity: Some calculations are date-dependent but use current date only

3. Negative balances: No validation for negative equity or unrealistic values

---

๐Ÿ”— Dependencies

Required Files

Database Dependencies

External Dependencies

Configuration Dependencies

---

Financial Analysis Notes:

Key Financial Position Indicators: