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

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



Revision: 1581
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1581&view=rev
Author:   tetragon
Date:     2007-09-13 06:40:43 -0700 (Thu, 13 Sep 2007)

Log Message:
-----------
Templates and CSV output for the account list and the chart of accounts report

Modified Paths:
--------------
    trunk/bin/am.pl
    trunk/bin/ca.pl

Added Paths:
-----------
    trunk/UI/am-list-accounts.csv
    trunk/UI/am-list-accounts.html

Added: trunk/UI/am-list-accounts.csv
===================================================================
--- trunk/UI/am-list-accounts.csv	                        (rev 0)
+++ trunk/UI/am-list-accounts.csv	2007-09-13 13:40:43 UTC (rev 1581)
@@ -0,0 +1,3 @@
+<?lsmb FOREACH column IN columns ?><?lsmb IF heading.$column.text; heading.$column.text; ELSE; heading.$column; END ?><?lsmb IF NOT loop.last ?>,<?lsmb END ?><?lsmb END ?>
+<?lsmb FOREACH row IN rows ?><?lsmb FOREACH column IN columns ?><?lsmb IF row.$column.href; row.$column.text; ELSE; row.$column; END ?><?lsmb IF NOT loop.last ?>,<?lsmb END ?><?lsmb END ?>
+<?lsmb END ?><?lsmb IF totals; t = []; FOREACH column IN columns; t.push(totals.$column); END; t.join(','); END ?>

Added: trunk/UI/am-list-accounts.html
===================================================================
--- trunk/UI/am-list-accounts.html	                        (rev 0)
+++ trunk/UI/am-list-accounts.html	2007-09-13 13:40:43 UTC (rev 1581)
@@ -0,0 +1,66 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
+<head>
+	<title><?lsmb form.titlebar ?></title>
+	<meta http-equiv="Pragma" content="no-cache" />
+	<meta http-equiv="Expires" content="-1" />
+	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
+	<link rel="stylesheet" href="css/<?lsmb form.stylesheet ?>" type="text/css" title="LedgerSMB stylesheet" />
+
+	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+	<meta name="robots" content="noindex,nofollow" />
+        
+</head>
+
+<?lsmb PROCESS elements.html ?> 
+
+<body>
+
+<table width="100%">
+  <tr>
+    <th class="listtop" colspan="<?lsmb columns.size ?>"><?lsmb form.title ?></th>
+  </tr>
+  <tr><td colspan="<?lsmb columns.size ?>"></td></tr>
+  <tr class="listheading">
+<?lsmb FOREACH column IN columns ?>
+    <th class="listtop"><?lsmb heading.$column ?></th>
+<?lsmb END ?>
+  </tr>
+<?lsmb FOREACH row IN rows ?>
+  <?lsmb IF row.heading == 'H'; s = 'th'; c = 'listheading'; ELSE;
+                                s = 'td'; c = "listrow${row.i}"; END ?>
+<tr class="<?lsmb c ?>">
+  <?lsmb FOREACH column IN columns ?>
+  <<?lsmb s ?> class="<?lsmb c ?>" <?lsmb IF (!row.heading && (column == 'credit' || column == 'debit')) ?>align="right"<?lsmb END ?>>
+    <?lsmb IF row.$column.href ?>
+    <a href="<?lsmb row.$column.href?>"><?lsmb row.$column.text ?></a>
+    <?lsmb ELSIF column == 'link'; FOREACH l IN row.link.split(':'); l ?><br /><?lsmb END ?>
+    <?lsmb ELSE; row.$column; END ?>
+  </<?lsmb s ?>>
+  <?lsmb END ?>
+</tr>
+<?lsmb END ?>
+<?lsmb IF totals ?>
+<tr class="listtotal">
+  <?lsmb FOREACH column IN columns ?>
+  <th class="listtotal" align="right"><?lsmb totals.$column ?></th>
+  <?lsmb END ?>
+</tr>
+<?lsmb END ?>
+  <tr><td colspan="<?lsmb columns.size ?>"><hr size="3" /></td></tr>
+</table>
+
+<br />
+
+<form method="post" action="<?lsmb form.script ?>">
+<?lsmb FOREACH pair IN form.callback.split('&amp;') ?><?lsmb hidden = pair.split('=') ?>
+<?lsmb IF NOT loop.first ?>
+<?lsmb PROCESS input element_data={type => 'hidden', name => hidden.0, value => hidden.1} ?>
+<?lsmb END ?><?lsmb END ?>
+<?lsmb PROCESS input element_data={type => 'hidden', name => 'callback', value => form.callback} ?>
+
+<?lsmb FOREACH button IN buttons ?><?lsmb PROCESS button element_data=button ?><?lsmb END ?>
+</form>
+</body>
+</html>

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2007-09-12 22:15:26 UTC (rev 1580)
+++ trunk/bin/am.pl	2007-09-13 13:40:43 UTC (rev 1581)
@@ -38,6 +38,7 @@
 use LedgerSMB::User;
 use LedgerSMB::RP;
 use LedgerSMB::GL;
