From ed63a853ab5b56d36999f922bbe5d4db65e70f1b 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 514eb3ae97..1973f8cd76 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -65,7 +65,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 ); @@ -1365,6 +1369,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, ); } @@ -1953,6 +1977,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 1ca767f729..a1a2b491a6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -156,6 +156,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 %] @@ -653,6 +662,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.50.1