Bug 13315 - Add feedback for last item checked out to circulation.pl
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 20 Nov 2014 17:39:21 +0000 (12:39 -0500)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Mon, 13 Apr 2015 17:52:26 +0000 (14:52 -0300)
It seems that many librarians find it disconcerting to have no feedback
with the new checkouts table. It seems that many of them wait for it to
fully load, check to verify the item was checked out, and only then
check out the next item.

To help alleviate this issue, we can have the checkouts page give
feedback about the item that was just checked out.

Test Plan:
1) Apply this patch
2) Check an item out
3) Note the message "$title ($barcode) due on $date_due"

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
This works well and fixes a very problematic issue with the new AJAX
circ. I will be submitting a follow-up which I think is an improvement
to the display.

Signed-off-by: Jason Burds <jburds@dubuque.lib.ia.us>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Circulation.pm
C4/SIP/ILS/Transaction/Checkout.pm
C4/SIP/ILS/Transaction/Renew.pm
circ/circulation.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
t/db_dependent/Circulation.t
t/db_dependent/rollingloans.t

index a8c8c08..41b6dea 100644 (file)
@@ -1194,6 +1194,8 @@ sub AddIssue {
     my $dbh = C4::Context->dbh;
     my $barcodecheck=CheckValidBarcode($barcode);
 
+    my $issue;
+
     if ($datedue && ref $datedue ne 'DateTime') {
         $datedue = dt_from_string($datedue);
     }
@@ -1264,12 +1266,6 @@ sub AddIssue {
         }
 
         # Record in the database the fact that the book was issued.
-        my $sth =
-          $dbh->prepare(
-                "INSERT INTO issues
-                    (borrowernumber, itemnumber,issuedate, date_due, branchcode, onsite_checkout, auto_renew)
-                VALUES (?,?,?,?,?,?,?)"
-          );
         unless ($datedue) {
             my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
             $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
@@ -1277,15 +1273,18 @@ sub AddIssue {
         }
         $datedue->truncate( to => 'minute');
 
-        $sth->execute(
-            $borrower->{'borrowernumber'},      # borrowernumber
-            $item->{'itemnumber'},              # itemnumber
-            $issuedate->strftime('%Y-%m-%d %H:%M:%S'), # issuedate
-            $datedue->strftime('%Y-%m-%d %H:%M:%S'),   # date_due
-            C4::Context->userenv->{'branch'},   # branchcode
-            $onsite_checkout,
-            $auto_renew ? 1 : 0                 # automatic renewal
+        $issue = Koha::Database->new()->schema()->resultset('Issue')->create(
+            {
+                borrowernumber  => $borrower->{'borrowernumber'},
+                itemnumber      => $item->{'itemnumber'},
+                issuedate       => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
+                date_due        => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
+                branchcode      => C4::Context->userenv->{'branch'},
+                onsite_checkout => $onsite_checkout,
+                auto_renew      => $auto_renew ? 1 : 0
+            }
         );
+
         if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart.
           CartToShelf( $item->{'itemnumber'} );
         }
@@ -1355,7 +1354,7 @@ sub AddIssue {
     logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $biblio->{'itemnumber'})
         if C4::Context->preference("IssueLog");
   }
-  return ($datedue);   # not necessarily the same as when it came in!
+  return $issue;
 }
 
 =head2 GetLoanLength
index 5c95b12..6a77aa3 100644 (file)
@@ -19,6 +19,8 @@ use C4::Circulation;
 use C4::Members;
 use C4::Reserves qw(ModReserveFill);
 use C4::Debug;
+use Koha::DateUtils;
+
 use parent qw(C4::SIP::ILS::Transaction);
 
 our $debug;
@@ -137,7 +139,8 @@ sub do_checkout {
        $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n"
                # . "w/ \$borrower: " . Dumper($borrower)
                . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
-       my $due_dt  = AddIssue($borrower, $barcode, $overridden_duedate, 0);
+    my $issue = AddIssue( $borrower, $barcode, $overridden_duedate, 0 );
+    my $due_dt = dt_from_string( $issue->date_due() );
     if ($due_dt) {
         $self->{due} = $due_dt->clone();
     } else {
index d3ef014..e0f905b 100644 (file)
@@ -9,6 +9,7 @@ use strict;
 
 use C4::Circulation;
 use C4::Members;
+use Koha::DateUtils;
 
 use parent qw(C4::SIP::ILS::Transaction);
 
@@ -45,7 +46,8 @@ sub do_renew_for  {
     }
     if ($renewokay){
         $self->{due} = undef;
-        my $due_date = AddIssue( $borrower, $self->{item}->id, undef, 0 );
+        my $issue = AddIssue( $borrower, $self->{item}->id, undef, 0 );
+        my $due_date = dt_from_string( $issue->date_due() );
         if ($due_date) {
             $self->{due} = $due_date;
         }
index d093c00..5702543 100755 (executable)
@@ -372,7 +372,8 @@ if ($barcode) {
             }
         }
         unless($confirm_required) {
-            AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
+            my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
+            $template->param( issue => $issue );
             $session->clear('auto_renew');
             $inprocess = 1;
         }
index 69ce8df..e845ee0 100644 (file)
@@ -795,6 +795,10 @@ No patron matched <span class="ex">[% message %]</span>
 
 </div>
 </div>
+[% IF ( issue ) %]
+    <div class="dialog message">[% issue.item.biblio.title %] ([% issue.item.barcode %]) due on [% issue.date_due | $KohaDates %]</div>
+[% END %]
+
 
 <div class="yui-g"><div id="patronlists" class="toptabs">
 
index 7396e86..e48ab70 100755 (executable)
@@ -271,11 +271,13 @@ C4::Context->dbh->do("DELETE FROM accountlines");
     my $checkitem      = undef;
     my $found          = undef;
 
-    my $datedue = AddIssue( $renewing_borrower, $barcode);
-    is (defined $datedue, 1, "Item 1 checked out, due date: $datedue");
+    my $issue = AddIssue( $renewing_borrower, $barcode);
+    my $datedue = dt_from_string( $issue->date_due() );
+    is (defined $issue->date_due(), 1, "Item 1 checked out, due date: " . $issue->date_due() );
 
-    my $datedue2 = AddIssue( $renewing_borrower, $barcode2);
-    is (defined $datedue2, 1, "Item 2 checked out, due date: $datedue2");
+    my $issue2 = AddIssue( $renewing_borrower, $barcode2);
+    $datedue = dt_from_string( $issue->date_due() );
+    is (defined $issue2, 1, "Item 2 checked out, due date: " . $issue2->date_due());
 
     my $borrowing_borrowernumber = GetItemIssue($itemnumber)->{borrowernumber};
     is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
@@ -495,8 +497,10 @@ C4::Context->dbh->do("DELETE FROM accountlines");
     my $two_days_ahead = DateTime->today(time_zone => C4::Context->tz())->add( days => 2 );
     my $today = DateTime->today(time_zone => C4::Context->tz());
 
-    my $datedue  = AddIssue( $a_borrower, $barcode, $yesterday );
-    my $datedue2 = AddIssue( $a_borrower, $barcode2, $two_days_ahead );
+    my $issue = AddIssue( $a_borrower, $barcode, $yesterday );
+    my $datedue = dt_from_string( $issue->date_due() );
+    my $issue2 = AddIssue( $a_borrower, $barcode2, $two_days_ahead );
+    my $datedue2 = dt_from_string( $issue->date_due() );
 
     my $upcoming_dues;
 
@@ -518,7 +522,7 @@ C4::Context->dbh->do("DELETE FROM accountlines");
 
     # Bug 11218 - Due notices not generated - GetUpcomingDueIssues needs to select due today items as well
 
-    my $datedue3 = AddIssue( $a_borrower, $barcode3, $today );
+    my $issue3 = AddIssue( $a_borrower, $barcode3, $today );
 
     $upcoming_dues = C4::Circulation::GetUpcomingDueIssues( { days_in_advance => -1 } );
     is ( scalar ( @$upcoming_dues), 0, "Overdues can not be selected" );
index 55fa58b..2b6ca50 100644 (file)
@@ -6,6 +6,7 @@ use C4::Context;
 use C4::Circulation;
 use C4::Members;
 use C4::Items;
+use Koha::DateUtils;
 
 use Test::More tests => 8;
 C4::Context->_new_userenv(1234567);
@@ -42,8 +43,8 @@ sub try_issue {
     my $issuedate = '2011-05-16';
     my $borrower = GetMemberDetails(0, $cardnumber);
     my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $borrower, $item );
-       my $due_date = AddIssue($borrower, $item, undef, 0, $issuedate);
-    return $due_date;
+    my $issue = AddIssue($borrower, $item, undef, 0, $issuedate);
+    return dt_from_string( $issue->due_date() );
 }
 
 sub try_return {