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

(-)a/C4/Branch.pm (+5 lines)
Lines 490-495 sub DelBranch { Link Here
490
    my $sth = $dbh->prepare("delete from branches where branchcode = ?");
490
    my $sth = $dbh->prepare("delete from branches where branchcode = ?");
491
    $sth->execute($branchcode);
491
    $sth->execute($branchcode);
492
    $sth->finish;
492
    $sth->finish;
493
494
    # We have to delete the corresponding circulation rules
495
    $dbh->do("DELETE FROM circ_rules WHERE branchcode = ?", {}, $branchcode);
496
    $dbh->do("DELETE FROM borrower_circ_rules WHERE branchcode = ?", {}, $branchcode);
497
    $dbh->do("DELETE FROM item_circ_rules WHERE branchcode = ?", {}, $branchcode);
493
}
498
}
494
499
495
=head2 ModBranchCategoryInfo
500
=head2 ModBranchCategoryInfo
(-)a/C4/Circulation.pm (-15 / +18 lines)
Lines 1356-1368 patron of the given category can have at the given Link Here
1356
branch.  If the value is undef, no limit.
1356
branch.  If the value is undef, no limit.
1357
1357
1358
This will first check for a specific branch and
1358
This will first check for a specific branch and
1359
category match from branch_borrower_circ_rules. 
1359
category match from borrower_circ_rules.
1360
1360
1361
If no rule is found, it will then check default_branch_circ_rules
1361
If no rule is found, it will then check circ_rules
1362
(same branch, default category).  If no rule is found,
1362
(same branch, default category).  If no rule is found,
1363
it will then check default_borrower_circ_rules (default 
1363
it will then check the default branch (*), then failing that, circ_rules
1364
branch, same category), then failing that, default_circ_rules
1364
with the default branch and default category.
1365
(default branch, default category).
1366
1365
1367
If no rule has been found in the database, it will default to
1366
If no rule has been found in the database, it will default to
1368
the buillt in rule:
1367
the buillt in rule:
Lines 1380-1386 sub GetBranchBorrowerCircRule { Link Here
1380
    my $categorycode = shift;
1379
    my $categorycode = shift;
1381
1380
1382
    my $branch_cat_query = "SELECT maxissueqty
1381
    my $branch_cat_query = "SELECT maxissueqty
1383
                            FROM branch_borrower_circ_rules
1382
                            FROM borrower_circ_rules
1384
                            WHERE branchcode = ?
1383
                            WHERE branchcode = ?
1385
                            AND   categorycode = ?";
1384
                            AND   categorycode = ?";
1386
    my $dbh = C4::Context->dbh();
1385
    my $dbh = C4::Context->dbh();
Lines 1393-1399 sub GetBranchBorrowerCircRule { Link Here
1393
1392
1394
    # try same branch, default borrower category
1393
    # try same branch, default borrower category
1395
    my $branch_query = "SELECT maxissueqty
1394
    my $branch_query = "SELECT maxissueqty
1396
                        FROM default_branch_circ_rules
1395
                        FROM circ_rules
1397
                        WHERE branchcode = ?";
1396
                        WHERE branchcode = ?";
1398
    $sth = $dbh->prepare($branch_query);
1397
    $sth = $dbh->prepare($branch_query);
1399
    $sth->execute($branchcode);
1398
    $sth->execute($branchcode);
Lines 1403-1410 sub GetBranchBorrowerCircRule { Link Here
1403
1402
1404
    # try default branch, same borrower category
1403
    # try default branch, same borrower category
1405
    my $category_query = "SELECT maxissueqty
1404
    my $category_query = "SELECT maxissueqty
1406
                          FROM default_borrower_circ_rules
1405
                          FROM borrower_circ_rules
1407
                          WHERE categorycode = ?";
1406
                          WHERE categorycode = ?
1407
                          AND branchcode = '*'
1408
                          ";
1408
    $sth = $dbh->prepare($category_query);
1409
    $sth = $dbh->prepare($category_query);
1409
    $sth->execute($categorycode);
1410
    $sth->execute($categorycode);
1410
    if ($result = $sth->fetchrow_hashref()) {
1411
    if ($result = $sth->fetchrow_hashref()) {
Lines 1413-1419 sub GetBranchBorrowerCircRule { Link Here
1413
  
1414
  
1414
    # try default branch, default borrower category
1415
    # try default branch, default borrower category
1415
    my $default_query = "SELECT maxissueqty
1416
    my $default_query = "SELECT maxissueqty
1416
                          FROM default_circ_rules";
1417
                          FROM circ_rules
1418
                          WHERE branchcode = '*'";
1417
    $sth = $dbh->prepare($default_query);
1419
    $sth = $dbh->prepare($default_query);
1418
    $sth->execute();
1420
    $sth->execute();
1419
    if ($result = $sth->fetchrow_hashref()) {
1421
    if ($result = $sth->fetchrow_hashref()) {
Lines 1462-1478 sub GetBranchItemRule { Link Here
1462
1464
1463
    my @attempts = (
1465
    my @attempts = (
1464
        ['SELECT holdallowed, returnbranch
1466
        ['SELECT holdallowed, returnbranch
1465
            FROM branch_item_rules
1467
            FROM item_circ_rules
1466
            WHERE branchcode = ?
1468
            WHERE branchcode = ?
1467
              AND itemtype = ?', $branchcode, $itemtype],
1469
              AND itemtype = ?', $branchcode, $itemtype],
1468
        ['SELECT holdallowed, returnbranch
1470
        ['SELECT holdallowed, returnbranch
1469
            FROM default_branch_circ_rules
1471
            FROM circ_rules
1470
            WHERE branchcode = ?', $branchcode],
1472
            WHERE branchcode = ?', $branchcode],
1471
        ['SELECT holdallowed, returnbranch
1473
        ['SELECT holdallowed, returnbranch
1472
            FROM default_branch_item_rules
1474
            FROM item_circ_rules
1473
            WHERE itemtype = ?', $itemtype],
1475
            WHERE branchcode = "*" AND itemtype = ?', $itemtype],
1474
        ['SELECT holdallowed, returnbranch
1476
        ['SELECT holdallowed, returnbranch
1475
            FROM default_circ_rules'],
1477
            FROM circ_rules
1478
            WHERE branchcode = "*"'],
1476
    );
1479
    );
1477
1480
1478
    foreach my $attempt (@attempts) {
1481
    foreach my $attempt (@attempts) {
(-)a/admin/smart-rules.pl (-217 / +81 lines)
Lines 17-24 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
use CGI;
21
use CGI;
23
use C4::Context;
22
use C4::Context;
24
use C4::Output;
23
use C4::Output;
Lines 44-50 my ($template, $loggedinuser, $cookie) Link Here
44
43
45
my $type=$input->param('type');
44
my $type=$input->param('type');
46
my $branch = $input->param('branch') || ( C4::Branch::onlymine() ? ( C4::Branch::mybranch() || '*' ) : '*' );
45
my $branch = $input->param('branch') || ( C4::Branch::onlymine() ? ( C4::Branch::mybranch() || '*' ) : '*' );
47
my $op = $input->param('op');
46
my $op = $input->param('op') || '';
48
47
49
if ($op eq 'delete') {
48
if ($op eq 'delete') {
50
    my $itemtype     = $input->param('itemtype');
49
    my $itemtype     = $input->param('itemtype');
Lines 56-101 if ($op eq 'delete') { Link Here
56
}
55
}
57
elsif ($op eq 'delete-branch-cat') {
56
elsif ($op eq 'delete-branch-cat') {
58
    my $categorycode  = $input->param('categorycode');
57
    my $categorycode  = $input->param('categorycode');
59
    if ($branch eq "*") {
58
    if ($categorycode eq "*") {
60
        if ($categorycode eq "*") {
59
        my $sth_delete = $dbh->prepare("DELETE FROM circ_rules WHERE branchcode = ?");
61
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
60
        $sth_delete->execute( $branch );
62
            $sth_delete->execute();
63
        } else {
64
            my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
65
                                            WHERE categorycode = ?");
66
            $sth_delete->execute($categorycode);
67
        }
68
    } elsif ($categorycode eq "*") {
69
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
70
                                        WHERE branchcode = ?");
71
        $sth_delete->execute($branch);
72
    } else {
61
    } else {
73
        my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
62
        my $sth_delete = $dbh->prepare("DELETE FROM borrower_circ_rules
74
                                        WHERE branchcode = ?
63
                                        WHERE branchcode = ?
75
                                        AND categorycode = ?");
64
                                        AND categorycode = ?");
76
        $sth_delete->execute($branch, $categorycode);
65
        $sth_delete->execute( $branch, $categorycode );
77
    }
66
    }
78
}
67
}
79
elsif ($op eq 'delete-branch-item') {
68
elsif ($op eq 'delete-branch-item') {
80
    my $itemtype  = $input->param('itemtype');
69
    my $itemtype  = $input->param('itemtype');
81
    if ($branch eq "*") {
70
    if ($itemtype eq "*") {
82
        if ($itemtype eq "*") {
71
        my $sth_delete = $dbh->prepare("DELETE FROM circ_rules WHERE branchcode = ?");
83
            my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
72
        $sth_delete->execute( $branch);
84
            $sth_delete->execute();
85
        } else {
86
            my $sth_delete = $dbh->prepare("DELETE FROM default_branch_item_rules
87
                                            WHERE itemtype = ?");
88
            $sth_delete->execute($itemtype);
89
        }
90
    } elsif ($itemtype eq "*") {
91
        my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
92
                                        WHERE branchcode = ?");
93
        $sth_delete->execute($branch);
94
    } else {
73
    } else {
95
        my $sth_delete = $dbh->prepare("DELETE FROM branch_item_rules
74
        my $sth_delete = $dbh->prepare("DELETE FROM item_circ_rules
96
                                        WHERE branchcode = ?
75
                                        WHERE branchcode = ?
97
                                        AND itemtype = ?");
76
                                        AND itemtype = ?");
98
        $sth_delete->execute($branch, $itemtype);
77
        $sth_delete->execute( $branch, $itemtype );
99
    }
78
    }
100
}
79
}
101
# save the values entered
80
# save the values entered
Lines 142-181 elsif ($op eq "set-branch-defaults") { Link Here
142
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
121
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
143
    $holdallowed =~ s/\s//g;
122
    $holdallowed =~ s/\s//g;
144
    $holdallowed = undef if $holdallowed !~ /^\d+/;
123
    $holdallowed = undef if $holdallowed !~ /^\d+/;
145
124
    my $sth_search = $dbh->prepare("SELECT count(*) AS total
146
    if ($branch eq "*") {
125
                                    FROM circ_rules
147
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
126
                                    WHERE branchcode = ?");
148
                                        FROM default_circ_rules");
127
    my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
149
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
128
                                    (branchcode, maxissueqty, holdallowed, returnbranch)
150
                                        (maxissueqty, holdallowed, returnbranch)
129
                                    VALUES (?, ?, ?, ?)");
151
                                        VALUES (?, ?, ?)");
130
    my $sth_update = $dbh->prepare("UPDATE circ_rules
152
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
131
                                    SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
153
                                        SET maxissueqty = ?, holdallowed = ?, returnbranch = ?");
132
                                    WHERE branchcode = ?");
154
133
155
        $sth_search->execute();
134
    $sth_search->execute( $branch );
156
        my $res = $sth_search->fetchrow_hashref();
135
    my $res = $sth_search->fetchrow_hashref();
157
        if ($res->{total}) {
136
    if ($res->{total}) {
158
            $sth_update->execute($maxissueqty, $holdallowed, $returnbranch);
137
        $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch);
159
        } else {
160
            $sth_insert->execute($maxissueqty, $holdallowed, $returnbranch);
161
        }
162
    } else {
138
    } else {
163
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
139
        $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch);
164
                                        FROM default_branch_circ_rules
165
                                        WHERE branchcode = ?");
166
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
167
                                        (branchcode, maxissueqty, holdallowed, returnbranch)
168
                                        VALUES (?, ?, ?, ?)");
169
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
170
                                        SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
171
                                        WHERE branchcode = ?");
172
        $sth_search->execute($branch);
173
        my $res = $sth_search->fetchrow_hashref();
174
        if ($res->{total}) {
175
            $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch);
176
        } else {
177
            $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch);
178
        }
179
    }
140
    }
180
}
141
}
181
elsif ($op eq "add-branch-cat") {
142
elsif ($op eq "add-branch-cat") {
Lines 184-255 elsif ($op eq "add-branch-cat") { Link Here
184
    $maxissueqty =~ s/\s//g;
145
    $maxissueqty =~ s/\s//g;
185
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
146
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
186
147
187
    if ($branch eq "*") {
148
    if ($categorycode eq "*") {
188
        if ($categorycode eq "*") {
189
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
190
                                            FROM default_circ_rules");
191
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
192
                                            (maxissueqty)
193
                                            VALUES (?)");
194
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
195
                                            SET maxissueqty = ?");
196
197
            $sth_search->execute();
198
            my $res = $sth_search->fetchrow_hashref();
199
            if ($res->{total}) {
200
                $sth_update->execute($maxissueqty);
201
            } else {
202
                $sth_insert->execute($maxissueqty);
203
            }
204
        } else {
205
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
206
                                            FROM default_borrower_circ_rules
207
                                            WHERE categorycode = ?");
208
            my $sth_insert = $dbh->prepare("INSERT INTO default_borrower_circ_rules
209
                                            (categorycode, maxissueqty)
210
                                            VALUES (?, ?)");
211
            my $sth_update = $dbh->prepare("UPDATE default_borrower_circ_rules
212
                                            SET maxissueqty = ?
213
                                            WHERE categorycode = ?");
214
            $sth_search->execute($branch);
215
            my $res = $sth_search->fetchrow_hashref();
216
            if ($res->{total}) {
217
                $sth_update->execute($maxissueqty, $categorycode);
218
            } else {
219
                $sth_insert->execute($categorycode, $maxissueqty);
220
            }
221
        }
222
    } elsif ($categorycode eq "*") {
223
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
149
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
224
                                        FROM default_branch_circ_rules
150
                                        FROM circ_rules
225
                                        WHERE branchcode = ?");
151
                                        WHERE branchcode = ?");
226
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
152
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
227
                                        (branchcode, maxissueqty)
153
                                        (branchcode, maxissueqty)
228
                                        VALUES (?, ?)");
154
                                        VALUES (?, ?)");
229
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
155
        my $sth_update = $dbh->prepare("UPDATE circ_rules
230
                                        SET maxissueqty = ?
156
                                        SET maxissueqty = ?
231
                                        WHERE branchcode = ?");
157
                                        WHERE branchcode = ?");
232
        $sth_search->execute($branch);
158
159
        $sth_search->execute( $branch );
233
        my $res = $sth_search->fetchrow_hashref();
160
        my $res = $sth_search->fetchrow_hashref();
234
        if ($res->{total}) {
161
        if ($res->{total}) {
235
            $sth_update->execute($maxissueqty, $branch);
162
            $sth_update->execute( $branch, $maxissueqty );
236
        } else {
163
        } else {
237
            $sth_insert->execute($branch, $maxissueqty);
164
            $sth_insert->execute( $maxissueqty, $branch );
238
        }
165
        }
239
    } else {
166
    } else {
240
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
167
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
241
                                        FROM branch_borrower_circ_rules
168
                                        FROM borrower_circ_rules
242
                                        WHERE branchcode = ?
169
                                        WHERE branchcode = ?
243
                                        AND   categorycode = ?");
170
                                        AND categorycode = ?");
244
        my $sth_insert = $dbh->prepare("INSERT INTO branch_borrower_circ_rules
171
        my $sth_insert = $dbh->prepare("INSERT INTO borrower_circ_rules
245
                                        (branchcode, categorycode, maxissueqty)
172
                                        (branchcode, categorycode, maxissueqty)
246
                                        VALUES (?, ?, ?)");
173
                                        VALUES (?, ?, ?)");
247
        my $sth_update = $dbh->prepare("UPDATE branch_borrower_circ_rules
174
        my $sth_update = $dbh->prepare("UPDATE borrower_circ_rules
248
                                        SET maxissueqty = ?
175
                                        SET maxissueqty = ?
249
                                        WHERE branchcode = ?
176
                                        WHERE branchcode = ?
250
                                        AND categorycode = ?");
177
                                        AND categorycode = ?");
251
178
        $sth_search->execute( $branch, $categorycode );
252
        $sth_search->execute($branch, $categorycode);
253
        my $res = $sth_search->fetchrow_hashref();
179
        my $res = $sth_search->fetchrow_hashref();
254
        if ($res->{total}) {
180
        if ($res->{total}) {
255
            $sth_update->execute($maxissueqty, $branch, $categorycode);
181
            $sth_update->execute($maxissueqty, $branch, $categorycode);
Lines 265-316 elsif ($op eq "add-branch-item") { Link Here
265
    $holdallowed =~ s/\s//g;
191
    $holdallowed =~ s/\s//g;
266
    $holdallowed = undef if $holdallowed !~ /^\d+/;
192
    $holdallowed = undef if $holdallowed !~ /^\d+/;
267
193
268
    if ($branch eq "*") {
194
    if ($itemtype eq "*") {
269
        if ($itemtype eq "*") {
270
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
271
                                            FROM default_circ_rules");
272
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
273
                                            (holdallowed, returnbranch)
274
                                            VALUES (?, ?)");
275
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
276
                                            SET holdallowed = ?, returnbranch = ?");
277
278
            $sth_search->execute();
279
            my $res = $sth_search->fetchrow_hashref();
280
            if ($res->{total}) {
281
                $sth_update->execute($holdallowed, $returnbranch);
282
            } else {
283
                $sth_insert->execute($holdallowed, $returnbranch);
284
            }
285
        } else {
286
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
287
                                            FROM default_branch_item_rules
288
                                            WHERE itemtype = ?");
289
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
290
                                            (itemtype, holdallowed, returnbranch)
291
                                            VALUES (?, ?, ?)");
292
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
293
                                            SET holdallowed = ?, returnbranch = ?
294
                                            WHERE itemtype = ?");
295
            $sth_search->execute($itemtype);
296
            my $res = $sth_search->fetchrow_hashref();
297
            if ($res->{total}) {
298
                $sth_update->execute($holdallowed, $returnbranch, $itemtype);
299
            } else {
300
                $sth_insert->execute($itemtype, $holdallowed, $returnbranch);
301
            }
302
        }
303
    } elsif ($itemtype eq "*") {
304
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
195
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
305
                                        FROM default_branch_circ_rules
196
                                        FROM circ_rules
306
                                        WHERE branchcode = ?");
197
                                        WHERE branchcode = ?");
307
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
198
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
308
                                        (branchcode, holdallowed, returnbranch)
199
                                        (branchcode, holdallowed, returnbranch)
309
                                        VALUES (?, ?, ?)");
200
                                        VALUES (?, ?, ?)");
310
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
201
        my $sth_update = $dbh->prepare("UPDATE circ_rules
311
                                        SET holdallowed = ?, returnbranch = ?
202
                                        SET holdallowed = ?, returnbranch = ?
312
                                        WHERE branchcode = ?");
203
                                        WHERE branchcode = ?");
313
        $sth_search->execute($branch);
204
205
        $sth_search->execute( $branch );
314
        my $res = $sth_search->fetchrow_hashref();
206
        my $res = $sth_search->fetchrow_hashref();
315
        if ($res->{total}) {
207
        if ($res->{total}) {
316
            $sth_update->execute($holdallowed, $returnbranch, $branch);
208
            $sth_update->execute($holdallowed, $returnbranch, $branch);
Lines 319-336 elsif ($op eq "add-branch-item") { Link Here
319
        }
211
        }
320
    } else {
212
    } else {
321
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
213
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
322
                                        FROM branch_item_rules
214
                                        FROM item_circ_rules
323
                                        WHERE branchcode = ?
215
                                        WHERE itemtype = ?");
324
                                        AND   itemtype = ?");
216
        my $sth_insert = $dbh->prepare("INSERT INTO item_circ_rules
325
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
326
                                        (branchcode, itemtype, holdallowed, returnbranch)
217
                                        (branchcode, itemtype, holdallowed, returnbranch)
327
                                        VALUES (?, ?, ?, ?)");
218
                                        VALUES (?, ?, ?, ?)");
328
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
219
        my $sth_update = $dbh->prepare("UPDATE item_circ_rules
329
                                        SET holdallowed = ?, returnbranch = ?
220
                                        SET holdallowed = ?, returnbranch = ?
330
                                        WHERE branchcode = ?
221
                                        WHERE branchcode = ?
331
                                        AND itemtype = ?");
222
                                        AND itemtype = ?");
332
223
        $sth_search->execute($itemtype);
333
        $sth_search->execute($branch, $itemtype);
334
        my $res = $sth_search->fetchrow_hashref();
224
        my $res = $sth_search->fetchrow_hashref();
335
        if ($res->{total}) {
225
        if ($res->{total}) {
336
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
226
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
Lines 385-391 while (my $row = $sth2->fetchrow_hashref) { Link Here
385
    $row->{'humancategorycode'} ||= $row->{'categorycode'};
275
    $row->{'humancategorycode'} ||= $row->{'categorycode'};
386
    $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
276
    $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
387
    $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
277
    $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
388
    if ($row->{'hardduedate'} ne '0000-00-00') {
278
    if ($row->{hardduedate} and $row->{'hardduedate'} ne '0000-00-00') {
389
       $row->{'hardduedate'} = format_date( $row->{'hardduedate'});
279
       $row->{'hardduedate'} = format_date( $row->{'hardduedate'});
390
       $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
280
       $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
391
       $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} ==  0);
281
       $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} ==  0);
Lines 400-422 $sth->finish; Link Here
400
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
290
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
401
291
402
my $sth_branch_cat;
292
my $sth_branch_cat;
403
if ($branch eq "*") {
293
$sth_branch_cat = $dbh->prepare("
404
    $sth_branch_cat = $dbh->prepare("
294
    SELECT borrower_circ_rules.*, categories.description AS humancategorycode
405
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
295
    FROM borrower_circ_rules
406
        FROM default_borrower_circ_rules
296
    JOIN categories USING (categorycode)
407
        JOIN categories USING (categorycode)
297
    WHERE borrower_circ_rules.branchcode = ?
408
        
298
");
409
    ");
299
$sth_branch_cat->execute($branch);
410
    $sth_branch_cat->execute();
411
} else {
412
    $sth_branch_cat = $dbh->prepare("
413
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
414
        FROM branch_borrower_circ_rules
415
        JOIN categories USING (categorycode)
416
        WHERE branch_borrower_circ_rules.branchcode = ?
417
    ");
418
    $sth_branch_cat->execute($branch);
419
}
420
300
421
my @branch_cat_rules = ();
301
my @branch_cat_rules = ();
422
while (my $row = $sth_branch_cat->fetchrow_hashref) {
302
while (my $row = $sth_branch_cat->fetchrow_hashref) {
Lines 432-453 foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { Link Here
432
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
312
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
433
313
434
my $sth_branch_item;
314
my $sth_branch_item;
435
if ($branch eq "*") {
315
$sth_branch_item = $dbh->prepare("
436
    $sth_branch_item = $dbh->prepare("
316
    SELECT item_circ_rules.*, itemtypes.description AS humanitemtype
437
        SELECT default_branch_item_rules.*, itemtypes.description AS humanitemtype
317
    FROM item_circ_rules
438
        FROM default_branch_item_rules
318
    JOIN itemtypes USING (itemtype)
439
        JOIN itemtypes USING (itemtype)
319
    WHERE item_circ_rules.branchcode = ?
440
    ");
320
");
441
    $sth_branch_item->execute();
321
$sth_branch_item->execute($branch);
442
} else {
443
    $sth_branch_item = $dbh->prepare("
444
        SELECT branch_item_rules.*, itemtypes.description AS humanitemtype
445
        FROM branch_item_rules
446
        JOIN itemtypes USING (itemtype)
447
        WHERE branch_item_rules.branchcode = ?
448
    ");
449
    $sth_branch_item->execute($branch);
450
}
451
322
452
my @branch_item_rules = ();
323
my @branch_item_rules = ();
453
while (my $row = $sth_branch_item->fetchrow_hashref) {
324
while (my $row = $sth_branch_item->fetchrow_hashref) {
Lines 466-485 $template->param(branch_item_rule_loop => \@sorted_branch_item_rules); Link Here
466
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
337
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
467
338
468
my $sth_defaults;
339
my $sth_defaults;
469
if ($branch eq "*") {
340
$sth_defaults = $dbh->prepare("
470
    $sth_defaults = $dbh->prepare("
341
    SELECT *
471
        SELECT *
342
    FROM circ_rules
472
        FROM default_circ_rules
343
    WHERE branchcode = ?
473
    ");
344
");
474
    $sth_defaults->execute();
345
$sth_defaults->execute($branch);
475
} else {
476
    $sth_defaults = $dbh->prepare("
477
        SELECT *
478
        FROM default_branch_circ_rules
479
        WHERE branchcode = ?
480
    ");
481
    $sth_defaults->execute($branch);
482
}
483
346
484
my $defaults = $sth_defaults->fetchrow_hashref;
347
my $defaults = $sth_defaults->fetchrow_hashref;
485
348
Lines 493-506 if ($defaults) { Link Here
493
356
494
$template->param(default_rules => ($defaults ? 1 : 0));
357
$template->param(default_rules => ($defaults ? 1 : 0));
495
358
496
$template->param(categoryloop => \@category_loop,
359
$template->param(
497
                        itemtypeloop => \@itemtypes,
360
    categoryloop   => \@category_loop,
498
                        rules => \@sorted_row_loop,
361
    itemtypeloop   => \@itemtypes,
499
                        branchloop => \@branchloop,
362
    rules          => \@sorted_row_loop,
500
                        humanbranch => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''),
363
    branchloop     => \@branchloop,
501
                        current_branch => $branch,
364
    humanbranch    => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''),
502
                        definedbranch => scalar(@sorted_row_loop)>0 
365
    current_branch => $branch,
503
                        );
366
    definedbranch  => scalar(@sorted_row_loop)>0,
367
);
504
output_html_with_http_headers $input, $cookie, $template->output;
368
output_html_with_http_headers $input, $cookie, $template->output;
505
369
506
exit 0;
370
exit 0;
(-)a/installer/data/mysql/kohastructure.sql (-51 / +19 lines)
Lines 466-538 CREATE TABLE collections_tracking ( Link Here
466
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
466
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
467
467
468
--
468
--
469
-- Table structure for table `borrower_branch_circ_rules`
469
-- Table structure for table `circ_rules`
470
--
470
--
471
471
472
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
472
DROP TABLE IF EXISTS `circ_rules`;
473
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
473
CREATE TABLE `circ_rules` (
474
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
475
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
476
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
477
  PRIMARY KEY (`categorycode`, `branchcode`),
478
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
479
    ON DELETE CASCADE ON UPDATE CASCADE,
480
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
481
    ON DELETE CASCADE ON UPDATE CASCADE
482
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
483
484
--
485
-- Table structure for table `default_borrower_circ_rules`
486
--
487
488
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
489
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
490
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
491
  `maxissueqty` int(4) default NULL,
492
  PRIMARY KEY (`categorycode`),
493
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
494
    ON DELETE CASCADE ON UPDATE CASCADE
495
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
496
497
--
498
-- Table structure for table `default_branch_circ_rules`
499
--
500
501
DROP TABLE IF EXISTS `default_branch_circ_rules`;
502
CREATE TABLE `default_branch_circ_rules` (
503
  `branchcode` VARCHAR(10) NOT NULL,
474
  `branchcode` VARCHAR(10) NOT NULL,
504
  `maxissueqty` int(4) default NULL,
475
  `maxissueqty` int(4) default NULL,
505
  `holdallowed` tinyint(1) default NULL,
476
  `holdallowed` tinyint(1) default NULL,
506
  `returnbranch` varchar(15) default NULL,
477
  `returnbranch` varchar(15) default NULL,
507
  PRIMARY KEY (`branchcode`),
478
  PRIMARY KEY (`branchcode`),
508
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
509
    ON DELETE CASCADE ON UPDATE CASCADE
510
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
479
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
511
480
512
--
481
--
513
-- Table structure for table `default_branch_item_rules`
482
-- Table structure for table `borrower_circ_rules`
514
--
483
--
515
DROP TABLE IF EXISTS `default_branch_item_rules`;
484
516
CREATE TABLE `default_branch_item_rules` (
485
DROP TABLE IF EXISTS `borrower_circ_rules`;
517
  `itemtype` varchar(10) NOT NULL,
486
CREATE TABLE `borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
518
  `holdallowed` tinyint(1) default NULL,
487
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
519
  `returnbranch` varchar(15) default NULL,
488
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
520
  PRIMARY KEY  (`itemtype`),
489
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
521
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
490
  PRIMARY KEY (`categorycode`, `branchcode`),
522
    ON DELETE CASCADE ON UPDATE CASCADE
523
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
491
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
524
492
525
--
493
--
526
-- Table structure for table `default_circ_rules`
494
-- Table structure for table `item_circ_rules`
527
--
495
--
528
496
529
DROP TABLE IF EXISTS `default_circ_rules`;
497
DROP TABLE IF EXISTS `item_circ_rules`;
530
CREATE TABLE `default_circ_rules` (
498
CREATE TABLE `item_circ_rules` (
531
    `singleton` enum('singleton') NOT NULL default 'singleton',
499
  `branchcode` varchar(10) NOT NULL,
532
    `maxissueqty` int(4) default NULL,
500
  `itemtype` varchar(10) NOT NULL,
533
    `holdallowed` int(1) default NULL,
501
  `holdallowed` tinyint(1) default NULL,
534
    `returnbranch` varchar(15) default NULL,
502
  `returnbranch` varchar(15) default NULL,
535
    PRIMARY KEY (`singleton`)
503
  PRIMARY KEY  (`branchcode`, `itemtype`),
536
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
504
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
537
505
538
--
506
--
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +57 lines)
Lines 5696-5701 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5696
    SetVersion($DBversion);
5696
    SetVersion($DBversion);
5697
}
5697
}
5698
5698
5699
5700
$DBversion = "3.09.00.XXX";
5701
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
5702
    $dbh->do(qq{
5703
        CREATE TABLE circ_rules (
5704
            branchcode VARCHAR(10) NOT NULL,
5705
            maxissueqty INT(4) DEFAULT NULL,
5706
            holdallowed TINYINT(1) DEFAULT NULL,
5707
            returnbranch VARCHAR(15) DEFAULT NULL,
5708
            PRIMARY KEY(branchcode)
5709
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5710
    });
5711
    $dbh->do(qq{
5712
        CREATE TABLE borrower_circ_rules (
5713
            branchcode VARCHAR(10) NOT NULL,
5714
            categorycode VARCHAR(10) NOT NULL,
5715
            maxissueqty INT(4) DEFAULT NULL,
5716
            PRIMARY KEY(branchcode, categorycode)
5717
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5718
    });
5719
    $dbh->do(qq{
5720
        CREATE TABLE item_circ_rules (
5721
            branchcode VARCHAR(10) NOT NULL,
5722
            itemtype VARCHAR(10) NOT NULL,
5723
            holdallowed TINYINT(1) DEFAULT NULL,
5724
            returnbranch VARCHAR(15) DEFAULT NULL,
5725
            PRIMARY KEY(branchcode, itemtype)
5726
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5727
    });
5728
    $dbh->do(qq{
5729
        INSERT INTO circ_rules(branchcode, maxissueqty, holdallowed, returnbranch)
5730
        SELECT '*', maxissueqty, holdallowed, returnbranch FROM default_circ_rules;
5731
    });
5732
    $dbh->do(qq{
5733
        INSERT INTO circ_rules(branchcode, maxissueqty, holdallowed, returnbranch)
5734
        SELECT branchcode, maxissueqty, holdallowed, returnbranch FROM default_branch_circ_rules;
5735
    });
5736
    $dbh->do(qq{
5737
        INSERT INTO borrower_circ_rules( branchcode, categorycode, maxissueqty )
5738
        SELECT '*', categorycode, maxissueqty FROM default_borrower_circ_rules;
5739
    });
5740
    $dbh->do(qq{
5741
        INSERT INTO borrower_circ_rules( branchcode, categorycode, maxissueqty )
5742
        SELECT branchcode, categorycode, maxissueqty FROM branch_borrower_circ_rules;
5743
    });
5744
    $dbh->do(qq{
5745
        INSERT INTO item_circ_rules( branchcode, itemtype, holdallowed, returnbranch )
5746
        SELECT '*', itemtype, holdallowed, returnbranch FROM default_branch_item_rules;
5747
    });
5748
    $dbh->do(qq{
5749
        INSERT INTO item_circ_rules( branchcode, itemtype, holdallowed, returnbranch )
5750
        SELECT branchcode, itemtype, holdallowed, returnbranch FROM branch_item_rules;
5751
    });
5752
    print "Upgrade to $DBversion done (Replace circ rules tables. 3 new tables: circ_rules, borrower_circ_rules, item_circ_rules)\n";
5753
    SetVersion($DBversion);
5754
}
5755
5699
=head1 FUNCTIONS
5756
=head1 FUNCTIONS
5700
5757
5701
=head2 TableExists($table)
5758
=head2 TableExists($table)
5702
- 

Return to bug 8369