X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fca.pl;h=774da855a9c37c3449e74d35dbe2cfa4719e968e;hb=08e48f66590f580cbe2c8e3df76883d88b4c0fef;hp=9e3d4ecf2f7acc44094094d40d7b0dd23f277a74;hpb=d333f237fcd8ef1d9145b7b51072f7088b857301;p=kivitendo-erp.git diff --git a/bin/mozilla/ca.pl b/bin/mozilla/ca.pl index 9e3d4ecf2..774da855a 100644 --- a/bin/mozilla/ca.pl +++ b/bin/mozilla/ca.pl @@ -24,7 +24,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # module for Chart of Accounts, Income Statement and Balance Sheet @@ -32,7 +33,15 @@ # #====================================================================== +use POSIX qw(strftime); + use SL::CA; +use SL::DB::Default; +use SL::ReportGenerator; + +require "bin/mozilla/reportgenerator.pl"; + +use strict; 1; @@ -67,252 +76,246 @@ use SL::CA; # $locale->text('Dec') sub chart_of_accounts { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - CA->all_accounts(\%myconfig, \%$form); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - @column_index = qw(accno description debit credit); - - $column_header{accno} = - qq|| . $locale->text('Account') . 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|; + $main::auth->assert('report'); $form->{title} = $locale->text('Chart of Accounts'); - $colspan = $#column_index + 1; + if ( $::instance_conf->get_accounting_method eq 'cash' ) { + # $form->{method} can probably be made redundant now that we have get_accounting_method + $form->{method} = "cash"; + } + + CA->all_accounts(\%myconfig, \%$form); - $form->header; + my @columns = qw(accno description debit credit); + my %column_defs = ( + 'accno' => { 'text' => $locale->text('Account'), }, + 'description' => { 'text' => $locale->text('Description'), }, + 'debit' => { 'text' => $locale->text('Debit'), }, + 'credit' => { 'text' => $locale->text('Credit'), }, + ); - print qq| - + my $report = SL::ReportGenerator->new(\%myconfig, $form); - - - - |; + $report->set_options('output_format' => 'HTML', + 'title' => $form->{title}, + 'attachment_basename' => $locale->text('chart_of_accounts') . strftime('_%Y%m%d', localtime time), + 'std_column_visibility' => 1, + ); + $report->set_options_from_form(); + $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv'; - map { print $column_header{$_} } @column_index; + $report->set_columns(%column_defs); + $report->set_column_order(@columns); - print qq| - -|; + $report->set_export_options('chart_of_accounts'); - foreach $ca (@{ $form->{CA} }) { + $report->set_sort_indicator($form->{sort}, 1); - $description = $form->escape($ca->{description}); + my %totals = ('debit' => 0, 'credit' => 0); - $href = - qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&password=$form->{password}&description=$description|; + foreach my $ca (@{ $form->{CA} }) { + next unless defined $ca->{amount}; + my $row = { }; - if ($ca->{charttype} eq "H") { - print qq||; - map { $column_data{$_} = ""; } qw(accno description); - } else { - $i++; - $i %= 2; - print qq||; - $column_data{accno} = ""; - $column_data{description} = ""; - } - my $debit = ""; - my $credit = ""; - if ($ca->{debit}) { - $debit = $form->format_amount(\%myconfig, $ca->{debit}, 2, " "); + foreach (qw(debit credit)) { + $totals{$_} += $ca->{$_} * 1; + $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_}); } - if ($ca->{credit}) { - $credit = $form->format_amount(\%myconfig, $ca->{credit}, 2, " "); - } - $column_data{debit} = - "\n"; - $column_data{credit} = - "\n"; - - $totaldebit += $ca->{debit}; - $totalcredit += $ca->{credit}; - - map { print $column_data{$_} } @column_index; - - print qq| - -|; - } - map { $column_data{$_} = ""; } - qw(accno description); + map { $row->{$_} = { 'data' => $ca->{$_} } } @columns; - $column_data{debit} = - ""; - $column_data{credit} = - ""; + map { $row->{$_}->{align} = 'right' } qw(debit credit); + map { $row->{$_}->{class} = 'listheading' } @columns if ($ca->{charttype} eq "H"); - print ""; + $row->{accno}->{link} = build_std_url('action=list', 'accno=' . E($ca->{accno}), 'description=' . E($ca->{description})); - map { print $column_data{$_} } @column_index; + $report->add_data($row); + } + + my $row = { map { $_ => { 'class' => 'listtotal', 'align' => 'right' } } @columns }; + map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } qw(debit credit); - print qq| - - - - -
$form->{title}
$ca->{$_}
$ca->{accno}$ca->{description}" - . $debit - . "" - . $credit - . "
 " - . $form->format_amount(\%myconfig, $totaldebit, 2, 0) . "" - . $form->format_amount(\%myconfig, $totalcredit, 2, 0) . "

+ $report->add_separator(); + $report->add_data($row); - - -|; + $report->generate_with_headers(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub list { - $lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('report'); - $form->{title} = $locale->text('List Transactions'); - $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}"; + $::form->{title} = $::locale->text('List Transactions') . " - " . $::locale->text('Account') . " $::form->{accno}" . " - " . $::form->{description}; - # get departments - $form->all_departments(\%myconfig); - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "