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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc (+1 lines)
Lines 20-25 Link Here
20
          [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled
20
          [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled
21
          [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in
21
          [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in
22
          [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout
22
          [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout
23
          [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewals
23
          [% ELSE %]Unknown [% END %]</td>
24
          [% ELSE %]Unknown [% END %]</td>
24
      [% IF ( messaging_preference.takes_days ) %]
25
      [% IF ( messaging_preference.takes_days ) %]
25
      <td>
26
      <td>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt (+1 lines)
Lines 51-56 Link Here
51
                                              [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled
51
                                              [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled
52
                                              [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in
52
                                              [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in
53
                                              [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout
53
                                              [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout
54
                                              [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewals
54
                                              [% ELSE %]Unknown [% END %]</td>
55
                                              [% ELSE %]Unknown [% END %]</td>
55
                                        [% IF ( messaging_preference.takes_days ) %]
56
                                        [% IF ( messaging_preference.takes_days ) %]
56
                                            <td><select class="input-mini" name="[% messaging_preference.message_attribute_id | html %]-DAYS">
57
                                            <td><select class="input-mini" name="[% messaging_preference.message_attribute_id | html %]-DAYS">
(-)a/misc/cronjobs/automatic_renewals.pl (-7 / +154 lines)
Lines 2-8 Link Here
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
5
# Copyright (C) 2014 Hochschule für Gesundheit (hsg), Germany
5
# Copyright (C) 2014 Hochschule für Gesundheit (hsg), Germany
6
#
6
#
7
# Koha is free software; you can redistribute it and/or modify it
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
8
# under the terms of the GNU General Public License as published by
Lines 42-48 and the renewal isn't premature (No Renewal before) the issue is renewed. Link Here
42
42
43
Send AUTO_RENEWALS notices to patrons if the auto renewal has been done.
43
Send AUTO_RENEWALS notices to patrons if the auto renewal has been done.
44
44
45
Note that this option does not support digest yet.
45
=item B<-v>
46
47
Verbose. Without this flag set, only fatal errors are reported.
48
49
=item B<--digest-per-branch>
50
51
Flag to indicate that generation of message digests should be
52
performed separately for each branch.
53
54
A patron could potentially have loans at several different branches
55
There is no natural branch to set as the sender on the aggregated
56
message in this situation so the default behavior is to use the
57
borrowers home branch.  This could surprise to the borrower when
58
message sender is a library where they have not borrowed anything.
59
60
Enabling this flag ensures that the issuing library is the sender of
61
the digested message.  It has no effect unless the borrower has
62
chosen 'Digests only' on the advance messages.
46
63
47
=back
64
=back
48
65
Lines 62-86 use Koha::Libraries; Link Here
62
use Koha::Patrons;
79
use Koha::Patrons;
63
80
64
my ( $help, $send_notices );
81
my ( $help, $send_notices );
82
my $verbose     = 0;        # -v: verbose
83
my $digest_per_branch = 0;  # -digest-per-branch: Prepare and send digests per branch
65
GetOptions(
84
GetOptions(
66
    'h|help' => \$help,
85
    'h|help'        => \$help,
67
    'send-notices' => \$send_notices,
86
    'send-notices'  => \$send_notices,
87
    'v'             => \$verbose,
88
    'digest-per-branch' => \$digest_per_branch,
89
68
) || pod2usage(1);
90
) || pod2usage(1);
69
91
70
pod2usage(0) if $help;
92
pod2usage(0) if $help;
93
94
# Since advance notice options are not visible in the web-interface
95
# unless EnhancedMessagingPreferences is on, let the user know that
96
# this script probably isn't going to do much
97
if ( ! C4::Context->preference('EnhancedMessagingPreferences') ) {
98
    warn <<'END_WARN';
99
100
The "EnhancedMessagingPreferences" syspref is off.
101
Therefore, it is unlikely that this script will actually produce any messages to be sent.
102
To change this, edit the "EnhancedMessagingPreferences" syspref.
103
104
END_WARN
105
}
106
71
cronlogaction();
107
cronlogaction();
72
108
109
warn 'getting auto renewals' if $verbose;
73
my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 });
110
my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 });
111
warn 'found ' . $auto_renews->count . ' auto renewals' if $verbose;
74
112
113
my $renew_digest = {};
75
my %report;
114
my %report;
76
while ( my $auto_renew = $auto_renews->next ) {
115
while ( my $auto_renew = $auto_renews->next ) {
116
    warn 'examining item "' . $auto_renew->itemnumber . '" to auto renew' if $verbose;
117
118
    my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $auto_renew->borrowernumber,
119
                                                                                   message_name   => 'auto_renewals' } );
120
121
    next unless $borrower_preferences;
77
122
78
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
123
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
79
    my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber );
124
    my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber );
80
    if ( $error eq 'auto_renew' ) {
125
    if ( $error eq 'auto_renew' ) {
126
        warn "item renewed" if $verbose;
81
        my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
127
        my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
82
        $auto_renew->auto_renew_error(undef)->store;
128
        $auto_renew->auto_renew_error(undef)->store;
83
        push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew;
129
        push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $borrower_preferences->{'wants_digest'};
84
    } elsif ( $error eq 'too_many'
130
    } elsif ( $error eq 'too_many'
85
        or $error eq 'on_reserve'
131
        or $error eq 'on_reserve'
86
        or $error eq 'restriction'
132
        or $error eq 'restriction'
Lines 90-101 while ( my $auto_renew = $auto_renews->next ) { Link Here
90
        or $error eq 'auto_too_much_oweing'
136
        or $error eq 'auto_too_much_oweing'
91
        or $error eq 'auto_too_soon'
137
        or $error eq 'auto_too_soon'
92
        or $error eq 'item_denied_renewal' ) {
138
        or $error eq 'item_denied_renewal' ) {
139
            warn "there was an error: $error" if $verbose;
93
        if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) {
140
        if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) {
94
            $auto_renew->auto_renew_error($error)->store;
141
            $auto_renew->auto_renew_error($error)->store;
95
            push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
142
            push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
96
              if $error ne 'auto_too_soon';    # Do not notify if it's too soon
143
              if $error ne 'auto_too_soon' && !$borrower_preferences->{'wants_digest'};    # Do not notify if it's too soon
97
        }
144
        }
98
    }
145
    }
146
    if ( $borrower_preferences->{'wants_digest'} ) {
147
        # cache this one to process after we've run through all of the items.
148
        if ($digest_per_branch) {
149
            $renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{success} ++ if $error eq 'auto_renew';
150
            $renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{error}++ unless $error eq 'auto_renew' || $error == 'auto_too_soon' ;
151
        } else {
152
            $renew_digest->{ $auto_renew->borrowernumber }->{success} ++ if $error eq 'auto_renew';
153
            $renew_digest->{ $auto_renew->borrowernumber }->{error}++ unless $error eq 'auto_renew' || $error eq 'auto_too_soon' ;
154
        }
155
    }
156
99
}
157
}
100
158
101
if ( $send_notices ) {
159
if ( $send_notices ) {
Lines 127-130 if ( $send_notices ) { Link Here
127
            );
185
            );
128
        }
186
        }
129
    }
187
    }
188
189
    if ($digest_per_branch) {
190
        while (my ($branchcode, $digests) = each %$renew_digest) {
191
            send_digests({
192
                digests => $digests,
193
                branchcode => $branchcode,
194
                letter_code => 'AUTO_RENEWALS_DGST',
195
            });
196
        }
197
    } else {
198
        send_digests({
199
            digests => $renew_digest,
200
            letter_code => 'AUTO_RENEWALS_DGST',
201
        });
202
    }
130
}
203
}
131
- 
204
205
=head1 METHODS
206
207
=head2 send_digests
208
209
    send_digests({
210
        digests => ...,
211
        letter_code => ...,
212
    })
