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

paul poulain paul at koha-fr.org
Mon Oct 30 10:53:15 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	paul poulain <tipaul>	06/10/30 09:53:14

Modified files:
	C4             : Serials.pm 

Log message:
	- code cleaning (incomplete)
	- reintroducing patron alerts system

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

Patches:
Index: Serials.pm
===================================================================
RCS file: /sources/koha/koha/C4/Serials.pm,v
retrieving revision 1.5.2.3
retrieving revision 1.5.2.4
diff -u -b -r1.5.2.3 -r1.5.2.4
--- Serials.pm	6 Oct 2006 13:23:49 -0000	1.5.2.3
+++ Serials.pm	30 Oct 2006 09:53:14 -0000	1.5.2.4
@@ -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.3 2006/10/06 13:23:49 toins Exp $
+# $Id: Serials.pm,v 1.5.2.4 2006/10/30 09:53:14 tipaul Exp $
 
 use strict;
 use C4::Date;
@@ -31,7 +31,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.3 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.5.2.4 $' =~ /\d+/g;
         shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 
@@ -52,36 +52,23 @@
 =cut
 @ISA = qw(Exporter);
 @EXPORT = qw(
-    &NewSubscription 
-    &ModSubscription
-    &DelSubscription
-    &GetSubscriptions
-    &GetSubscription
-    &CountSubscriptionFromBiblionumber
-    &GetSubscriptionsFromBiblionumber
-    &GetFullSubscriptionsFromBiblionumber
-    &GetNextSeq
-    &ModSubscriptionHistory
-    &NewIssue
-    &ItemizeSerials
-    &GetSerials
-    &GetLatestSerials
-    &ModSerialStatus
-    &HasSubscriptionExpired
-    &GetSubscriptionExpirationDate
-    &ReNewSubscription
-    &GetSuppliersWithLateIssues
-    &GetLateIssues
-    &GetMissingIssues
-    &GetDistributedTo
-    &SetDistributedTo
-    &SerialChangeStatus
-    &getroutinglist
-    &delroutingmember
-    &addroutingmember
+    
+    &NewSubscription    &ModSubscription    &DelSubscription    &GetSubscriptions
+    &GetSubscription    &CountSubscriptionFromBiblionumber      &GetSubscriptionsFromBiblionumber
+    &GetFullSubscriptionsFromBiblionumber   &ModSubscriptionHistory
+    &HasSubscriptionExpired                 &GetSubscriptionExpirationDate      &abouttoexpire
+    
+    &GetNextSeq         &NewIssue           &ItemizeSerials    &GetSerials
+    &GetLatestSerials   &ModSerialStatus    &GetNextDate
+    &ReNewSubscription  &GetLateIssues      &GetMissingIssues
+    
+    &GetSuppliersWithLateIssues             &getsupplierbyserialid
+    &GetDistributedTo   &SetDistributedTo
+    &getroutinglist     &delroutingmember   &addroutingmember
     &reorder_members
-    &check_routing &getsupplierbyserialid &updateClaim &removeMissingIssue &abouttoexpire
-    &old_newsubscription &old_modsubscription &old_getserials &GetNextDate
+    &check_routing &updateClaim &removeMissingIssue
+    
+    &old_newsubscription &old_modsubscription &old_getserials
 );
 
 =head2 GetSuppliersWithLateIssues
@@ -497,13 +484,12 @@
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     # OK, now add the last 5 issues arrives/missing
-    my $query = qq|
-        SELECT   serialid,serialseq, status, planneddate, publisheddate,notes
+    my $query = "SELECT   serialid,serialseq, status, planneddate, publisheddate,notes
         FROM     serial
         WHERE    subscriptionid = ?
         AND      (status in (2,4,5))
         ORDER BY publisheddate,serialid DESC
-    |;
+                    ";
     my $sth=$dbh->prepare($query);
     $sth->execute($subscriptionid);
     my $counter=0;
@@ -516,12 +502,10 @@
         push @serials,$line;
     }
     # status = 2 is "arrived"
-    my $query = qq|
-        SELECT serialid,serialseq, status, publisheddate, planneddate,notes 
+    my $query = "SELECT serialid,serialseq, status, publisheddate, planneddate,notes 
         FROM   serial
         WHERE  subscriptionid = ? AND status NOT IN (2,4,5) 
