X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fca.pl;h=774da855a9c37c3449e74d35dbe2cfa4719e968e;hb=bfa674c9d4edc551afa6e27aac6f684a7b8cb656;hp=3d52198409568586de1d14e09590102a2544f642;hpb=d319704a66e9be64da837ccea10af6774c2b0838;p=kivitendo-erp.git diff --git a/bin/mozilla/ca.pl b/bin/mozilla/ca.pl index 3d5219840..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,267 +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 gifi_accno description debit credit); - - $column_header{accno} = - qq|| . $locale->text('Account') . qq|\n|; - $column_header{gifi_accno} = - qq|| . $locale->text('GIFI') . 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"; + } - $form->header; + CA->all_accounts(\%myconfig, \%$form); - print qq| - - - - - - |; + 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'), }, + ); - map { print $column_header{$_} } @column_index; + my $report = SL::ReportGenerator->new(\%myconfig, $form); - print qq| - -|; + $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'; - foreach $ca (@{ $form->{CA} }) { + $report->set_columns(%column_defs); + $report->set_column_order(@columns); - $description = $form->escape($ca->{description}); - $gifi_description = $form->escape($ca->{gifi_description}); + $report->set_export_options('chart_of_accounts'); - $href = - qq|$form->{script}?path=$form->{path}&action=list&accno=$ca->{accno}&login=$form->{login}&password=$form->{password}&description=$description&gifi_accno=$ca->{gifi_accno}&gifi_description=$gifi_description|; + $report->set_sort_indicator($form->{sort}, 1); - if ($ca->{charttype} eq "H") { - print qq||; - map { $column_data{$_} = ""; } qw(accno description); - $column_data{gifi_accno} = ""; - } else { - $i++; - $i %= 2; - print qq||; - $column_data{accno} = ""; - $column_data{gifi_accno} = - ""; - $column_data{description} = ""; + my %totals = ('debit' => 0, 'credit' => 0); + + foreach my $ca (@{ $form->{CA} }) { + next unless defined $ca->{amount}; + my $row = { }; + + foreach (qw(debit credit)) { + $totals{$_} += $ca->{$_} * 1; + $ca->{$_} = $form->format_amount(\%myconfig, $ca->{$_}, 2) if ($ca->{$_}); } - $column_data{debit} = - "\n"; - $column_data{credit} = - "\n"; + map { $row->{$_} = { 'data' => $ca->{$_} } } @columns; - $totaldebit += $ca->{debit}; - $totalcredit += $ca->{credit}; + map { $row->{$_}->{align} = 'right' } qw(debit credit); + map { $row->{$_}->{class} = 'listheading' } @columns if ($ca->{charttype} eq "H"); - map { print $column_data{$_} } @column_index; + $row->{accno}->{link} = build_std_url('action=list', 'accno=' . E($ca->{accno}), 'description=' . E($ca->{description})); - print qq| - -|; + $report->add_data($row); } - map { $column_data{$_} = ""; } - qw(accno gifi_accno description); + my $row = { map { $_ => { 'class' => 'listtotal', 'align' => 'right' } } @columns }; + map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } qw(debit credit); + + $report->add_separator(); + $report->add_data($row); - $column_data{debit} = - ""; - $column_data{credit} = - ""; + $report->generate_with_headers(); - print ""; + $main::lxdebug->leave_sub(); +} - map { print $column_data{$_} } @column_index; +sub list { + $::lxdebug->enter_sub; + $::auth->assert('report'); - print qq| - - - - -
$form->{title}
$ca->{$_}$ca->{gifi_accno} 
$ca->{accno}$ca->{gifi_accno} $ca->{description}" - . $form->format_amount(\%myconfig, $ca->{debit}, 2, " ") - . "" - . $form->format_amount(\%myconfig, $ca->{credit}, 2, " ") - . "
 " - . $form->format_amount(\%myconfig, $totaldebit, 2, 0) . "" - . $form->format_amount(\%myconfig, $totalcredit, 2, 0) . "

+ $::form->{title} = $::locale->text('List Transactions') . " - " . $::locale->text('Account') . " $::form->{accno}" . " - " . $::form->{description}; - - -|; + $::form->header; + print $::form->parse_html_template('ca/list', { + year => DateTime->today->year, + }); - $lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -sub list { - $lxdebug->enter_sub(); +sub format_debit_credit { + $main::lxdebug->enter_sub(); - $form->{title} = $locale->text('List Transactions'); - if ($form->{accounttype} eq 'gifi') { - $form->{title} .= " - " . $locale->text('GIFI') . " $form->{gifi_accno}"; - } else { - $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}"; - } + my $dc = shift; - # get departments - $form->all_departments(\%myconfig); - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "