use SL::DB::Default;
use SL::DB::Project;
+use SL::DB::Customer;
use SL::PE;
use SL::RP;
use SL::Iconv;
# $form->parse_html_template('rp/html_report_susa')
my $rp_access_map = {
- 'projects' => 'report',
- 'ar_aging' => 'general_ledger',
- 'ap_aging' => 'general_ledger',
- 'receipts' => 'cash',
- 'payments' => 'cash',
- 'trial_balance' => 'report',
- 'income_statement' => 'report',
- 'bwa' => 'report',
- 'balance_sheet' => 'report',
+ 'projects' => 'report',
+ 'ar_aging' => 'general_ledger',
+ 'ap_aging' => 'general_ledger',
+ 'receipts' => 'cash',
+ 'payments' => 'cash',
+ 'trial_balance' => 'report',
+ 'income_statement' => 'report',
+ 'erfolgsrechnung' => 'report',
+ 'bwa' => 'report',
+ 'balance_sheet' => 'report',
};
sub check_rp_access {
my %title = (
balance_sheet => $::locale->text('Balance Sheet'),
income_statement => $::locale->text('Income Statement'),
+ erfolgsrechnung => $::locale->text('Erfolgsrechnung'),
trial_balance => $::locale->text('Trial Balance'),
ar_aging => $::locale->text('Search AR Aging'),
ap_aging => $::locale->text('Search AP Aging'),
);
$::form->{title} = $title{$::form->{report}};
+ $::request->{layout}->add_javascripts('autocomplete_customer.js');
+ $::request->{layout}->add_javascripts('autocomplete_project.js');
+ $::form->{fromdate} = DateTime->today->truncate(to => 'year')->to_kivitendo;
+ $::form->{todate} = DateTime->today->truncate(to => 'year')->add(years => 1)->add(days => -1)->to_kivitendo;
# get departments
$::form->all_departments(\%::myconfig);
$::form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 });
- my $is_projects = $::form->{report} eq "projects";
- my $is_income_statement = $::form->{report} eq "income_statement";
- my $is_bwa = $::form->{report} eq "bwa";
- my $is_balance_sheet = $::form->{report} eq "balance_sheet";
- my $is_trial_balance = $::form->{report} eq "trial_balance";
- my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
- my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
+ my $is_projects = $::form->{report} eq "projects";
+ my $is_income_statement = $::form->{report} eq "income_statement";
+ my $is_erfolgsrechnung = $::form->{report} eq "erfolgsrechnung";
+ my $is_bwa = $::form->{report} eq "bwa";
+ my $is_balance_sheet = $::form->{report} eq "balance_sheet";
+ my $is_trial_balance = $::form->{report} eq "trial_balance";
+ my $is_aging = $::form->{report} =~ /^a[rp]_aging$/;
+ my $is_payments = $::form->{report} =~ /(receipts|payments)$/;
my ($label, $nextsub, $vc);
if ($is_aging) {
$::form->header;
print $::form->parse_html_template('rp/report', {
- paymentaccounts => $paymentaccounts,
- selection => $selection,
- is_aging => $is_aging,
- vc => $vc,
- label => $label,
- year => DateTime->today->year,
- today => DateTime->today,
- nextsub => $nextsub,
- accrual => $::instance_conf->get_accounting_method ne 'cash',
- cash => $::instance_conf->get_accounting_method eq 'cash',
- is_payments => $is_payments,
- is_trial_balance => $is_trial_balance,
- is_balance_sheet => $is_balance_sheet,
- is_bwa => $is_bwa,
- is_income_statement => $is_income_statement,
- is_projects => $is_projects,
+ paymentaccounts => $paymentaccounts,
+ selection => $selection,
+ is_aging => $is_aging,
+ vc => $vc,
+ label => $label,
+ year => DateTime->today->year,
+ today => DateTime->today,
+ nextsub => $nextsub,
+ is_payments => $is_payments,
+ is_trial_balance => $is_trial_balance,
+ is_balance_sheet => $is_balance_sheet,
+ is_bwa => $is_bwa,
+ is_income_statement => $is_income_statement,
+ is_erfolgsrechnung => $is_erfolgsrechnung,
+ is_projects => $is_projects,
});
$::lxdebug->leave_sub;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- my $defaults = SL::DB::Default->get;
- $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
- $form->{templates} = $defaults->templates;
-
$form->{padding} = " ";
$form->{bold} = "<b>";
$form->{endbold} = "</b>";
. qq| $longcomparetodate|;
}
- $form->{IN} = "income_statement.html";
+ if ( $::instance_conf->get_profit_determination eq 'balance' ) {
+ $form->{title} = $locale->text('Income Statement');
+ } elsif ( $::instance_conf->get_profit_determination eq 'income' ) {
+ $form->{title} = $locale->text('Net Income Statement');
+ } else {
+ $form->{title} = "";
+ };
- $form->parse_template;
+ if ( $form->{method} eq 'cash' ) {
+ $form->{accounting_method} = $locale->text('Cash accounting');
+ } elsif ( $form->{method} eq 'accrual' ) {
+ $form->{accounting_method} = $locale->text('Accrual accounting');
+ } else {
+ $form->{accounting_method} = "";
+ };
+
+ $form->{report_date} = $locale->text('Report date') . ": " . $form->current_date;
+
+ $form->header;
+ print $form->parse_html_template('rp/income_statement');
$main::lxdebug->leave_sub();
}
+sub generate_erfolgsrechnung {
+ $::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->erfolgsrechnung(\%::myconfig, $::form);
+
+ $::form->header();
+ print $::form->parse_html_template('rp/erfolgsrechnung', $data);
+
+ $::lxdebug->leave_sub;
+}
+
+
sub generate_balance_sheet {
$::lxdebug->enter_sub;
$::auth->assert('report');
- my $defaults = SL::DB::Default->get;
- $::form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
- $::form->{templates} = $defaults->templates;
$::form->{decimalplaces} = $::form->{decimalplaces} * 1 || 2;
$::form->{padding} = " ";
$::form->{bold} = "<b>";
my $data = RP->balance_sheet(\%::myconfig, $::form);
- $::form->{asofdate} ||= $::form->current_date;
- $::form->{period} = $::locale->date(\%::myconfig, $::form->current_date, 1);
+ $::form->{asofdate} ||= $::form->current_date;
+ $::form->{report_title} = $::locale->text('Balance Sheet');
+ $::form->{report_date} ||= $::form->current_date;
($::form->{department}) = split /--/, $::form->{department};
$::form->{this_period} = $::locale->date(\%::myconfig, $::form->{asofdate}, 0);
$::form->{last_period} = $::locale->date(\%::myconfig, $::form->{compareasofdate}, 0);
+# balance sheet isn't read from print templates anymore,
+# instead use template in rp
# $::form->{IN} = "balance_sheet.html";
$::form->header;
my $project = $form->{project_id} ? SL::DB::Project->new(id => $form->{project_id})->load : undef;
$form->{projectnumber} = $project ? $project->projectnumber : '';
+ # make sure todate and fromdate always have a value, even if the date fields
+ # were left empty or the inputs weren't valid dates/couldn't be parsed
+
+ $project = SL::DB::Project->new() unless $project; # dummy object for dbh
+ unless ($::locale->parse_date_to_object($::form->{fromdate})) {
+ ($form->{fromdate}) = $project->db->dbh->selectrow_array('select min(transdate) from acc_trans');
+ };
+
+ unless ($::locale->parse_date_to_object($::form->{todate})) {
+ ($form->{todate}) = $project->db->dbh->selectrow_array('select max(transdate) from acc_trans');
+ };
+
$form->{nextsub} = "generate_projects";
$form->{title} = $locale->text('Project Transactions');
RP->trial_balance(\%myconfig, \%$form);
$form->{company} = $locale->text('Company') . " " . $defaults->company;
push (@options, $form->{company});
+ if ($::form->{customer_id}) {
+ my $customer = SL::DB::Manager::Customer->find_by(id => $::form->{customer_id});
+ push @options, $::locale->text('Customer') . ' ' . $customer->displayable_name;
+ }
+
$form->{template_to} = $locale->date(\%myconfig, $form->{todate}, 0);
sub generate_ar_aging {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('general_ledger | ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
sub generate_ap_aging {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('general_ledger | ap_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
- my @hidden_variables = qw(todate customer vendor arap title ct fordate reporttype);
+ my @hidden_variables = qw(todate customer vendor arap title ct fordate reporttype department);
$report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
my @options;
$::form->header;
print $::form->parse_html_template('rp/e_mail', {
- show_bcc => $::auth->assert('email_bcc', 'may fail'),
print_options => print_options(inline => 1),
hidden_values => \@hidden_values,
});
$::form->{SM}{ $::form->{sendmode} } = "selected";
my $output = $::form->parse_html_template('rp/print_options', {
- got_printer => $::myconfig{printer},
- show_latex => $::lx_office_conf{print_templates}->{latex},
is_email => $::form->{media} eq 'email',
});
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- my $defaults = SL::DB::Default->get;
- $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
- $form->{templates} = $defaults->templates;
-
$form->{padding} = " ";
$form->{bold} = "<b>";
$form->{endbold} = "</b>";
# if (defined ($form->{fromdate|todate}=='..'))
# immer wahr
if ($form->{fromdate}){
- my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
- my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
+ my $datetime = $locale->parse_date_to_object($form->{fromdate});
$datetime->set( month => 1,
day => 1);
$form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
. qq| $longtodate|;
}
- $form->{IN} = "bwa.html";
+ $form->{report_date} = $locale->text('Report date') . ": " . $form->current_date;
+
+ if ( $form->{method} eq 'cash' ) {
+ $form->{accounting_method} = $locale->text('Cash accounting');
+ } elsif ( $form->{method} eq 'accrual' ) {
+ $form->{accounting_method} = $locale->text('Accrual accounting');
+ } else {
+ $form->{accounting_method} = "";
+ };
+
+ $form->{title} = $locale->text('BWA');
- $form->parse_template;
+ $::request->layout->add_stylesheets('bwa.css');
+ $form->header;
+ print $form->parse_html_template('rp/bwa');
$main::lxdebug->leave_sub();
}