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

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



Revision: 1988
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1988&view=rev
Author:   einhverfr
Date:     2007-12-20 17:56:50 -0800 (Thu, 20 Dec 2007)

Log Message:
-----------
Adding chart of account filter to GL reports

Modified Paths:
--------------
    trunk/LedgerSMB/Form.pm
    trunk/LedgerSMB/GL.pm
    trunk/bin/gl.pl

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2007-12-21 01:07:57 UTC (rev 1987)
+++ trunk/LedgerSMB/Form.pm	2007-12-21 01:56:50 UTC (rev 1988)
@@ -1816,6 +1816,26 @@
     $self->all_taxaccounts( $myconfig, $dbh, $transdate );
 }
 
+=item $form->all_accounts()
+
+Sets $form->{accounts} to all accounts.  Returns the list as well.
+Example:  my @account_list = $form->all_accounts();
+
+=cut
+
+sub all_accounts {
+    my ($self) = @_;
+    my $ref;
+    $self->{all_accounts} = [];
+    my $sth = $self->{dbh}->prepare('SELECT * FROM chart_list_all()');
+    $sth->execute || $self->dberror('SELECT * FROM chart_list_all()');
+    while ($ref = $sth->fetchrow_hashref('NAME_lc')){
+        push(@{$self->{all_accounts}}, $ref);
+    }
+    $sth->finish;
+    return @{$self->{all_accounts}};
+}
+
 =item $form->all_taxaccounts($myconfig, $dbh2[, $transdate]);
 
 Get the tax rates and numbers for all the taxes in $form->{taxaccounts}.  Does

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2007-12-21 01:07:57 UTC (rev 1987)
+++ trunk/LedgerSMB/GL.pm	2007-12-21 01:56:50 UTC (rev 1988)
@@ -411,6 +411,12 @@
     my @a = ( id, transdate, reference, source, description, accno );
     my $sortorder = $form->sort_order( ..hidden.., \%ordinal );
 
+    my $chart_id;
+    if ($form->{chart_id}){
+        $chart_id = $dbh->quote($form->{chart_id});
+    } else {
+        $chart_id = 'NULL';
+    }
     my $query = qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference,
 						  g.description, ac.transdate, ac.source,
 						  ac.amount, c.accno, c.gifi_accno, g.notes, c.link,
@@ -420,7 +426,9 @@
 					 JOIN acc_trans ac ON (g.id = ac.trans_id)
 					 JOIN chart c ON (ac.chart_id = c.id)
 				LEFT JOIN department d ON (d.id = g.department_id)
-					WHERE $glwhere
+					WHERE $glwhere 
+				              AND (ac.chart_id = $chart_id OR
+                                                   $chart_id IS NULL)
 
 					UNION ALL
 
@@ -435,6 +443,8 @@
 					 JOIN entity e ON (a.entity_id = e.id)
 				LEFT JOIN department d ON (d.id = a.department_id)
 					WHERE $arwhere
+				              AND (ac.chart_id = $chart_id OR
+                                                   $chart_id IS NULL)
 
 				UNION ALL
 
@@ -449,6 +459,8 @@
 					 JOIN entity e ON (a.entity_id = e.id)
 				LEFT JOIN department d ON (d.id = a.department_id)
 					WHERE $apwhere
+				              AND (ac.chart_id = $chart_id OR
+                                                   $chart_id IS NULL)
 				 ORDER BY $sortorder|;
 
     my $sth = $dbh->prepare($query);

Modified: trunk/bin/gl.pl
===================================================================
--- trunk/bin/gl.pl	2007-12-21 01:07:57 UTC (rev 1987)
+++ trunk/bin/gl.pl	2007-12-21 01:56:50 UTC (rev 1988)
@@ -238,6 +238,13 @@
 |;
     }
 
+    my @accounts = $form->all_accounts;
+    my $account_select = qq|<select name="chart_id" class="account>|;
+    for my $act (@accounts){
+        $account_select .= qq|<option value="$act->{id}">$act->{accno}--| .
+            qq|$act->{description}</option>|;
+    }
+
     if ( @{ $form->{all_years} } ) {
 
         # accounting years
@@ -324,7 +331,10 @@
 	<tr>
 	  <th align=right>| . $locale->text('Reference') . qq|</th>
 	  <td><input name=reference size=20></td>
-
+        </tr>
+         <tr>
+          <th align="right">| . $locale->text('Account') . qq|</th>
+          <td>$account_select</td>
 	  </tr>
 	  <tr>
 	  <th align=right>| . $locale->text('Source') . qq|</th>


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