From 2d2e3f24176d4580e7c17434e7fb03d05e0dcbb8 Mon Sep 17 00:00:00 2001 From: Nicolas Vigier Date: Thu, 16 May 2013 20:26:38 +0000 Subject: mktreasurer: add start_balance and end_balance git-svn-id: svn+ssh://svn.mageia.org/svn/soft/mga-treasurer/trunk@8278 5b7c3c08-40e5-403b-9995-ace06908e4af --- mktreasurer | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'mktreasurer') diff --git a/mktreasurer b/mktreasurer index fa41ae0..25b4999 100755 --- a/mktreasurer +++ b/mktreasurer @@ -125,10 +125,23 @@ sub transactions_infos { push @{$res{by_account}->{$tra->{ac}}->{transactions}}, $tra; $res{balance} += new Math::BigFloat $tra->{amount}; } - foreach my $t (values %{$res{by_account}}) { - $t->{balance} = new Math::BigFloat 0; - foreach my $tra (@{$t->{transactions}}) { - $t->{balance} += new Math::BigFloat $tra->{amount}; + foreach my $by ('by_account', 'by_year', 'by_month') { + foreach my $t (values %{$res{$by}}) { + $t->{balance} = new Math::BigFloat 0; + foreach my $tra (@{$t->{transactions}}) { + $t->{balance} += new Math::BigFloat $tra->{amount}; + } + } + } + foreach my $by ('by_year', 'by_month') { + my ($prev, $start_balance); + foreach my $b (sort keys %{$res{$by}}) { + my $y = $res{$by}->{$b}; + $y->{start_balance} = $start_balance ? $start_balance : new Math::BigFloat 0; + $y->{end_balance} = $y->{balance} + new Math::BigFloat $y->{start_balance}; + $start_balance = $y->{end_balance}; + $y->{prev} = $prev if $prev; + $prev = $b; } } return \%res; -- cgit v1.2.1