Lines 91-118
elsif ($op eq 'delete-branch-cat') {
Link Here
|
91 |
if ($categorycode eq "*") { |
91 |
if ($categorycode eq "*") { |
92 |
my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); |
92 |
my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); |
93 |
$sth_delete->execute(); |
93 |
$sth_delete->execute(); |
94 |
} else { |
|
|
95 |
my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules |
96 |
WHERE categorycode = ?"); |
97 |
$sth_delete->execute($categorycode); |
98 |
} |
94 |
} |
99 |
} elsif ($categorycode eq "*") { |
95 |
} elsif ($categorycode eq "*") { |
100 |
my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules |
96 |
my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules |
101 |
WHERE branchcode = ?"); |
97 |
WHERE branchcode = ?"); |
102 |
$sth_delete->execute($branch); |
98 |
$sth_delete->execute($branch); |
103 |
} else { |
|
|
104 |
my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules |
105 |
WHERE branchcode = ? |
106 |
AND categorycode = ?"); |
107 |
$sth_delete->execute($branch, $categorycode); |
108 |
} |
99 |
} |
109 |
Koha::CirculationRules->set_rule( |
100 |
Koha::CirculationRules->set_rules( |
110 |
{ |
101 |
{ |
111 |
branchcode => $branch, |
102 |
categorycode => $categorycode eq '*' ? undef : $categorycode, |
112 |
categorycode => $categorycode, |
103 |
branchcode => $branch eq '*' ? undef : $branch, |
113 |
itemtype => undef, |
104 |
itemtype => undef, |
114 |
rule_name => 'max_holds', |
105 |
rules => { |
115 |
rule_value => undef, |
106 |
max_holds => undef, |
|
|
107 |
maxissueqty => undef, |
108 |
maxonsiteissueqty => undef, |
109 |
} |
116 |
} |
110 |
} |
117 |
); |
111 |
); |
118 |
} |
112 |
} |
Lines 198-205
elsif ($op eq 'add') {
Link Here
|
198 |
firstremind => $firstremind, |
192 |
firstremind => $firstremind, |
199 |
chargeperiod => $chargeperiod, |
193 |
chargeperiod => $chargeperiod, |
200 |
chargeperiod_charge_at => $chargeperiod_charge_at, |
194 |
chargeperiod_charge_at => $chargeperiod_charge_at, |
201 |
maxissueqty => $maxissueqty, |
|
|
202 |
maxonsiteissueqty => $maxonsiteissueqty, |
203 |
renewalsallowed => $renewalsallowed, |
195 |
renewalsallowed => $renewalsallowed, |
204 |
renewalperiod => $renewalperiod, |
196 |
renewalperiod => $renewalperiod, |
205 |
norenewalbefore => $norenewalbefore, |
197 |
norenewalbefore => $norenewalbefore, |
Lines 228-233
elsif ($op eq 'add') {
Link Here
|
228 |
Koha::IssuingRule->new()->set($params)->store(); |
220 |
Koha::IssuingRule->new()->set($params)->store(); |
229 |
} |
221 |
} |
230 |
|
222 |
|
|
|
223 |
Koha::CirculationRules->set_rules( |
224 |
{ |
225 |
categorycode => $bor, |
226 |
itemtype => $itemtype, |
227 |
branchcode => $br, |
228 |
rules => { |
229 |
maxissueqty => $maxissueqty, |
230 |
maxonsiteissueqty => $maxonsiteissueqty, |
231 |
} |
232 |
} |
233 |
); |
234 |
|
231 |
} |
235 |
} |
232 |
elsif ($op eq "set-branch-defaults") { |
236 |
elsif ($op eq "set-branch-defaults") { |
233 |
my $categorycode = $input->param('categorycode'); |
237 |
my $categorycode = $input->param('categorycode'); |
Lines 250-284
elsif ($op eq "set-branch-defaults") {
Link Here
|
250 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
254 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
251 |
FROM default_circ_rules"); |
255 |
FROM default_circ_rules"); |
252 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
256 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
253 |
(maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) |
257 |
(holdallowed, hold_fulfillment_policy, returnbranch) |
254 |
VALUES (?, ?, ?, ?, ?)"); |
258 |
VALUES (?, ?, ?)"); |
255 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
259 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
256 |
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); |
260 |
SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); |
257 |
|
261 |
|
258 |
$sth_search->execute(); |
262 |
$sth_search->execute(); |
259 |
my $res = $sth_search->fetchrow_hashref(); |
263 |
my $res = $sth_search->fetchrow_hashref(); |
260 |
if ($res->{total}) { |
264 |
if ($res->{total}) { |
261 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
265 |
$sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); |
262 |
} else { |
266 |
} else { |
263 |
$sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
267 |
$sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); |
264 |
} |
268 |
} |
|
|
269 |
|
270 |
Koha::CirculationRules->set_rules( |
271 |
{ |
272 |
categorycode => undef, |
273 |
itemtype => undef, |
274 |
branchcode => undef, |
275 |
rules => { |
276 |
maxissueqty => $maxissueqty, |
277 |
maxonsiteissueqty => $maxonsiteissueqty, |
278 |
} |
279 |
} |
280 |
); |
265 |
} else { |
281 |
} else { |
266 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
282 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
267 |
FROM default_branch_circ_rules |
283 |
FROM default_branch_circ_rules |
268 |
WHERE branchcode = ?"); |
284 |
WHERE branchcode = ?"); |
269 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
285 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
270 |
(branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) |
286 |
(branchcode, holdallowed, hold_fulfillment_policy, returnbranch) |
271 |
VALUES (?, ?, ?, ?, ?, ?)"); |
287 |
VALUES (?, ?, ?, ?)"); |
272 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
288 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
273 |
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? |
289 |
SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? |
274 |
WHERE branchcode = ?"); |
290 |
WHERE branchcode = ?"); |
275 |
$sth_search->execute($branch); |
291 |
$sth_search->execute($branch); |
276 |
my $res = $sth_search->fetchrow_hashref(); |
292 |
my $res = $sth_search->fetchrow_hashref(); |
277 |
if ($res->{total}) { |
293 |
if ($res->{total}) { |
278 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); |
294 |
$sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); |
279 |
} else { |
295 |
} else { |
280 |
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
296 |
$sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
281 |
} |
297 |
} |
|
|
298 |
|
299 |
Koha::CirculationRules->set_rules( |
300 |
{ |
301 |
categorycode => undef, |
302 |
itemtype => undef, |
303 |
branchcode => $branch, |
304 |
rules => { |
305 |
maxissueqty => $maxissueqty, |
306 |
maxonsiteissueqty => $maxonsiteissueqty, |
307 |
} |
308 |
} |
309 |
); |
282 |
} |
310 |
} |
283 |
Koha::CirculationRules->set_rule( |
311 |
Koha::CirculationRules->set_rule( |
284 |
{ |
312 |
{ |
Lines 304-428
elsif ($op eq "add-branch-cat") {
Link Here
|
304 |
|
332 |
|
305 |
if ($branch eq "*") { |
333 |
if ($branch eq "*") { |
306 |
if ($categorycode eq "*") { |
334 |
if ($categorycode eq "*") { |
307 |
#FIXME This block is will probably be never used |
335 |
Koha::CirculationRules->set_rules( |
308 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
|
|
309 |
FROM default_circ_rules"); |
310 |
my $sth_insert = $dbh->prepare(q| |
311 |
INSERT INTO default_circ_rules |
312 |
(maxissueqty, maxonsiteissueqty) |
313 |
VALUES (?, ?) |
314 |
|); |
315 |
my $sth_update = $dbh->prepare(q| |
316 |
UPDATE default_circ_rules |
317 |
SET maxissueqty = ?, |
318 |
maxonsiteissueqty = ?, |
319 |
|); |
320 |
|
321 |
$sth_search->execute(); |
322 |
my $res = $sth_search->fetchrow_hashref(); |
323 |
if ($res->{total}) { |
324 |
$sth_update->execute( $maxissueqty, $maxonsiteissueqty ); |
325 |
} else { |
326 |
$sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); |
327 |
} |
328 |
|
329 |
Koha::CirculationRules->set_rule( |
330 |
{ |
336 |
{ |
331 |
branchcode => undef, |
|
|
332 |
categorycode => undef, |
337 |
categorycode => undef, |
333 |
itemtype => undef, |
338 |
itemtype => undef, |
334 |
rule_name => 'max_holds', |
339 |
branchcode => undef, |
335 |
rule_value => $max_holds, |
340 |
rules => { |
|
|
341 |
max_holds => $max_holds, |
342 |
maxissueqty => $maxissueqty, |
343 |
maxonsiteissueqty => $maxonsiteissueqty, |
344 |
} |
336 |
} |
345 |
} |
337 |
); |
346 |
); |
338 |
} else { |
347 |
} else { |
339 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
348 |
Koha::CirculationRules->set_rules( |
340 |
FROM default_borrower_circ_rules |
|
|
341 |
WHERE categorycode = ?"); |
342 |
my $sth_insert = $dbh->prepare(q| |
343 |
INSERT INTO default_borrower_circ_rules |
344 |
(categorycode, maxissueqty, maxonsiteissueqty) |
345 |
VALUES ( ?, ?, ?) |
346 |
|); |
347 |
my $sth_update = $dbh->prepare(q| |
348 |
UPDATE default_borrower_circ_rules |
349 |
SET maxissueqty = ?, |
350 |
maxonsiteissueqty = ?, |
351 |
WHERE categorycode = ? |
352 |
|); |
353 |
$sth_search->execute($categorycode); |
354 |
my $res = $sth_search->fetchrow_hashref(); |
355 |
if ($res->{total}) { |
356 |
$sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); |
357 |
} else { |
358 |
$sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); |
359 |
} |
360 |
|
361 |
Koha::CirculationRules->set_rule( |
362 |
{ |
349 |
{ |
363 |
branchcode => undef, |
350 |
branchcode => undef, |
364 |
categorycode => $categorycode, |
351 |
categorycode => $categorycode, |
365 |
itemtype => undef, |
352 |
itemtype => undef, |
366 |
rule_name => 'max_holds', |
353 |
rules => { |
367 |
rule_value => $max_holds, |
354 |
max_holds => $max_holds, |
|
|
355 |
maxissueqty => $maxissueqty, |
356 |
maxonsiteissueqty => $maxonsiteissueqty, |
357 |
} |
368 |
} |
358 |
} |
369 |
); |
359 |
); |
370 |
} |
360 |
} |
371 |
} elsif ($categorycode eq "*") { |
361 |
} elsif ($categorycode eq "*") { |
372 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
362 |
Koha::CirculationRules->set_rules( |
373 |
FROM default_branch_circ_rules |
|
|
374 |
WHERE branchcode = ?"); |
375 |
my $sth_insert = $dbh->prepare(q| |
376 |
INSERT INTO default_branch_circ_rules |
377 |
(branchcode, maxissueqty, maxonsiteissueqty) |
378 |
VALUES (?, ?, ?) |
379 |
|); |
380 |
my $sth_update = $dbh->prepare(q| |
381 |
UPDATE default_branch_circ_rules |
382 |
SET maxissueqty = ?, |
383 |
maxonsiteissueqty = ? |
384 |
WHERE branchcode = ? |
385 |
|); |
386 |
$sth_search->execute($branch); |
387 |
my $res = $sth_search->fetchrow_hashref(); |
388 |
if ($res->{total}) { |
389 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch); |
390 |
} else { |
391 |
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty); |
392 |
} |
393 |
} else { |
394 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
395 |
FROM branch_borrower_circ_rules |
396 |
WHERE branchcode = ? |
397 |
AND categorycode = ?"); |
398 |
my $sth_insert = $dbh->prepare(q| |
399 |
INSERT INTO branch_borrower_circ_rules |
400 |
(branchcode, categorycode, maxissueqty, maxonsiteissueqty) |
401 |
VALUES (?, ?, ?, ?) |
402 |
|); |
403 |
my $sth_update = $dbh->prepare(q| |
404 |
UPDATE branch_borrower_circ_rules |
405 |
SET maxissueqty = ?, |
406 |
maxonsiteissueqty = ? |
407 |
WHERE branchcode = ? |
408 |
AND categorycode = ? |
409 |
|); |
410 |
|
411 |
$sth_search->execute($branch, $categorycode); |
412 |
my $res = $sth_search->fetchrow_hashref(); |
413 |
if ($res->{total}) { |
414 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode); |
415 |
} else { |
416 |
$sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty); |
417 |
} |
418 |
|
419 |
Koha::CirculationRules->set_rule( |
420 |
{ |
363 |
{ |
|
|
364 |
categorycode => undef, |
365 |
itemtype => undef, |
421 |
branchcode => $branch, |
366 |
branchcode => $branch, |
|
|
367 |
rules => { |
368 |
max_holds => $max_holds, |
369 |
maxissueqty => $maxissueqty, |
370 |
maxonsiteissueqty => $maxonsiteissueqty, |
371 |
} |
372 |
} |
373 |
); |
374 |
} else { |
375 |
Koha::CirculationRules->set_rules( |
376 |
{ |
422 |
categorycode => $categorycode, |
377 |
categorycode => $categorycode, |
423 |
itemtype => undef, |
378 |
itemtype => undef, |
424 |
rule_name => 'max_holds', |
379 |
branchcode => $branch, |
425 |
rule_value => $max_holds, |
380 |
rules => { |
|
|
381 |
max_holds => $max_holds, |
382 |
maxissueqty => $maxissueqty, |
383 |
maxonsiteissueqty => $maxonsiteissueqty, |
384 |
} |
426 |
} |
385 |
} |
427 |
); |
386 |
); |
428 |
} |
387 |
} |
Lines 590-630
while (my $row = $sth2->fetchrow_hashref) {
Link Here
|
590 |
|
549 |
|
591 |
my @sorted_row_loop = sort by_category_and_itemtype @row_loop; |
550 |
my @sorted_row_loop = sort by_category_and_itemtype @row_loop; |
592 |
|
551 |
|
593 |
my $sth_branch_cat; |
|
|
594 |
if ($branch eq "*") { |
595 |
$sth_branch_cat = $dbh->prepare(" |
596 |
SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode |
597 |
FROM default_borrower_circ_rules |
598 |
JOIN categories USING (categorycode) |
599 |
|
600 |
"); |
601 |
$sth_branch_cat->execute(); |
602 |
} else { |
603 |
$sth_branch_cat = $dbh->prepare(" |
604 |
SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode |
605 |
FROM branch_borrower_circ_rules |
606 |
JOIN categories USING (categorycode) |
607 |
WHERE branch_borrower_circ_rules.branchcode = ? |
608 |
"); |
609 |
$sth_branch_cat->execute($branch); |
610 |
} |
611 |
|
612 |
my @branch_cat_rules = (); |
613 |
while (my $row = $sth_branch_cat->fetchrow_hashref) { |
614 |
push @branch_cat_rules, $row; |
615 |
} |
616 |
my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules; |
617 |
|
618 |
# note undef maxissueqty so that template can deal with them |
619 |
foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { |
620 |
$entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); |
621 |
$entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty}); |
622 |
$entry->{unlimited_max_holds} = 1 unless defined($entry->{max_holds}); |
623 |
$entry->{unlimited_holds_per_day} = 1 unless defined($entry->{holds_per_day}); |
624 |
} |
625 |
|
626 |
@sorted_row_loop = sort by_category_and_itemtype @row_loop; |
627 |
|
628 |
my $sth_branch_item; |
552 |
my $sth_branch_item; |
629 |
if ($branch eq "*") { |
553 |
if ($branch eq "*") { |
630 |
$sth_branch_item = $dbh->prepare(" |
554 |
$sth_branch_item = $dbh->prepare(" |
Lines 665-671
foreach my $entry (@sorted_branch_item_rules) {
Link Here
|
665 |
|
589 |
|
666 |
$template->param(show_branch_cat_rule_form => 1); |
590 |
$template->param(show_branch_cat_rule_form => 1); |
667 |
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); |
591 |
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); |
668 |
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); |
|
|
669 |
|
592 |
|
670 |
my $sth_defaults; |
593 |
my $sth_defaults; |
671 |
if ($branch eq "*") { |
594 |
if ($branch eq "*") { |