Bug 28290: Don't send subfields to 'as_string' if none to send
[koha-ffzg.git] / C4 / Serials.pm
index 1da5058..75c9d7f 100644 (file)
@@ -32,12 +32,12 @@ use Date::Calc qw(
     Today
 );
 use POSIX qw( strftime );
-use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio );
+use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
 use C4::Log qw( logaction );    # logaction
 use C4::Serials::Frequency qw( GetSubscriptionFrequency );
 use C4::Serials::Numberpattern;
 use Koha::AdditionalFieldValues;
-use Koha::DateUtils qw( dt_from_string output_pref );
+use Koha::Biblios;
 use Koha::Serial;
 use Koha::Subscriptions;
 use Koha::Subscription::Histories;
@@ -426,23 +426,11 @@ sub GetSubscriptionsFromBiblionumber {
     $sth->execute($biblionumber);
     my @res;
     while ( my $subs = $sth->fetchrow_hashref ) {
-        $subs->{startdate}     = output_pref( { dt => dt_from_string( $subs->{startdate} ),     dateonly => 1 } );
-        $subs->{histstartdate} = output_pref( { dt => dt_from_string( $subs->{histstartdate} ), dateonly => 1 } );
-        if ( defined $subs->{histenddate} ) {
-           $subs->{histenddate}   = output_pref( { dt => dt_from_string( $subs->{histenddate} ),   dateonly => 1 } );
-        } else {
-            $subs->{histenddate} = "";
-        }
         $subs->{opacnote}     //= "";
         $subs->{ "periodicity" . $subs->{periodicity} }     = 1;
         $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
         $subs->{ "status" . $subs->{'status'} }             = 1;
 
-        if (not defined $subs->{enddate} ) {
-            $subs->{enddate} = '';
-        } else {
-            $subs->{enddate} = output_pref( { dt => dt_from_string( $subs->{enddate}), dateonly => 1 } );
-        }
         $subs->{'abouttoexpire'}       = abouttoexpire( $subs->{'subscriptionid'} );
         $subs->{'subscriptionexpired'} = HasSubscriptionExpired( $subs->{'subscriptionid'} );
         $subs->{cannotedit} = not can_edit_subscription( $subs );
@@ -676,13 +664,6 @@ sub GetSerials {
 
     while ( my $line = $sth->fetchrow_hashref ) {
         $line->{ "status" . $line->{status} } = 1;                                         # fills a "statusX" value, used for template status select list
-        for my $datefield ( qw( planneddate publisheddate) ) {
-            if ($line->{$datefield} && $line->{$datefield}!~m/^00/) {
-                $line->{$datefield} =  output_pref( { dt => dt_from_string( $line->{$datefield} ), dateonly => 1 } );
-            } else {
-                $line->{$datefield} = q{};
-            }
-        }
         push @serials, $line;
     }
 
@@ -699,13 +680,6 @@ sub GetSerials {
     while ( ( my $line = $sth->fetchrow_hashref ) && $counter < $count ) {
         $counter++;
         $line->{ "status" . $line->{status} } = 1;                                         # fills a "statusX" value, used for template status select list
-        for my $datefield ( qw( planneddate publisheddate) ) {
-            if ($line->{$datefield} && $line->{$datefield}!~m/^00/) {
-                $line->{$datefield} = output_pref( { dt => dt_from_string( $line->{$datefield} ), dateonly => 1 } );
-            } else {
-                $line->{$datefield} = q{};
-            }
-        }
 
         push @serials, $line;
     }
@@ -750,15 +724,6 @@ sub GetSerials2 {
 
     while ( my $line = $sth->fetchrow_hashref ) {
         $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list
-        # Format dates for display
-        for my $datefield ( qw( planneddate publisheddate ) ) {
-            if (!defined($line->{$datefield}) || $line->{$datefield} =~m/^00/) {
-                $line->{$datefield} = q{};
-            }
-            else {
-                $line->{$datefield} = output_pref( { dt => dt_from_string( $line->{$datefield} ), dateonly => 1 } );
-            }
-        }
         push @serials, $line;
     }
     return @serials;
@@ -1497,7 +1462,7 @@ sub NewSubscription {
     #set serial flag on biblio if not already set.
     my $biblio = Koha::Biblios->find( $biblionumber );
     if ( $biblio and !$biblio->serial ) {
-        my $record = GetMarcBiblio({ biblionumber => $biblionumber });
+        my $record = $biblio->metadata->record;
         my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial' );
         if ($tag) {
             eval { $record->field($tag)->update( $subf => 1 ); };
@@ -1899,15 +1864,6 @@ sub GetLateOrMissingIssues {
     $sth->execute( EXPECTED, LATE, CLAIMED );
     my @issuelist;
     while ( my $line = $sth->fetchrow_hashref ) {
-
-        if ($line->{planneddate} && $line->{planneddate} !~/^0+\-/) {
-            $line->{planneddateISO} = $line->{planneddate};
-            $line->{planneddate} = output_pref( { dt => dt_from_string( $line->{"planneddate"} ), dateonly => 1 } );
-        }
-        if ($line->{claimdate} && $line->{claimdate} !~/^0+\-/) {
-            $line->{claimdateISO} = $line->{claimdate};
-            $line->{claimdate}   = output_pref( { dt => dt_from_string( $line->{"claimdate"} ), dateonly => 1 } );
-        }
         $line->{"status".$line->{status}}   = 1;
 
         my $subscription_object = Koha::Subscriptions->find($line->{subscriptionid});