@@ -, +, @@ circulation_rules both on and off site --- C4/Circulation.pm | 125 ++++++----- Koha/CirculationRules.pm | 13 +- admin/smart-rules.pl | 248 ++++++++------------- installer/data/mysql/atomicupdate/bug_18925.perl | 75 +++++++ installer/data/mysql/kohastructure.sql | 37 --- .../prog/en/modules/admin/smart-rules.tt | 79 ++++--- t/db_dependent/Circulation.t | 26 ++- t/db_dependent/Circulation/Branch.t | 60 +++-- t/db_dependent/Circulation/GetHardDueDate.t | 16 +- t/db_dependent/Circulation/Returns.t | 1 - t/db_dependent/Circulation/SwitchOnSiteCheckouts.t | 38 ++-- t/db_dependent/Circulation/TooMany.t | 105 +++++---- .../Holds/DisallowHoldIfItemsAvailable.t | 1 - t/db_dependent/Reserves.t | 14 +- 14 files changed, 440 insertions(+), 398 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18925.perl --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -396,10 +396,20 @@ sub TooMany { # given branch, patron category, and item type, determine # applicable issuing rule - my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( - { categorycode => $cat_borrower, + my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( + { + categorycode => $cat_borrower, + itemtype => $type, + branchcode => $branch, + rule_name => 'maxissueqty', + } + ); + my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( + { + categorycode => $cat_borrower, itemtype => $type, - branchcode => $branch + branchcode => $branch, + rule_name => 'maxonsiteissueqty', } ); @@ -407,7 +417,7 @@ sub TooMany { # if a rule is found and has a loan limit set, count # how many loans the patron already has that meet that # rule - if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) { + if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) { my @bind_params; my $count_query = q| SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts @@ -415,7 +425,7 @@ sub TooMany { JOIN items USING (itemnumber) |; - my $rule_itemtype = $issuing_rule->itemtype; + my $rule_itemtype = $maxissueqty_rule->itemtype; if ($rule_itemtype eq "*") { # matching rule has the default item type, so count only # those existing loans that don't fall under a more @@ -436,8 +446,8 @@ sub TooMany { AND itemtype <> '*' ) "; } - push @bind_params, $issuing_rule->branchcode; - push @bind_params, $issuing_rule->categorycode; + push @bind_params, $maxissueqty_rule->branchcode; + push @bind_params, $maxissueqty_rule->categorycode; push @bind_params, $cat_borrower; } else { # rule has specific item type, so count loans of that @@ -453,7 +463,7 @@ sub TooMany { $count_query .= " AND borrowernumber = ? "; push @bind_params, $borrower->{'borrowernumber'}; - my $rule_branch = $issuing_rule->branchcode; + my $rule_branch = $maxissueqty_rule->branchcode; if ($rule_branch ne "*") { if (C4::Context->preference('CircControl') eq 'PickupLibrary') { $count_query .= " AND issues.branchcode = ? "; @@ -468,8 +478,8 @@ sub TooMany { my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params ); - my $max_checkouts_allowed = $issuing_rule->maxissueqty; - my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty; + my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0; + my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0; if ( $onsite_checkout ) { if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { @@ -554,7 +564,7 @@ sub TooMany { } } - if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { + if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; } @@ -1579,14 +1589,11 @@ maxonsiteissueqty - maximum of on-site checkouts that a patron of the given category can have at the given branch. If the value is undef, no limit. -This will first check for a specific branch and -category match from branch_borrower_circ_rules. - -If no rule is found, it will then check default_branch_circ_rules -(same branch, default category). If no rule is found, -it will then check default_borrower_circ_rules (default -branch, same category), then failing that, default_circ_rules -(default branch, default category). +This will check for different branch/category combinations in the following order: +branch and category +branch only +category only +default branch and category If no rule has been found in the database, it will default to the buillt in rule: @@ -1603,44 +1610,54 @@ wildcards. sub GetBranchBorrowerCircRule { my ( $branchcode, $categorycode ) = @_; - my $rules; - my $dbh = C4::Context->dbh(); - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM branch_borrower_circ_rules - WHERE branchcode = ? - AND categorycode = ? - |, {}, $branchcode, $categorycode ) ; - return $rules if $rules; - - # try same branch, default borrower category - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM default_branch_circ_rules - WHERE branchcode = ? - |, {}, $branchcode ) ; - return $rules if $rules; - - # try default branch, same borrower category - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM default_borrower_circ_rules - WHERE categorycode = ? - |, {}, $categorycode ) ; - return $rules if $rules; - - # try default branch, default borrower category - $rules = $dbh->selectrow_hashref( q| - SELECT maxissueqty, maxonsiteissueqty - FROM default_circ_rules - |, {} ); - return $rules if $rules; + # Set search prededences + my @params = ( + { + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => undef, + }, + { + branchcode => $branchcode, + categorycode => undef, + itemtype => undef, + }, + { + branchcode => undef, + categorycode => $categorycode, + itemtype => undef, + }, + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + }, + ); - # built-in default circulation rule - return { - maxissueqty => undef, + # Initialize default values + my $rules = { + maxissueqty => undef, maxonsiteissueqty => undef, }; + + # Search for rules! + foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) { + foreach my $params (@params) { + my $rule = Koha::CirculationRules->search( + { + rule_name => $rule_name, + %$params, + } + )->next(); + + if ( $rule ) { + $rules->{$rule_name} = $rule->rule_value; + last; + } + } + } + + return $rules; } =head2 GetBranchItemRule --- a/Koha/CirculationRules.pm +++ a/Koha/CirculationRules.pm @@ -136,24 +136,27 @@ sub set_rule { sub set_rules { my ( $self, $params ) = @_; - warn Data::Dumper::Dumper( $params ); my $branchcode = $params->{branchcode}; my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; my $rules = $params->{rules}; - foreach my $rule (@$rules) { - Koha::CirculationRules->set_rule( + my $rule_objects = []; + while ( my ( $rule_name, $rule_value ) = each %$rules ) { + my $rule_object = Koha::CirculationRules->set_rule( { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, - rule_name => $rule->{rule_name}, - rule_value => $rule->{rule_value}, + rule_name => $rule_name, + rule_value => $rule_value, } ); + push( @$rule_objects, $rule_object ); } + + return $rule_objects; } =head3 type --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -80,28 +80,22 @@ elsif ($op eq 'delete-branch-cat') { if ($categorycode eq "*") { my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); $sth_delete->execute(); - } else { - my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules - WHERE categorycode = ?"); - $sth_delete->execute($categorycode); } } elsif ($categorycode eq "*") { my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules WHERE branchcode = ?"); $sth_delete->execute($branch); - } else { - my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules - WHERE branchcode = ? - AND categorycode = ?"); - $sth_delete->execute($branch, $categorycode); } - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { - branchcode => $branch, - categorycode => $categorycode, + categorycode => $categorycode eq '*' ? undef : $categorycode, + branchcode => $branch eq '*' ? undef : $branch, itemtype => undef, - rule_name => 'max_holds', - rule_value => undef, + rules => { + max_holds => undef, + maxissueqty => undef, + maxonsiteissueqty => undef, + } } ); } @@ -182,8 +176,6 @@ elsif ($op eq 'add') { firstremind => $firstremind, chargeperiod => $chargeperiod, chargeperiod_charge_at => $chargeperiod_charge_at, - maxissueqty => $maxissueqty, - maxonsiteissueqty => $maxonsiteissueqty, renewalsallowed => $renewalsallowed, renewalperiod => $renewalperiod, norenewalbefore => $norenewalbefore, @@ -211,6 +203,18 @@ elsif ($op eq 'add') { Koha::IssuingRule->new()->set($params)->store(); } + Koha::CirculationRules->set_rules( + { + categorycode => $bor, + itemtype => $itemtype, + branchcode => $br, + rules => { + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); + } elsif ($op eq "set-branch-defaults") { my $categorycode = $input->param('categorycode'); @@ -230,35 +234,59 @@ elsif ($op eq "set-branch-defaults") { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_circ_rules"); my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules - (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) - VALUES (?, ?, ?, ?, ?)"); + (holdallowed, hold_fulfillment_policy, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); + SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); + $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); } else { - $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); + $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); } + + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => undef, + rules => { + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_branch_circ_rules WHERE branchcode = ?"); my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules - (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) - VALUES (?, ?, ?, ?, ?, ?)"); + (branchcode, holdallowed, hold_fulfillment_policy, returnbranch) + VALUES (?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules - SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? + SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? WHERE branchcode = ?"); $sth_search->execute($branch); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); + $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); } else { - $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); + $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch); } + + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => $branch, + rules => { + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); } } elsif ($op eq "add-branch-cat") { @@ -275,124 +303,56 @@ elsif ($op eq "add-branch-cat") { if ($branch eq "*") { if ($categorycode eq "*") { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM default_circ_rules"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO default_circ_rules - (maxissueqty, maxonsiteissueqty) - VALUES (?, ?, ) - |); - my $sth_update = $dbh->prepare(q| - UPDATE default_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ? - |); - - $sth_search->execute(); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute( $maxissueqty, $maxonsiteissueqty ); - } else { - $sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); - } - - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { - branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'max_holds', - rule_value => $max_holds, + branchcode => undef, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } } ); } else { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM default_borrower_circ_rules - WHERE categorycode = ?"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO default_borrower_circ_rules - (categorycode, maxissueqty, maxonsiteissueqty) - VALUES (?, ?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE default_borrower_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ? - WHERE categorycode = ? - |); - $sth_search->execute($branch); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); - } else { - $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); - } - - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { - branchcode => undef, categorycode => $categorycode, itemtype => undef, - rule_name => 'max_holds', - rule_value => $max_holds, + branchcode => undef, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } } ); } } elsif ($categorycode eq "*") { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM default_branch_circ_rules - WHERE branchcode = ?"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO default_branch_circ_rules - (branchcode, maxissueqty, maxonsiteissueqty) - VALUES (?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE default_branch_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ? - WHERE branchcode = ? - |); - $sth_search->execute($branch); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch); - } else { - $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty); - } - } else { - my $sth_search = $dbh->prepare("SELECT count(*) AS total - FROM branch_borrower_circ_rules - WHERE branchcode = ? - AND categorycode = ?"); - my $sth_insert = $dbh->prepare(q| - INSERT INTO branch_borrower_circ_rules - (branchcode, categorycode, maxissueqty, maxonsiteissueqty) - VALUES (?, ?, ?, ?) - |); - my $sth_update = $dbh->prepare(q| - UPDATE branch_borrower_circ_rules - SET maxissueqty = ?, - maxonsiteissueqty = ? - WHERE branchcode = ? - AND categorycode = ? - |); - - $sth_search->execute($branch, $categorycode); - my $res = $sth_search->fetchrow_hashref(); - if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode); - } else { - $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty); - } - - Koha::CirculationRules->set_rule( + Koha::CirculationRules->set_rules( { + categorycode => undef, + itemtype => undef, branchcode => $branch, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } + } + ); + } else { + Koha::CirculationRules->set_rules( + { categorycode => $categorycode, itemtype => undef, - rule_name => 'max_holds', - rule_value => $max_holds, + branchcode => $branch, + rules => { + max_holds => $max_holds, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, + } } ); } @@ -560,39 +520,6 @@ while (my $row = $sth2->fetchrow_hashref) { my @sorted_row_loop = sort by_category_and_itemtype @row_loop; -my $sth_branch_cat; -if ($branch eq "*") { - $sth_branch_cat = $dbh->prepare(" - SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode - FROM default_borrower_circ_rules - JOIN categories USING (categorycode) - - "); - $sth_branch_cat->execute(); -} else { - $sth_branch_cat = $dbh->prepare(" - SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode - FROM branch_borrower_circ_rules - JOIN categories USING (categorycode) - WHERE branch_borrower_circ_rules.branchcode = ? - "); - $sth_branch_cat->execute($branch); -} - -my @branch_cat_rules = (); -while (my $row = $sth_branch_cat->fetchrow_hashref) { - push @branch_cat_rules, $row; -} -my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules; - -# note undef maxissueqty so that template can deal with them -foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { - $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); - $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty}); -} - -@sorted_row_loop = sort by_category_and_itemtype @row_loop; - my $sth_branch_item; if ($branch eq "*") { $sth_branch_item = $dbh->prepare(" @@ -633,7 +560,6 @@ foreach my $entry (@sorted_branch_item_rules) { $template->param(show_branch_cat_rule_form => 1); $template->param(branch_item_rule_loop => \@sorted_branch_item_rules); -$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); my $sth_defaults; if ($branch eq "*") { --- a/installer/data/mysql/atomicupdate/bug_18925.perl +++ a/installer/data/mysql/atomicupdate/bug_18925.perl @@ -0,0 +1,75 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, NULL, 'maxissueqty', maxissueqty + FROM branch_borrower_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM branch_borrower_circ_rules + "); + $dbh->do("DROP TABLE branch_borrower_circ_rules"); + } + + if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, NULL, NULL, 'maxissueqty', maxissueqty + FROM default_borrower_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM default_borrower_circ_rules + "); + $dbh->do("DROP TABLE default_borrower_circ_rules"); + } + + if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, NULL, NULL, 'maxissueqty', maxissueqty + FROM default_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM default_circ_rules + "); + $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); + } + + if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, branchcode, NULL, 'maxissueqty', maxissueqty + FROM default_branch_circ_rules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty + FROM default_branch_circ_rules + "); + $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); + } + + if ( column_exists( 'issuingrules', 'maxissueqty' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty + FROM issuingrules + "); + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty + FROM issuingrules + "); + $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -368,45 +368,12 @@ CREATE TABLE collections_tracking ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- --- Table structure for table `branch_borrower_circ_rules` --- - -DROP TABLE IF EXISTS `branch_borrower_circ_rules`; -CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category" - `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode) - `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode) - `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch - `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch - PRIMARY KEY (`categorycode`, `branchcode`), - CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) - ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) - ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table `default_borrower_circ_rules` --- - -DROP TABLE IF EXISTS `default_borrower_circ_rules`; -CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy" - `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul - `maxissueqty` int(4) default NULL, - `maxonsiteissueqty` int(4) default NULL, - PRIMARY KEY (`categorycode`), - CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) - ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- -- Table structure for table `default_branch_circ_rules` -- DROP TABLE IF EXISTS `default_branch_circ_rules`; CREATE TABLE `default_branch_circ_rules` ( `branchcode` VARCHAR(10) NOT NULL, - `maxissueqty` int(4) default NULL, - `maxonsiteissueqty` int(4) default NULL, `holdallowed` tinyint(1) default NULL, hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode `returnbranch` varchar(15) default NULL, @@ -422,8 +389,6 @@ CREATE TABLE `default_branch_circ_rules` ( DROP TABLE IF EXISTS `default_circ_rules`; CREATE TABLE `default_circ_rules` ( `singleton` enum('singleton') NOT NULL default 'singleton', - `maxissueqty` int(4) default NULL, - `maxonsiteissueqty` int(4) default NULL, `holdallowed` int(1) default NULL, hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode `returnbranch` varchar(15) default NULL, @@ -866,8 +831,6 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period `accountsent` int(11) default NULL, -- not used? always NULL `chargename` varchar(100) default NULL, -- not used? always NULL - `maxissueqty` int(4) default NULL, -- total number of checkouts allowed - `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours) `hardduedate` date default NULL, -- hard due date --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -1,5 +1,14 @@ [% USE Branches %] +[% USE Categories %] [% USE CirculationRules %] + +[% SET branchcode = humanbranch %] + +[% SET categorycodes = ['*'] %] +[% FOREACH pc IN patron_categories %] + [% categorycodes.push( pc.id ) %] +[% END %] + [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Circulation and fine rules [% INCLUDE 'doc-head-close.inc' %] @@ -212,18 +221,22 @@ $(document).ready(function() { [% rule.translated_description %] [% END %] - [% IF ( rule.unlimited_maxissueqty ) %] - Unlimited - [% ELSE %] - [% rule.maxissueqty %] - [% END %] - - [% IF rule.unlimited_maxonsiteissueqty %] + + [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %] + [% IF rule_value %] + [% rule_value %] + [% ELSE %] Unlimited + [% END %] + + + [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %] + [% IF rule_value %] + [% rule_value %] [% ELSE %] - [% rule.maxonsiteissueqty %] + Unlimited [% END %] - + [% rule.issuelength %] [% rule.lengthunit %] @@ -446,8 +459,14 @@ $(document).ready(function() { Defaults[% UNLESS ( default_rules ) %] (not set)[% END %] - - + + [% SET maxissueqty = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %] + + + + [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %] + +