From ec692da4e6342964da35983113b7e3595c542a6d Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Mon, 30 Jun 2025 13:20:39 +0100 Subject: [PATCH] Bug 4858: Add category based print notice charging support to patron.pm This adds the ability to define print charge notice amounts at a patron category level. Sponsored-by: OpenFifth Signed-off-by: Jackie Usher --- Koha/Patron.pm | 47 +++++++++++++++++++ admin/categories.pl | 3 ++ .../prog/en/modules/admin/categories.tt | 14 ++++++ misc/cronjobs/gather_print_notices.pl | 5 +- 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index c0ef6e292c5..52532a45ead 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -21,6 +21,7 @@ package Koha::Patron; use Modern::Perl; use List::MoreUtils qw( any none uniq notall zip6); +use Scalar::Util qw( looks_like_number ); use JSON qw( to_json ); use Scalar::Util qw(looks_like_number); use Unicode::Normalize qw( NFKD ); @@ -1663,6 +1664,52 @@ sub add_enrolment_fee_if_needed { return $enrolment_fee || 0; } +=head3 add_print_notice_charge_if_needed + +my $result = $patron->add_print_notice_charge_if_needed($params); + +Add a print notice charge for a patron if needed. + +$params - hash reference containing: + - amount: charge amount (optional, uses system preference if not provided) + - notice_code: the notice code for the charge description + - library_id: library branch for the charge (optional) + +Returns the account line object if a charge was added, undef otherwise. + +=cut + +sub add_print_notice_charge_if_needed { + my ( $self, $params ) = @_; + + return unless $params && ref($params) eq 'HASH'; + + # Get charge amount from patron category (0 = disabled) + my $charge_amount = defined $params->{amount} ? $params->{amount} : $self->category->print_notice_charge; + + # Return early for invalid amounts + return unless defined $charge_amount; + return unless Scalar::Util::looks_like_number($charge_amount); + return unless $charge_amount > 0; + + my $userenv = C4::Context->userenv; + my $library_id = $params->{library_id} || ($userenv ? $userenv->{branch} : undef); + + my $result; + try { + $result = $self->account->add_debit({ + amount => $charge_amount, + type => 'PRINT_NOTICE', + interface => C4::Context->interface, + library_id => $library_id, + }); + } catch { + return; + }; + + return $result; +} + =head3 checkouts my $checkouts = $patron->checkouts diff --git a/admin/categories.pl b/admin/categories.pl index d471e9cc768..8b8e08b0490 100755 --- a/admin/categories.pl +++ b/admin/categories.pl @@ -63,6 +63,7 @@ if ( $op eq 'add_form' ) { my $upperagelimit = $input->param('upperagelimit'); my $dateofbirthrequired = $input->param('dateofbirthrequired'); my $enrolmentfee = $input->param('enrolmentfee'); + my $print_notice_charge = $input->param('print_notice_charge'); my $hidelostitems = $input->param('hidelostitems'); my $overduenoticerequired = $input->param('overduenoticerequired'); my $category_type = $input->param('category_type'); @@ -102,6 +103,7 @@ if ( $op eq 'add_form' ) { $category->upperagelimit($upperagelimit); $category->dateofbirthrequired($dateofbirthrequired); $category->enrolmentfee($enrolmentfee); + $category->print_notice_charge($print_notice_charge); $category->hidelostitems($hidelostitems); $category->overduenoticerequired($overduenoticerequired); $category->category_type($category_type); @@ -140,6 +142,7 @@ if ( $op eq 'add_form' ) { upperagelimit => $upperagelimit, dateofbirthrequired => $dateofbirthrequired, enrolmentfee => $enrolmentfee, + print_notice_charge => $print_notice_charge, hidelostitems => $hidelostitems, overduenoticerequired => $overduenoticerequired, category_type => $category_type, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt index c0a66967ffb..0aba29fd18c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -204,6 +204,12 @@ [% END %] +
  • + + +
    Charge for print notices (0.00 = disabled)
    +
  • +