From 60e6844bf0357d67ac56888578c48de3249572e6 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 25 Sep 2019 15:30:51 +0200 Subject: [PATCH] Bug 25812: Fines can be displayed on SIP checkin/checkout 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 Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/SIP/ILS.pm | 27 +++++++++- etc/SIPconfig.xml | 1 + t/db_dependent/SIP/Transaction.t | 93 ++++++++++++++++++++++++++++++-- 3 files changed, 117 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index bebeaf6b6d..f33aaee5c4 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -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 diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index 8e0dcbef85..58d9b1054a 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -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=""> diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index ffabc838c1..dc9a631ff6 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -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', -- 2.39.5