From 59b539628096d57bc8803682bb9990939d5e9178 Mon Sep 17 00:00:00 2001 From: tetragon Date: Mon, 10 Sep 2007 21:13:14 +0000 Subject: Initial templating of the GL report. Adding CSV output git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1555 4979c152-3d1c-0410-bac9-87ea11338e46 --- bin/gl.pl | 185 ++++++++++++++++++++++++++++---------------------------------- 1 file changed, 84 insertions(+), 101 deletions(-) (limited to 'bin') diff --git a/bin/gl.pl b/bin/gl.pl index 89a4cf88..16871f25 100644 --- a/bin/gl.pl +++ b/bin/gl.pl @@ -47,6 +47,7 @@ use LedgerSMB::GL; use LedgerSMB::PE; +use LedgerSMB::Template; require "bin/arap.pl"; @@ -640,31 +641,6 @@ sub generate_report { $column_header{balance} = "" . $locale->text('Balance') . ""; $column_header{cleared} = qq|| . $locale->text('R') . qq||; - $form->header; - - print qq| - - - - - - - - - - - - - - - - -
$form->{title}
$option
- - -|; - - for (@column_index) { print "$column_header{$_}\n" } - - print " - -"; - # add sort to callback $form->{callback} = "$callback&sort=$form->{sort}"; $callback = $form->escape( $form->{callback} ); @@ -677,24 +653,17 @@ sub generate_report { $cml = -1 if $form->{contra}; } + my @rows; if ( ( $form->{accno} || $form->{gifi_accno} ) && $form->{balance} ) { + my %column_data; - for (@column_index) { $column_data{$_} = "" } - $column_data{balance} = ""; + for (@column_index) { $column_data{$_} = " " } + $column_data{balance} = + $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, + 2, 0 ); - $i++; - $i %= 2; - print qq| - -|; - for (@column_index) { print "$column_data{$_}\n" } - - print qq| - -|; + $column_data{i} = 1; + push @rows, \%column_data; } # reverse href @@ -702,13 +671,14 @@ sub generate_report { $form->sort_order(); $href =~ s/direction=$form->{direction}/direction=$direction/; - $i = 0; + my $i = 0; foreach $ref ( @{ $form->{GL} } ) { + my %column_data; # if item ne sort print subtotal if ( $form->{l_subtotal} eq 'Y' ) { if ( $sameitem ne $ref->{ $form->{sort} } ) { - &gl_subtotal; + push @rows, &gl_subtotal_tt(); } } @@ -725,62 +695,45 @@ sub generate_report { $ref->{credit} = $form->format_amount( \%myconfig, $ref->{credit}, 2, " " ); - for (qw(id transdate)) { $column_data{$_} = "" } + for (qw(id transdate)) { $column_data{$_} = "$ref->{$_}" } $column_data{reference} = -""; +"{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}"; $ref->{notes} =~ s/\r?\n/
/g; for (qw(description source memo notes department)) { - $column_data{$_} = "
"; + $column_data{$_} = "$ref->{$_} "; } - $column_data{debit} = ""; - $column_data{credit} = ""; + $column_data{debit} = "$ref->{debit}"; + $column_data{credit} = "$ref->{credit}"; $column_data{accno} = -""; +"{accno}&callback=$callback>$ref->{accno} $ref->{accname}"; $column_data{gifi_accno} = -""; - $column_data{balance} = ""; +"{gifi_accno}&callback=$callback>$ref->{gifi_accno} "; + $column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, + 2, 0 ); $column_data{cleared} = - ( $ref->{cleared} ) ? "" : ""; + ( $ref->{cleared} ) ? "*" : " "; if ( $ref->{id} != $sameid ) { $i++; $i %= 2; } - print " - "; - for (@column_index) { print "$column_data{$_}\n" } - print ""; + $column_data{'i'} = $i; + push @rows, \%column_data; $sameid = $ref->{id}; } - &gl_subtotal if ( $form->{l_subtotal} eq 'Y' ); - - for (@column_index) { $column_data{$_} = "" } + push @rows, &gl_subtotal_tt() if ( $form->{l_subtotal} eq 'Y' ); - $column_data{debit} = - ""; - $column_data{credit} = - ""; - $column_data{balance} = - ""; + for (@column_index) { $column_data{$_} = " " } - print qq| - -|; - - for (@column_index) { print "$column_data{$_}\n" } + $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, " " ); + $column_data{credit} = $form->format_amount( \%myconfig, $totalcredit, 2, " " ); + $column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, 2, 0 ); $i = 1; if ( $myconfig{acs} !~ /General Ledger--General Ledger/ ) { @@ -819,40 +772,70 @@ qq| -
 " - . $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, - 2, 0 ) - . "
$ref->{$_}{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}$ref->{$_} $ref->{debit}$ref->{credit}{accno}&callback=$callback>$ref->{accno} $ref->{accname}{gifi_accno}&callback=$callback>$ref->{gifi_accno} " - . $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, - 2, 0 ) - . "* 
 " - . $form->format_amount( \%myconfig, $totaldebit, 2, " " ) . "" - . $form->format_amount( \%myconfig, $totalcredit, 2, " " ) . "" - . $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, 2, 0 ) - . "
-

+ my @buttons; + foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) { + push @buttons, $item->{code}; + } -
+##SC: Taking this out for now... +## if ( $form->{lynx} ) { +## require "bin/menu.pl"; +## &menubar; +## } + + my $template; + if ($form->{action} eq 'csv_gl_report') { + $template = LedgerSMB::Template->new( + user => \%myconfig, + locale => $locale, + path => 'UI', + template => 'gl-report', + format => 'CSV' + ); + } else { + $template = LedgerSMB::Template->new( + user => \%myconfig, + locale => $locale, + path => 'UI', + template => 'gl-report', + format => 'HTML', + no_escape => 1 + ); + } + $template->render({ + form => $form, + buttons => \@buttons, + options => $option, + columns => \@column_index, + heading => \%column_header, + rows => \@rows, + totals => \%column_data + }); -
{script}> -|; +} - $form->hide_form(qw(callback path login sessionid)); +sub csv_gl_report { &generate_report } - foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) { - print $item->{code}; - } +sub gl_subtotal_tt { - if ( $form->{lynx} ) { - require "bin/menu.pl"; - &menubar; - } + my %column_data; + $subtotaldebit = + $form->format_amount( \%myconfig, $subtotaldebit, 2, " " ); + $subtotalcredit = + $form->format_amount( \%myconfig, $subtotalcredit, 2, " " ); - print qq| + for (@column_index) { $column_data{$_} = " " } + $column_data{'is_subtotal'} = 1; -
+ $column_data{debit} = $subtotaldebit; + $column_data{credit} = $subtotalcredit; - - -|; + $subtotaldebit = 0; + $subtotalcredit = 0; + + $sameitem = $ref->{ $form->{sort} }; + return \%column_data; } sub gl_subtotal { -- cgit v1.2.3