@@ -, +, @@ circulation.pl --- 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(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -1193,6 +1193,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); } @@ -1263,12 +1265,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 ); @@ -1276,15 +1272,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'} ); } @@ -1354,7 +1353,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 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ a/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; @@ -124,7 +126,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 { --- a/C4/SIP/ILS/Transaction/Renew.pm +++ a/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); @@ -34,7 +35,8 @@ sub do_renew_for { my ($renewokay,$renewerror) = CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber}); 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; } --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -369,7 +369,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; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -761,6 +761,10 @@ No patron matched [% message %] +[% IF ( issue ) %] +
[% issue.item.biblio.title %] ([% issue.item.barcode %]) due on [% issue.date_due | $KohaDates %]
+[% END %] +
--- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -270,11 +270,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}"); @@ -494,8 +496,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; @@ -517,7 +521,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" ); --- a/t/db_dependent/rollingloans.t +++ a/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 { --