|
Lines 71-77
use Koha::Patron::Quota;
Link Here
|
| 71 |
use Koha::Patron::Quota::Usage; |
71 |
use Koha::Patron::Quota::Usage; |
| 72 |
use Koha::Patron::Quota::Usages; |
72 |
use Koha::Patron::Quota::Usages; |
| 73 |
|
73 |
|
| 74 |
use Carp qw( carp ); |
74 |
use Carp qw( carp ); |
| 75 |
use List::MoreUtils qw( any ); |
75 |
use List::MoreUtils qw( any ); |
| 76 |
use Scalar::Util qw( looks_like_number blessed ); |
76 |
use Scalar::Util qw( looks_like_number blessed ); |
| 77 |
use Date::Calc qw( Date_to_Days ); |
77 |
use Date::Calc qw( Date_to_Days ); |
|
Lines 1377-1402
sub CanBookBeIssued {
Link Here
|
| 1377 |
} |
1377 |
} |
| 1378 |
|
1378 |
|
| 1379 |
# CHECK FOR QUOTAS |
1379 |
# CHECK FOR QUOTAS |
| 1380 |
if ( my $quotas = $patron->all_quotas->filter_by_active ) { |
1380 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
| 1381 |
if ( $quotas->count > 1 ) { |
1381 |
if ( my $quotas = $patron->all_quotas->filter_by_active ) { |
| 1382 |
|
1382 |
if ( $quotas->count > 1 ) { |
| 1383 |
# Multiple available quotas found - need confirmation from user |
1383 |
|
| 1384 |
$needsconfirmation{QUOTA_SELECT} = $quotas; |
1384 |
# Multiple available quotas found - need confirmation from user |
| 1385 |
} elsif ( $quotas->count == 1 ) { |
1385 |
$needsconfirmation{QUOTA_SELECT} = $quotas; |
| 1386 |
my $quota = $quotas->next; |
1386 |
} elsif ( $quotas->count == 1 ) { |
| 1387 |
if ( !$quota->has_available_quota ) { |
1387 |
my $quota = $quotas->next; |
| 1388 |
if ( C4::Context->preference("AllowQuotaOverride") ) { |
1388 |
if ( !$quota->has_available_quota ) { |
| 1389 |
$needsconfirmation{QUOTA_EXCEEDED} = { |
1389 |
if ( C4::Context->preference("AllowQuotaOverride") ) { |
| 1390 |
available => $quota->available_quota, |
1390 |
$needsconfirmation{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 |
} else { |
1394 |
}; |
| 1395 |
$issuingimpossible{QUOTA_EXCEEDED} = { |
1395 |
} else { |
| 1396 |
available => $quota->available_quota, |
1396 |
$issuingimpossible{QUOTA_EXCEEDED} = { |
| 1397 |
total => $quota->allocation, |
1397 |
available => $quota->available_quota, |
| 1398 |
used => $quota->used, |
1398 |
total => $quota->allocation, |
| 1399 |
}; |
1399 |
used => $quota->used, |
|
|
1400 |
}; |
| 1401 |
} |
| 1400 |
} |
1402 |
} |
| 1401 |
} |
1403 |
} |
| 1402 |
} |
1404 |
} |
|
Lines 2021-2039
sub AddIssue {
Link Here
|
| 2021 |
if C4::Context->preference('RealTimeHoldsQueue'); |
2023 |
if C4::Context->preference('RealTimeHoldsQueue'); |
| 2022 |
|
2024 |
|
| 2023 |
# Check quotas and record usage if needed |
2025 |
# Check quotas and record usage if needed |
| 2024 |
my $quota; |
2026 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
| 2025 |
if ($selected_quota_id) { |
2027 |
my $quota; |
| 2026 |
$quota = Koha::Patron::Quotas->find($selected_quota_id); |
2028 |
if ($selected_quota_id) { |
| 2027 |
} else { |
2029 |
$quota = Koha::Patron::Quotas->find($selected_quota_id); |
| 2028 |
$quota = $patron->all_quotas->filter_by_active->single; |
2030 |
} else { |
| 2029 |
} |
2031 |
$quota = $patron->all_quotas->filter_by_active->single; |
|
|
2032 |
} |
| 2033 |
|
| 2034 |
if ($quota) { |
| 2030 |
|
2035 |
|
| 2031 |
if ($quota) { |
2036 |
# Update patron's used quota value |
| 2032 |
# Update patron's used quota value |
2037 |
$quota->add_usage( |
| 2033 |
$quota->add_usage({ |
2038 |
{ |
| 2034 |
patron_id => $patron->patron_id, |
2039 |
patron_id => $patron->borrowernumber, |
| 2035 |
issue_id => $issue->issue_id, |
2040 |
issue_id => $issue->issue_id, |
| 2036 |
}); |
2041 |
} |
|
|
2042 |
); |
| 2043 |
} |
| 2037 |
} |
2044 |
} |
| 2038 |
} |
2045 |
} |
| 2039 |
} |
2046 |
} |
|
Lines 3389-3406
sub CanBookBeRenewed {
Link Here
|
| 3389 |
} |
3396 |
} |
| 3390 |
} |
3397 |
} |
| 3391 |
|
3398 |
|
| 3392 |
# # CHECK FOR QUOTAS |
3399 |
# # CHECK FOR QUOTAS |
| 3393 |
if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { |
3400 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
|
|
3401 |
if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { |
| 3394 |
|
3402 |
|
| 3395 |
# Get current actives quota for the patron |
3403 |
# Get current actives quota for the patron |
| 3396 |
if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { |
3404 |
if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { |
| 3397 |
my $all_exceeded = 1; |
3405 |
my $all_exceeded = 1; |
| 3398 |
while ( my $active_quota = $active_quotas->next ) { |
3406 |
while ( my $active_quota = $active_quotas->next ) { |
| 3399 |
if ( $active_quota->has_available_quota ) { |
3407 |
if ( $active_quota->has_available_quota ) { |
| 3400 |
$all_exceeded = 0; |
3408 |
$all_exceeded = 0; |
|
|
3409 |
} |
| 3401 |
} |
3410 |
} |
|
|
3411 |
return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; |
| 3402 |
} |
3412 |
} |
| 3403 |
return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; |
|
|
| 3404 |
} |
3413 |
} |
| 3405 |
} |
3414 |
} |
| 3406 |
|
3415 |
|
|
Lines 3519-3532
sub AddRenewal {
Link Here
|
| 3519 |
my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); |
3528 |
my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); |
| 3520 |
|
3529 |
|
| 3521 |
# Check quotas and record usage if needed |
3530 |
# Check quotas and record usage if needed |
| 3522 |
if (my $quota_usage = Koha::Patron::Quota::Usages->find({ issue_id => $issue->issue_id })) { |
3531 |
if ( C4::Context->preference('EnableCirculationQuotas') ) { |
| 3523 |
# Get current active quota for the patron |
3532 |
if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { |
| 3524 |
if (my $active_quota = Koha::Patron::Quotas->find($quota_usage->patron_quota_id)) { |
3533 |
|
| 3525 |
# Update patron's used quota value |
3534 |
# Get current active quota for the patron |
| 3526 |
$active_quota->add_usage({ |
3535 |
if ( my $active_quota = Koha::Patron::Quotas->find( $quota_usage->patron_quota_id ) ) { |
| 3527 |
patron_id => $patron->borrowernumber, |
3536 |
|
| 3528 |
issue_id => $issue->issue_id, |
3537 |
# Update patron's used quota value |
| 3529 |
}); |
3538 |
$active_quota->add_usage( |
|
|
3539 |
{ |
| 3540 |
patron_id => $patron->borrowernumber, |
| 3541 |
issue_id => $issue->issue_id, |
| 3542 |
} |
| 3543 |
); |
| 3544 |
} |
| 3530 |
} |
3545 |
} |
| 3531 |
} |
3546 |
} |
| 3532 |
|
3547 |
|