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

(-)a/C4/Letters.pm (-45 / +17 lines)
Lines 62-119 C4::Letters - Give functions for Letters management Link Here
62
62
63
  Letters are managed through "alerts" sent by Koha on some events. All "alert" related functions are in this module too.
63
  Letters are managed through "alerts" sent by Koha on some events. All "alert" related functions are in this module too.
64
64
65
=head2 GetLetters([$category])
65
=head2 GetLetters([$module])
66
66
67
  $letters = &GetLetters($category);
67
  $letters = &GetLetters($module);
68
  returns informations about letters.
68
  returns informations about letters.
69
  if needed, $category filters for letters given category
69
  if needed, $module filters for letters given module
70
  Create a letter selector with the following code
71
72
=head3 in PERL SCRIPT
73
74
my $letters = GetLetters($cat);
75
my @letterloop;
76
foreach my $thisletter (keys %$letters) {
77
    my $selected = 1 if $thisletter eq $letter;
78
    my %row =(
79
        value => $thisletter,
80
        selected => $selected,
81
        lettername => $letters->{$thisletter},
82
    );
83
    push @letterloop, \%row;
84
}
85
$template->param(LETTERLOOP => \@letterloop);
86
87
=head3 in TEMPLATE
88
89
    <select name="letter">
90
        <option value="">Default</option>
91
    <!-- TMPL_LOOP name="LETTERLOOP" -->
92
        <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="lettername" --></option>
93
    <!-- /TMPL_LOOP -->
94
    </select>
