From 412698dc2b60ba589ab2f1d1e32d584990e53265 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Fri, 31 Jan 2025 15:07:43 +0000 Subject: [PATCH] Bug 38924: Hook quota check and allocation into checkout --- C4/Circulation.pm | 35 ++++++++++++++++++- .../prog/en/modules/circ/circulation.tt | 13 +++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0a8df342638..7a64f8603ae 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -66,7 +66,11 @@ use Koha::Exceptions::Checkout; use Koha::Plugins; use Koha::Recalls; use Koha::Library::Hours; -use Carp qw( carp ); +use Koha::Patron::Quotas; +use Koha::Patron::Quota; +use Koha::Patron::Quota::Usage; + +use Carp qw( carp ); use List::MoreUtils qw( any ); use Scalar::Util qw( looks_like_number blessed ); use Date::Calc qw( Date_to_Days ); @@ -1371,6 +1375,26 @@ sub CanBookBeIssued { } } + # CHECK FOR QUOTAS + if ( my $quota = Koha::Patron::Quotas->get_patron_quota($patron->borrowernumber) ) { + unless ( $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, + }; + } + } + } + return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages ); } @@ -1987,6 +2011,15 @@ sub AddIssue { Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $item_object->biblionumber ] } ) if C4::Context->preference('RealTimeHoldsQueue'); + + # Check quotas and record usage if needed + if ( my $quota = Koha::Patron::Quotas->get_patron_quota($patron->borrowernumber) ) { + # Update patron's used quota value + $quota->add_usage({ + patron_id => $patron->patron_id, + issue_id => $issue->issue_id, + }); + } } } return $issue; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 8872479a71e..27fbfbde2f4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -155,6 +155,15 @@ [% END %] + [%IF ( QUOTA_EXCEEDED ) %] +
  • + Quota Exceeded [% QUOTA_EXCEEDED | html %]. + [% IF CAN_user_circulate_force_checkout %] + Check out anyway? + [% END %] +
  • + [% END %] + [% IF ( DEBT ) %]
  • The patron has a debt of [% DEBT | $Price %].
  • [% END %] @@ -652,6 +661,10 @@
  • Age restriction [% AGE_RESTRICTION | html %].
  • [% END %] + [%IF ( QUOTA_EXCEEDED ) %] +
  • Quota Exceeded [% QUOTA_EXCEEDED | html %].
  • + [% END %] + [% IF ( EXPIRED ) %]
  • Patron's card is expired
  • [% END %] -- 2.39.5