From e96e1126b6a17325002f0d2638dffe4e433bbc5c Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 20 Nov 2014 12:39:21 -0500 Subject: [PATCH] Bug 13315 - Add feedback for last item checked out to circulation.pl 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 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 Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 29 +++++++++---------- C4/SIP/ILS/Transaction/Checkout.pm | 5 +++- C4/SIP/ILS/Transaction/Renew.pm | 4 ++- circ/circulation.pl | 3 +- .../prog/en/modules/circ/circulation.tt | 4 +++ t/db_dependent/Circulation.t | 18 +++++++----- t/db_dependent/rollingloans.t | 5 ++-- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index a8c8c08778..41b6deafad 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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 diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index 5c95b12f9e..6a77aa3023 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -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 { diff --git a/C4/SIP/ILS/Transaction/Renew.pm b/C4/SIP/ILS/Transaction/Renew.pm index d3ef01477c..e0f905b023 100644 --- a/C4/SIP/ILS/Transaction/Renew.pm +++ b/C4/SIP/ILS/Transaction/Renew.pm @@ -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; } diff --git a/circ/circulation.pl b/circ/circulation.pl index d093c00f72..570254397e 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -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; } 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 69ce8dfa90..e845ee05b8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -795,6 +795,10 @@ No patron matched [% message %] +[% IF ( issue ) %] +
[% issue.item.biblio.title %] ([% issue.item.barcode %]) due on [% issue.date_due | $KohaDates %]
+[% END %] +
diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 7396e862c7..e48ab70012 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -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" ); diff --git a/t/db_dependent/rollingloans.t b/t/db_dependent/rollingloans.t index 55fa58b4d2..2b6ca503a2 100644 --- a/t/db_dependent/rollingloans.t +++ b/t/db_dependent/rollingloans.t @@ -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 { -- 2.20.1