Improved layout of Supplier Invoice/Credit. All Items can now be added in one sweep.
[fa-stable.git] / reporting / rep708.php
index cb19d72f95fd2310164f4d778f7acd551dc7910e..6d72454bcf6691b0108ed9cba6a7c4726e5d133b 100644 (file)
@@ -51,19 +51,19 @@ function print_trial_balance()
 
        $cols2 = array(0, 50, 230, 330, 430, 530);
        //-------------0--1---2----3----4----5--
-       
+
        $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
-       
+
        $aligns2 = array('left', 'left', 'left', 'left', 'left');
-       
+
        $cols = array(0, 50, 200, 250, 300,     350, 400, 450, 500,     550);
        //------------0--1---2----3----4----5----6----7----8----9--
-       
+
        $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
                _('Credit'), _('Debit'), _('Credit'));
-       
+
        $aligns = array('left', 'left', 'right', 'right', 'right', 'right',     'right', 'right');
-    
+
     if ($dim == 2)
     {
        $params =   array(      0 => $comments,
@@ -91,49 +91,96 @@ function print_trial_balance()
        $rep->Font();
        $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
        $rep->Header();
+       $totprevd = $totprevc = $totcurrd = $totcurrc = 0.0;
 
        $accounts = get_gl_accounts();
 
-       while ($account=db_fetch($accounts)) 
+       while ($account=db_fetch($accounts))
        {
 
-               $begin = begin_fiscalyear();
                if (is_account_balancesheet($account["account_code"]))
                        $begin = "";
-               elseif ($from < $begin)
-                       $begin = $from;
+               else
+               {
+                       $begin = begin_fiscalyear();
+                       if (date1_greater_date2($begin, $from))
+                               $begin = $from;
+                       $begin = add_days($begin, -1);
+               }
+
                $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
 
                $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
 
                if ($zero == 0 && !$prev_balance && !$curr_balance)
                        continue;
-
                $rep->TextCol(0, 1, $account['account_code']);
                $rep->TextCol(1, 2,     $account['account_name']);
 
-               if ($prev_balance > 0.0)
+               if ($prev_balance >= 0.0)
+               {
+                       $totprevd += $prev_balance;
                        $rep->TextCol(2, 3,     number_format2(abs($prev_balance), $dec));
+               }       
                else
+               {
+                       $totprevc += $prev_balance;
                        $rep->TextCol(3, 4,     number_format2(abs($prev_balance), $dec));
-               if ($curr_balance > 0.0)
+               }       
+               if ($curr_balance >= 0.0)
+               {
+                       $totcurrd += $curr_balance;
                        $rep->TextCol(4, 5,     number_format2(abs($curr_balance), $dec));
+               }       
                else
+               {
+                       $totcurrc += $curr_balance;
                        $rep->TextCol(5, 6,     number_format2(abs($curr_balance), $dec));
-               if ($curr_balance + $prev_balance > 0.0)
+               }       
+               if ($curr_balance + $prev_balance >= 0.0)
                        $rep->TextCol(6, 7,     number_format2(abs($curr_balance + $prev_balance), $dec));
                else
                        $rep->TextCol(7, 8,     number_format2(abs($curr_balance + $prev_balance), $dec));
 
                $rep->NewLine();
 
-               if ($rep->row < $rep->bottomMargin + $rep->lineHeight) 
+               if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
                {
                        $rep->Line($rep->row - 2);
                        $rep->Header();
                }
        }
        $rep->Line($rep->row);
+       $rep->NewLine();
+       $rep->Font('bold');
+       $rep->TextCol(0, 2, _("Total"));
+
+       $rep->TextCol(2, 3,     number_format2(abs($totprevd), $dec));
+       $rep->TextCol(3, 4,     number_format2(abs($totprevc), $dec));
+       $rep->TextCol(4, 5,     number_format2(abs($totcurrd), $dec));
+       $rep->TextCol(5, 6,     number_format2(abs($totcurrc), $dec));
+       $rep->TextCol(6, 7,     number_format2(abs($totcurrd + $totprevd), $dec));
+       $rep->TextCol(7, 8,     number_format2(abs($totcurrc + $totprevc), $dec));
+       $rep->NewLine();
+       $totprev = $totprevd + $totprevc;
+       $totcurr = $totcurrd + $totcurrc;
+       $rep->TextCol(0, 2, _("Ending Balance"));
+
+       if ($totprev >= 0.0)
+               $rep->TextCol(2, 3,     number_format2(abs($totprev), $dec));
+       else
+               $rep->TextCol(3, 4,     number_format2(abs($totprev), $dec));
+       if ($totcurr >= 0.0)
+               $rep->TextCol(4, 5,     number_format2(abs($totcurr), $dec));
+       else
+               $rep->TextCol(5, 6,     number_format2(abs($totcurr), $dec));
+       if ($totcurr + $totprev >= 0.0)
+               $rep->TextCol(6, 7,     number_format2(abs($totcurr + $totprev), $dec));
+       else
+               $rep->TextCol(7, 8,     number_format2(abs($totcurr + $totprev), $dec));
+       
+       $rep->Line($rep->row - 6);
+       
        $rep->End();
 }