From 611352bb86e849af7529ccc38c69f526f4f12a38 Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Wed, 30 Aug 2017 23:26:38 +0000
Subject: [PATCH] Bug 16463: Replace discharge link with error message if user
has checked out items
To test:
1) Ensure the useDischarge syspref is enabled
2) Check out an item to a borrower
3) Log in to the OPAC as this borrower
4) Click the 'ask for a discharge' link in the nav
5) Click the 'Ask for a discharge' link
6) Notice you cannot be discharged because you have checkouts
7) Apply the patch, click the 'ask for a discharge' link in the nav
8) Notice the link has been replaced with an appropriate error message
9) Attempt to force the discharge URL:
/cgi-bin/koha/opac-discharge?op=request
10) Notice the message and you cannot be discharged.
11) Confirm that when you check in your item, the discharge link shows
again and works as expected.
Sponsored-by: Catalyst IT
Signed-off-by: Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com>
---
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt | 7 ++++++-
opac/opac-discharge.pl | 5 +++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt
index 3053bf7..5cc5c4c 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt
@@ -44,7 +44,12 @@
<h2>What is a discharge?</h2>
<p>This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.</p>
<p><strong>Warning</strong>: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.</p>
- <a href="/cgi-bin/koha/opac-discharge.pl?op=request">Ask for a discharge</a>
+ [% IF has_checkouts %]
+ <div class="dialog alert">You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</div>
+ [% ELSE %]
+ <a href="/cgi-bin/koha/opac-discharge.pl?op=request">Ask for a discharge</a>
+ [% END %]
+
[% END %]
</div> <!-- / #discharge -->
</div> <!-- / .span10 -->
diff --git a/opac/opac-discharge.pl b/opac/opac-discharge.pl
index 4ce1322..c5f4745 100755
--- a/opac/opac-discharge.pl
+++ b/opac/opac-discharge.pl
@@ -47,6 +47,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
debug => 1,
});
+my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $loggedinuser });
+if ($can_be_discharged == 0) {
+ $template->param( has_checkouts => 1 );
+}
+
if ( $op eq 'request' ) {
my $success = Koha::Patron::Discharge::request({
borrowernumber => $loggedinuser,
--
2.1.4