[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5222] trunk



Revision: 5222
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5222&view=rev
Author:   einhverfr
Date:     2012-11-21 07:28:26 +0000 (Wed, 21 Nov 2012)
Log Message:
-----------
Income statement on new framework now minimally works
Needs menu update, better CSS, and hyperlinks.

Modified Paths:
--------------
    trunk/LedgerSMB/Report/PNL/Income_Statement.pm
    trunk/UI/Reports/PNL.html

Modified: trunk/LedgerSMB/Report/PNL/Income_Statement.pm
===================================================================
--- trunk/LedgerSMB/Report/PNL/Income_Statement.pm	2012-11-20 10:03:51 UTC (rev 5221)
+++ trunk/LedgerSMB/Report/PNL/Income_Statement.pm	2012-11-21 07:28:26 UTC (rev 5222)
@@ -35,6 +35,8 @@
 
 has '_cols' => (is => 'rw', isa => 'ArrayRef[Any]', required => 0);
 
+has 'account_data' =>  (is => 'rw', isa => 'HashRef[Any]');
+
 =back
 
 =head1 CONSTANT REPORT-RELATED FUNCTIONS
@@ -45,7 +47,7 @@
 
 =cut
 
-sub template { return 'PNL' }
+sub template { return 'Reports/PNL' }
 
 =item name
 
@@ -66,7 +68,7 @@
 
 =cut
 
-sub columns { return $_[0]->_cols  }
+sub columns { return []  }
 
 =back
 
@@ -77,16 +79,14 @@
 # private method
 # report_base($from, $to)
 # returns an array of hashrefs of report results.  Used in adding comparison
-# as well ans the main report
+# as well as the main report
 
 sub report_base {
     my ($self, $from_date, $to_date) = @_;
     die LedgerSMB::Report::text('Invalid Reporting Basis') 
            if ($self->basis ne 'accrual') and ($self->basis ne 'cash');
     my $procname = 'pnl__income_statement_' . $self->basis;
-    return $self->exec_method({
-             funcname => $procname
-    });
+    return $self->exec_method({funcname => $procname});
 }
 
 =over
@@ -99,6 +99,25 @@
     my ($self) = @_;
     my @rows = $self->report_base($self->from_date, $self->to_date);
     $self->rows(..hidden..);
+    my $data = $self->account_data;
+    $data ||= $data = {'I' => {}, 'E' => {}};
+    for my $r (@rows){
+        $data->{$r->{account_category}}->{$r->{account_number}} = {'main' => $r};
+    }
+    my $i_total = 0;
+    my $e_total = 0;
+    my $total;
+    for my $k (keys %{$data->{I}}){
+       $i_total += $data->{I}->{$k}->{main}->{amount}; 
+    }
+    for my $k (keys %{$data->{E}}){
+       $e_total += $data->{E}->{$k}->{main}->{amount}; 
+    }
+    $data->{totals}->{main}->{I} = $i_total;
+    $data->{totals}->{main}->{E} = $e_total;
+    $data->{totals}->{main}->{total} = $i_total - $e_total;
+    $self->account_data($data);
+    return @rows;
 }
 
 =item add_comparison($from, $to)

Modified: trunk/UI/Reports/PNL.html
===================================================================
--- trunk/UI/Reports/PNL.html	2012-11-20 10:03:51 UTC (rev 5221)
+++ trunk/UI/Reports/PNL.html	2012-11-21 07:28:26 UTC (rev 5222)
@@ -1,71 +1,94 @@
-<?lsmb INCLUDE 'ui-header.html';
-
-INCOME_ROWS = [];
-TOTAL_INCOME = 0;
-EXPENSE_ROWS = [];
-TOTAL_EXPENSE = 0;
-
-FORACH r IN rows;
-   IF r.category = 'E';
-       EXPENSE_ROWS.push(r);
-       TOTAL_EXPENSE = TOTAL_EXPENSE + r.amount;
-   ELSIF r.category = 'I';
-       INCOME_ROWS.push(r);
-       TOTAL_INCOME = TOTAL_INCOME + r.amount;
-   END;
-END;
-
-RETAINED_EARNINGS = TOTAL_INCOME - TOTAL_EXPENSE;
-
-IF RETAINED_EARNINGS < 0;
-   RETAINED_EARNINGS = '(' _ RETAINED_EARNINGS * -1 _ ')';
-END;
-?>
+<?lsmb INCLUDE 'ui-header.html' include_stylesheet = ['UI/Reports/pnl.css'];
+account_data = report.account_data ?>
 <body>
