From d1bdc2fdf4f965bdbf4f81ab650e8eb4839335dc Mon Sep 17 00:00:00 2001 From: tetragon Date: Thu, 13 Sep 2007 13:40:43 +0000 Subject: Templates and CSV output for the account list and the chart of accounts report git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1581 4979c152-3d1c-0410-bac9-87ea11338e46 --- UI/am-list-accounts.csv | 3 + UI/am-list-accounts.html | 66 ++++++++++++++++++++++ bin/am.pl | 140 ++++++++++++++++++++++------------------------- bin/ca.pl | 134 ++++++++++++++++++++------------------------- 4 files changed, 194 insertions(+), 149 deletions(-) create mode 100644 UI/am-list-accounts.csv create mode 100644 UI/am-list-accounts.html diff --git a/UI/am-list-accounts.csv b/UI/am-list-accounts.csv new file mode 100644 index 00000000..784c9a8f --- /dev/null +++ b/UI/am-list-accounts.csv @@ -0,0 +1,3 @@ +, +, + diff --git a/UI/am-list-accounts.html b/UI/am-list-accounts.html new file mode 100644 index 00000000..286f550e --- /dev/null +++ b/UI/am-list-accounts.html @@ -0,0 +1,66 @@ + + + + <?lsmb form.titlebar ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + < class="" align="right"> + + +
+ + > + + + + + + + + + + + +

+ +
+ +
+ + + 'hidden', name => hidden.0, value => hidden.1} ?> + + 'hidden', name => 'callback', value => form.callback} ?> + + +
+ + diff --git a/bin/am.pl b/bin/am.pl index 8acd0c0f..e41b9b59 100644 --- a/bin/am.pl +++ b/bin/am.pl @@ -38,6 +38,7 @@ use LedgerSMB::Form; use LedgerSMB::User; use LedgerSMB::RP; use LedgerSMB::GL; +use LedgerSMB::Template; 1; @@ -368,106 +369,97 @@ sub list_account { $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|| . $locale->text('Account') . qq||; - $column_header{gifi_accno} = - qq|| . $locale->text('GIFI') . qq||; - $column_header{description} = - qq|| . $locale->text('Description') . qq||; - $column_header{debit} = - qq|| . $locale->text('Debit') . qq||; - $column_header{credit} = - qq|| . $locale->text('Credit') . qq||; - $column_header{link} = - qq|| . $locale->text('Link') . qq||; - - $form->header; - $colspan = $#column_index + 1; - - print qq| - - - - - - - - -|; - - for (@column_index) { print "$column_header{$_}\n" } - - print qq| - -|; + $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'); # escape callback $callback = $form->escape($callback); - foreach $ca ( @{ $form->{CA} } ) { + my @rows; + foreach my $ca ( @{ $form->{CA} } ) { - $ca->{debit} = " "; - $ca->{credit} = " "; + my %column_data; + $ca->{debit} = " "; + $ca->{credit} = " "; if ( $ca->{amount} > 0 ) { $ca->{credit} = - $form->format_amount( \%myconfig, $ca->{amount}, 2, " " ); + $form->format_amount( \%myconfig, $ca->{amount}, 2, " " ); } if ( $ca->{amount} < 0 ) { $ca->{debit} = - $form->format_amount( \%myconfig, -$ca->{amount}, 2, " " ); + $form->format_amount( \%myconfig, -$ca->{amount}, 2, " " ); } - $ca->{link} =~ s/:/
/og; + #$ca->{link} =~ s/:/
/og; $gifi_accno = $form->escape( $ca->{gifi_accno} ); if ( $ca->{charttype} eq "H" ) { - print qq||; - - $column_data{accno} = -qq||; - $column_data{gifi_accno} = -qq||; - $column_data{description} = - qq||; - $column_data{debit} = qq||; - $column_data{credit} = qq| |; - $column_data{link} = qq||; + $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} = " "; } else { $i++; $i %= 2; - print qq| -|; - $column_data{accno} = -qq||; - $column_data{gifi_accno} = -qq||; - $column_data{description} = qq||; - $column_data{debit} = qq||; - $column_data{credit} = qq||; - $column_data{link} = qq||; + $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 "\n"; - } - - print qq| - -
$form->{title}
$ca->{accno}$ca->{gifi_accno} $ca->{description}    
$ca->{accno}$ca->{gifi_accno} $ca->{description} $ca->{debit}$ca->{credit}$ca->{link} 

