From dbf8609c259bae4a15d7d2d31070e2d398ef509d Mon Sep 17 00:00:00 2001 From: Johanna Raisa Date: Wed, 10 Jul 2019 13:42:25 +0300 Subject: [PATCH] Bug 22322: Self check-in without log in One should be able to return loans via SCO without login required. This patch adds check in box where patrons can check in their loans with barcode. To test: 1. Find patron with loan or add one. 2. Go to /cgi-bin/koha/sco/sco-main.pl. 3. Return loan by passing items barcode. => Confirm loans is returned succesfully. 4. Attempt to return item again. => Confirm that "Item not checked in:..." message is displayed. 5. Attempt to return empty barcode field. => Confirm that "Please enter barcode." message is displayed. Sponsored-by: Koha-Suomi Oy --- .../bootstrap/en/modules/sco/sco-main.tt | 76 ++++++++++++---- opac/sco/sco-main.pl | 89 ++++++++++++++----- 2 files changed, 126 insertions(+), 39 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt index 15f863e122..2f8a657c39 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt @@ -302,7 +302,8 @@ [% END %] -
+
+

Check out

[% INCLUDE 'csrf-token.inc' %]
@@ -310,22 +311,22 @@
[% IF ( Koha.Preference('SelfCheckoutByLogin') ) %] -
-
[% PROCESS login_label for="patronlogin" %]
-
- -
-
- -
-
- -
-
- -
+
+
[% PROCESS login_label for="patronlogin" %]
+
+
- +
+ +
+
+ +
+
+ +
+
+ [% ELSE %]
@@ -352,7 +353,39 @@
- + +
+
+ [% INCLUDE 'csrf-token.inc' %] +
+
+
+

Check in

