Bugzilla – Attachment 194261 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
ec692da.patch (text/plain), 8.64 KB, created by
Martin Renvoize (ashimema)
on 2026-03-02 09:27:45 UTC
(
hide
)
Description:
Bug 4858: Add category based print notice charging support to patron.pm
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-03-02 09:27:45 UTC
Size:
8.64 KB
patch
obsolete
>From ec692da4e6342964da35983113b7e3595c542a6d 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. > >Sponsored-by: OpenFifth <https://openfifth.co.uk\> >Signed-off-by: Jackie Usher <jackie.usher@westsussex.gov.uk> >--- > 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 %] > </select> > </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"> >@@ -567,6 +573,7 @@ > <tr><th scope="row">Enrollment fee: </th><td>[% category.enrolmentfee | $Price %]</td></tr> > <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">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> >@@ -647,6 +654,8 @@ > <th scope="col" data-colname="enrollment_fee">Enrollment fee</th> > <th scope="col" data-colname="overdue">Overdue</th> > <th scope="col" data-colname="lost_items">Lost items</th> >+ <th scope="col" data-colname="print_notice_charge">Print notice charge</th> >+ > [% IF ( EnhancedMessagingPreferences ) %] > <th scope="col" data-colname="messaging">Messaging</th> > [% END %] >@@ -720,6 +729,11 @@ > [% END %] > <td>[% IF ( category.overduenoticerequired ) %]Yes[% ELSE %]No[% END %]</td> > <td>[% IF ( category.hidelostitems ) %]Hidden[% ELSE %]Shown[% END %]</td> >+ [% 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 3e2fcc52b78..853f0ebb056 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.53.0 >
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
|
194257
|
194258
|
194259
|
194260
| 194261 |
194262
|
194263
|
194264
|
194265
|
194266
|
194267
|
194268
|
194269
|
194270
|
194271
|
194272