-<div id="report_name" class="income_statement">
 <h1><?lsmb name ?></h1>
-<h2><?lsmb text('Accounting period: [_1] to [_2]', from_date, to_date); ?></h2>
+<h2><?lsmb text('Accounting period: [_1] to [_2]', report.from_date, report.to_date); ?></h2>
+<?lsmb 
+IF comparisons;
+    FOREACH COMP IN comparisons ?>
+<h2><?lsmb text('Compared to: [_1] to [_2]', COMP.from_date, COMP.to_date) ?>
+</h2>
+   <?lsmb END;
+END ?>
 <table>
 <tbody>
     <tr class="sectionhead">
         <th><?lsmb text('Income Account') ?></th>
-        <th><?lsmb text('Amount') ?></th>
+        <th><?lsmb report.from_date _ ' - ' _ report.to_date ?></th>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <th><?lsmb COMP.from_date _ ' - ' _ COMP.to_date ?></th>
+    <?lsmb END ?>
     </tr>
-  <?lsmb FOREACH R IN INCOME_ROWS ?>
+  <?lsmb FOREACH k IN account_data.I.keys ?>
     <tr class="incomerow">
-        <td class="label"><?lsmb R.accno _ '--' R.description ?></td>
-        <td class="amount"><?lsmb R.amount ?></td>
+        <td class="label"><?lsmb k _ '--' 
+                             _ account_data.I.${k}.main.account_description ?></td>
+        <td class="amount"><?lsmb account_data.I.${k}.main.amount ?></td>
+       
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.I.${k}.${COMP.label}.amount ?></td>
+    <?lsmb END ?>
     </tr>
  <?lsmb END ?>
    <tr class="sectionfoot">
      <th><?lsmb text('Total Income') ?></th>
-     <td class="amount"><?lsmb TOTAL_INCOME ?></td>
+     <td class="amount"><?lsmb account_data.totals.main.I ?></td>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.totals.${COMP.label}.I ?></td>
+    <?lsmb END ?>
    </tr>
     <tr class="sectionhead">
         <th><?lsmb text('Expense Account') ?></th>
-        <th><?lsmb text('Amount') ?></th>
+        <th>&nbsp;</th>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <th>&nbsp;</th>
+    <?lsmb END ?>
     </tr>
-  <?lsmb FOREACH R IN EXPENSE_ROWS ?>
+  <?lsmb FOREACH k IN account_data.E.keys ?>
     <tr class="incomerow">
-        <td class="label"><?lsmb R.accno _ '--' R.description ?></td>
-        <td class="amount"><?lsmb R.amount ?></td>
+        <td class="label"><?lsmb k _ '--' _
+             account_data.E.${k}.main.account_description ?></td>
+        <td class="amount"><?lsmb account_data.E.${k}.main.amount ?></td>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.E.${k}.${COMP.label}.amount ?></td>
+    <?lsmb END ?>
     </tr>
  <?lsmb END ?>
    <tr class="sectionfoot">
      <th><?lsmb text('Total Expense') ?></th>
-     <td class="amount"><?lsmb TOTAL_EXPENSE ?></td>
+     <td class="amount"><?lsmb account_data.totals.main.E ?></td>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.totals.${COMP.label}.E ?></td>
+    <?lsmb END ?>
    </tr>
+   <tr class="separator"><td></td></tr>
    <tr class="sectionfoot">
      <th><?lsmb text('Total Income') ?></th>
-     <td class="amount"><?lsmb TOTAL_INCOME ?></td>
+     <td class="amount"><?lsmb account_data.totals.main.I ?></td>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.totals.${COMP.label}.I ?></td>
+    <?lsmb END ?>
    </tr>
    <tr class="reportfoot">
      <th><?lsmb text('Less Total Expense') ?></th>
-     <td class="amount"><?lsmb TOTAL_EXPENSE ?></td>
+     <td class="amount"><?lsmb account_data.totals.main.E ?></td>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.totals.${COMP.label}.E ?></td>
+    <?lsmb END ?>
    </tr>
    <tr class="reportfoot">
      <th><?lsmb text('Income (Loss)') ?></th>
-     <td class="amount"><?lsmb RETAINED_EARNINGS ?></td>
+     <td class="amount"><?lsmb account_data.totals.main.total ?></td>
+    <?lsmb FOREACH COMP IN comparison ?>
+        <td class="amount">
+            <?lsmb account_data.totals.${COMP.label}.total ?></td>
+    <?lsmb END ?>
    </tr>
 </tbody>
 </table>

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.