|
Lines 551-664
sub TooMany {
Link Here
|
| 551 |
return; |
551 |
return; |
| 552 |
} |
552 |
} |
| 553 |
|
553 |
|
| 554 |
=head2 itemissues |
|
|
| 555 |
|
| 556 |
@issues = &itemissues($biblioitemnumber, $biblio); |
| 557 |
|
| 558 |
Looks up information about who has borrowed the bookZ<>(s) with the |
| 559 |
given biblioitemnumber. |
| 560 |
|
| 561 |
C<$biblio> is ignored. |
| 562 |
|
| 563 |
C<&itemissues> returns an array of references-to-hash. The keys |
| 564 |
include the fields from the C<items> table in the Koha database. |
| 565 |
Additional keys include: |
| 566 |
|
| 567 |
=over 4 |
| 568 |
|
| 569 |
=item C<date_due> |
| 570 |
|
| 571 |
If the item is currently on loan, this gives the due date. |
| 572 |
|
| 573 |
If the item is not on loan, then this is either "Available" or |
| 574 |
"Cancelled", if the item has been withdrawn. |
| 575 |
|
| 576 |
=item C<card> |
| 577 |
|
| 578 |
If the item is currently on loan, this gives the card number of the |
| 579 |
patron who currently has the item. |
| 580 |
|
| 581 |
=item C<timestamp0>, C<timestamp1>, C<timestamp2> |
| 582 |
|
| 583 |
These give the timestamp for the last three times the item was |
| 584 |
borrowed. |
| 585 |
|
| 586 |
=item C<card0>, C<card1>, C<card2> |
| 587 |
|
| 588 |
The card number of the last three patrons who borrowed this item. |
| 589 |
|
| 590 |
=item C<borrower0>, C<borrower1>, C<borrower2> |
| 591 |
|
| 592 |
The borrower number of the last three patrons who borrowed this item. |
| 593 |
|
| 594 |
=back |
| 595 |
|
| 596 |
=cut |
| 597 |
|
| 598 |
#' |
| 599 |
sub itemissues { |
| 600 |
my ( $bibitem, $biblio ) = @_; |
| 601 |
my $dbh = C4::Context->dbh; |
| 602 |
my $sth = |
| 603 |
$dbh->prepare("Select * from items where items.biblioitemnumber = ?") |
| 604 |
|| die $dbh->errstr; |
| 605 |
my $i = 0; |
| 606 |
my @results; |
| 607 |
|
| 608 |
$sth->execute($bibitem) || die $sth->errstr; |
| 609 |
|
| 610 |
while ( my $data = $sth->fetchrow_hashref ) { |
| 611 |
|
| 612 |
# Find out who currently has this item. |
| 613 |
# FIXME - Wouldn't it be better to do this as a left join of |
| 614 |
# some sort? Currently, this code assumes that if |
| 615 |
# fetchrow_hashref() fails, then the book is on the shelf. |
| 616 |
# fetchrow_hashref() can fail for any number of reasons (e.g., |
| 617 |
# database server crash), not just because no items match the |
| 618 |
# search criteria. |
| 619 |
my $sth2 = $dbh->prepare( |
| 620 |
"SELECT * FROM issues |
| 621 |
LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber |
| 622 |
WHERE itemnumber = ? |
| 623 |
" |
| 624 |
); |
| 625 |
|
| 626 |
$sth2->execute( $data->{'itemnumber'} ); |
| 627 |
if ( my $data2 = $sth2->fetchrow_hashref ) { |
| 628 |
$data->{'date_due'} = $data2->{'date_due'}; |
| 629 |
$data->{'card'} = $data2->{'cardnumber'}; |
| 630 |
$data->{'borrower'} = $data2->{'borrowernumber'}; |
| 631 |
} |
| 632 |
else { |
| 633 |
$data->{'date_due'} = ($data->{'withdrawn'} eq '1') ? 'Cancelled' : 'Available'; |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
# Find the last 3 people who borrowed this item. |
| 638 |
$sth2 = $dbh->prepare( |
| 639 |
"SELECT * FROM old_issues |
| 640 |
LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber |
| 641 |
WHERE itemnumber = ? |
| 642 |
ORDER BY returndate DESC,timestamp DESC" |
| 643 |
); |
| 644 |
|
| 645 |
$sth2->execute( $data->{'itemnumber'} ); |
| 646 |
for ( my $i2 = 0 ; $i2 < 2 ; $i2++ ) |
| 647 |
{ # FIXME : error if there is less than 3 pple borrowing this item |
| 648 |
if ( my $data2 = $sth2->fetchrow_hashref ) { |
| 649 |
$data->{"timestamp$i2"} = $data2->{'timestamp'}; |
| 650 |
$data->{"card$i2"} = $data2->{'cardnumber'}; |
| 651 |
$data->{"borrower$i2"} = $data2->{'borrowernumber'}; |
| 652 |
} # if |
| 653 |
} # for |
| 654 |
|
| 655 |
$results[$i] = $data; |
| 656 |
$i++; |
| 657 |
} |
| 658 |
|
| 659 |
return (@results); |
| 660 |
} |
| 661 |
|
| 662 |
=head2 CanBookBeIssued |
554 |
=head2 CanBookBeIssued |
| 663 |
|
555 |
|
| 664 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, |
556 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, |
| 665 |
- |
|
|