Bugzilla – Attachment 186495 Details for
Bug 4858
Ability to Charge for Print Notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 4858: Add category based print notice charging support to patron.pm
Bug-4858-Add-category-based-print-notice-charging-.patch (text/plain), 8.48 KB, created by
Jacob O'Mara
on 2025-09-16 17:01:47 UTC
(
hide
)
Description:
Bug 4858: Add category based print notice charging support to patron.pm
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-09-16 17:01:47 UTC
Size:
8.48 KB
patch
obsolete
>From 5ab62c3121411224c34fdf2d8cd251ba8066bf09 Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <jacob.omara@openfifth.co.uk> >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 @@ > <label for="reservefee">Hold fee: </label> > <input type="text" name="reservefee" id="reservefee" size="6" value="[% category.reservefee | $Price on_editing => 1 %]" /> > </li> >+ <li> >+ <label for="print_notice_charge">Print notice charge: </label> >+ <input type="text" name="print_notice_charge" id="print_notice_charge" size="6" value="[% category.print_notice_charge | $Price on_editing => 1 %]" /> >+ <div class="hint">Charge for print notices (0.00 = disabled)</div> >+ </li> >+ > <li> > <label for="category_type" class="required">Category type: </label> > <select name="category_type" id="category_type"> >@@ -572,6 +578,7 @@ > <tr><th scope="row">Receives overdue notices: </th><td>[% IF category. overduenoticerequired %]Yes[% ELSE %]No[% END %]</td></tr> > <tr><th scope="row">Lost items in staff interface:</th><td>[% IF category.hidelostitems %]Hidden by default[% ELSE %]Shown[% END %]</td></tr> > <tr><th scope="row">Hold fee: </th><td>[% category.reservefee | $Price %]</td></tr> >+ <tr><th scope="row">Print notice charge: </th><td>[% IF category.print_notice_charge > 0 %][% category.print_notice_charge | $Price %][% ELSE %]Disabled[% END %]</td></tr> > > [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %] > <tr> >@@ -653,6 +660,8 @@ > <th scope="col" data-colname="overdue">Overdue</th> > <th scope="col" data-colname="lost_items">Lost items</th> > <th scope="col" data-colname="hold_fee">Hold fee</th> >+ <th scope="col" data-colname="print_notice_charge">Print notice charge</th> >+ > [% IF ( EnhancedMessagingPreferences ) %] > <th scope="col" data-colname="messaging">Messaging</th> > [% END %] >@@ -731,6 +740,11 @@ > [% ELSE %] > <td>-</td> > [% END %] >+ [% IF (category.print_notice_charge > 0) %] >+ <td>[% category.print_notice_charge | $Price %]</td> >+ [% ELSE %] >+ <td>-</td> >+ [% END %] > [% IF Koha.Preference('EnhancedMessagingPreferences') %] > <td style="white-space: nowrap; font-size:80%;"> > [% SET default_messaging = category.default_messaging %] >diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl >index e0556bb1d80..7f6eea133ec 100755 >--- a/misc/cronjobs/gather_print_notices.pl >+++ b/misc/cronjobs/gather_print_notices.pl >@@ -205,7 +205,7 @@ sub print_notices { > if ( $send ) { > foreach my $message ( @$branch_messages ) { > # Apply print notice charges if enabled >- if (!$skip_charges && C4::Context->preference('PrintNoticeCharging')) { >+ if (!$skip_charges) { > apply_print_notice_charge($message); > } > >@@ -382,8 +382,7 @@ sub apply_print_notice_charge { > } > > eval { >- my $account = Koha::Account->new({ patron_id => $patron->borrowernumber }); >- $account->add_print_notice_charge({ >+ my $result = $patron->add_print_notice_charge_if_needed({ > notice_code => $message->{letter_code}, > library_id => $message->{branchcode}, > }); >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 4858
:
186491
|
186492
|
186493
|
186494
| 186495 |
186496
|
186497
|
186498
|
186499
|
186500
|
186501
|
186502