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

(-)a/admin/clone-rules.pl (-102 lines)
Lines 1-102 Link Here
1
#!/usr/bin/perl
2
# vim: et ts=4 sw=4
3
# Copyright BibLibre 
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
21
# This script clones issuing rules from a library to another
22
# parameters : 
23
#  - frombranch : the branch we want to clone issuing rules from
24
#  - tobranch   : the branch we want to clone issuing rules to
25
#
26
# The script can be called with one of the parameters, both or none
27
28
use strict;
29
#use warnings; FIXME - Bug 2505
30
use CGI qw ( -utf8 );
31
use C4::Context;
32
use C4::Output;
33
use C4::Auth;
34
use C4::Koha;
35
use C4::Debug;
36
37
my $input = new CGI;
38
my $dbh = C4::Context->dbh;
39
40
my ($template, $loggedinuser, $cookie)
41
    = get_template_and_user({template_name => "admin/clone-rules.tt",
42
                            query => $input,
43
                            type => "intranet",
44
                            authnotrequired => 0,
45
                            flagsrequired => {parameters => 'parameters_remaining_permissions'},
46
                            debug => 1,
47
                            });
48
49
my $frombranch = $input->param("frombranch");
50
my $tobranch   = $input->param("tobranch");
51
52
$template->param(frombranch     => $frombranch)                if ($frombranch);
53
$template->param(tobranch       => $tobranch)                  if ($tobranch);
54
55
if ($frombranch && $tobranch) {
56
57
    my $error;	
58
59
    # First, we create a temporary table with the rules we want to clone
60
    my $query = "CREATE TEMPORARY TABLE tmpissuingrules ENGINE=memory SELECT * FROM issuingrules WHERE branchcode=?";
61
    my $sth = $dbh->prepare($query);
62
    my $res = $sth->execute($frombranch);
63
    $error = 1 unless ($res);
64
65
    if (!$error) {
66
	# We modify these rules according to the new branchcode
67
	$query = "UPDATE tmpissuingrules SET branchcode=? WHERE branchcode=?";
68
	$sth = $dbh->prepare($query);
69
	$res = $sth->execute($tobranch, $frombranch);
70
	$error = 1 unless ($res);
71
    }
72
73
    if (!$error) {
74
	# We delete the rules for the existing branchode
75
	$query = "DELETE FROM issuingrules WHERE branchcode=?";
76
	$sth = $dbh->prepare($query);
77
	$res = $sth->execute($tobranch);
78
	$error = 1 unless ($res);
79
    }
80
81
82
    if (!$error) {
83
	# We insert the new rules from our temporary table
84
	$query = "INSERT INTO issuingrules SELECT * FROM tmpissuingrules WHERE branchcode=?";
85
	$sth = $dbh->prepare($query);
86
	$res = $sth->execute($tobranch);
87
	$error = 1 unless ($res);
88
    }
89
90
    # Finally, we delete our temporary table
91
    $query = "DROP TABLE tmpissuingrules";
92
    $sth = $dbh->prepare($query);
93
    $res = $sth->execute();
94
95
    $template->param(result => "1");
96
    $template->param(error  => $error);
97
}
98
99
100
101
output_html_with_http_headers $input, $cookie, $template->output;
102
(-)a/admin/smart-rules.pl (-602 lines)
Lines 1-602 Link Here
1
#!/usr/bin/perl
2
# Copyright 2000-2002 Katipo Communications
3
# copyright 2010 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use strict;
21
use warnings;
22
use CGI qw ( -utf8 );
23
use C4::Context;
24
use C4::Output;
25
use C4::Auth;
26
use C4::Koha;
27
use C4::Debug;
28
use Koha::DateUtils;
29
use Koha::Database;
30
use Koha::Logger;
31
use Koha::RefundLostItemFeeRules;
32
use Koha::Libraries;
33
use Koha::CirculationRules;
34
use Koha::Patron::Categories;
35
use Koha::Patrons;
36
37
my $input = CGI->new;
38
my $dbh = C4::Context->dbh;
39
40
# my $flagsrequired;
41
# $flagsrequired->{circulation}=1;
42
my ($template, $loggedinuser, $cookie)
43
    = get_template_and_user({template_name => "admin/smart-rules.tt",
44
                            query => $input,
45
                            type => "intranet",
46
                            authnotrequired => 0,
47
                            flagsrequired => {parameters => 'manage_circ_rules'},
48
                            debug => 1,
49
                            });
50
51
my $type=$input->param('type');
52
53
my $branch = $input->param('branch');
54
unless ( $branch ) {
55
    if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) {
56
        $branch = Koha::Libraries->search->count() == 1 ? undef : C4::Context::mybranch();
57
    }
58
    else {
59
        $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
60
    }
61
}
62
63
my $uid = Koha::Patrons->find( $loggedinuser )->userid;
64
my $restricted_to_own_library = $uid && haspermission( $uid, { parameters => 'manage_circ_rules_restricted' }, { no_inherit => 1 } );
65
$template->param( restricted_to_own_library => $restricted_to_own_library );
66
$branch = C4::Context::mybranch() if $restricted_to_own_library;
67
68
$branch = '*' if $branch eq 'NO_LIBRARY_SET';
69
70
my $op = $input->param('op') || q{};
71
my $language = C4::Languages::getlanguage();
72
73
if ($op eq 'delete') {
74
    my $itemtype     = $input->param('itemtype');
75
    my $categorycode = $input->param('categorycode');
76
    $debug and warn "deleting $1 $2 $branch";
77
78
    Koha::CirculationRules->set_rules(
79
        {
80
            categorycode => $categorycode eq '*' ? undef : $categorycode,
81
            branchcode   => $branch eq '*' ? undef : $branch,
82
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
83
            rules        => {
84
                restrictedtype                   => undef,
85
                rentaldiscount                   => undef,
86
                fine                             => undef,
87
                finedays                         => undef,
88
                maxsuspensiondays                => undef,
89
                firstremind                      => undef,
90
                chargeperiod                     => undef,
91
                chargeperiod_charge_at           => undef,
92
                accountsent                      => undef,
93
                issuelength                      => undef,
94
                lengthunit                       => undef,
95
                hardduedate                      => undef,
96
                hardduedatecompare               => undef,
97
                renewalsallowed                  => undef,
98
                renewalperiod                    => undef,
99
                norenewalbefore                  => undef,
100
                auto_renew                       => undef,
101
                no_auto_renewal_after            => undef,
102
                no_auto_renewal_after_hard_limit => undef,
103
                reservesallowed                  => undef,
104
                holds_per_record                 => undef,
105
                overduefinescap                  => undef,
106
                cap_fine_to_replacement_price    => undef,
107
                onshelfholds                     => undef,
108
                opacitemholds                    => undef,
109
                article_requests                 => undef,
110
            }
111
        }
112
    );
113
}
114
elsif ($op eq 'delete-branch-cat') {
115
    my $categorycode  = $input->param('categorycode');
116
    if ($branch eq "*") {
117
        if ($categorycode eq "*") {
118
            Koha::CirculationRules->set_rules(
119
                {
120
                    branchcode   => undef,
121
                    categorycode => undef,
122
                    rules        => {
123
                        patron_maxissueqty             => undef,
124
                        patron_maxonsiteissueqty       => undef,
125
                    }
126
                }
127
            );
128
            Koha::CirculationRules->set_rules(
129
                {
130
                    branchcode   => undef,
131
                    itemtype     => undef,
132
                    rules        => {
133
                        holdallowed             => undef,
134
                        hold_fulfillment_policy => undef,
135
                        returnbranch            => undef,
136
                    }
137
                }
138
            );
139
        } else {
140
            Koha::CirculationRules->set_rules(
141
                {
142
                    categorycode => $categorycode,
143
                    branchcode   => undef,
144
                    rules        => {
145
                        max_holds         => undef,
146
                        patron_maxissueqty       => undef,
147
                        patron_maxonsiteissueqty => undef,
148
                    }
149
                }
150
            );
151
        }
152
    } elsif ($categorycode eq "*") {
153
        Koha::CirculationRules->set_rules(
154
            {
155
                branchcode   => $branch,
156
                categorycode => undef,
157
                rules        => {
158
                    patron_maxissueqty       => undef,
159
                    patron_maxonsiteissueqty => undef,
160
                }
161
            }
162
        );
163
        Koha::CirculationRules->set_rules(
164
            {
165
                branchcode   => $branch,
166
                rules        => {
167
                    holdallowed             => undef,
168
                    hold_fulfillment_policy => undef,
169
                    returnbranch            => undef,
170
                }
171
            }
172
        );
173
    } else {
174
        Koha::CirculationRules->set_rules(
175
            {
176
                categorycode => $categorycode,
177
                branchcode   => $branch,
178
                rules        => {
179
                    max_holds         => undef,
180
                    patron_maxissueqty       => undef,
181
                    patron_maxonsiteissueqty => undef,
182
                }
183
            }
184
        );
185
    }
186
}
187
elsif ($op eq 'delete-branch-item') {
188
    my $itemtype  = $input->param('itemtype');
189
    if ($branch eq "*") {
190
        if ($itemtype eq "*") {
191
            Koha::CirculationRules->set_rules(
192
                {
193
                    branchcode   => undef,
194
                    itemtype     => undef,
195
                    rules        => {
196
                        holdallowed             => undef,
197
                        hold_fulfillment_policy => undef,
198
                        returnbranch            => undef,
199
                    }
200
                }
201
            );
202
        } else {
203
            Koha::CirculationRules->set_rules(
204
                {
205
                    branchcode   => undef,
206
                    itemtype     => $itemtype,
207
                    rules        => {
208
                        holdallowed             => undef,
209
                        hold_fulfillment_policy => undef,
210
                        returnbranch            => undef,
211
                    }
212
                }
213
            );
214
        }
215
    } elsif ($itemtype eq "*") {
216
        Koha::CirculationRules->set_rules(
217
            {
218
                branchcode   => $branch,
219
                itemtype     => undef,
220
                rules        => {
221
                    holdallowed             => undef,
222
                    hold_fulfillment_policy => undef,
223
                    returnbranch            => undef,
224
                }
225
            }
226
        );
227
    } else {
228
        Koha::CirculationRules->set_rules(
229
            {
230
                branchcode   => $branch,
231
                itemtype     => $itemtype,
232
                rules        => {
233
                    holdallowed             => undef,
234
                    hold_fulfillment_policy => undef,
235
                    returnbranch            => undef,
236
                }
237
            }
238
        );
239
    }
240
}
241
# save the values entered
242
elsif ($op eq 'add') {
243
    my $br = $branch; # branch
244
    my $bor  = $input->param('categorycode'); # borrower category
245
    my $itemtype  = $input->param('itemtype');     # item type
246
    my $fine = $input->param('fine');
247
    my $finedays     = $input->param('finedays');
248
    my $maxsuspensiondays = $input->param('maxsuspensiondays');
249
    $maxsuspensiondays = '' if $maxsuspensiondays eq q||;
250
    my $firstremind  = $input->param('firstremind');
251
    my $chargeperiod = $input->param('chargeperiod');
252
    my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
253
    my $maxissueqty  = $input->param('maxissueqty');
254
    my $maxonsiteissueqty  = $input->param('maxonsiteissueqty');
255
    my $renewalsallowed  = $input->param('renewalsallowed');
256
    my $renewalperiod    = $input->param('renewalperiod');
257
    my $norenewalbefore  = $input->param('norenewalbefore');
258
    $norenewalbefore = '' if $norenewalbefore =~ /^\s*$/;
259
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
260
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
261
    $no_auto_renewal_after = '' if $no_auto_renewal_after =~ /^\s*$/;
262
    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || '';
263
    $no_auto_renewal_after_hard_limit = eval { dt_from_string( $input->param('no_auto_renewal_after_hard_limit') ) } if ( $no_auto_renewal_after_hard_limit );
264
    $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit );
