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