[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[5224] trunk/LedgerSMB/Report/PNL/Income_Statement. pm
- Subject: SF.net SVN: ledger-smb:[5224] trunk/LedgerSMB/Report/PNL/Income_Statement. pm
- From: ..hidden..
- Date: Wed, 21 Nov 2012 08:47:47 +0000
Revision: 5224
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5224&view=rev
Author: einhverfr
Date: 2012-11-21 08:47:46 +0000 (Wed, 21 Nov 2012)
Log Message:
-----------
More Perl PNL fixes, adding comparison logic
Modified Paths:
--------------
trunk/LedgerSMB/Report/PNL/Income_Statement.pm
Modified: trunk/LedgerSMB/Report/PNL/Income_Statement.pm
===================================================================
--- trunk/LedgerSMB/Report/PNL/Income_Statement.pm 2012-11-21 08:14:38 UTC (rev 5223)
+++ trunk/LedgerSMB/Report/PNL/Income_Statement.pm 2012-11-21 08:47:46 UTC (rev 5224)
@@ -37,6 +37,8 @@
has 'account_data' => (is => 'rw', isa => 'HashRef[Any]');
+has 'comparisons' => (is => 'rw', isa => 'ArrayRef[Any]');
+
=back
=head1 CONSTANT REPORT-RELATED FUNCTIONS
@@ -89,41 +91,73 @@
return $self->exec_method({funcname => $procname});
}
-=over
+# private method
+# _merge_rows(arrayref $rows, string $label, report $report)
-=item run_report
+sub _merge_rows {
+ my $self = shift @_;
+ my $label = shift @_;
+ my @rows = @_;
-=cut
-
-sub run_report {
- my ($self) = @_;
- my @rows = $self->report_base($self->from_date, $self->to_date);
- $self->rows(..hidden..);
my $data = $self->account_data;
$data ||= $data = {'I' => {}, 'E' => {}};
for my $r (@rows){
$data->{$r->{account_category}}->{$r->{account_number}} = {'main' => $r};
+ $data->{$r->{account_category}}->{$r->{account_number}}->{info} = $r;
}
my $i_total = 0;
my $e_total = 0;
my $total;
for my $k (keys %{$data->{I}}){
- $i_total += $data->{I}->{$k}->{main}->{amount};
+ $i_total += $data->{I}->{$k}->{$label}->{amount};
}
for my $k (keys %{$data->{E}}){
- $e_total += $data->{E}->{$k}->{main}->{amount};
+ $e_total += $data->{E}->{$k}->{$label}->{amount};
}
- $data->{totals}->{main}->{I} = $i_total;
- $data->{totals}->{main}->{E} = $e_total;
- $data->{totals}->{main}->{total} = $i_total - $e_total;
+ $data->{totals}->{$label}->{I} = $i_total;
+ $data->{totals}->{$label}->{E} = $e_total;
+ $data->{totals}->{$label}->{total} = $i_total - $e_total;
$self->account_data($data);
+}
+
+=over
+
+=item run_report
+
+=cut
+
+sub run_report {
+ my ($self) = @_;
+ my @rows = $self->report_base($self->from_date, $self->to_date);
+ $self->rows(..hidden..);
+ $self->_merge_rows('main', @rows);
return @rows;
}
=item add_comparison($from, $to)
-TODO
+Adds a comparison.
+=cut
+
+sub add_comparison {
+ my ($self, $label, $from, $to) = @_;
+ my %attributes = %{ $self->meta->get_attribute_map };
+ my %new_data;
+ while (my ($name, $attribute) = each %attributes) {
+ my $reader = $attribute->get_read_method;
+ $new_data{$name} = $self->$reader;
+ }
+ $new_data{from_date} = $from;
+ $new_data{to_date} = $to;
+ my $new_report = $self->new(%new_data);
+ my @rows = $new_report->run_report;
+ my $comparisons = $self->comparisons;
+ $comparisons ||= [];
+ push $comparisons, {label => $label, from_date => $from, to_date => $to};
+ $self->_merge_rows($label, @rows);
+}
+
=head1 SEE ALSO
=over
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.