+use LedgerSMB::Template;
 
 1;
 
@@ -368,107 +369,98 @@
     $callback =
 "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
 
+    $form->{callback} = $callback;
     @column_index = qw(accno gifi_accno description debit credit link);
 
-    $column_header{accno} =
-      qq|<th class=listtop>| . $locale->text('Account') . qq|</a></th>|;
-    $column_header{gifi_accno} =
-      qq|<th class=listtop>| . $locale->text('GIFI') . qq|</a></th>|;
-    $column_header{description} =
-      qq|<th class=listtop>| . $locale->text('Description') . qq|</a></th>|;
-    $column_header{debit} =
-      qq|<th class=listtop>| . $locale->text('Debit') . qq|</a></th>|;
-    $column_header{credit} =
-      qq|<th class=listtop>| . $locale->text('Credit') . qq|</a></th>|;
-    $column_header{link} =
-      qq|<th class=listtop>| . $locale->text('Link') . qq|</a></th>|;
+    $column_header{accno} = $locale->text('Account');
+    $column_header{gifi_accno} = $locale->text('GIFI');
+    $column_header{description} = $locale->text('Description');
+    $column_header{debit} = $locale->text('Debit');
+    $column_header{credit} = $locale->text('Credit');
+    $column_header{link} = $locale->text('Link');
 
-    $form->header;
-    $colspan = $#column_index + 1;
-
-    print qq|
-<body>
-
-<table width=100%>
-  <tr>
-    <th class=listtop colspan=$colspan>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
-  <tr class="listheading">
-|;
-
-    for (@column_index) { print "$column_header{$_}\n" }
-
-    print qq|
-</tr>
-|;
-
     # escape callback
     $callback = $form->escape($callback);
 
