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 1494-1506 patron of the given category can have at the given Link Here
1494
branch.  If the value is undef, no limit.
1494
branch.  If the value is undef, no limit.
1495
1495
1496
This will first check for a specific branch and
1496
This will first check for a specific branch and
1497
category match from branch_borrower_circ_rules. 
1497
category match from borrower_circ_rules.
1498
1498
1499
If no rule is found, it will then check default_branch_circ_rules
1499
If no rule is found, it will then check circ_rules
1500
(same branch, default category).  If no rule is found,
1500
(same branch, default category).  If no rule is found,
1501
it will then check default_borrower_circ_rules (default 
1501
it will then check the default branch (*), then failing that, circ_rules
1502
branch, same category), then failing that, default_circ_rules
1502
with the default branch and default category.
1503
(default branch, default category).
1504
1503
1505
If no rule has been found in the database, it will default to
1504
If no rule has been found in the database, it will default to
1506
the buillt in rule:
1505
the buillt in rule:
Lines 1518-1524 sub GetBranchBorrowerCircRule { Link Here
1518
    my $categorycode = shift;
1517
    my $categorycode = shift;
1519
1518
1520
    my $branch_cat_query = "SELECT maxissueqty
1519
    my $branch_cat_query = "SELECT maxissueqty
1521
                            FROM branch_borrower_circ_rules
1520
                            FROM borrower_circ_rules
1522
                            WHERE branchcode = ?
1521
                            WHERE branchcode = ?
1523
                            AND   categorycode = ?";
1522
                            AND   categorycode = ?";
1524
    my $dbh = C4::Context->dbh();
1523
    my $dbh = C4::Context->dbh();
Lines 1531-1537 sub GetBranchBorrowerCircRule { Link Here
1531
1530
1532
    # try same branch, default borrower category
1531
    # try same branch, default borrower category
1533
    my $branch_query = "SELECT maxissueqty
1532
    my $branch_query = "SELECT maxissueqty
1534
                        FROM default_branch_circ_rules
1533
                        FROM circ_rules
1535
                        WHERE branchcode = ?";
1534
                        WHERE branchcode = ?";
1536
    $sth = $dbh->prepare($branch_query);
1535
    $sth = $dbh->prepare($branch_query);
1537
    $sth->execute($branchcode);
1536
    $sth->execute($branchcode);
Lines 1541-1548 sub GetBranchBorrowerCircRule { Link Here
1541
1540
1542
    # try default branch, same borrower category
1541
    # try default branch, same borrower category
1543
    my $category_query = "SELECT maxissueqty
1542
    my $category_query = "SELECT maxissueqty
1544
                          FROM default_borrower_circ_rules
1543
                          FROM borrower_circ_rules
1545
                          WHERE categorycode = ?";
1544
                          WHERE categorycode = ?
1545
                          AND branchcode = '*'
1546
                          ";
1546
    $sth = $dbh->prepare($category_query);
1547
    $sth = $dbh->prepare($category_query);
1547
    $sth->execute($categorycode);
1548
    $sth->execute($categorycode);
1548
    if ($result = $sth->fetchrow_hashref()) {
1549
    if ($result = $sth->fetchrow_hashref()) {
Lines 1551-1557 sub GetBranchBorrowerCircRule { Link Here
1551
  
1552
  
1552
    # try default branch, default borrower category
1553
    # try default branch, default borrower category
1553
    my $default_query = "SELECT maxissueqty
1554
    my $default_query = "SELECT maxissueqty
1554
                          FROM default_circ_rules";
1555
                          FROM circ_rules
1556
                          WHERE branchcode = '*'";
1555
    $sth = $dbh->prepare($default_query);
1557
    $sth = $dbh->prepare($default_query);
1556
    $sth->execute();
1558
    $sth->execute();
1557
    if ($result = $sth->fetchrow_hashref()) {
1559
    if ($result = $sth->fetchrow_hashref()) {
Lines 1600-1616 sub GetBranchItemRule { Link Here
1600
1602
1601
    my @attempts = (
1603
    my @attempts = (
1602
        ['SELECT holdallowed, returnbranch
1604
        ['SELECT holdallowed, returnbranch
1603
            FROM branch_item_rules
1605
            FROM item_circ_rules
1604
            WHERE branchcode = ?
1606
            WHERE branchcode = ?
1605
              AND itemtype = ?', $branchcode, $itemtype],
1607
              AND itemtype = ?', $branchcode, $itemtype],
1606
        ['SELECT holdallowed, returnbranch
1608
        ['SELECT holdallowed, returnbranch
1607
            FROM default_branch_circ_rules
1609
            FROM circ_rules
1608
            WHERE branchcode = ?', $branchcode],
1610
            WHERE branchcode = ?', $branchcode],
1609
        ['SELECT holdallowed, returnbranch
1611
        ['SELECT holdallowed, returnbranch
1610
            FROM default_branch_item_rules
1612
            FROM item_circ_rules
1611
            WHERE itemtype = ?', $itemtype],
1613
            WHERE branchcode = "*" AND itemtype = ?', $itemtype],
1612
        ['SELECT holdallowed, returnbranch
1614
        ['SELECT holdallowed, returnbranch
1613
            FROM default_circ_rules'],
1615
            FROM circ_rules
1616
            WHERE branchcode = "*"'],
1614
    );
1617
    );
1615
1618
1616
    foreach my $attempt (@attempts) {
1619
    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 143-182 elsif ($op eq "set-branch-defaults") { Link Here
143
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
122
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
144
    $holdallowed =~ s/\s//g;
123
    $holdallowed =~ s/\s//g;
145
    $holdallowed = undef if $holdallowed !~ /^\d+/;
124
    $holdallowed = undef if $holdallowed !~ /^\d+/;
146
125
    my $sth_search = $dbh->prepare("SELECT count(*) AS total
147
    if ($branch eq "*") {
126
                                    FROM circ_rules
148
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
127
                                    WHERE branchcode = ?");
149
                                        FROM default_circ_rules");
128
    my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
150
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
129
                                    (branchcode, maxissueqty, holdallowed, returnbranch)
151
                                        (maxissueqty, holdallowed, returnbranch)
130
                                    VALUES (?, ?, ?, ?)");
152
                                        VALUES (?, ?, ?)");
131
    my $sth_update = $dbh->prepare("UPDATE circ_rules
153
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
132
                                    SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
154
                                        SET maxissueqty = ?, holdallowed = ?, returnbranch = ?");
133
                                    WHERE branchcode = ?");
155
134
156
        $sth_search->execute();
135
    $sth_search->execute( $branch );
157
        my $res = $sth_search->fetchrow_hashref();
136
    my $res = $sth_search->fetchrow_hashref();
158
        if ($res->{total}) {
137
    if ($res->{total}) {
159
            $sth_update->execute($maxissueqty, $holdallowed, $returnbranch);
138
        $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch);
160
        } else {
161
            $sth_insert->execute($maxissueqty, $holdallowed, $returnbranch);
162
        }
163
    } else {
139
    } else {
164
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
140
        $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch);
165
                                        FROM default_branch_circ_rules
166
                                        WHERE branchcode = ?");
167
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
168
                                        (branchcode, maxissueqty, holdallowed, returnbranch)
169
                                        VALUES (?, ?, ?, ?)");
170
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
171
                                        SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
172
                                        WHERE branchcode = ?");
173
        $sth_search->execute($branch);
174
        my $res = $sth_search->fetchrow_hashref();
175
        if ($res->{total}) {
176
            $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch);
177
        } else {
178
            $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch);
179
        }
180
    }
141
    }
181
}
142
}
182
elsif ($op eq "add-branch-cat") {
143
elsif ($op eq "add-branch-cat") {
Lines 185-256 elsif ($op eq "add-branch-cat") { Link Here
185
    $maxissueqty =~ s/\s//g;
146
    $maxissueqty =~ s/\s//g;
186
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
147
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
187
148
188
    if ($branch eq "*") {
149
    if ($categorycode eq "*") {
189
        if ($categorycode eq "*") {
190
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
191
                                            FROM default_circ_rules");
192
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
193
                                            (maxissueqty)
194
                                            VALUES (?)");
195
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
196
                                            SET maxissueqty = ?");
197
198
            $sth_search->execute();
199
            my $res = $sth_search->fetchrow_hashref();
200
            if ($res->{total}) {
201
                $sth_update->execute($maxissueqty);
202
            } else {
203
                $sth_insert->execute($maxissueqty);
204
            }
205
        } else {
206
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
207
                                            FROM default_borrower_circ_rules
208
                                            WHERE categorycode = ?");
209
            my $sth_insert = $dbh->prepare("INSERT INTO default_borrower_circ_rules
210
                                            (categorycode, maxissueqty)
211
                                            VALUES (?, ?)");
212
            my $sth_update = $dbh->prepare("UPDATE default_borrower_circ_rules
213
                                            SET maxissueqty = ?
214
                                            WHERE categorycode = ?");
215
            $sth_search->execute($branch);
216
            my $res = $sth_search->fetchrow_hashref();
217
            if ($res->{total}) {
218
                $sth_update->execute($maxissueqty, $categorycode);
219
            } else {
220
                $sth_insert->execute($categorycode, $maxissueqty);
221
            }
222
        }
223
    } elsif ($categorycode eq "*") {
224
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
150
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
225
                                        FROM default_branch_circ_rules
151
                                        FROM circ_rules
226
                                        WHERE branchcode = ?");
152
                                        WHERE branchcode = ?");
227
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
153
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
228
                                        (branchcode, maxissueqty)
154
                                        (branchcode, maxissueqty)
229
                                        VALUES (?, ?)");
155
                                        VALUES (?, ?)");
230
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
156
        my $sth_update = $dbh->prepare("UPDATE circ_rules
231
                                        SET maxissueqty = ?
157
                                        SET maxissueqty = ?
232
                                        WHERE branchcode = ?");
158
                                        WHERE branchcode = ?");
233
        $sth_search->execute($branch);
159
160
        $sth_search->execute( $branch );
234
        my $res = $sth_search->fetchrow_hashref();
161
        my $res = $sth_search->fetchrow_hashref();
235
        if ($res->{total}) {
162
        if ($res->{total}) {
236
            $sth_update->execute($maxissueqty, $branch);
163
            $sth_update->execute( $branch, $maxissueqty );
237
        } else {
164
        } else {
238
            $sth_insert->execute($branch, $maxissueqty);
165
            $sth_insert->execute( $maxissueqty, $branch );
239
        }
166
        }
240
    } else {
167
    } else {
241
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
168
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
242
                                        FROM branch_borrower_circ_rules
169
                                        FROM borrower_circ_rules
243
                                        WHERE branchcode = ?
170
                                        WHERE branchcode = ?
244
                                        AND   categorycode = ?");
171
                                        AND categorycode = ?");
245
        my $sth_insert = $dbh->prepare("INSERT INTO branch_borrower_circ_rules
172
        my $sth_insert = $dbh->prepare("INSERT INTO borrower_circ_rules
246
                                        (branchcode, categorycode, maxissueqty)
173
                                        (branchcode, categorycode, maxissueqty)
247
                                        VALUES (?, ?, ?)");
174
                                        VALUES (?, ?, ?)");
248
        my $sth_update = $dbh->prepare("UPDATE branch_borrower_circ_rules
175
        my $sth_update = $dbh->prepare("UPDATE borrower_circ_rules
249
                                        SET maxissueqty = ?
176
                                        SET maxissueqty = ?
250
                                        WHERE branchcode = ?
177
                                        WHERE branchcode = ?
251
                                        AND categorycode = ?");
178
                                        AND categorycode = ?");
252
179
        $sth_search->execute( $branch, $categorycode );
253
        $sth_search->execute($branch, $categorycode);
254
        my $res = $sth_search->fetchrow_hashref();
180
        my $res = $sth_search->fetchrow_hashref();
255
        if ($res->{total}) {
181
        if ($res->{total}) {
256
            $sth_update->execute($maxissueqty, $branch, $categorycode);
182
            $sth_update->execute($maxissueqty, $branch, $categorycode);
Lines 266-317 elsif ($op eq "add-branch-item") { Link Here
266
    $holdallowed =~ s/\s//g;
192
    $holdallowed =~ s/\s//g;
267
    $holdallowed = undef if $holdallowed !~ /^\d+/;
193
    $holdallowed = undef if $holdallowed !~ /^\d+/;
268
194
269
    if ($branch eq "*") {
195
    if ($itemtype eq "*") {
270
        if ($itemtype eq "*") {
271
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
272
                                            FROM default_circ_rules");
273
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
274
                                            (holdallowed, returnbranch)
275
                                            VALUES (?, ?)");
276
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
277
                                            SET holdallowed = ?, returnbranch = ?");
278
279
            $sth_search->execute();
280
            my $res = $sth_search->fetchrow_hashref();
281
            if ($res->{total}) {
282
                $sth_update->execute($holdallowed, $returnbranch);
283
            } else {
284
                $sth_insert->execute($holdallowed, $returnbranch);
285
            }
286
        } else {
287
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
288
                                            FROM default_branch_item_rules
289
                                            WHERE itemtype = ?");
290
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
291
                                            (itemtype, holdallowed, returnbranch)
292
                                            VALUES (?, ?, ?)");
293
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
294
                                            SET holdallowed = ?, returnbranch = ?
295
                                            WHERE itemtype = ?");
296
            $sth_search->execute($itemtype);
297
            my $res = $sth_search->fetchrow_hashref();
298
            if ($res->{total}) {
299
                $sth_update->execute($holdallowed, $returnbranch, $itemtype);
300
            } else {
301
                $sth_insert->execute($itemtype, $holdallowed, $returnbranch);
302
            }
303
        }
304
    } elsif ($itemtype eq "*") {
305
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
196
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
306
                                        FROM default_branch_circ_rules
197
                                        FROM circ_rules
307
                                        WHERE branchcode = ?");
198
                                        WHERE branchcode = ?");
308
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
199
        my $sth_insert = $dbh->prepare("INSERT INTO circ_rules
309
                                        (branchcode, holdallowed, returnbranch)
200
                                        (branchcode, holdallowed, returnbranch)
310
                                        VALUES (?, ?, ?)");
201
                                        VALUES (?, ?, ?)");
311
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
202
        my $sth_update = $dbh->prepare("UPDATE circ_rules
312
                                        SET holdallowed = ?, returnbranch = ?
203
                                        SET holdallowed = ?, returnbranch = ?
313
                                        WHERE branchcode = ?");
204
                                        WHERE branchcode = ?");
314
        $sth_search->execute($branch);
205
206
        $sth_search->execute( $branch );
315
        my $res = $sth_search->fetchrow_hashref();
207
        my $res = $sth_search->fetchrow_hashref();
316
        if ($res->{total}) {
208
        if ($res->{total}) {
317
            $sth_update->execute($holdallowed, $returnbranch, $branch);
209
            $sth_update->execute($holdallowed, $returnbranch, $branch);
Lines 320-337 elsif ($op eq "add-branch-item") { Link Here
320
        }
212
        }
321
    } else {
213
    } else {
322
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
214
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
323
                                        FROM branch_item_rules
215
                                        FROM item_circ_rules
324
                                        WHERE branchcode = ?
216
                                        WHERE itemtype = ?");
325
                                        AND   itemtype = ?");
217
        my $sth_insert = $dbh->prepare("INSERT INTO item_circ_rules
326
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
327
                                        (branchcode, itemtype, holdallowed, returnbranch)
218
                                        (branchcode, itemtype, holdallowed, returnbranch)
328
                                        VALUES (?, ?, ?, ?)");
219
                                        VALUES (?, ?, ?, ?)");
329
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
220
        my $sth_update = $dbh->prepare("UPDATE item_circ_rules
330
                                        SET holdallowed = ?, returnbranch = ?
221
                                        SET holdallowed = ?, returnbranch = ?
331
                                        WHERE branchcode = ?
222
                                        WHERE branchcode = ?
332
                                        AND itemtype = ?");
223
                                        AND itemtype = ?");
333
224
        $sth_search->execute($itemtype);
334
        $sth_search->execute($branch, $itemtype);
335
        my $res = $sth_search->fetchrow_hashref();
225
        my $res = $sth_search->fetchrow_hashref();
336
        if ($res->{total}) {
226
        if ($res->{total}) {
337
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
227
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
Lines 386-392 while (my $row = $sth2->fetchrow_hashref) { Link Here
386
    $row->{'humancategorycode'} ||= $row->{'categorycode'};
276
    $row->{'humancategorycode'} ||= $row->{'categorycode'};
387
    $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
277
    $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
388
    $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
278
    $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
389
    if ($row->{'hardduedate'} ne '0000-00-00') {
279
    if ($row->{hardduedate} and $row->{'hardduedate'} ne '0000-00-00') {
390
       $row->{'hardduedate'} = format_date( $row->{'hardduedate'});
280
       $row->{'hardduedate'} = format_date( $row->{'hardduedate'});
391
       $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
281
       $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
392
       $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} ==  0);
282
       $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} ==  0);
Lines 401-423 $sth->finish; Link Here
401
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
291
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
402
292
403
my $sth_branch_cat;
293
my $sth_branch_cat;
404
if ($branch eq "*") {
294
$sth_branch_cat = $dbh->prepare("
405
    $sth_branch_cat = $dbh->prepare("
295
    SELECT borrower_circ_rules.*, categories.description AS humancategorycode
406
        SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
296
    FROM borrower_circ_rules
407
        FROM default_borrower_circ_rules
297
    JOIN categories USING (categorycode)
408
        JOIN categories USING (categorycode)
298
    WHERE borrower_circ_rules.branchcode = ?
409
        
299
");
410
    ");
300
$sth_branch_cat->execute($branch);
411
    $sth_branch_cat->execute();
412
} else {
413
    $sth_branch_cat = $dbh->prepare("
414
        SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
415
        FROM branch_borrower_circ_rules
416
        JOIN categories USING (categorycode)
417
        WHERE branch_borrower_circ_rules.branchcode = ?
418
    ");
419
    $sth_branch_cat->execute($branch);
420
}
421
301
422
my @branch_cat_rules = ();
302
my @branch_cat_rules = ();
423
while (my $row = $sth_branch_cat->fetchrow_hashref) {
303
while (my $row = $sth_branch_cat->fetchrow_hashref) {
Lines 433-454 foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { Link Here
433
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
313
@sorted_row_loop = sort by_category_and_itemtype @row_loop;
434
314
435
my $sth_branch_item;
315
my $sth_branch_item;
436
if ($branch eq "*") {
316
$sth_branch_item = $dbh->prepare("
437
    $sth_branch_item = $dbh->prepare("
317
    SELECT item_circ_rules.*, itemtypes.description AS humanitemtype
438
        SELECT default_branch_item_rules.*, itemtypes.description AS humanitemtype
318
    FROM item_circ_rules
439
        FROM default_branch_item_rules
319
    JOIN itemtypes USING (itemtype)
440
        JOIN itemtypes USING (itemtype)
320
    WHERE item_circ_rules.branchcode = ?
441
    ");
321
");
442
    $sth_branch_item->execute();
322
$sth_branch_item->execute($branch);
443
} else {
444
    $sth_branch_item = $dbh->prepare("
445
        SELECT branch_item_rules.*, itemtypes.description AS humanitemtype
446
        FROM branch_item_rules
447
        JOIN itemtypes USING (itemtype)
448
        WHERE branch_item_rules.branchcode = ?
449
    ");
450
    $sth_branch_item->execute($branch);
451
}
452
323
453
my @branch_item_rules = ();
324
my @branch_item_rules = ();
454
while (my $row = $sth_branch_item->fetchrow_hashref) {
325
while (my $row = $sth_branch_item->fetchrow_hashref) {
Lines 467-486 $template->param(branch_item_rule_loop => \@sorted_branch_item_rules); Link Here
467
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
338
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules);
468
339
469
my $sth_defaults;
340
my $sth_defaults;
470
if ($branch eq "*") {
341
$sth_defaults = $dbh->prepare("
471
    $sth_defaults = $dbh->prepare("
342
    SELECT *
472
        SELECT *
343
    FROM circ_rules
473
        FROM default_circ_rules
344
    WHERE branchcode = ?
474
    ");
345
");
475
    $sth_defaults->execute();
346
$sth_defaults->execute($branch);
476
} else {
477
    $sth_defaults = $dbh->prepare("
478
        SELECT *
479
        FROM default_branch_circ_rules
480
        WHERE branchcode = ?
481
    ");
482
    $sth_defaults->execute($branch);
483
}
484
347
485
my $defaults = $sth_defaults->fetchrow_hashref;
348
my $defaults = $sth_defaults->fetchrow_hashref;
486
349
Lines 494-507 if ($defaults) { Link Here
494
357
495
$template->param(default_rules => ($defaults ? 1 : 0));
358
$template->param(default_rules => ($defaults ? 1 : 0));
496
359
497
$template->param(categoryloop => \@category_loop,
360
$template->param(
498
                        itemtypeloop => \@itemtypes,
361
    categoryloop   => \@category_loop,
499
                        rules => \@sorted_row_loop,
362
    itemtypeloop   => \@itemtypes,
500
                        branchloop => \@branchloop,
363
    rules          => \@sorted_row_loop,
501
                        humanbranch => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''),
364
    branchloop     => \@branchloop,
502
                        current_branch => $branch,
365
    humanbranch    => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''),
503
                        definedbranch => scalar(@sorted_row_loop)>0 
366
    current_branch => $branch,
504
                        );
367
    definedbranch  => scalar(@sorted_row_loop)>0,
368
);
505
output_html_with_http_headers $input, $cookie, $template->output;
369
output_html_with_http_headers $input, $cookie, $template->output;
506
370
507
exit 0;
371
exit 0;
(-)a/installer/data/mysql/kohastructure.sql (-51 / +19 lines)
Lines 571-643 ALTER TABLE `course_reserves` Link Here
571
  ADD CONSTRAINT `course_reserves_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`);
571
  ADD CONSTRAINT `course_reserves_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`);
572
572
573
--
573
--
574
-- Table structure for table `branch_borrower_circ_rules`
574
-- Table structure for table `circ_rules`
575
--
575
--
576
576
577
DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
577
DROP TABLE IF EXISTS `circ_rules`;
578
CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
578
CREATE TABLE `circ_rules` (
579
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
580
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
581
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
582
  PRIMARY KEY (`categorycode`, `branchcode`),
583
  CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
584
    ON DELETE CASCADE ON UPDATE CASCADE,
585
  CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
586
    ON DELETE CASCADE ON UPDATE CASCADE
587
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
588
589
--
590
-- Table structure for table `default_borrower_circ_rules`
591
--
592
593
DROP TABLE IF EXISTS `default_borrower_circ_rules`;
594
CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
595
  `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
596
  `maxissueqty` int(4) default NULL,
597
  PRIMARY KEY (`categorycode`),
598
  CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
599
    ON DELETE CASCADE ON UPDATE CASCADE
600
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
601
602
--
603
-- Table structure for table `default_branch_circ_rules`
604
--
605
606
DROP TABLE IF EXISTS `default_branch_circ_rules`;
607
CREATE TABLE `default_branch_circ_rules` (
608
  `branchcode` VARCHAR(10) NOT NULL,
579
  `branchcode` VARCHAR(10) NOT NULL,
609
  `maxissueqty` int(4) default NULL,
580
  `maxissueqty` int(4) default NULL,
610
  `holdallowed` tinyint(1) default NULL,
581
  `holdallowed` tinyint(1) default NULL,
611
  `returnbranch` varchar(15) default NULL,
582
  `returnbranch` varchar(15) default NULL,
612
  PRIMARY KEY (`branchcode`),
583
  PRIMARY KEY (`branchcode`),
613
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
614
    ON DELETE CASCADE ON UPDATE CASCADE
615
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
584
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
616
585
617
--
586
--
618
-- Table structure for table `default_branch_item_rules`
587
-- Table structure for table `borrower_circ_rules`
619
--
588
--
620
DROP TABLE IF EXISTS `default_branch_item_rules`;
589
621
CREATE TABLE `default_branch_item_rules` (
590
DROP TABLE IF EXISTS `borrower_circ_rules`;
622
  `itemtype` varchar(10) NOT NULL,
591
CREATE TABLE `borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
623
  `holdallowed` tinyint(1) default NULL,
592
  `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
624
  `returnbranch` varchar(15) default NULL,
593
  `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
625
  PRIMARY KEY  (`itemtype`),
594
  `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
626
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
595
  PRIMARY KEY (`categorycode`, `branchcode`),
627
    ON DELETE CASCADE ON UPDATE CASCADE
628
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
596
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
629
597
630
--
598
--
631
-- Table structure for table `default_circ_rules`
599
-- Table structure for table `item_circ_rules`
632
--
600
--
633
601
634
DROP TABLE IF EXISTS `default_circ_rules`;
602
DROP TABLE IF EXISTS `item_circ_rules`;
635
CREATE TABLE `default_circ_rules` (
603
CREATE TABLE `item_circ_rules` (
636
    `singleton` enum('singleton') NOT NULL default 'singleton',
604
  `branchcode` varchar(10) NOT NULL,
637
    `maxissueqty` int(4) default NULL,
605
  `itemtype` varchar(10) NOT NULL,
638
    `holdallowed` int(1) default NULL,
606
  `holdallowed` tinyint(1) default NULL,
639
    `returnbranch` varchar(15) default NULL,
607
  `returnbranch` varchar(15) default NULL,
640
    PRIMARY KEY (`singleton`)
608
  PRIMARY KEY  (`branchcode`, `itemtype`),
641
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
609
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
642
610
643
--
611
--
(-)a/installer/data/mysql/updatedatabase.pl (-2 / +57 lines)
Lines 7067-7072 if ( CheckVersion($DBversion) ) { Link Here
7067
    SetVersion($DBversion);
7067
    SetVersion($DBversion);
7068
}
7068
}
7069
7069
7070
$DBversion = "3.13.00.XXX";
7071
if (C4::Context->preference("version") < TransformToNum($DBversion)) {
7072
    $dbh->do(qq{
7073
        CREATE TABLE circ_rules (
7074
            branchcode VARCHAR(10) NOT NULL,
7075
            maxissueqty INT(4) DEFAULT NULL,
7076
            holdallowed TINYINT(1) DEFAULT NULL,
7077
            returnbranch VARCHAR(15) DEFAULT NULL,
7078
            PRIMARY KEY(branchcode)
7079
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
7080
    });
7081
    $dbh->do(qq{
7082
        CREATE TABLE borrower_circ_rules (
7083
            branchcode VARCHAR(10) NOT NULL,
7084
            categorycode VARCHAR(10) NOT NULL,
7085
            maxissueqty INT(4) DEFAULT NULL,
7086
            PRIMARY KEY(branchcode, categorycode)
7087
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
7088
    });
7089
    $dbh->do(qq{
7090
        CREATE TABLE item_circ_rules (
7091
            branchcode VARCHAR(10) NOT NULL,
7092
            itemtype VARCHAR(10) NOT NULL,
7093
            holdallowed TINYINT(1) DEFAULT NULL,
7094
            returnbranch VARCHAR(15) DEFAULT NULL,
7095
            PRIMARY KEY(branchcode, itemtype)
7096
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
7097
    });
7098
    $dbh->do(qq{
7099
        INSERT INTO circ_rules(branchcode, maxissueqty, holdallowed, returnbranch)
7100
        SELECT '*', maxissueqty, holdallowed, returnbranch FROM default_circ_rules;
7101
    });
7102
    $dbh->do(qq{
7103
        INSERT INTO circ_rules(branchcode, maxissueqty, holdallowed, returnbranch)
7104
        SELECT branchcode, maxissueqty, holdallowed, returnbranch FROM default_branch_circ_rules;
7105
    });
7106
    $dbh->do(qq{
7107
        INSERT INTO borrower_circ_rules( branchcode, categorycode, maxissueqty )
7108
        SELECT '*', categorycode, maxissueqty FROM default_borrower_circ_rules;
7109
    });
7110
    $dbh->do(qq{
7111
        INSERT INTO borrower_circ_rules( branchcode, categorycode, maxissueqty )
7112
        SELECT branchcode, categorycode, maxissueqty FROM branch_borrower_circ_rules;
7113
    });
7114
    $dbh->do(qq{
7115
        INSERT INTO item_circ_rules( branchcode, itemtype, holdallowed, returnbranch )
7116
        SELECT '*', itemtype, holdallowed, returnbranch FROM default_branch_item_rules;
7117
    });
7118
    $dbh->do(qq{
7119
        INSERT INTO item_circ_rules( branchcode, itemtype, holdallowed, returnbranch )
7120
        SELECT branchcode, itemtype, holdallowed, returnbranch FROM branch_item_rules;
7121
    });
7122
    print "Upgrade to $DBversion done (Bug 8369: Replace circ rules tables. 3 new tables: circ_rules, borrower_circ_rules, item_circ_rules)\n";
7123
    SetVersion($DBversion);
7124
}
7125
7070
=head1 FUNCTIONS
7126
=head1 FUNCTIONS
7071
7127
7072
=head2 TableExists($table)
7128
=head2 TableExists($table)
Lines 7126-7132 sub TransformToNum { Link Here
7126
    # three X's at the end indicate that you are testing patch with dbrev
7182
    # three X's at the end indicate that you are testing patch with dbrev
7127
    # change it into 999
7183
    # change it into 999
7128
    # prevents error on a < comparison between strings (should be: lt)
7184
    # prevents error on a < comparison between strings (should be: lt)
7129
    $version =~ s/XXX$/999/;
7185
    $version =~ s/XXX$/999/i;
7130
    return $version;
7186
    return $version;
7131
}
7187
}
7132
7188
7133
- 

Return to bug 8369