95
70
96
=cut
71
=cut
97
72
98
sub GetLetters {
73
sub GetLetters {
74
    my ($filters) = @_;
75
    my $module    = $filters->{module};
76
    my $dbh       = C4::Context->dbh;
77
    my $letters   = $dbh->selectall_arrayref(
78
        q|
79
            SELECT module, code, branchcode, name
80
            FROM letter
81
            WHERE 1
82
        |
83
          . ( $module ? q| AND module = ?| : q|| )
84
          . q| GROUP BY code ORDER BY name|, { Slice => {} }
85
        , ( $module ? $module : () )
86
    );
99
87
100
    # returns a reference to a hash of references to ALL letters...
88
    return $letters;
101
    my ( $cat ) = @_;
102
    my %letters;
103
    my $dbh = C4::Context->dbh;
104
    my $sth;
105
    my $query = q{
106
        SELECT * FROM letter WHERE 1
107
    };
108
    $query .= q{ AND module = ? } if defined $cat;
109
    $query .= q{ GROUP BY code ORDER BY name};
110
    $sth = $dbh->prepare($query);
111
    $sth->execute((defined $cat ? $cat : ()));
112
113
    while ( my $letter = $sth->fetchrow_hashref ) {
114
        $letters{ $letter->{'code'} } = $letter->{'name'};
115
    }
116
    return \%letters;
117
}
89
}
118
90
119
# FIXME: using our here means that a Plack server will need to be
91
# FIXME: using our here means that a Plack server will need to be
(-)a/acqui/lateorders.pl (-6 / +2 lines)
Lines 159-175 foreach (@lateorders){ Link Here
159
	$total += $_->{subtotal};
159
	$total += $_->{subtotal};
160
}
160
}
161
161
162
my @letters;
162
my $letters = GetLetters({ module => "claimacquisition" });
163
my $letters=GetLetters("claimacquisition");
164
foreach (keys %$letters){
165
	push @letters, {code=>$_,name=>$letters->{$_}};
166
}
167
$template->param(letters=>\@letters) if (@letters);
168
163
169
$template->param(ERROR_LOOP => \@errors) if (@errors);
164
$template->param(ERROR_LOOP => \@errors) if (@errors);
170
$template->param(
165
$template->param(
171
	lateorders => \@lateorders,
166
	lateorders => \@lateorders,
172
	delay => $delay,
167
	delay => $delay,
168
    letters => $letters,
173
    estimateddeliverydatefrom => $estimateddeliverydatefrom,
169
    estimateddeliverydatefrom => $estimateddeliverydatefrom,
174
    estimateddeliverydateto   => $estimateddeliverydateto,
170
    estimateddeliverydateto   => $estimateddeliverydateto,
175
	total => $total,
171
	total => $total,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt (-3 / +3 lines)
Lines 177-188 Link Here
177
177
178
    <h1>Claims</h1>
178
    <h1>Claims</h1>
179
179
180
[% IF ( letter ) %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %] <div class="dialog alert">No missing issues found.</div>[% ELSE %]<div class="dialog message">Please choose a vendor.</div>[% END %][% END %][% END %]
180
[% IF letters %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %] <div class="dialog alert">No missing issues found.</div>[% ELSE %]<div class="dialog message">Please choose a vendor.</div>[% END %][% END %][% END %]
181
	
181
	
182
	     [% IF ( SHOWCONFIRMATION ) %]
182
	     [% IF ( SHOWCONFIRMATION ) %]
183
     <div class="dialog alert">Your notification has been sent.</div>
183
     <div class="dialog alert">Your notification has been sent.</div>
184
     [% END %]
184
     [% END %]
185
[% UNLESS ( letter ) %]<div class="dialog alert">No claims notice defined. <a href="/cgi-bin/koha/tools/letter.pl">Please define one</a>.</div>[% END %]
185
[% UNLESS letters %]<div class="dialog alert">No claims notice defined. <a href="/cgi-bin/koha/tools/letter.pl">Please define one</a>.</div>[% END %]
186
    <form id="claims" name="claims" action="claims.pl" method="post">
186
    <form id="claims" name="claims" action="claims.pl" method="post">
187
    <fieldset>
187
    <fieldset>
188
	    <label for="supplierid">Vendor: </label>
188
	    <label for="supplierid">Vendor: </label>
Lines 331-337 Link Here
331
            <span class="exportSelected"><a id="ExportSelected" href="/cgi-bin/koha/serials/claims.pl">Download selected claims</a></span>
331
            <span class="exportSelected"><a id="ExportSelected" href="/cgi-bin/koha/serials/claims.pl">Download selected claims</a></span>
332
        [% END %]
332
        [% END %]
333
333
334
[% IF ( letter ) %]
334
[% IF ( letters ) %]
335
        <fieldset class="action"> <label for="letter_code">Select notice:</label>
335
        <fieldset class="action"> <label for="letter_code">Select notice:</label>
336
            <select name="letter_code" id="letter_code">
336
            <select name="letter_code" id="letter_code">
337
                [% FOREACH letter IN letters %]
337
                [% FOREACH letter IN letters %]
(-)a/serials/claims.pl (-8 / +4 lines)
Lines 58-71 for my $s (@{$supplierlist} ) { Link Here
58
    }
58
    }
59
}
59
}
60
60
61
my $letters = GetLetters('claimissues');
61
my $letters = GetLetters({ module => 'claimissues' });
62
my @letters;
63
foreach (keys %{$letters}){
64
    push @letters ,{code=>$_,name=> $letters->{$_}};
65
}
66
62
67
my $letter=((scalar(@letters)>1) || ($letters[0]->{name}||$letters[0]->{code}));
63
my @missingissues;
68
my  @missingissues;
69
my @supplierinfo;
64
my @supplierinfo;
70
if ($supplierid) {
65
if ($supplierid) {
71
    @missingissues = GetLateOrMissingIssues($supplierid,$serialid,$order);
66
    @missingissues = GetLateOrMissingIssues($supplierid,$serialid,$order);
Lines 85-91 if($op && $op eq 'preview'){ Link Here
85
        ### $cntupdate SHOULD be equal to scalar(@$serialnums)
80
        ### $cntupdate SHOULD be equal to scalar(@$serialnums)
86
    }
81
    }
87
}
82
}
88
$template->param('letters'=>\@letters,'letter'=>$letter);
83
89
$template->param(
84
$template->param(
90
        order =>$order,
85
        order =>$order,
91
        suploop => $supplierlist,
86
        suploop => $supplierlist,
Lines 99-104 $template->param( Link Here
99
        supplierloop => \@supplierinfo,
94
        supplierloop => \@supplierinfo,
100
        branchloop   => $branchloop,
95
        branchloop   => $branchloop,
101
        csv_profiles => C4::Csv::GetCsvProfiles( "sql" ),
96
        csv_profiles => C4::Csv::GetCsvProfiles( "sql" ),
97
        letters => $letters,
102
        (uc(C4::Context->preference("marcflavour"))) => 1
98
        (uc(C4::Context->preference("marcflavour"))) => 1
103
        );
99
        );
104
output_html_with_http_headers $input, $cookie, $template->output;
100
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/subscription-add.pl (-16 / +22 lines)
Lines 88-94 if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') { Link Here
88
      if (!defined $subs->{letter}) {
88
      if (!defined $subs->{letter}) {
89
          $subs->{letter}= q{};
89
          $subs->{letter}= q{};
90
      }
90
      }
91
    letter_loop($subs->{'letter'}, $template);
92
    my $nextexpected = GetNextExpected($subscriptionid);
91
    my $nextexpected = GetNextExpected($subscriptionid);
93
    $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate} eq $firstissuedate ;
