From 097c069d803955b6c0591bfba064ae126aced040 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 15 Apr 2025 10:06:33 +0300 Subject: [PATCH 1/2] 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 | 125 ++++++++++++------ opac/sco/sco-main.pl | 80 ++++++++--- 2 files changed, 146 insertions(+), 59 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 52530b7e18..4c1655f1d9 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 @@ -303,60 +303,94 @@ [% END %] -
-
- [% INCLUDE 'csrf-token.inc' %] -
- Log in to your account -
-
- [% IF ( Koha.Preference('SelfCheckoutByLogin') ) %] -
-
[% PROCESS login_label for="patronlogin" %]
-
- -
-
- -
-
- +
+
+

Check out

+ + [% INCLUDE 'csrf-token.inc' %] +
+ Log in to your account +
+ [% IF ( Koha.Preference('SelfCheckoutByLogin') ) %] +
+
[% PROCESS login_label for="patronlogin" %]
+
+ +
+
+ +
+
+ +
+
+ +
-
- + + [% ELSE %] +
+
+ +
+
+ +
+
+ +
-
- - [% ELSE %] + + [% END %] +
+ + [% FOREACH INPUT IN INPUTS %] + + [% END %] + +
+ + +
+ +
+

Check in

+
+ [% INCLUDE 'csrf-token.inc' %] +
+
- +
- + [% IF ( returned == 1 || returned == 0 || empty_return ) %] + + [% ELSE %] + + [% END %]
- [% END %] -
- -
- - [% FOREACH INPUT IN INPUTS %] - - [% END %] - -
- - + [% FOREACH INPUT IN INPUTS %] + + [% END %] + +
+ + + + + + + [% IF ( SCOMainUserBlock ) %] +
[% PROCESS koha_news_block news => SCOMainUserBlock %]
+ [% END %] - - [% IF ( SCOMainUserBlock ) %] -
[% PROCESS koha_news_block news => SCOMainUserBlock %]
- [% END %] + @@ -453,7 +487,7 @@ $(document).ready(function() { dofocus(); - [% IF ( patronid ) %]sco_init();[% END %] + [% IF ( patronid || barcode ) %]sco_init();[% END %] var dTables = $("#loanTable, #holdst, #finestable"); dTables.each(function(){ @@ -711,7 +745,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..b94299ade1 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; @@ -88,14 +89,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 +110,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 +158,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 +183,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 +191,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