Bug 30477: Add new UNIMARC installer translation files
[koha.git] / misc / devel / get_prepared_letter.pl
1 #!/usr/bin/perl
2
3 # Copyright 2020 BibLibre
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 =head1 NAME
20
21 get-prepared-letter.pl - preview letter content
22
23 =head1 SYNOPSIS
24
25 get-prepared-letter.pl --module MODULE --letter-code CODE [options]
26
27 =head1 OPTIONS
28
29 =over
30
31 =item B<--module MODULE>
32
33 The letter module (acquisition, catalogue, circulation, ...)
34
35 =item B<--letter-code CODE>
36
37 The letter code (DUE, PREDUE, ...)
38
39 =item B<--branchcode BRANCHCODE>
40
41 The letter branchcode
42
43 =item B<--message-transport-type TYPE>
44
45 The message transport type (email, print, ...)
46
47 =item B<--lang LANG>
48
49 The letter language (es-ES, fr-FR, ...)
50
51 =item B<--repeat REPEAT>
52
53 A JSON formatted string that will be used as repeat parameter. See
54 documentation of GetPreparedLetter for more informations.
55
56 =item B<--tables TABLES>
57
58 A JSON formatted string that will be used as tables parameter. See
59 documentation of GetPreparedLetter for more informations.
60
61 =item B<--loops LOOPS>
62
63 A JSON formatted string that will be used as loops parameter. See
64 documentation of GetPreparedLetter for more informations.
65
66 =back
67
68 =cut
69
70 use Modern::Perl;
71
72 use Getopt::Long qw( GetOptions );
73 use JSON qw( decode_json );
74 use Pod::Usage qw( pod2usage );
75
76 use C4::Letters qw( GetPreparedLetter );
77
78 my $help;
79 my ( $module, $letter_code, $branchcode, $message_transport_type, $lang,
80     $repeat, $tables, $loops );
81
82 GetOptions(
83     'help'                     => \$help,
84     'module=s'                 => \$module,
85     'letter-code=s'            => \$letter_code,
86     'branchcode=s'             => \$branchcode,
87     'message-transport-type=s' => \$message_transport_type,
88     'lang=s'                   => \$lang,
89     'repeat=s'                 => \$repeat,
90     'tables=s'                 => \$tables,
91     'loops=s'                  => \$loops,
92 ) or pod2usage( -exitval => 2, -verbose => 1 );
93
94 if ($help) {
95     pod2usage( -exitval => 0, -verbose => 1 );
96 }
97
98 $repeat = $repeat ? decode_json($repeat) : {};
99 $tables = $tables ? decode_json($tables) : {};
100 $loops  = $loops  ? decode_json($loops)  : {};
101
102 my $letter = C4::Letters::GetPreparedLetter(
103     module                 => $module,
104     letter_code            => $letter_code,
105     branchcode             => $branchcode,
106     message_transport_type => $message_transport_type,
107     lang                   => $lang,
108     repeat                 => $repeat,
109     tables                 => $tables,
110     loops                  => $loops,
111 );
112
113 print "Subject: " . $letter->{title} . "\n\n";
114 print $letter->{content} . "\n";