265
    my $reservesallowed  = $input->param('reservesallowed');
266
    my $holds_per_record  = $input->param('holds_per_record');
267
    my $onshelfholds     = $input->param('onshelfholds') || 0;
268
    $maxissueqty =~ s/\s//g;
269
    $maxissueqty = '' if $maxissueqty !~ /^\d+/;
270
    $maxonsiteissueqty =~ s/\s//g;
271
    $maxonsiteissueqty = '' if $maxonsiteissueqty !~ /^\d+/;
272
    my $issuelength  = $input->param('issuelength');
273
    $issuelength = $issuelength eq q{} ? undef : $issuelength;
274
    my $lengthunit  = $input->param('lengthunit');
275
    my $hardduedate = $input->param('hardduedate') || undef;
276
    $hardduedate = eval { dt_from_string( $input->param('hardduedate') ) } if ( $hardduedate );
277
    $hardduedate = output_pref( { dt => $hardduedate, dateonly => 1, dateformat => 'iso' } ) if ( $hardduedate );
278
    my $hardduedatecompare = $input->param('hardduedatecompare');
279
    my $rentaldiscount = $input->param('rentaldiscount');
280
    my $opacitemholds = $input->param('opacitemholds') || 0;
281
    my $article_requests = $input->param('article_requests') || 'no';
282
    my $overduefinescap = $input->param('overduefinescap') || '';
283
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
284
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
285
286
    my $params = {
287
        fine                          => $fine,
288
        finedays                      => $finedays,
289
        maxsuspensiondays             => $maxsuspensiondays,
290
        firstremind                   => $firstremind,
291
        chargeperiod                  => $chargeperiod,
292
        chargeperiod_charge_at        => $chargeperiod_charge_at,
293
        renewalsallowed               => $renewalsallowed,
294
        renewalperiod                 => $renewalperiod,
295
        norenewalbefore               => $norenewalbefore,
296
        auto_renew                    => $auto_renew,
297
        no_auto_renewal_after         => $no_auto_renewal_after,
298
        no_auto_renewal_after_hard_limit => $no_auto_renewal_after_hard_limit,
299
        reservesallowed               => $reservesallowed,
300
        holds_per_record              => $holds_per_record,
301
        issuelength                   => $issuelength,
302
        lengthunit                    => $lengthunit,
303
        hardduedate                   => $hardduedate,
304
        hardduedatecompare            => $hardduedatecompare,
305
        rentaldiscount                => $rentaldiscount,
306
        onshelfholds                  => $onshelfholds,
307
        opacitemholds                 => $opacitemholds,
308
        overduefinescap               => $overduefinescap,
309
        cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
310
        article_requests              => $article_requests,
311
        maxissueqty                   => $maxissueqty,
312
        maxonsiteissueqty             => $maxonsiteissueqty,
313
    };
314
315
    Koha::CirculationRules->set_rules(
316
        {
317
            categorycode => $bor eq '*' ? undef : $bor,
318
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
319
            branchcode   => $br eq '*' ? undef : $br,
320
            rules        => {
321
                %$params,
322
            }
323
        }
324
    );
