Bug 20620: Remove warnings in moredetail.pl
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 19 Apr 2018 12:54:45 +0000 (09:54 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 4 May 2018 12:19:36 +0000 (09:19 -0300)
Since 19995 warnings are displayed in moredetail.pl, we should get rid
of them.

Test plan:
Hit moredetail.pl with different biblionumbers and confirm you do no
longer see warnings in logs.

Make sure values for rentalcharge, item type, ccode and replacementprice
are displayed correctly.

Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

catalogue/moredetail.pl

index 845d10e..3d6bd4a 100755 (executable)
@@ -123,8 +123,9 @@ my $copynumbers =
 
 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
 
-$data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
-$data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
+$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
+  if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
+$data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} || 0); # Price formatting should be done template-side
 foreach ( keys %{$data} ) {
     $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
 }
@@ -132,9 +133,9 @@ foreach ( keys %{$data} ) {
 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
 foreach my $item (@items){
     $item->{object} = Koha::Items->find( $item->{itemnumber} );
-    $item->{'collection'}              = $ccodes->{ $item->{ccode} } if ($ccodes);
-    $item->{'itype'}                   = $itemtypes->{ $item->{'itype'} }->{'translated_description'};
-    $item->{'replacementprice'}        = sprintf( "%.2f", $item->{'replacementprice'} );
+    $item->{'collection'}              = $ccodes->{ $item->{ccode} } if $ccodes && $item->{ccode} && exists $ccodes->{ $item->{ccode} };
+    $item->{'itype'}                   = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} };
+    $item->{'replacementprice'}        = sprintf( "%.2f", $item->{'replacementprice'} || 0 ); # Price formatting should be done template-side
     if ( defined $item->{'copynumber'} ) {
         $item->{'displaycopy'} = 1;
         if ( defined $copynumbers->{ $item->{'copynumber'} } ) {