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