From eb135a6712e9062aa3798649dfa2569f6fb52e52 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 11 Feb 2025 14:14:09 +0000 Subject: [PATCH] Bug 38924: Add option to enable/disable quotas --- C4/Circulation.pm | 115 ++++++++++-------- .../atomicupdate/bug_38924-patron_quotas.pl | 28 +++-- installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/includes/circ-menu.inc | 2 + .../admin/preferences/circulation.pref | 31 +++-- 5 files changed, 104 insertions(+), 73 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 50cd2a81a20..ec32ad65c34 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -71,7 +71,7 @@ use Koha::Patron::Quota; use Koha::Patron::Quota::Usage; use Koha::Patron::Quota::Usages; -use Carp qw( carp ); +use Carp qw( carp ); use List::MoreUtils qw( any ); use Scalar::Util qw( looks_like_number blessed ); use Date::Calc qw( Date_to_Days ); @@ -1377,26 +1377,28 @@ sub CanBookBeIssued { } # CHECK FOR QUOTAS - if ( my $quotas = $patron->all_quotas->filter_by_active ) { - if ( $quotas->count > 1 ) { - - # Multiple available quotas found - need confirmation from user - $needsconfirmation{QUOTA_SELECT} = $quotas; - } elsif ( $quotas->count == 1 ) { - my $quota = $quotas->next; - if ( !$quota->has_available_quota ) { - if ( C4::Context->preference("AllowQuotaOverride") ) { - $needsconfirmation{QUOTA_EXCEEDED} = { - available => $quota->available_quota, - total => $quota->allocation, - used => $quota->used, - }; - } else { - $issuingimpossible{QUOTA_EXCEEDED} = { - available => $quota->available_quota, - total => $quota->allocation, - used => $quota->used, - }; + if ( C4::Context->preference('EnableCirculationQuotas') ) { + if ( my $quotas = $patron->all_quotas->filter_by_active ) { + if ( $quotas->count > 1 ) { + + # Multiple available quotas found - need confirmation from user + $needsconfirmation{QUOTA_SELECT} = $quotas; + } elsif ( $quotas->count == 1 ) { + my $quota = $quotas->next; + if ( !$quota->has_available_quota ) { + if ( C4::Context->preference("AllowQuotaOverride") ) { + $needsconfirmation{QUOTA_EXCEEDED} = { + available => $quota->available_quota, + total => $quota->allocation, + used => $quota->used, + }; + } else { + $issuingimpossible{QUOTA_EXCEEDED} = { + available => $quota->available_quota, + total => $quota->allocation, + used => $quota->used, + }; + } } } } @@ -2021,19 +2023,24 @@ sub AddIssue { if C4::Context->preference('RealTimeHoldsQueue'); # Check quotas and record usage if needed - my $quota; - if ($selected_quota_id) { - $quota = Koha::Patron::Quotas->find($selected_quota_id); - } else { - $quota = $patron->all_quotas->filter_by_active->single; - } + if ( C4::Context->preference('EnableCirculationQuotas') ) { + my $quota; + if ($selected_quota_id) { + $quota = Koha::Patron::Quotas->find($selected_quota_id); + } else { + $quota = $patron->all_quotas->filter_by_active->single; + } + + if ($quota) { - if ($quota) { - # Update patron's used quota value - $quota->add_usage({ - patron_id => $patron->patron_id, - issue_id => $issue->issue_id, - }); + # Update patron's used quota value + $quota->add_usage( + { + patron_id => $patron->borrowernumber, + issue_id => $issue->issue_id, + } + ); + } } } } @@ -3389,18 +3396,20 @@ sub CanBookBeRenewed { } } - # # CHECK FOR QUOTAS - if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { + # # CHECK FOR QUOTAS + if ( C4::Context->preference('EnableCirculationQuotas') ) { + if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { - # Get current actives quota for the patron - if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { - my $all_exceeded = 1; - while ( my $active_quota = $active_quotas->next ) { - if ( $active_quota->has_available_quota ) { - $all_exceeded = 0; + # Get current actives quota for the patron + if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { + my $all_exceeded = 1; + while ( my $active_quota = $active_quotas->next ) { + if ( $active_quota->has_available_quota ) { + $all_exceeded = 0; + } } + return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; } - return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; } } @@ -3519,14 +3528,20 @@ sub AddRenewal { my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); # Check quotas and record usage if needed - if (my $quota_usage = Koha::Patron::Quota::Usages->find({ issue_id => $issue->issue_id })) { - # Get current active quota for the patron - if (my $active_quota = Koha::Patron::Quotas->find($quota_usage->patron_quota_id)) { - # Update patron's used quota value - $active_quota->add_usage({ - patron_id => $patron->borrowernumber, - issue_id => $issue->issue_id, - }); + if ( C4::Context->preference('EnableCirculationQuotas') ) { + if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { + + # Get current active quota for the patron + if ( my $active_quota = Koha::Patron::Quotas->find( $quota_usage->patron_quota_id ) ) { + + # Update patron's used quota value + $active_quota->add_usage( + { + patron_id => $patron->borrowernumber, + issue_id => $issue->issue_id, + } + ); + } } } diff --git a/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl b/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl index 7c1ae600b1a..67fea327011 100755 --- a/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl +++ b/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl @@ -25,21 +25,23 @@ return { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; } ); - - $dbh->do(q{ + + $dbh->do( + q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (4, 'manage_borrower_quotas', 'Manage patron quotas'), (4, 'view_borrower_quotas', 'View patron quotas') - }); - + } + ); + say_success( $out, "Patron quota table and permissions created successfully" ); } else { say_info( $out, "Patron quota table already exists" ); } - unless ( TableExists('patron_quota_usage') ) - { - $dbh->do(q{ + unless ( TableExists('patron_quota_usage') ) { + $dbh->do( + q{ CREATE TABLE `patron_quota_usage` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier for quota usage record', `patron_quota_id` int(11) NOT NULL COMMENT 'foreign key linking to patron_quota.id', @@ -54,19 +56,23 @@ return { CONSTRAINT `patron_quota_usage_ibfk_1` FOREIGN KEY (`patron_quota_id`) REFERENCES `patron_quota` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `patron_quota_usage_ibfk_2` FOREIGN KEY (`patron_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - }); + } + ); say_success( $out, "Patron quota usage table created successfully" ); } else { say_info( $out, "Patron quota usage table already exists" ); } - $dbh->do(q{ + $dbh->do( + q{ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('AllowQuotaOverride', '0', NULL, 'Allow staff to override and check out items to patrons who have exceeded their quota limit', 'YesNo'), - ('UseGuarantorQuota', '0', NULL, 'Use guarantor quota instead of guarantee quota when checking out items', 'YesNo') - }); + ('UseGuarantorQuota', '0', NULL, 'Use guarantor quota instead of guarantee quota when checking out items', 'YesNo'), + ('EnableCirculationQuotas','0','','Enable or disable the circulation quotas feature','YesNo') + } + ); say_success( $out, "Patron quota preferences added successfully" ); }, diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 85a0f3cec58..c934709b5c6 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -258,6 +258,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'), ('EnableBooking','1',NULL,'If enabled, activate every functionnalities related with Bookings module','YesNo'), ('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'), +('EnableCirculationQuotas','0','','Enable or disable the circulation quotas feature','YesNo'), ('EnableExpiredPasswordReset', '0', NULL, 'Enable ability for patrons with expired password to reset their password directly', 'YesNo'), ('EnableItemGroupHolds','0','','Enable item groups holds feature','YesNo'), ('EnableItemGroups','0','','Enable the item groups feature','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc index 32f78d217fc..16eba07f5dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -203,11 +203,13 @@ [% END %] [% END %] + [% IF Koha.Preference('EnableCirculationQuotas') %] [% IF patron.category.category_type == 'I' %]
  • [% END %]> Circulation quota
  • [% END %] + [% END %] [% IF CAN_user_borrowers_edit_borrowers %] [% IF ( IntranetReadingHistoryHolds ) %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 11906976b50..dbbea16d00a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -389,18 +389,6 @@ Circulation: 1: Allow 0: "Don't allow" - staff to check out an item with age restriction. - - - - pref: AllowQuotaOverride - choices: - 1: "Allow" - 0: "Don't allow" - - staff to check out items to patrons who have exceeded their quota limit. - - - - pref: UseGuarantorQuota - choices: - 1: "Use" - 0: "Don't use" - - guarantor's quota instead of guarantee's quota when checking out items if guarantor has an active quota and quota has enough availability. - - Prevent patrons from checking out items if they have more than - pref: noissuescharge @@ -1347,6 +1335,25 @@ Circulation: - pref: SCOBatchCheckoutsValidCategories choices: patron-categories class: multiple + Quotas: + - + - pref: EnableCirculationQuotas + choices: + 1: "Enable" + 0: "Disable" + - circulation quotas for patrons. + - + - pref: AllowQuotaOverride + choices: + 1: "Allow" + 0: "Don't allow" + - staff to check out items to patrons who have exceeded their quota limit. + - + - pref: UseGuarantorQuota + choices: + 1: "Use" + 0: "Don't use" + - guarantor's quota instead of guarantee's quota when checking out items if guarantor has an active quota and quota has enough availability. Course reserves: - - pref: UseCourseReserves -- 2.39.5