diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php
index a9a1f1d12cf..ef19a6ae330 100644
--- a/htdocs/accountancy/bookkeeping/balance.php
+++ b/htdocs/accountancy/bookkeeping/balance.php
@@ -265,6 +265,8 @@ if ($action != 'export_csv')
$total_credit = 0;
$sous_total_debit = 0;
$sous_total_credit = 0;
+ $total_opening_balance = 0;
+ $sous_total_opening_balance = 0;
$displayed_account = "";
$sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance";
@@ -288,6 +290,8 @@ if ($action != 'export_csv')
$total_credit += $line->credit;
$description = $object->get_compte_desc($line->numero_compte); // Search description of the account
$root_account_description = $object->get_compte_racine($line->numero_compte);
+ $opening_balance = isset($opening_balances["'".$line->numero_compte."'"]) ? $opening_balances["'".$line->numero_compte."'"] : 0;
+ $total_opening_balance += $opening_balance;
if (empty($description)) {
$link = ''.img_edit_add().'';
}
@@ -298,7 +302,7 @@ if ($action != 'export_csv')
{
// Display a sub-total per account
if ($displayed_account != "") {
- print '
| '.$langs->trans("SubTotal").': | '.price($sous_total_debit).' | '.price($sous_total_credit).' | '.price(price2num($sous_total_credit - $sous_total_debit)).' | ';
+ print '
| '.$langs->trans("SubTotal").': | '.price($sous_total_opening_balance).' | '.price($sous_total_debit).' | '.price($sous_total_credit).' | '.price(price2num($sous_total_credit - $sous_total_debit)).' | ';
print " | \n";
print '
';
}
@@ -311,16 +315,17 @@ if ($action != 'export_csv')
$displayed_account = $root_account_description;
$sous_total_debit = 0;
$sous_total_credit = 0;
+ $sous_total_opening_balance = 0;
}
// $object->get_compte_racine($line->numero_compte);
print ''.length_accountg($line->numero_compte).' | ';
print ''.$description.' | ';
- print ''.price($opening_balances["'".$line->numero_compte."'"]).' | ';
+ print ''.price($opening_balance).' | ';
print ''.price($line->debit).' | ';
print ''.price($line->credit).' | ';
- print ''.price($line->debit - $line->credit).' | ';
+ print ''.price($opening_balance + $line->debit - $line->credit).' | ';
print ''.$link;
print ' | ';
print "\n";
@@ -328,13 +333,14 @@ if ($action != 'export_csv')
// Records the sub-total
$sous_total_debit += $line->debit;
$sous_total_credit += $line->credit;
+ $sous_total_opening_balance += $opening_balance;
}
- print '| '.$langs->trans("SubTotal").': | '.price($sous_total_debit).' | '.price($sous_total_credit).' | '.price(price2num($sous_total_debit - $sous_total_credit)).' | ';
+ print '
| '.$langs->trans("SubTotal").': | '.price($sous_total_opening_balance).' | '.price($sous_total_debit).' | '.price($sous_total_credit).' | '.price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit)).' | ';
print " | \n";
print '
';
- print '| '.$langs->trans("AccountBalance").': | '.price($total_debit).' | '.price($total_credit).' | '.price(price2num($total_debit - $total_credit)).' | ';
+ print '
| '.$langs->trans("AccountBalance").': | '.price($total_opening_balance).' | '.price($total_debit).' | '.price($total_credit).' | '.price(price2num($total_opening_balance + $total_debit - $total_credit)).' | ';
print " | \n";
print '
';