use warnings;
use C4::Members;
-use C4::Items;
-use C4::Circulation;
+use C4::Items qw( get_hostitemnumbers_of );
+use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal );
use C4::Accounts;
-use C4::Biblio;
-use C4::Reserves qw(AddReserve CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
+use C4::Biblio qw( GetMarcBiblio );
+use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved );
use C4::Context;
-use C4::AuthoritiesMarc;
-use XML::Simple;
-use HTML::Entities;
+use C4::Auth;
use CGI qw ( -utf8 );
use DateTime;
use C4::Auth;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Biblios;
use Koha::Checkouts;
# 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;
+ foreach my $checkout (@$checkouts) {
+ delete $checkout->{'borrowernumber'};
+ }
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} = {
push @{ $biblioitem->{items}->{item} }, \%item;
}
+ # Holds
+ my $holds = $biblio->current_holds->unblessed;
+ foreach my $hold (@$holds) {
+ delete $hold->{'borrowernumber'};
+ }
+
# Hashref building...
$biblioitem->{'reserves'}->{'reserve'} = $holds;
- $biblioitem->{'issues'}->{'issue'} = $issues;
+ $biblioitem->{'issues'}->{'issue'} = $checkouts;
push @records, $biblioitem;
}
# 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
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;
+ # Check for patron expired, category and syspref settings
+ return { code => 'PatronExpired' } if ($patron->category->effective_BlockExpiredPatronOpacActions && $patron->is_expired);
+
# Get the biblio record, or return an error code
my $biblionumber = $cgi->param('bib_id');
my $biblio = Koha::Biblios->find( $biblionumber );
my $priority= C4::Reserves::CalculatePriority( $biblionumber );
AddReserve(
{
- branch => $branch,
+ branchcode => $branch,
borrowernumber => $borrowernumber,
biblionumber => $biblionumber,
priority => $priority,
# If borrower is restricted return an error code
return { code => 'PatronRestricted' } if $patron->is_debarred;
+ # Check for patron expired, category and syspref settings
+ return { code => 'PatronExpired' } if ($patron->category->effective_BlockExpiredPatronOpacActions && $patron->is_expired);
+
# Get the biblio or return an error code
my $biblionumber = $cgi->param('bib_id');
my $biblio = Koha::Biblios->find( $biblionumber );
my $priority = C4::Reserves::CalculatePriority($biblionumber);
AddReserve(
{
- branch => $branch,
+ branchcode => $branch,
borrowernumber => $borrowernumber,
biblionumber => $biblionumber,
priority => $priority,