From 5ab62c3121411224c34fdf2d8cd251ba8066bf09 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. --- 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 479eb3c209b..9db082635c8 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 Unicode::Normalize qw( NFKD ); use Try::Tiny; @@ -1653,6 +1654,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 04b5e5cc024..93d21239447 100755 --- a/admin/categories.pl +++ b/admin/categories.pl @@ -64,6 +64,7 @@ if ( $op eq 'add_form' ) { my $dateofbirthrequired = $input->param('dateofbirthrequired'); my $enrolmentfee = $input->param('enrolmentfee'); my $reservefee = $input->param('reservefee'); + 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'); @@ -104,6 +105,7 @@ if ( $op eq 'add_form' ) { $category->dateofbirthrequired($dateofbirthrequired); $category->enrolmentfee($enrolmentfee); $category->reservefee($reservefee); + $category->print_notice_charge($print_notice_charge); $category->hidelostitems($hidelostitems); $category->overduenoticerequired($overduenoticerequired); $category->category_type($category_type); @@ -143,6 +145,7 @@ if ( $op eq 'add_form' ) { dateofbirthrequired => $dateofbirthrequired, enrolmentfee => $enrolmentfee, reservefee => $reservefee, + 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 e91ba21feb3..f80664b19a8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -208,6 +208,12 @@ +
  • + + +
    Charge for print notices (0.00 = disabled)
    +
  • +