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

(-)a/C4/Branch.pm (+5 lines)
Lines 491-496 sub DelBranch { Link Here
491
    my $sth = $dbh->prepare("delete from branches where branchcode = ?");
491
    my $sth = $dbh->prepare("delete from branches where branchcode = ?");
492
    $sth->execute($branchcode);
492
    $sth->execute($branchcode);
493
    $sth->finish;
493
    $sth->finish;
494
495
    # We have to delete the corresponding circulation rules
496
    $dbh->do("DELETE FROM circ_rules WHERE branchcode = ?", {}, $branchcode);
497
    $dbh->do("DELETE FROM borrower_circ_rules WHERE branchcode = ?", {}, $branchcode);
498
    $dbh->do("DELETE FROM item_circ_rules WHERE branchcode = ?", {}, $branchcode);
494
}
499
}
495
500
496
=head2 ModBranchCategoryInfo
501
=head2 ModBranchCategoryInfo
(-)a/C4/Circulation.pm (-15 / +18 lines)
Lines 1467-1479 patron of the given category can have at the given Link Here
1467
branch.  If the value is undef, no limit.
1467
branch.  If the value is undef, no limit.
1468
1468
1469
This will first check for a specific branch and
1469
This will first check for a specific branch and
1470
category match from branch_borrower_circ_rules. 
1470
category match from borrower_circ_rules.
1471
1471
1472
If no rule is found, it will then check default_branch_circ_rules
1472
If no rule is found, it will then check circ_rules
1473
(same branch, default category).  If no rule is found,
1473
(same branch, default category).  If no rule is found,
1474
it will then check default_borrower_circ_rules (default 
1474
it will then check the default branch (*), then failing that, circ_rules
1475
branch, same category), then failing that, default_circ_rules
1475
with the default branch and default category.
1476
(default branch, default category).
1477
1476
1478
If no rule has been found in the database, it will default to
1477
If no rule has been found in the database, it will default to
1479
the buillt in rule:
1478
the buillt in rule:
Lines 1491-1497 sub GetBranchBorrowerCircRule { Link Here
1491
    my $categorycode = shift;
1490
    my $categorycode = shift;
1492
1491
1493
    my $branch_cat_query = "SELECT maxissueqty
1492
    my $branch_cat_query = "SELECT maxissueqty
1494
                            FROM branch_borrower_circ_rules
1493
                            FROM borrower_circ_rules
1495
                            WHERE branchcode = ?
1494
                            WHERE branchcode = ?
1496
                            AND   categorycode = ?";
1495
                            AND   categorycode = ?";
1497
    my $dbh = C4::Context->dbh();
1496
    my $dbh = C4::Context->dbh();
Lines 1504-1510 sub GetBranchBorrowerCircRule { Link Here
1504
1503
1505
    # try same branch, default borrower category
1504
    # try same branch, default borrower category
1506
    my $branch_query = "SELECT maxissueqty
1505
    my $branch_query = "SELECT maxissueqty
1507
                        FROM default_branch_circ_rules
1506
                        FROM circ_rules
1508
                        WHERE branchcode = ?";
1507
                        WHERE branchcode = ?";
1509
    $sth = $dbh->prepare($branch_query);
1508
    $sth = $dbh->prepare($branch_query);
1510
    $sth->execute($branchcode);
1509
    $sth->execute($branchcode);
Lines 1514-1521 sub GetBranchBorrowerCircRule { Link Here
1514
1513
1515
    # try default branch, same borrower category
1514
    # try default branch, same borrower category
1516
    my $category_query = "SELECT maxissueqty
1515
    my $category_query = "SELECT maxissueqty
1517
                          FROM default_borrower_circ_rules
1516
                          FROM borrower_circ_rules
1518
                          WHERE categorycode = ?";
1517
                          WHERE categorycode = ?
1518
                          AND branchcode = '*'
1519
                          ";
1519
    $sth = $dbh->prepare($category_query);
1520
    $sth = $dbh->prepare($category_query);
1520
    $sth->execute($categorycode);
1521
    $sth->execute($categorycode);
1521
    if ($result = $sth->fetchrow_hashref()) {
1522
    if ($result = $sth->fetchrow_hashref()) {
Lines 1524-1530 sub GetBranchBorrowerCircRule { Link Here
1524
  
1525
  
1525
    # try default branch, default borrower category
1526
    # try default branch, default borrower category
1526
    my $default_query = "SELECT maxissueqty
1527
    my $default_query = "SELECT maxissueqty
1527
                          FROM default_circ_rules";
1528
                          FROM circ_rules
1529
                          WHERE branchcode = '*'";
1528
    $sth = $dbh->prepare($default_query);
1530
    $sth = $dbh->prepare($default_query);
1529
    $sth->execute();
1531
    $sth->execute();
1530
    if ($result = $sth->fetchrow_hashref()) {
1532
    if ($result = $sth->fetchrow_hashref()) {
Lines 1573-1589 sub GetBranchItemRule { Link Here
1573
1575
1574
    my @attempts = (
1576
    my @attempts = (
1575
        ['SELECT holdallowed, returnbranch
1577
        ['SELECT holdallowed, returnbranch
1576
            FROM branch_item_rules
1578
            FROM item_circ_rules
1577
            WHERE branchcode = ?
1579
            WHERE branchcode = ?
1578
              AND itemtype = ?', $branchcode, $itemtype],
1580
              AND itemtype = ?', $branchcode, $itemtype],
1579
        ['SELECT holdallowed, returnbranch
1581
        ['SELECT holdallowed, returnbranch
1580
            FROM default_branch_circ_rules
1582
            FROM circ_rules
1581
            WHERE branchcode = ?', $branchcode],
1583
            WHERE branchcode = ?', $branchcode],
1582
        ['SELECT holdallowed, returnbranch
1584
        ['SELECT holdallowed, returnbranch
1583
            FROM default_branch_item_rules
1585
            FROM item_circ_rules
1584
            WHERE itemtype = ?', $itemtype],
1586
            WHERE branchcode = "*" AND itemtype = ?', $itemtype],
1585
        ['SELECT holdallowed, returnbranch
1587
        ['SELECT holdallowed, returnbranch
1586
            FROM default_circ_rules'],
1588
            FROM circ_rules
1589
            WHERE branchcode = "*"'],
1587
    );
1590
    );
1588
1591
1589
    foreach my $attempt (@attempts) {
1592
    foreach my $attempt (@attempts) {
(-)a/admin/smart-rules.pl (-216 / +80 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 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 / +56 lines)
Lines 6134-6139 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
6134
    SetVersion ($DBversion);
6134
    SetVersion ($DBversion);
6135
}
6135
}
6136
6136
6137
$DBversion = "3.09.00.XXX";
6138
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
6139
    $dbh->do(qq{
6140
        CREATE TABLE circ_rules (
6141
            branchcode VARCHAR(10) NOT NULL,
6142
            maxissueqty INT(4) DEFAULT NULL,
6143
            holdallowed TINYINT(1) DEFAULT NULL,
6144
            returnbranch VARCHAR(15) DEFAULT NULL,
6145
            PRIMARY KEY(branchcode)
6146
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6147
    });
6148
    $dbh->do(qq{
6149
        CREATE TABLE borrower_circ_rules (
6150
            branchcode VARCHAR(10) NOT NULL,
6151
            categorycode VARCHAR(10) NOT NULL,
6152
            maxissueqty INT(4) DEFAULT NULL,
6153
            PRIMARY KEY(branchcode, categorycode)
6154
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6155
    });
6156
    $dbh->do(qq{
6157
        CREATE TABLE item_circ_rules (
6158
            branchcode VARCHAR(10) NOT NULL,
6159
            itemtype VARCHAR(10) NOT NULL,
6160
            holdallowed TINYINT(1) DEFAULT NULL,
6161
            returnbranch VARCHAR(15) DEFAULT NULL,
6162
            PRIMARY KEY(branchcode, itemtype)
6163
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6164
    });
6165
    $dbh->do(qq{
6166
        INSERT INTO circ_rules(branchcode, maxissueqty, holdallowed, returnbranch)
6167
        SELECT '*', maxissueqty, holdallowed, returnbranch FROM default_circ_rules;
6168
    });
6169
    $dbh->do(qq{
6170
        INSERT INTO circ_rules(branchcode, maxissueqty, holdallowed, returnbranch)
6171
        SELECT branchcode, maxissueqty, holdallowed, returnbranch FROM default_branch_circ_rules;
6172
    });
6173
    $dbh->do(qq{
6174
        INSERT INTO borrower_circ_rules( branchcode, categorycode, maxissueqty )
6175
        SELECT '*', categorycode, maxissueqty FROM default_borrower_circ_rules;
6176
    });
6177
    $dbh->do(qq{
6178
        INSERT INTO borrower_circ_rules( branchcode, categorycode, maxissueqty )
6179
        SELECT branchcode, categorycode, maxissueqty FROM branch_borrower_circ_rules;
6180
    });
6181
    $dbh->do(qq{
6182
        INSERT INTO item_circ_rules( branchcode, itemtype, holdallowed, returnbranch )
6183
        SELECT '*', itemtype, holdallowed, returnbranch FROM default_branch_item_rules;
6184
    });
6185
    $dbh->do(qq{
6186
        INSERT INTO item_circ_rules( branchcode, itemtype, holdallowed, returnbranch )
6187
        SELECT branchcode, itemtype, holdallowed, returnbranch FROM branch_item_rules;
6188
    });
6189
    print "Upgrade to $DBversion done (Replace circ rules tables. 3 new tables: circ_rules, borrower_circ_rules, item_circ_rules)\n";
6190
    SetVersion($DBversion);
6191
}
6192
6137
=head1 FUNCTIONS
6193
=head1 FUNCTIONS
6138
6194
6139
=head2 TableExists($table)
6195
=head2 TableExists($table)
6140
- 

Return to bug 8369