From a664742ffd1bcb93f1e88764082ca5eca7c4bcbc Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 13 Mar 2013 08:36:57 -0400 Subject: [PATCH] Bug 9805 - Lost items are un-lost if returned, but not if renewed. If an item has a lost status, that status is removed when the item is returned. However, it is not removed if the item is renewed. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Browse to the circ rules 4) Note the "Renew lost?" and "Renewal marks lost found" rules 5) Set and test each of the rules both ways for the rules for all libraries 6) Repeat but for a specific branch this time Signed-off-by: Paul Poulain --- C4/Circulation.pm | 35 +++++++++++++++++- admin/smart-rules.pl | 38 +++++++++++--------- installer/data/mysql/atomicupdate/bug_9805.sql | 7 ++++ installer/data/mysql/kohastructure.sql | 4 +++ installer/data/mysql/updatedatabase.pl | 1 + .../intranet-tmpl/prog/en/includes/strings.inc | 1 + .../prog/en/modules/admin/smart-rules.tt | 42 +++++++++++++++++++++- .../intranet-tmpl/prog/en/modules/circ/renew.tt | 4 +++ .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 2 ++ 9 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_9805.sql diff --git a/C4/Circulation.pm b/C4/Circulation.pm index a1d7815..5506af4 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2925,6 +2925,13 @@ sub CanBookBeRenewed { return ( 0, "auto_too_soon" ); } + if ( $item->{itemlost} ) { + my $schema = Koha::Database->new()->schema(); + my $rule = $schema->resultset('DefaultBranchCircRule')->single( { branchcode => $branchcode } ); + $rule ||= $schema->resultset('DefaultCircRule')->single(); + return ( 0, "item_lost" ) unless $rule->renew_lost_allowed(); + } + return ( 1, undef ); } @@ -3005,7 +3012,33 @@ sub AddRenewal { # Update the renewal count on the item, and tell zebra to reindex $renews = $biblio->{'renewals'} + 1; - ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); + + my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); + my $schema = Koha::Database->new()->schema(); + my $rule = $schema->resultset('DefaultBranchCircRule')->single( { branchcode => _GetCircControlBranch( $item, $borrower ) } ); + $rule ||= $schema->resultset('DefaultCircRule')->single(); + + # If item was lost, it has now been found, reverse any list item charges if necessary. + my $itemlost = 0; + if ( $item->{itemlost} ) { + $itemlost = 1; + if ( $rule->renew_lost_found ) { + $itemlost = 0; + if ( C4::Context->preference('RefundLostItemFeeOnReturn') ) { + _FixAccountForLostAndReturned( $item->{itemnumber}, undef, $item->{barcode} ); + } + } + } + + ModItem( + { + renewals => $renews, + onloan => $datedue->strftime('%Y-%m-%d %H:%M'), + itemlost => $itemlost, + }, + $biblio->{'biblionumber'}, + $itemnumber + ); # Charge a new rental fee, if applicable? my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index da4e577..ed97a2d 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -188,11 +188,14 @@ elsif ($op eq 'add') { } elsif ($op eq "set-branch-defaults") { - my $categorycode = $input->param('categorycode'); - my $maxissueqty = $input->param('maxissueqty'); - my $maxonsiteissueqty = $input->param('maxonsiteissueqty'); - my $holdallowed = $input->param('holdallowed'); - my $returnbranch = $input->param('returnbranch'); + my $categorycode = $input->param('categorycode'); + my $maxissueqty = $input->param('maxissueqty'); + my $maxonsiteissueqty = $input->param('maxonsiteissueqty'); + my $holdallowed = $input->param('holdallowed'); + my $returnbranch = $input->param('returnbranch'); + my $renew_lost_allowed = $input->param('renew_lost_allowed'); + my $renew_lost_found = $input->param('renew_lost_found'); + $maxissueqty =~ s/\s//g; $maxissueqty = undef if $maxissueqty !~ /^\d+/; $maxonsiteissueqty =~ s/\s//g; @@ -204,17 +207,17 @@ 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, returnbranch) - VALUES (?, ?, ?, ?)"); + (maxissueqty, maxonsiteissueqty, holdallowed, returnbranch, renew_lost_allowed, renew_lost_found) + VALUES (?, ?, ?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?"); + SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?, renew_lost_allowed = ?, renew_lost_found = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch); + $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch, $renew_lost_allowed, $renew_lost_found ); } else { - $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch); + $sth_insert->execute( $maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch, $renew_lost_allowed, $renew_lost_found ); } } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total @@ -575,12 +578,15 @@ if ($branch eq "*") { my $defaults = $sth_defaults->fetchrow_hashref; if ($defaults) { - $template->param(default_holdallowed_none => 1) if($defaults->{holdallowed} == 0); - $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1); - $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2); - $template->param(default_maxissueqty => $defaults->{maxissueqty}); - $template->param(default_maxonsiteissueqty => $defaults->{maxonsiteissueqty}); - $template->param(default_returnbranch => $defaults->{returnbranch}); + $template->param( default_holdallowed_none => 1 ) if ( $defaults->{holdallowed} == 0 ); + $template->param( default_holdallowed_same => 1 ) if ( $defaults->{holdallowed} == 1 ); + $template->param( default_holdallowed_any => 1 ) if ( $defaults->{holdallowed} == 2 ); + + $template->param( default_maxissueqty => $defaults->{maxissueqty} ); + $template->param( default_maxonsiteissueqty => $defaults->{maxonsiteissueqty} ); + $template->param( default_returnbranch => $defaults->{returnbranch} ); + $template->param( default_renew_lost_allowed => $defaults->{renew_lost_allowed} ); + $template->param( default_renew_lost_found => $defaults->{renew_lost_found} ); } $template->param(default_rules => ($defaults ? 1 : 0)); diff --git a/installer/data/mysql/atomicupdate/bug_9805.sql b/installer/data/mysql/atomicupdate/bug_9805.sql new file mode 100644 index 0000000..f1b7f8a --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_9805.sql @@ -0,0 +1,7 @@ +ALTER TABLE default_circ_rules + ADD renew_lost_allowed BOOLEAN NOT NULL DEFAULT '1', + ADD renew_lost_found BOOLEAN NOT NULL DEFAULT '0'; + +ALTER TABLE default_branch_circ_rules + ADD renew_lost_allowed BOOLEAN NOT NULL DEFAULT '1', + ADD renew_lost_found BOOLEAN NOT NULL DEFAULT '0'; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 63fefe7..90c72a6 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -684,6 +684,8 @@ CREATE TABLE `default_branch_circ_rules` ( `maxonsiteissueqty` int(4) default NULL, `holdallowed` tinyint(1) default NULL, `returnbranch` varchar(15) default NULL, + renew_lost_allowed BOOLEAN NOT NULL DEFAULT '1', + renew_lost_found BOOLEAN NOT NULL DEFAULT '0', PRIMARY KEY (`branchcode`), CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE @@ -713,6 +715,8 @@ CREATE TABLE `default_circ_rules` ( `maxonsiteissueqty` int(4) default NULL, `holdallowed` int(1) default NULL, `returnbranch` varchar(15) default NULL, + renew_lost_allowed BOOLEAN NOT NULL DEFAULT '1', + renew_lost_found BOOLEAN NOT NULL DEFAULT '0', PRIMARY KEY (`singleton`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index c3cf05d..3edb8b2 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -12022,6 +12022,7 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } + # DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc index 62af2a3..4ae477a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc @@ -18,6 +18,7 @@ var NOT_RENEWABLE_TOO_SOON = _("No renewal before %s"); var NOT_RENEWABLE_AUTO_TOO_SOON = _("Scheduled for automatic renewal"); var NOT_RENEWABLE_AUTO_RENEW = _("Scheduled for automatic renewal"); + var ITEM_LOST = _("Item lost"); var RENEWALS_REMAINING = _("%s of %s renewals remaining"); var HOLD_IS_SUSPENDED = _("Hold is suspended"); var UNTIL = _("until %s"); 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 c7e27ad..a596bf9 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 @@ -368,7 +368,7 @@ for="tobranch">Clone these rules to: -

Default checkout, hold and return policy[% IF ( humanbranch ) %] for [% humanbranch %][% END %]

+

Default checkout, hold, renewal and return policy[% IF ( humanbranch ) %] for [% humanbranch %][% END %]

You can set a default maximum number of checkouts, hold policy and return policy that will be used if none is defined below for a particular item type or category.

@@ -380,6 +380,8 @@ for="tobranch">Clone these rules to: Clone these rules to: + [% IF ( default_renew_lost_allowed == '1' ) %] + + + [% IF ( default_renew_lost_allowed == '0' ) %] + + + + + + Unset diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt index 7c481f4..f806d32 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt @@ -104,6 +104,10 @@

[% borrower.firstname %] [% borrower.surname %] ( [% borrower.cardnumber %] ) is currently restricted.

+ [% ELSIF error == "item_lost" %] + +

This item is lost.

+ [% ELSE %] [% error %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index d45222e..94909b7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -248,6 +248,8 @@ ([% ISSUE.renewsleft %] of [% ISSUE.renewsallowed %] renewals remaining) [% ELSIF ( ISSUE.on_reserve ) %] (On hold) + [% ELSIF ( ISSUE.item_lost ) %] + (Item is lost) [% END %] [% END %] -- 2.1.4