From 11192f242aaab20051bf2cc1395ac2a7acadad46 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 d546bc04f3f..3fea13473c7 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -64,7 +64,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 ); @@ -1350,6 +1354,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, ); } @@ -1899,6 +1923,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 5d05ba5c13e..06b8af85305 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -135,6 +135,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 %] @@ -628,6 +637,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.48.1