From 6e535354448a27ad29bfe6295d23d35ae70b05c3 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 21 Dec 2016 00:25:50 +0000 Subject: [PATCH] Bug 14866: [FOLLOW-UP] Make high holds work with different item types This patch fixes merge conflicts, fixes the indentation of the table in smart-rules.tt and uses Koha::IssuingRules->get_effective_issuing_rule. Keep in mind - I am sure that when the original patch for this was written (before get_effective_issuing_rule was used), it all worked fine. I had to add an extra line of code in my patch to get this method to work because it was fetching the WRONG circulation rule - one that did not have decreaseloanholds defined. I don't know if it was my patch that is broken or the get_effective_issuing_rule method that is not fetching the 'most specific/relevant' rule. Sponsored-by: Region Halland --- C4/Circulation.pm | 13 +- Koha/Schema/Result/Issuingrule.pm | 11 +- admin/smart-rules.pl | 2 +- .../bug_14866-add_decreaseloanholds.sql | 2 +- installer/data/mysql/kohastructure.sql | 11 +- .../prog/en/modules/admin/smart-rules.tt | 239 +++++++++++---------- 6 files changed, 146 insertions(+), 132 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 242d673..bd50b91 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -23,7 +23,6 @@ use strict; #use warnings; FIXME - Bug 2505 use DateTime; use POSIX qw( floor ); -use Koha::DateUtils; use C4::Context; use C4::Stats; use C4::Reserves; @@ -1049,14 +1048,20 @@ sub CanBookBeIssued { # Decrease loan period for item if rule exist in smart-rules.pl # Overrides decreaseLoanHighHoldsValue syspref my $branch = _GetCircControlBranch($item,$borrower); - my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branch); - my $issuedate = DateTime->now( time_zone => C4::Context->tz() ); + my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule( + { categorycode => $borrower->{categorycode}, + itemtype => $item->{itype}, + branchcode => $branch + } + ); + my $issuedate = dt_from_string(); my $calendar = Koha::Calendar->new( branchcode => $branch ); + $issuingrule->{decreaseloanholds} = 0 if not defined $issuingrule->{decreaseloanholds}; my $reduced_datedue = $calendar->addDate( $issuedate, $issuingrule->{decreaseloanholds} ); if ( defined($issuingrule->{decreaseloanholds}) ) { $needsconfirmation{HIGHHOLDS} = { - num_holds => $num, + num_holds => $issuingrule->{outstanding}, duration => $issuingrule->{decreaseloanholds}, returndate => output_pref($reduced_datedue), } diff --git a/Koha/Schema/Result/Issuingrule.pm b/Koha/Schema/Result/Issuingrule.pm index 5958055..ed683b5 100644 --- a/Koha/Schema/Result/Issuingrule.pm +++ b/Koha/Schema/Result/Issuingrule.pm @@ -221,6 +221,11 @@ __PACKAGE__->table("issuingrules"); extra: {list => ["no","yes","bib_only","item_only"]} is_nullable: 0 +=head2 decreaseloanholds + + data_type: 'integer' + is_nullable: 1 + =cut __PACKAGE__->add_columns( @@ -302,6 +307,8 @@ __PACKAGE__->add_columns( extra => { list => ["no", "yes", "bib_only", "item_only"] }, is_nullable => 0, }, + "decreaseloanholds", + { data_type => "integer", is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -321,8 +328,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("branchcode", "categorycode", "itemtype"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-12-13 12:44:30 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VBD8atc/D/6rN0D+aTaSOQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-06-07 03:02:31 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wRqrq6dJHXE+ocOQKhnKnA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index ebd255b..00cbfb4 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -160,7 +160,7 @@ elsif ($op eq 'add') { my $article_requests = $input->param('article_requests') || 'no'; my $overduefinescap = $input->param('overduefinescap') || undef; my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on'; - my $decreaseloanholds = $input->param('decreaseloanholds'); + my $decreaseloanholds = $input->param('decreaseloanholds') || undef; $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price"; my $params = { diff --git a/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds.sql b/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds.sql index c041a1c..f38c199 100644 --- a/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds.sql +++ b/installer/data/mysql/atomicupdate/bug_14866-add_decreaseloanholds.sql @@ -1 +1 @@ -ALTER TABLE issuingrules ADD decreaseloanholds INTEGER; +ALTER IGNORE TABLE issuingrules ADD decreaseloanholds INTEGER(11) DEFAULT NULL AFTER `article_requests`; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 909eda2..c1d4de9 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -858,11 +858,12 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed `holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode) - overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine - cap_fine_to_replacement_price BOOLEAN NOT NULL DEFAULT '0', -- cap the fine based on item's replacement price - onshelfholds tinyint(1) NOT NULL default 0, -- allow holds for items that are on shelf - opacitemholds char(1) NOT NULL default 'N', -- allow opac users to place specific items on hold - article_requests enum('no','yes','bib_only','item_only') NOT NULL DEFAULT 'no', -- allow article requests to be placed, + `overduefinescap` decimal(28,6) default NULL, -- the maximum amount of an overdue fine + `cap_fine_to_replacement_price` BOOLEAN NOT NULL DEFAULT '0', -- cap the fine based on item's replacement price + `onshelfholds` tinyint(1) NOT NULL default 0, -- allow holds for items that are on shelf + `opacitemholds` char(1) NOT NULL default 'N', -- allow opac users to place specific items on hold + `article_requests` enum('no','yes','bib_only','item_only') NOT NULL DEFAULT 'no', -- allow article requests to be placed, + `decreaseloanholds` int(11) default NULL, PRIMARY KEY (`branchcode`,`categorycode`,`itemtype`), KEY `categorycode` (`categorycode`), KEY `itemtype` (`itemtype`) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index f4dd8bc..0b93236 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -97,129 +97,130 @@ - [% FOREACH rule IN rules %] - - [% IF ( rule.default_humancategorycode ) %] - All - [% ELSE %] - [% rule.humancategorycode %] - [% END %] - - [% IF rule.default_translated_description %] - All - [% ELSE %] - [% rule.translated_description %] - [% END %] - - - Edit - Delete - - - [% IF ( rule.unlimited_maxissueqty ) %] - Unlimited - [% ELSE %] - [% rule.maxissueqty %] - [% END %] - - [% IF rule.unlimited_maxonsiteissueqty %] - Unlimited - [% ELSE %] - [% rule.maxonsiteissueqty %] - [% END %] - - [% rule.issuelength %] - - [% rule.lengthunit %] - - - [% IF ( rule.hardduedate ) %] + [% FOREACH rule IN rules %] + + + [% IF ( rule.default_humancategorycode ) %] + All + [% ELSE %] + [% rule.humancategorycode %] + [% END %] + + + [% IF rule.default_translated_description %] + All + [% ELSE %] + [% rule.translated_description %] + [% END %] + + + Edit + Delete + + + [% IF ( rule.unlimited_maxissueqty ) %] + Unlimited + [% ELSE %] + [% rule.maxissueqty %] + [% END %] + + + [% IF rule.unlimited_maxonsiteissueqty %] + Unlimited + [% ELSE %] + [% rule.maxonsiteissueqty %] + [% END %] + + [% rule.issuelength %] + [% rule.lengthunit %] + + [% IF ( rule.hardduedate ) %] [% IF ( rule.hardduedatebefore ) %] - before [% rule.hardduedate %] - + before [% rule.hardduedate %] + [% ELSIF ( rule.hardduedateexact ) %] - on [% rule.hardduedate %] - + on [% rule.hardduedate %] + [% ELSIF ( rule.hardduedateafter ) %] - after [% rule.hardduedate %] - + after [% rule.hardduedate %] + [% END %] - [% ELSE %] + [% ELSE %] None defined - [% END %] - - [% rule.fine %] - [% rule.chargeperiod %] - - [% IF rule.chargeperiod_charge_at %] - Start of interval - [% ELSE %] - End of interval - [% END %] - - [% rule.firstremind %] - [% rule.overduefinescap FILTER format("%.2f") %] - - [% IF rule.cap_fine_to_replacement_price %] - - [% ELSE %] - - [% END %] - - [% rule.finedays %] - [% rule.maxsuspensiondays %] - [% rule.suspension_chargeperiod %] - [% rule.renewalsallowed %] - [% rule.renewalperiod %] - [% rule.norenewalbefore %] - - [% IF ( rule.auto_renew ) %] - Yes - [% ELSE %] - No - [% END %] - - [% rule.no_auto_renewal_after %] - [% rule.no_auto_renewal_after_hard_limit %] - [% rule.reservesallowed %] - [% rule.holds_per_record %] - - [% IF rule.onshelfholds == 1 %] - Yes - [% ELSIF rule.onshelfholds == 2 %] - If all unavailable - [% ELSE %] - If any unavailable - [% END %] - - - [% IF rule.opacitemholds == 'F'%] - Force - [% ELSIF rule.opacitemholds == 'Y'%] - Allow - [% ELSE %] - Don't allow - [% END %] - - [% rule.decreaseloanholds %] - - [% IF rule.article_requests == 'no' %] - No - [% ELSIF rule.article_requests == 'yes' %] - Yes - [% ELSIF rule.article_requests == 'bib_only' %] - Record only - [% ELSIF rule.article_requests == 'item_only' %] - Item only - [% END %] - - [% rule.rentaldiscount %] - - Edit - Delete - - - [% END %] + [% END %] + + [% rule.fine %] + [% rule.chargeperiod %] + + [% IF rule.chargeperiod_charge_at %] + Start of interval + [% ELSE %] + End of interval + [% END %] + + [% rule.firstremind %] + [% rule.overduefinescap FILTER format("%.2f") %] + + [% IF rule.cap_fine_to_replacement_price %] + + [% ELSE %] + + [% END %] + + [% rule.finedays %] + [% rule.maxsuspensiondays %] + [% rule.suspension_chargeperiod %] + [% rule.renewalsallowed %] + [% rule.renewalperiod %] + [% rule.norenewalbefore %] + + [% IF ( rule.auto_renew ) %] + Yes + [% ELSE %] + No + [% END %] + + [% rule.no_auto_renewal_after %] + [% rule.no_auto_renewal_after_hard_limit %] + [% rule.reservesallowed %] + [% rule.holds_per_record %] + + [% IF rule.onshelfholds == 1 %] + Yes + [% ELSIF rule.onshelfholds == 2 %] + If all unavailable + [% ELSE %] + If any unavailable + [% END %] + + + [% IF rule.opacitemholds == 'F'%] + Force + [% ELSIF rule.opacitemholds == 'Y'%] + Allow + [% ELSE %] + Don't allow + [% END %] + + [% rule.decreaseloanholds %] + + [% IF rule.article_requests == 'no' %] + No + [% ELSIF rule.article_requests == 'yes' %] + Yes + [% ELSIF rule.article_requests == 'bib_only' %] + Record only + [% ELSIF rule.article_requests == 'item_only' %] + Item only + [% END %] + + [% rule.rentaldiscount %] + + Edit + Delete + + + [% END %]