+
+
+
+
+ +
+
+ [% IF ( returned == 1 || returned == 0 || empty_return ) %] + + [% ELSE %] + + [% END %] +
+
+ +
+
+ [% FOREACH INPUT IN INPUTS %] + + [% END %] + +
+
+
+ [% IF ( SCOMainUserBlock ) %]
[% PROCESS koha_news_block news => SCOMainUserBlock %]
[% END %] @@ -452,7 +485,7 @@ $(document).ready(function() { dofocus(); - [% IF ( patronid ) %]sco_init();[% END %] + [% IF ( patronid || barcode ) %]sco_init();[% END %] var dTables = $("#loanTable, #holdst, #finestable"); dTables.each(function(){ @@ -710,7 +743,12 @@ [% ELSIF ( returned == 1 ) %]
-

Item checked in ([% barcode | html %])

+

Item checked in: [% title | html %] ([% barcode | html %])[% IF library %], [% library | html %][% END %]

+
+ [% ELSIF ( empty_return == 1 ) %] + +
+

Please enter barcode.

[% END %] [% END %] diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index 9ecae7c76c..91fb989831 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -34,9 +34,10 @@ use CGI qw ( -utf8 ); use C4::Auth qw( in_iprange get_template_and_user checkpw ); use C4::Circulation qw( barcodedecode AddReturn CanBookBeIssued AddIssue CanBookBeRenewed AddRenewal ); -use C4::Reserves; +use C4::Reserves qw ( ModReserveAffect ); use C4::Output qw( output_html_with_http_headers ); use C4::Members; +use C4::Items qw( ModItemTransfer ); use Koha::DateUtils qw( dt_from_string ); use Koha::Acquisition::Currencies; use Koha::Items; @@ -67,10 +68,11 @@ $query->param( -name => 'sco_user_login', -values => [1] ); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "sco/sco-main.tt", - flagsrequired => { self_check => "self_checkout_module" }, - query => $query, - type => "opac", + template_name => "sco/sco-main.tt", + authnotrequired => 0, + flagsrequired => { self_check => "self_checkout_module" }, + query => $query, + type => "opac", } ); @@ -88,14 +90,15 @@ if ( defined C4::Context->preference('SCOAllowCheckin') ) { } my $issuerid = $loggedinuser; -my ( $op, $patronlogin, $patronpw, $barcodestr, $confirmed, $newissues, $load_checkouts ) = ( - $query->param("op") || '', - $query->param("patronlogin") || '', - $query->param("patronpw") || '', - $query->param("barcode") || '', - $query->param("confirmed") || '', - $query->param("newissues") || '', - $query->param("load_checkouts") || '', +my ( $op, $patronlogin, $patronpw, $barcodestr, $confirmed, $newissues, $load_checkouts, $sco_entry_barcode ) = ( + $query->param("op") || '', + $query->param("patronlogin") || '', + $query->param("patronpw") || '', + $query->param("barcode") || '', + $query->param("confirmed") || '', + $query->param("newissues") || '', + $query->param("load_checkouts") || '', + $query->param("sco_entry_barcode") || '', ); my $jwt = $query->cookie('JWT'); @@ -108,8 +111,8 @@ if ( $op eq "logout" ) { } my $barcodes = []; -if ($barcodestr) { - push @$barcodes, split( /\s\n/, $barcodestr ); +if ( $barcodestr || $sco_entry_barcode ) { + push @$barcodes, split( /\s\n/, $barcodestr ? $barcodestr : $sco_entry_barcode ); $barcodes = [ map { $_ =~ /^\s*$/ ? () : barcodedecode($_) } @$barcodes ]; } @@ -156,11 +159,23 @@ if ($patron) { } } -if ( $patron && $op eq "cud-returnbook" && $allowselfcheckreturns ) { +if ( ( $op eq "cud-sco_entry_checkin" ) || ( $patron && $op eq "cud-returnbook" && $allowselfcheckreturns ) ) { my $success = 1; + if ( !@$barcodes ) { + $template->param( empty_return => 1 ); + } + foreach my $barcode (@$barcodes) { my $item = Koha::Items->find( { barcode => $barcode } ); + + my $title = $item ? Koha::Biblios->find( { biblionumber => $item->biblionumber } )->title : undef; + my $checkinlibrary = $issuer && $branch ? Koha::Libraries->find($branch)->branchname : undef; + + if ( !$item ) { + $success = 0; + } + if ( $success && C4::Context->preference("CircConfirmItemParts") ) { if ( defined($item) && $item->materials ) @@ -169,7 +184,7 @@ if ( $patron && $op eq "cud-returnbook" && $allowselfcheckreturns ) { } } - if ($success) { + if ( $success && ( $op ne "cud-sco_entry_checkin" ) ) { # Patron cannot checkin an item they don't own $success = 0 @@ -177,12 +192,46 @@ if ( $patron && $op eq "cud-returnbook" && $allowselfcheckreturns ) { } if ($success) { - ($success) = AddReturn( $barcode, $branch ); + + my $to_branch = $item->homebranch; + my $messages; + + ( $success, $messages ) = AddReturn( $barcode, $branch ); + + if ( $messages->{'ResFound'} ) { + my $reserve = $messages->{'ResFound'}; + my $reserve_id = $reserve->{'reserve_id'}; + my $resborrower = $reserve->{'borrowernumber'}; + my $resbranch = $reserve->{'branchcode'}; + my $itemnumber = $item->itemnumber; + my $diff_branch_send = ( $branch ne $resbranch ) ? $resbranch : undef; + + if ($diff_branch_send) { + ModReserveAffect( $itemnumber, $resborrower, $diff_branch_send, $reserve_id ); + ModItemTransfer( $itemnumber, $branch, $resbranch, 'ResFound' ); + } else { + my $set_transit = C4::Context->preference('RequireSCCheckInBeforeNotifyingPickups'); + ModReserveAffect( $itemnumber, $resborrower, $set_transit, $reserve_id ); + } + } elsif ( $messages->{'NeedsTransfer'} ) { + ModItemTransfer( $item->itemnumber, $branch, $to_branch, 'NeedsTransfer' ); + } + + if ( $messages->{'WrongTransfer'} ) { + my $item = Koha::Items->find( $messages->{'WrongTransferItem'} ); + my $old_transfer = $item->get_transfer; + my $new_transfer = $item->request_transfer( + { to => $old_transfer->tobranch, reason => $old_transfer->reason, replace => 'WrongTransfer' } ); + } + } $template->param( - returned => $success, - barcode => $barcode + SelfCheckTimeout => 10000, #don't show returns long + returned => $success, + barcode => $barcode, + title => $title, + library => $checkinlibrary ); } # foreach barcode in barcodes -- 2.34.1