This patch adds the normalize_balance() method to Koha::Account. Its
purpose is to apply outstanding credits (i.e. manual ones ore remaining
amounts like in the case of refunds) to outstanding debts.
To test:
- Apply this patchset
- Run:
$ kshell
k$ prove t/db_dependent/Koha/Account.t
=> SUCCESS: Tests pass!
- Sign off :-D
Signed-off-by: Christopher Brannon <cbrannon@cdalibrary.org>
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit
1176947b42342ca725020455361fe092255e4d04)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
);
}
+=head3 normalize_balance
+
+$account->normalize_balance();
+
+Find outstanding credits and use them to pay outstanding debits
+
+=cut
+
+sub normalize_balance {
+ my ($self) = @_;
+
+ my $outstanding_debits = $self->outstanding_debits;
+ my $outstanding_credits = $self->outstanding_credits;
+
+ while ( $outstanding_debits->total_outstanding > 0
+ and my $credit = $outstanding_credits->next )
+ {
+ # there's both outstanding debits and credits
+ $credit->apply( { debits => $outstanding_debits } ); # applying credit, no special offset
+
+ $outstanding_debits = $self->outstanding_debits;
+
+ }
+
+ return $self;
+}
+
1;
=head2 Name mappings