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

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