X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fca.pl;h=774da855a9c37c3449e74d35dbe2cfa4719e968e;hb=713de5ed35a8a1faea940354254c4e781631c495;hp=f92e8774661d8072d4926a3bec2e94b9c97008a5;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/ca.pl b/bin/mozilla/ca.pl index f92e87746..774da855a 100644 --- a/bin/mozilla/ca.pl +++ b/bin/mozilla/ca.pl @@ -24,18 +24,27 @@ # 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 # search and edit transactions posted by the GL, AR and AP -# +# #====================================================================== +use POSIX qw(strftime); use SL::CA; +use SL::DB::Default; +use SL::ReportGenerator; + +require "bin/mozilla/reportgenerator.pl"; + +use strict; 1; + # end of main # this is for our long dates @@ -66,402 +75,519 @@ use SL::CA; # $locale->text('Nov') # $locale->text('Dec') - sub chart_of_accounts { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('report'); + + $form->{title} = $locale->text('Chart of Accounts'); + + 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); - @column_index = qw(accno gifi_accno description debit credit); + 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'), }, + ); - $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|; - + my $report = SL::ReportGenerator->new(\%myconfig, $form); - $form->{title} = $locale->text('Chart of Accounts'); + $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'; + + $report->set_columns(%column_defs); + $report->set_column_order(@columns); + + $report->set_export_options('chart_of_accounts'); + + $report->set_sort_indicator($form->{sort}, 1); + + my %totals = ('debit' => 0, 'credit' => 0); - $colspan = $#column_index + 1; - - $form->header; - - print qq| - - - - - - |; - - map { print $column_header{$_} } @column_index; - - print qq| - -|; - - - foreach $ca (@{ $form->{CA} }) { - - $description = $form->escape($ca->{description}); - $gifi_description = $form->escape($ca->{gifi_description}); - - $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|; - - 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} = ""; + 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"; - - $totaldebit += $ca->{debit}; - $totalcredit += $ca->{credit}; - - map { print $column_data{$_} } @column_index; - - print qq| - -|; - } - map { $column_data{$_} = ""; } qw(accno gifi_accno description); + map { $row->{$_} = { 'data' => $ca->{$_} } } @columns; - $column_data{debit} = ""; - $column_data{credit} = ""; - - print ""; + 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| - - - - -
$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)."

+ $report->add_data($row); + } - - -|; + my $row = { map { $_ => { 'class' => 'listtotal', 'align' => 'right' } } @columns }; + map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } qw(debit credit); - $lxdebug->leave_sub(); -} + $report->add_separator(); + $report->add_data($row); + $report->generate_with_headers(); + + $main::lxdebug->leave_sub(); +} sub list { - $lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('report'); + $::form->{title} = $::locale->text('List Transactions') . " - " . $::locale->text('Account') . " $::form->{accno}" . " - " . $::form->{description}; - $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}"; - } + $::form->header; + print $::form->parse_html_template('ca/list', { + year => DateTime->today->year, + }); + + $::lxdebug->leave_sub; +} - # get departments - $form->all_departments(\%myconfig); - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "