From da586a8ae03b37d0a2fa1e1bbc816deeb90ff295 Mon Sep 17 00:00:00 2001
From: mbeaulieu <mbeaulieu@inlibro.com>
Date: Tue, 29 Jul 2014 16:20:39 -0400
Subject: [PATCH] [PASSED QA] Bug 12448: Ask for confirmation when checking out
 an item with rental fees
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Sponsored-by: Ville de Victoriaville, QC

Confirmation box contents:

"Please confirm checkout"
"-Rental charge for this item: n"
[Yes, check out (Y)] [No, Don't Check Out (N)]

Test case A: Confirm checkout
1) Go to checkout user "X"'s checkout page.
2) Enter barcode for an item with rental fees.
3) Click the "Check out" button.
4) Confirmation box appears.
5) Click on the "Yes" button.
6) Item is added to checkout list.
7) Fees are added to the patron's account.

Test case B: Decline checkout
1) Go to checkout user "X"'s checkout page.
2) Enter barcode for an item with rental fees.
3) Click the "Check out" button.
4) Confirmation box appears.
5) Click the "No" button.
6) Checkout page goes back to its initial state.
7) Patron has no item checked out and no fees to pay.

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
With the system preference RentalFeesCheckoutConfirmation
set to "don't ask" there is no change in behaviour.
---
 C4/Circulation.pm                                         | 15 +++++++++++++--
 installer/data/mysql/sysprefs.sql                         |  1 +
 installer/data/mysql/updatedatabase.pl                    | 11 +++++++++++
 .../prog/en/modules/admin/preferences/circulation.pref    |  9 ++++++++-
 .../intranet-tmpl/prog/en/modules/circ/circulation.tt     |  6 +++++-
 5 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index dc7334a..41d1c75 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -913,12 +913,23 @@ sub CanBookBeIssued {
               if ( $borrower->{'branchcode'} ne $userenv->{branch} );
         }
     }
+    #
+    # CHECK IF THERE IS RENTAL CHARGES. RENTAL MUST BE CONFIRMED BY THE BORROWER
+    #
+    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
+
+    if ( $rentalConfirmation ){
+        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
+        if ( $rentalCharge ){
+            $rentalCharge = sprintf("%.02f", $rentalCharge);
+            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
+        }
+    }
 
     #
     # CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
     #
-    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} )
-    {
+    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
 
         # Already issued to current borrower. Ask whether the loan should
         # be renewed.
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index 7eb08a8..eb06cbb 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -331,6 +331,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
 ('RenewalSendNotice','0','',NULL,'YesNo'),
 ('RenewSerialAddsSuggestion','0',NULL,'If ON, adds a new suggestion at serial subscription renewal','YesNo'),
+('RentalFeesCheckoutConfirmation', '0', NULL , 'Allow user to confirm when checking out an item with rental fees.', 'YesNo'),
 ('RentalsInNoissuesCharge','1',NULL,'Rental charges block checkouts (added to noissuescharge).','YesNo'),
 ('RequestOnOpac','1',NULL,'If ON, globally enables patron holds on OPAC','YesNo'),
 ('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice'),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index de77bf3..52c42be 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -8613,6 +8613,17 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
+
+
+$DBversion = "XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('RentalFeesCheckoutConfirmation', '0', NULL , 'Allow user to confirm when checking out an item with rental fees.', 'YesNo')
+    |);
+    print "Upgrade to $DBversion done (Bug 11169 - Add RentalFeesCheckoutConfirmation syspref)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
index 37c368c..ac592f0 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
@@ -327,7 +327,14 @@ Circulation:
                   block: Block
                   noblock: "Don't block"
                   confirmation: Ask for confirmation
-            - when checking out to a borrower that has overdues outstanding	    
+            - when checking out to a borrower that has overdues outstanding
+        -
+            - "When checking out an item with rental fees, "
+            - pref: RentalFeesCheckoutConfirmation
+              choices:
+                  yes: ask
+                  no: "do not ask"
+            - "for confirmation."
         -
             - On checkin route the returned item to
             - pref: HomeOrHoldingBranchReturn
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
index fd65b02..524f844 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
@@ -160,7 +160,11 @@ $(document).ready(function() {
 [% END %]
 
 [% IF ( DEBT ) %]
-    <li>The patron has a debt of [% DEBT %]</li>
+    <li>The patron has a debt of [% DEBT %].</li>
+[% END %]
+
+[% IF ( RENTALCHARGE ) %]
+    <li>Rental charge for this item: [% RENTALCHARGE %]</li>
 [% END %]
 
 [% IF ( RENEW_ISSUE ) %]
-- 
1.9.1