-        ORDER BY publisheddate,serialid DESC
-    |;
+                        ORDER BY publisheddate,serialid DESC";
     my $sth=$dbh->prepare($query);
     $sth->execute($subscriptionid);
     while(my $line = $sth->fetchrow_hashref) {
@@ -530,11 +514,7 @@
         $line->{"planneddate"} = format_date($line->{"planneddate"});
         push @serials,$line;
     }
-    my $query = qq|
-        SELECT count(*)
-        FROM   serial
-        WHERE  subscriptionid=?
-    |;
+    my $query = "SELECT count(*) FROM serial WHERE subscriptionid=?";
     $sth=$dbh->prepare($query);
     $sth->execute($subscriptionid);
     my ($totalissues) = $sth->fetchrow;
@@ -557,13 +537,12 @@
     my ($subscriptionid,$limit) = @_;
     my $dbh = C4::Context->dbh;
     # status = 2 is "arrived"
-    my $strsth=qq(
-        SELECT   serialid,serialseq, status, planneddate
+    my $strsth="SELECT   serialid,serialseq, status, planneddate
         FROM     serial
         WHERE    subscriptionid = ?
         AND      (status =2 or status=4)
         ORDER BY planneddate DESC LIMIT 0,$limit
-    );
+                ";
     my $sth=$dbh->prepare($strsth);
     $sth->execute($subscriptionid);
     my @serials;
@@ -597,11 +576,7 @@
     my $dbh = C4::Context->dbh;
     my $distributedto;
     my $subscriptionid = @_;
-    my $query = qq|
-        SELECT distributedto
-        FROM   subscription
-        WHERE  subscriptionid=?
-    |;
+    my $query = "SELECT distributedto FROM subscription WHERE subscriptionid=?";
     my $sth = $dbh->prepare($query);
     $sth->execute($subscriptionid);
     return ($distributedto) = $sth->fetchrow;