92
    $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate} eq $firstissuedate ;
94
    $subs->{nextacquidate} = $nextexpected->{planneddate}  if($op eq 'modify');
93
    $subs->{nextacquidate} = $nextexpected->{planneddate}  if($op eq 'modify');
Lines 123-128 if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') { Link Here
123
        my @fields_id = map { fieldid => $_ }, split '\|', $dont_copy_fields;
122
        my @fields_id = map { fieldid => $_ }, split '\|', $dont_copy_fields;
124
        $template->param( dont_export_field_loop => \@fields_id );
123
        $template->param( dont_export_field_loop => \@fields_id );
125
    }
124
    }
125
126
    my $letters = get_letter_loop( $subs->{letter} );
127
    $template->param( letterloop => $letters );
128
126
}
129
}
127
130
128
my $onlymine =
131
my $onlymine =
Lines 152-158 $template->param(branchloop => $branchloop, Link Here
152
);
155
);
153
# prepare template variables common to all $op conditions:
156
# prepare template variables common to all $op conditions:
154
if ($op!~/^mod/) {
157
if ($op!~/^mod/) {
155
    letter_loop(q{}, $template);
158
    my $letters = get_letter_loop();
159
    $template->param( letterloop => $letters );
156
}
160
}
157
161
158
if ($op eq 'addsubscription') {
162
if ($op eq 'addsubscription') {
Lines 172-178 if ($op eq 'addsubscription') { Link Here
172
        }
176
        }
173
    $template->param(subtype => \@sub_type_data);
177
    $template->param(subtype => \@sub_type_data);
174
178
175
    letter_loop( '', $template ) if ($op ne 'modsubscription' && $op ne 'dup' && $op ne 'modify');
179
    if ( $op ne 'modsubscription' && $op ne 'dup' && $op ne 'modify' ) {
180
        my $letters = get_letter_loop();
181
        $template->param( letterloop => $letters );
182
    }
176
183
177
    my $new_biblionumber = $query->param('biblionumber_for_new_subscription');
184
    my $new_biblionumber = $query->param('biblionumber_for_new_subscription');
178
    if (defined $new_biblionumber) {
185
    if (defined $new_biblionumber) {
Lines 225-243 if ($op eq 'addsubscription') { Link Here
225
    output_html_with_http_headers $query, $cookie, $template->output;
232
    output_html_with_http_headers $query, $cookie, $template->output;
226
}
233
}
227
234
228
sub letter_loop {
235
sub get_letter_loop {
229
    my ($selected_letter, $templte) = @_;
236
    my ($selected_lettercode) = @_;
230
    my $letters = GetLetters('serial');
237
    my $letters = GetLetters({ module => 'serial' });
231
    my $letterloop;
238
    return [
232
    foreach my $thisletter (keys %{$letters}) {
239
        map {
233
        push @{$letterloop}, {
240
            {
234
            value => $thisletter,
241
                value      => $_->{code},
235
            selected => $thisletter eq $selected_letter,
242
                lettername => $_->{name},
236
            lettername => $letters->{$thisletter},
243
                ( $_->{code} eq $selected_lettercode ? ( selected => 1 ) : () ),
237
        };
244
            }
238
    }
245
          } @$letters
239
    $templte->param(letterloop => $letterloop);
246
    ];
240
    return;
241
}
247
}
242
248
243
sub _get_sub_length {
249
sub _get_sub_length {
(-)a/t/Letters.t (-1 / +3 lines)
Lines 31-37 $dbh->{mock_add_resultset} = $mock_letters; Link Here
31
31
32
my $letters = C4::Letters::GetLetters();
32
my $letters = C4::Letters::GetLetters();
33
33
34
is( $letters->{ISBN}, 'book', 'HASH ref of ISBN is book' );
34
my ( $ISBN_letter ) = grep {$_->{code} eq 'ISBN'} @$letters;
35
is( $ISBN_letter->{name}, 'book', 'letter name for "ISBN" letter is book' );
36
is( scalar( @$letters ), 2, 'GetLetters returns the 2 inserted letters' );
35
37
36
# Regression test for bug 10843
38
# Regression test for bug 10843
37
# $dt->add takes a scalar, not undef
39
# $dt->add takes a scalar, not undef
(-)a/tools/overduerules.pl (-41 / +6 lines)
Lines 201-209 if ($op eq 'save') { Link Here
201
}
201
}
202
my $branchloop = GetBranchesLoop($branch);
202
my $branchloop = GetBranchesLoop($branch);
203
203
204
my $letters = GetLetters("circulation");
204
my $letters = GetLetters({ module => "circulation" });
205
206
my $countletters = keys %{$letters};
207
205
208
my @line_loop;
206
my @line_loop;
209
207
Lines 222-246 for my $data (@categories) { Link Here
222
            );
220
            );
223
            $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"};
221
            $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"};
224
            $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"};
222
            $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"};
225
            if ($countletters){
223
            $row{selected_lettercode} = $temphash{ $data->{categorycode} }->{"letter$i"};
226
                my @letterloop;
227
                foreach my $thisletter (sort { $letters->{$a} cmp $letters->{$b} } keys %$letters) {
228
                    my $selected;
229
                    if ( $temphash{$data->{categorycode}}->{"letter$i"} &&
230
                        $thisletter eq $temphash{$data->{'categorycode'}}->{"letter$i"}) {
231
                        $selected = 1;
232
                    }
233
                    my %letterrow =(value => $thisletter,
234
                                    selected => $selected,
235
                                    lettername => $letters->{$thisletter},
236
                                    );
237
                    push @letterloop, \%letterrow;
238
                }
239
                $row{letterloop}=\@letterloop;
240
            } else {
241
                $row{noletter}=1;
242
                $row{letter}=$temphash{$data->{'categorycode'}}->{"letter$i"};
243
            }
244
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
224
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
245
            my @mtts;
225
            my @mtts;
246
            for my $mtt ( @$message_transport_types ) {
226
            for my $mtt ( @$message_transport_types ) {
Lines 268-291 for my $data (@categories) { Link Here
268
                overduename => $data->{'categorycode'},
248
                overduename => $data->{'categorycode'},
269
                line        => $data->{'description'}
249
                line        => $data->{'description'}
270
            );
250
            );
271
            if ($countletters){
251
272
                my @letterloop;
252
            $row{selected_lettercode} = $dat->{"letter$i"};
273
                foreach my $thisletter (sort { $letters->{$a} cmp $letters->{$b} } keys %$letters) {
253
274
                    my $selected;
275
                    if ($dat->{"letter$i"} && $thisletter eq $dat->{"letter$i"}) {
276
                        $selected = 1;
277
                    }
278
                    my %letterrow =(value => $thisletter,
279
                                    selected => $selected,
280
                                    lettername => $letters->{$thisletter},
281
                                    );
282
                    push @letterloop, \%letterrow;
283
                }
284
                $row{letterloop}=\@letterloop;
285
            } else {
286
                $row{noletter}=1;
287
                if ($dat->{"letter$i"}){$row{letter}=$dat->{"letter$i"};}
288
            }
289
            if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
254
            if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
290
            if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
255
            if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
291
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
256
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
Lines 333-337 $template->param( Link Here
333
    branch => $branch,
298
    branch => $branch,
334
    tabs => \@tabs,
299
    tabs => \@tabs,
335
    message_transport_types => $message_transport_types,
300
    message_transport_types => $message_transport_types,
301
    letters => $letters,
336
);
302
);
337
output_html_with_http_headers $input, $cookie, $template->output;
303
output_html_with_http_headers $input, $cookie, $template->output;
338
- 

Return to bug 11742