Bug 23148: Fix bridge image paths in de-DE installer files
[koha.git] / misc / cronjobs / notice_unprocessed_suggestions.pl
blob055315c9dd7887baeccebf05c107b5e381f269aa
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Pod::Usage;
6 use Getopt::Long;
8 use Koha::Script -cron;
9 use C4::Budgets qw( GetBudget );
10 use C4::Suggestions qw( GetUnprocessedSuggestions );
11 use Koha::Libraries;
12 use Koha::Patrons;
14 my ( $help, $verbose, $confirm, @days );
15 GetOptions(
16 'h|help' => \$help,
17 'v|verbose' => \$verbose,
18 'days:s' => \@days,
19 'c|confirm' => \$confirm,
20 ) || pod2usage( verbose => 2 );
22 if ($help) {
23 pod2usage( verbose => 2 );
26 unless (@days) {
27 pod2usage(q{At least one day parameter should be given});
28 exit;
31 unless ($confirm) {
32 say "Doing a dry run; no email will be sent.";
33 say "Run again with --confirm to send emails.";
34 $verbose = 1 unless $verbose;
37 for my $number_of_days (@days) {
38 say "Searching suggestions suggested $number_of_days days ago" if $verbose;
40 my $suggestions = C4::Suggestions::GetUnprocessedSuggestions($number_of_days);
42 say "No suggestion found" if $verbose and not @$suggestions;
44 for my $suggestion (@$suggestions) {
46 say "Suggestion $suggestion->{suggestionid} should be processed" if $verbose;
48 my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
49 my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
50 my $email_address = $patron->notice_email_address;
51 my $library = $patron->library;
52 my $admin_email_address = $library->branchemail
53 || C4::Context->preference('KohaAdminEmailAddress');
55 if ($email_address) {
56 say "Patron " . $patron->borrowernumber . " is going to be notified" if $verbose;
57 my $letter = C4::Letters::GetPreparedLetter(
58 module => 'suggestions',
59 letter_code => 'TO_PROCESS',
60 branchcode => $patron->branchcode,
61 lang => $patron->lang,
62 tables => {
63 suggestions => $suggestion->{suggestionid},
64 branches => $patron->branchcode,
65 borrowers => $patron->borrowernumber,
68 if ( $confirm ) {
69 C4::Letters::EnqueueLetter(
71 letter => $letter,
72 borrowernumber => $patron->borrowernumber,
73 message_transport_type => 'email',
74 from_address => $admin_email_address,
78 } else {
79 say "Patron " . $patron->borrowernumber . " does not have an email address" if $verbose;
85 =head1 NAME
87 notice_unprocessed_suggestions.pl - Generate notification for unprocessed suggestions.
89 The budget owner will be notified.
91 The letter template 'TO_PROCESS' will be used.
93 =head1 SYNOPSIS
95 notice_unprocessed_suggestions.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--days=NUMBER_OF_DAYS]
97 =head1 OPTIONS
99 =over
101 =item B<-h|--help>
103 Print a brief help message
105 =item B<-c|--confirm>
107 This flag must be provided in order for the script to actually
108 generate notices. If it is not supplied, the script will
109 only report on the patron it would have noticed.
111 =item B<--days>
113 This parameter is mandatory.
114 It must contain an integer representing the number of days elapsed since the last modification of suggestions to process.
116 =item B<-v|--verbose>
118 Verbose mode.
120 =back
122 =head1 AUTHOR
124 Jonathan Druart <jonathan.druart@biblibre.com>
126 =head1 COPYRIGHT
128 Copyright 2014 BibLibre
130 =head1 LICENSE
132 This file is part of Koha.
134 # Koha is free software; you can redistribute it and/or modify it
135 # under the terms of the GNU General Public License as published by
136 # the Free Software Foundation; either version 3 of the License, or
137 # (at your option) any later version.
139 # Koha is distributed in the hope that it will be useful, but
140 # WITHOUT ANY WARRANTY; without even the implied warranty of
141 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142 # GNU General Public License for more details.
144 # You should have received a copy of the GNU General Public License
145 # along with Koha; if not, see <http://www.gnu.org/licenses>.
147 =cut