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

(-)a/misc/cronjobs/gather_print_notices.pl (-13 / +32 lines)
Lines 21-28 use Getopt::Long; Link Here
21
use File::Basename qw( dirname );
21
use File::Basename qw( dirname );
22
use Koha::DateUtils;
22
use Koha::DateUtils;
23
23
24
my ( $stylesheet, $help, $split, $html, $csv, $ods, $delimiter, @letter_codes );
24
my (
25
25
    $stylesheet,
26
    $help,
27
    $split,
28
    $html,
29
    $csv,
30
    $ods,
31
    $delimiter,
32
    @letter_codes,
33
    $send,
34
);
35
36
$send = 1;
26
GetOptions(
37
GetOptions(
27
    'h|help'  => \$help,
38
    'h|help'  => \$help,
28
    's|split' => \$split,
39
    's|split' => \$split,
Lines 31-36 GetOptions( Link Here
31
    'ods'     => \$ods,
42
    'ods'     => \$ods,
32
    'd|delimiter:s' => \$delimiter,
43
    'd|delimiter:s' => \$delimiter,
33
    'letter_code:s' => \@letter_codes,
44
    'letter_code:s' => \@letter_codes,
45
    'send!'         => \$send,
34
) || pod2usage(1);
46
) || pod2usage(1);
35
47
36
pod2usage(0) if $help;
48
pod2usage(0) if $help;
Lines 72-78 my @all_messages = @{ GetPrintMessages() }; Link Here
72
    (
84
    (
73
        grep { /^$letter_code$/ } @letter_codes
85
        grep { /^$letter_code$/ } @letter_codes
74
    ) ? $_ : ()
86
    ) ? $_ : ()
75
} @all_messages;
87
} @all_messages if @letter_codes;
76
exit unless @all_messages;
88
exit unless @all_messages;
77
89
78
my ( $html_filenames, $csv_filenames, $ods_filenames );
90
my ( $html_filenames, $csv_filenames, $ods_filenames );
Lines 151-163 sub print_notices { Link Here
151
            });
163
            });
152
        }
164
        }
153
165
154
        foreach my $message ( @$branch_messages ) {
166
        if ( $send ) {
155
            C4::Letters::_set_message_status(
167
            foreach my $message ( @$branch_messages ) {
156
                {
168
                C4::Letters::_set_message_status(
157
                    message_id => $message->{'message_id'},
169
                    {
158
                    status => 'sent'
170
                        message_id => $message->{'message_id'},
159
                }
171
                        status => 'sent'
160
            );
172
                    }
173
                );
174
            }
161
        }
175
        }
162
        push @filenames, $filename;
176
        push @filenames, $filename;
163
    }
177
    }
Lines 227-233 sub generate_ods { Link Here
227
    my $table = $doc->getTable(0);
241
    my $table = $doc->getTable(0);
228
242
229
    my @headers;
243
    my @headers;
230
    my ( $nb_rows, $nb_cols ) = ( scalar(@$messages), 0 );
244
    my ( $nb_rows, $nb_cols, $i ) = ( scalar(@$messages), 0, 0 );
231
    foreach my $message ( @$messages ) {
245
    foreach my $message ( @$messages ) {
232
        my @lines = split /\n/, $message->{content};
246
        my @lines = split /\n/, $message->{content};
233
        chomp for @lines;
247
        chomp for @lines;
Lines 244-253 sub generate_ods { Link Here
244
                $doc->cellValue( $row, $j, Encode::encode( 'UTF8', $header ) );
258
                $doc->cellValue( $row, $j, Encode::encode( 'UTF8', $header ) );
245
                $j++;
259
                $j++;
246
            }
260
            }
261
            $i = 1;
247
        }
262
        }
248
263
249
        shift @lines; # remove headers
264
        shift @lines; # remove headers
250
        my $i = 1;
251
        for my $line ( @lines ) {
265
        for my $line ( @lines ) {
252
            my @row_data = split $delimiter, $line;
266
            my @row_data = split $delimiter, $line;
253
            my $row = $doc->getRow( $table, $i );
267
            my $row = $doc->getRow( $table, $i );
Lines 282-287 The generated filename will be holdnotices-TODAY.[csv|html|ods] or holdnotices-T Link Here
282
296
283
Define the output directory where the files will be generated.
297
Define the output directory where the files will be generated.
284
298
299
=item B<--send|--nosend>
300
301
After files have been generated, messages status is changed from 'pending' to
302
'sent'. This is the default action, without this parameter or with --send.
303
Using --nosend, mesages status aren't changed.
304
285
=item B<-s|--split>
305
=item B<-s|--split>
286
306
287
Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.[csv|html|ods]
307
Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.[csv|html|ods]
288
- 

Return to bug 11603