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