Bugzilla – Attachment 186492 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: Implement print notice charging backend logic to scripts
Bug-4858-Implement-print-notice-charging-backend-l.patch (text/plain), 3.67 KB, created by
Jacob O'Mara
on 2025-09-16 17:01:16 UTC
(
hide
)
Description:
Bug 4858: Implement print notice charging backend logic to scripts
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-09-16 17:01:16 UTC
Size:
3.67 KB
patch
obsolete
>From 215a6c0df6fe2790de9c9d22cc8418800c8cfd8f Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <jacob.omara@openfifth.co.uk> >Date: Mon, 30 Jun 2025 12:11:06 +0100 >Subject: [PATCH] Bug 4858: Implement print notice charging backend logic to > scripts > >- Update misc/cronjobs/gather_print_notices.pl to apply charges >- Add --skip-charges option for testing purposes >--- > misc/cronjobs/gather_print_notices.pl | 65 ++++++++++++++++++++++++++- > 1 file changed, 63 insertions(+), 2 deletions(-) > >diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl >index 1fd460df83e..e0556bb1d80 100755 >--- a/misc/cronjobs/gather_print_notices.pl >+++ b/misc/cronjobs/gather_print_notices.pl >@@ -16,6 +16,8 @@ use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Email; > use Koha::Util::OpenDocument qw( generate_ods ); > use Koha::SMTP::Servers; >+use Koha::Account; >+use Koha::Patrons; > > my ( > $help, >@@ -27,6 +29,7 @@ my ( > @letter_codes, > $send, > @emails, >+ $skip_charges, > ); > > my $command_line_options = join( " ", @ARGV ); >@@ -43,6 +46,7 @@ GetOptions( > 'letter_code:s' => \@letter_codes, > 'send!' => \$send, > 'e|email:s' => \@emails, >+ 'skip-charges' => \$skip_charges, > ) || pod2usage(1); > > pod2usage(0) if $help; >@@ -198,8 +202,13 @@ sub print_notices { > ); > } > >- if ($send) { >- foreach my $message (@$branch_messages) { >+ if ( $send ) { >+ foreach my $message ( @$branch_messages ) { >+ # Apply print notice charges if enabled >+ if (!$skip_charges && C4::Context->preference('PrintNoticeCharging')) { >+ apply_print_notice_charge($message); >+ } >+ > C4::Letters::_set_message_status( > { > message_id => $message->{'message_id'}, >@@ -344,6 +353,53 @@ sub send_files { > > } > >+=head2 apply_print_notice_charge >+ >+Apply a print notice charge to the patron's account >+ >+=cut >+ >+sub apply_print_notice_charge { >+ my ($message) = @_; >+ >+ # Check for valid message data >+ unless ($message && ref($message) eq 'HASH') { >+ warn "Invalid message data passed to apply_print_notice_charge"; >+ return; >+ } >+ >+ # Check for borrowernumber >+ unless ($message->{borrowernumber}) { >+ warn "No borrowernumber in message for print notice charge"; >+ return; >+ } >+ >+ # Skip if patron not found >+ my $patron = Koha::Patrons->find($message->{borrowernumber}); >+ unless ($patron) { >+ warn "Patron " . $message->{borrowernumber} . " not found for print notice charge"; >+ return; >+ } >+ >+ eval { >+ my $account = Koha::Account->new({ patron_id => $patron->borrowernumber }); >+ $account->add_print_notice_charge({ >+ notice_code => $message->{letter_code}, >+ library_id => $message->{branchcode}, >+ }); >+ >+ cronlogaction({ >+ action => 'Print notice charge', >+ info => "Applied charge for patron " . $message->{borrowernumber} . >+ " notice " . ($message->{letter_code} || 'unknown') >+ }); >+ }; >+ >+ if ($@) { >+ warn "Error applying print notice charge for patron " . $patron->borrowernumber . ": $@"; >+ } >+} >+ > =head1 NAME > > gather_print_notices - Print waiting print notices >@@ -406,6 +462,11 @@ Several letter_code parameters can be given. > Repeatable. > E-mail address to send generated files to. > >+=item B<--skip-charges> >+ >+Skip applying charges for print notices, even if patron category has print notice charging enabled. >+Useful for testing or administrative runs. >+ > =item B<-h|--help> > > Print a brief help message >-- >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