@@ -790,11 +765,7 @@
 sub CountSubscriptionFromBiblionumber {
     my ($biblionumber) = @_;
     my $dbh = C4::Context->dbh;
-    my $query = qq|
-        SELECT count(*)
-        FROM   subscription
-        WHERE  biblionumber=?
-    |;
+    my $query = "SELECT count(*) FROM subscription WHERE biblionumber=?";
     my $sth = $dbh->prepare($query);
     $sth->execute($biblionumber);
     my $subscriptionsnumber = $sth->fetchrow;
@@ -816,11 +787,10 @@
 sub ModSubscriptionHistory {
     my ($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote)=@_;
     my $dbh=C4::Context->dbh;
-    my $query = qq(
-        UPDATE subscriptionhistory 
+    my $query = "UPDATE subscriptionhistory 
         SET histstartdate=?,enddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
         WHERE subscriptionid=?
-    );
+                ";
     my $sth = $dbh->prepare($query);
     $recievedlist =~ s/^,//g;
     $missinglist =~ s/^,//g;
@@ -844,11 +814,7 @@
     my ($serialid,$serialseq, $publisheddate,$planneddate,$status,$notes)=@_;
     # 1st, get previous status :
     my $dbh = C4::Context->dbh;
-    my $query = qq|
-        SELECT subscriptionid,status
-        FROM   serial
-        WHERE  serialid=?
-    |;
+    my $query = "SELECT subscriptionid,status FROM serial WHERE  serialid=?";
     my $sth = $dbh->prepare($query);
     $sth->execute($serialid);
     my ($subscriptionid,$oldstatus) = $sth->fetchrow;
@@ -856,18 +822,10 @@
     if ($status eq 6){
         DelIssue($serialseq, $subscriptionid)
     } else {
-        my $query = qq(
-            UPDATE serial
-            SET    serialseq=?,publisheddate=?,planneddate=?,status=?,notes=?
-            WHERE  serialid = ?
-        );
+        my $query = "UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE  serialid = ?";
         $sth = $dbh->prepare($query);
         $sth->execute($serialseq,$publisheddate,$planneddate,$status,$notes,$serialid);
-        my $query = qq(
-            SELECT missinglist,recievedlist
-            FROM   subscriptionhistory
-            WHERE  subscriptionid=?
-        );
+        my $query = "SELECT missinglist,recievedlist FROM   subscriptionhistory WHERE  subscriptionid=?";
         $sth = $dbh->prepare($query);
         $sth->execute($subscriptionid);
         my ($missinglist,$recievedlist) = $sth->fetchrow;
@@ -878,21 +836,13 @@
         warn "missinglist : $missinglist serialseq :$serialseq, ".index("$missinglist","$serialseq");
         $missinglist .= ",$serialseq" if ($status eq 4 and not index("$missinglist","$serialseq")>=0) ;
         $missinglist .= ",not issued $serialseq" if ($status eq 5 and index("$missinglist","$serialseq")>=0);
-        my $query = qq(
-            UPDATE subscriptionhistory
-            SET    recievedlist=?, missinglist=?
-            WHERE  subscriptionid=?
-        );
+        my $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
         $sth=$dbh->prepare($query);
         $sth->execute($recievedlist,$missinglist,$subscriptionid);
     }
     # create new waited entry if needed (ie : was a "waited" and has changed)
     if ($oldstatus eq 1 && $status ne 1) {
-        my $query = qq(
-            SELECT *
-            FROM   subscription
-            WHERE  subscriptionid = ?
-        );
+        my $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
         $sth = $dbh->prepare($query);
         $sth->execute($subscriptionid);
         my $val = $sth->fetchrow_hashref;
@@ -901,14 +851,14 @@
         # next date (calculated from actual date & frequency parameters)
         my $nextpublisheddate = GetNextDate($publisheddate,$val);
         NewIssue($newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate,$nextpublisheddate);
-        my $query = qq|
-            UPDATE subscription
-            SET    lastvalue1=?, lastvalue2=?, lastvalue3=?,
-                   innerloop1=?, innerloop2=?, innerloop3=?
-            WHERE  subscriptionid = ?
-        |;
+        my $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
+                     WHERE  subscriptionid = ?";
         $sth = $dbh->prepare($query);
         $sth->execute($newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3,$subscriptionid);
+        # check if an alert must be sent... (= a letter is defined & status became "arrived"
+        if ($val->{letter} && $status eq 2 && $oldstatus ne 2) {
+            SendAlerts('issue',$val->{subscriptionid},$val->{letter});
+        }
     }
 }
 
@@ -923,29 +873,27 @@
 =cut
 sub ModSubscription {
     my ($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
-        $periodicity,$dow,$numberlength,$weeklength,$monthlength,
+                    $periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
-        $numberingmethod, $status, $biblionumber, $notes, $letter, $subscriptionid)= @_;
+                    $numberingmethod, $status, $biblionumber, $callnumber, $notes, $letter, $hemisphere, $subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
-    my $query = qq|
-        UPDATE subscription
+    my $query = "UPDATE subscription
         SET     librarian=?, aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
-                periodicity=?,dow=?,numberlength=?,weeklength=?,monthlength=?,
+                        periodicity=?,firstacquidate=?,dow=?,irregularity=?, numberpattern=?, numberlength=?,weeklength=?,monthlength=?,
                 add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?,
                 add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?,
                 add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
-                numberingmethod=?, status=?, biblionumber=?, notes=?, letter=?
-        WHERE subscriptionid = ?
-    |;
+                        numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, letter=?, hemisphere=?
+                    WHERE subscriptionid = ?";
     my $sth=$dbh->prepare($query);
     $sth->execute($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
-        $periodicity,$dow,$numberlength,$weeklength,$monthlength,
+                    $periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
-        $numberingmethod, $status, $biblionumber, $notes, $letter, $subscriptionid);
+                    $numberingmethod, $status, $biblionumber, $callnumber, $notes, $letter, $hemisphere, $subscriptionid);
     $sth->finish;
 }
 
@@ -1115,73 +1063,6 @@
     $sth->execute($recievedlist,$missinglist,$subscriptionid);
 }
 
