X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=misc%2Fcronjobs%2Ffines.pl;h=02bde14bf142514959e5355ac27ed3b6b71520f6;hb=a52a0a8811f6ad03c422c62280bc184a9e16996d;hp=5124f3cd9e68f2878c9d7bc4fa1c5e08d33a00f4;hpb=367c4fb8815bfe4a01869a25bcd8222989c15dcd;p=koha_fer diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 5124f3cd9e..02bde14bf1 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -42,22 +42,24 @@ use Koha::DateUtils; my $help; my $verbose; my $output_dir; +my $log; GetOptions( 'h|help' => \$help, 'v|verbose' => \$verbose, + 'l|log' => \$log, 'o|out:s' => \$output_dir, ); my $usage = << 'ENDUSAGE'; This script calculates and charges overdue fines -to patron accounts. If the Koha System Preference -'finesMode' is set to 'production', the fines are charged -to the patron accounts. If set to 'test', the fines are -calculated but not applied. +to patron accounts. The Koha system preference 'finesMode' controls +whether the fines are calculated and charged to the patron accounts ("Calculate and charge"); +calculated and emailed to the admin but not applied ("Calculate (but only for mailing to the admin)"); or not calculated ("Don't calculate"). This script has the following parameters : -h --help: this message + -l --log: log the output to a file (optional if the -o parameter is given) -o --out: ouput directory for logs (defaults to env or /tmp if !exist) -v --verbose @@ -79,13 +81,18 @@ my $delim = "\t"; # ? C4::Context->preference('delimiter') || "\t"; my %is_holiday; my $today = DateTime->now( time_zone => C4::Context->tz() ); -my $filename = get_filename($output_dir); - -open my $fh, '>>', $filename or croak "Cannot write file $filename: $!"; -print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields ); -print {$fh} "\n"; +my $filename; +if ($log or $output_dir) { + $filename = get_filename($output_dir); +} -my $counted = 0; +my $fh; +if ($filename) { + open $fh, '>>', $filename or croak "Cannot write file $filename: $!"; + print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields ); + print {$fh} "\n"; +} +my $counted = 0; my $overdues = Getoverdues(); for my $overdue ( @{$overdues} ) { if ( !defined $overdue->{borrowernumber} ) { @@ -110,10 +117,9 @@ for my $overdue ( @{$overdues} ) { } ++$counted; - my ( $amount, $type, $daycounttotal ) = + my ( $amount, $type, $unitcounttotal ) = CalcFine( $overdue, $borrower->{categorycode}, $branchcode, $datedue, $today ); - $type ||= q{}; # Don't update the fine if today is a holiday. @@ -127,19 +133,29 @@ for my $overdue ( @{$overdues} ) { ); } } - my @cells; - push @cells, - map { defined $borrower->{$_} ? $borrower->{$_} : q{} } @borrower_fields; - push @cells, map { $overdue->{$_} } @item_fields; - push @cells, $type, $daycounttotal, $amount; - say {$fh} join $delim, @cells; + if ($filename) { + my @cells; + push @cells, + map { defined $borrower->{$_} ? $borrower->{$_} : q{} } + @borrower_fields; + push @cells, map { $overdue->{$_} } @item_fields; + push @cells, $type, $unitcounttotal, $amount; + say {$fh} join $delim, @cells; + } +} +if ($filename){ + close $fh; } -close $fh; if ($verbose) { my $overdue_items = @{$overdues}; - print <<'EOM'; -Fines assessment -- $today->ymd() -- Saved to $filename + print <<"EOM"; +Fines assessment -- $today +EOM + if ($filename) { + say "Saved to $filename"; + } + print <<"EOM"; Number of Overdue Items: counted $overdue_items reported $counted @@ -166,7 +182,7 @@ sub get_filename { $name =~ s/\W//; $name .= join q{}, q{_}, $today->ymd(), '.log'; $name = File::Spec->catfile( $directory, $name ); - if ($verbose) { + if ($verbose && $log) { say "writing to $name"; } return $name;