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

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