-    foreach $ca ( @{ $form->{CA} } ) {
+    my @rows;
+    foreach my $ca ( @{ $form->{CA} } ) {
 
-        $ca->{debit}  = "&nbsp;";
-        $ca->{credit} = "&nbsp;";
+        my %column_data;
+        $ca->{debit}  = " ";
+        $ca->{credit} = " ";
 
         if ( $ca->{amount} > 0 ) {
             $ca->{credit} =
-              $form->format_amount( \%myconfig, $ca->{amount}, 2, "&nbsp;" );
+              $form->format_amount( \%myconfig, $ca->{amount}, 2, " " );
         }
         if ( $ca->{amount} < 0 ) {
             $ca->{debit} =
-              $form->format_amount( \%myconfig, -$ca->{amount}, 2, "&nbsp;" );
+              $form->format_amount( \%myconfig, -$ca->{amount}, 2, " " );
         }
 
-        $ca->{link} =~ s/:/<br>/og;
+        #$ca->{link} =~ s/:/<br>/og;
 
         $gifi_accno = $form->escape( $ca->{gifi_accno} );
 
         if ( $ca->{charttype} eq "H" ) {
-            print qq|<tr class="listheading">|;
+            $column_data{heading} = 'H';
+            $column_data{accno} = {
+              text => $ca->{accno},
+              href => "$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
+            $column_data{gifi_accno} = {
+              text => $ca->{gifi_accno},
+              href => "$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
+            $column_data{description} = $ca->{description};
+            $column_data{debit}  = " ";
+            $column_data{credit} = " ";
+            $column_data{link}   = " ";
 
-            $column_data{accno} =
-qq|<th><a class="listheading" href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></th>|;
-            $column_data{gifi_accno} =
-qq|<th class="listheading"><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</th>|;
-            $column_data{description} =
-              qq|<th class="listheading">$ca->{description}&nbsp;</th>|;
-            $column_data{debit}  = qq|<th>&nbsp;</th>|;
-            $column_data{credit} = qq| <th>&nbsp;</th>|;
-            $column_data{link}   = qq|<th>&nbsp;</th>|;
-
         }
         else {
             $i++;
             $i %= 2;
-            print qq|
-<tr valign=top class="listrow$i">|;
-            $column_data{accno} =
-qq|<td><a href="$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{accno}</a></td>|;
-            $column_data{gifi_accno} =
-qq|<td><a href="$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback">$ca->{gifi_accno}</a>&nbsp;</td>|;
-            $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
-            $column_data{debit}       = qq|<td align="right">$ca->{debit}</td>|;
-            $column_data{credit} = qq|<td align="right">$ca->{credit}</td>|;
-            $column_data{link}   = qq|<td>$ca->{link}&nbsp;</td>|;
+            $column_data{i} = $i;
+            $column_data{accno} = {
+              text => $ca->{accno},
+              href => "$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
+            $column_data{gifi_accno} = {
+              text => $ca->{gifi_accno},
+              href => "$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"};
+            $column_data{description} = $ca->{description};
+            $column_data{debit}       = $ca->{debit};
+            $column_data{credit} = $ca->{credit};
+            $column_data{link}   = $ca->{link};
 
         }
-
-        for (@column_index) { print "$column_data{$_}\n" }
-
-        print "</tr>\n";
+        push @rows, \%column_data;
     }
 
-    print qq|
-  <tr><td colspan="$colspan"><hr size="3" noshade /></td></tr>
-</table>
+    my @buttons;
+    push @buttons, {
+        name => 'action',
+        value => 'csv_list_account',
+        text => $locale->text('CSV Report'),
+        type => 'submit',
+        class => 'submit',
+    };
 
-</body>
-</html>
-|;
-
+    my $template = LedgerSMB::Template->new(
+        user => \%myconfig, 
+        locale => $locale,
+        path => 'UI',
+        template => 'am-list-accounts',
+        format => ($form->{action} =~ /^csv/)? 'CSV': 'HTML');
+    $template->render({
+        form => \%$form,
+        buttons => ..hidden..,
+        columns => ..hidden..,
+        heading => \%column_header,
+        rows => ..hidden..,
+    });
 }
 
+sub csv_list_account { &list_account }
+
 sub delete_account {
 
     $form->{title} = $locale->text('Delete Account');

Modified: trunk/bin/ca.pl
===================================================================
--- trunk/bin/ca.pl	2007-09-12 22:15:26 UTC (rev 1580)
+++ trunk/bin/ca.pl	2007-09-13 13:40:43 UTC (rev 1581)
@@ -47,6 +47,7 @@
 #======================================================================
 
 use LedgerSMB::CA;
+use LedgerSMB::Template;
 
 1;
 
@@ -86,110 +87,93 @@
 
     @column_index = qw(accno gifi_accno description debit credit);
 
-    $column_header{accno} =
-      qq|<th class=listtop>| . $locale->text('Account') . qq|</th>\n|;
-    $column_header{gifi_accno} =
-      qq|<th class=listtop>| . $locale->text('GIFI') . qq|</th>\n|;
-    $column_header{description} =
-      qq|<th class=listtop>| . $locale->text('Description') . qq|</th>\n|;
-    $column_header{debit} =
-      qq|<th class=listtop>| . $locale->text('Debit') . qq|</th>\n|;
-    $column_header{credit} =
-      qq|<th class=listtop>| . $locale->text('Credit') . qq|</th>\n|;
+    $column_header{accno} = $locale->text('Account');
+    $column_header{gifi_accno} = $locale->text('GIFI');
+    $column_header{description} = $locale->text('Description');
+    $column_header{debit} = $locale->text('Debit');
+    $column_header{credit} = $locale->text('Credit');
 
     $form->{title} = $locale->text('Chart of Accounts');
+    $form->{callback} = 
+      qq|$form->{script}?path=$form->{path}&action=chart_of_accounts&login=$form->{login}&sessionid=$form->{sessionid}|;
 
-    $colspan = $#column_index + 1;
+    my @rows;
+    my $totaldebit = 0;
+    my $totalcredit = 0;
+    foreach my $ca ( @{ $form->{CA} } ) {
+        my %column_data;
 
-    $form->header;
+        my $description      = $form->escape( $ca->{description} );
+        my $gifi_description = $form->escape( $ca->{gifi_description} );
 
-    print qq|
-<body>
-  
-<table border=0 width=100%>
-  <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
-  <tr height="5"></tr>
-  <tr class=listheading>|;
-
-    for (@column_index) { print $column_header{$_} }
-
-    print qq|
-  </tr>
-|;
-
-    foreach $ca ( @{ $form->{CA} } ) {
-
-        $description      = $form->escape( $ca->{description} );
-        $gifi_description = $form->escape( $ca->{gifi_description} );
-
-        $href =
+        my $href =
 qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&sessionid=$form->{sessionid}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|;
 
         if ( $ca->{charttype} eq "H" ) {
-            print qq|<tr class=listheading>|;
+            $column_data{heading} = 'H';
             for (qw(accno description)) {
-                $column_data{$_} = "<th class=listheading>$ca->{$_}</th>";
+                $column_data{$_} = $ca->{$_};
             }
-            $column_data{gifi_accno} =
-              "<th class=listheading>$ca->{gifi_accno}&nbsp;</th>";
+            $column_data{gifi_accno} = $ca->{gifi_accno};
         }
         else {
             $i++;
             $i %= 2;
-            print qq|<tr class=listrow$i>|;
-            $column_data{accno} = "<td><a href=$href>$ca->{accno}</a></td>";
-            $column_data{gifi_accno} =
-"<td><a href=$href&accounttype=gifi>$ca->{gifi_accno}</a>&nbsp;</td>";
-            $column_data{description} = "<td>$ca->{description}</td>";
+            $column_data{i} = $i;
+            $column_data{accno} = {
+                text => $ca->{accno},
+                href => $href};
+            $column_data{gifi_accno} = {
+                text => $ca->{gifi_accno},
+                href => "$href&accounttype=gifi"};
+            $column_data{description} = $ca->{description};
         }
 
         $column_data{debit} =
-            "<td align=right>"
-          . $form->format_amount( \%myconfig, $ca->{debit}, 2, "&nbsp;" )
-          . "</td>\n";
+          $form->format_amount( \%myconfig, $ca->{debit}, 2, " " );
         $column_data{credit} =
-            "<td align=right>"
-          . $form->format_amount( \%myconfig, $ca->{credit}, 2, "&nbsp;" )
-          . "</td>\n";
+          $form->format_amount( \%myconfig, $ca->{credit}, 2, " " );
 
         $totaldebit  += $ca->{debit};
         $totalcredit += $ca->{credit};
 
-        for (@column_index) { print "$column_data{$_}\n" }
-
-        print qq|
-</tr>
-|;
+	push @rows, \%column_data;
     }
 
     for (qw(accno gifi_accno description)) {
-        $column_data{$_} = "<td>&nbsp;</td>";
+        $column_data{$_} = " ";
     }
 
-    $column_data{debit} =
-      "<th align=right class=listtotal>"
-      . $form->format_amount( \%myconfig, $totaldebit, 2, 0 ) . "</th>";
-    $column_data{credit} =
-      "<th align=right class=listtotal>"
-      . $form->format_amount( \%myconfig, $totalcredit, 2, 0 ) . "</th>";
+    $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, 0 );
+    $column_data{credit} = $form->format_amount(\%myconfig, $totalcredit, 2, 0);
 
-    print "<tr class=listtotal>";
+    my @buttons;
+    push @buttons, {
+        name => 'action',
+        value => 'csv_chart_of_accounts',
+        text => $locale->text('CSV Report'),
+        type => 'submit',
+        class => 'submit',
+    };
 
-    for (@column_index) { print "$column_data{$_}\n" }
-
-    print qq|
-</tr>
-<tr>
-  <td colspan=$colspan><hr size=3 noshade></td>
-</tr>
-</table>
-
-</body>
-</html>
-|;
-
+    my $template = LedgerSMB::Template->new(
+        user => \%myconfig, 
+        locale => $locale,
+        path => 'UI',
+        template => 'am-list-accounts',
+        format => ($form->{action} =~ /^csv/)? 'CSV': 'HTML');
+    $template->render({
+        form => \%$form,
+        buttons => ..hidden..,
+        columns => ..hidden..,
+        heading => \%column_header,
+	totals => \%column_data,
+        rows => ..hidden..,
+    });
 }
 
+sub csv_chart_of_accounts { &chart_of_accounts }
+
 sub list {
 
     $form->{title} = $locale->text('List Transactions');


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