Bug 4180: Fixes unclose TMPL_IF in supplier.tmpl
[koha_fer] / C4 / Serials.pm
index 8bfa659..d72e98c 100644 (file)
@@ -24,6 +24,7 @@ use POSIX qw(strftime);
 use C4::Suggestions;
 use C4::Koha;
 use C4::Biblio;
+use C4::Branch;
 use C4::Items;
 use C4::Search;
 use C4::Letters;
@@ -55,6 +56,7 @@ BEGIN {
       &reorder_members
       &check_routing &updateClaim &removeMissingIssue
       &CountIssues
+      HasItems
 
     );
 }
@@ -83,6 +85,8 @@ this function get all suppliers with late issues.
 
 return :
 the supplierlist into a hash. this hash containts id & name of the supplier
+Only valid suppliers are returned. Late subscriptions lacking a supplier are
+ignored.
 
 =back
 
@@ -103,6 +107,7 @@ sub GetSuppliersWithLateIssues {
     $sth->execute;
     my %supplierlist;
     while ( my ( $id, $name ) = $sth->fetchrow ) {
+        next if !defined $id;
         $supplierlist{$id} = $name;
     }
     return %supplierlist;
@@ -457,6 +462,7 @@ sub PrepareSerialsData {
             ? format_date( $subs->{'publisheddate'} )
             : "XXX"
         );
+        $subs->{'branchname'} = GetBranchName( $subs->{'branchcode'} );
         $subs->{'planneddate'}                  = format_date( $subs->{'planneddate'} );
         $subs->{ "status" . $subs->{'status'} } = 1;
         $subs->{"checked"}                      = $subs->{'status'} =~ /1|3|4|7/;
@@ -1128,7 +1134,7 @@ sub ModSerialStatus {
             $missinglist .= "; $serialseq"
               if ( $status eq 4
                 and not index( "$missinglist", "$serialseq" ) >= 0 );
-            $missinglist .= "; not issued $serialseq"
+            $missinglist .= "; $serialseq"
               if ( $status eq 5
                 and index( "$missinglist", "$serialseq" ) >= 0 );
             $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
@@ -2237,6 +2243,32 @@ sub CountIssues {
     return $countreceived;
 }
 
+=head2 HasItems
+
+=over 4
+
+$result = &HasItems($subscriptionid)
+
+
+=back
+
+=cut
+
+sub HasItems {
+    my ($subscriptionid) = @_;
+    my $dbh              = C4::Context->dbh;
+    my $query = qq|
+            SELECT COUNT(serialitems.itemnumber)
+            FROM   serial 
+                       LEFT JOIN serialitems USING(serialid)
+            WHERE  subscriptionid=? AND serialitems.serialid NOT NULL
+        |;
+    my $sth=$dbh->prepare($query);
+    $sth->execute($subscriptionid);
+    my ($countitems)=$sth->fetchrow;
+    return $countitems;  
+}
+
 =head2 abouttoexpire
 
 =over 4