325
326
}
327
elsif ($op eq "set-branch-defaults") {
328
    my $categorycode  = $input->param('categorycode');
329
    my $patron_maxissueqty   = $input->param('patron_maxissueqty');
330
    my $patron_maxonsiteissueqty = $input->param('patron_maxonsiteissueqty');
331
    my $holdallowed   = $input->param('holdallowed');
332
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
333
    my $returnbranch  = $input->param('returnbranch');
334
    my $max_holds = $input->param('max_holds');
335
    $patron_maxissueqty =~ s/\s//g;
336
    $patron_maxissueqty = '' if $patron_maxissueqty !~ /^\d+/;
337
    $patron_maxonsiteissueqty =~ s/\s//g;
338
    $patron_maxonsiteissueqty = '' if $patron_maxonsiteissueqty !~ /^\d+/;
339
    $holdallowed =~ s/\s//g;
340
    $holdallowed = undef if $holdallowed !~ /^\d+/;
341
    $max_holds =~ s/\s//g;
342
    $max_holds = '' if $max_holds !~ /^\d+/;
343
344
    if ($branch eq "*") {
345
        Koha::CirculationRules->set_rules(
346
            {
347
                itemtype     => undef,
348
                branchcode   => undef,
349
                rules        => {
350
                    holdallowed             => $holdallowed,
351
                    hold_fulfillment_policy => $hold_fulfillment_policy,
352
                    returnbranch            => $returnbranch,
353
                }
354
            }
355
        );
356
        Koha::CirculationRules->set_rules(
357
            {
358
                categorycode => undef,
359
                branchcode   => undef,
360
                rules        => {
361
                    patron_maxissueqty             => $patron_maxissueqty,
362
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
363
                }
364
            }
365
        );
366
    } else {
367
        Koha::CirculationRules->set_rules(
368
            {
369
                itemtype     => undef,
370
                branchcode   => $branch,
371
                rules        => {
372
                    holdallowed             => $holdallowed,
373
                    hold_fulfillment_policy => $hold_fulfillment_policy,
374
                    returnbranch            => $returnbranch,
375
                }
376
            }
377
        );
378
        Koha::CirculationRules->set_rules(
379
            {
380
                categorycode => undef,
381
                branchcode   => $branch,
382
                rules        => {
383
                    patron_maxissueqty             => $patron_maxissueqty,
384
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
385
                }
386
            }
387
        );
388
    }
389
    Koha::CirculationRules->set_rule(
390
        {
391
            branchcode   => $branch,
392
            categorycode => '*',
393
            itemtype     => undef,
394
            rule_name    => 'max_holds',
395
            rule_value   => $max_holds,
396
        }
397
    );
398
}
399
elsif ($op eq "add-branch-cat") {
400
    my $categorycode  = $input->param('categorycode');
401
    my $patron_maxissueqty   = $input->param('patron_maxissueqty');
402
    my $patron_maxonsiteissueqty = $input->param('patron_maxonsiteissueqty');
403
    my $max_holds = $input->param('max_holds');
404
    $patron_maxissueqty =~ s/\s//g;
405
    $patron_maxissueqty = '' if $patron_maxissueqty !~ /^\d+/;
406
    $patron_maxonsiteissueqty =~ s/\s//g;
407
    $patron_maxonsiteissueqty = '' if $patron_maxonsiteissueqty !~ /^\d+/;
408
    $max_holds =~ s/\s//g;
409
    $max_holds = '' if $max_holds !~ /^\d+/;
410
411
    if ($branch eq "*") {
412
        if ($categorycode eq "*") {
413
            Koha::CirculationRules->set_rules(
414
                {
415
                    categorycode => undef,
416
                    branchcode   => undef,
417
                    rules        => {
418
                        max_holds         => $max_holds,
419
                        patron_maxissueqty       => $patron_maxissueqty,
420
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
421
                    }
422
                }
423
            );
424
        } else {
425
            Koha::CirculationRules->set_rules(
426
                {
427
                    categorycode => $categorycode,
428
                    branchcode   => undef,
429
                    rules        => {
430
                        max_holds         => $max_holds,
431
                        patron_maxissueqty       => $patron_maxissueqty,
432
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
433
                    }
434
                }
435
            );
436
        }
437
    } elsif ($categorycode eq "*") {
438
        Koha::CirculationRules->set_rules(
439
            {
440
                categorycode => undef,
441
                branchcode   => $branch,
442
                rules        => {
443
                    max_holds         => $max_holds,
444
                    patron_maxissueqty       => $patron_maxissueqty,
445
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
446
                }
447
            }
448
        );
449
    } else {
450
        Koha::CirculationRules->set_rules(
451
            {
452
                categorycode => $categorycode,
453
                branchcode   => $branch,
454
                rules        => {
455
                    max_holds         => $max_holds,
456
                    patron_maxissueqty       => $patron_maxissueqty,
457
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
458
                }
459
            }
460
        );
461
    }
462
}
463
elsif ($op eq "add-branch-item") {
464
    my $itemtype                = $input->param('itemtype');
465
    my $holdallowed             = $input->param('holdallowed');
466
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
467
    my $returnbranch            = $input->param('returnbranch');
468
469
    $holdallowed =~ s/\s//g;
470
    $holdallowed = undef if $holdallowed !~ /^\d+/;
471
472
    if ($branch eq "*") {
473
        if ($itemtype eq "*") {
474
            Koha::CirculationRules->set_rules(
475
                {
476
                    itemtype     => undef,
477
                    branchcode   => undef,
478
                    rules        => {
479
                        holdallowed             => $holdallowed,
480
                        hold_fulfillment_policy => $hold_fulfillment_policy,
481
                        returnbranch            => $returnbranch,
482
                    }
483
                }
484
            );
485
        } else {
486
            Koha::CirculationRules->set_rules(
487
                {
488
                    itemtype     => $itemtype,
489
                    branchcode   => undef,
490
                    rules        => {
491
                        holdallowed             => $holdallowed,
492
                        hold_fulfillment_policy => $hold_fulfillment_policy,
493
                        returnbranch            => $returnbranch,
494
                    }
495
                }
496
            );
497
        }
498
    } elsif ($itemtype eq "*") {
499
            Koha::CirculationRules->set_rules(
500
                {
501
                    itemtype     => undef,
502
                    branchcode   => $branch,
503
                    rules        => {
504
                        holdallowed             => $holdallowed,
505
                        hold_fulfillment_policy => $hold_fulfillment_policy,
506
                        returnbranch            => $returnbranch,
507
                    }
508
                }
509
            );
510
    } else {
511
        Koha::CirculationRules->set_rules(
512
            {
513
                itemtype     => $itemtype,
514
                branchcode   => $branch,
515
                rules        => {
516
                    holdallowed             => $holdallowed,
517
                    hold_fulfillment_policy => $hold_fulfillment_policy,
518
                    returnbranch            => $returnbranch,
519
                }
520
            }
521
        );
522
    }
523
}
524
elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
525
526
    my $refund = $input->param('refund');
527
528
    if ( $refund eq '*' ) {
529
        if ( $branch ne '*' ) {
530
            # only do something for $refund eq '*' if branch-specific
531
            Koha::CirculationRules->set_rules(
532
                {
533
                    branchcode   => $branch,
534
                    rules        => {
535
                        refund => undef
536
                    }
537
                }
538
            );
539
        }
540
    } else {
541
        Koha::CirculationRules->set_rules(
542
            {
543
                branchcode   => undef,
544
                rules        => {
545
                    refund => $refund
546
                }
547
            }
548
        );
549
    }
550
}
551
552
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch eq '*' ? undef : $branch });
553
$template->param(
554
    refundLostItemFeeRule => $refundLostItemFeeRule,
555
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
556
);
557
558
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
559
560
my $itemtypes = Koha::ItemTypes->search_with_localization;
561
562
$template->param(show_branch_cat_rule_form => 1);
563
564
$template->param(
565
    patron_categories => $patron_categories,
566
    itemtypeloop      => $itemtypes,
567
    humanbranch       => ( $branch ne '*' ? $branch : undef ),
568
    current_branch    => $branch,
569
);
570
output_html_with_http_headers $input, $cookie, $template->output;
571
572
exit 0;
573
574
# sort by patron category, then item type, putting
575
# default entries at the bottom
576
sub by_category_and_itemtype {
577
    unless (by_category($a, $b)) {
578
        return by_itemtype($a, $b);
579
    }
580
}
581
582
sub by_category {
583
    my ($a, $b) = @_;
584
    if ($a->{'default_humancategorycode'}) {
585
        return ($b->{'default_humancategorycode'} ? 0 : 1);
586
    } elsif ($b->{'default_humancategorycode'}) {
587
        return -1;
588
    } else {
589
        return $a->{'humancategorycode'} cmp $b->{'humancategorycode'};
590
    }
591
}
592
593
sub by_itemtype {
594
    my ($a, $b) = @_;
595
    if ($a->{default_translated_description}) {
596
        return ($b->{'default_translated_description'} ? 0 : 1);
597
    } elsif ($b->{'default_translated_description'}) {
598
        return -1;
599
    } else {
600
        return lc $a->{'translated_description'} cmp lc $b->{'translated_description'};
601
    }
602
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (-1 / +1 lines)
Lines 17-23 Link Here
17
<h5>Patrons and circulation</h5>
17
<h5>Patrons and circulation</h5>
18
<ul>
18
<ul>
19
    <li><a href="/cgi-bin/koha/admin/categories.pl">Patron categories</a></li>
19
    <li><a href="/cgi-bin/koha/admin/categories.pl">Patron categories</a></li>
20
    <li><a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fines rules</a></li>
20
    <li><a href="/cgi-bin/koha/admin/policy.pl">Circulation, fines, and holds rules</a></li>
21
    <li><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron attribute types</a></li>
21
    <li><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron attribute types</a></li>
22
    <li><a href="/cgi-bin/koha/admin/branch_transfer_limits.pl">Library transfer limits</a></li>
22
    <li><a href="/cgi-bin/koha/admin/branch_transfer_limits.pl">Library transfer limits</a></li>
23
    <li><a href="/cgi-bin/koha/admin/transport-cost-matrix.pl">Transport cost matrix</a></li>
23
    <li><a href="/cgi-bin/koha/admin/transport-cost-matrix.pl">Transport cost matrix</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-2 / +2 lines)
Lines 43-50 Link Here
43
                    <dt><a href="/cgi-bin/koha/admin/categories.pl">Patron categories</a></dt>
43
                    <dt><a href="/cgi-bin/koha/admin/categories.pl">Patron categories</a></dt>
