Bug 17600: Standardize our EXPORT_OK
[srvgit] / C4 / ILSDI / Services.pm
index e929b37..54ef783 100644 (file)
@@ -21,19 +21,17 @@ use strict;
 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;
@@ -227,8 +225,17 @@ sub GetRecords {
 
         # 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} = [];
@@ -246,6 +253,20 @@ sub GetRecords {
             $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} = {
@@ -258,9 +279,15 @@ sub GetRecords {
             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;
     }
@@ -655,7 +682,7 @@ sub RenewLoan {
 
     # 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
@@ -699,9 +726,13 @@ sub HoldTitle {
     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 );
@@ -756,7 +787,7 @@ sub HoldTitle {
     my $priority= C4::Reserves::CalculatePriority( $biblionumber );
     AddReserve(
         {
-            branch           => $branch,
+            branchcode       => $branch,
             borrowernumber   => $borrowernumber,
             biblionumber     => $biblionumber,
             priority         => $priority,
@@ -810,6 +841,9 @@ sub HoldItem {
     # 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 );
@@ -852,7 +886,7 @@ sub HoldItem {
     my $priority = C4::Reserves::CalculatePriority($biblionumber);
     AddReserve(
         {
-            branch           => $branch,
+            branchcode       => $branch,
             borrowernumber   => $borrowernumber,
             biblionumber     => $biblionumber,
             priority         => $priority,