From ba93c2ed8d5938d7a961a0ecf221c8a94415892d Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 2 Nov 2007 15:25:32 +0000 Subject: Convert tax reports to dynatable git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1838 4979c152-3d1c-0410-bac9-87ea11338e46 --- bin/rp.pl | 237 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 110 insertions(+), 127 deletions(-) (limited to 'bin') diff --git a/bin/rp.pl b/bin/rp.pl index 9e7523ac..866dde8e 100644 --- a/bin/rp.pl +++ b/bin/rp.pl @@ -2178,10 +2178,12 @@ sub generate_tax_report { RP->tax_report( \%myconfig, \%$form ); - $descvar = "$form->{accno}_description"; - $description = $form->escape( $form->{$descvar} ); - $ratevar = "$form->{accno}_rate"; - $taxrate = $form->{"$form->{accno}_rate"}; + my %hiddens; + my @options; + my $descvar = "$form->{accno}_description"; + my $description = $form->escape( $form->{$descvar} ); + my $ratevar = "$form->{accno}_rate"; + my $taxrate = $form->{"$form->{accno}_rate"}; if ( $form->{accno} =~ /^gifi_/ ) { $descvar = "gifi_$form->{accno}_description"; @@ -2190,10 +2192,10 @@ sub generate_tax_report { $taxrate = $form->{"gifi_$form->{accno}_rate"}; } - $department = $form->escape( $form->{department} ); + my $department = $form->escape( $form->{department} ); # construct href - $href = + my $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}"; # construct callback @@ -2202,26 +2204,27 @@ sub generate_tax_report { $form->sort_order(); - $callback = + my $callback = "$form->{script}?path=$form->{path}&direction=$form->{direction}&oldsort=$form->{oldsort}&action=generate_tax_report&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&summary=$form->{summary}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}"; $form->{title} = $locale->text('GIFI') . " - " if ( $form->{accno} =~ /^gifi_/ ); - $title = $form->escape( $form->{title} ); + my $title = $form->escape( $form->{title} ); $href .= "&title=$title"; $title = $form->escape( $form->{title}, 1 ); $callback .= "&title=$title"; $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |; - @columns = + my @columns = $form->sort_columns( qw(id transdate invnumber name description netamount tax total)); $form->{"l_description"} = "" if $form->{summary}; - foreach $item (@columns) { + my @column_index; + foreach my $item (@columns) { if ( $form->{"l_$item"} eq "Y" ) { push @column_index, $item; @@ -2238,10 +2241,12 @@ sub generate_tax_report { if ( $form->{department} ) { ($department) = split /--/, $form->{department}; - $option = $locale->text('Department') . " : $department"; + push @options, $locale->text('Department: [_1]', $department); } # if there are any dates + my $fromdate; + my $todate; if ( $form->{fromdate} || $form->{todate} ) { if ( $form->{fromdate} ) { $fromdate = $locale->date( \%myconfig, $form->{fromdate}, 1 ); @@ -2257,6 +2262,9 @@ sub generate_tax_report { $locale->date( \%myconfig, $form->current_date( \%myconfig ), 1 ); } + my $name; + my $invoice; + my $arap; if ( $form->{db} eq 'ar' ) { $name = $locale->text('Customer'); $invoice = 'is.pl'; @@ -2268,76 +2276,54 @@ sub generate_tax_report { $arap = 'ap.pl'; } - $option .= "
" if $option; - $option .= "$form->{period}"; - - $column_header{id} = - qq|| - . $locale->text('ID') - . qq||; - $column_header{invnumber} = - qq|| - . $locale->text('Invoice') - . qq||; - $column_header{transdate} = - qq|| - . $locale->text('Date') - . qq||; - $column_header{netamount} = - qq|| . $locale->text('Amount') . qq||; - $column_header{tax} = - qq|| . $locale->text('Tax') . qq||; - $column_header{total} = - qq|| . $locale->text('Total') . qq||; - - $column_header{name} = - qq|$name|; - - $column_header{description} = - qq|| - . $locale->text('Description') - . qq||; - - $form->header; - - print qq| - - - - - - - - - - - - - - - - -
$form->{title}
$option
- - -|; + push @options, $form->{period}; - for (@column_index) { print "$column_header{$_}\n" } + my %column_header; + $column_header{id} = { + href => "$href&sort=id", + text => $locale->text('ID'), + }; + $column_header{invnumber} = { + href => "$href&sort=invnumber", + text => $locale->text('Invoice') + }; + $column_header{transdate} = { + href => "$href&sort=transdate", + text => $locale->text('Date'), + }; + $column_header{netamount} = $locale->text('Amount'); + $column_header{tax} = $locale->text('Tax'); + $column_header{total} = $locale->text('Total'); - print qq| - -|; + $column_header{name} = { + href => "$href&sort=name", + text => $name, + }; + $column_header{description} = { + href => "$href&sort=description", + text => $locale->text('Description'), + }; # add sort and escape callback $callback = $form->escape( $callback . "&sort=$form->{sort}" ); + my $sameitem; if ( @{ $form->{TR} } ) { $sameitem = $form->{TR}->[0]->{ $form->{sort} }; } - foreach $ref ( @{ $form->{TR} } ) { + my $totalnetamount; + my @rows; + my $i; + foreach my $ref ( @{ $form->{TR} } ) { - $module = ( $ref->{invoice} ) ? $invoice : $arap; + my %column_data; + my $module = ( $ref->{invoice} ) ? $invoice : $arap; $module = 'ps.pl' if $ref->{till}; if ( $form->{l_subtotal} eq 'Y' ) { if ( $sameitem ne $ref->{ $form->{sort} } ) { - &tax_subtotal; + push @rows, &tax_subtotal(\@column_index); $sameitem = $ref->{ $form->{sort} }; } } @@ -2351,103 +2337,100 @@ sub generate_tax_report { for (qw(netamount tax total)) { $ref->{$_} = - $form->format_amount( \%myconfig, $ref->{$_}, 2, " " ); + $form->format_amount( \%myconfig, $ref->{$_}, 2, ' ' ); } - $column_data{id} = qq||; - $column_data{invnumber} = -qq||; + $column_data{id} = $ref->{id}; + $column_data{invnumber} = { + href => "$module?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback", + text => $ref->{invnumber}, + }; for (qw(id transdate name partnumber description)) { - $column_data{$_} = qq||; + $column_data{$_} = $ref->{$_}; } for (qw(netamount tax total)) { - $column_data{$_} = qq||; + $column_data{$_} = $ref->{$_}; } $i++; $i %= 2; - print qq| - -|; - - for (@column_index) { print "$column_data{$_}\n" } - - print qq| - -|; + $column_data{i} = $i; + push @rows, \%column_data; } if ( $form->{l_subtotal} eq 'Y' ) { - &tax_subtotal; + push @rows, &tax_subtotal(\@column_index); } - for (@column_index) { $column_data{$_} = qq|| } - - print qq| - - -|; + my %column_data; + for (@column_index) { $column_data{$_} = ' ' } $total = $form->format_amount( \%myconfig, $totalnetamount + $totaltax, - 2, " " ); + 2, ' ' ); $totalnetamount = - $form->format_amount( \%myconfig, $totalnetamount, 2, " " ); - $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, " " ); - - $column_data{netamount} = - qq||; - $column_data{tax} = qq||; - $column_data{total} = qq||; - - for (@column_index) { print "$column_data{$_}\n" } + $form->format_amount( \%myconfig, $totalnetamount, 2, ' ' ); + $totaltax = $form->format_amount( \%myconfig, $totaltax, 2, ' ' ); - print qq| - -
$ref->{id}{path}&action=edit&id=$ref->{id}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber}$ref->{$_}$ref->{$_}
 
$totalnetamount$totaltax$total
-

- - - -|; + $column_data{netamount} = $totalnetamount; + $column_data{tax} = $totaltax; + $column_data{total} = $total; + my $template = LedgerSMB::Template->new_UI( + user => \%myconfig, + locale => $locale, + template => 'form-dynatable', + ); + $template->render({ + form => $form, + hiddens => \%hiddens, + options => \@options, + columns => \@column_index, + heading => \%column_header, + rows => \@rows, + totals => \%column_data, + row_alignment => { + netamount => 'right', + tax => 'right', + total => 'right', + }, + }); } sub tax_subtotal { - for (@column_index) { $column_data{$_} = " " } + my $column_index = shift; + my %column_data; + for (@{$column_index}) { $column_data{$_} = ' ' } + #SC: Yes, right now these are global, inherited from generate_tax_report $subtotal = $form->format_amount( \%myconfig, $subtotalnetamount + $subtotaltax, - 2, " " ); + 2, ' ' ); $subtotalnetamount = - $form->format_amount( \%myconfig, $subtotalnetamount, 2, " " ); + $form->format_amount( \%myconfig, $subtotalnetamount, 2, ' ' ); $subtotaltax = - $form->format_amount( \%myconfig, $subtotaltax, 2, " " ); + $form->format_amount( \%myconfig, $subtotaltax, 2, ' ' ); - $column_data{netamount} = - "$subtotalnetamount"; - $column_data{tax} = "$subtotaltax"; - $column_data{total} = "$subtotal"; + $column_data{netamount} = { + class => 'subtotal', + text => $subtotalnetamount, + }; + $column_data{tax} = { + class => 'subtotal', + text => $subtotaltax, + }; + $column_data{total} = { + class => 'subtotal', + text => $subtotal, + }; $subtotalnetamount = 0; $subtotaltax = 0; - print qq| - -|; - for (@column_index) { print "\n$column_data{$_}" } - - print qq| - -|; + \%column_data; } -- cgit v1.2.3