44
                    <dd>Define patron categories.</dd>
44
                    <dd>Define patron categories.</dd>
45
                [% IF CAN_user_parameters_manage_circ_rules %]
45
                [% IF CAN_user_parameters_manage_circ_rules %]
46
                    <dt><a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fines rules</a></dt>
46
                    <dt><a href="/cgi-bin/koha/admin/policy.pl">Circulation, fines, and holds rules</a></dt>
47
                    <dd>Define circulation and fines rules for combinations of libraries, patron categories, and item types</dd>
47
                    <dd>Define circulation, fines, and holds rules for combinations of libraries, patron categories, and item types</dd>
48
                [% END %]
48
                [% END %]
49
                    <dt><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron attribute types</a></dt>
49
                    <dt><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron attribute types</a></dt>
50
                    <dd>Define extended attributes (identifiers and statistical categories) for patron records</dd>
50
                    <dd>Define extended attributes (identifiers and statistical categories) for patron records</dd>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/clone-rules.tt (-73 lines)
Lines 1-73 Link Here
1
[% USE Branches %]
2
[% SET footerjs = 1 %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules &rsaquo; Clone circulation and fine rules</title>
5
[% INCLUDE 'doc-head-close.inc' %]
6
</head>
7
<body id="admin_clone-rules" class="admin">
8
[% INCLUDE 'header.inc' %]
9
[% INCLUDE 'prefs-admin-search.inc' %]
10
11
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fine rules</a> &rsaquo; Clone circulation and fine rules</div>
12
13
<div id="doc3" class="yui-t1">
14
15
<div id="bd">
16
    <div id="yui-main">
17
    <div class="yui-b">
18
    <h2>Cloning circulation and fine rules
19
        [% IF frombranch %] from "[% Branches.GetName( frombranch ) %]"[% END %]
20
        [% IF tobranch %] to "[% Branches.GetName( tobranch ) %]"[% END %]
21
    </h2>
22
23
    [% IF ( result ) %]
24
	[% IF ( error ) %]
25
        <div class="dialog alert">Cloning of circulation and fine rules failed!</div>
26
	[% ELSE %]
27
	    <div class="dialog message"><p>The rules have been cloned.</p></div>
28
	[% END %]
29
    <a href="/cgi-bin/koha/admin/smart-rules.pl">Return to circulation and fine rules</a>
30
    [% ELSE %]
31
32
    <p class="help">Use carefully! If the destination library already has circulation and fine rules, they will be deleted without warning!</p>
33
    <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
34
        [% UNLESS ( frombranch ) %]
35
            <fieldset>
36
                <legend>Please choose a library to clone rules from:</legend>
37
                <label for="frombranch">Source library:</label>
38
                <select name="frombranch" id="frombranch">
39
                    <option value="">Default</option>
40
                    [% PROCESS options_for_libraries libraries => Branches.all() %]
41
                </select>
42
                [% IF ( tobranch ) %]<input type="hidden" name="tobranch" value="[% tobranch %]" />[% END %]
43
            </fieldset>
44
        [% END %]
45
46
        [% UNLESS ( tobranch ) %]
47
            <fieldset>
48
            <legend>Please choose the library to clone the rules to:</legend>
49
            <label for="tobranch">Destination library:</label>
50
            <select name="tobranch" id="tobranch">
51
                <option value="">Default</option>
52
                [% PROCESS options_for_libraries libraries => Branches.all() %]
53
            </select>
54
            [% IF ( frombranch ) %]<input type="hidden" name="frombranch" value="[% frombranch %]" />[% END %]
55
            </fieldset>
56
        [% END %]
57
        <input type="submit" value="Submit" />
58
    </form>
59
60
    [% END %]
61
    </div>
62
63
</div>
64
<div class="yui-b">
65
[% INCLUDE 'admin-menu.inc' %]
66
</div>
67
</div>
68
69
[% MACRO jsinclude BLOCK %]
70
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
71
[% END %]
72
73
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/policy.tt (-2 / +2 lines)
Lines 9-20 Link Here
9
[% INCLUDE 'doc-head-close.inc' %]
9
[% INCLUDE 'doc-head-close.inc' %]
10
<link rel="stylesheet" href="[% interface %]/[% theme %]/css/admin/policy.css" />
10
<link rel="stylesheet" href="[% interface %]/[% theme %]/css/admin/policy.css" />
11
</head>
11
</head>
12
<body id="admin_smart-rules" class="admin">
12
<body id="admin_policy" class="admin">
13
[% INCLUDE 'header.inc' %]
13
[% INCLUDE 'header.inc' %]
14
[% INCLUDE 'calendar.inc' %]
14
[% INCLUDE 'calendar.inc' %]
15
[% INCLUDE 'prefs-admin-search.inc' %]
15
[% INCLUDE 'prefs-admin-search.inc' %]
16
16
17
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Policy</div>
17
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Circulation, fines and holds rules</div>
18
18
19
<div id="doc3" class="yui-t1">
19
<div id="doc3" class="yui-t1">
20
20
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-946 lines)
Lines 1-946 Link Here
1
[% USE KohaDates %]
2
[% USE Branches %]
3
[% USE Categories %]
4
[% USE ItemTypes %]
5
[% USE CirculationRules %]
6
[% SET footerjs = 1 %]
7
8
[% SET branchcode = humanbranch || undef %]
9
10
[% SET categorycodes = [] %]
11
[% FOREACH pc IN patron_categories %]
12
    [% categorycodes.push( pc.id ) %]
13
[% END %]
14
[% categorycodes.push(undef) %]
15
16
[% SET itemtypes = [] %]
17
[% FOREACH i IN itemtypeloop %]
18
    [% itemtypes.push( i.itemtype ) %]
19
[% END %]
20
[% itemtypes.push(undef) %]
21
22
[% INCLUDE 'doc-head-open.inc' %]
23
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
24
[% INCLUDE 'doc-head-close.inc' %]
25
</head>
26
27
<body id="admin_smart-rules" class="admin">
28
[% INCLUDE 'header.inc' %]
29
[% INCLUDE 'prefs-admin-search.inc' %]
30
31
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Circulation and fine rules</div>
32
33
<div id="doc3" class="yui-t1">
34
35
<div id="bd">
36
    <div id="yui-main">
37
    <div class="yui-b">
38
    <h1 class="parameters">
39
        [% IF humanbranch %]
40
            Defining circulation and fine rules for "[% Branches.GetName( humanbranch ) %]"
41
        [% ELSE %]
42
            Defining circulation and fine rules for all libraries
43
        [% END %]
44
    </h1>
45
    <div class="help">
46
        <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
47
        <ul>
48
            <li>same library, same patron category, same item type</li>
49
            <li>same library, same patron category, all item types</li>
50
            <li>same library, all patron categories, same item type</li>
51
            <li>same library, all patron categories, all item types</li>
52
            <li>default (all libraries), same patron category, same item type</li>
53
            <li>default (all libraries), same patron category, all item types</li>
54
            <li>default (all libraries), all patron categories, same item type</li>
55
            <li>default (all libraries), all patron categories, all item types</li>
56
        </ul>
57
        <p>To modify a rule, create a new one with the same patron category and item type.</p>
58
    </div>
59
    <div>
60
        [% UNLESS restricted_to_own_library %]
61
            <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
62
            Select a library :
63
                <select name="branch" id="branch" style="width:20em;">
64
                    <option value="*">Standard rules for all libraries</option>
