8 use C4::Budgets qw( GetBudget );
9 use C4::Members qw( GetMember );
10 use C4::Suggestions qw( GetUnprocessedSuggestions );
12 my ( $help, $verbose, $confirm, @days );
15 'v|verbose' => \$verbose,
17 'c|confirm' => \$confirm,
18 ) || pod2usage( verbose => 2 );
21 pod2usage( verbose => 2 );
25 pod2usage(q{At least one day parameter should be given});
30 say "Doing a dry run; no email will be sent.";
31 say "Run again with --confirm to send emails.";
32 $verbose = 1 unless $verbose;
35 for my $number_of_days (@days) {
36 say "Searching suggestions suggested $number_of_days days ago" if $verbose;
38 my $suggestions = C4::Suggestions::GetUnprocessedSuggestions($number_of_days);
40 say "No suggestion found" if $verbose and not @$suggestions;
42 for my $suggestion (@$suggestions) {
44 say "Suggestion $suggestion->{suggestionid} should be processed" if $verbose;
46 my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
47 my $patron = C4::Members::GetMember( borrowernumber => $budget->{budget_owner_id} );
49 C4::Members::GetNoticeEmailAddress( $budget->{budget_owner_id} );
50 my $library = C4::Branch::GetBranchDetail( $patron->{branchcode} );
51 my $admin_email_address = $library->{branchemail}
52 || C4::Context->preference('KohaAdminEmailAddress');
55 say "Patron $patron->{borrowernumber} is going to be notified" if $verbose;
56 my $letter = C4::Letters::GetPreparedLetter(
57 module => 'suggestions',
58 letter_code => 'TO_PROCESS',
59 branchcode => $patron->{branchcode},
61 suggestions => $suggestion->{suggestionid},
62 branches => $patron->{branchcode},
63 borrowers => $patron->{borrowernumber},
67 C4::Letters::EnqueueLetter(
70 borrowernumber => $patron->{borrowernumber},
71 message_transport_type => 'email',
72 from_address => $admin_email_address,
77 say "Patron $patron->{borrowernumber} does not have an email address" if $verbose;
85 notice_unprocessed_suggestions.pl - Generate notification for unprocessed suggestions.
87 The budget owner will be notified.
89 The letter template 'TO_PROCESS' will be used.
93 notice_unprocessed_suggestions.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--days=NUMBER_OF_DAYS]
101 Print a brief help message
103 =item B<-c|--confirm>
105 This flag must be provided in order for the script to actually
106 generate notices. If it is not supplied, the script will
107 only report on the patron it would have noticed.
111 This parameter is mandatory.
112 It must contain an integer representing the number of days elapsed since the last modification of suggestions to process.
114 =item B<-v|--verbose>
122 Jonathan Druart <jonathan.druart@biblibre.com>
126 Copyright 2014 BibLibre
130 This file is part of Koha.
132 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
133 Foundation; either version 3 of the License, or (at your option) any later version.
135 You should have received a copy of the GNU General Public License along
136 with Koha; if not, write to the Free Software Foundation, Inc.,
137 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.