213
214
Enqueue digested letters.
215
216
Parameters:
217
218
=over 4
219
220
=item C<$digests>
221
222
Reference to the array of digested messages.
223
224
=item C<$letter_code>
225
226
String that denote the letter code.
227
228
=back
229
230
=cut
231
232
sub send_digests {
233
    my $params = shift;
234
235
    my $admin_email_address = C4::Context->preference('KohaAdminEmailAddress');
236
237
    PATRON: while ( my ( $borrowernumber, $digest ) = each %{$params->{digests}} ) {
238
        my $borrower_preferences =
239
            C4::Members::Messaging::GetMessagingPreferences(
240
                {
241
                    borrowernumber => $borrowernumber,
242
                    message_name   => 'auto_renewals'
243
                }
244
            );
245
246
        next PATRON unless $borrower_preferences; # how could this happen?
247
248
        my $patron = Koha::Patrons->find( $borrowernumber );
249
        my $library = Koha::Libraries->find( $params->{branchcode} );
250
        my $from_address = $library->{branchemail} || $admin_email_address;
251
252
        foreach my $transport ( keys %{ $borrower_preferences->{'transports'} } ) {
253
            my $letter = C4::Letters::GetPreparedLetter (
254
                module => 'circulation',
255
                letter_code => $params->{letter_code},
256
                branchcode => $params->{branchcode},
257
                lang => $patron->lang,
258
                substitute => {
259
                    error => $digest->{error}||0,
260
                    success => $digest->{success}||0,
261
                },
262
                tables      => {
263
                    borrowers => $patron->borrowernumber,
264
                },
265
                message_transport_type => $transport,
266
            ) || warn "no letter of type '$params->{letter_code}' found for borrowernumber $borrowernumber. Please see sample_notices.sql";
267
268
            next unless $letter;
269
270
            C4::Letters::EnqueueLetter({
271
                letter                 => $letter,
272
                borrowernumber         => $borrowernumber,
273
                from_address           => $from_address,
274
                message_transport_type => $transport
275
            });
276
        }
277
    }
278
}

Return to bug 18532