65
                    [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
66
                </select>
67
            </form>
68
            [% IF ( definedbranch ) %]
69
                <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
70
                    <label for="tobranch"><strong>Clone these rules to:</strong></label>
71
                    <input type="hidden" name="frombranch" value="[% current_branch %]" />
72
                    <select name="tobranch" id="tobranch">
73
                        [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
74
                    </select>
75
                    <input type="submit" id="clone_rules" value="Clone" />
76
                </form>
77
            [% END %]
78
        [% END %]
79
80
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
81
            <input type="hidden" name="op" value="add" />
82
            <input type="hidden" name="branch" value="[% current_branch %]"/>
83
            <table id="default-circulation-rules">
84
            <thead>
85
            <tr>
86
                <th>Patron category</th>
87
                <th>Item type</th>
88
                <th>Actions</th>
89
                <th>Current checkouts allowed</th>
90
                <th>Current on-site checkouts allowed</th>
91
                <th>Loan period</th>
92
                <th>Unit</th>
93
                <th>Hard due date</th>
94
                <th>Fine amount</th>
95
                <th>Fine charging interval</th>
96
                <th>When to charge</th>
97
                <th>Fine grace period</th>
98
                <th>Overdue fines cap (amount)</th>
99
                <th>Cap fine at replacement price</th>
100
                <th>Suspension in days (day)</th>
101
                <th>Max. suspension duration (day)</th>
102
                <th>Renewals allowed (count)</th>
103
                <th>Renewal period</th>
104
                <th>No renewal before</th>
105
                <th>Automatic renewal</th>
106
                <th>No automatic renewal after</th>
107
                <th>No automatic renewal after (hard limit)</th>
108
                <th>Holds allowed (count)</th>
109
                <th>Holds per record (count)</th>
110
                <th>On shelf holds allowed</th>
111
                <th>Item level holds</th>
112
                <th>Article requests</th>
113
                <th>Rental discount (%)</th>
114
                <th>Actions</th>
115
            </tr>
116
            </thead>
117
            <tbody>
118
                [% SET row_count = 0 %]
119
                [% FOREACH c IN categorycodes %]
120
                    [% FOREACH i IN itemtypes %]
121
                        [% SET maxissueqty = CirculationRules.Get( branchcode, c, i, 'maxissueqty' ) %]
122
                        [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, i, 'maxonsiteissueqty' ) %]
123
                        [% SET issuelength = CirculationRules.Get( branchcode, c, i, 'issuelength' ) %]
124
                        [% SET lengthunit = CirculationRules.Get( branchcode, c, i, 'lengthunit' ) %]
125
                        [% SET hardduedate = CirculationRules.Get( branchcode, c, i, 'hardduedate' ) %]
126
                        [% SET hardduedatecompare = CirculationRules.Get( branchcode, c, i, 'hardduedatecompare' ) %]
127
                        [% SET fine = CirculationRules.Get( branchcode, c, i, 'fine' ) %]
128
                        [% SET chargeperiod = CirculationRules.Get( branchcode, c, i, 'chargeperiod' ) %]
129
                        [% SET chargeperiod_charge_at = CirculationRules.Get( branchcode, c, i, 'chargeperiod_charge_at' ) %]
130
                        [% SET firstremind = CirculationRules.Get( branchcode, c, i, 'firstremind' ) %]
131
                        [% SET overduefinescap = CirculationRules.Get( branchcode, c, i, 'overduefinescap' ) %]
132
                        [% SET cap_fine_to_replacement_price = CirculationRules.Get( branchcode, c, i, 'cap_fine_to_replacement_price' ) %]
133
                        [% SET finedays = CirculationRules.Get( branchcode, c, i, 'finedays' ) %]
134
                        [% SET maxsuspensiondays = CirculationRules.Get( branchcode, c, i, 'maxsuspensiondays' ) %]
135
                        [% SET renewalsallowed = CirculationRules.Get( branchcode, c, i, 'renewalsallowed' ) %]
136
                        [% SET renewalperiod = CirculationRules.Get( branchcode, c, i, 'renewalperiod' ) %]
137
                        [% SET norenewalbefore = CirculationRules.Get( branchcode, c, i, 'norenewalbefore' ) %]
138
                        [% SET auto_renew = CirculationRules.Get( branchcode, c, i, 'auto_renew' ) %]
139
                        [% SET no_auto_renewal_after = CirculationRules.Get( branchcode, c, i, 'no_auto_renewal_after' ) %]
140
                        [% SET no_auto_renewal_after_hard_limit = CirculationRules.Get( branchcode, c, i, 'no_auto_renewal_after_hard_limit' ) %]
141
                        [% SET reservesallowed = CirculationRules.Get( branchcode, c, i, 'reservesallowed' ) %]
142
                        [% SET holds_per_record = CirculationRules.Get( branchcode, c, i, 'holds_per_record' ) %]
143
                        [% SET onshelfholds = CirculationRules.Get( branchcode, c, i, 'onshelfholds' ) %]
144
                        [% SET opacitemholds = CirculationRules.Get( branchcode, c, i, 'opacitemholds' ) %]
145
                        [% SET article_requests = CirculationRules.Get( branchcode, c, i, 'article_requests' ) %]
146
                        [% SET rentaldiscount = CirculationRules.Get( branchcode, c, i, 'rentaldiscount' ) %]
147
148
                        [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod
149
                                        || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || renewalsallowed
150
                                        || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed
151
                                        || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %]
152
                        [% IF show_rule %]
153
                            [% SET row_count = row_count + 1 %]
154
                            <tr row_countd="row_[% row_count %]">
155
                                    <td>
156
                                        [% IF c == undef %]
157
                                            <em>All</em>
158
                                        [% ELSE %]
159
                                            [% Categories.GetName(c) %]
160
                                        [% END %]
161
                                    </td>
162
                                    <td>
163
                                        [% IF i == undef %]
164
                                            <em>All</em>
165
                                        [% ELSE %]
166
                                            [% ItemTypes.GetDescription(i) %]
167
                                        [% END %]
168
                                    </td>
169
                                    <td class="actions">
170
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
171
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
172
                                    </td>
173
                                    <td>
174
                                        [% IF maxissueqty.defined && maxissueqty != '' %]
175
                                            [% maxissueqty %]
176
                                        [% ELSE %]
177
                                            Unlimited
178
                                        [% END %]
179
                                    </td>
180
                                    <td>
181
                                        [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
182
                                            [% maxonsiteissueqty %]
183
                                        [% ELSE %]
184
                                            Unlimited
185
                                        [% END %]
186
                                    </td>
187
                                    <td>[% issuelength %]</td>
188
                                    <td>
189
                                        [% lengthunit %]
190
                                    </td>
191
                                    <td>
192
                                      [% IF ( hardduedate ) %]
193
                                        [% IF ( hardduedatecompare == '-1' ) %]
194
                                          before [% hardduedate | $KohaDates %]
195
                                          <input type="hidden" name="hardduedatecomparebackup" value="-1" />
196
                                        [% ELSIF ( hardduedatecompare == '0' ) %]
197
                                          on [% hardduedate | $KohaDates %]
198
                                          <input type="hidden" name="hardduedatecomparebackup" value="0" />
199
                                        [% ELSIF ( hardduedatecompare == '1' ) %]
200
                                          after [% hardduedate | $KohaDates %]
201
                                          <input type="hidden" name="hardduedatecomparebackup" value="1" />
202
                                        [% END %]
203
                                      [% ELSE %]
204
                                        None defined
205
                                      [% END %]
206
                                    </td>
207
                                    <td>[% fine %]</td>
208
                                    <td>[% chargeperiod %]</td>
209
                                    <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
210
                                    <td>[% firstremind %]</td>
211
                                    <td>[% overduefinescap FILTER format("%.2f") %]</td>
212
                                    <td>
213
                                        [% IF cap_fine_to_replacement_price %]
214
                                            <input type="checkbox" checked="checked" disabled="disabled" />
215
                                        [% ELSE %]
216
                                            <input type="checkbox" disabled="disabled" />
217
                                        [% END %]
218
                                    </td>
219
                                    <td>[% finedays %]</td>
220
                                    <td>[% maxsuspensiondays %]</td>
221
                                    <td>[% renewalsallowed %]</td>
222
                                    <td>[% renewalperiod %]</td>
223
                                    <td>[% norenewalbefore %]</td>
224
                                    <td>
225
                                        [% IF auto_renew %]
226
                                            Yes
227
                                        [% ELSE %]
228
                                            No
229
                                        [% END %]
230
                                    </td>
231
                                    <td>[% no_auto_renewal_after %]</td>
232
                                    <td>[% no_auto_renewal_after_hard_limit %]</td>
233
                                    <td>[% reservesallowed %]</td>
234
                                    <td>[% holds_per_record %]</td>
235
                                    <td>
236
                                        [% IF onshelfholds == 1 %]
237
                                            Yes
238
                                        [% ELSIF onshelfholds == 2 %]
239
                                            If all unavailable
240
                                        [% ELSE %]
241
                                            If any unavailable
242
                                        [% END %]
243
                                    </td>
244
                                    <td>[% IF opacitemholds == 'F'%]Force[% ELSIF opacitemholds == 'Y'%]Allow[% ELSE %]Don't allow[% END %]</td>
245
                                    <td>
246
                                        [% IF article_requests == 'no' %]
247
                                            No
248
                                        [% ELSIF article_requests == 'yes' %]
249
                                            Yes
250
                                        [% ELSIF article_requests == 'bib_only' %]
251
                                            Record only
252
                                        [% ELSIF article_requests == 'item_only' %]
253
                                            Item only
254
                                        [% END %]
255
                                    </td>
256
                                    <td>[% rentaldiscount %]</td>
257
                                    <td class="actions">
258
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
259
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
260
                                    </td>
261
                            </tr>
262
                        [% END %]
263
                    [% END %]
264
                [% END %]
265
                <tr id="edit_row">
266
                    <td>
267
                        <select name="categorycode" id="categorycode">
268
                            <option value="*">All</option>
269
                        [% FOREACH patron_category IN patron_categories%]
270
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
271
                        [% END %]
272
                        </select>
273
                    </td>
274
                    <td>
275
                        <select name="itemtype" id="matrixitemtype" style="width:13em;">
276
                            <option value="*">All</option>
277
                        [% FOREACH itemtypeloo IN itemtypeloop %]
278
                            <option value="[% itemtypeloo.itemtype %]">[% itemtypeloo.translated_description %]</option>
279
                        [% END %]
280
                        </select>
281
                    </td>
282
                    <td class="actions">
283
                        <input type="hidden" name="branch" value="[% current_branch %]"/>
284
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
285
                        <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
286
                    </td>
287
                    <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
288
                    <td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
289
                    <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
290
                    <td>
291
                      <select name="lengthunit" id="lengthunit">
292
                        <option value="days" selected="selected">Days</option>
293
                        <option value="hours">Hours</option>
294
                      </select>
295
                    </td>
296
                    <td>
297
                        <select name="hardduedatecompare" id="hardduedatecompare">
298
                           <option value="-1">Before</option>
299
                           <option value="0">Exactly on</option>
300
                           <option value="1">After</option>
301
                        </select>
302
                        <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate %]" class="datepicker" />
303
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
304
                    </td>
305
                    <td><input type="text" name="fine" id="fine" size="4" /></td>
306
                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
307
                    <td>
308
                        <select name="chargeperiod_charge_at" id="chargeperiod_charge_at">
309
                           <option value="0">End of interval</option>
310
                           <option value="1">Start of interval</option>
311
                        </select>
312
                    </td>
313
                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
314
                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
315
                    <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
316
                    <td><input type="text" name="finedays" id="fined" size="3" /> </td>
317
                    <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
318
                    <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
319
                    <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
320
                    <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
321
                    <td>
322
                        <select name="auto_renew" id="auto_renew">
323
                            <option value="no" selected>No</option>
324
                            <option value="yes">Yes</option>
325
                        </select>
326
                    </td>
327
                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
328
                    <td>
329
                        <input type="text" size="10" name="no_auto_renewal_after_hard_limit" id="no_auto_renewal_after_hard_limit" value="[% no_auto_renewal_after_hard_limit %]" class="datepicker"/>
330
                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
331
                    </td>
332
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
333
                    <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
334
                    <td>
335
                        <select name="onshelfholds" id="onshelfholds">
336
                            <option value="1">Yes</option>
337
                            <option value="0">If any unavailable</option>
338
                            <option value="2">If all unavailable</option>
339
                        </select>
340
                    </td>
341
                    <td>
342
                        <select id="opacitemholds" name="opacitemholds">
343
                            <option value="N">Don't allow</option>
344
                            <option value="Y">Allow</option>
345
                            <option value="F">Force</option>
346
                        </select>
347
                    </td>
348
                    <td>
349
                        <select id="article_requests" name="article_requests">
350
                            <option value="no">No</option>
351
                            <option value="yes">Yes</option>
352
                            <option value="bib_only">Record only</option>
353
                            <option value="item_only">Item only</option>
354
                        </select>
355
                    </td>
356
                    <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
357
                    <td class="actions">
358
                        <input type="hidden" name="branch" value="[% current_branch %]"/>
359
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
360
                        <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
361
                    </td>
362
                </tr>
363
                <tfoot>
364
                    <tr>
365
                      <th>Patron category</th>
366
                      <th>Item type</th>
367
                      <th>&nbsp;</th>
368
                      <th>Current checkouts allowed</th>
369
                      <th>Current on-site checkouts allowed</th>
370
                      <th>Loan period</th>
371
                      <th>Unit</th>
372
                      <th>Hard due date</th>
373
                      <th>Fine amount</th>
374
                      <th>Fine charging interval</th>
375
                      <th>Charge when?</th>
376
                      <th>Fine grace period</th>
377
                      <th>Overdue fines cap (amount)</th>
378
                      <th>Cap fine at replacement price</th>
379
                      <th>Suspension in days (day)</th>
380
                      <th>Max. suspension duration (day)</th>
381
                      <th>Renewals allowed (count)</th>
382
                      <th>Renewal period</th>
383
                      <th>No renewal before</th>
384
                      <th>Automatic renewal</th>
385
                      <th>No automatic renewal after</th>
386
                       <th>No automatic renewal after (hard limit)</th>
387
                      <th>Holds allowed (count)</th>
388
                      <th>Holds per record (count)</th>
389
                      <th>On shelf holds allowed</th>
390
                      <th>Item level holds</th>
391
                      <th>Article requests</th>
392
                      <th>Rental discount (%)</th>
393
                      <th>&nbsp;</th>
394
                    </tr>
395
                  </tfoot>
396
                </tbody>
397
            </table>
398
        </form>
399
    </div>
400
    <div id="defaults-for-this-library" class="container">
401
    <h3>Default checkout, hold and return policy[% IF humanbranch %] for [% Branches.GetName( humanbranch ) %][% END %]</h3>
402
        <p>You can set a default maximum number of checkouts, hold policy and return policy that will be used if none is defined below for a particular item type or category.</p>
403
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
404
            <input type="hidden" name="op" value="set-branch-defaults" />
405
            <input type="hidden" name="branch" value="[% current_branch %]"/>
406
            <table>
407
                <tr>
408
                    <th>&nbsp;</th>
409
                    <th>Total current checkouts allowed</th>
410
                    <th>Total current on-site checkouts allowed</th>
411
                    <th>Maximum total holds allowed (count)</th>
412
                    <th>Hold policy</th>
413
                    <th>Hold pickup library match</th>
414
                    <th>Return policy</th>
415
                    <th>Actions</th>
416
                </tr>
417
                <tr>
418
                    <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td>
419
                    <td>
420
                        [% SET patron_maxissueqty = CirculationRules.Get( branchcode, undef, undef, 'patron_maxissueqty' ) %]
421
                        <input type="text" name="patron_maxissueqty" size="3" value="[% patron_maxissueqty %]"/>
422
                    </td>
423
                    <td>
424
                        [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, undef, undef, 'patron_maxonsiteissueqty' ) %]
