View | Details | Raw Unified | Return to bug 19935
Collapse All | Expand All

(-)a/C4/Members.pm (-40 / +56 lines)
Lines 944-999 sub IssueSlip { Link Here
944
    my $patron = Koha::Patrons->find( $borrowernumber );
944
    my $patron = Koha::Patrons->find( $borrowernumber );
945
    return unless $patron;
945
    return unless $patron;
946
946
947
    my @issues = @{ GetPendingIssues($borrowernumber) };
947
    my $pending_checkouts = $patron->pending_checkouts; # Should be $patron->checkouts->pending?
948
949
    for my $issue (@issues) {
950
        $issue->{date_due} = $issue->{date_due_sql};
951
        if ($quickslip) {
952
            my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
953
            if ( substr( $issue->{issuedate}, 0, 10 ) eq $today
954
                or substr( $issue->{lastreneweddate}, 0, 10 ) eq $today ) {
955
                  $issue->{now} = 1;
956
            };
957
        }
958
    }
959
960
    # Sort on timestamp then on issuedate then on issue_id
961
    # useful for tests and could be if modified in a batch
962
    @issues = sort {
963
            $b->{timestamp} <=> $a->{timestamp}
964
         or $b->{issuedate} <=> $a->{issuedate}
965
         or $b->{issue_id}  <=> $a->{issue_id}
966
    } @issues;
967
948
968
    my ($letter_code, %repeat, %loops);
949
    my ($letter_code, %repeat, %loops);
969
    if ( $quickslip ) {
950
    if ( $quickslip ) {
951
        my $today_start = dt_from_string->set( hour => 0, minute => 0, second => 0 );
952
        my $today_end = dt_from_string->set( hour => 23, minute => 59, second => 0 );
953
        $today_start = Koha::Database->new->schema->storage->datetime_parser->format_datetime( $today_start );
954
        $today_end = Koha::Database->new->schema->storage->datetime_parser->format_datetime( $today_end );
970
        $letter_code = 'ISSUEQSLIP';
955
        $letter_code = 'ISSUEQSLIP';
971
        my @checkouts = map {
956
972
                'biblio'       => $_,
957
        # issue date or lastreneweddate is today
973
                'items'        => $_,
958
        my $todays_checkouts = $pending_checkouts->search(
974
                'biblioitems'  => $_,
959
            {
975
                'issues'       => $_,
960
                -or => {
976
            }, grep { $_->{'now'} } @issues;
961
                    issuedate => {
962
                        '>=' => $today_start,
963
                        '<=' => $today_end,
964
                    },
965
                    lastreneweddate =>
966
                      { '>=' => $today_start, '<=' => $today_end, }
967
                }
968
            }
969
        );
970
        my @checkouts;
971
        while ( my $c = $todays_checkouts->next ) {
972
            my $all = $c->unblessed_all_relateds;
973
            push @checkouts, {
974
                biblio      => $all,
975
                items       => $all,
976
                biblioitems => $all,
977
                issues      => $all,
978
            };
979
        }
980
977
        %repeat =  (
981
        %repeat =  (
978
            checkedout => \@checkouts, # History syntax
982
            checkedout => \@checkouts, # Historical syntax
979
        );
983
        );
980
        %loops = (
984
        %loops = (
981
            issues => [ map { $_->{issues}{itemnumber} } @checkouts ], # TT syntax
985
            issues => [ map { $_->{issues}{itemnumber} } @checkouts ], # TT syntax
982
        );
986
        );
983
    }
987
    }
984
    else {
988
    else {
985
        my @checkouts = map {
989
        my $today = Koha::Database->new->schema->storage->datetime_parser->format_datetime( dt_from_string );
986
            'biblio'        => $_,
990
        # Checkouts due in the future
987
              'items'       => $_,
991
        my $checkouts = $pending_checkouts->search({ date_due => { '>' => $today } });
988
              'biblioitems' => $_,
992
        my @checkouts; my @overdues;
989
              'issues'      => $_,
993
        while ( my $c = $checkouts->next ) {
990
        }, grep { !$_->{'overdue'} } @issues;
994
            my $all = $c->unblessed_all_relateds;
991
        my @overdues = map {
995
            push @checkouts, {
992
            'biblio'        => $_,
996
                biblio      => $all,
993
              'items'       => $_,
997
                items       => $all,
994
              'biblioitems' => $_,
998
                biblioitems => $all,
995
              'issues'      => $_,
999
                issues      => $all,
996
        }, grep { $_->{'overdue'} } @issues;
1000
            };
1001
        }
1002
1003
        # Checkouts due in the past are overdues
1004
        my $overdues = $pending_checkouts->search({ date_due => { '<=' => $today } });
1005
        while ( my $o = $overdues->next ) {
1006
            my $all = $o->unblessed_all_relateds;
1007
            push @overdues, {
1008
                biblio      => $all,
1009
                items       => $all,
1010
                biblioitems => $all,
1011
                issues      => $all,
1012
            };
1013
        }
997
        my $news = GetNewsToDisplay( "slip", $branch );
1014
        my $news = GetNewsToDisplay( "slip", $branch );
998
        my @news = map {
1015
        my @news = map {
999
            $_->{'timestamp'} = $_->{'newdate'};
1016
            $_->{'timestamp'} = $_->{'newdate'};
1000
- 

Return to bug 19935