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

(-)a/misc/cronjobs/notice_unprocessed_suggestions.pl (-1 / +135 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Pod::Usage;
6
use Getopt::Long;
7
8
use C4::Budgets qw( GetBudget );
9
use C4::Members qw( GetMember );
10
use C4::Suggestions qw( GetUnprocessedSuggestions );
11
12
my ( $help, $verbose, $confirm, @days );
13
GetOptions(
14
    'h|help'    => \$help,
15
    'v|verbose' => \$verbose,
16
    'days:s'    => \@days,
17
    'c|confirm' => \$confirm,
18
) || pod2usage(1);
19
20
if ($help) {
21
    pod2usage(1);
22
}
23
24
unless (@days) {
25
    pod2usage(q{At least one day should be given});
26
    exit;
27
}
28
29
unless ($confirm) {
30
    say "Doing a dry run; no email will be sent.";
31
    say "Run again with --confirm to sent emails.";
32
}
33
34
for my $number_of_days (@days) {
35
    say "Searching suggestions suggested $number_of_days ago" if $verbose;
36
37
    my $suggestions = C4::Suggestions::GetUnprocessedSuggestions($number_of_days);
38
39
    say "No suggestion found" if $verbose and not @$suggestions;
40
41
    for my $suggestion (@$suggestions) {
42
43
        say "Suggestion $suggestion->{suggestionid} should be processed" if $verbose;
44
45
        my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
46
        my $patron = C4::Members::GetMember( borrowernumber => $budget->{budget_owner_id} );
47
        my $email_address =
48
          C4::Members::GetNoticeEmailAddress( $budget->{budget_owner_id} );
49
        my $library = C4::Branch::GetBranchDetail( $patron->{branchcode} );
50
        my $admin_email_address = $library->{branchemail}
51
          || C4::Context->preference('KohaAdminEmailAddress');
52
53
        if ($email_address) {
54
            say "Patron $patron->{borrowernumber} is going to be notified" if $verbose;
55
            my $letter = C4::Letters::GetPreparedLetter(
56
                module      => 'suggestions',
57
                letter_code => 'TO_PROCESS',
58
                branchcode  => $patron->{branchcode},
59
                tables      => {
60
                    suggestions => $suggestion->{suggestionid},
61
                    branches    => $patron->{branchcode},
62
                },
63
            );
64
            if ( $confirm ) {
65
                C4::Letters::EnqueueLetter(
66
                    {
67
                        letter                 => $letter,
68
                        borrowernumber         => $patron->{borrowernumber},
69
                        message_transport_type => 'email',
70
                        from_address           => $admin_email_address,
71
                    }
72
                );
73
            }
74
        } else {
75
            say "Patron $patron->{borrowernumber} does not have an email address" if $verbose;
76
        }
77
    }
78
79
}
80
81
=head1 NAME
82
83
notice_unprocessed_suggestions.pl - Generate notification for unprocessed suggestions.
84
85
The budget owner will be notified.
86
87
=head1 SYNOPSIS
88
89
notice_unprocessed_suggestions.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--days=NUMBER_OF_DAYS]
90
91
=head1 OPTIONS
92
93
=over
94
95
=item B<-h|--help>
96
97
Print a brief help message
98
99
=item B<-c|--confirm>
100
101
This flag must be provided in order for the script to actually
102
generate notices.  If it is not supplied, the script will
103
only report on the patron it would have noticed.
104
105
=item B<--days>
106
107
This parameter is mandatory.
108
It must contain an integer representing the number of days elapsed since the last modification of suggestions to process.
109
110
=item B<-v|--verbose>
111
112
Verbose mode.
113
114
=back
115
116
=head1 AUTHOR
117
118
Jonathan Druart <jonathan.druart@biblibre.com>
119
120
=head1 COPYRIGHT
121
122
Copyright 2014 BibLibre
123
124
=head1 LICENSE
125
126
This file is part of Koha.
127
128
Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
129
Foundation; either version 3 of the License, or (at your option) any later version.
130
131
You should have received a copy of the GNU General Public License along
132
with Koha; if not, write to the Free Software Foundation, Inc.,
133
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
134
135
=cut

Return to bug 13014