425
                        <input type="text" name="patron_maxonsiteissueqty" size="3" value="[% patron_maxonsiteissueqty %]"/>
426
                    </td>
427
                    <td>
428
                        [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %]
429
                        <input name="max_holds" size="3" value="[% rule_value %]" />
430
                    </td>
431
                    <td>
432
                        <select name="holdallowed">
433
                            [% SET holdallowed = CirculationRules.Get( branchcode, undef, undef, 'holdallowed' ) %]
434
                            <option value="">
435
                                Not set
436
                            </option>
437
438
                            [% IF holdallowed == 2 %]
439
                                <option value="2" selected="selected">
440
                            [% ELSE %]
441
                                <option value="2">
442
                            [% END %]
443
                                From any library
444
                            </option>
445
446
                            [% IF holdallowed == 1 %]
447
                                <option value="1" selected="selected">
448
                            [% ELSE %]
449
                                <option value="1">
450
                            [% END %]
451
                                From home library
452
                            </option>
453
454
                            [% IF holdallowed == 0 %]
455
                                <option value="0" selected="selected">
456
                            [% ELSE %]
457
                                <option value="0">
458
                            [% END %]
459
                                No holds allowed
460
                            </option>
461
                        </select>
462
                    </td>
463
                    <td>
464
                        <select name="hold_fulfillment_policy">
465
                            [% SET hold_fulfillment_policy = CirculationRules.Get( branchcode, undef, undef, 'hold_fulfillment_policy' ) %]
466
467
                            <option value="">
468
                                Not set
469
                            </option>
470
471
                            [% IF hold_fulfillment_policy == 'any' %]
472
                                <option value="any" selected="selected">
473
                                    any library
474
                                </option>
475
                            [% ELSE %]
476
                                <option value="any">
477
                                    any library
478
                                </option>
479
                            [% END %]
480
481
                            [% IF hold_fulfillment_policy == 'homebranch' %]
482
                                <option value="homebranch" selected="selected">
483
                                    item's home library
484
                                </option>
