Lines 23-29
automatic_renewals.pl - cron script to renew loans
Link Here
|
23 |
|
23 |
|
24 |
=head1 SYNOPSIS |
24 |
=head1 SYNOPSIS |
25 |
|
25 |
|
26 |
./automatic_renewals.pl |
26 |
./automatic_renewals.pl [--send-notices] |
27 |
|
27 |
|
28 |
or, in crontab: |
28 |
or, in crontab: |
29 |
0 3 * * * automatic_renewals.pl |
29 |
0 3 * * * automatic_renewals.pl |
Lines 36-46
and the renewal isn't premature (No Renewal before) the issue is renewed.
Link Here
|
36 |
|
36 |
|
37 |
=head1 OPTIONS |
37 |
=head1 OPTIONS |
38 |
|
38 |
|
39 |
No options. |
39 |
=over |
|
|
40 |
|
41 |
=item B<--send-notices> |
42 |
|
43 |
Send AUTO_RENEWALS notices to patrons if the auto renewal has been done. |
44 |
|
45 |
Note that this option does not support digest yet. |
46 |
|
47 |
=back |
40 |
|
48 |
|
41 |
=cut |
49 |
=cut |
42 |
|
50 |
|
43 |
use Modern::Perl; |
51 |
use Modern::Perl; |
|
|
52 |
use Pod::Usage; |
53 |
use Getopt::Long; |
44 |
|
54 |
|
45 |
use C4::Circulation; |
55 |
use C4::Circulation; |
46 |
use C4::Context; |
56 |
use C4::Context; |
Lines 50-55
use Koha::Checkouts;
Link Here
|
50 |
use Koha::Libraries; |
60 |
use Koha::Libraries; |
51 |
use Koha::Patrons; |
61 |
use Koha::Patrons; |
52 |
|
62 |
|
|
|
63 |
my ( $help, $send_notices ); |
64 |
GetOptions( |
65 |
'h|help' => \$help, |
66 |
'send-notices' => \$send_notices, |
67 |
) || pod2usage(1); |
68 |
|
69 |
pod2usage(0) if $help; |
70 |
|
53 |
cronlogaction(); |
71 |
cronlogaction(); |
54 |
|
72 |
|
55 |
my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); |
73 |
my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); |
Lines 78-108
while ( my $auto_renew = $auto_renews->next ) {
Link Here
|
78 |
} |
96 |
} |
79 |
} |
97 |
} |
80 |
|
98 |
|
81 |
for my $borrowernumber ( keys %report ) { |
99 |
if ( $send_notices ) { |
82 |
my $patron = Koha::Patrons->find($borrowernumber); |
100 |
for my $borrowernumber ( keys %report ) { |
83 |
my @issues; |
101 |
my $patron = Koha::Patrons->find($borrowernumber); |
84 |
for my $issue ( @{ $report{$borrowernumber} } ) { |
102 |
my @issues; |
85 |
my $item = Koha::Items->find( $issue->itemnumber ); |
103 |
for my $issue ( @{ $report{$borrowernumber} } ) { |
86 |
my $letter = C4::Letters::GetPreparedLetter( |
104 |
my $item = Koha::Items->find( $issue->itemnumber ); |
87 |
module => 'circulation', |
105 |
my $letter = C4::Letters::GetPreparedLetter( |
88 |
letter_code => 'AUTO_RENEWALS', |
106 |
module => 'circulation', |
89 |
tables => { |
107 |
letter_code => 'AUTO_RENEWALS', |
90 |
borrowers => $patron->borrowernumber, |
108 |
tables => { |
91 |
issues => $issue->itemnumber, |
109 |
borrowers => $patron->borrowernumber, |
92 |
items => $issue->itemnumber, |
110 |
issues => $issue->itemnumber, |
93 |
biblio => $item->biblionumber, |
111 |
items => $issue->itemnumber, |
94 |
}, |
112 |
biblio => $item->biblionumber, |
95 |
); |
113 |
}, |
96 |
|
114 |
); |
97 |
my $library = Koha::Libraries->find( $patron->branchcode ); |
115 |
|
98 |
my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'); |
116 |
my $library = Koha::Libraries->find( $patron->branchcode ); |
99 |
|
117 |
my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'); |
100 |
C4::Letters::EnqueueLetter( |
118 |
|
101 |
{ letter => $letter, |
119 |
C4::Letters::EnqueueLetter( |
102 |
borrowernumber => $borrowernumber, |
120 |
{ letter => $letter, |
103 |
message_transport_type => 'email', |
121 |
borrowernumber => $borrowernumber, |
104 |
from_address => $admin_email_address, |
122 |
message_transport_type => 'email', |
105 |
} |
123 |
from_address => $admin_email_address, |
106 |
); |
124 |
} |
|
|
125 |
); |
126 |
} |
107 |
} |
127 |
} |
108 |
} |
128 |
} |
109 |
- |
|
|