View | Details | Raw Unified | Return to bug 5320
Collapse All | Expand All

(-)a/C4/Serials.pm (-2 / +35 lines)
Lines 2178-2184 sub GetNextDate(@) { Link Here
2178
2178
2179
    #       warn "DOW $dayofweek";
2179
    #       warn "DOW $dayofweek";
2180
    if ( $subscription->{periodicity} % 16 == 0 ) {    # 'without regularity' || 'irregular'
2180
    if ( $subscription->{periodicity} % 16 == 0 ) {    # 'without regularity' || 'irregular'
2181
        return 0;
2181
      return 0 unless _estimate_option_enabled($subscription->{periodicity});
2182
      my $estimate_days=_get_estimate_for_no_periodicity($subscription);
2183
      if(!$estimate_days) { #return today
2184
        ($year, $month, $day)= (localtime)[5,4,3]; $year+=1900; $month++;
2185
      }
2186
      @resultdate = Add_Delta_Days($year,$month,$day,$estimate_days);
2182
    }
2187
    }
2183
2188
2184
    #   daily : n / week
2189
    #   daily : n / week
Lines 2305-2310 sub GetNextDate(@) { Link Here
2305
2310
2306
    return "$resultdate";
2311
    return "$resultdate";
2307
}
2312
}
2313
sub _estimate_option_enabled { #check preference
2314
  my $periodicity= shift;
2315
  my $pref=C4::Context->preference('SerialEstimatePlannedDate');
2316
  my $period_char= substr("WIU",-1+$periodicity/16,1);
2317
	#16=Without,32=Irreg,48=Unknwn
2318
  return $pref=~ /$period_char/;
2319
}
2320
sub _get_estimate_for_no_periodicity {
2321
  my ($subscription) = @_;
2322
2323
  my $dbh= C4::Context->dbh;
2324
  my $sth= $dbh->prepare('SELECT
2325
        YEAR(COALESCE(publisheddate,planneddate)),
2326
	MONTH(COALESCE(publisheddate,planneddate)),
2327
	DAY(COALESCE(publisheddate,planneddate))
2328
	FROM serial
2329
	WHERE subscriptionid = ? AND
2330
	  (planneddate IS NOT NULL OR publisheddate IS NOT NULL)
2331
	ORDER BY serialid DESC LIMIT 2');
2332
  $sth->execute($subscription->{subscriptionid});
2333
  my $dates= $sth->fetchall_arrayref; #last two non-null dates
2334
  $sth->finish;
2335
  return if @$dates<2 ||
2336
	!check_date(@{$dates->[1]}) || !check_date(@{$dates->[0]});
2337
2338
  #pass args in chronological order to Delta_Days, return difference in days
2339
  #check on positive result
2340
  my $d; return ($d=Delta_Days(@{$dates->[1]}, @{$dates->[0]}))>0? $d: 1;
2341
}
2308
2342
2309
=head2 itemdata
2343
=head2 itemdata
2310
2344
2311
- 

Return to bug 5320