From 20ecb0daa04b2e40036a40014c4377254bbfa161 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 c9664352e83..d81e4bf464e 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -69,7 +69,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 ); @@ -1356,26 +1356,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, + }; + } } } } @@ -1933,19 +1935,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, + } + ); + } } } } @@ -3284,18 +3291,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; } } @@ -3412,14 +3421,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 ff68b902b2e..c558c436f3f 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -254,6 +254,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''), ('EnablePointOfSale','0',NULL,'Enable the point of sale feature to allow anonymous transactions with the accounting system. (Requires UseCashRegisters)','YesNo'), ('EnableSearchHistory','0','','Enable or disable search history','YesNo'), +('EnableCirculationQuotas','0','','Enable or disable the circulation quotas feature','YesNo'), ('EnhancedMessagingPreferences','1','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'), ('EnhancedMessagingPreferencesOPAC', '1', NULL, 'If ON, show patrons messaging setting on the OPAC.', 'YesNo'), ('ERMModule', '0', NULL, 'Enable the e-resource management module', '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 b4eefa133aa..6fa47bf2ae7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -195,11 +195,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 d54d6aa09bf..61d6ad840cd 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 @@ -1324,6 +1312,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.48.1