use CGI qw ( -utf8 );
use DateTime;
use C4::Auth;
-use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::DateUtils;
use Koha::Biblios;
# Get most of the needed data
my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
my $holds = $biblio->current_holds->unblessed;
- my $issues = GetBiblioIssues($biblionumber);
+ my $checkouts = Koha::Checkouts->search(
+ { biblionumber => $biblionumber },
+ {
+ join => 'item',
+ '+select' => ['item.barcode'],
+ '+as' => ['barcode'],
+ }
+ )->unblessed;
my @items = $biblio->items->as_list;
$biblioitem->{items}->{item} = [];
$item{'homebranchname'} = $home_library ? $home_library->branchname : '';
$item{'holdingbranchname'} = $holding_library ? $holding_library->branchname : '';
+ if ($item->location) {
+ my $authorised_value = Koha::AuthorisedValues->find_by_koha_field({ kohafield => 'items.location', authorised_value => $item->location });
+ if ($authorised_value) {
+ $item{location_description} = $authorised_value->opac_description;
+ }
+ }
+
+ if ($item->itype) {
+ my $itemtype = Koha::ItemTypes->find($item->itype);
+ if ($itemtype) {
+ $item{itype_description} = $itemtype->description;
+ }
+ }
+
my $transfer = $item->get_transfer;
if ($transfer) {
$item{transfer} = {
# Hashref building...
$biblioitem->{'reserves'}->{'reserve'} = $holds;
- $biblioitem->{'issues'}->{'issue'} = $issues;
+ $biblioitem->{'issues'}->{'issue'} = $checkouts;
push @records, $biblioitem;
}
# Issues management
if ( $cgi->param('show_loans') && $cgi->param('show_loans') eq "1" ) {
+ my $per_page = $cgi->param('loans_per_page');
+ my $page = $cgi->param('loans_page');
+
my $pending_checkouts = $patron->pending_checkouts;
+
+ if ($page || $per_page) {
+ $page ||= 1;
+ $per_page ||= 10;
+ $borrower->{total_loans} = $pending_checkouts->count();
+ $pending_checkouts = $pending_checkouts->search(undef, {
+ rows => $per_page,
+ page => $page,
+ });
+ }
+
my @checkouts;
while ( my $c = $pending_checkouts->next ) {
# FIXME We should only retrieve what is needed in the template
$borrower->{'loans'}->{'loan'} = \@checkouts;
}
- if ( $cgi->param('show_attributes') eq "1" ) {
- my $attrs = GetBorrowerAttributes( $borrowernumber, 1 );
- $borrower->{'attributes'} = $attrs;
+ my $show_attributes = $cgi->param('show_attributes');
+ if ( $show_attributes && $show_attributes eq "1" ) {
+ # FIXME Regression expected here, we do not retrieve the same field as previously
+ # Waiting for answer on bug 14257 comment 15
+ $borrower->{'attributes'} = [
+ map {
+ $_->type->opac_display
+ ? {
+ %{ $_->unblessed },
+ %{ $_->type->unblessed },
+ value => $_->attribute, # Backward compatibility
+ value_description => $_->description, # Awkward retro-compability...
+ }
+ : ()
+ } $patron->extended_attributes->search
+ ];
}
# Add is expired information
# Add renewal if possible
my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
- if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
+ if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber, undef, undef, undef, undef, 0 ); }
my $issue = $item->checkout;
return unless $issue; # FIXME should be handled
IP address where the end user request is being placed
- pickup_location (Optional)
a branch code indicating the location to which to deliver the item for pickup
- - needed_before_date (Optional)
- date after which hold request is no longer needed
- - pickup_expiry_date (Optional)
+ - start_date (Optional)
+ date after which hold request is no longer needed if the document has not been made available
+ - expiry_date (Optional)
date after which item returned to shelf if item is not picked up
=cut
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
+ # If borrower is restricted return an error code
+ return { code => 'PatronRestricted' } if $patron->is_debarred;
+
# Get the biblio record, or return an error code
my $biblionumber = $cgi->param('bib_id');
my $biblio = Koha::Biblios->find( $biblionumber );
return { code => 'libraryNotPickupLocation' } unless $destination->pickup_location;
return { code => 'cannotBeTransferred' } unless $biblio->can_be_transferred({ to => $destination });
+ my $resdate;
+ if ( $cgi->param('start_date') ) {
+ $resdate = $cgi->param('start_date');
+ }
+
+ my $expdate;
+ if ( $cgi->param('expiry_date') ) {
+ $expdate = $cgi->param('expiry_date');
+ }
+
# Add the reserve
# $branch, $borrowernumber, $biblionumber,
# $constraint, $bibitems, $priority, $resdate, $expdate, $notes,
# $title, $checkitem, $found
my $priority= C4::Reserves::CalculatePriority( $biblionumber );
- AddReserve( $branch, $borrowernumber, $biblionumber, undef, $priority, undef, undef, undef, $title, undef, undef );
+ AddReserve(
+ {
+ branchcode => $branch,
+ borrowernumber => $borrowernumber,
+ biblionumber => $biblionumber,
+ priority => $priority,
+ reservation_date => $resdate,
+ expiration_date => $expdate,
+ title => $title,
+ }
+ );
# Hashref building
my $out;
an itemnumber
- pickup_location (Optional)
a branch code indicating the location to which to deliver the item for pickup
- - needed_before_date (Optional)
- date after which hold request is no longer needed
- - pickup_expiry_date (Optional)
+ - start_date (Optional)
+ date after which hold request is no longer needed if the item has not been made available
+ - expiry_date (Optional)
date after which item returned to shelf if item is not picked up
=cut
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
+ # If borrower is restricted return an error code
+ return { code => 'PatronRestricted' } if $patron->is_debarred;
+
# Get the biblio or return an error code
my $biblionumber = $cgi->param('bib_id');
my $biblio = Koha::Biblios->find( $biblionumber );
my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber, $branch )->{status};
return { code => $canitembereserved } unless $canitembereserved eq 'OK';
+ my $resdate;
+ if ( $cgi->param('start_date') ) {
+ $resdate = $cgi->param('start_date');
+ }
+
+ my $expdate;
+ if ( $cgi->param('expiry_date') ) {
+ $expdate = $cgi->param('expiry_date');
+ }
+
# Add the reserve
- # $branch, $borrowernumber, $biblionumber,
- # $constraint, $bibitems, $priority, $resdate, $expdate, $notes,
- # $title, $checkitem, $found
- my $priority= C4::Reserves::CalculatePriority( $biblionumber );
- AddReserve( $branch, $borrowernumber, $biblionumber, undef, $priority, undef, undef, undef, $title, $itemnumber, undef );
+ my $priority = C4::Reserves::CalculatePriority($biblionumber);
+ AddReserve(
+ {
+ branchcode => $branch,
+ borrowernumber => $borrowernumber,
+ biblionumber => $biblionumber,
+ priority => $priority,
+ reservation_date => $resdate,
+ expiration_date => $expdate,
+ title => $title,
+ itemnumber => $itemnumber,
+ }
+ );
# Hashref building
my $out;