Lines 87-114
elsif ($op eq 'delete-branch-cat') {
Link Here
|
87 |
if ($categorycode eq "*") { |
87 |
if ($categorycode eq "*") { |
88 |
my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); |
88 |
my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); |
89 |
$sth_delete->execute(); |
89 |
$sth_delete->execute(); |
90 |
} else { |
|
|
91 |
my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules |
92 |
WHERE categorycode = ?"); |
93 |
$sth_delete->execute($categorycode); |
94 |
} |
90 |
} |
95 |
} elsif ($categorycode eq "*") { |
91 |
} elsif ($categorycode eq "*") { |
96 |
my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules |
92 |
my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules |
97 |
WHERE branchcode = ?"); |
93 |
WHERE branchcode = ?"); |
98 |
$sth_delete->execute($branch); |
94 |
$sth_delete->execute($branch); |
99 |
} else { |
|
|
100 |
my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules |
101 |
WHERE branchcode = ? |
102 |
AND categorycode = ?"); |
103 |
$sth_delete->execute($branch, $categorycode); |
104 |
} |
95 |
} |
105 |
Koha::CirculationRules->set_rule( |
96 |
Koha::CirculationRules->set_rules( |
106 |
{ |
97 |
{ |
107 |
branchcode => $branch, |
98 |
categorycode => $categorycode eq '*' ? undef : $categorycode, |
108 |
categorycode => $categorycode, |
99 |
branchcode => $branch eq '*' ? undef : $branch, |
109 |
itemtype => undef, |
100 |
itemtype => undef, |
110 |
rule_name => 'max_holds', |
101 |
rules => { |
111 |
rule_value => undef, |
102 |
max_holds => undef, |
|
|
103 |
maxissueqty => undef, |
104 |
maxonsiteissueqty => undef, |
105 |
} |
112 |
} |
106 |
} |
113 |
); |
107 |
); |
114 |
} |
108 |
} |
Lines 189-196
elsif ($op eq 'add') {
Link Here
|
189 |
firstremind => $firstremind, |
183 |
firstremind => $firstremind, |
190 |
chargeperiod => $chargeperiod, |
184 |
chargeperiod => $chargeperiod, |
191 |
chargeperiod_charge_at => $chargeperiod_charge_at, |
185 |
chargeperiod_charge_at => $chargeperiod_charge_at, |
192 |
maxissueqty => $maxissueqty, |
|
|
193 |
maxonsiteissueqty => $maxonsiteissueqty, |
194 |
renewalsallowed => $renewalsallowed, |
186 |
renewalsallowed => $renewalsallowed, |
195 |
renewalperiod => $renewalperiod, |
187 |
renewalperiod => $renewalperiod, |
196 |
norenewalbefore => $norenewalbefore, |
188 |
norenewalbefore => $norenewalbefore, |
Lines 218-223
elsif ($op eq 'add') {
Link Here
|
218 |
Koha::IssuingRule->new()->set($params)->store(); |
210 |
Koha::IssuingRule->new()->set($params)->store(); |
219 |
} |
211 |
} |
220 |
|
212 |
|
|
|
213 |
Koha::CirculationRules->set_rules( |
214 |
{ |
215 |
categorycode => $bor, |
216 |
itemtype => $itemtype, |
217 |
branchcode => $br, |
218 |
rules => { |
219 |
maxissueqty => $maxissueqty, |
220 |
maxonsiteissueqty => $maxonsiteissueqty, |
221 |
} |
222 |
} |
223 |
); |
224 |
|
221 |
} |
225 |
} |
222 |
elsif ($op eq "set-branch-defaults") { |
226 |
elsif ($op eq "set-branch-defaults") { |
223 |
my $categorycode = $input->param('categorycode'); |
227 |
my $categorycode = $input->param('categorycode'); |
Lines 240-274
elsif ($op eq "set-branch-defaults") {
Link Here
|
240 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
244 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
241 |
FROM default_circ_rules"); |
245 |
FROM default_circ_rules"); |
242 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
246 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
243 |
(maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) |
247 |
(holdallowed, hold_fulfillment_policy, returnbranch) |
244 |
VALUES (?, ?, ?, ?, ?)"); |
248 |
VALUES (?, ?, ?)"); |
245 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
249 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
246 |
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); |
250 |
SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); |
247 |
|
251 |
|
248 |
$sth_search->execute(); |
252 |
$sth_search->execute(); |
249 |
my $res = $sth_search->fetchrow_hashref(); |
253 |
my $res = $sth_search->fetchrow_hashref(); |
250 |
if ($res->{total}) { |
254 |
if ($res->{total}) { |
251 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
255 |
$sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); |
252 |
} else { |
256 |
} else { |
253 |
$sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
257 |
$sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); |
254 |
} |
258 |
} |
|
|
259 |
|
260 |
Koha::CirculationRules->set_rules( |
261 |
{ |
262 |
categorycode => undef, |
263 |
itemtype => undef, |
264 |
branchcode => undef, |
265 |
rules => { |
266 |
maxissueqty => $maxissueqty, |
267 |
maxonsiteissueqty => $maxonsiteissueqty, |
268 |
} |
269 |
} |
270 |
); |
255 |
} else { |
271 |
} else { |
256 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
272 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
257 |
FROM default_branch_circ_rules |
273 |
FROM default_branch_circ_rules |
258 |
WHERE branchcode = ?"); |
274 |
WHERE branchcode = ?"); |
259 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
275 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
260 |
(branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) |
276 |
(branchcode, holdallowed, hold_fulfillment_policy, returnbranch) |
261 |
VALUES (?, ?, ?, ?, ?, ?)"); |
277 |
VALUES (?, ?, ?, ?)"); |
262 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
278 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
263 |
SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? |
279 |
SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? |
264 |
WHERE branchcode = ?"); |
280 |
WHERE branchcode = ?"); |
265 |
$sth_search->execute($branch); |
281 |
$sth_search->execute($branch); |
266 |
my $res = $sth_search->fetchrow_hashref(); |
282 |
my $res = $sth_search->fetchrow_hashref(); |
267 |
if ($res->{total}) { |
283 |
if ($res->{total}) { |
268 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); |
284 |
$sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); |
269 |
} else { |
285 |
} else { |
270 |
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
286 |
$sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch); |
271 |
} |
287 |
} |
|
|
288 |
|
289 |
Koha::CirculationRules->set_rules( |
290 |
{ |
291 |
categorycode => undef, |
292 |
itemtype => undef, |
293 |
branchcode => $branch, |
294 |
rules => { |
295 |
maxissueqty => $maxissueqty, |
296 |
maxonsiteissueqty => $maxonsiteissueqty, |
297 |
} |
298 |
} |
299 |
); |
272 |
} |
300 |
} |
273 |
Koha::CirculationRules->set_rule( |
301 |
Koha::CirculationRules->set_rule( |
274 |
{ |
302 |
{ |
Lines 294-417
elsif ($op eq "add-branch-cat") {
Link Here
|
294 |
|
322 |
|
295 |
if ($branch eq "*") { |
323 |
if ($branch eq "*") { |
296 |
if ($categorycode eq "*") { |
324 |
if ($categorycode eq "*") { |
297 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
325 |
Koha::CirculationRules->set_rules( |
298 |
FROM default_circ_rules"); |
|
|
299 |
my $sth_insert = $dbh->prepare(q| |
300 |
INSERT INTO default_circ_rules |
301 |
(maxissueqty, maxonsiteissueqty) |
302 |
VALUES (?, ?, ) |
303 |
|); |
304 |
my $sth_update = $dbh->prepare(q| |
305 |
UPDATE default_circ_rules |
306 |
SET maxissueqty = ?, |
307 |
maxonsiteissueqty = ? |
308 |
|); |
309 |
|
310 |
$sth_search->execute(); |
311 |
my $res = $sth_search->fetchrow_hashref(); |
312 |
if ($res->{total}) { |
313 |
$sth_update->execute( $maxissueqty, $maxonsiteissueqty ); |
314 |
} else { |
315 |
$sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); |
316 |
} |
317 |
|
318 |
Koha::CirculationRules->set_rule( |
319 |
{ |
326 |
{ |
320 |
branchcode => undef, |
|
|
321 |
categorycode => undef, |
327 |
categorycode => undef, |
322 |
itemtype => undef, |
328 |
itemtype => undef, |
323 |
rule_name => 'max_holds', |
329 |
branchcode => undef, |
324 |
rule_value => $max_holds, |
330 |
rules => { |
|
|
331 |
max_holds => $max_holds, |
332 |
maxissueqty => $maxissueqty, |
333 |
maxonsiteissueqty => $maxonsiteissueqty, |
334 |
} |
325 |
} |
335 |
} |
326 |
); |
336 |
); |
327 |
} else { |
337 |
} else { |
328 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
338 |
Koha::CirculationRules->set_rules( |
329 |
FROM default_borrower_circ_rules |
|
|
330 |
WHERE categorycode = ?"); |
331 |
my $sth_insert = $dbh->prepare(q| |
332 |
INSERT INTO default_borrower_circ_rules |
333 |
(categorycode, maxissueqty, maxonsiteissueqty) |
334 |
VALUES (?, ?, ?) |
335 |
|); |
336 |
my $sth_update = $dbh->prepare(q| |
337 |
UPDATE default_borrower_circ_rules |
338 |
SET maxissueqty = ?, |
339 |
maxonsiteissueqty = ? |
340 |
WHERE categorycode = ? |
341 |
|); |
342 |
$sth_search->execute($branch); |
343 |
my $res = $sth_search->fetchrow_hashref(); |
344 |
if ($res->{total}) { |
345 |
$sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); |
346 |
} else { |
347 |
$sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); |
348 |
} |
349 |
|
350 |
Koha::CirculationRules->set_rule( |
351 |
{ |
339 |
{ |
352 |
branchcode => '*', |
340 |
branchcode => '*', |
353 |
categorycode => $categorycode, |
341 |
categorycode => $categorycode, |
354 |
itemtype => undef, |
342 |
itemtype => undef, |
355 |
rule_name => 'max_holds', |
343 |
rules => { |
356 |
rule_value => $max_holds, |
344 |
max_holds => $max_holds, |
|
|
345 |
maxissueqty => $maxissueqty, |
346 |
maxonsiteissueqty => $maxonsiteissueqty, |
347 |
} |
357 |
} |
348 |
} |
358 |
); |
349 |
); |
359 |
} |
350 |
} |
360 |
} elsif ($categorycode eq "*") { |
351 |
} elsif ($categorycode eq "*") { |
361 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
352 |
Koha::CirculationRules->set_rules( |
362 |
FROM default_branch_circ_rules |
|
|
363 |
WHERE branchcode = ?"); |
364 |
my $sth_insert = $dbh->prepare(q| |
365 |
INSERT INTO default_branch_circ_rules |
366 |
(branchcode, maxissueqty, maxonsiteissueqty) |
367 |
VALUES (?, ?, ?) |
368 |
|); |
369 |
my $sth_update = $dbh->prepare(q| |
370 |
UPDATE default_branch_circ_rules |
371 |
SET maxissueqty = ?, |
372 |
maxonsiteissueqty = ? |
373 |
WHERE branchcode = ? |
374 |
|); |
375 |
$sth_search->execute($branch); |
376 |
my $res = $sth_search->fetchrow_hashref(); |
377 |
if ($res->{total}) { |
378 |
$sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch); |
379 |
} else { |
380 |
$sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty); |
381 |
} |
382 |
} else { |
383 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
384 |
FROM branch_borrower_circ_rules |
385 |
WHERE branchcode = ? |
386 |
AND categorycode = ?"); |
387 |
my $sth_insert = $dbh->prepare(q| |
388 |
INSERT INTO branch_borrower_circ_rules |
389 |
(branchcode, categorycode, maxissueqty, maxonsiteissueqty) |
390 |
VALUES (?, ?, ?, ?) |
391 |
|); |
392 |
my $sth_update = $dbh->prepare(q| |
393 |
UPDATE branch_borrower_circ_rules |
394 |
SET maxissueqty = ?, |
395 |
maxonsiteissueqty = ? |
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, $branch, $categorycode); |
404 |
} else { |
405 |
$sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty); |
406 |
} |
407 |
|
408 |
Koha::CirculationRules->set_rule( |
409 |
{ |
353 |
{ |
|
|
354 |
categorycode => undef, |
355 |
itemtype => undef, |
410 |
branchcode => $branch, |
356 |
branchcode => $branch, |
|
|
357 |
rules => { |
358 |
max_holds => $max_holds, |
359 |
maxissueqty => $maxissueqty, |
360 |
maxonsiteissueqty => $maxonsiteissueqty, |
361 |
} |
362 |
} |
363 |
); |
364 |
} else { |
365 |
Koha::CirculationRules->set_rules( |
366 |
{ |
411 |
categorycode => $categorycode, |
367 |
categorycode => $categorycode, |
412 |
itemtype => undef, |
368 |
itemtype => undef, |
413 |
rule_name => 'max_holds', |
369 |
branchcode => $branch, |
414 |
rule_value => $max_holds, |
370 |
rules => { |
|
|
371 |
max_holds => $max_holds, |
372 |
maxissueqty => $maxissueqty, |
373 |
maxonsiteissueqty => $maxonsiteissueqty, |
374 |
} |
415 |
} |
375 |
} |
416 |
); |
376 |
); |
417 |
} |
377 |
} |
Lines 579-617
while (my $row = $sth2->fetchrow_hashref) {
Link Here
|
579 |
|
539 |
|
580 |
my @sorted_row_loop = sort by_category_and_itemtype @row_loop; |
540 |
my @sorted_row_loop = sort by_category_and_itemtype @row_loop; |
581 |
|
541 |
|
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 |
} |
612 |
|
613 |
@sorted_row_loop = sort by_category_and_itemtype @row_loop; |
614 |
|
615 |
my $sth_branch_item; |
542 |
my $sth_branch_item; |
616 |
if ($branch eq "*") { |
543 |
if ($branch eq "*") { |
617 |
$sth_branch_item = $dbh->prepare(" |
544 |
$sth_branch_item = $dbh->prepare(" |
Lines 652-658
foreach my $entry (@sorted_branch_item_rules) {
Link Here
|
652 |
|
579 |
|
653 |
$template->param(show_branch_cat_rule_form => 1); |
580 |
$template->param(show_branch_cat_rule_form => 1); |
654 |
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); |
581 |
$template->param(branch_item_rule_loop => \@sorted_branch_item_rules); |
655 |
$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); |
|
|
656 |
|
582 |
|
657 |
my $sth_defaults; |
583 |
my $sth_defaults; |
658 |
if ($branch eq "*") { |
584 |
if ($branch eq "*") { |