From 508d55eb7bd7b7d8e1c2ec1f455c5181fd1d2800 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 17 Oct 2023 12:39:44 +0100 Subject: [PATCH] Bug 35074: Add support for category_code to writeoff_debts This patch adds support for passing category_code as a limiter for the writeoff_debts script. Signed-off-by: Lucas Gass Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- misc/cronjobs/writeoff_debts.pl | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/misc/cronjobs/writeoff_debts.pl b/misc/cronjobs/writeoff_debts.pl index 1fc7ce18e3..dad36ffaf9 100755 --- a/misc/cronjobs/writeoff_debts.pl +++ b/misc/cronjobs/writeoff_debts.pl @@ -11,15 +11,16 @@ use Koha::DateUtils qw( dt_from_string ); use Koha::Script -cron; -my ( $help, $verbose, @type, $before, $after, $file, $confirm ); +my ( $help, $verbose, @type, $before, $after, @category_code, $file, $confirm ); GetOptions( - 'h|help' => \$help, - 'v|verbose+' => \$verbose, - 't|type:s' => \@type, - 'ab|added_before|added-before:s' => \$before, - 'aa|added_after|added-after:s' => \$after, - 'f|file:s' => \$file, - 'c|confirm' => \$confirm, + 'h|help' => \$help, + 'v|verbose+' => \$verbose, + 't|type:s' => \@type, + 'ab|added_before|added-before:s' => \$before, + 'aa|added_after|added-after:s' => \$after, + 'cc|category_code|category-code:s' => \@category_code, + 'f|file:s' => \$file, + 'c|confirm' => \$confirm, ); @type = split( /,/, join( ',', @type ) ); @@ -59,6 +60,11 @@ if ($after) { $where->{date}->{'>'} = $dtf->format_datetime($added_after); } +if (@category_code) { + $where->{'patron.categorycode'}->{'-in'} = \@category_code; + push @{ $attr->{'join'} }, 'patron'; +} + my $lines = Koha::Account::Lines->search( $where, $attr ); if ( $verbose ) { print "Attempting to write off " . $lines->count . " debts"; @@ -168,6 +174,12 @@ Writeoff debts added after the date passed. Dates should be in ISO format, e.g., 2013-07-19, and can be generated with `date -d '-3 month' --iso-8601`. +=item B<--category-code> + +Writeoff debts for patrons belonging to the passed categories. + +Can be used multiple times for additional category codes. + =item B<--type> Writeoff debts of the passed type. Accepts a list of CREDIT_TYPE_CODEs. -- 2.39.5