@@ -, +, @@ C4/SIP/ILS/Patron.pm --patron -s " Y " -m patron_information --- C4/SIP/ILS/Patron.pm | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) --- a/C4/SIP/ILS/Patron.pm +++ a/C4/SIP/ILS/Patron.pm @@ -130,7 +130,7 @@ sub new { # FIXME: populate fine_items recall_items $ilspatron{unavail_holds} = _get_outstanding_holds($kp->{borrowernumber}); - $ilspatron{items} = $patron->pending_checkouts->unblessed; + $ilspatron{items} = _get_pending_issues($kp->{borrowernumber}); $self = \%ilspatron; $debug and warn Dumper($self); syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,$self->{id}); @@ -501,6 +501,79 @@ sub _get_outstanding_holds { return \@holds; } +sub _get_pending_issues { + my @borrowernumbers = @_; + unless (@borrowernumbers ) { # return a ref_to_array + return \@borrowernumbers; # to not cause surprise to caller + } + # Borrowers part of the query + my $bquery = ''; + for (my $i = 0; $i < @borrowernumbers; $i++) { + $bquery .= ' issues.borrowernumber = ?'; + if ($i < $#borrowernumbers ) { + $bquery .= ' OR'; + } + } + + # must avoid biblioitems.* to prevent large marc and marcxml fields from killing performance + # FIXME: namespace collision: each table has "timestamp" fields. Which one is "timestamp" ? + # FIXME: circ/ciculation.pl tries to sort by timestamp! + # FIXME: namespace collision: other collisions possible. + # FIXME: most of this data isn't really being used by callers. + my $query = + "SELECT issues.*, + items.*, + biblio.*, + biblioitems.volume, + biblioitems.number, + biblioitems.itemtype, + biblioitems.isbn, + biblioitems.issn, + biblioitems.publicationyear, + biblioitems.publishercode, + biblioitems.volumedate, + biblioitems.volumedesc, + biblioitems.lccn, + biblioitems.url, + borrowers.firstname, + borrowers.surname, + borrowers.cardnumber, + issues.timestamp AS timestamp, + issues.renewals AS renewals, + issues.borrowernumber AS borrowernumber, + items.renewals AS totalrenewals + FROM issues + LEFT JOIN items ON items.itemnumber = issues.itemnumber + LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber + LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber + LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber + WHERE + $bquery + ORDER BY issues.issuedate" + ; + + my $sth = C4::Context->dbh->prepare($query); + $sth->execute(@borrowernumbers); + my $data = $sth->fetchall_arrayref({}); + my $today = dt_from_string; + foreach (@{$data}) { + if ($_->{issuedate}) { + $_->{issuedate} = dt_from_string($_->{issuedate}, 'sql'); + } + $_->{date_due_sql} = $_->{date_due}; + # FIXME no need to have this value + $_->{date_due} or next; + $_->{date_due_sql} = $_->{date_due}; + # FIXME no need to have this value + $_->{date_due} = dt_from_string($_->{date_due}, 'sql'); + if ( DateTime->compare($_->{date_due}, $today) == -1 ) { + $_->{overdue} = 1; + } + } + return $data; +} + + =head2 build_patron_attributes_string This method builds the part of the sip message for extended patron --