[Koha-patches] [PATCH] Enhancement 5320 (Estimate optionally next planned date for serials without periodicity) WHITESPACE FIX

Marcel de Rooy M.de.Rooy at rijksmuseum.nl
Thu Dec 2 15:35:32 CET 2010


For periodicity Irregular, Unknown or "Without periodicity", it would be
helpful if Koha could suggest a next planned date when receiving an issue based
on the time interval between the last two receivals of this serial. 

This option is triggered by new local-use preference SerialEstimatePlannedDate.
If this option exists and contains uppercase W for without periodicity, I for
irregular or U for unknown, or a combination of those characters, the option is
enabled for these particular periodicities. Behavior does not change for other
periodicities.
---
 C4/Serials.pm |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/C4/Serials.pm b/C4/Serials.pm
index 32e46be..3835e2e 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -2178,7 +2178,12 @@ sub GetNextDate(@) {
 
     #       warn "DOW $dayofweek";
     if ( $subscription->{periodicity} % 16 == 0 ) {    # 'without regularity' || 'irregular'
-        return 0;
+      return 0 unless _estimate_option_enabled($subscription->{periodicity});
+      my $estimate_days=_get_estimate_for_no_periodicity($subscription);
+      if(!$estimate_days) { #return today
+        ($year, $month, $day)= (localtime)[5,4,3]; $year+=1900; $month++;
+      }
+      @resultdate = Add_Delta_Days($year,$month,$day,$estimate_days);
     }
 
     #   daily : n / week
@@ -2305,6 +2310,35 @@ sub GetNextDate(@) {
 
     return "$resultdate";
 }
+sub _estimate_option_enabled { #check preference
+  my $periodicity= shift;
+  my $pref=C4::Context->preference('SerialEstimatePlannedDate');
+  my $period_char= substr("WIU",-1+$periodicity/16,1);
+	#16=Without,32=Irreg,48=Unknwn
+  return $pref=~ /$period_char/;
+}
+sub _get_estimate_for_no_periodicity {
+  my ($subscription) = @_;
+
+  my $dbh= C4::Context->dbh;
+  my $sth= $dbh->prepare('SELECT
+        YEAR(COALESCE(publisheddate,planneddate)),
+	MONTH(COALESCE(publisheddate,planneddate)),
+	DAY(COALESCE(publisheddate,planneddate))
+	FROM serial
+	WHERE subscriptionid = ? AND
+	  (planneddate IS NOT NULL OR publisheddate IS NOT NULL)
+	ORDER BY serialid DESC LIMIT 2');
+  $sth->execute($subscription->{subscriptionid});
+  my $dates= $sth->fetchall_arrayref; #last two non-null dates
+  $sth->finish;
+  return if @$dates<2 ||
+	!check_date(@{$dates->[1]}) || !check_date(@{$dates->[0]});
+
+  #pass args in chronological order to Delta_Days, return difference in days
+  #check on positive result
+  my $d; return ($d=Delta_Days(@{$dates->[1]}, @{$dates->[0]}))>0? $d: 1;
+}
 
 =head2 itemdata
 
-- 
1.6.0.6



More information about the Koha-patches mailing list