Bug 20227: Check for categorycode in default_borrower_circ_rules
[koha.git] / circ / transferstoreceive.pl
index 60bcd8b..10df07d 100755 (executable)
@@ -18,8 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Context;
 use C4::Output;
@@ -40,6 +39,7 @@ use Koha::ItemTypes;
 use Koha::Libraries;
 use Koha::DateUtils;
 use Koha::BiblioFrameworks;
+use Koha::Patrons;
 
 my $input = new CGI;
 my $itemnumber = $input->param('itemnumber');
@@ -89,28 +89,32 @@ while ( my $library = $libraries->next ) {
                 $getransf{'messcompa'} = 1;
                                $getransf{'diff'} = $diff;
             }
-            my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
-            my $itemtype = Koha::ItemTypes->find( (C4::Context->preference('item-level_itypes')) ? $gettitle->{'itype'} : $gettitle->{'itemtype'} );
+
+            my $item = Koha::Items->find( $num->{itemnumber} );
+            my $biblio = $item->biblio;
+            my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
 
             $getransf{'datetransfer'} = $num->{'datesent'};
             $getransf{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description?
-                       foreach (qw(title author biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) {
-               $getransf{$_} = $gettitle->{$_};
-                       }
-
-            my $record = GetMarcBiblio($gettitle->{'biblionumber'});
-            $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'}));
+            %getransf = (
+                %getransf,
+                title          => $biblio->title,
+                author         => $biblio->author,
+                biblionumber   => $biblio->biblionumber,
+                itemnumber     => $item->itemnumber,
+                barcode        => $item->barcode,
+                homebranch     => $item->homebranch,
+                holdingbranch  => $item->holdingbranch,
+                itemcallnumber => $item->itemcallnumber,
+            );
+
+            my $record = GetMarcBiblio({ biblionumber => $biblio->biblionumber });
+            $getransf{'subtitle'} = GetRecordValue('subtitle', $record, $biblio->frameworkcode);
 
             # we check if we have a reserv for this transfer
-            my $item = Koha::Items->find( $num->{itemnumber} );
             my $holds = $item->current_holds;
             if ( my $first_hold = $holds->next ) {
-                my $getborrower = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber );
-                $getransf{'borrowernum'}       = $getborrower->{'borrowernumber'};
-                $getransf{'borrowername'}      = $getborrower->{'surname'};
-                $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
-                $getransf{'borrowermail'}      = $getborrower->{'email'} if $getborrower->{'email'};
-                $getransf{'borrowerphone'}     = $getborrower->{'phone'};
+                $getransf{patron} = Koha::Patrons->find( $first_hold->borrowernumber );
             }
             push( @transferloop, \%getransf );
         }