- - - -|; - -} + push @rows, \%column_data; + } + + my @buttons; + push @buttons, { + name => 'action', + value => 'csv_list_account', + text => $locale->text('CSV Report'), + type => 'submit', + class => 'submit', + }; + + 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 => \@buttons, + columns => \@column_index, + heading => \%column_header, + rows => \@rows, + }); +} + +sub csv_list_account { &list_account } sub delete_account { diff --git a/bin/ca.pl b/bin/ca.pl index d606d8a5..09cc8dbe 100644 --- a/bin/ca.pl +++ b/bin/ca.pl @@ -47,6 +47,7 @@ #====================================================================== use LedgerSMB::CA; +use LedgerSMB::Template; 1; @@ -86,110 +87,93 @@ sub chart_of_accounts { @column_index = qw(accno gifi_accno description debit credit); - $column_header{accno} = - qq|| . $locale->text('Account') . qq|\n|; - $column_header{gifi_accno} = - qq|| . $locale->text('GIFI') . qq|\n|; - $column_header{description} = - qq|| . $locale->text('Description') . qq|\n|; - $column_header{debit} = - qq|| . $locale->text('Debit') . qq|\n|; - $column_header{credit} = - qq|| . $locale->text('Credit') . qq|\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; - - $form->header; - - print qq| - - - - - - |; - - for (@column_index) { print $column_header{$_} } - - print qq| - -|; + my @rows; + my $totaldebit = 0; + my $totalcredit = 0; + foreach my $ca ( @{ $form->{CA} } ) { + my %column_data; - foreach $ca ( @{ $form->{CA} } ) { + my $description = $form->escape( $ca->{description} ); + my $gifi_description = $form->escape( $ca->{gifi_description} ); - $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||; + $column_data{heading} = 'H'; for (qw(accno description)) { - $column_data{$_} = ""; + $column_data{$_} = $ca->{$_}; } - $column_data{gifi_accno} = - ""; + $column_data{gifi_accno} = $ca->{gifi_accno}; } else { $i++; $i %= 2; - print qq||; - $column_data{accno} = ""; - $column_data{gifi_accno} = -""; - $column_data{description} = ""; + $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} = - "\n"; + $form->format_amount( \%myconfig, $ca->{debit}, 2, " " ); $column_data{credit} = - "\n"; + $form->format_amount( \%myconfig, $ca->{credit}, 2, " " ); $totaldebit += $ca->{debit}; $totalcredit += $ca->{credit}; - for (@column_index) { print "$column_data{$_}\n" } - - print qq| - -|; + push @rows, \%column_data; } for (qw(accno gifi_accno description)) { - $column_data{$_} = ""; + $column_data{$_} = " "; } - $column_data{debit} = - ""; - $column_data{credit} = - ""; - - print ""; - - for (@column_index) { print "$column_data{$_}\n" } - - print qq| - - - - -
$form->{title}
$ca->{$_}$ca->{gifi_accno} 
$ca->{accno}$ca->{gifi_accno} $ca->{description}" - . $form->format_amount( \%myconfig, $ca->{debit}, 2, " " ) - . "" - . $form->format_amount( \%myconfig, $ca->{credit}, 2, " " ) - . "
 " - . $form->format_amount( \%myconfig, $totaldebit, 2, 0 ) . "" - . $form->format_amount( \%myconfig, $totalcredit, 2, 0 ) . "

- - - -|; - + $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, 0 ); + $column_data{credit} = $form->format_amount(\%myconfig, $totalcredit, 2, 0); + + my @buttons; + push @buttons, { + name => 'action', + value => 'csv_chart_of_accounts', + text => $locale->text('CSV Report'), + type => 'submit', + class => 'submit', + }; + + 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 => \@buttons, + columns => \@column_index, + heading => \%column_header, + totals => \%column_data, + rows => \@rows, + }); } +sub csv_chart_of_accounts { &chart_of_accounts } + sub list { $form->{title} = $locale->text('List Transactions'); -- cgit v1.2.3