1 package SL::Controller::ChartOfAccounts;
4 use parent qw(SL::Controller::Base);
6 use POSIX qw(strftime);
10 use SL::ReportGenerator;
11 use SL::Controller::Helper::ReportGenerator;
12 use SL::Locale::String;
14 use Rose::Object::MakeMethods::Generic (
15 scalar => [ qw(report) ],
18 __PACKAGE__->run_before(sub { $::auth->assert('report'); });
23 if ( $::instance_conf->get_accounting_method eq 'cash' ) {
24 $::form->{method} = "cash";
27 $self->prepare_report;
28 $self->set_report_data;
29 $self->report->generate_with_headers;
37 $self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
39 $self->report->{title} = t8 ('Chart of Accounts');
40 my @columns = qw(accno description debit credit);
42 accno => { text => t8('Account') },
43 description => { text => t8('Description') },
44 debit => { text => t8('Debit') },
45 credit => { text => t8('Credit') },
48 $self->report->set_options(
49 std_column_visibility => 1,
50 controller_class => 'ChartOfAccounts',
51 output_format => 'HTML',
52 title => t8('Chart of Accounts'),
53 allow_pdf_export => 1,
54 allow_csv_export => 1,
55 attachment_basename => t8('chart_of_accounts') . strftime('_%Y%m%d', localtime time),
57 $self->report->set_columns(%column_defs);
58 $self->report->set_column_order(@columns);
60 $self->report->set_export_options(qw(list));
61 $self->report->set_options_from_form;
62 $self->report->set_sort_indicator($::form->{sort}, 1);
71 # i tried to use the get_balance function from SL::DB::Manager::Chart here,
72 # but the results i got were different (numbers and defined balance/amount),
73 # the database queries in CA are more sophisticated, therefore i'm still using these for now,
74 # also performance wise they seem faster
75 CA->all_accounts(\%::myconfig, \%$::form);
77 my $formatted_zero = $::form->format_amount(\%::myconfig, 0., 2);
79 for my $chart (@{ $::form->{CA} }) {
80 my $balance = $chart->{amount};
82 my $link = "controller.pl?action=ListTransactions%2freport_settings&accno=$chart->{accno}&link=1";
83 if (defined($balance)) {
85 accno => { data => $chart->{accno}, link => $link },
86 description => { data => $chart->{description} },
87 debit => { data => $balance < 0 ? $::form->format_amount(\%::myconfig, $balance * -1., 2) : ''},
88 credit => { data => $balance >= 0 ? $::form->format_amount(\%::myconfig, $balance, 2) : ''},
90 $data{$_}->{align} = 'right' for qw(debit credit);
91 map { $data{$_}->{class} = 'listheading' } keys %data if ($chart->{charttype} eq "H") ;
92 $self->report->add_data(\%data);
95 $debit_sum += $balance;
97 $credit_sum += $balance;
102 accno => { data => t8('Total') },
103 description => { data => '' },
104 debit => { data => $::form->format_amount(\%::myconfig, $debit_sum * -1., 2)},
105 credit => { data => $::form->format_amount(\%::myconfig, $credit_sum, 2)},
107 $data_total{$_}->{align} = 'right' for qw(debit credit);
108 $data_total{$_}->{class} = 'listtotal' for keys %data_total;
110 $self->report->add_data(\%data_total);
121 SL::Controller::ChartOfAccounts - Controller for the chart of accounts report
125 New controller for Reports -> Chart of Accounts.
127 This replaces the old bin/mozilla/ca.pl chart_of_accounts sub.
129 The rest of the functions from ca.pl are separated into the new ListTransactions.pm
134 Displays a list of all accounts with their balance.
136 Clicking on an account number will open the form for Reports -> List Transactions, with
137 the account number preselected.
139 Export to PDF, CSV and Chart is possible.
141 =head1 CAVEATS / TODO
143 Database queries are still from SL::CA.
145 I tried to use the get_balance function from SL::DB::Manager::Chart here,
146 but the results i got were different (numbers and defined balance/amount).
147 The database queries in CA are more sophisticated, therefore i'm still using these for now.
148 Also performance wise they seem faster.
156 Cem Aydin E<lt>cem.aydin@revamp-it.chE<gt>