485
                            [% ELSE %]
486
                                <option value="homebranch">
487
                                    item's home library
488
                                </option>
489
                            [% END %]
490
491
                            [% IF hold_fulfillment_policy == 'holdingbranch' %]
492
                                <option value="holdingbranch" selected="selected">
493
                                    item's holding library
494
                                </option>
495
                            [% ELSE %]
496
                                <option value="holdingbranch">
497
                                    item's holding library
498
                                </option>
499
                            [% END %]
500
                        </select>
501
                    </td>
502
                    <td>
503
                        <select name="returnbranch">
504
                            [% SET returnbranch = CirculationRules.Get( branchcode, undef, undef, 'returnbranch' ) %]
505
506
                            <option value="">
507
                                Not set
508
                            </option>
509
510
                            [% IF returnbranch == 'homebranch' %]
511
                            <option value="homebranch" selected="selected">
512
                            [% ELSE %]
513
                            <option value="homebranch">
514
                            [% END %]
515
                                Item returns home
516
                            </option>
517
                            [% IF returnbranch == 'holdingbranch' %]
518
                            <option value="holdingbranch" selected="selected">
519
                            [% ELSE %]
520
                            <option value="holdingbranch">
521
                            [% END %]
522
                                Item returns to issuing library
523
                            </option>
524
                            [% IF returnbranch == 'noreturn' %]
525
                            <option value="noreturn" selected="selected">
526
                            [% ELSE %]
527
                            <option value="noreturn">
528
                            [% END %]
529
                                Item floats
530
                            </option>
531
                        </select>
532
                    </td>
533
                    <td class="actions">
534
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
535
                        <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
536
                    </td>
537
                </tr>
538
            </table>
539
        </form>
540
    </div>
541
    [% IF ( show_branch_cat_rule_form ) %]
542
    <div id="holds-policy-by-patron-category" class="container">
543
    <h3>[% IF humanbranch %]Checkout, hold policy by patron category for [% Branches.GetName( humanbranch ) %][% ELSE %]Default checkout, hold policy by patron category[% END %]</h3>
544
        <p>For this library, you can specify the maximum number of loans that
545
            a patron of a given category can make, regardless of the item type.
546
        </p>
547
        <p>If the total amount loanable for a given patron category is left blank,
548
           no limit applies, except possibly for a limit you define for a specific item type.
549
        </p>
550
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
551
            <input type="hidden" name="op" value="add-branch-cat" />
552
            <input type="hidden" name="branch" value="[% current_branch %]"/>
553
            <table>
554
                <tr>
555
                    <th>Patron category</th>
556
                    <th>Total current checkouts allowed</th>
557
                    <th>Total current on-site checkouts allowed</th>
558
                    <th>Total holds allowed</th>
559
                    <th>&nbsp;</th>
560
                </tr>
561
                [% FOREACH c IN categorycodes %]
562
                    [% NEXT UNLESS c %]
