Bug 20946: Use K::Account->outstanding_debits in pay.pl and paycollect.pl
authorTomas Cohen Arazi <tomascohen@theke.io>
Sat, 16 Jun 2018 12:44:19 +0000 (09:44 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 10:33:13 +0000 (10:33 +0000)
This patch changes the how account lines are fetched (using
Koha::Account->outstanding_debits) so credits are not picked.

To test:
- Add a $5 credit to a patron
- Add a $1 fine
- Go to the 'Pay fines' tab
=> FAIL: Credit is displayed
- Try to pay all fines
=> FAIL: You are told to enter a value less than or equal to -4.00
         (Observe you cannot do that)
- Apply this patch
- Reload
=> SUCCESS: Credit is not displayed
=> SUCCESS: You are able to pay all fines
- Sign off :-D

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

members/pay.pl
members/paycollect.pl

index 53a8f37..8245f38 100755 (executable)
@@ -139,8 +139,7 @@ output_html_with_http_headers $input, $cookie, $template->output;
 sub add_accounts_to_template {
 
     my $patron = Koha::Patrons->find( $borrowernumber );
-    my $total = $patron->account->balance;
-    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber, amountoutstanding => { '!=' => 0 } }, { order_by => ['accounttype'] });
+    my ( $total, $account_lines ) = Koha::Account->new( { patron_id => $borrowernumber } )->outstanding_debits;
     my @accounts;
     while ( my $account_line = $account_lines->next ) {
         $account_line = $account_line->unblessed;
index 0f98a9d..1676177 100755 (executable)
@@ -59,8 +59,7 @@ my $category       = $patron->category;
 my $user           = $input->remote_user;
 
 my $branch         = C4::Context->userenv->{'branch'};
-
-my $total_due = $patron->account->balance;
+my ( $total_due ) = Koha::Account->new( { patron_id => $borrowernumber } )->outstanding_debits;
 my $total_paid = $input->param('paid');
 
 my $individual   = $input->param('pay_individual');