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 / +152 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->size . ' 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 ' . $auto_renew->{'itemnumber'} . ' 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' ) {
81
        my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
126
        my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
82
        $auto_renew->auto_renew_error(undef)->store;
127
        $auto_renew->auto_renew_error(undef)->store;
83
        push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew;
128
        push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $borrower_preferences->{'wants_digest'};
84
    } elsif ( $error eq 'too_many'
129
    } elsif ( $error eq 'too_many'
85
        or $error eq 'on_reserve'
130
        or $error eq 'on_reserve'
86
        or $error eq 'restriction'
131
        or $error eq 'restriction'
Lines 93-101 while ( my $auto_renew = $auto_renews->next ) { Link Here
93
        if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) {
138
        if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) {
94
            $auto_renew->auto_renew_error($error)->store;
139
            $auto_renew->auto_renew_error($error)->store;
95
            push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
140
            push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
96
              if $error ne 'auto_too_soon';    # Do not notify if it's too soon
141
              if $error ne 'auto_too_soon' && !$borrower_preferences->{'wants_digest'};    # Do not notify if it's too soon
97
        }
142
        }
98
    }
143
    }
144
    if ( $borrower_preferences->{'wants_digest'} ) {
145
        # cache this one to process after we've run through all of the items.
146
        if ($digest_per_branch) {
147
            $renew_digest->{ $auto_renew->{branchcode} }->{ $auto_renew->{borrowernumber} }->{success} ++ if $error == 'auto_renew';
148
            $renew_digest->{ $auto_renew->{branchcode} }->{ $auto_renew->{borrowernumber} }->{error}++ unless $error == 'auto_renew' || $error == 'auto_too_soon' ;
149
        } else {
150
            $renew_digest->{ $auto_renew->{borrowernumber} }->{success} ++ if $error == 'auto_renew';
151
            $renew_digest->{ $auto_renew->{borrowernumber} }->{error}++ unless $error == 'auto_renew' || $error == 'auto_too_soon' ;
152
        }
153
    }
154
99
}
155
}
100
156
101
if ( $send_notices ) {
157
if ( $send_notices ) {
Lines 127-130 if ( $send_notices ) { Link Here
127
            );
183
            );
128
        }
184
        }
129
    }
185
    }
186
187
    if ($digest_per_branch) {
188
        while (my ($branchcode, $digests) = each %$renew_digest) {
189
            send_digests({
190
                digests => $digests,
191
                branchcode => $branchcode,
192
                letter_code => 'AUTO_RENEWALS_DGST',
193
            });
194
        }
195
    } else {
196
        send_digests({
197
            digests => $renew_digest,
198
            letter_code => 'AUTO_RENEWALS_DGST',
199
        });
200
    }
130
}
201
}
131
- 
202
203
=head1 METHODS
204
205
=head2 send_digests
206
207
    send_digests({
208
        digests => ...,
209
        letter_code => ...,
210
    })
211
212
Enqueue digested letters.
213
214
Parameters:
215
216
=over 4
217
218
=item C<$digests>
219
220
Reference to the array of digested messages.
221
222
=item C<$letter_code>
223
224
String that denote the letter code.
225
226
=back
227
228
=cut
229
230
sub send_digests {
231
    my $params = shift;
232
233
    my $admin_email_address = C4::Context->preference('KohaAdminEmailAddress');
234
235
    PATRON: while ( my ( $borrowernumber, $digest ) = each %{$params->{digests}} ) {
236
        my $borrower_preferences =
237
            C4::Members::Messaging::GetMessagingPreferences(
238
                {
239
                    borrowernumber => $borrowernumber,
240
                    message_name   => 'auto_renewals'
241
                }
242
            );
243
244
        next PATRON unless $borrower_preferences; # how could this happen?
245
246
        my $patron = Koha::Patrons->find( $borrowernumber );
247
        my $library = Koha::Libraries->find( $params->{branchcode} );
248
        my $from_address = $library->{branchemail} || $admin_email_address;
249
250
        foreach my $transport ( keys %{ $borrower_preferences->{'transports'} } ) {
251
            my $letter = C4::Letters::GetPreparedLetter (
252
                module => 'circulation',
253
                letter_code => $params->{letter_code},
254
                branchcode => $params->{branchcode},
255
                lang => $patron->lang,
256
                substitute => {
257
                    error => $digest->{error},
258
                    success => $digest->{success},
259
                },
260
                tables      => {
261
                    borrowers => $patron->borrowernumber,
262
                },
263
                message_transport_type => $transport,
264
            ) || warn "no letter of type '$params->{letter_code}' found for borrowernumber $borrowernumber. Please see sample_notices.sql";
265
266
            next unless $letter;
267
268
            C4::Letters::EnqueueLetter({
269
                letter                 => $letter,
270
                borrowernumber         => $borrowernumber,
271
                from_address           => $from_address,
272
                message_transport_type => $transport
273
            });
274
        }
275
    }
276
}

Return to bug 18532