Skip to content

Commit

Permalink
Merge pull request #8169 from ylavoie/fix-comparison-reports
Browse files Browse the repository at this point in the history
Fix Balance Sheet & Income Tax comparisons report by dates or by periods
  • Loading branch information
ehuelsmann committed Jun 9, 2024
2 parents 9988e9d + 2710477 commit 163643c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
11 changes: 9 additions & 2 deletions lib/LedgerSMB/Report/Balance_Sheet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ Boolean, true if it is a gifi report.

has gifi => (is => 'rw', isa => 'Bool');

=item from_date
=item to_date
Dates come from LedgerSMB::Report::Dates
=cut

=item legacy_hierarchy
Boolean, true if the regular hierarchies need to be ignored,
Expand Down Expand Up @@ -168,8 +175,8 @@ sub run_report {

my $col_id = $self->cheads->map_path($self->column_path_prefix);
$self->cheads->id_props($col_id,
{ description => $self->date_to->to_output,
to_date => $self->date_to->to_output,
{ description => $self->date_to->to_output($self->{formatter_options}),
to_date => $self->date_to->to_output($self->{formatter_options}),
});

for my $line (@lines) {
Expand Down
10 changes: 3 additions & 7 deletions lib/LedgerSMB/Report/Dates.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ These are the first and last date in acc_trans.
=cut


sub get_bracket_dates {
my ($self) = @_;
my $return_hashref = {};
Expand All @@ -150,9 +149,9 @@ sub _collect_dates_comparisons {

foreach my $i (1 .. $args{comparison_periods}) {
push @dates, {
from_date => LedgerSMB::PGDate->from_input($args{"from_date_$i"}),
to_date => LedgerSMB::PGDate->from_input($args{"to_date_$i"}),
column_path_prefix => [ $i ]
from_date => LedgerSMB::PGDate->from_input($args{"from_date_$i"},$args{formatter_options}),
to_date => LedgerSMB::PGDate->from_input($args{"to_date_$i"},$args{formatter_options}),
column_path_prefix => [ sprintf('%02u', $i) ]
};
}

Expand Down Expand Up @@ -242,9 +241,6 @@ sub _set_lazy_dates {
return;
}




before 'render' => sub {
my ($self) = @_;
# Set lazy attributes
Expand Down
17 changes: 13 additions & 4 deletions lib/LedgerSMB/Report/PNL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ Boolean, true if it is a gifi report.

has gifi => (is => 'rw', isa => 'Bool');

=item from_date
=item to_date
Dates come from LedgerSMB::Report::Dates
=cut

=item legacy_hierarchy
Boolean, true if the regular hierarchies need to be ignored,
Expand Down Expand Up @@ -153,14 +160,16 @@ sub run_report {


my $col_id = $self->cheads->map_path($self->column_path_prefix);
my $_from_date = $self->from_date->to_output($self->{formatter_options});
my $_to_date = $self->to_date->to_output($self->{formatter_options});
$self->cheads->id_props($col_id,
{ description =>
$self->Text(
"[_1]\n[_2]",
$self->from_date->to_output,
$self->to_date->to_output),
from_date => $self->from_date->to_output,
to_date => $self->to_date->to_output,
$_from_date,
$_to_date),
from_date => $_from_date,
to_date => $_to_date
});

for my $line (@lines) {
Expand Down
8 changes: 5 additions & 3 deletions lib/LedgerSMB/Scripts/pnl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ sub generate_income_statement {
$rpt = LedgerSMB::Report::PNL::Income_Statement->new(
%$request,
formatter_options => $request->formatter_options,
from_date => $request->parse_date( $request->{from_date} ),
to_date => $request->parse_date( $request->{to_date} ),
from_date => $request->{from_date} ? $request->parse_date( $request->{from_date} ) : undef,
to_date => $request->{to_date} ? $request->parse_date( $request->{to_date} ) : undef,
column_path_prefix => [ 0 ]);
$rpt->run_report($request);

Expand All @@ -85,7 +85,9 @@ sub generate_income_statement {

for my $cmp_dates (@{$rpt->comparisons}) {
my $cmp = LedgerSMB::Report::PNL::Income_Statement->new(
%$request, %$cmp_dates);
%$request,
formatter_options => $request->formatter_options,
%$cmp_dates);
$cmp->run_report($request);
$rpt->add_comparison($cmp);
}
Expand Down
16 changes: 5 additions & 11 deletions lib/LedgerSMB/Scripts/reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,21 @@ Generates a balance sheet
=cut

use Log::Any;
my $logger = Log::Any->get_logger(category => 'LedgerSMB::Scripts::reports');

sub generate_balance_sheet {
my ($request) = @_;
$logger->debug("Stub LedgerSMB::Scripts::reports->generate_balance_sheet\n");
my $rpt = LedgerSMB::Report::Balance_Sheet->new(
%$request,
formatter_options => $request->formatter_options,
from_date => $request->parse_date( $request->{from_date} ),
to_date => $request->parse_date( $request->{to_date} ),
from_date => $request->{from_date} ? $request->parse_date( $request->{from_date} ) : undef,
to_date => $request->{to_date} ? $request->parse_date( $request->{to_date} ) : undef,
column_path_prefix => [ 0 ]);
$rpt->run_report($request);

for my $key (qw(from_month from_year from_date to_date internal)) {
delete $request->{$_} for (grep { /^$key/ } keys %$request);
}

for my $cmp_dates (@{$rpt->comparisons}) {
my $cmp = LedgerSMB::Report::Balance_Sheet->new(
%$request, %$cmp_dates);
%$request,
formatter_options => $request->formatter_options,
%$cmp_dates);
$cmp->run_report($request);
$rpt->add_comparison($cmp);
}
Expand Down

0 comments on commit 163643c

Please sign in to comment.