View | Details | Raw Unified | Return to bug 4858
Collapse All | Expand All

(-)a/misc/cronjobs/gather_print_notices.pl (-3 / +63 lines)
Lines 16-21 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
16
use Koha::Email;
16
use Koha::Email;
17
use Koha::Util::OpenDocument qw( generate_ods );
17
use Koha::Util::OpenDocument qw( generate_ods );
18
use Koha::SMTP::Servers;
18
use Koha::SMTP::Servers;
19
use Koha::Account;
20
use Koha::Patrons;
19
21
20
my (
22
my (
21
    $help,
23
    $help,
Lines 27-32 my ( Link Here
27
    @letter_codes,
29
    @letter_codes,
28
    $send,
30
    $send,
29
    @emails,
31
    @emails,
32
    $skip_charges,
30
);
33
);
31
34
32
my $command_line_options = join( " ", @ARGV );
35
my $command_line_options = join( " ", @ARGV );
Lines 43-48 GetOptions( Link Here
43
    'letter_code:s' => \@letter_codes,
46
    'letter_code:s' => \@letter_codes,
44
    'send!'         => \$send,
47
    'send!'         => \$send,
45
    'e|email:s'     => \@emails,
48
    'e|email:s'     => \@emails,
49
    'skip-charges'  => \$skip_charges,
46
) || pod2usage(1);
50
) || pod2usage(1);
47
51
48
pod2usage(0) if $help;
52
pod2usage(0) if $help;
Lines 198-205 sub print_notices { Link Here
198
            );
202
            );
199
        }
203
        }
200
204
201
        if ($send) {
205
        if ( $send ) {
202
            foreach my $message (@$branch_messages) {
206
            foreach my $message ( @$branch_messages ) {
207
                # Apply print notice charges if enabled
208
                if (!$skip_charges && C4::Context->preference('PrintNoticeCharging')) {
209
                    apply_print_notice_charge($message);
210
                }
211
203
                C4::Letters::_set_message_status(
212
                C4::Letters::_set_message_status(
204
                    {
213
                    {
205
                        message_id => $message->{'message_id'},
214
                        message_id => $message->{'message_id'},
Lines 344-349 sub send_files { Link Here
344
353
345
}
354
}
346
355
356
=head2 apply_print_notice_charge
357
358
Apply a print notice charge to the patron's account
359
360
=cut
361
362
sub apply_print_notice_charge {
363
    my ($message) = @_;
364
365
    # Check for valid message data
366
    unless ($message && ref($message) eq 'HASH') {
367
        warn "Invalid message data passed to apply_print_notice_charge";
368
        return;
369
    }
370
371
    # Check for borrowernumber
372
    unless ($message->{borrowernumber}) {
373
        warn "No borrowernumber in message for print notice charge";
374
        return;
375
    }
376
377
    # Skip if patron not found
378
    my $patron = Koha::Patrons->find($message->{borrowernumber});
379
    unless ($patron) {
380
        warn "Patron " . $message->{borrowernumber} . " not found for print notice charge";
381
        return;
382
    }
383
384
    eval {
385
        my $account = Koha::Account->new({ patron_id => $patron->borrowernumber });
386
        $account->add_print_notice_charge({
387
            notice_code => $message->{letter_code},
388
            library_id  => $message->{branchcode},
389
        });
390
391
        cronlogaction({
392
            action => 'Print notice charge',
393
            info   => "Applied charge for patron " . $message->{borrowernumber} .
394
                     " notice " . ($message->{letter_code} || 'unknown')
395
        });
396
    };
397
398
    if ($@) {
399
        warn "Error applying print notice charge for patron " . $patron->borrowernumber . ": $@";
400
    }
401
}
402
347
=head1 NAME
403
=head1 NAME
348
404
349
gather_print_notices - Print waiting print notices
405
gather_print_notices - Print waiting print notices
Lines 406-411 Several letter_code parameters can be given. Link Here
406
Repeatable.
462
Repeatable.
407
E-mail address to send generated files to.
463
E-mail address to send generated files to.
408
464
465
=item B<--skip-charges>
466
467
Skip applying charges for print notices, even if patron category has print notice charging enabled.
468
Useful for testing or administrative runs.
469
409
=item B<-h|--help>
470
=item B<-h|--help>
410
471
411
Print a brief help message
472
Print a brief help message
412
- 

Return to bug 4858