Commit 1c230fd3 authored by Mahmoud Aglan's avatar Mahmoud Aglan

dfhgkftgjuyl

parent 89449302
......@@ -46,7 +46,7 @@ final class FinancialReportService
WHERE status = 'posted' AND entry_date >= ? AND entry_date <= ? AND is_archived = 0
)
{$extraWhere}
WHERE coa.account_type = 'revenue' AND coa.is_archived = 0 AND coa.is_header = 0
WHERE coa.account_type = 'revenue' AND coa.is_archived = 0
GROUP BY coa.id, coa.account_code, coa.name_ar, coa.name_en
HAVING balance != 0
ORDER BY coa.account_code ASC",
......@@ -64,7 +64,7 @@ final class FinancialReportService
WHERE status = 'posted' AND entry_date >= ? AND entry_date <= ? AND is_archived = 0
)
{$extraWhere}
WHERE coa.account_type = 'expense' AND coa.is_archived = 0 AND coa.is_header = 0
WHERE coa.account_type = 'expense' AND coa.is_archived = 0
GROUP BY coa.id, coa.account_code, coa.name_ar, coa.name_en
HAVING balance != 0
ORDER BY coa.account_code ASC",
......@@ -130,7 +130,7 @@ final class FinancialReportService
WHERE status = 'posted' AND entry_date <= ? AND is_archived = 0
)
{$extraWhere}
WHERE coa.is_archived = 0 AND coa.is_header = 0
WHERE coa.is_archived = 0
AND coa.account_type IN ('asset','liability','equity')
GROUP BY coa.id, coa.account_code, coa.name_ar, coa.name_en,
coa.account_type, coa.account_nature, coa.opening_balance
......
......@@ -149,7 +149,7 @@ final class LedgerService
WHERE status = 'posted' AND entry_date >= ? AND entry_date <= ? AND is_archived = 0
)
{$extraWhere}
WHERE coa.is_archived = 0 AND coa.is_header = 0
WHERE coa.is_archived = 0
GROUP BY coa.id, coa.account_code, coa.name_ar, coa.name_en,
coa.account_type, coa.account_nature, coa.level, coa.is_header,
coa.opening_balance, coa.current_balance
......@@ -192,9 +192,28 @@ final class LedgerService
$balance = bcadd($opening, bcsub($creditMovement, $debitMovement, 2), 2);
}
// If no journal movements, use current_balance from DB
// If no journal movements, use current_balance from DB and restore opening from stored value
if (bccomp($debitMovement, '0.00', 2) === 0 && bccomp($creditMovement, '0.00', 2) === 0) {
$balance = (string) $acc['current_balance'];
$opening = (string) $acc['opening_balance'];
if (bccomp($opening, '0.00', 2) >= 0) {
$acc['opening_debit'] = $opening;
$acc['opening_credit'] = '0.00';
} else {
$acc['opening_debit'] = '0.00';
$acc['opening_credit'] = bcmul($opening, '-1', 2);
}
// Derive period movement as difference between closing and opening
$closingNet = (string) $acc['current_balance'];
$periodNet = bcsub($closingNet, $opening, 2);
if (bccomp($periodNet, '0.00', 2) >= 0) {
$acc['period_debit'] = $periodNet;
$acc['period_credit'] = '0.00';
} else {
$acc['period_debit'] = '0.00';
$acc['period_credit'] = bcmul($periodNet, '-1', 2);
}
}
// Closing debit/credit split
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment