|
Lines 79-106
elsif ($op eq 'delete-branch-cat') {
Link Here
|
| 79 |
if ($categorycode eq "*") { |
79 |
if ($categorycode eq "*") { |
| 80 |
my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); |
80 |
my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); |
| 81 |
$sth_delete->execute(); |
81 |
$sth_delete->execute(); |
| 82 |
} else { |
|
|
| 83 |
my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules |
| 84 |
WHERE categorycode = ?"); |
| 85 |
$sth_delete->execute($categorycode); |
| 86 |
} |
82 |
} |
| 87 |
} elsif ($categorycode eq "*") { |
83 |
} elsif ($categorycode eq "*") { |
| 88 |
my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules |
84 |
my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules |
| 89 |
WHERE branchcode = ?"); |
85 |
WHERE branchcode = ?"); |
| 90 |
$sth_delete->execute($branch); |
86 |
$sth_delete->execute($branch); |
| 91 |
} else { |
|
|
| 92 |
my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules |
| 93 |
WHERE branchcode = ? |
| 94 |
AND categorycode = ?"); |
| 95 |
$sth_delete->execute($branch, $categorycode); |
| 96 |
} |
87 |
} |
| 97 |
Koha::CirculationRules->set_rule( |
88 |
Koha::CirculationRules->set_rules( |
| 98 |
{ |
89 |
{ |
| 99 |
branchcode => $branch, |
90 |
categorycode => $categorycode eq '*' ? undef : $categorycode, |
| 100 |
categorycode => $categorycode, |
91 |
branchcode => $branch eq '*' ? undef : $branch, |
| 101 |
itemtype => undef, |
92 |
itemtype => undef, |
| 102 |
rule_name => 'max_holds', |
93 |
rules => { |
| 103 |
rule_value => undef, |
94 |
max_holds => undef, |
|
|
95 |
maxissueqty => undef, |
| 96 |
maxonsiteissueqty => undef, |
| 97 |
} |
| 104 |
} |
98 |
} |
| 105 |
); |
99 |
); |
| 106 |
} |
100 |
} |
|
Lines 183-190
elsif ($op eq 'add') {
Link Here
|
| 183 |
firstremind => $firstremind, |
177 |
firstremind => $firstremind, |
| 184 |
chargeperiod => $chargeperiod, |
178 |
chargeperiod => $chargeperiod, |
| 185 |
chargeperiod_charge_at => $chargeperiod_charge_at, |
179 |
chargeperiod_charge_at => $chargeperiod_charge_at, |
| 186 |
maxissueqty => $maxissueqty, |
|
|
| 187 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 188 |
renewalsallowed => $renewalsallowed, |
180 |
renewalsallowed => $renewalsallowed, |
| 189 |
renewalperiod => $renewalperiod, |
181 |
renewalperiod => $renewalperiod, |
| 190 |
norenewalbefore => $norenewalbefore, |
182 |
norenewalbefore => $norenewalbefore, |
|
Lines 212-217
elsif ($op eq 'add') {
Link Here
|
| 212 |
Koha::IssuingRule->new()->set($params)->store(); |
204 |
Koha::IssuingRule->new()->set($params)->store(); |
| 213 |
} |
205 |
} |
| 214 |
|
206 |
|
|
|
207 |
Koha::CirculationRules->set_rules( |
| 208 |
{ |
| 209 |
categorycode => $bor, |
| 210 |
itemtype => $itemtype, |
| 211 |
branchcode => $br, |
| 212 |
rules => { |
| 213 |
maxissueqty => $maxissueqty, |
| 214 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 215 |
} |
| 216 |
} |
| 217 |
); |
| 218 |
|
| 215 |
} |
219 |
} |
| 216 |
elsif ($op eq "set-branch-defaults") { |
220 |
elsif ($op eq "set-branch-defaults") { |
| 217 |
my $categorycode = $input->param('categorycode'); |
221 |
my $categorycode = $input->param('categorycode'); |
|
Lines 234-268
elsif ($op eq "set-branch-defaults") {
Link Here
|
| 234 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
238 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
| 235 |
FROM default_circ_rules"); |
239 |
FROM default_circ_rules"); |
| 236 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
240 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
| 237 |
(maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) |
241 |
(holdallowed, hold_fulfillment_policy, returnbranch) |
| 238 |
VALUES (?, ?, ?, ?, ?)"); |
242 |
VALUES (?, ?, ?)"); |
| 239 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
243 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
| 240 |
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); |
244 |
SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); |
| 241 |
|
245 |
|
| 242 |
$sth_search->execute(); |
246 |
$sth_search->execute(); |
| 243 |
my $res = $sth_search->fetchrow_hashref(); |
247 |
my $res = $sth_search->fetchrow_hashref(); |
| 244 |
if ($res->{total}) { |
248 |
if ($res->{total}) { |
| 245 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
249 |
$sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); |
| 246 |
} else { |
250 |
} else { |
| 247 |
$sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
251 |
$sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); |
| 248 |
} |
252 |
} |
|
|
253 |
|
| 254 |
Koha::CirculationRules->set_rules( |
| 255 |
{ |
| 256 |
categorycode => undef, |
| 257 |
itemtype => undef, |
| 258 |
branchcode => undef, |
| 259 |
rules => { |
| 260 |
maxissueqty => $maxissueqty, |
| 261 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 262 |
} |
| 263 |
} |
| 264 |
); |
| 249 |
} else { |
265 |
} else { |
| 250 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
266 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
| 251 |
FROM default_branch_circ_rules |
267 |
FROM default_branch_circ_rules |
| 252 |
WHERE branchcode = ?"); |
268 |
WHERE branchcode = ?"); |
| 253 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
269 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
| 254 |
(branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) |
270 |
(branchcode, holdallowed, hold_fulfillment_policy, returnbranch) |
| 255 |
VALUES (?, ?, ?, ?, ?, ?)"); |
271 |
VALUES (?, ?, ?, ?)"); |
| 256 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
272 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
| 257 |
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? |
273 |
SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? |
| 258 |
WHERE branchcode = ?"); |
274 |
WHERE branchcode = ?"); |
| 259 |
$sth_search->execute($branch); |
275 |
$sth_search->execute($branch); |
| 260 |
my $res = $sth_search->fetchrow_hashref(); |
276 |
my $res = $sth_search->fetchrow_hashref(); |
| 261 |
if ($res->{total}) { |
277 |
if ($res->{total}) { |
| 262 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); |
278 |
$sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); |
| 263 |
} else { |
279 |
} else { |
| 264 |
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
280 |
$sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
| 265 |
} |
281 |
} |
|
|
282 |
|
| 283 |
Koha::CirculationRules->set_rules( |
| 284 |
{ |
| 285 |
categorycode => undef, |
| 286 |
itemtype => undef, |
| 287 |
branchcode => $branch, |
| 288 |
rules => { |
| 289 |
maxissueqty => $maxissueqty, |
| 290 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 291 |
} |
| 292 |
} |
| 293 |
); |
| 266 |
} |
294 |
} |
| 267 |
Koha::CirculationRules->set_rule( |
295 |
Koha::CirculationRules->set_rule( |
| 268 |
{ |
296 |
{ |
|
Lines 288-413
elsif ($op eq "add-branch-cat") {
Link Here
|
| 288 |
|
316 |
|
| 289 |
if ($branch eq "*") { |
317 |
if ($branch eq "*") { |
| 290 |
if ($categorycode eq "*") { |
318 |
if ($categorycode eq "*") { |
| 291 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
319 |
Koha::CirculationRules->set_rules( |
| 292 |
FROM default_circ_rules"); |
|
|
| 293 |
my $sth_insert = $dbh->prepare(q| |
| 294 |
INSERT INTO default_circ_rules |
| 295 |
(maxissueqty, maxonsiteissueqty, max_holds) |
| 296 |
VALUES (?, ?, ?) |
| 297 |
|); |
| 298 |
my $sth_update = $dbh->prepare(q| |
| 299 |
UPDATE default_circ_rules |
| 300 |
SET maxissueqty = ?, |
| 301 |
maxonsiteissueqty = ?, |
| 302 |
max_holds = ? |
| 303 |
|); |
| 304 |
|
| 305 |
$sth_search->execute(); |
| 306 |
my $res = $sth_search->fetchrow_hashref(); |
| 307 |
if ($res->{total}) { |
| 308 |
$sth_update->execute( $maxissueqty, $maxonsiteissueqty ); |
| 309 |
} else { |
| 310 |
$sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); |
| 311 |
} |
| 312 |
|
| 313 |
Koha::CirculationRules->set_rule( |
| 314 |
{ |
320 |
{ |
| 315 |
branchcode => undef, |
|
|
| 316 |
categorycode => undef, |
321 |
categorycode => undef, |
| 317 |
itemtype => undef, |
322 |
itemtype => undef, |
| 318 |
rule_name => 'max_holds', |
323 |
branchcode => undef, |
| 319 |
rule_value => $max_holds, |
324 |
rules => { |
|
|
325 |
max_holds => $max_holds, |
| 326 |
maxissueqty => $maxissueqty, |
| 327 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 328 |
} |
| 320 |
} |
329 |
} |
| 321 |
); |
330 |
); |
| 322 |
} else { |
331 |
} else { |
| 323 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
332 |
Koha::CirculationRules->set_rules( |
| 324 |
FROM default_borrower_circ_rules |
|
|
| 325 |
WHERE categorycode = ?"); |
| 326 |
my $sth_insert = $dbh->prepare(q| |
| 327 |
INSERT INTO default_borrower_circ_rules |
| 328 |
(categorycode, maxissueqty, maxonsiteissueqty) |
| 329 |
VALUES ( ?, ?, ?) |
| 330 |
|); |
| 331 |
my $sth_update = $dbh->prepare(q| |
| 332 |
UPDATE default_borrower_circ_rules |
| 333 |
SET maxissueqty = ?, |
| 334 |
maxonsiteissueqty = ?, |
| 335 |
WHERE categorycode = ? |
| 336 |
|); |
| 337 |
$sth_search->execute($categorycode); |
| 338 |
my $res = $sth_search->fetchrow_hashref(); |
| 339 |
if ($res->{total}) { |
| 340 |
$sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); |
| 341 |
} else { |
| 342 |
$sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); |
| 343 |
} |
| 344 |
|
| 345 |
Koha::CirculationRules->set_rule( |
| 346 |
{ |
333 |
{ |
| 347 |
branchcode => undef, |
334 |
branchcode => undef, |
| 348 |
categorycode => $categorycode, |
335 |
categorycode => $categorycode, |
| 349 |
itemtype => undef, |
336 |
itemtype => undef, |
| 350 |
rule_name => 'max_holds', |
337 |
rules => { |
| 351 |
rule_value => $max_holds, |
338 |
max_holds => $max_holds, |
|
|
339 |
maxissueqty => $maxissueqty, |
| 340 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 341 |
} |
| 352 |
} |
342 |
} |
| 353 |
); |
343 |
); |
| 354 |
} |
344 |
} |
| 355 |
} elsif ($categorycode eq "*") { |
345 |
} elsif ($categorycode eq "*") { |
| 356 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
346 |
Koha::CirculationRules->set_rules( |
| 357 |
FROM default_branch_circ_rules |
|
|
| 358 |
WHERE branchcode = ?"); |
| 359 |
my $sth_insert = $dbh->prepare(q| |
| 360 |
INSERT INTO default_branch_circ_rules |
| 361 |
(branchcode, maxissueqty, maxonsiteissueqty) |
| 362 |
VALUES (?, ?, ?) |
| 363 |
|); |
| 364 |
my $sth_update = $dbh->prepare(q| |
| 365 |
UPDATE default_branch_circ_rules |
| 366 |
SET maxissueqty = ?, |
| 367 |
maxonsiteissueqty = ? |
| 368 |
WHERE branchcode = ? |
| 369 |
|); |
| 370 |
$sth_search->execute($branch); |
| 371 |
my $res = $sth_search->fetchrow_hashref(); |
| 372 |
if ($res->{total}) { |
| 373 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch); |
| 374 |
} else { |
| 375 |
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty); |
| 376 |
} |
| 377 |
} else { |
| 378 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
| 379 |
FROM branch_borrower_circ_rules |
| 380 |
WHERE branchcode = ? |
| 381 |
AND categorycode = ?"); |
| 382 |
my $sth_insert = $dbh->prepare(q| |
| 383 |
INSERT INTO branch_borrower_circ_rules |
| 384 |
(branchcode, categorycode, maxissueqty, maxonsiteissueqty, max_holds) |
| 385 |
VALUES (?, ?, ?, ?, ?) |
| 386 |
|); |
| 387 |
my $sth_update = $dbh->prepare(q| |
| 388 |
UPDATE branch_borrower_circ_rules |
| 389 |
SET maxissueqty = ?, |
| 390 |
maxonsiteissueqty = ? |
| 391 |
max_holds = ? |
| 392 |
WHERE branchcode = ? |
| 393 |
AND categorycode = ? |
| 394 |
|); |
| 395 |
|
| 396 |
$sth_search->execute($branch, $categorycode); |
| 397 |
my $res = $sth_search->fetchrow_hashref(); |
| 398 |
if ($res->{total}) { |
| 399 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $max_holds, $branch, $categorycode); |
| 400 |
} else { |
| 401 |
$sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds); |
| 402 |
} |
| 403 |
|
| 404 |
Koha::CirculationRules->set_rule( |
| 405 |
{ |
347 |
{ |
|
|
348 |
categorycode => undef, |
| 349 |
itemtype => undef, |
| 406 |
branchcode => $branch, |
350 |
branchcode => $branch, |
|
|
351 |
rules => { |
| 352 |
max_holds => $max_holds, |
| 353 |
maxissueqty => $maxissueqty, |
| 354 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 355 |
} |
| 356 |
} |
| 357 |
); |
| 358 |
} else { |
| 359 |
Koha::CirculationRules->set_rules( |
| 360 |
{ |
| 407 |
categorycode => $categorycode, |
361 |
categorycode => $categorycode, |
| 408 |
itemtype => undef, |
362 |
itemtype => undef, |
| 409 |
rule_name => 'max_holds', |
363 |
branchcode => $branch, |
| 410 |
rule_value => $max_holds, |
364 |
rules => { |
|
|
365 |
max_holds => $max_holds, |
| 366 |
maxissueqty => $maxissueqty, |
| 367 |
maxonsiteissueqty => $maxonsiteissueqty, |
| 368 |
} |
| 411 |
} |
369 |
} |
| 412 |
); |
370 |
); |
| 413 |
} |
371 |
} |
|
Lines 575-614
while (my $row = $sth2->fetchrow_hashref) {
Link Here
|
| 575 |
|
533 |
|
| 576 |
my @sorted_row_loop = sort by_category_and_itemtype @row_loop; |
534 |
my @sorted_row_loop = sort by_category_and_itemtype @row_loop; |
| 577 |
|
535 |
|
| 578 |
my $sth_branch_cat; |
|
|
| 579 |
if ($branch eq "*") { |
| 580 |
$sth_branch_cat = $dbh->prepare(" |
| 581 |
SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode |
| 582 |
FROM default_borrower_circ_rules |
| 583 |
JOIN categories USING (categorycode) |
| 584 |
|
| 585 |
"); |
| 586 |
$sth_branch_cat->execute(); |
| 587 |
} else { |
| 588 |
$sth_branch_cat = $dbh->prepare(" |
| 589 |
SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode |
| 590 |
FROM branch_borrower_circ_rules |
| 591 |
JOIN categories USING (categorycode) |
| 592 |
WHERE branch_borrower_circ_rules.branchcode = ? |
| 593 |
"); |
| 594 |
$sth_branch_cat->execute($branch); |
| 595 |
} |
| 596 |
|
| 597 |
my @branch_cat_rules = (); |
| 598 |
while (my $row = $sth_branch_cat->fetchrow_hashref) { |
| 599 |
push @branch_cat_rules, $row; |
| 600 |
} |
| 601 |
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules; |
| 602 |
|
| 603 |
# note undef maxissueqty so that template can deal with them |
| 604 |
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { |
| 605 |
$entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); |
| 606 |
$entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty}); |
| 607 |
$entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds}); |
| 608 |
} |
| 609 |
|
| 610 |
@sorted_row_loop = sort by_category_and_itemtype @row_loop; |
| 611 |
|
| 612 |
my $sth_branch_item; |
536 |
my $sth_branch_item; |
| 613 |
if ($branch eq "*") { |
537 |
if ($branch eq "*") { |
| 614 |
$sth_branch_item = $dbh->prepare(" |
538 |
$sth_branch_item = $dbh->prepare(" |
|
Lines 649-655
foreach my $entry (@sorted_branch_item_rules) {
Link Here
|
| 649 |
|
573 |
|
| 650 |
$template->param(show_branch_cat_rule_form => 1); |
574 |
$template->param(show_branch_cat_rule_form => 1); |
| 651 |
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); |
575 |
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); |
| 652 |
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); |
|
|
| 653 |
|
576 |
|
| 654 |
my $sth_defaults; |
577 |
my $sth_defaults; |
| 655 |
if ($branch eq "*") { |
578 |
if ($branch eq "*") { |