563
                    [% SET patron_maxissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxissueqty' ) %]
564
                    [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
565
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
566
567
                    [% IF patron_maxissueqty || patron_maxonsiteissueqty || max_holds %]
568
                    <tr>
569
                        <td>
570
                            [% IF c == undef %]
571
                                <em>Default</em>
572
                            [% ELSE %]
573
                                [% Categories.GetName(c) %]
574
                            [% END %]
575
                        </td>
576
                        <td>
577
                            [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %]
578
                                [% patron_maxissueqty %]
579
                            [% ELSE %]
580
                                Unlimited
581
                            [% END %]
582
                        </td>
583
                        <td>
584
                            [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %]
585
                                [% patron_maxonsiteissueqty %]
586
                            [% ELSE %]
587
                                Unlimited
588
                            [% END %]
589
                        </td>
590
                        <td>
591
                            [% IF max_holds.defined && max_holds != ''  %]
592
                                [% max_holds %]
593
                            [% ELSE %]
594
                                Unlimited
595
                            [% END %]
596
                        </td>
597
598
                        <td class="actions">
599
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
600
                        </td>
601
                    </tr>
602
                    [% END %]
603
                [% END %]
604
                <tr>
605
                    <td>
606
                        <select name="categorycode">
607
                        [% FOREACH patron_category IN patron_categories%]
608
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
609
                        [% END %]
610
                        </select>
611
                    </td>
612
                    <td><input name="patron_maxissueqty" size="3" /></td>
613
                    <td><input name="patron_maxonsiteissueqty" size="3" /></td>
614
                    <td><input name="max_holds" size="3" /></td>
615
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
616
                </tr>
617
            </table>
618
        </form>
619
    </div>
620
    [% END %]
621
622
    <div id="refund-lost-item-fee-on-return" class="container">
623
  [% IF current_branch == '*' %]
624
    <h3>Default lost item fee refund on return policy</h3>
625
  [% ELSE %]
626
    <h3>Lost item fee refund on return policy for [% Branches.GetName(current_branch) %]</h3>
627
  [% END %]
628
        <p>Specify the default policy for lost item fees on return.
629
        </p>
630
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
631
            <input type="hidden" name="op" value="mod-refund-lost-item-fee-rule" />
632
            <input type="hidden" name="branch" value="[% current_branch %]" />
633
            <table>
634
                <tr>
635
                    <th>Refund lost item fee</th>
636
                    <th>&nbsp;</th>
637
                </tr>
638
                <tr>
639
                    <td>
640
                        <select name="refund">
641
                          [#% Default branch %#]
642
                          [% IF ( current_branch == '*' ) %]
643
                            [% IF ( refundLostItemFeeRule.rule_value ) %]
644
                            <option value="1" selected="selected">
645
                            [% ELSE %]
646
                            <option value="1">
647
                            [% END %]
648
                                Yes
649
                            </option>
650
                            [% IF ( not refundLostItemFeeRule.rule_value ) %]
651
                            <option value="0" selected="selected">
652
                            [% ELSE %]
653
                            <option value="0">
654
                            [% END %]
655
                                No
656
                            </option>
657
                          [% ELSE %]
658
                          [#% Branch-specific %#]
659
                            [% IF ( not refundLostItemFeeRule ) %]
660
                                <option value="*" selected="selected">
661
                            [% ELSE %]
662
                                <option value="*">
663
                            [% END %]
664
                              [% IF defaultRefundRule %]
665
                                Use default (Yes)
666
                              [% ELSE %]
667
                                Use default (No)
668
                              [% END %]
669
                                </option>
670
                            [% IF ( not refundLostItemFeeRule ) %]
671
                                <option value="1">Yes</option>
672
                                <option value="0">No</option>
673
                            [% ELSE %]
674
                                [% IF ( refundLostItemFeeRule.rule_value ) %]
675
                                <option value="1" selected="selected">
676
                                [% ELSE %]
677
                                <option value="1">
678
                                [% END %]
679
                                    Yes
680
                                </option>
681
                                [% IF ( not refundLostItemFeeRule.rule_value ) %]
682
                                <option value="0" selected="selected">
683
                                [% ELSE %]
684
                                <option value="0">
685
                                [% END %]
686
                                    No
687
                                </option>
688
                            [% END %]
689
                          [% END %]
690
                        </select>
691
                    </td>
692
                    <td class="actions">
693
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
694
                    </td>
695
                    </td>
696
                </tr>
697
            </table>
698
        </form>
699
    </div>
700
701
    <div id="holds-policy-by-item-type" class="container">
702
    <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) %][% ELSE %]Default holds policy by item type[% END %]</h3>
703
        <p>
704
            For this library, you can edit rules for given itemtypes, regardless
705
            of the patron's category.
706
        </p>
707
        <p>
708
            Currently, this means hold policies.
709
            The various policies have the following effects:
710
        </p>
711
        <ul>
712
            <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
713
            <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
714
            <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
715
        </ul>
716
        <p><strong>Note: </strong>If the system preference 'AllowHoldPolicyOverride' is enabled, these policies can be overridden by your circulation staff.</br />
717
            <strong>Important: </strong>The policies are based on the patron's home library, not the library where the hold is being placed.
718
        </p>
719
720
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
721
            <input type="hidden" name="op" value="add-branch-item" />
722
            <input type="hidden" name="branch" value="[% current_branch %]"/>
723
            <table>
724
                <tr>
725
                    <th>Item type</th>
726
                    <th>Hold policy</th>
727
                    <th>Hold pickup library match</th>
728
                    <th>Return policy</th>
729
                    <th>&nbsp;</th>
730
                </tr>
731
                [% FOREACH i IN itemtypeloop %]
732
                    [% SET holdallowed = CirculationRules.Get( branchcode, undef, i.itemtype, 'holdallowed' ) %]
733
                    [% SET hold_fulfillment_policy = CirculationRules.Get( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %]
734
                    [% SET returnbranch = CirculationRules.Get( branchcode, undef, i.itemtype, 'returnbranch' ) %]
735
736
                    [% IF holdallowed || hold_fulfillment_policy || returnbranch %]
737
                        <tr>
738
                            <td>
739
                                [% i.translated_description %]
740
                            </td>
741
                            <td>
742
                                [% IF holdallowed == 2 %]
743
                                    From any library
744
                                [% ELSIF holdallowed == 1 %]
745
                                    From home library
746
                                [% ELSE %]
747
                                    No holds allowed
748
                                [% END %]
749
                            </td>
750
                            <td>
751
                                [% IF hold_fulfillment_policy == 'any' %]
752
                                    any library
753
                                [% ELSIF hold_fulfillment_policy == 'homebranch' %]
754
                                    item's home library
755
                                [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
756
                                    item's holding library
757
                                [% END %]
758
                            </td>
759
                            <td>
760
                                [% IF returnbranch == 'homebranch' %]
761
                                    Item returns home
762
                                [% ELSIF returnbranch == 'holdingbranch' %]
763
                                    Item returns to issuing branch
764
                                [% ELSIF returnbranch == 'noreturn' %]
765
                                    Item floats
766
                                [% END %]
767
                            </td>
768
                            <td class="actions">
769
                                <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&amp;itemtype=[% i.itemtype %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
770
                            </td>
771
                        </tr>
772
                    [% END %]
773
                [% END %]
774
                <tr>
775
                    <td>
776
                        <select name="itemtype">
777
                        [% FOREACH itemtypeloo IN itemtypeloop %]
778
                            <option value="[% itemtypeloo.itemtype %]">[% itemtypeloo.translated_description %]</option>
779
                        [% END %]
780
                        </select>
781
                    </td>
782
                    <td>
783
                        <select name="holdallowed">
784
                            <option value="2">From any library</option>
785
                            <option value="1">From home library</option>
786
                            <option value="0">No holds allowed</option>
787
                        </select>
788
                    </td>
789
                    <td>
790
                        <select name="hold_fulfillment_policy">
791
                            <option value="any">
792
                                any library
793
                            </option>
794
795
                            <option value="homebranch">
796
                                item's home library
797
                            </option>
798
799
                            <option value="holdingbranch">
800
                                item's holding library
801
                            </option>
802
                        </select>
803
                    </td>
804
                    <td>
805
                        <select name="returnbranch">
806
                            <option value="homebranch">Item returns home</option>
807
                            <option value="holdingbranch">Item returns to issuing library</option>
808
                            <option value="noreturn">Item floats</option>
809
                        </select>
810
                    </td>
811
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
812
                </tr>
813
            </table>
814
        </form>
815
    </div>
816
</div>
817
818
</div>
819
<div class="yui-b">
820
[% INCLUDE 'admin-menu.inc' %]
821
</div>
822
</div>
823
824
[% MACRO jsinclude BLOCK %]
825
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
826
    [% INCLUDE 'calendar.inc' %]
827
    <script type="text/javascript">
828
829
        function clear_edit(){
830
            var cancel = confirm(_("Are you sure you want to cancel your changes?"));
831
            if ( !cancel ) return;
832
            $('#default-circulation-rules td').removeClass('highlighted-row');
833
            var edit_row = $("#edit_row");
834
            $(edit_row).find("input").each(function(){
835
                var type = $(this).attr("type");
836
                if (type != "button" && type != "submit" ) {
837
                    $(this).val("");
838
                    $(this).prop('disabled', false);
839
                }
840
                if ( type == "checkbox" ) {
841
                    $(this).prop('checked', false);
842
                }
843
            });
844
            $(edit_row).find("select").prop('disabled', false);
845
            $(edit_row).find("select option:first").attr("selected", "selected");
846
            $(edit_row).find("td:last input[name='clear']").remove();
847
        }
848
849
        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
850
851
        $(document).ready(function() {
852
            $(".delete").on("click",function(){
853
                return confirmDelete(MSG_CONFIRM_DELETE);
854
            });
855
856
            $("#clone_rules").on("click",function(){
857
                var library_dropdown = document.getElementById("branch");
858
                var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
859
                var selected_library_text = $("#branch option:selected").text();
860
                var to_library = $("#tobranch option:selected").text();
861
                var MSG_CONFIRM_CLONE;
862
                if (selected_library === "*") {
863
                    MSG_CONFIRM_CLONE = _("Are you sure you want to clone this standard rule to %s library? This will override the existing rules in this library.").format(to_library);
864
                    return confirmClone(MSG_CONFIRM_CLONE);
865
                } else {
866
                    MSG_CONFIRM_CLONE = _("Are you sure you want to clone this circulation and fine rule from %s to %s library? This will override the existing rules in this library.").format(selected_library_text, to_library);
867
                    return confirmClone(MSG_CONFIRM_CLONE);
868
                }
869
            });
870
871
            $('#cap_fine_to_replacement_price').on('change', function(){
872
                $('#overduefinescap').prop('disabled', $(this).is(':checked') );
873
            });
874
            $('#selectlibrary').find("input:submit").hide();
875
            $('#branch').change(function() {
876
                    $('#selectlibrary').submit();
877
            });
878
            $(".editrule").click(function(){
879
                if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
880
                    var edit = confirm(_("Are you sure you want to edit another rule?"));
881
                    if (!edit) return false;
882
                }
883
                $('#default-circulation-rules td').removeClass('highlighted-row');
884
                $(this).parent().parent().find("td").each(function (i) {
885
                    $(this).addClass('highlighted-row');
886
                    itm = $(this).text();
887
                    itm = itm.replace(/^\s*|\s*$/g,'');
888
                    var current_column = $("#edit_row td:eq("+i+")");
889
                    if ( i == 7 ) {
890
                        // specific processing for the Hard due date column
891
                        var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
892
                        var input_value = '';
893
                        if (typeof select_value === 'undefined'){
894
                            select_value = '-1';
895
                        }else {
896
                            input_value = itm.split(' ')[1];
897
                        }
898
                        $(current_column).find("input[type='text']").val(input_value);
899
                        $(current_column).find("select").val(select_value);
900
                    } else if ( i == 13 ) {
901
                        // specific processing for cap_fine_to_replacement_price
902
                        var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
903
                        $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
904
                        $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
905
                    } else {
906
                        $(current_column).find("input[type='text']").val(itm);
907
                        // select the corresponding option
908
                        $(current_column).find("select option").each(function(){
909
                            opt = $(this).text().toLowerCase();
910
                            opt = opt.replace(/^\s*|\s*$/g,'');
911
                            if ( opt == itm.toLowerCase() ) {
912
                                $(this).attr('selected', 'selected');
913
                            }
914
                        });
915
                        if ( i == 0 || i == 1 ) {
916
                            // Disable the 2 first columns, we cannot update them.
917
                            var val = $(current_column).find("select option:selected").val();
918
                            var name = "categorycode";
919
                            if ( i == 1 ) {
920
                                name="itemtype";
921
                            }
922
                            // Remove potential previous input added
923
                            $(current_column).find("input").remove();
924
                            $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
925
                        } else if ( i == 3 || i == 4 ) {
926
                            // If the value is not an integer for "Current checkouts allowed" or "Current on-site checkouts allowed"
927
                            // The value is "Unlimited" (or an equivalent translated string)
928
                            // an it should be set to an empty string
929
                            if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
930
                                $(current_column).find("input[type='text']").val("");
931
                            }
932
                        }
933
                    }
934
                });
935
                $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
936
                $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
937
                return false;
938
            });
939
            $(".clear_edit").on("click",function(e){
940
                e.preventDefault();
941
                clear_edit();
942
            });
943
        });
944
    </script>
945
[% END %]
946
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/src/admin/policy/app.js (-2 / +1 lines)
Lines 212-218 export default class PolicyApp extends React.Component { Link Here
212
        }
212
        }
213
213
214
        return <section>
214
        return <section>
215
            <h1>{__( "Circulation, fine and hold policy" )}</h1>
215
            <h1>{__( "Circulation, fines and holds rules" )}</h1>
216
            <PolicyAppToolbar
216
            <PolicyAppToolbar
217
                branch={this.state.branch}
217
                branch={this.state.branch}
218
                group={this.state.kindGroup}
218
                group={this.state.kindGroup}
219
- 

Return to bug 15522