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

Antoine Farnault antoine at koha-fr.org
Tue Nov 21 18:01:12 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Antoine Farnault <toins>	06/11/21 17:01:12

Modified files:
	C4             : Serials.pm 

Log message:
	-search on ISSN only works now (san op #51). -removing warn wompilation. - re-indenting

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

Patches:
Index: Serials.pm
===================================================================
RCS file: /sources/koha/koha/C4/Serials.pm,v
retrieving revision 1.5.2.9
retrieving revision 1.5.2.10
diff -u -b -r1.5.2.9 -r1.5.2.10
--- Serials.pm	17 Nov 2006 14:57:21 -0000	1.5.2.9
+++ Serials.pm	21 Nov 2006 17:01:12 -0000	1.5.2.10
@@ -17,11 +17,11 @@
 # 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.9 2006/11/17 14:57:21 tipaul Exp $
+# $Id: Serials.pm,v 1.5.2.10 2006/11/21 17:01:12 toins Exp $
 
 use strict;
 use C4::Date;
-use Date::Manip;
+#use Date::Manip;
 use C4::Suggestions;
 use C4::Koha;
 use C4::Biblio;
@@ -32,9 +32,9 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.5.2.9 $' =~ /\d+/g;
-        shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
-
+$VERSION = do { my @v = '$Revision: 1.5.2.10 $' =~ /\d+/g;
+    shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
+};
 
 =head1 NAME
 
@@ -51,14 +51,14 @@
 =head1 FUNCTIONS
 
 =cut
+
 @ISA = qw(Exporter);
 @EXPORT = qw(
-    
-    &NewSubscription    &ModSubscription    &DelSubscription    &GetSubscriptions
+  &NewSubscription    &ModSubscription
+  &DelSubscription    &GetSubscriptions
     &GetSubscription    &CountSubscriptionFromBiblionumber      &GetSubscriptionsFromBiblionumber
     &GetFullSubscriptionsFromBiblionumber   &ModSubscriptionHistory
     &HasSubscriptionExpired                 &GetSubscriptionExpirationDate      &abouttoexpire
-    
     &GetNextSeq         &NewIssue           &ItemizeSerials    &GetSerials
     &GetLatestSerials   &ModSerialStatus    &GetNextDate
     &ReNewSubscription  &GetLateIssues      &GetMissingIssues
@@ -87,6 +87,7 @@
 =back
 
 =cut
+
 sub GetSuppliersWithLateIssues {
     my $dbh = C4::Context->dbh;
     my $query = qq|
@@ -99,10 +100,10 @@
     my $sth = $dbh->prepare($query);
     $sth->execute;
     my %supplierlist;
-    while (my ($id,$name) = $sth->fetchrow) {
+    while ( my ( $id, $name ) = $sth->fetchrow ) {
         $supplierlist{$id} = $name;
     }
-    if(C4::Context->preference("RoutingSerials")){
+    if ( C4::Context->preference("RoutingSerials") ) {
 	$supplierlist{''} = "All Suppliers";
     }
     return %supplierlist;
@@ -123,12 +124,13 @@
 =back
 
 =cut
+
 sub GetLateIssues {
     my ($supplierid) = @_;
     my $dbh = C4::Context->dbh;
     my $sth;
     if ($supplierid) {
-        my $query = qq |
+        my $query = qq|
             SELECT     name,title,planneddate,serialseq,serial.subscriptionid
             FROM       subscription, serial, biblio
             LEFT JOIN  aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
@@ -139,7 +141,8 @@
             ORDER BY   title
         |;
         $sth = $dbh->prepare($query);
-    } else {
+    }
+    else {
         my $query = qq|
             SELECT     name,title,planneddate,serialseq,serial.subscriptionid
             FROM       subscription, serial, biblio
@@ -154,18 +157,18 @@
     $sth->execute;
     my @issuelist;
     my $last_title;
-    my $odd=0;
-    my $count=0;
-    while (my $line = $sth->fetchrow_hashref) {
+    my $odd   = 0;
+    my $count = 0;
+    while ( my $line = $sth->fetchrow_hashref ) {
         $odd++ unless $line->{title} eq $last_title;
         $line->{title} = "" if $line->{title} eq $last_title;
-        $last_title = $line->{title} if ($line->{title});
-        $line->{planneddate} = format_date($line->{planneddate});
-        $line->{'odd'} = 1 if $odd %2 ;
+        $last_title = $line->{title} if ( $line->{title} );
+        $line->{planneddate} = format_date( $line->{planneddate} );
+        $line->{'odd'} = 1 if $odd % 2;
 	$count++;
-        push @issuelist,$line;
+        push @issuelist, $line;
     }
-    return $count, at issuelist;
+    return $count, @issuelist;
 }
 
 =head2 GetSubscriptionHistoryFromSubscriptionId
@@ -181,6 +184,7 @@
 =back
 
 =cut
+
 sub GetSubscriptionHistoryFromSubscriptionId() {
     my $dbh = C4::Context->dbh;
     my $query = qq|
@@ -204,7 +208,8 @@
 =back
 
 =cut
-sub GetSerialStatusFromSerialId(){
+
+sub GetSerialStatusFromSerialId() {
     my $dbh = C4::Context->dbh;
     my $query = qq|
         SELECT status
@@ -227,44 +232,51 @@
 =back
 
 =cut
-sub GetSerialInformation{
-    my ($serialid)=@_;
+
+sub GetSerialInformation {
+    my ($serialid) = @_;
     my $dbh = C4::Context->dbh;
     my $query = qq|
         SELECT serial.*, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid
         FROM   serial LEFT JOIN subscription ON subscription.subscriptionid=serial.subscriptionid
         WHERE  serialid = ?
     |;
-    my $rq=$dbh->prepare($query);
+    my $rq = $dbh->prepare($query);
     $rq->execute($serialid);
-    my $data=$rq->fetchrow_hashref;
+    my $data = $rq->fetchrow_hashref;
+
+    if ( C4::Context->preference("serialsadditems") ) {
+        if ( $data->{'itemnumber'} ) {
+            my @itemnumbers = split /,/, $data->{'itemnumber'};
+            foreach my $itemnum (@itemnumbers) {
 
-    if (C4::Context->preference("serialsadditems")){
-      if ($data->{'itemnumber'}){
-        my @itemnumbers= split /,/,$data->{'itemnumber'};
-        foreach my $itemnum (@itemnumbers){
         #It is ASSUMED that MARCgetitem ALWAYS WORK... 
         #Maybe MARCgetitem should return values on failure
-          my $itemprocessed=PrepareItemrecordDisplay($data->{'biblionumber'},$itemnum);
-          $itemprocessed->{'itemnumber'}=$itemnum;
-          $itemprocessed->{'itemid'}=$itemnum;
-          $itemprocessed->{'serialid'}=$serialid;
-          $itemprocessed->{'biblionumber'}=$data->{'biblionumber'};
-          push @{$data->{'items'}},$itemprocessed;
+                my $itemprocessed =
+                  PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum );
+                $itemprocessed->{'itemnumber'}   = $itemnum;
+                $itemprocessed->{'itemid'}       = $itemnum;
+                $itemprocessed->{'serialid'}     = $serialid;
+                $itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
+                push @{ $data->{'items'} }, $itemprocessed;
+            }
         }
-      } else {
+        else {
         my $itemrecord;
-        my $itemprocessed=PrepareItemrecordDisplay($data->{'biblionumber'});
-        $itemprocessed->{'itemid'}="N$serialid";
-        $itemprocessed->{'serialid'}=$serialid;
-        $itemprocessed->{'biblionumber'}=$data->{'biblionumber'};
-        $itemprocessed->{'countitems'}=0;
-        push @{$data->{'items'}},$itemprocessed;
+            my $itemprocessed =
+              PrepareItemrecordDisplay( $data->{'biblionumber'} );
+            $itemprocessed->{'itemid'}       = "N$serialid";
+            $itemprocessed->{'serialid'}     = $serialid;
+            $itemprocessed->{'biblionumber'} = $data->{'biblionumber'};
+            $itemprocessed->{'countitems'}   = 0;
+            push @{ $data->{'items'} }, $itemprocessed;
       }
    }
-   $data->{"status".$data->{'serstatus'}}=1;
-   $data->{'subscriptionexpired'} = HasSubscriptionExpired($data->{'subscriptionid'});
-   $data->{'subscriptionaboutexpire'} = abouttoexpire($data->{'subscriptionid'});
+    $data->{ "status" . $data->{'serstatus'} } = 1;
+    $data->{'subscriptionexpired'} =
+      HasSubscriptionExpired( $data->{'subscriptionid'} );
+    $data->{'subscriptionaboutexpire'} =
+      abouttoexpire( $data->{'subscriptionid'} );
    return $data;
 }
       
@@ -277,14 +289,15 @@
 =back
 
 =cut
-sub AddItem2Serial{
-    my ($serialid,$itemnumber)=@_;
+
+sub AddItem2Serial {
+    my ( $serialid, $itemnumber ) = @_;
     my $dbh = C4::Context->dbh;
     my $query = qq|
         UPDATE serial SET itemnumber=IF(itemnumber IS NULL, $itemnumber, CONCAT(itemnumber,",",$itemnumber))
         WHERE  serialid = ?
     |;
-    my $rq=$dbh->prepare($query);
+    my $rq = $dbh->prepare($query);
     $rq->execute($serialid);
    return $rq->rows;
 }
@@ -302,10 +315,11 @@
 =back
 
 =cut
+
 sub GetSubscription {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
-    my $query =qq(
+    my $query            = qq(
         SELECT  subscription.*,
                 subscriptionhistory.*,
                 aqbudget.bookfundid,
@@ -338,6 +352,7 @@
 =back
 
 =cut
+
 sub GetSubscriptionsFromBiblionumber {
     my ($biblionumber) = @_;
     my $dbh = C4::Context->dbh;
@@ -359,23 +374,25 @@
     my $sth = $dbh->prepare($query);
     $sth->execute($biblionumber);
     my @res;
-    while (my $subs = $sth->fetchrow_hashref) {
-        $subs->{startdate} = format_date($subs->{startdate});
-        $subs->{histstartdate} = format_date($subs->{histstartdate});
+    while ( my $subs = $sth->fetchrow_hashref ) {
+        $subs->{startdate}     = format_date( $subs->{startdate} );
+        $subs->{histstartdate} = format_date( $subs->{histstartdate} );
         $subs->{opacnote} =~ s/\n/\<br\/\>/g;
         $subs->{missinglist} =~ s/\n/\<br\/\>/g;
         $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
-        $subs->{"periodicity".$subs->{periodicity}} = 1;
-        $subs->{"status".$subs->{'status'}} = 1;
-        if ($subs->{enddate} eq '0000-00-00') {
-            $subs->{enddate}='';
-        } else {
-            $subs->{enddate} = format_date($subs->{enddate});
+        $subs->{ "periodicity" . $subs->{periodicity} } = 1;
+        $subs->{ "status" . $subs->{'status'} } = 1;
+        if ( $subs->{enddate} eq '0000-00-00' ) {
+            $subs->{enddate} = '';
+        }
+        else {
+            $subs->{enddate} = format_date( $subs->{enddate} );
         }
-        push @res,$subs;
+        push @res, $subs;
     }
     return \@res;
 }
+
 =head2 GetFullSubscriptionsFromBiblionumber
 
 =over 4
@@ -386,10 +403,11 @@
 =back
 
 =cut
+
 sub GetFullSubscriptionsFromBiblionumber {
     my ($biblionumber) = @_;
     my $dbh = C4::Context->dbh;
-    my $query=qq|
+    my $query          = qq|
   SELECT serial.serialid,
     serial.serialseq,
     serial.planneddate, 
@@ -422,40 +440,48 @@
 	my $bibliotitle;
 	my @loopissues;
 	my $first;
-	my $previousnote="";
-	while (my $subs = $sth->fetchrow_hashref) {
-        $subs->{'publisheddate'}=($subs->{'publisheddate'}?format_date($subs->{'publisheddate'}):"XXX");
-        $subs->{'planneddate'} = format_date($subs->{'planneddate'}), 
-        $subs->{"status".$subs->{'status'}} = 1;
+    my $previousnote = "";
+
+    while ( my $subs = $sth->fetchrow_hashref ) {
+        $subs->{'publisheddate'} =
+          ( $subs->{'publisheddate'}
+            ? format_date( $subs->{'publisheddate'} )
+            : "XXX" );
+        $subs->{'planneddate'} = format_date( $subs->{'planneddate'} ),
+          $subs->{ "status" . $subs->{'status'} } = 1;
+
 #         $subs->{'notes'} = $subs->{'notes'} eq $previousnote?"":$subs->{notes};
-        if ($subs->{'year'} && $subs->{'year'} ne ""){
-          $year=$subs->{'year'};
-        } else {
-          $year="manage"
-        }
-		if ($tmpresults{$year}){
-          push @{$tmpresults{$year}->{'serials'}},$subs;
-		}else {
-          $tmpresults{$year}={
-              'year'=>$year,
-#               'startdate'=>format_date($subs->{'startdate'}),
-              'aqbooksellername'=>$subs->{'aqbooksellername'},
-              'bibliotitle'=>$subs->{'bibliotitle'},
-              'serials'=>[$subs],
-              'first'=>$first,
-              'branchcode' => $subs->{'branchcode'} ,
-              'subscriptionid' => $subs->{'subscriptionid'} ,
+        if ( $subs->{'year'} && $subs->{'year'} ne "" ) {
+            $year = $subs->{'year'};
+        }
+        else {
+            $year = "manage";
+        }
+        if ( $tmpresults{$year} ) {
+            push @{ $tmpresults{$year}->{'serials'} }, $subs;
+        }
+        else {
+            $tmpresults{$year} = {
+                'year' => $year,
+
+                #               'startdate'=>format_date($subs->{'startdate'}),
+                'aqbooksellername' => $subs->{'aqbooksellername'},
+                'bibliotitle'      => $subs->{'bibliotitle'},
+                'serials'          => [$subs],
+                'first'            => $first,
+                'branchcode'       => $subs->{'branchcode'},
+                'subscriptionid'   => $subs->{'subscriptionid'},
           };
         } 
-# 		$previousnote=$subs->{notes};
+
+        # 		$previousnote=$subs->{notes};
 	}
-    foreach my $key (sort {$b cmp $a} keys %tmpresults){
-       push @res,$tmpresults{$key};
+    foreach my $key ( sort { $b cmp $a } keys %tmpresults ) {
+        push @res, $tmpresults{$key};
     }
     return \@res;
 }
 
-
 =head2 GetSubscriptions
 
 =over 4
@@ -468,8 +494,9 @@
 =back
 
 =cut
+
 sub GetSubscriptions {
-    my ($title,$ISSN,$biblionumber) = @_;
+    my ( $title, $ISSN, $biblionumber ) = @_;
     return unless $title or $ISSN or $biblionumber;
     my $dbh = C4::Context->dbh;
     my $sth;
@@ -484,8 +511,9 @@
         );
     $sth = $dbh->prepare($query);
     $sth->execute($biblionumber);
-    } else {
-        if ($ISSN and $title){
+    }
+    else {
+        if ( $ISSN and $title ) {
             my $query = qq|
                 SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber
                 FROM   subscription,biblio,biblioitems
@@ -495,21 +523,22 @@
                 ORDER BY title
             |;
             $sth = $dbh->prepare($query);
-            $sth->execute("%$title%",$ISSN);
+            $sth->execute( "%$title%", $ISSN );
         }
-        else{
-            if ($ISSN){
+        else {
+            if ($ISSN) {
                 my $query = qq(
                     SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber
                     FROM   subscription,biblio,biblioitems
                     WHERE  biblio.biblionumber = biblioitems.biblionumber
                         AND biblio.biblionumber=subscription.biblionumber
-                        AND biblioitems.issn = ?
+                        AND biblioitems.issn LIKE ?
                     ORDER BY title
                 );
                 $sth = $dbh->prepare($query);
-                $sth->execute($ISSN);
-            } else {
+                $sth->execute( "%" . $ISSN . "%" );
+            }
+            else {
                 my $query = qq(
                     SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber
                     FROM   subscription,biblio,biblioitems
@@ -519,22 +548,23 @@
                     ORDER BY title
                 );
                 $sth = $dbh->prepare($query);
-                $sth->execute("%$title%");
+                $sth->execute( "%" . $title . "%" );
             }
         }
     }
     my @results;
-    my $previoustitle="";
-    my $odd=1;
-    while (my $line = $sth->fetchrow_hashref) {
-        if ($previoustitle eq $line->{title}) {
-            $line->{title}="";
-            $line->{issn}="";
-            $line->{toggle} = 1 if $odd==1;
-        } else {
-            $previoustitle=$line->{title};
-            $odd=-$odd;
-            $line->{toggle} = 1 if $odd==1;
+    my $previoustitle = "";
+    my $odd           = 1;
+    while ( my $line = $sth->fetchrow_hashref ) {
+        if ( $previoustitle eq $line->{title} ) {
+            $line->{title}  = "";
+            $line->{issn}   = "";
+            $line->{toggle} = 1 if $odd == 1;
+        }
+        else {
+            $previoustitle = $line->{title};
+            $odd           = -$odd;
+            $line->{toggle} = 1 if $odd == 1;
         }
         push @results, $line;
     }
@@ -553,45 +583,52 @@
 =back
 
 =cut
+
 sub GetSerials {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
+
     # OK, now add the last 5 issues arrives/missing
-    my $query = "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);
+    my $sth = $dbh->prepare($query);
     $sth->execute($subscriptionid);
-    my $counter=0;
+    my $counter = 0;
     my @serials;
-    while((my $line = $sth->fetchrow_hashref) && $counter <5) {
+    while ( ( my $line = $sth->fetchrow_hashref ) && $counter < 5 ) {
         $counter++;
-        $line->{"status".$line->{status}} = 1; # fills a "statusX" value, used for template status select list
-        $line->{"planneddate"} = format_date($line->{"planneddate"});
-        $line->{"publisheddate"} = format_date($line->{"publisheddate"});
-        push @serials,$line;
+        $line->{ "status" . $line->{status} } =
+          1;    # fills a "statusX" value, used for template status select list
+        $line->{"planneddate"}   = format_date( $line->{"planneddate"} );
+        $line->{"publisheddate"} = format_date( $line->{"publisheddate"} );
+        push @serials, $line;
     }
+
     # status = 2 is "arrived"
-    my $query = "SELECT serialid,serialseq, status, publisheddate, planneddate,notes 
+    $query =
+      "SELECT serialid,serialseq, status, publisheddate, planneddate,notes 
                         FROM   serial
                         WHERE  subscriptionid = ? AND status NOT IN (2,4,5) 
                         ORDER BY publisheddate,serialid DESC";
-    my $sth=$dbh->prepare($query);
+    $sth = $dbh->prepare($query);
     $sth->execute($subscriptionid);
-    while(my $line = $sth->fetchrow_hashref) {
-        $line->{"status".$line->{status}} = 1; # fills a "statusX" value, used for template status select list
-        $line->{"publisheddate"} = format_date($line->{"publisheddate"});
-        $line->{"planneddate"} = format_date($line->{"planneddate"});
-        push @serials,$line;
+    while ( my $line = $sth->fetchrow_hashref ) {
+        $line->{ "status" . $line->{status} } =
+          1;    # fills a "statusX" value, used for template status select list
+        $line->{"publisheddate"} = format_date( $line->{"publisheddate"} );
+        $line->{"planneddate"}   = format_date( $line->{"planneddate"} );
+        push @serials, $line;
     }
-    my $query = "SELECT count(*) FROM serial WHERE subscriptionid=?";
-    $sth=$dbh->prepare($query);
+    $query = "SELECT count(*) FROM serial WHERE subscriptionid=?";
+    $sth = $dbh->prepare($query);
     $sth->execute($subscriptionid);
     my ($totalissues) = $sth->fetchrow;
-    return ($totalissues, at serials);
+    return ( $totalissues, @serials );
 }
 
 =head2 GetLatestSerials
@@ -606,32 +643,36 @@
 =back
 
 =cut
+
 sub GetLatestSerials {
-    my ($subscriptionid,$limit) = @_;
+    my ( $subscriptionid, $limit ) = @_;
     my $dbh = C4::Context->dbh;
+
     # status = 2 is "arrived"
-    my $strsth="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);
+    my $sth = $dbh->prepare($strsth);
     $sth->execute($subscriptionid);
     my @serials;
-    while(my $line = $sth->fetchrow_hashref) {
-        $line->{"status".$line->{status}} = 1; # fills a "statusX" value, used for template status select list
-        $line->{"planneddate"} = format_date($line->{"planneddate"});
-        push @serials,$line;
-    }
-#     my $query = qq|
-#         SELECT count(*)
-#         FROM   serial
-#         WHERE  subscriptionid=?
-#     |;
-#     $sth=$dbh->prepare($query);
-#     $sth->execute($subscriptionid);
-#     my ($totalissues) = $sth->fetchrow;
+    while ( my $line = $sth->fetchrow_hashref ) {
+        $line->{ "status" . $line->{status} } =
+          1;    # fills a "statusX" value, used for template status select list
+        $line->{"planneddate"} = format_date( $line->{"planneddate"} );
+        push @serials, $line;
+    }
+
+    #     my $query = qq|
+    #         SELECT count(*)
+    #         FROM   serial
+    #         WHERE  subscriptionid=?
+    #     |;
+    #     $sth=$dbh->prepare($query);
+    #     $sth->execute($subscriptionid);
+    #     my ($totalissues) = $sth->fetchrow;
     return \@serials;
 }
 
@@ -645,6 +686,7 @@
 =back
 
 =cut
+
 sub GetDistributedTo {
     my $dbh = C4::Context->dbh;
     my $distributedto;
@@ -668,6 +710,7 @@
 =back
 
 =cut
+
 # sub GetNextSeq {
 #     my ($val) =@_;
 #     my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
@@ -699,72 +742,79 @@
 #     return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
 # }
 
-
 sub GetNextSeq {
-    my ($val) =@_;
-    my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
+    my ($val) = @_;
+    my (
+        $calculated,    $newlastvalue1, $newlastvalue2, $newlastvalue3,
+        $newinnerloop1, $newinnerloop2, $newinnerloop3
+    );
     my $pattern = $val->{numberpattern};
-    my @seasons = ('nothing','Winter','Spring','Summer','Autumn');
-    my @southern_seasons = ('','Summer','Autumn','Winter','Spring');
+    my @seasons = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' );
+    my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' );
     $calculated = $val->{numberingmethod};
     $newlastvalue1 = $val->{lastvalue1};
     $newlastvalue2 = $val->{lastvalue2};
     $newlastvalue3 = $val->{lastvalue3};
-    if($newlastvalue3 > 0){ # if x y and z columns are used
-	$newlastvalue3 = $newlastvalue3+1;
-	if($newlastvalue3 > $val->{whenmorethan3}){
+
+    if ( $newlastvalue3 > 0 ) {    # if x y and z columns are used
+        $newlastvalue3 = $newlastvalue3 + 1;
+        if ( $newlastvalue3 > $val->{whenmorethan3} ) {
 	    $newlastvalue3 = $val->{setto3};
 	    $newlastvalue2++;
-	    if($newlastvalue2 > $val->{whenmorethan2}){
+            if ( $newlastvalue2 > $val->{whenmorethan2} ) {
 		$newlastvalue1++;
 		$newlastvalue2 = $val->{setto2};
 	    }
 	}
 	$calculated =~ s/\{X\}/$newlastvalue1/g;
-	if($pattern == 6){
-	    if($val->{hemisphere} == 2){
+        if ( $pattern == 6 ) {
+            if ( $val->{hemisphere} == 2 ) {
 		my $newlastvalue2seq = $southern_seasons[$newlastvalue2];
 		$calculated =~ s/\{Y\}/$newlastvalue2seq/g;
-	    } else {
+            }
+            else {
 		my $newlastvalue2seq = $seasons[$newlastvalue2];
 		$calculated =~ s/\{Y\}/$newlastvalue2seq/g;
 	    }
-	} else {
+        }
+        else {
 	    $calculated =~ s/\{Y\}/$newlastvalue2/g;
 	}
 	$calculated =~ s/\{Z\}/$newlastvalue3/g;
     }
-    if($newlastvalue2 > 0 && $newlastvalue3 < 1){ # if x and y columns are used
-	$newlastvalue2 = $newlastvalue2+1;
-	if($newlastvalue2 > $val->{whenmorethan2}){
+    if ( $newlastvalue2 > 0 && $newlastvalue3 < 1 )
+    {    # if x and y columns are used
+        $newlastvalue2 = $newlastvalue2 + 1;
+        if ( $newlastvalue2 > $val->{whenmorethan2} ) {
 	    $newlastvalue2 = $val->{setto2};
 	    $newlastvalue1++;
 	}
 	$calculated =~ s/\{X\}/$newlastvalue1/g;
-	if($pattern == 6){
-	    if($val->{hemisphere} == 2){
+        if ( $pattern == 6 ) {
+            if ( $val->{hemisphere} == 2 ) {
 		my $newlastvalue2seq = $southern_seasons[$newlastvalue2];
 		$calculated =~ s/\{Y\}/$newlastvalue2seq/g;
-	    } else {
+            }
+            else {
 		my $newlastvalue2seq = $seasons[$newlastvalue2];
 		$calculated =~ s/\{Y\}/$newlastvalue2seq/g;
 	    }
-	} else {
+        }
+        else {
 	    $calculated =~ s/\{Y\}/$newlastvalue2/g;
 	}
     }
-    if($newlastvalue1 > 0 && $newlastvalue2 < 1 && $newlastvalue3 < 1){ # if column x only
-	$newlastvalue1 = $newlastvalue1+1;
-	if($newlastvalue1 > $val->{whenmorethan1}){
+    if ( $newlastvalue1 > 0 && $newlastvalue2 < 1 && $newlastvalue3 < 1 )
+    {    # if column x only
+        $newlastvalue1 = $newlastvalue1 + 1;
+        if ( $newlastvalue1 > $val->{whenmorethan1} ) {
 	    $newlastvalue1 = $val->{setto2};
 	}
 	$calculated =~ s/\{X\}/$newlastvalue1/g;
     }
-    return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3);
+    return ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3 );
 }
 
-
-
 =head2 GetSeq
 
 =over 4
@@ -778,14 +828,15 @@
 =back
 
 =cut
+
 sub GetSeq {
-    my ($val) =@_;
+    my ($val)      = @_;
     my $calculated = $val->{numberingmethod};
-    my $x=$val->{'lastvalue1'};
+    my $x          = $val->{'lastvalue1'};
     $calculated =~ s/\{X\}/$x/g;
-    my $y=$val->{'lastvalue2'};
+    my $y = $val->{'lastvalue2'};
     $calculated =~ s/\{Y\}/$y/g;
-    my $z=$val->{'lastvalue3'};
+    my $z = $val->{'lastvalue3'};
     $calculated =~ s/\{Z\}/$z/g;
     return $calculated;
 }
@@ -804,21 +855,30 @@
 =back
 
 =cut
+
 sub GetSubscriptionExpirationDate {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
-    my $enddate=$subscription->{startdate};
-    # we don't do the same test if the subscription is based on X numbers or on X weeks/months
-    if ($subscription->{numberlength}) {
+    my $enddate          = $subscription->{startdate};
+
+# we don't do the same test if the subscription is based on X numbers or on X weeks/months
+    if ( $subscription->{numberlength} ) {
+
         #calculate the date of the last issue.
-        for (my $i=1;$i<=$subscription->{numberlength};$i++) {
-            $enddate = GetNextDate($enddate,$subscription);
+        for ( my $i = 1 ; $i <= $subscription->{numberlength} ; $i++ ) {
+            $enddate = GetNextDate( $enddate, $subscription );
         }
     }
     else {
-        $enddate = DateCalc(format_date_in_iso($subscription->{startdate}),$subscription->{monthlength}." months") if ($subscription->{monthlength});
-        $enddate = DateCalc(format_date_in_iso($subscription->{startdate}),$subscription->{weeklength}." weeks") if ($subscription->{weeklength});
+        $enddate = DateCalc(
+            format_date_in_iso( $subscription->{startdate} ),
+            $subscription->{monthlength} . " months"
+        ) if ( $subscription->{monthlength} );
+        $enddate = DateCalc(
+            format_date_in_iso( $subscription->{startdate} ),
+            $subscription->{weeklength} . " weeks"
+        ) if ( $subscription->{weeklength} );
     }
     return $enddate;
 }
@@ -835,6 +895,7 @@
 =back
 
 =cut
+
 sub CountSubscriptionFromBiblionumber {
     my ($biblionumber) = @_;
     my $dbh = C4::Context->dbh;
@@ -845,7 +906,6 @@
     return $subscriptionsnumber;
 }
 
-
 =head2 ModSubscriptionHistory
 
 =over 4
@@ -857,9 +917,13 @@
 =back
 
 =cut
+
 sub ModSubscriptionHistory {
-    my ($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote)=@_;
-    my $dbh=C4::Context->dbh;
+    my (
+        $subscriptionid, $histstartdate, $enddate, $recievedlist,
+        $missinglist,    $opacnote,      $librariannote
+    ) = @_;
+    my $dbh   = C4::Context->dbh;
     my $query = "UPDATE subscriptionhistory 
                     SET histstartdate=?,enddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
                     WHERE subscriptionid=?
@@ -868,7 +932,10 @@
     $recievedlist =~ s/^,//g;
     $missinglist =~ s/^,//g;
     $opacnote =~ s/^,//g;
-    $sth->execute($histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote,$subscriptionid);
+    $sth->execute(
+        $histstartdate, $enddate,       $recievedlist, $missinglist,
+        $opacnote,      $librariannote, $subscriptionid
+    );
     return $sth->rows;
 }
 
@@ -884,61 +951,89 @@
 =back
 
 =cut
+
 sub ModSerialStatus {
-    my ($serialid,$serialseq, $publisheddate,$planneddate,$status,$notes)=@_;
+    my ( $serialid, $serialseq, $publisheddate, $planneddate, $status, $notes )
+      = @_;
+
     # 1st, get previous status :
     my $dbh = C4::Context->dbh;
     my $query = "SELECT subscriptionid,status FROM serial WHERE  serialid=?";
     my $sth = $dbh->prepare($query);
     $sth->execute($serialid);
-    my ($subscriptionid,$oldstatus) = $sth->fetchrow;
+    my ( $subscriptionid, $oldstatus ) = $sth->fetchrow;
+
     # change status & update subscriptionhistory
     my $val;
-    if ($status eq 6){
-        DelIssue($serialseq, $subscriptionid)
-    } else {
-        my $query = "UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE  serialid = ?";
+    if ( $status eq 6 ) {
+        DelIssue( $serialseq, $subscriptionid );
+    }
+    else {
+        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 = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
+        $sth->execute( $serialseq, $publisheddate, $planneddate, $status,
+            $notes, $serialid );
+        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
         $sth = $dbh->prepare($query);
         $sth->execute($subscriptionid);
-        my $val=$sth->fetchrow_hashref;
-        unless ($val->{manualhistory}){
-          my $query = "SELECT missinglist,recievedlist FROM subscriptionhistory WHERE  subscriptionid=?";
+        my $val = $sth->fetchrow_hashref;
+        unless ( $val->{manualhistory} ) {
+            $query =
+"SELECT missinglist,recievedlist FROM subscriptionhistory WHERE  subscriptionid=?";
           $sth = $dbh->prepare($query);
           $sth->execute($subscriptionid);
-          my ($missinglist,$recievedlist) = $sth->fetchrow;
-          if ($status eq 2) {
-  #             warn "receivedlist : $recievedlist serialseq :$serialseq, ".index("$recievedlist","$serialseq");
-              $recievedlist .= ",$serialseq" unless (index("$recievedlist","$serialseq")>=0);
-          }
-  #         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 = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
-          $sth=$dbh->prepare($query);
-          $sth->execute($recievedlist,$missinglist,$subscriptionid);
+            my ( $missinglist, $recievedlist ) = $sth->fetchrow;
+            if ( $status eq 2 ) {
+
+#             warn "receivedlist : $recievedlist serialseq :$serialseq, ".index("$recievedlist","$serialseq");
+                $recievedlist .= ",$serialseq"
+                  unless ( index( "$recievedlist", "$serialseq" ) >= 0 );
+            }
+
+#         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 );
+            $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) {
+    if ( $oldstatus eq 1 && $status ne 1 ) {
         my $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
         $sth = $dbh->prepare($query);
         $sth->execute($subscriptionid);
         my $val = $sth->fetchrow_hashref;
+
         # next issue number
-        my ($newserialseq,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3) = GetNextSeq($val);
+        my (
+            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
+            $newinnerloop1, $newinnerloop2, $newinnerloop3
+        ) = GetNextSeq($val);
+
         # next date (calculated from actual date & frequency parameters)
-        my $nextpublisheddate = GetNextDate($publisheddate,$val);
-        NewIssue($newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate,$nextpublisheddate);
-        my $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
+        my $nextpublisheddate = GetNextDate( $publisheddate, $val );
+        NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'},
+            1, $nextpublisheddate, $nextpublisheddate );
+        $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});
+        $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} );
         }
     }
 }
@@ -952,13 +1047,21 @@
 =back
 
 =cut
+
 sub ModSubscription {
-    my ($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
-                    $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, $callnumber, $notes, $letter, $hemisphere,$manualhistory, $subscriptionid) = @_;
+    my (
+        $auser,           $branchcode,   $aqbooksellerid, $cost,
+        $aqbudgetid,      $startdate,    $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,   $callnumber,
+        $notes,           $letter,       $hemisphere,     $manualhistory,
+        $subscriptionid
+    ) = @_;
     my $dbh = C4::Context->dbh;
     my $query = "UPDATE subscription
                     SET librarian=?, branchcode=?,aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
@@ -968,17 +1071,23 @@
                         add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
                         numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, letter=?, hemisphere=?,manualhistory=?
                     WHERE subscriptionid = ?";
-    my $sth=$dbh->prepare($query);
-    $sth->execute($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
-                    $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, $callnumber, $notes, $letter, $hemisphere,$manualhistory, $subscriptionid);
+    my $sth = $dbh->prepare($query);
+    $sth->execute(
+        $auser,           $branchcode,   $aqbooksellerid, $cost,
+        $aqbudgetid,      $startdate,    $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,   $callnumber,
+        $notes,           $letter,       $hemisphere,     $manualhistory,
+        $subscriptionid
+    );
     $sth->finish;
 }
 
-
 =head2 NewSubscription
 
 =over 4
@@ -998,18 +1107,23 @@
 =back
 
 =cut
+
 sub NewSubscription {
-    my ($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
-        $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
-        $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
-        $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
-        $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
-        $numberingmethod, $status, $notes, $letter,
-        $firstacquidate,$irregularity,$numberpattern, $callnumber, $hemisphere,
-        $manualhistory
+    my (
+        $auser,         $branchcode,   $aqbooksellerid,  $cost,
+        $aqbudgetid,    $biblionumber, $startdate,       $periodicity,
+        $dow,           $numberlength, $weeklength,      $monthlength,
+        $add1,          $every1,       $whenmorethan1,   $setto1,
+        $lastvalue1,    $innerloop1,   $add2,            $every2,
+        $whenmorethan2, $setto2,       $lastvalue2,      $innerloop2,
+        $add3,          $every3,       $whenmorethan3,   $setto3,
+        $lastvalue3,    $innerloop3,   $numberingmethod, $status,
+        $notes,         $letter,       $firstacquidate,  $irregularity,
+        $numberpattern, $callnumber,   $hemisphere,      $manualhistory
         ) = @_;
     my $dbh = C4::Context->dbh;
-#save subscription (insert into database)
+
+    #save subscription (insert into database)
     my $query = qq|
         INSERT INTO subscription
             (librarian,branchcode,aqbooksellerid,cost,aqbudgetid,biblionumber,
@@ -1021,28 +1135,44 @@
             numberpattern, callnumber, hemisphere,manualhistory)
         VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
         |;
-    my $sth=$dbh->prepare($query);
+    my $sth = $dbh->prepare($query);
     $sth->execute(
-        $auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
-        format_date_in_iso($startdate),$periodicity,$dow,$numberlength,$weeklength,$monthlength,
-        $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
-        $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
-        $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
-        $numberingmethod, "$status", $notes, $letter,$firstacquidate,$irregularity,
-        $numberpattern, $callnumber, $hemisphere,$manualhistory);
+        $auser,                         $branchcode,
+        $aqbooksellerid,                $cost,
+        $aqbudgetid,                    $biblionumber,
+        format_date_in_iso($startdate), $periodicity,
+        $dow,                           $numberlength,
+        $weeklength,                    $monthlength,
+        $add1,                          $every1,
+        $whenmorethan1,                 $setto1,
+        $lastvalue1,                    $innerloop1,
+        $add2,                          $every2,
+        $whenmorethan2,                 $setto2,
+        $lastvalue2,                    $innerloop2,
+        $add3,                          $every3,
+        $whenmorethan3,                 $setto3,
+        $lastvalue3,                    $innerloop3,
+        $numberingmethod,               "$status",
+        $notes,                         $letter,
+        $firstacquidate,                $irregularity,
+        $numberpattern,                 $callnumber,
+        $hemisphere,                    $manualhistory
+    );
 
-#then create the 1st waited number
+    #then create the 1st waited number
     my $subscriptionid = $dbh->{'mysql_insertid'};
-    my $query = qq(
+    $query             = qq(
         INSERT INTO subscriptionhistory
             (biblionumber, subscriptionid, histstartdate, enddate, missinglist, recievedlist, opacnote, librariannote)
         VALUES (?,?,?,?,?,?,?,?)
         );
     $sth = $dbh->prepare($query);
-    $sth->execute($biblionumber, $subscriptionid, format_date_in_iso($startdate), 0, "", "", "", "$notes");
+    $sth->execute( $biblionumber, $subscriptionid,
+        format_date_in_iso($startdate),
+        0, "", "", "", "$notes" );
 
-# reread subscription to get a hash (for calculation of the 1st issue number)
-    my $query = qq(
+   # reread subscription to get a hash (for calculation of the 1st issue number)
+    $query = qq(
         SELECT *
         FROM   subscription
         WHERE  subscriptionid = ?
@@ -1051,19 +1181,22 @@
     $sth->execute($subscriptionid);
     my $val = $sth->fetchrow_hashref;
 
-# calculate issue number
+    # calculate issue number
     my $serialseq = GetSeq($val);
-    my $query = qq|
+    $query     = qq|
         INSERT INTO serial
             (serialseq,subscriptionid,biblionumber,status, planneddate, publisheddate)
         VALUES (?,?,?,?,?,?)
     |;
     $sth = $dbh->prepare($query);
-    $sth->execute("$serialseq", $subscriptionid, $biblionumber, 1, format_date_in_iso($startdate),format_date_in_iso($startdate));
+    $sth->execute(
+        "$serialseq", $subscriptionid, $biblionumber, 1,
+        format_date_in_iso($startdate),
+        format_date_in_iso($startdate)
+    );
     return $subscriptionid;
 }
 
-
 =head2 ReNewSubscription
 
 =over 4
@@ -1075,8 +1208,11 @@
 =back
 
 =cut
+
 sub ReNewSubscription {
-    my ($subscriptionid,$user,$startdate,$numberlength,$weeklength,$monthlength,$note) = @_;
+    my ( $subscriptionid, $user, $startdate, $numberlength, $weeklength,
+        $monthlength, $note )
+      = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
     my $query = qq|
@@ -1086,20 +1222,28 @@
         AND    biblio.biblionumber=?
     |;
     my $sth = $dbh->prepare($query);
-    $sth->execute($subscription->{biblionumber});
+    $sth->execute( $subscription->{biblionumber} );
     my $biblio = $sth->fetchrow_hashref;
-    NewSuggestion($user,$subscription->{bibliotitle},$biblio->{author},$biblio->{publishercode},$biblio->{note},'','','','','',$subscription->{biblionumber});
+    NewSuggestion(
+        $user,             $subscription->{bibliotitle},
+        $biblio->{author}, $biblio->{publishercode},
+        $biblio->{note},   '',
+        '',                '',
+        '',                '',
+        $subscription->{biblionumber}
+    );
+
     # renew subscription
-    my $query = qq|
+    $query = qq|
         UPDATE subscription
         SET    startdate=?,numberlength=?,weeklength=?,monthlength=?
         WHERE  subscriptionid=?
     |;
-    $sth=$dbh->prepare($query);
-    $sth->execute(format_date_in_iso($startdate),$numberlength,$weeklength,$monthlength, $subscriptionid);
+    $sth = $dbh->prepare($query);
+    $sth->execute( format_date_in_iso($startdate),
+        $numberlength, $weeklength, $monthlength, $subscriptionid );
 }
 
-
 =head2 NewIssue
 
 =over 4
@@ -1112,8 +1256,11 @@
 =back
 
 =cut
+
 sub NewIssue {
-    my ($serialseq,$subscriptionid,$biblionumber,$status, $publisheddate, $planneddate) = @_;
+    my ( $serialseq, $subscriptionid, $biblionumber, $status, $publisheddate,
+        $planneddate )
+      = @_;
     my $dbh = C4::Context->dbh;
     my $query = qq|
         INSERT INTO serial
@@ -1121,28 +1268,30 @@
         VALUES (?,?,?,?,?,?)
     |;
     my $sth = $dbh->prepare($query);
-    $sth->execute($serialseq,$subscriptionid,$biblionumber,$status,$publisheddate, $planneddate);
-    my $query = qq|
+    $sth->execute( $serialseq, $subscriptionid, $biblionumber, $status,
+        $publisheddate, $planneddate );
+    $query = qq|
         SELECT missinglist,recievedlist
         FROM   subscriptionhistory
         WHERE  subscriptionid=?
     |;
     $sth = $dbh->prepare($query);
     $sth->execute($subscriptionid);
-    my ($missinglist,$recievedlist) = $sth->fetchrow;
-    if ($status eq 2) {
+    my ( $missinglist, $recievedlist ) = $sth->fetchrow;
+
+    if ( $status eq 2 ) {
         $recievedlist .= ",$serialseq";
     }
-    if ($status eq 4) {
+    if ( $status eq 4 ) {
         $missinglist .= ",$serialseq";
     }
-    my $query = qq|
+    $query = qq|
         UPDATE subscriptionhistory
         SET    recievedlist=?, missinglist=?
         WHERE  subscriptionid=?
     |;
-    $sth=$dbh->prepare($query);
-    $sth->execute($recievedlist,$missinglist,$subscriptionid);
+    $sth = $dbh->prepare($query);
+    $sth->execute( $recievedlist, $missinglist, $subscriptionid );
 }
 
 =head2 ItemizeSerials
@@ -1159,150 +1308,188 @@
 =back
 
 =cut
+
 sub ItemizeSerials {
-    my ($serialid, $info) =@_;
+    my ( $serialid, $info ) = @_;
     my $now = ParseDate("today");
-    $now = UnixDate($now,"%Y-%m-%d");
+    $now = UnixDate( $now, "%Y-%m-%d" );
 
-    my $dbh= C4::Context->dbh;
+    my $dbh   = C4::Context->dbh;
     my $query = qq|
         SELECT *
         FROM   serial
         WHERE  serialid=?
     |;
-    my $sth=$dbh->prepare($query);
+    my $sth = $dbh->prepare($query);
     $sth->execute($serialid);
-    my $data=$sth->fetchrow_hashref;
-    if(C4::Context->preference("RoutingSerials")){
+    my $data = $sth->fetchrow_hashref;
+    if ( C4::Context->preference("RoutingSerials") ) {
+
         # check for existing biblioitem relating to serial issue
-	my($count, @results) = getbiblioitembybiblionumber($data->{'biblionumber'});
+        my ( $count, @results ) =
+          getbiblioitembybiblionumber( $data->{'biblionumber'} );
 	my $bibitemno = 0;
-	for(my $i=0;$i<$count;$i++){
-	    if($results[$i]->{'volumeddesc'} eq $data->{'serialseq'}.' ('.$data->{'planneddate'}.')'){
+        for ( my $i = 0 ; $i < $count ; $i++ ) {
+            if (  $results[$i]->{'volumeddesc'} eq $data->{'serialseq'} . ' ('
+                . $data->{'planneddate'}
+                . ')' )
+            {
 		$bibitemno = $results[$i]->{'biblioitemnumber'};
 		last;
 	    }
 	}
-	if($bibitemno == 0){
+        if ( $bibitemno == 0 ) {
+
 	    # warn "need to add new biblioitem so copy last one and make minor changes";
-	    my $sth=$dbh->prepare("SELECT * FROM biblioitems WHERE biblionumber = ? ORDER BY biblioitemnumber DESC");
-	    $sth->execute($data->{'biblionumber'});
-	    my $biblioitem;
+            my $sth =
+              $dbh->prepare(
+"SELECT * FROM biblioitems WHERE biblionumber = ? ORDER BY biblioitemnumber DESC"
+              );
+            $sth->execute( $data->{'biblionumber'} );
 	    my $biblioitem = $sth->fetchrow_hashref;
-	    $biblioitem->{'volumedate'} = format_date_in_iso($data->{planneddate});
-	    $biblioitem->{'volumeddesc'} = $data->{serialseq}.' ('.format_date($data->{'planneddate'}).')';
+            $biblioitem->{'volumedate'} =
+              format_date_in_iso( $data->{planneddate} );
+            $biblioitem->{'volumeddesc'} =
+              $data->{serialseq} . ' ('
+              . format_date( $data->{'planneddate'} ) . ')';
 	    $biblioitem->{'dewey'} = $info->{itemcallnumber};
-	    if ($info->{barcode}){ # only make biblioitem if we are going to make item also
+
+            if ( $info->{barcode} )
+            {    # only make biblioitem if we are going to make item also
 		$bibitemno = newbiblioitem($biblioitem);
 	    }
 	}
     }
 	
-    my $fwk=MARCfind_frameworkcode($dbh,$data->{'biblionumber'});
-    if ($info->{barcode}){
+    my $fwk = MARCfind_frameworkcode( $dbh, $data->{'biblionumber'} );
+    if ( $info->{barcode} ) {
         my @errors;
-        my $exists = itemdata($info->{'barcode'});
-        push @errors,"barcode_not_unique" if($exists);
-        unless ($exists){
+        my $exists = itemdata( $info->{'barcode'} );
+        push @errors, "barcode_not_unique" if ($exists);
+        unless ($exists) {
             my $marcrecord = MARC::Record->new();
-            my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.barcode",$fwk);
-            my $newField = MARC::Field->new(
-                "$tag",'','',
-                "$subfield" => $info->{barcode}
-            );
+            my ( $tag, $subfield ) =
+              MARCfind_marc_from_kohafield( $dbh, "items.barcode", $fwk );
+            my $newField =
+              MARC::Field->new( "$tag", '', '',
+                "$subfield" => $info->{barcode} );
             $marcrecord->insert_fields_ordered($newField);
-            if ($info->{branch}){
-                my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.homebranch",$fwk);
+            if ( $info->{branch} ) {
+                my ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.homebranch",
+                    $fwk );
+
                 #warn "items.homebranch : $tag , $subfield";
-                if ($marcrecord->field($tag)) {
-                    $marcrecord->field($tag)->add_subfields("$subfield" => $info->{branch})
-                } else {
-                    my $newField = MARC::Field->new(
-                        "$tag",'','',
-                        "$subfield" => $info->{branch}
-                    );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $info->{branch} );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '',
+                        "$subfield" => $info->{branch} );
                     $marcrecord->insert_fields_ordered($newField);
                 }
-                my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.holdingbranch",$fwk);
+                ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.holdingbranch",
+                    $fwk );
+
                 #warn "items.holdingbranch : $tag , $subfield";
-                if ($marcrecord->field($tag)) {
-                    $marcrecord->field($tag)->add_subfields("$subfield" => $info->{branch})
-                } else {
-                    my $newField = MARC::Field->new(
-                        "$tag",'','',
-                        "$subfield" => $info->{branch}
-                    );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $info->{branch} );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '',
+                        "$subfield" => $info->{branch} );
                     $marcrecord->insert_fields_ordered($newField);
                 }
             }
-            if ($info->{itemcallnumber}){
-                my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.itemcallnumber",$fwk);
+            if ( $info->{itemcallnumber} ) {
+                my ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.itemcallnumber",
+                    $fwk );
+
                 #warn "items.itemcallnumber : $tag , $subfield";
-                if ($marcrecord->field($tag)) {
-                    $marcrecord->field($tag)->add_subfields("$subfield" => $info->{itemcallnumber})
-                } else {
-                    my $newField = MARC::Field->new(
-                        "$tag",'','',
-                        "$subfield" => $info->{itemcallnumber}
-                    );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $info->{itemcallnumber} );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '',
+                        "$subfield" => $info->{itemcallnumber} );
                     $marcrecord->insert_fields_ordered($newField);
                 }
             }
-            if ($info->{notes}){
-                my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.itemnotes",$fwk);
+            if ( $info->{notes} ) {
+                my ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.itemnotes", $fwk );
+
                 # warn "items.itemnotes : $tag , $subfield";
-                if ($marcrecord->field($tag)) {
-                    $marcrecord->field($tag)->add_subfields("$subfield" => $info->{notes})
-                } else {
-                    my $newField = MARC::Field->new(
-                    "$tag",'','',
-                    "$subfield" => $info->{notes}
-                );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $info->{notes} );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '',
+                        "$subfield" => $info->{notes} );
                     $marcrecord->insert_fields_ordered($newField);
                 }
             }
-            if ($info->{location}){
-                my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.location",$fwk);
+            if ( $info->{location} ) {
+                my ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.location", $fwk );
+
                 # warn "items.location : $tag , $subfield";
-                if ($marcrecord->field($tag)) {
-                    $marcrecord->field($tag)->add_subfields("$subfield" => $info->{location})
-                } else {
-                    my $newField = MARC::Field->new(
-                        "$tag",'','',
-                        "$subfield" => $info->{location}
-                    );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $info->{location} );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '',
+                        "$subfield" => $info->{location} );
                     $marcrecord->insert_fields_ordered($newField);
                 }
             }
-            if ($info->{status}){
-                my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.notforloan",$fwk);
+            if ( $info->{status} ) {
+                my ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.notforloan",
+                    $fwk );
+
                 # warn "items.notforloan : $tag , $subfield";
-                if ($marcrecord->field($tag)) {
-                $marcrecord->field($tag)->add_subfields("$subfield" => $info->{status})
-                } else {
-                    my $newField = MARC::Field->new(
-                        "$tag",'','',
-                        "$subfield" => $info->{status}
-                    );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $info->{status} );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '',
+                        "$subfield" => $info->{status} );
                     $marcrecord->insert_fields_ordered($newField);
                 }
             }
-	    if(C4::Context->preference("RoutingSerials")){
-		my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.dateaccessioned",$fwk);
-		if ($marcrecord->field($tag)) {
-		    $marcrecord->field($tag)->add_subfields("$subfield" => $now)
-		} else {
-		    my $newField = MARC::Field->new(
-			"$tag",'','',
-			"$subfield" => $now
-		    );
+            if ( C4::Context->preference("RoutingSerials") ) {
+                my ( $tag, $subfield ) =
+                  MARCfind_marc_from_kohafield( $dbh, "items.dateaccessioned",
+                    $fwk );
+                if ( $marcrecord->field($tag) ) {
+                    $marcrecord->field($tag)
+                      ->add_subfields( "$subfield" => $now );
+                }
+                else {
+                    my $newField =
+                      MARC::Field->new( "$tag", '', '', "$subfield" => $now );
 		    $marcrecord->insert_fields_ordered($newField);
 		}
 	    }
-	    AddItem($dbh,$marcrecord,$data->{'biblionumber'});
+            AddItem( $dbh, $marcrecord, $data->{'biblionumber'} );
             return 1;
         }
-        return (0, at errors);
+        return ( 0, @errors );
     }
 }
 
@@ -1320,27 +1507,32 @@
 =back
 
 =cut
+
 sub HasSubscriptionExpired {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
-    # we don't do the same test if the subscription is based on X numbers or on X weeks/months
-    if ($subscription->{numberlength}) {
+
+# we don't do the same test if the subscription is based on X numbers or on X weeks/months
+    if ( $subscription->{numberlength} ) {
         my $query = qq|
             SELECT count(*)
             FROM   serial
             WHERE  subscriptionid=? AND planneddate>=?
         |;
         my $sth = $dbh->prepare($query);
-        $sth->execute($subscriptionid,$subscription->{startdate});
+        $sth->execute( $subscriptionid, $subscription->{startdate} );
         my $res = $sth->fetchrow;
-        if ($subscription->{numberlength}>=$res) {
+        if ( $subscription->{numberlength} >= $res ) {
             return 0;
-        } else {
+        }
+        else {
             return 1;
         }
-    } else {
-        #a little bit more tricky if based on X weeks/months : search if the latest issue waited is not after subscription startdate + duration
+    }
+    else {
+
+#a little bit more tricky if based on X weeks/months : search if the latest issue waited is not after subscription startdate + duration
         my $query = qq|
             SELECT max(planneddate)
             FROM   serial
@@ -1348,11 +1540,17 @@
         |;
         my $sth = $dbh->prepare($query);
         $sth->execute($subscriptionid);
-        my $res = ParseDate(format_date_in_iso($sth->fetchrow));
+        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 1 if ($res >= $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 1 if ( $res >= $endofsubscriptiondate );
         return 0;
     }
 }
@@ -1367,8 +1565,9 @@
 =back
 
 =cut
+
 sub SetDistributedto {
-    my ($distributedto,$subscriptionid) = @_;
+    my ( $distributedto, $subscriptionid ) = @_;
     my $dbh = C4::Context->dbh;
     my $query = qq|
         UPDATE subscription
@@ -1376,7 +1575,7 @@
         WHERE  subscriptionid=?
     |;
     my $sth = $dbh->prepare($query);
-    $sth->execute($distributedto,$subscriptionid);
+    $sth->execute( $distributedto, $subscriptionid );
 }
 
 =head2 DelSubscription
@@ -1389,12 +1588,14 @@
 =back
 
 =cut
+
 sub DelSubscription {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
-    $subscriptionid=$dbh->quote($subscriptionid);
+    $subscriptionid = $dbh->quote($subscriptionid);
     $dbh->do("DELETE FROM subscription WHERE subscriptionid=$subscriptionid");
-    $dbh->do("DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid");
+    $dbh->do(
+        "DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid");
     $dbh->do("DELETE FROM serial WHERE subscriptionid=$subscriptionid");
 }
 
@@ -1408,8 +1609,9 @@
 =back
 
 =cut
+
 sub DelIssue {
-    my ($serialseq,$subscriptionid) = @_;
+    my ( $serialseq, $subscriptionid ) = @_;
     my $dbh = C4::Context->dbh;
     my $query = qq|
         DELETE FROM serial
@@ -1417,25 +1619,28 @@
         AND         subscriptionid= ?
     |;
     my $mainsth = $dbh->prepare($query);
-    $mainsth->execute($serialseq,$subscriptionid);
+    $mainsth->execute( $serialseq, $subscriptionid );
     
     #Delete element from subscription history
-    my $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
+    $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
     my $sth = $dbh->prepare($query);
     $sth->execute($subscriptionid);
-    my $val=$sth->fetchrow_hashref;
-    unless ($val->{manualhistory}){
+    my $val = $sth->fetchrow_hashref;
+    unless ( $val->{manualhistory} ) {
       my $query = qq|
           SELECT * FROM subscriptionhistory
           WHERE       subscriptionid= ?
       |;
       my $sth = $dbh->prepare($query);
       $sth->execute($subscriptionid);
-      my $data=$sth->fetchrow_hashref;
-      $data->{'missinglist'}=~s/$serialseq//;
-      $data->{'recievedlist'}=~s/$serialseq//;
-      my $strsth = "UPDATE subscriptionhistory SET ".join(",",map{join("=",$_,$dbh->quote($data->{$_}))} keys %$data)." WHERE subscriptionid=?";
-      $sth=$dbh->prepare($strsth);
+        my $data = $sth->fetchrow_hashref;
+        $data->{'missinglist'}  =~ s/$serialseq//;
+        $data->{'recievedlist'} =~ s/$serialseq//;
+        my $strsth = "UPDATE subscriptionhistory SET "
+          . join( ",",
+            map { join( "=", $_, $dbh->quote( $data->{$_} ) ) } keys %$data )
+          . " WHERE subscriptionid=?";
+        $sth = $dbh->prepare($strsth);
       $sth->execute($subscriptionid);
     }
     return $mainsth->rows;
@@ -1457,47 +1662,57 @@
 =back
 
 =cut
+
 sub GetMissingIssues {
-    my ($supplierid,$serialid) = @_;
+    my ( $supplierid, $serialid ) = @_;
     my $dbh = C4::Context->dbh;
     my $sth;
-    my $byserial='';
-    if($serialid) {
-	$byserial = "and serialid = ".$serialid;
+    my $byserial = '';
+    if ($serialid) {
+        $byserial = "and serialid = " . $serialid;
     }
     if ($supplierid) {
-	$sth = $dbh->prepare("SELECT serialid,aqbooksellerid,name,title,planneddate,serialseq,serial.subscriptionid,claimdate
+        $sth = $dbh->prepare(
+"SELECT serialid,aqbooksellerid,name,title,planneddate,serialseq,serial.subscriptionid,claimdate
                                   FROM subscription, serial, biblio
                                   LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
                                   WHERE subscription.subscriptionid = serial.subscriptionid AND
                                   serial.STATUS = 4 and
                                   subscription.aqbooksellerid=$supplierid and
-                                  biblio.biblionumber = subscription.biblionumber ".$byserial." order by title
-                                  ");
-    } else {
-	$sth = $dbh->prepare("SELECT serialid,aqbooksellerid,name,title,planneddate,serialseq,serial.subscriptionid,claimdate
+                                  biblio.biblionumber = subscription.biblionumber "
+              . $byserial
+              . " order by title
+                                  "
+        );
+    }
+    else {
+        $sth = $dbh->prepare(
+"SELECT serialid,aqbooksellerid,name,title,planneddate,serialseq,serial.subscriptionid,claimdate
                                   FROM subscription, serial, biblio
                                   LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
                                   WHERE subscription.subscriptionid = serial.subscriptionid AND
                                   serial.STATUS =4 and
-                                  biblio.biblionumber = subscription.biblionumber ".$byserial." order by title
-                                  ");
+                                  biblio.biblionumber = subscription.biblionumber "
+              . $byserial
+              . " order by title
+                                  "
+        );
     }
     $sth->execute;
     my @issuelist;
     my $last_title;
-    my $odd=0;
-    my $count=0;
-    while (my $line = $sth->fetchrow_hashref) {
+    my $odd   = 0;
+    my $count = 0;
+    while ( my $line = $sth->fetchrow_hashref ) {
 	$odd++ unless $line->{title} eq $last_title;
-	$last_title = $line->{title} if ($line->{title});
-	$line->{planneddate} = format_date($line->{planneddate});
-	$line->{claimdate} = format_date($line->{claimdate});
-	$line->{'odd'} = 1 if $odd %2 ;
+        $last_title = $line->{title} if ( $line->{title} );
+        $line->{planneddate} = format_date( $line->{planneddate} );
+        $line->{claimdate}   = format_date( $line->{claimdate} );
+        $line->{'odd'} = 1 if $odd % 2;
 	$count++;
-	push @issuelist,$line;
+        push @issuelist, $line;
     }
-    return $count, at issuelist;
+    return $count, @issuelist;
 }
 
 =head2 removeMissingIssue
@@ -1514,25 +1729,32 @@
 =back
 
 =cut
+
 sub removeMissingIssue {
-    my ($sequence,$subscriptionid) = @_;
+    my ( $sequence, $subscriptionid ) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT * FROM subscriptionhistory WHERE subscriptionid = ?");
+    my $sth =
+      $dbh->prepare(
+        "SELECT * FROM subscriptionhistory WHERE subscriptionid = ?");
     $sth->execute($subscriptionid);
     my $data = $sth->fetchrow_hashref;
     my $missinglist = $data->{'missinglist'};
     my $missinglistbefore = $missinglist;
+
     # warn $missinglist." before";
     $missinglist =~ s/($sequence)//;
+
     # warn $missinglist." after";
-    if($missinglist ne $missinglistbefore){
+    if ( $missinglist ne $missinglistbefore ) {
 	$missinglist =~ s/\|\s\|/\|/g;
 	$missinglist =~ s/^\| //g;
 	$missinglist =~ s/\|$//g;
-	my $sth2= $dbh->prepare("UPDATE subscriptionhistory
+        my $sth2 = $dbh->prepare(
+            "UPDATE subscriptionhistory
                                        SET missinglist = ?
-                                       WHERE subscriptionid = ?");
-        $sth2->execute($missinglist,$subscriptionid);
+                                       WHERE subscriptionid = ?"
+        );
+        $sth2->execute( $missinglist, $subscriptionid );
     }
 }
 
@@ -1549,12 +1771,15 @@
 =back
 
 =cut
+
 sub updateClaim {
     my ($serialid) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("UPDATE serial SET claimdate = now()
+    my $sth        = $dbh->prepare(
+        "UPDATE serial SET claimdate = now()
                                    WHERE serialid = ?
-                                   ");
+                                   "
+    );
     $sth->execute($serialid);
 }
 
@@ -1572,14 +1797,17 @@
 =back
 
 =cut
+
 sub getsupplierbyserialid {
     my ($serialid) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT serialid, serial.subscriptionid, aqbooksellerid
+    my $sth        = $dbh->prepare(
+        "SELECT serialid, serial.subscriptionid, aqbooksellerid
                                    FROM serial, subscription
                                    WHERE serial.subscriptionid = subscription.subscriptionid
                                    AND serialid = ?
-                                   ");
+                                   "
+    );
     $sth->execute($serialid);
     my $line = $sth->fetchrow_hashref;
     my $result = $line->{'aqbooksellerid'};
@@ -1597,13 +1825,16 @@
 =back
 
 =cut
+
 sub check_routing {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT count(routingid) routingids FROM subscriptionroutinglist, subscription
+    my $sth              = $dbh->prepare(
+"SELECT count(routingid) routingids FROM subscriptionroutinglist, subscription
                               WHERE subscription.subscriptionid = subscriptionroutinglist.subscriptionid
                               AND subscription.subscriptionid = ? ORDER BY ranking ASC
-                              ");
+                              "
+    );
     $sth->execute($subscriptionid);
     my $line = $sth->fetchrow_hashref;
     my $result = $line->{'routingids'};
@@ -1623,21 +1854,29 @@
 =back
 
 =cut
+
 sub addroutingmember {
-    my ($borrowernumber,$subscriptionid) = @_;
+    my ( $borrowernumber, $subscriptionid ) = @_;
     my $rank;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?");
+    my $sth =
+      $dbh->prepare(
+"SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?"
+      );
     $sth->execute($subscriptionid);
-    while(my $line = $sth->fetchrow_hashref){
-	if($line->{'rank'}>0){
-	    $rank = $line->{'rank'}+1;
-	} else {
+    while ( my $line = $sth->fetchrow_hashref ) {
+        if ( $line->{'rank'} > 0 ) {
+            $rank = $line->{'rank'} + 1;
+        }
+        else {
 	    $rank = 1;
 	}
     }
-    $sth = $dbh->prepare("INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)");
-    $sth->execute($subscriptionid,$borrowernumber,$rank);
+    $sth =
+      $dbh->prepare(
+"INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)"
+      );
+    $sth->execute( $subscriptionid, $borrowernumber, $rank );
 }
 
 =head2 reorder_members
@@ -1657,32 +1896,44 @@
 =back
 
 =cut
+
 sub reorder_members {
-    my ($subscriptionid,$routingid,$rank) = @_;
+    my ( $subscriptionid, $routingid, $rank ) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC");
+    my $sth =
+      $dbh->prepare(
+"SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC"
+      );
     $sth->execute($subscriptionid);
     my @result;
-    while(my $line = $sth->fetchrow_hashref){
-	push(@result,$line->{'routingid'});
+    while ( my $line = $sth->fetchrow_hashref ) {
+        push( @result, $line->{'routingid'} );
     }
+
     # To find the matching index
     my $i;
     my $key = -1; # to allow for 0 being a valid response
-    for ($i = 0; $i < @result; $i++) {
-	if ($routingid == $result[$i]) {
+    for ( $i = 0 ; $i < @result ; $i++ ) {
+        if ( $routingid == $result[$i] ) {
 	    $key = $i; # save the index
 	    last;
 	}
     }
+
     # if index exists in array then move it to new position
-    if($key > -1 && $rank > 0){
-	my $new_rank = $rank-1; # $new_rank is what you want the new index to be in the array
-	my $moving_item = splice(@result, $key, 1);
-	splice(@result, $new_rank, 0, $moving_item);
-    }
-    for(my $j = 0; $j < @result; $j++){
-	my $sth = $dbh->prepare("UPDATE subscriptionroutinglist SET ranking = '" . ($j+1) . "' WHERE routingid = '". $result[$j]."'");
+    if ( $key > -1 && $rank > 0 ) {
+        my $new_rank = $rank -
+          1;    # $new_rank is what you want the new index to be in the array
+        my $moving_item = splice( @result, $key, 1 );
+        splice( @result, $new_rank, 0, $moving_item );
+    }
+    for ( my $j = 0 ; $j < @result ; $j++ ) {
+        my $sth =
+          $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '"
+              . ( $j + 1 )
+              . "' WHERE routingid = '"
+              . $result[$j]
+              . "'" );
 	$sth->execute;
     }
 }
@@ -1699,16 +1950,23 @@
 =back
 
 =cut
+
 sub delroutingmember {
-    # if $routingid exists then deletes that row otherwise deletes all with $subscriptionid
-    my ($routingid,$subscriptionid) = @_;
+
+# if $routingid exists then deletes that row otherwise deletes all with $subscriptionid
+    my ( $routingid, $subscriptionid ) = @_;
     my $dbh = C4::Context->dbh;
-    if($routingid){
-	my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?");
+    if ($routingid) {
+        my $sth =
+          $dbh->prepare(
+            "DELETE FROM subscriptionroutinglist WHERE routingid = ?");
 	$sth->execute($routingid);
-	reorder_members($subscriptionid,$routingid);
-    } else {
-	my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?");
+        reorder_members( $subscriptionid, $routingid );
+    }
+    else {
+        my $sth =
+          $dbh->prepare(
+            "DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?");
 	$sth->execute($subscriptionid);
     }
 }
@@ -1729,22 +1987,25 @@
 =back
 
 =cut
+
 sub getroutinglist {
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT routingid, borrowernumber,
+    my $sth              = $dbh->prepare(
+        "SELECT routingid, borrowernumber,
                               ranking, biblionumber FROM subscriptionroutinglist, subscription
                               WHERE subscription.subscriptionid = subscriptionroutinglist.subscriptionid
                               AND subscription.subscriptionid = ? ORDER BY ranking ASC
-                              ");
+                              "
+    );
     $sth->execute($subscriptionid);
     my @routinglist;
-    my $count=0;
-    while (my $line = $sth->fetchrow_hashref) {
+    my $count = 0;
+    while ( my $line = $sth->fetchrow_hashref ) {
 	$count++;
-	push(@routinglist,$line);
+        push( @routinglist, $line );
     }
-    return ($count, at routinglist);
+    return ( $count, @routinglist );
 }
 
 =head2 abouttoexpire
@@ -1766,41 +2027,60 @@
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
-    # we don't do the same test if the subscription is based on X numbers or on X weeks/months
-    if ($subscription->{numberlength}) {
-	my $sth = $dbh->prepare("select count(*) from serial where subscriptionid=?  and planneddate>=?");
-	$sth->execute($subscriptionid,$subscription->{startdate});
+
+# we don't do the same test if the subscription is based on X numbers or on X weeks/months
+    if ( $subscription->{numberlength} ) {
+        my $sth =
+          $dbh->prepare(
+"select count(*) from serial where subscriptionid=?  and planneddate>=?"
+          );
+        $sth->execute( $subscriptionid, $subscription->{startdate} );
 	my $res = $sth->fetchrow;
+
 	# warn "length: ".$subscription->{numberlength}." vs count: ".$res;
-	if ($subscription->{numberlength}==$res) {
+        if ( $subscription->{numberlength} == $res ) {
 	    return 1;
-	} else {
+        }
+        else {
 	    return 0;
 	}
-    } else {
-	# a little bit more tricky if based on X weeks/months : search if the latest issue waited is not after subscription startdate + duration
-	my $sth = $dbh->prepare("select max(planneddate) from serial where subscriptionid=?");
+    }
+    else {
+
+# a little bit more tricky if based on X weeks/months : search if the latest issue waited is not after subscription startdate + duration
+        my $sth =
+          $dbh->prepare(
+            "select max(planneddate) from serial where subscriptionid=?");
 	$sth->execute($subscriptionid);
-	my $res = ParseDate(format_date_in_iso($sth->fetchrow));
+        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});
+        $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} );
+
 	# warn "last: ".$endofsubscriptiondate." vs currentdate: ".$res;
 	my $per = $subscription->{'periodicity'};
 	my $x = 0;
-	if ($per == 1) { $x = '1 day'; }
-	if ($per == 2) { $x = '1 week'; }
-	if ($per == 3) { $x = '2 weeks'; }
-	if ($per == 4) { $x = '3 weeks'; }
-	if ($per == 5) { $x = '1 month'; }
-	if ($per == 6) { $x = '2 months'; }
-	if ($per == 7 || $per == 8) { $x = '3 months'; }
-	if ($per == 9) { $x = '6 months'; }
-	if ($per == 10) { $x = '1 year'; }
-	if ($per == 11) { $x = '2 years'; }
-	my $datebeforeend = DateCalc($endofsubscriptiondate,"- ".$x); # if ($subscription->{weeklength});
+        if ( $per == 1 ) { $x = '1 day'; }
+        if ( $per == 2 ) { $x = '1 week'; }
+        if ( $per == 3 ) { $x = '2 weeks'; }
+        if ( $per == 4 ) { $x = '3 weeks'; }
+        if ( $per == 5 ) { $x = '1 month'; }
+        if ( $per == 6 ) { $x = '2 months'; }
+        if ( $per == 7 || $per == 8 ) { $x = '3 months'; }
+        if ( $per == 9 )  { $x = '6 months'; }
+        if ( $per == 10 ) { $x = '1 year'; }
+        if ( $per == 11 ) { $x = '2 years'; }
+        my $datebeforeend =
+          DateCalc( $endofsubscriptiondate, "- " . $x )
+          ;    # if ($subscription->{weeklength});
 	# warn "DATE BEFORE END: $datebeforeend";
-	return 1 if ($res >= $datebeforeend && $res < $endofsubscriptiondate);
+        return 1 if ( $res >= $datebeforeend && $res < $endofsubscriptiondate );
 	return 0;
     }
 }
@@ -1832,16 +2112,24 @@
 =back
 
 =cut
+
 sub old_newsubscription {
-            my ($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
-		                $startdate,$periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
-		                $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
-		                $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
-		                $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
-		                $numberingmethod, $status, $callnumber, $notes, $hemisphere) = @_;
+    my (
+        $auser,         $aqbooksellerid,  $cost,          $aqbudgetid,
+        $biblionumber,  $startdate,       $periodicity,   $firstacquidate,
+        $dow,           $irregularity,    $numberpattern, $numberlength,
+        $weeklength,    $monthlength,     $add1,          $every1,
+        $whenmorethan1, $setto1,          $lastvalue1,    $add2,
+        $every2,        $whenmorethan2,   $setto2,        $lastvalue2,
+        $add3,          $every3,          $whenmorethan3, $setto3,
+        $lastvalue3,    $numberingmethod, $status,        $callnumber,
+        $notes,         $hemisphere
+    ) = @_;
             my $dbh = C4::Context->dbh;
+
             #save subscription
-            my $sth=$dbh->prepare("insert into subscription (librarian,aqbooksellerid,cost,aqbudgetid,biblionumber,
+    my $sth = $dbh->prepare(
+"insert into subscription (librarian,aqbooksellerid,cost,aqbudgetid,biblionumber,
 		                                                startdate,periodicity,firstacquidate,dow,irregularity,numberpattern,numberlength,weeklength,monthlength,
 		                                                        add1,every1,whenmorethan1,setto1,lastvalue1,
 		                                                        add2,every2,whenmorethan2,setto2,lastvalue2,
@@ -1849,28 +2137,57 @@
 		                                                        numberingmethod, status, callnumber, notes, hemisphere) values
                                                           (?,?,?,?,?,?,?,?,?,?,?,
 							                                                               ?,?,?,?,?,?,?,?,?,?,?,
-							                                                               ?,?,?,?,?,?,?,?,?,?,?,?)");
-        $sth->execute($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
-	    format_date_in_iso($startdate),$periodicity,format_date_in_iso($firstacquidate),$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
-	                                            $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
-	                                            $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
-	                                            $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
-	                                            $numberingmethod, $status,$callnumber, $notes, $hemisphere);
+							                                                               ?,?,?,?,?,?,?,?,?,?,?,?)"
+    );
+    $sth->execute(
+        $auser,         $aqbooksellerid,
+        $cost,          $aqbudgetid,
+        $biblionumber,  format_date_in_iso($startdate),
+        $periodicity,   format_date_in_iso($firstacquidate),
+        $dow,           $irregularity,
+        $numberpattern, $numberlength,
+        $weeklength,    $monthlength,
+        $add1,          $every1,
+        $whenmorethan1, $setto1,
+        $lastvalue1,    $add2,
+        $every2,        $whenmorethan2,
+        $setto2,        $lastvalue2,
+        $add3,          $every3,
+        $whenmorethan3, $setto3,
+        $lastvalue3,    $numberingmethod,
+        $status,        $callnumber,
+        $notes,         $hemisphere
+    );
+
         #then create the 1st waited number
         my $subscriptionid = $dbh->{'mysql_insertid'};
         my $enddate = GetSubscriptionExpirationDate($subscriptionid);
 
-        $sth = $dbh->prepare("insert into subscriptionhistory (biblionumber, subscriptionid, histstartdate, enddate, missinglist, recievedlist, opacnote, librariannote) values (?,?,?,?,?,?,?,?)");
-        $sth->execute($biblionumber, $subscriptionid, format_date_in_iso($startdate), format_date_in_iso($enddate), "", "", "", $notes);
+    $sth =
+      $dbh->prepare(
+"insert into subscriptionhistory (biblionumber, subscriptionid, histstartdate, enddate, missinglist, recievedlist, opacnote, librariannote) values (?,?,?,?,?,?,?,?)"
+      );
+    $sth->execute(
+        $biblionumber, $subscriptionid,
+        format_date_in_iso($startdate),
+        format_date_in_iso($enddate),
+        "", "", "", $notes
+    );
+
         # reread subscription to get a hash (for calculation of the 1st issue number)
-        $sth = $dbh->prepare("select * from subscription where subscriptionid = ? ");
+    $sth =
+      $dbh->prepare("select * from subscription where subscriptionid = ? ");
         $sth->execute($subscriptionid);
         my $val = $sth->fetchrow_hashref;
 
         # calculate issue number
         my $serialseq = GetSeq($val);
-        $sth = $dbh->prepare("insert into serial (serialseq,subscriptionid,biblionumber,status, planneddate) values (?,?,?,?,?)");
-        $sth->execute($serialseq, $subscriptionid, $val->{'biblionumber'}, 1, format_date_in_iso($startdate));
+    $sth =
+      $dbh->prepare(
+"insert into serial (serialseq,subscriptionid,biblionumber,status, planneddate) values (?,?,?,?,?)"
+      );
+    $sth->execute( $serialseq, $subscriptionid, $val->{'biblionumber'},
+        1, format_date_in_iso($startdate) );
         return $subscriptionid;
 }
 
@@ -1898,41 +2215,57 @@
 =back
 
 =cut
+
 sub old_modsubscription {
-            my ($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
-		                                        $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, $callnumber, $notes, $hemisphere, $subscriptionid)= @_;
+    my (
+        $auser,        $aqbooksellerid, $cost,           $aqbudgetid,
+        $startdate,    $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,   $callnumber,     $notes,
+        $hemisphere,   $subscriptionid
+    ) = @_;
             my $dbh = C4::Context->dbh;
-            my $sth=$dbh->prepare("update subscription set librarian=?, aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
+    my $sth = $dbh->prepare(
+"update subscription set librarian=?, aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
                                                    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=?, callnumber=?, notes=?, hemisphere=? where subscriptionid = ?");
-        $sth->execute($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
-	                                            $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, $callnumber, $notes, $hemisphere, $subscriptionid);
+                                                  numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, hemisphere=? where subscriptionid = ?"
+    );
+    $sth->execute(
+        $auser,        $aqbooksellerid, $cost,           $aqbudgetid,
+        $startdate,    $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,   $callnumber,     $notes,
+        $hemisphere,   $subscriptionid
+    );
         $sth->finish;
 
-
-        $sth = $dbh->prepare("select * from subscription where subscriptionid = ? ");
+    $sth =
+      $dbh->prepare("select * from subscription where subscriptionid = ? ");
         $sth->execute($subscriptionid);
         my $val = $sth->fetchrow_hashref;
 
         # calculate issue number
         my $serialseq = Get_Seq($val);
-        $sth = $dbh->prepare("UPDATE serial SET serialseq = ? WHERE subscriptionid = ?");
-        $sth->execute($serialseq,$subscriptionid);
+    $sth =
+      $dbh->prepare("UPDATE serial SET serialseq = ? WHERE subscriptionid = ?");
+    $sth->execute( $serialseq, $subscriptionid );
 
         my $enddate = subscriptionexpirationdate($subscriptionid);
         $sth = $dbh->prepare("update subscriptionhistory set enddate=?");
-        $sth->execute(format_date_in_iso($enddate));
+    $sth->execute( format_date_in_iso($enddate) );
 }
 
 =head2 old_getserials
@@ -1951,25 +2284,31 @@
 =back
 
 =cut
+
 sub old_getserials {
             my ($subscriptionid) = @_;
             my $dbh = C4::Context->dbh;
+
             # status = 2 is "arrived"
-            my $sth=$dbh->prepare("select serialid,serialseq, status, planneddate,notes,routingnotes from serial where subscriptionid = ? and status <>2 and status <>4 and status <>5");    
+    my $sth =
+      $dbh->prepare(
+"select serialid,serialseq, status, planneddate,notes,routingnotes from serial where subscriptionid = ? and status <>2 and status <>4 and status <>5"
+      );
           $sth->execute($subscriptionid);
         my @serials;
         my $num = 1;
-        while(my $line = $sth->fetchrow_hashref) {
-	                    $line->{"status".$line->{status}} = 1; # fills a "statusX" value, used for template status select list
-	                    $line->{"planneddate"} = format_date($line->{"planneddate"});
+    while ( my $line = $sth->fetchrow_hashref ) {
+        $line->{ "status" . $line->{status} } =
+          1;    # fills a "statusX" value, used for template status select list
+        $line->{"planneddate"} = format_date( $line->{"planneddate"} );
 	                    $line->{"num"} = $num;
 	                    $num++;
-	                    push @serials,$line;
+        push @serials, $line;
 	            }
-        $sth=$dbh->prepare("select count(*) from serial where subscriptionid=?");
+    $sth = $dbh->prepare("select count(*) from serial where subscriptionid=?");
         $sth->execute($subscriptionid);
         my ($totalissues) = $sth->fetchrow;
-        return ($totalissues, at serials);
+    return ( $totalissues, @serials );
 }
 
 =head2 GetNextDate
@@ -1991,116 +2330,136 @@
 =back
 
 =cut
+
 sub GetNextDate(@) {
-    my ($planneddate,$subscription) = @_;
-    my @irreg = split(/\|/,$subscription->{irregularity});
+    my ( $planneddate, $subscription ) = @_;
+    my @irreg = split( /\|/, $subscription->{irregularity} );
 
-    my ($year, $month, $day) = UnixDate($planneddate, "%Y", "%m", "%d");
-    my $dayofweek = Date_DayOfWeek($month,$day,$year);
+    my ( $year, $month, $day ) = UnixDate( $planneddate, "%Y", "%m", "%d" );
+    my $dayofweek = Date_DayOfWeek( $month, $day, $year );
     my $resultdate;
+
     #       warn "DOW $dayofweek";
-    if ($subscription->{periodicity} == 1) {
-	for(my $i=0;$i<@irreg;$i++){
-	    if($dayofweek == 7){ $dayofweek = 0; }
-	    if(in_array(($dayofweek+1), @irreg)){
-		$planneddate = DateCalc($planneddate,"1 day");
+    if ( $subscription->{periodicity} == 1 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $dayofweek == 7 ) { $dayofweek = 0; }
+            if ( in_array( ( $dayofweek + 1 ), @irreg ) ) {
+                $planneddate = DateCalc( $planneddate, "1 day" );
 		$dayofweek++;
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"1 day");
+        $resultdate = DateCalc( $planneddate, "1 day" );
     }
-    if ($subscription->{periodicity} == 2) {
-	my $wkno = Date_WeekOfYear($month,$day,$year,1);
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($wkno > 52) { $wkno = 0; } # need to rollover at January
-	    if($irreg[$i] == ($wkno+1)){
-		$planneddate = DateCalc($planneddate,"1 week");
+    if ( $subscription->{periodicity} == 2 ) {
+        my $wkno = Date_WeekOfYear( $month, $day, $year, 1 );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $wkno > 52 ) { $wkno = 0; }    # need to rollover at January
+            if ( $irreg[$i] == ( $wkno + 1 ) ) {
+                $planneddate = DateCalc( $planneddate, "1 week" );
 		$wkno++;
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"1 week");
+        $resultdate = DateCalc( $planneddate, "1 week" );
     }
-    if ($subscription->{periodicity} == 3) {
-	my $wkno = Date_WeekOfYear($month,$day,$year,1);
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($wkno > 52) { $wkno = 0; } # need to rollover at January
-	    if($irreg[$i] == ($wkno+1)){
-		$planneddate = DateCalc($planneddate,"2 weeks");
+    if ( $subscription->{periodicity} == 3 ) {
+        my $wkno = Date_WeekOfYear( $month, $day, $year, 1 );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $wkno > 52 ) { $wkno = 0; }    # need to rollover at January
+            if ( $irreg[$i] == ( $wkno + 1 ) ) {
+                $planneddate = DateCalc( $planneddate, "2 weeks" );
 		$wkno++;
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"2 weeks");
+        $resultdate = DateCalc( $planneddate, "2 weeks" );
     }
-    if ($subscription->{periodicity} == 4) {
-	my $wkno = Date_WeekOfYear($month,$day,$year,1);
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($wkno > 52) { $wkno = 0; } # need to rollover at January
-	    if($irreg[$i] == ($wkno+1)){
-		$planneddate = DateCalc($planneddate,"3 weeks");
+    if ( $subscription->{periodicity} == 4 ) {
+        my $wkno = Date_WeekOfYear( $month, $day, $year, 1 );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $wkno > 52 ) { $wkno = 0; }    # need to rollover at January
+            if ( $irreg[$i] == ( $wkno + 1 ) ) {
+                $planneddate = DateCalc( $planneddate, "3 weeks" );
 		$wkno++;
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"3 weeks");
+        $resultdate = DateCalc( $planneddate, "3 weeks" );
     }
-    if ($subscription->{periodicity} == 5) {
-	for(my $i = 0;$i < @irreg; $i++){
+    if ( $subscription->{periodicity} == 5 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+
 	    # warn $irreg[$i];
 	    # warn $month;
-	    if($month == 12) { $month = 0; } # need to rollover to check January
-	    if($irreg[$i] == ($month+1)){ # check next one to see if is to be skipped
-		$planneddate = DateCalc($planneddate,"1 month");
+            if ( $month == 12 ) {
+                $month = 0;
+            }    # need to rollover to check January
+            if ( $irreg[$i] == ( $month + 1 ) )
+            {    # check next one to see if is to be skipped
+                $planneddate = DateCalc( $planneddate, "1 month" );
 		$month++; # to check if following ones are to be skipped too
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"1 month");
+        $resultdate = DateCalc( $planneddate, "1 month" );
+
 	# warn "Planneddate2: $planneddate";
     }
-    if ($subscription->{periodicity} == 6) {
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($month == 12) { $month = 0; } # need to rollover to check January
-	    if($irreg[$i] == ($month+1)){ # check next one to see if is to be skipped
-		$planneddate = DateCalc($planneddate,"2 months");
+    if ( $subscription->{periodicity} == 6 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $month == 12 ) {
+                $month = 0;
+            }    # need to rollover to check January
+            if ( $irreg[$i] == ( $month + 1 ) )
+            {    # check next one to see if is to be skipped
+                $planneddate = DateCalc( $planneddate, "2 months" );
 		$month++; # to check if following ones are to be skipped too
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"2 months");
+        $resultdate = DateCalc( $planneddate, "2 months" );
     }
-    if ($subscription->{periodicity} == 7) {
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($month == 12) { $month = 0; } # need to rollover to check January
-	    if($irreg[$i] == ($month+1)){ # check next one to see if is to be skipped
-		$planneddate = DateCalc($planneddate,"3 months");
+    if ( $subscription->{periodicity} == 7 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $month == 12 ) {
+                $month = 0;
+            }    # need to rollover to check January
+            if ( $irreg[$i] == ( $month + 1 ) )
+            {    # check next one to see if is to be skipped
+                $planneddate = DateCalc( $planneddate, "3 months" );
 		$month++; # to check if following ones are to be skipped too
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"3 months");
+        $resultdate = DateCalc( $planneddate, "3 months" );
     }
-    if ($subscription->{periodicity} == 8) {
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($month == 12) { $month = 0; } # need to rollover to check January
-	    if($irreg[$i] == ($month+1)){ # check next one to see if is to be skipped
-		$planneddate = DateCalc($planneddate,"3 months");
+    if ( $subscription->{periodicity} == 8 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $month == 12 ) {
+                $month = 0;
+            }    # need to rollover to check January
+            if ( $irreg[$i] == ( $month + 1 ) )
+            {    # check next one to see if is to be skipped
+                $planneddate = DateCalc( $planneddate, "3 months" );
 		$month++; # to check if following ones are to be skipped too
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"3 months");
+        $resultdate = DateCalc( $planneddate, "3 months" );
     }
-    if ($subscription->{periodicity} == 9) {
-	for(my $i = 0;$i < @irreg; $i++){
-	    if($month == 12) { $month = 0; } # need to rollover to check January
-	    if($irreg[$i] == ($month+1)){ # check next one to see if is to be skipped
-		$planneddate = DateCalc($planneddate,"6 months");
+    if ( $subscription->{periodicity} == 9 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $month == 12 ) {
+                $month = 0;
+            }    # need to rollover to check January
+            if ( $irreg[$i] == ( $month + 1 ) )
+            {    # check next one to see if is to be skipped
+                $planneddate = DateCalc( $planneddate, "6 months" );
 		$month++; # to check if following ones are to be skipped too
 	    }
 	}
-	$resultdate=DateCalc($planneddate,"6 months");
+        $resultdate = DateCalc( $planneddate, "6 months" );
     }
-    if ($subscription->{periodicity} == 10) {
-	$resultdate=DateCalc($planneddate,"1 year");
+    if ( $subscription->{periodicity} == 10 ) {
+        $resultdate = DateCalc( $planneddate, "1 year" );
     }
-    if ($subscription->{periodicity} == 11) {
-	$resultdate=DateCalc($planneddate,"2 years");
+    if ( $subscription->{periodicity} == 11 ) {
+        $resultdate = DateCalc( $planneddate, "2 years" );
     }
+
     #    warn "date: ".$resultdate;
     return format_date_in_iso($resultdate);
 }





More information about the Koha-cvs mailing list