Bugzilla – Attachment 20044 Details for
Bug 10493
Add renewal script
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10493 - Add renewal script
Bug-10493---Add-renewal-script.patch (text/plain), 17.01 KB, created by
Kyle M Hall (khall)
on 2013-08-01 16:52:23 UTC
(
hide
)
Description:
Bug 10493 - Add renewal script
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-08-01 16:52:23 UTC
Size:
17.01 KB
patch
obsolete
>From 94aa3da134a3852098d3120fcfa632f747d84cbb Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 19 Jun 2013 05:28:01 -0400 >Subject: [PATCH] Bug 10493 - Add renewal script > >Koha needs a renewal tool that functions similar to the returns where a >librarian can continuously scan items for renewal. This script should >block renewals that are impossible, and allow the same renewal overrides >as circulation.pl > >Test plan: > 1) Apply the patches for bug 8798 > 2) Apply this patch > 3) Browse to /cgi-bin/koha/circ/renew.pl > 4) Enter an invalid barcode, you should get an error message > 5) Enter a valid, but not checked out barcode, you should get an error > message. > 6) Enter a valid barcode that is checkout out and should be renewable, > you should get a success message. > 7) Enable AllowRenewalLimitOverride > 8) Enter a barcode for an item that has been renewed too many times > 9) You should get a warning which you can override. >10) Disable AllowRenewalLimitOverride >11) Repeat steap 8 >12) You should get a blocking error message >11) Enter a barcode for an item with unfilled holds on it, > you should get an overridable warning >--- > C4/Circulation.pm | 44 ++++--- > C4/Items.pm | 4 + > C4/Reserves.pm | 7 +- > Koha/Schema/Result/Issue.pm | 7 +- > Koha/Schema/Result/Item.pm | 6 +- > circ/renew.pl | 102 +++++++++++++++ > .../prog/en/modules/circ/circulation-home.tt | 1 + > .../intranet-tmpl/prog/en/modules/circ/renew.tt | 131 ++++++++++++++++++++ > 8 files changed, 278 insertions(+), 24 deletions(-) > create mode 100755 circ/renew.pl > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index ca66931..b5c38a0 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2462,34 +2462,36 @@ already renewed the loan. $error will contain the reason the renewal can not pro > =cut > > sub CanBookBeRenewed { >- >- # check renewal status > my ( $borrowernumber, $itemnumber, $override_limit ) = @_; >+ > my $dbh = C4::Context->dbh; > my $renews = 1; > my $renewokay = 0; > my $error; > >- my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return; >- my $item = GetItem($itemnumber) or return; >- my $itemissue = GetItemIssue($itemnumber) or return; >+ my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); >+ my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); >+ >+ $borrowernumber ||= $itemissue->{borrowernumber}; >+ my $borrower = C4::Members::GetMemberDetails($borrowernumber) >+ or return; > > my $branchcode = _GetCircControlBranch($item, $borrower); > > my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); > >- if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { >- $renewokay = 1; >- } else { >- $error = "too_many"; >- } >- > my $resstatus = C4::Reserves::GetReserveStatus($itemnumber); > if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) { > $renewokay = 0; > $error = "on_reserve"; > } > >+ if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { >+ $renewokay = 1; >+ } else { >+ $error = "too_many"; >+ } >+ > return ( $renewokay, $error ); > } > >@@ -2518,28 +2520,32 @@ from the book's item type. > =cut > > sub AddRenewal { >- my $borrowernumber = shift or return; >+ my $borrowernumber = shift; > my $itemnumber = shift or return; > my $branch = shift; > my $datedue = shift; > my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd(); >+ > my $item = GetItem($itemnumber) or return; > my $biblio = GetBiblioFromItemNumber($itemnumber) or return; > > my $dbh = C4::Context->dbh; >+ > # Find the issues record for this book > my $sth = >- $dbh->prepare("SELECT * FROM issues >- WHERE borrowernumber=? >- AND itemnumber=?" >- ); >- $sth->execute( $borrowernumber, $itemnumber ); >+ $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); >+ $sth->execute( $itemnumber ); > my $issuedata = $sth->fetchrow_hashref; >- $sth->finish; >- if(defined $datedue && ref $datedue ne 'DateTime' ) { >+ >+ return unless ( $issuedata ); >+ >+ $borrowernumber ||= $issuedata->{borrowernumber}; >+ >+ if ( defined $datedue && ref $datedue ne 'DateTime' ) { > carp 'Invalid date passed to AddRenewal.'; > return; > } >+ > # If the due date wasn't specified, calculate it by adding the > # book's loan length to today's date or the current due date > # based on the value of the RenewalPeriodBase syspref. >diff --git a/C4/Items.pm b/C4/Items.pm >index 212a9d3..580dacc 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -144,6 +144,7 @@ sub GetItem { > my ($itemnumber,$barcode, $serial) = @_; > my $dbh = C4::Context->dbh; > my $data; >+ > if ($itemnumber) { > my $sth = $dbh->prepare(" > SELECT * FROM items >@@ -158,6 +159,9 @@ sub GetItem { > $sth->execute($barcode); > $data = $sth->fetchrow_hashref; > } >+ >+ return unless ( $data ); >+ > if ( $serial) { > my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?"); > $ssth->execute($data->{'itemnumber'}) ; >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 1f89127..a3d0465 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -788,10 +788,11 @@ sub GetReserveStatus { > if(defined $found) { > return 'Waiting' if $found eq 'W' and $priority == 0; > return 'Finished' if $found eq 'F'; >- return 'Reserved' if $priority > 0; > } >- return ''; >- #empty string here will remove need for checking undef, or less log lines >+ >+ return 'Reserved' if $priority > 0; >+ >+ return ''; # empty string here will remove need for checking undef, or less log lines > } > > =head2 CheckReserves >diff --git a/Koha/Schema/Result/Issue.pm b/Koha/Schema/Result/Issue.pm >index d10a338..838f672 100644 >--- a/Koha/Schema/Result/Issue.pm >+++ b/Koha/Schema/Result/Issue.pm >@@ -147,6 +147,11 @@ __PACKAGE__->belongs_to( > # Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-06-18 13:13:57 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uZUDWDGWOkC3oCOyMaG1sg > >+__PACKAGE__->belongs_to( >+ "borrower", >+ "Koha::Schema::Result::Borrower", >+ { borrowernumber => "borrowernumber" }, >+ { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" }, >+); > >-# You can replace this text with custom content, and it will be preserved on regeneration > 1; >diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm >index 69edbe6..d1ec368 100644 >--- a/Koha/Schema/Result/Item.pm >+++ b/Koha/Schema/Result/Item.pm >@@ -543,6 +543,10 @@ __PACKAGE__->might_have( > # Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-06-18 13:13:57 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f3HngbnArIKegakzHgcFBg > >+__PACKAGE__->belongs_to( >+ "biblio", >+ "Koha::Schema::Result::Biblio", >+ { "foreign.biblionumber" => "self.biblionumber" } >+); > >-# You can replace this text with custom content, and it will be preserved on regeneration > 1; >diff --git a/circ/renew.pl b/circ/renew.pl >new file mode 100755 >index 0000000..6634c0c >--- /dev/null >+++ b/circ/renew.pl >@@ -0,0 +1,102 @@ >+#!/usr/bin/perl >+ >+# Copyright 2013 ByWater Solutions >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use CGI; >+use C4::Context; >+use C4::Auth qw/:DEFAULT get_session/; >+use C4::Output; >+use C4::Circulation; >+use Koha::DateUtils; >+use Koha::Database; >+ >+my $cgi = new CGI; >+ >+my ( $template, $librarian, $cookie ) = get_template_and_user( >+ { >+ template_name => "circ/renew.tmpl", >+ query => $cgi, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { circulate => "circulate_remaining_permissions" }, >+ } >+); >+ >+my $schema = Koha::Database->new()->schema(); >+ >+my $barcode = $cgi->param('barcode'); >+my $override_limit = $cgi->param('override_limit'); >+my $override_holds = $cgi->param('override_holds'); >+ >+my ( $item, $issue, $borrower, $error ); >+ >+if ($barcode) { >+ $item = $schema->resultset("Item")->single( { barcode => $barcode } ); >+ >+ if ($item) { >+ >+ $issue = $item->issues()->single(); >+ >+ if ($issue) { >+ >+ $borrower = $issue->borrower(); >+ >+ if ( $borrower->debarred() lt dt_from_string()->ymd() ) { >+ my $can_renew; >+ ( $can_renew, $error ) = >+ CanBookBeRenewed( $borrower->borrowernumber(), >+ $item->itemnumber(), $override_limit ); >+ >+ if ( $error eq 'on_reserve' ) { >+ if ($override_holds) { >+ $can_renew = 1; >+ $error = undef; >+ } >+ else { >+ $can_renew = 0; >+ } >+ } >+ >+ if ($can_renew) { >+ my $date_due = AddRenewal( undef, $item->itemnumber() ); >+ $template->param( date_due => $date_due ); >+ } >+ } >+ else { >+ $error = "patron_restricted"; >+ } >+ } >+ else { >+ $error = "no_checkout"; >+ } >+ } >+ else { >+ $error = "no_item"; >+ } >+ >+ $template->param( >+ item => $item, >+ issue => $issue, >+ borrower => $borrower, >+ error => $error >+ ); >+} >+ >+output_html_with_http_headers( $cgi, $cookie, $template->output ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt >index af533f4..f1d92a3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt >@@ -19,6 +19,7 @@ > <ul> > <li><a href="/cgi-bin/koha/circ/circulation.pl">Check out</a></li> > <li><a href="/cgi-bin/koha/circ/returns.pl">Check in</a></li> >+ <li><a href="/cgi-bin/koha/circ/renew.pl">Renew</a></li> > [% IF ( display_transfer ) %] > <li><a href="/cgi-bin/koha/circ/branchtransfers.pl">Transfer</a></li> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt >new file mode 100644 >index 0000000..eba8892 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt >@@ -0,0 +1,131 @@ >+[% USE Koha %] >+[% USE KohaDates %] >+[% USE KohaBranchName %] >+ >+[% INCLUDE 'doc-head-open.inc' %] >+ >+<title>Koha › Circulation › Renew [% title |html %]</title> >+ >+[% INCLUDE 'doc-head-close.inc' %] >+ >+<script type="text/javascript"> >+//<![CDATA[ >+ >+$(document).ready(function () { >+ $("#barcode").focus(); >+}); >+ >+//]]> >+</script> >+ >+</head> >+ >+<body> >+ >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'circ-search.inc' %] >+ >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a> › Check in</div> >+ >+<div id="doc" class="yui-t7"> >+ <div id="bd"> >+ <div id="yui-main"> >+ >+ <div class="yui-g"> >+ [% IF error %] >+ <div class="dialog alert"> >+ <h3>Cannot renew:</h3> >+ <p> >+ [% IF error == "no_item" %] >+ >+ No item matches this barcode >+ >+ [% ELSIF error == "no_checkout" %] >+ >+ <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title %] [% item.biblioitem.subtitle %]</a> >+ ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&biblionumber=[% item.biblionumber %]&bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> ) >+ is not checked out to a patron. >+ >+ [% ELSIF error == "too_many" %] >+ >+ [% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) >+ has been renewed the maximum number of times by >+ [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> ) >+ >+ [% IF Koha.Preference('AllowRenewalLimitOverride') %] >+ <form method="post" action="/cgi-bin/koha/circ/renew.pl" autocomplete="off" > >+ <input type="hidden" name="barcode" value="[% item.barcode %]"/> >+ <input type="hidden" name="override_limit" value="1" /> >+ <input type="submit" class="submit" value="Override limit and renew" /> >+ </form> >+ [% END %] >+ >+ [% ELSIF error == "on_reserve" %] >+ >+ This item is on hold for other patrons. >+ >+ <form method="post" action="/cgi-bin/koha/circ/renew.pl" autocomplete="off" > >+ <input type="hidden" name="barcode" value="[% item.barcode %]"/> >+ <input type="hidden" name="override_limit" value="1" /> >+ <input type="hidden" name="override_holds" value="1" /> >+ <input type="submit" class="submit" value="Override and renew" /> >+ </form> >+ >+ [% ELSIF error == "patron_restricted" %] >+ >+ [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> ) >+ is currently restricted. >+ >+ [% ELSE %] >+ >+ [% error %] >+ >+ [% END %] >+ >+ <a href="/cgi-bin/koha/circ/renew.pl">Ignore & continue</a> >+ </p> >+ </div> >+ [% END %] >+ >+ [% IF date_due %] >+ <div class="dialog message"> >+ <p> >+ <h3>Item renewed:</h3> >+ >+ <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title %] [% item.biblioitem.subtitle %]</a> >+ ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&biblionumber=[% item.biblionumber %]&bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> ) >+ renewed for >+ [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> ) >+ now due on [% date_due | $KohaDates %] >+ </p> >+ </div> >+ [% END %] >+ </div> >+ >+ <div class="yui-g"> >+ >+ [% UNLESS error %] >+ <form method="post" action="/cgi-bin/koha/circ/renew.pl" autocomplete="off" > >+ >+ <div class="yui-u first"> >+ <fieldset> >+ <legend>Renew</legend> >+ >+ <label for="barcode">Enter item barcode: </label> >+ >+ <input name="barcode" id="barcode" size="14" class="focus"/> >+ >+ <input type="submit" class="submit" value="Submit" /> >+ </fieldset> >+ </div> >+ >+ </form> >+ [% END %] >+ >+ </div> >+ >+ </div> >+ >+<div> >+ >+[% INCLUDE 'intranet-bottom.inc' %] >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10493
:
19155
|
20044
|
20049
|
20050
|
20143
|
22076
|
22077
|
22139
|
22180
|
22192
|
22194
|
22196
|
22197
|
22199
|
22200
|
22202
|
22203
|
22241
|
22242
|
22243