|
Lines 274-280
See CanItemBeReserved() for possible return values.
Link Here
|
| 274 |
sub CanBookBeReserved{ |
274 |
sub CanBookBeReserved{ |
| 275 |
my ($borrowernumber, $biblionumber, $pickup_branchcode) = @_; |
275 |
my ($borrowernumber, $biblionumber, $pickup_branchcode) = @_; |
| 276 |
|
276 |
|
|
|
277 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 278 |
my $holds = $patron->holds; |
| 279 |
|
| 280 |
# Check if borrower has reached the maximum number of holds allowed |
| 281 |
my $maxreserves = C4::Context->preference('maxreserves'); |
| 282 |
if ($maxreserves && $holds->count >= $maxreserves) { |
| 283 |
return { status => 'tooManyReserves' }; |
| 284 |
} |
| 285 |
|
| 277 |
my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); |
286 |
my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); |
|
|
287 |
|
| 278 |
#get items linked via host records |
288 |
#get items linked via host records |
| 279 |
my @hostitems = get_hostitemnumbers_of($biblionumber); |
289 |
my @hostitems = get_hostitemnumbers_of($biblionumber); |
| 280 |
if (@hostitems){ |
290 |
if (@hostitems){ |
|
Lines 286-292
sub CanBookBeReserved{
Link Here
|
| 286 |
$canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode ); |
296 |
$canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode ); |
| 287 |
return { status => 'OK' } if $canReserve->{status} eq 'OK'; |
297 |
return { status => 'OK' } if $canReserve->{status} eq 'OK'; |
| 288 |
} |
298 |
} |
| 289 |
return $canReserve; |
299 |
|
|
|
300 |
return { status => 'none_available' }; |
| 290 |
} |
301 |
} |
| 291 |
|
302 |
|
| 292 |
=head2 CanItemBeReserved |
303 |
=head2 CanItemBeReserved |
|
Lines 303-308
sub CanBookBeReserved{
Link Here
|
| 303 |
{ status => libraryNotFound }, if given branchcode is not an existing library |
314 |
{ status => libraryNotFound }, if given branchcode is not an existing library |
| 304 |
{ status => libraryNotPickupLocation }, if given branchcode is not configured to be a pickup location |
315 |
{ status => libraryNotPickupLocation }, if given branchcode is not configured to be a pickup location |
| 305 |
{ status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode |
316 |
{ status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode |
|
|
317 |
{ status => alreadyReserved }, if the borrower has already reserved this item. |
| 306 |
|
318 |
|
| 307 |
=cut |
319 |
=cut |
| 308 |
|
320 |
|
|
Lines 336-341
sub CanItemBeReserved {
Link Here
|
| 336 |
return { status =>'itemAlreadyOnHold' } |
348 |
return { status =>'itemAlreadyOnHold' } |
| 337 |
if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); |
349 |
if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); |
| 338 |
|
350 |
|
|
|
351 |
# Check if borrower already has reserved the same item. |
| 352 |
my $holds = $patron->holds; |
| 353 |
while (my $hold = $holds->next) { |
| 354 |
if ( $hold->itemnumber == $itemnumber ) { |
| 355 |
return { status => 'alreadyReserved' }; |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
# Check if borrower has reached the maximum number of holds allowed |
| 360 |
my $maxreserves = C4::Context->preference('maxreserves'); |
| 361 |
if ($maxreserves && $holds->count >= $maxreserves) { |
| 362 |
return { status => 'tooManyReserves', limit => $maxreserves }; |
| 363 |
} |
| 364 |
|
| 339 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
365 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 340 |
|
366 |
|
| 341 |
my $querycount = q{ |
367 |
my $querycount = q{ |
|
Lines 370-376
sub CanItemBeReserved {
Link Here
|
| 370 |
$ruleitemtype = '*'; |
396 |
$ruleitemtype = '*'; |
| 371 |
} |
397 |
} |
| 372 |
|
398 |
|
| 373 |
my $holds = Koha::Holds->search( |
399 |
$holds = Koha::Holds->search( |
| 374 |
{ |
400 |
{ |
| 375 |
borrowernumber => $borrowernumber, |
401 |
borrowernumber => $borrowernumber, |
| 376 |
biblionumber => $item->biblionumber, |
402 |
biblionumber => $item->biblionumber, |