Lines 70-76
use Koha::Patron::Quota;
Link Here
|
70 |
use Koha::Patron::Quota::Usage; |
70 |
use Koha::Patron::Quota::Usage; |
71 |
use Koha::Patron::Quota::Usages; |
71 |
use Koha::Patron::Quota::Usages; |
72 |
|
72 |
|
73 |
use Carp qw( carp ); |
73 |
use Carp qw( carp ); |
74 |
use List::MoreUtils qw( any ); |
74 |
use List::MoreUtils qw( any ); |
75 |
use Scalar::Util qw( looks_like_number blessed ); |
75 |
use Scalar::Util qw( looks_like_number blessed ); |
76 |
use Date::Calc qw( Date_to_Days ); |
76 |
use Date::Calc qw( Date_to_Days ); |
Lines 1371-1396
sub CanBookBeIssued {
Link Here
|
1371 |
} |
1371 |
} |
1372 |
|
1372 |
|
1373 |
# CHECK FOR QUOTAS |
1373 |
# CHECK FOR QUOTAS |
1374 |
if ( my $quotas = $patron->all_quotas->filter_by_active ) { |
1374 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
1375 |
if ( $quotas->count > 1 ) { |
1375 |
if ( my $quotas = $patron->all_quotas->filter_by_active ) { |
1376 |
|
1376 |
if ( $quotas->count > 1 ) { |
1377 |
# Multiple available quotas found - need confirmation from user |
1377 |
|
1378 |
$needsconfirmation{QUOTA_SELECT} = $quotas; |
1378 |
# Multiple available quotas found - need confirmation from user |
1379 |
} elsif ( $quotas->count == 1 ) { |
1379 |
$needsconfirmation{QUOTA_SELECT} = $quotas; |
1380 |
my $quota = $quotas->next; |
1380 |
} elsif ( $quotas->count == 1 ) { |
1381 |
if ( !$quota->has_available_quota ) { |
1381 |
my $quota = $quotas->next; |
1382 |
if ( C4::Context->preference("AllowQuotaOverride") ) { |
1382 |
if ( !$quota->has_available_quota ) { |
1383 |
$needsconfirmation{QUOTA_EXCEEDED} = { |
1383 |
if ( C4::Context->preference("AllowQuotaOverride") ) { |
1384 |
available => $quota->available_quota, |
1384 |
$needsconfirmation{QUOTA_EXCEEDED} = { |
1385 |
total => $quota->allocation, |
1385 |
available => $quota->available_quota, |
1386 |
used => $quota->used, |
1386 |
total => $quota->allocation, |
1387 |
}; |
1387 |
used => $quota->used, |
1388 |
} else { |
1388 |
}; |
1389 |
$issuingimpossible{QUOTA_EXCEEDED} = { |
1389 |
} else { |
1390 |
available => $quota->available_quota, |
1390 |
$issuingimpossible{QUOTA_EXCEEDED} = { |
1391 |
total => $quota->allocation, |
1391 |
available => $quota->available_quota, |
1392 |
used => $quota->used, |
1392 |
total => $quota->allocation, |
1393 |
}; |
1393 |
used => $quota->used, |
|
|
1394 |
}; |
1395 |
} |
1394 |
} |
1396 |
} |
1395 |
} |
1397 |
} |
1396 |
} |
1398 |
} |
Lines 1987-2005
sub AddIssue {
Link Here
|
1987 |
if C4::Context->preference('RealTimeHoldsQueue'); |
1989 |
if C4::Context->preference('RealTimeHoldsQueue'); |
1988 |
|
1990 |
|
1989 |
# Check quotas and record usage if needed |
1991 |
# Check quotas and record usage if needed |
1990 |
my $quota; |
1992 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
1991 |
if ($selected_quota_id) { |
1993 |
my $quota; |
1992 |
$quota = Koha::Patron::Quotas->find($selected_quota_id); |
1994 |
if ($selected_quota_id) { |
1993 |
} else { |
1995 |
$quota = Koha::Patron::Quotas->find($selected_quota_id); |
1994 |
$quota = $patron->all_quotas->filter_by_active->single; |
1996 |
} else { |
1995 |
} |
1997 |
$quota = $patron->all_quotas->filter_by_active->single; |
|
|
1998 |
} |
1999 |
|
2000 |
if ($quota) { |
1996 |
|
2001 |
|
1997 |
if ($quota) { |
2002 |
# Update patron's used quota value |
1998 |
# Update patron's used quota value |
2003 |
$quota->add_usage( |
1999 |
$quota->add_usage({ |
2004 |
{ |
2000 |
patron_id => $patron->patron_id, |
2005 |
patron_id => $patron->borrowernumber, |
2001 |
issue_id => $issue->issue_id, |
2006 |
issue_id => $issue->issue_id, |
2002 |
}); |
2007 |
} |
|
|
2008 |
); |
2009 |
} |
2003 |
} |
2010 |
} |
2004 |
} |
2011 |
} |
2005 |
} |
2012 |
} |
Lines 3353-3369
sub CanBookBeRenewed {
Link Here
|
3353 |
} |
3360 |
} |
3354 |
|
3361 |
|
3355 |
# # CHECK FOR QUOTAS |
3362 |
# # CHECK FOR QUOTAS |
3356 |
if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { |
3363 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
3357 |
|
3364 |
if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { |
3358 |
# Get current actives quota for the patron |
3365 |
|
3359 |
if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { |
3366 |
# Get current actives quota for the patron |
3360 |
my $all_exceeded = 1; |
3367 |
if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { |
3361 |
while ( my $active_quota = $active_quotas->next ) { |
3368 |
my $all_exceeded = 1; |
3362 |
if ( $active_quota->has_available_quota ) { |
3369 |
while ( my $active_quota = $active_quotas->next ) { |
3363 |
$all_exceeded = 0; |
3370 |
if ( $active_quota->has_available_quota ) { |
|
|
3371 |
$all_exceeded = 0; |
3372 |
} |
3364 |
} |
3373 |
} |
|
|
3374 |
return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; |
3365 |
} |
3375 |
} |
3366 |
return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; |
|
|
3367 |
} |
3376 |
} |
3368 |
} |
3377 |
} |
3369 |
|
3378 |
|
Lines 3480-3493
sub AddRenewal {
Link Here
|
3480 |
my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); |
3489 |
my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); |
3481 |
|
3490 |
|
3482 |
# Check quotas and record usage if needed |
3491 |
# Check quotas and record usage if needed |
3483 |
if (my $quota_usage = Koha::Patron::Quota::Usages->find({ issue_id => $issue->issue_id })) { |
3492 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
3484 |
# Get current active quota for the patron |
3493 |
if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { |
3485 |
if (my $active_quota = Koha::Patron::Quotas->find($quota_usage->patron_quota_id)) { |
3494 |
|
3486 |
# Update patron's used quota value |
3495 |
# Get current active quota for the patron |
3487 |
$active_quota->add_usage({ |
3496 |
if ( my $active_quota = Koha::Patron::Quotas->find( $quota_usage->patron_quota_id ) ) { |
3488 |
patron_id => $patron->borrowernumber, |
3497 |
|
3489 |
issue_id => $issue->issue_id, |
3498 |
# Update patron's used quota value |
3490 |
}); |
3499 |
$active_quota->add_usage( |
|
|
3500 |
{ |
3501 |
patron_id => $patron->borrowernumber, |
3502 |
issue_id => $issue->issue_id, |
3503 |
} |
3504 |
); |
3505 |
} |
3491 |
} |
3506 |
} |
3492 |
} |
3507 |
} |
3493 |
|
3508 |
|