[Koha-cvs] koha/C4 Serials.pm [rel_3_0]

Antoine Farnault antoine at koha-fr.org
Thu Dec 21 16:04:52 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Antoine Farnault <toins>	06/12/21 15:04:52

Modified files:
	C4             : Serials.pm 

Log message:
	- input params for GetSubscriptions aren't required (if no param ihas been writed, GetSubscriptions search on title like %%) (comment the return statement)
	- New function HasExpiredBefore($subscriptionid,$date) return 1 if $subscriptionid will expire before $date. (this function is used on a script not yet commited.)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Serials.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.17&r2=1.5.2.18

Patches:
Index: Serials.pm
===================================================================
RCS file: /sources/koha/koha/C4/Serials.pm,v
retrieving revision 1.5.2.17
retrieving revision 1.5.2.18
diff -u -b -r1.5.2.17 -r1.5.2.18
--- Serials.pm	14 Dec 2006 12:59:23 -0000	1.5.2.17
+++ Serials.pm	21 Dec 2006 15:04:52 -0000	1.5.2.18
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Serials.pm,v 1.5.2.17 2006/12/14 12:59:23 hdl Exp $
+# $Id: Serials.pm,v 1.5.2.18 2006/12/21 15:04:52 toins Exp $
 
 use strict;
 use C4::Date;
@@ -33,7 +33,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.5.2.17 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.5.2.18 $' =~ /\d+/g;
     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
 };
 
@@ -59,7 +59,7 @@
     &NewSubscription    &ModSubscription    &DelSubscription    &GetSubscriptions
     &GetSubscription    &CountSubscriptionFromBiblionumber      &GetSubscriptionsFromBiblionumber
     &GetFullSubscriptionsFromBiblionumber   &ModSubscriptionHistory
-    &HasSubscriptionExpired                 &GetSubscriptionExpirationDate      &abouttoexpire
+    &HasSubscriptionExpired &HasExpiredBefore &GetSubscriptionExpirationDate &abouttoexpire
     
     &GetNextSeq         &NewIssue           &ItemizeSerials    &GetSerials
     &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
@@ -232,6 +232,7 @@
   serial table field
   subscription table field
   + information about subscription expiration
+  
 =back
 
 =cut
@@ -368,8 +369,6 @@
 
 =head2 GetSubscriptionsFromBiblionumber
 
-=over 4
-
 \@res = GetSubscriptionsFromBiblionumber($biblionumber)
 this function get the subscription list. it reads on subscription table.
 return :
@@ -377,8 +376,6 @@
 each line of this table is a hashref. All hashes containt
 startdate, histstartdate,opacnote,missinglist,recievedlist,periodicity,status & enddate
 
-=back
-
 =cut
 
 sub GetSubscriptionsFromBiblionumber {
@@ -525,7 +522,7 @@
 
 sub GetSubscriptions {
     my ( $title, $ISSN, $biblionumber ) = @_;
-    return unless $title or $ISSN or $biblionumber;
+    #return unless $title or $ISSN or $biblionumber;
     my $dbh = C4::Context->dbh;
     my $sth;
     if ($biblionumber) {
@@ -2177,6 +2174,45 @@
     }
 }
 
+=head2 HasExpiredBefore
+
+$result = &HasExpiredBefore($subscriptionid,$date)
+
+C<$date> must be a string like "1 month","1 day","3 weeks"
+C<$result> is 1 or 0
+
+
+=cut
+
+sub HasExpiredBefore {
+    my $subscriptionid = shift;
+    my $date           = shift;
+    my $dbh            = C4::Context->dbh;
+    my $subscription   = GetSubscription($subscriptionid);
+
+    if ( $subscription->{numberlength} ) {
+        return undef; # FIXME, don't know how count the date in this case.
+    }
+    else {
+        my $sth =
+          $dbh->prepare(
+            "select max(planneddate) from serial where subscriptionid=?");
+        $sth->execute($subscriptionid);
+        my $res = ParseDate( format_date_in_iso( $sth->fetchrow ) );
+        my $endofsubscriptiondate;
+        $endofsubscriptiondate = DateCalc(
+            format_date_in_iso( $subscription->{startdate} ),
+            $subscription->{monthlength} . " months"
+        ) if ( $subscription->{monthlength} );
+        $endofsubscriptiondate = DateCalc(
+            format_date_in_iso( $subscription->{startdate} ),
+            $subscription->{weeklength} . " weeks"
+        ) if ( $subscription->{weeklength} );
+
+        return DateCalc( $endofsubscriptiondate, "- " . $date );
+    }
+}
+
 =head2 old_newsubscription
 
 =over 4





More information about the Koha-cvs mailing list