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