#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
=head1 request.pl
use strict;
use warnings;
use C4::Branch;
-use CGI;
+use CGI qw ( -utf8 );
use List::MoreUtils qw/uniq/;
use Date::Calc qw/Date_to_Days/;
use C4::Output;
use C4::Koha;
use C4::Circulation;
use C4::Dates qw/format_date/;
+use C4::Utils::DataTables::Members;
use C4::Members;
use C4::Search; # enabled_staff_search_views
use Koha::DateUtils;
my $borrowernumber_hold = $input->param('borrowernumber') || '';
my $messageborrower;
my $maxreserves;
+my $warnings;
+my $messages;
my $date = C4::Dates->today('iso');
my $action = $input->param('action');
}
if ($findborrower) {
- my $borrowers = Search($findborrower, 'cardnumber');
-
- if ($borrowers && @$borrowers) {
- if ( @$borrowers == 1 ) {
- $borrowernumber_hold = $borrowers->[0]->{'borrowernumber'};
- }
- else {
- $template->param( borrower_list => sort_borrowerlist($borrowers));
- }
+ my $borrower = C4::Members::GetMember( cardnumber => $findborrower );
+ if ( $borrower ) {
+ $borrowernumber_hold = $borrower->{borrowernumber};
} else {
- $messageborrower = "'$findborrower'";
+ my $dt_params = { iDisplayLength => -1 };
+ my $results = C4::Utils::DataTables::Members::search(
+ {
+ searchmember => $findborrower,
+ dt_params => $dt_params,
+ }
+ );
+ my $borrowers = $results->{patrons};
+ if ( scalar @$borrowers == 1 ) {
+ $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
+ } elsif ( @$borrowers ) {
+ $template->param( borrowers => $borrowers );
+ } else {
+ $messageborrower = "'$findborrower'";
+ }
}
}
my @getreservloop;
my $count_reserv = 0;
-# we check the reserves of the borrower, and if he can reserv a document
-# FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
+ # we check the reserves of the borrower, and if he can reserv a document
+ # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
my $number_reserves =
GetReserveCount( $borrowerinfo->{'borrowernumber'} );
if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
+ $warnings = 1;
$maxreserves = 1;
}
my $expiry_date = $borrowerinfo->{dateexpiry};
my $expiry = 0; # flag set if patron account has expired
if ($expiry_date and $expiry_date ne '0000-00-00' and
- Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
+ Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
$expiry = 1;
}
cardnumber => $borrowerinfo->{'cardnumber'},
expiry => $expiry,
diffbranch => $diffbranch,
+ messages => $messages,
+ warnings => $warnings
);
}
my $dat = GetBiblioData($biblionumber);
- unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
+ my $canReserve = CanBookBeReserved( $borrowerinfo->{borrowernumber}, $biblionumber );
+ $canReserve //= '';
+ if ( $canReserve eq 'OK' ) {
+
+ #All is OK and we can continue
+ }
+ elsif ( $canReserve eq 'tooManyReserves' ) {
$maxreserves = 1;
}
+ elsif ( $canReserve eq 'ageRestricted' ) {
+ $template->param( $canReserve => 1 );
+ $biblioloopiter{$canReserve} = 1;
+ }
+ else {
+ $biblioloopiter{$canReserve} = 1;
+ }
my $alreadypossession;
if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
my $alreadyreserved = 0;
foreach my $res (@$reserves) {
- if ( defined $res->{found} && $res->{found} eq 'W' ) {
+ if ( defined $res->{found} ) { # found can be 'W' or 'T'
$count--;
}
$item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
}
- # add information
- $item->{itemcallnumber} = $item->{itemcallnumber};
-
# if the item is currently on loan, we display its return date and
# change the background color
my $issues= GetItemIssue($itemnumber);
if ( $issues->{'date_due'} ) {
- $item->{date_due} = format_sqldatetime($issues->{date_due});
+ $item->{date_due} = $issues->{date_due_sql};
$item->{backgroundcolor} = 'onloan';
}
# checking reserve
my ($reservedate,$reservedfor,$expectedAt,$reserve_id,$wait) = GetReservesFromItemnumber($itemnumber);
- my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
-
if ( defined $reservedate ) {
+ my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
+
$item->{backgroundcolor} = 'reserved';
$item->{reservedate} = format_date($reservedate);
$item->{ReservedForBorrowernumber} = $reservedfor;
}
# If there is no loan, return and transfer, we show a checkbox.
- $item->{notforloan} = $item->{notforloan} || 0;
+ $item->{notforloan} ||= 0;
# if independent branches is on we need to check if the person can reserve
# for branches they arent logged in to
my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
- my $policy_holdallowed = 1;
$item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
- if ( $branchitemrule->{'holdallowed'} == 0 ||
- ( $branchitemrule->{'holdallowed'} == 1 &&
- $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
- $policy_holdallowed = 0;
- }
-
if (
- $policy_holdallowed
- && !$item->{cantreserve}
- && IsAvailableForItemLevelRequest($itemnumber)
+ !$item->{cantreserve}
+ && IsAvailableForItemLevelRequest($item, $borrowerinfo)
&& CanItemBeReserved(
$borrowerinfo->{borrowernumber}, $itemnumber
- )
+ ) eq 'OK'
)
{
$item->{available} = 1;
$num_available++;
}
elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
-
-# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
+ # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
$item->{override} = 1;
$num_override++;
}
$reserve{'notes'} = $res->{'reservenotes'};
$reserve{'wait'} =
( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) );
- $reserve{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' );
- $reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' );
$reserve{'voldesc'} = $res->{'volumeddesc'};
$reserve{'ccode'} = $res->{'ccode'};
$reserve{'barcode'} = $res->{'barcode'};