summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/am.pl140
-rw-r--r--bin/ca.pl134
2 files changed, 125 insertions, 149 deletions
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|<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>|;
-
- $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>
-|;
+ $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} = "&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{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>|;
+ $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|
-<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";
- }
-
- print qq|
- <tr><td colspan="$colspan"><hr size="3" noshade /></td></tr>
-</table>
-
-</body>
-</html>
-|;
-
-}
+ 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|<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;
-
- $form->header;
-
- 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>
-|;
+ 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|<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>";
-
- print "<tr class=listtotal>";
-
- for (@column_index) { print "$column_data{$_}\n" }
-
- print qq|
-</tr>
-<tr>
- <td colspan=$colspan><hr size=3 noshade></td>
-</tr>
-</table>
-
-</body>
-</html>
-|;
-
+ $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');