From 52af054b6091ee3256f3d87f58ab8e2d29134c32 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Jan 2018 15:49:18 -0300 Subject: [PATCH] Bug 19935: Replace GetPendingIssues - IssueSlip Luckily we have a good test coverage here! Test plan: Print issue slips before and after these patches (with overdues, etc.) They should be the same. Signed-off-by: Benjamin Rokseth Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Members.pm | 95 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 5438184b9c..0862f51754 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -924,56 +924,73 @@ sub IssueSlip { my $patron = Koha::Patrons->find( $borrowernumber ); return unless $patron; - my @issues = @{ GetPendingIssues($borrowernumber) }; - - for my $issue (@issues) { - $issue->{date_due} = $issue->{date_due_sql}; - if ($quickslip) { - my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); - if ( substr( $issue->{issuedate}, 0, 10 ) eq $today - or substr( $issue->{lastreneweddate}, 0, 10 ) eq $today ) { - $issue->{now} = 1; - }; - } - } - - # Sort on timestamp then on issuedate then on issue_id - # useful for tests and could be if modified in a batch - @issues = sort { - $b->{timestamp} <=> $a->{timestamp} - or $b->{issuedate} <=> $a->{issuedate} - or $b->{issue_id} <=> $a->{issue_id} - } @issues; + my $pending_checkouts = $patron->pending_checkouts; # Should be $patron->checkouts->pending? my ($letter_code, %repeat, %loops); if ( $quickslip ) { + my $today_start = dt_from_string->set( hour => 0, minute => 0, second => 0 ); + my $today_end = dt_from_string->set( hour => 23, minute => 59, second => 0 ); + $today_start = Koha::Database->new->schema->storage->datetime_parser->format_datetime( $today_start ); + $today_end = Koha::Database->new->schema->storage->datetime_parser->format_datetime( $today_end ); $letter_code = 'ISSUEQSLIP'; - my @checkouts = map { - 'biblio' => $_, - 'items' => $_, - 'biblioitems' => $_, - 'issues' => $_, - }, grep { $_->{'now'} } @issues; + + # issue date or lastreneweddate is today + my $todays_checkouts = $pending_checkouts->search( + { + -or => { + issuedate => { + '>=' => $today_start, + '<=' => $today_end, + }, + lastreneweddate => + { '>=' => $today_start, '<=' => $today_end, } + } + } + ); + my @checkouts; + while ( my $c = $todays_checkouts->next ) { + my $all = $c->unblessed_all_relateds; + push @checkouts, { + biblio => $all, + items => $all, + biblioitems => $all, + issues => $all, + }; + } + %repeat = ( - checkedout => \@checkouts, # History syntax + checkedout => \@checkouts, # Historical syntax ); %loops = ( issues => [ map { $_->{issues}{itemnumber} } @checkouts ], # TT syntax ); } else { - my @checkouts = map { - 'biblio' => $_, - 'items' => $_, - 'biblioitems' => $_, - 'issues' => $_, - }, grep { !$_->{'overdue'} } @issues; - my @overdues = map { - 'biblio' => $_, - 'items' => $_, - 'biblioitems' => $_, - 'issues' => $_, - }, grep { $_->{'overdue'} } @issues; + my $today = Koha::Database->new->schema->storage->datetime_parser->format_datetime( dt_from_string ); + # Checkouts due in the future + my $checkouts = $pending_checkouts->search({ date_due => { '>' => $today } }); + my @checkouts; my @overdues; + while ( my $c = $checkouts->next ) { + my $all = $c->unblessed_all_relateds; + push @checkouts, { + biblio => $all, + items => $all, + biblioitems => $all, + issues => $all, + }; + } + + # Checkouts due in the past are overdues + my $overdues = $pending_checkouts->search({ date_due => { '<=' => $today } }); + while ( my $o = $overdues->next ) { + my $all = $o->unblessed_all_relateds; + push @overdues, { + biblio => $all, + items => $all, + biblioitems => $all, + issues => $all, + }; + } my $news = GetNewsToDisplay( "slip", $branch ); my @news = map { $_->{'timestamp'} = $_->{'newdate'}; -- 2.39.5