+ $main::lxdebug->leave_sub();
+}
+
+sub generate_balance_sheet {
+ $::lxdebug->enter_sub;
+ $::auth->assert('report');
+
+ $::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
+ $::form->{padding} = " ";
+ $::form->{bold} = "<b>";
+ $::form->{endbold} = "</b>";
+ $::form->{br} = "<br>";
+
+ my $data = RP->balance_sheet(\%::myconfig, $::form);
+
+ $::form->{asofdate} ||= $::form->current_date;
+ $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
+
+ ($::form->{department}) = split /--/, $::form->{department};
+
+ # define Current Earnings account
+ my $padding = $::form->{l_heading} ? $::form->{padding} : "";
+ push @{ $::form->{equity_account} }, $padding . $::locale->text('Current Earnings');
+
+ $::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
+ $::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
+
+# $::form->{IN} = "balance_sheet.html";
+
+ # setup company variables for the form
+ map { $::form->{$_} = $::myconfig{$_} } qw(company address businessnumber nativecurr);
+
+ $::form->{templates} = $::myconfig{templates};
+
+ $::form->header;
+ print $::form->parse_html_template('rp/balance_sheet', $data);
+
+ $::lxdebug->leave_sub;
+}
+
+sub generate_projects {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('report');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ &get_project("generate_projects");
+ $form->{projectnumber} = $form->{projectnumber_1};
+
+ $form->{nextsub} = "generate_projects";
+ $form->{title} = $locale->text('Project Transactions');
+ RP->trial_balance(\%myconfig, \%$form);
+
+ list_accounts('generate_projects');
+
+ $main::lxdebug->leave_sub();
+}
+
+# Antonio Gallardo
+#
+# D.S. Feb 16, 2001
+# included links to display transactions for period entered
+# added headers and subtotals
+#
+sub generate_trial_balance {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('report');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ if ($form->{reporttype} eq "custom") {
+
+ #forgotten the year --> thisyear
+ if ($form->{year} !~ m/^\d\d\d\d$/) {
+ $locale->date(\%myconfig, $form->current_date(\%myconfig), 0) =~
+ /(\d\d\d\d)/;
+ $form->{year} = $1;
+ }
+
+ #yearly report
+ if ($form->{duetyp} eq "13") {
+ $form->{fromdate} = "1.1.$form->{year}";
+ $form->{todate} = "31.12.$form->{year}";
+ }
+
+ #Quater reports
+ if ($form->{duetyp} eq "A") {
+ $form->{fromdate} = "1.1.$form->{year}";
+ $form->{todate} = "31.3.$form->{year}";
+ }
+ if ($form->{duetyp} eq "B") {
+ $form->{fromdate} = "1.4.$form->{year}";
+ $form->{todate} = "30.6.$form->{year}";
+ }
+ if ($form->{duetyp} eq "C") {
+ $form->{fromdate} = "1.7.$form->{year}";
+ $form->{todate} = "30.9.$form->{year}";
+ }
+ if ($form->{duetyp} eq "D") {
+ $form->{fromdate} = "1.10.$form->{year}";
+ $form->{todate} = "31.12.$form->{year}";
+ }
+
+ #Monthly reports
+ SWITCH: {
+ $form->{duetyp} eq "1" && do {
+ $form->{fromdate} = "1.1.$form->{year}";
+ $form->{todate} = "31.1.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "2" && do {
+ $form->{fromdate} = "1.2.$form->{year}";
+
+ #this works from 1901 to 2099, 1900 and 2100 fail.
+ my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
+ $form->{todate} = "$leap.2.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "3" && do {
+ $form->{fromdate} = "1.3.$form->{year}";
+ $form->{todate} = "31.3.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "4" && do {
+ $form->{fromdate} = "1.4.$form->{year}";
+ $form->{todate} = "30.4.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "5" && do {
+ $form->{fromdate} = "1.5.$form->{year}";
+ $form->{todate} = "31.5.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "6" && do {
+ $form->{fromdate} = "1.6.$form->{year}";
+ $form->{todate} = "30.6.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "7" && do {
+ $form->{fromdate} = "1.7.$form->{year}";
+ $form->{todate} = "31.7.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "8" && do {
+ $form->{fromdate} = "1.8.$form->{year}";
+ $form->{todate} = "31.8.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "9" && do {
+ $form->{fromdate} = "1.9.$form->{year}";
+ $form->{todate} = "30.9.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "10" && do {
+ $form->{fromdate} = "1.10.$form->{year}";
+ $form->{todate} = "31.10.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "11" && do {
+ $form->{fromdate} = "1.11.$form->{year}";
+ $form->{todate} = "30.11.$form->{year}";
+ last SWITCH;
+ };
+ $form->{duetyp} eq "12" && do {
+ $form->{fromdate} = "1.12.$form->{year}";
+ $form->{todate} = "31.12.$form->{year}";
+ last SWITCH;
+ };
+ }
+ hotfix_reformat_date();
+ }
+
+
+ # get for each account initial balance, debits and credits
+ RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
+
+
+ $form->{rowcount} = scalar @{ $form->{TB} || [] };
+ $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
+
+ my @columns = (
+ "accno", "description",
+ "last_transaction", "soll_eb",
+ "haben_eb",
+ "soll", "haben",
+ "soll_kumuliert", "haben_kumuliert",
+ "soll_saldo", "haben_saldo"
+ );
+
+
+ my $attachment_basename = $locale->text('trial_balance');
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
+
+ my @hidden_variables = qw(fromdate todate year cash);
+
+ my $href = build_std_url('action=generate_trial_balance', grep { $form->{$_} } @hidden_variables);
+
+ my %column_defs = (
+ 'accno' => { 'text' => $locale->text('Account'), },
+ 'description' => { 'text' => $locale->text('Description'), },
+ 'last_transaction' => { 'text' => $locale->text('Last Transaction'), },
+ 'soll_eb' => { 'text' => $locale->text('Debit Starting Balance'), },
+ 'haben_eb' => { 'text' => $locale->text('Credit Starting Balance'), },
+ 'soll' => { 'text' => $locale->text('Debit'), },
+ 'haben' => { 'text' => $locale->text('Credit'), },
+ 'soll_kumuliert' => { 'text' => $locale->text('Sum Debit'), },
+ 'haben_kumuliert' => { 'text' => $locale->text('Sum Credit'), },
+ 'soll_saldo' => { 'text' => $locale->text('Saldo Debit'), },
+ 'haben_saldo' => { 'text' => $locale->text('Saldo Credit'), }
+ );
+
+
+
+ my %column_alignment = map { $_ => 'right' } qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
+
+ map { $column_defs{$_}->{visible} = 1 } @columns;
+
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
+
+ $report->set_export_options('generate_trial_balance', @hidden_variables);
+
+ my @options;
+
+
+ $form->{template_fromto} = $locale->date(\%myconfig, $form->{fromdate}, 0) . " - " . $locale->date(\%myconfig, $form->{todate}, 0);
+
+ $form->{print_date} = $locale->text('Create Date') . " " . $locale->date(\%myconfig, $form->current_date(\%myconfig), 0);
+ push (@options, $form->{print_date});
+
+ $form->{company} = $locale->text('Company') . " " . $myconfig{company};
+ push (@options, $form->{company});
+
+
+ $form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
+
+ $report->set_options('output_format' => 'HTML',
+ 'top_info_text' => join("\n", @options),
+ 'title' => $form->{title},
+ 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
+ 'html_template' => 'rp/html_report_susa',
+ 'pdf_template' => 'rp/html_report_susa',
+ );
+ $report->set_options_from_form();
+ $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
+
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $href .= "&sort=$form->{sort}";
+
+ # escape callback for href
+ my $callback = $form->escape($href);
+
+ my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
+
+ my %totals = map { $_ => 0 } @subtotal_columns;
+
+ my $edit_url = build_std_url('action=edit', 'type', 'vc');
+
+ my $idx;
+ foreach my $accno (@{ $form->{TB} || [] }) {
+
+ $accno->{soll} = $accno->{debit};
+ $accno->{haben} = $accno->{credit};
+ map { $totals{$_} += $accno->{$_} } @subtotal_columns;
+
+ map { $accno->{$_} = $accno->{$_} == 0 ? '' : $form->format_amount(\%myconfig, $accno->{$_}, 2) }
+ qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);