-=head2 serialchangestatus
-
-=over 4
-
-serialchangestatus($serialid,$serialseq,$planneddate,$status,$notes)
-
-Change the status of a serial issue.
-Note: this was the older subroutine
-
-=back
-
-=cut
-sub SerialChangeStatus {
-    my ($serialid,$serialseq,$planneddate,$publisheddate,$status,$notes)=@_;
-    # 1st, get previous status : if we change from "waited" to something else, then we will have to create a new "waited" entry
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("select subscriptionid,status from serial where serialid=?");
-    $sth->execute($serialid);
-    my ($subscriptionid,$oldstatus) = $sth->fetchrow;
-    # change status & update subscriptionhistory
-    if ($status eq 6){
-        DelIssue($serialseq, $subscriptionid)
-    }else{
-        $sth = $dbh->prepare(qq|
-     UPDATE serial 
-     SET serialseq=?,
-         planneddate=?,
-         publisheddate=?,
-         status=?,
-         notes=? 
-     WHERE serialid = ?|);
-        $sth->execute($serialseq,$planneddate,$publisheddate,$status,$notes,$serialid);
-        $sth = $dbh->prepare("select missinglist,recievedlist from subscriptionhistory where subscriptionid=?");
-        $sth->execute($subscriptionid);
-        my ($missinglist,$recievedlist) = $sth->fetchrow;
-        if ($status eq 2) {
-            $recievedlist .= "| $serialseq" unless (index($recievedlist,$serialseq)>=0);
-            $recievedlist =~ s/^\| //g;
-        }
-        $missinglist .= "| $serialseq" if ($status eq 4 and not index($missinglist,$serialseq)>=0) ;
-        $missinglist .= "| not issued $serialseq" if ($status eq 5 and not index($missinglist,$serialseq)>=0);
-        $missinglist =~ s/^\| //g;
-        $sth=$dbh->prepare("update subscriptionhistory set recievedlist=?, missinglist=? where subscriptionid=?");
-        $sth->execute($recievedlist,$missinglist,$subscriptionid);
-    }
-    # create new waited entry if needed (ie : was a "waited" and has changed)
-    if ($oldstatus eq 1 && $status ne 1) {
-        $sth = $dbh->prepare("select * from subscription where subscriptionid = ? ");
-        $sth->execute($subscriptionid);
-        my $val = $sth->fetchrow_hashref;
-        # next issue number
-        my ($newserialseq,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3) = GetNextSeq($val);
-        my $nextplanneddate = GetNextDate($planneddate,$val);
-        NewIssue($newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextplanneddate,$nextplanneddate);
-        $sth = $dbh->prepare("update subscription set lastvalue1=?, lastvalue2=?,lastvalue3=?,innerloop1=?, innerloop2=?,innerloop3=? where subscriptionid = ?");
-        $sth->execute($newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3,$subscriptionid);
-    }
-    # check if an alert must be sent... (= a letter is defined & status became "arrived"
-   	$sth = $dbh->prepare("select * from subscription where subscriptionid = ? ");
-	$sth->execute($subscriptionid);
-	my $subscription = $sth->fetchrow_hashref; 
-    if ($subscription->{letter} && $status eq 2) {
-        SendAlerts('issue',$subscription->{subscriptionid},$subscription->{letter});
-    }
-}
-
-
 =head2 ItemizeSerials
 
 =over 4
@@ -1526,7 +1407,7 @@
 this function removes an issue from being part of the missing string in 
 subscriptionlist.missinglist column
 
-called when a missing issue is found from the statecollection.pl file
+called when a missing issue is found from the serials-recieve.pl file
 
 =back
 
@@ -1839,7 +1720,7 @@
 $irregularity - the issues not expected separated by a '|'
 - eg. monthly issue but not expecting issue for june and july would have $irregularity of '6|7'
 $numberpattern - the number for an array of labels to reconstruct the javascript correctly in the 
-   alt_subscription-add.tmpl file
+   subscription-add.tmpl file
 $callnumber - display the callnumber of the serial
 $hemisphere - either 2 = southern hemisphere or 1 = northern hemisphere - used for quarterly serials
 
@@ -1908,7 +1789,7 @@
 $irregularity - the issues not expected separated by a '|'
 - eg. monthly issue but not expecting issue for june and july would have $irregularity of '6|7'
 $numberpattern - the number for an array of labels to reconstruct the javascript correctly in the 
-   alt_subscription-add.tmpl file
+   subscription-add.tmpl file
 $callnumber - display the callnumber of the serial
 $hemisphere - either 2 = southern hemisphere or 1 = northern hemisphere - used for quarterly serials
 





More information about the Koha-cvs mailing list