Bug 25812: Fines can be displayed on SIP checkin/checkout
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Wed, 25 Sep 2019 13:30:51 +0000 (15:30 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 31 Jan 2023 13:21:52 +0000 (10:21 -0300)
Test plan:

 - Enable show_outstanding_amount in SIPconfig.xml

 - Check that the total outstanding amout for the patron is displayed on SIP
   checkout (if it exists), for example:
   Patron has fines - You owe $10.00.

 - Check that the outstanding amout for a given item is displayed on SIP
   checkin (if it exists), for example:
   "You owe $10.00 for this item."

 - Check that it is not displayed when show_outstanding_amount is disabled.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/SIP/ILS.pm
etc/SIPconfig.xml
t/db_dependent/SIP/Transaction.t

index bebeaf6..f33aaee 100644 (file)
@@ -140,7 +140,15 @@ sub checkout {
         } elsif ($patron->expired) {
             $circ->screen_msg("Patron expired on " . output_pref({ dt => dt_from_string( $patron->dateexpiry_iso, 'iso' ), dateonly => 1 }));
         } elsif ($patron->fine_blocked) {
-            $circ->screen_msg("Patron has fines");
+            my $message = "Patron has fines";
+            if ($account->{show_outstanding_amount}) {
+                my $patron_account = Koha::Account->new( { patron_id => $patron->{borrowernumber} });
+                my $balance = $patron_account->balance;
+                if ($balance) {
+                    $message .= (" - You owe " . Koha::Number::Price->new( $balance )->format({ with_symbol => 1}) . ".");
+                }
+            }
+            $circ->screen_msg($message);
         } else {
             $circ->screen_msg("Patron blocked");
         }
@@ -247,6 +255,23 @@ sub checkin {
         delete $item->{borrowernumber};
         delete $item->{due_date};
         $patron->{items} = [ grep { $_ ne $item_id } @{ $patron->{items} } ];
+        # Check for overdue fines to display
+        if ($account->{show_outstanding_amount}) {
+            my $kohaitem = Koha::Items->find( { barcode => $item_id } );
+            if ($kohaitem) {
+                my $charges = Koha::Account::Lines->search(
+                    {
+                        borrowernumber    => $patron->{borrowernumber},
+                        amountoutstanding => { '>' => 0 },
+                        debit_type_code   => [ 'OVERDUE' ],
+                        itemnumber        => $kohaitem->itemnumber
+                    },
+                );
+                if ($charges) {
+                    $circ->screen_msg("You owe " . Koha::Number::Price->new( $charges->total_outstanding )->format({ with_symbol => 1}) . " for this item.");
+                }
+            }
+        }
     } else {
         # Checkin failed: Wrongbranch or withdrawn?
         # Bug 10748 with pref BlockReturnOfLostItems adds another case to come
index 8e0dcbe..58d9b10 100644 (file)
@@ -74,6 +74,7 @@
              holds_get_captured="1"
              prevcheckout_block_checkout="0"
              overdues_block_checkout="1"
+             show_outstanding_amount="1"
              format_due_date="0"
              inhouse_item_types=""
              inhouse_patron_categories="">
index ffabc83..dc9a631 100755 (executable)
@@ -334,8 +334,10 @@ subtest "Placing holds via SIP check CanItemBeReserved" => sub {
 };
 
 subtest do_checkin => sub {
-    plan tests => 12;
+    plan tests => 13;
 
+    my $mockILS = Test::MockObject->new;
+    my $server = { ils => $mockILS };
     my $library = $builder->build_object( { class => 'Koha::Libraries' } );
     my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
     my $patron = $builder->build_object(
@@ -437,11 +439,92 @@ subtest do_checkin => sub {
         is( $hold->itemnumber, $item->itemnumber, );
         is( Koha::Checkouts->search({itemnumber => $item->itemnumber})->count, 0, );
     };
+
+    subtest 'Checkin with fines' => sub {
+        plan tests => 2;
+
+        my $mockILS = Test::MockObject->new;
+        my $server = { ils => $mockILS };
+        my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+        my $institution = {
+            id             => $library->id,
+            implementation => "ILS",
+            policy         => {
+                checkin  => "true",
+                renewal  => "true",
+                checkout => "true",
+                timeout  => 100,
+                retries  => 5,
+            }
+        };
+        my $ils = C4::SIP::ILS->new($institution);
+        my $item = $builder->build_sample_item(
+            {
+                library => $library->branchcode,
+            }
+        );
+
+        # show_outstanding_amount disabled
+        my $patron = $builder->build_object(
+            {
+                class => 'Koha::Patrons',
+                value => {
+                    branchcode => $library->branchcode,
+                }
+            }
+        );
+        my $circ = $ils->checkout($patron->cardnumber, $item->barcode, undef, undef, $server->{account});
+        my $fee1 = $builder->build(
+            {
+                source => 'Accountline',
+                value  => {
+                    borrowernumber => $patron->borrowernumber,
+                    amountoutstanding => 12,
+                    debit_type_code   => 'OVERDUE',
+                    itemnumber        => $item->itemnumber
+                }
+            }
+        );
+        $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode, undef, undef, $server->{account} );
+        is( $circ->{screen_msg}, '', "The fine is not displayed on checkin when show_outstanding_amount is disabled" );
+
+        # show_outstanding_amount enabled
+        $patron = $builder->build_object(
+            {
+                class => 'Koha::Patrons',
+                value => {
+                    branchcode => $library->branchcode,
+                }
+            }
+        );
+        $circ = $ils->checkout($patron->cardnumber, $item->barcode, undef, undef, $server->{account});
+
+        $fee1 = $builder->build(
+            {
+                source => 'Accountline',
+                value  => {
+                    borrowernumber => $patron->borrowernumber,
+                    amountoutstanding => 12,
+                    debit_type_code   => 'OVERDUE',
+                    itemnumber        => $item->itemnumber
+                }
+            }
+        );
+
+        $server->{account}->{show_outstanding_amount} = 1;
+        $circ = $ils->checkout($patron->cardnumber, $item->barcode, undef, undef, $server->{account});
+
+        $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode, undef, undef, $server->{account} );
+        is( $circ->{screen_msg}, 'You owe $12.00 for this item.', "The fine is displayed on checkin when show_outstanding_amount is enabled" );
+
+    };
 };
 
 subtest do_checkout_with_patron_blocked => sub {
-    plan tests => 4;
+    plan tests => 5;
 
+    my $mockILS = Test::MockObject->new;
+    my $server = { ils => $mockILS };
     my $library = $builder->build_object( { class => 'Koha::Libraries' } );
     my $institution = {
         id             => $library->id,
@@ -492,9 +575,13 @@ subtest do_checkout_with_patron_blocked => sub {
     );
 
     my $fines_sip_patron  = C4::SIP::ILS::Patron->new( $fines_patron->cardnumber );
-    $circ = $ils->checkout($fines_patron->cardnumber, $item->barcode);
+
+    $circ = $ils->checkout($fines_patron->cardnumber, $item->barcode, undef, undef, $server->{account});
     is( $circ->{screen_msg}, 'Patron has fines', "Got correct fines screen message" );
 
+    $server->{account}->{show_outstanding_amount} = 1;
+    $circ = $ils->checkout($fines_patron->cardnumber, $item->barcode, undef, undef, $server->{account});
+    is( $circ->{screen_msg}, 'Patron has fines - You owe $10.00.', "Got correct fines with amount screen message" );
     my $debarred_patron = $builder->build_object(
         {
             class => 'Koha::Patrons',