Bug 11861: Add ISSN column in serials claims table
[koha.git] / C4 / Serials.pm
index da876e2..6c035d5 100644 (file)
@@ -102,7 +102,7 @@ sub GetSuppliersWithLateIssues {
     WHERE id > 0
         AND (
             (planneddate < now() AND serial.status=1)
-            OR serial.STATUS = 3 OR serial.STATUS = 4
+            OR serial.STATUS IN (3, 4, 41, 42, 43, 44)
         )
         AND subscription.closed = 0
     ORDER BY name|;
@@ -425,7 +425,9 @@ sub PrepareSerialsData {
             }
         }
         $subs->{ "status" . $subs->{'status'} } = 1;
-        $subs->{"checked"}                      = $subs->{'status'} =~ /1|3|4|7/;
+        if ( grep { $_ == $subs->{status} } qw( 1 3 4 41 42 43 44 7 ) ) {
+            $subs->{"checked"} = 1;
+        }
 
         if ( $subs->{'year'} && $subs->{'year'} ne "" ) {
             $year = $subs->{'year'};
@@ -628,13 +630,27 @@ sub GetSubscriptions {
 
 =head2 SearchSubscriptions
 
-@results = SearchSubscriptions($args);
-$args is a hashref. Its keys can be contained: title, issn, ean, publisher, bookseller and branchcode
+  @results = SearchSubscriptions($args);
 
-this function gets all subscriptions which have title like $title, ISSN like $issn, EAN like $ean, publisher like $publisher, bookseller like $bookseller AND branchcode eq $branch.
+This function returns a list of hashrefs, one for each subscription
+that meets the conditions specified by the $args hashref.
 
-return:
-a table of hashref. Each hash containt the subscription.
+The valid search fields are:
+
+  biblionumber
+  title
+  issn
+  ean
+  callnumber
+  location
+  publisher
+  bookseller
+  branch
+  expiration_date
+  closed
+
+The expiration_date search field is special; it specifies the maximum
+subscription expiration date.
 
 =cut
 
@@ -682,6 +698,10 @@ sub SearchSubscriptions {
         push @where_strs, "biblioitems.ean LIKE ?";
         push @where_args, "%$args->{ean}%";
     }
+    if ( $args->{callnumber} ) {
+        push @where_strs, "subscription.callnumber LIKE ?";
+        push @where_args, "%$args->{callnumber}%";
+    }
     if( $args->{publisher} ){
         push @where_strs, "biblioitems.publishercode LIKE ?";
         push @where_args, "%$args->{publisher}%";
@@ -694,6 +714,14 @@ sub SearchSubscriptions {
         push @where_strs, "subscription.branchcode = ?";
         push @where_args, "$args->{branch}";
     }
+    if ( $args->{location} ) {
+        push @where_strs, "subscription.location = ?";
+        push @where_args, "$args->{location}";
+    }
+    if ( $args->{expiration_date} ) {
+        push @where_strs, "subscription.enddate <= ?";
+        push @where_args, "$args->{expiration_date}";
+    }
     if( defined $args->{closed} ){
         push @where_strs, "subscription.closed = ?";
         push @where_args, "$args->{closed}";
@@ -711,8 +739,9 @@ sub SearchSubscriptions {
     for my $subscription ( @$results ) {
         $subscription->{cannotedit} = not can_edit_subscription( $subscription );
         $subscription->{cannotdisplay} =
-            ( C4::Context->preference("IndependentBranches")
-                and $subscription->{branchcode} ne C4::Context->userenv->{'branch'} ) ? 1 : 0;
+            ( C4::Context->preference("IndependentBranches") &&
+              C4::Context->userenv &&
+              $subscription->{branchcode} ne C4::Context->userenv->{'branch'} ) ? 1 : 0;
     }
 
     return @$results;
@@ -852,7 +881,7 @@ sub GetLatestSerials {
     my $strsth = "SELECT   serialid,serialseq, status, planneddate, publisheddate, notes
                         FROM     serial
                         WHERE    subscriptionid = ?
-                        AND      (status =2 or status=4)
+                        AND      status IN (2, 4, 41, 42, 43, 44)
                         ORDER BY publisheddate DESC LIMIT 0,$limit
                 ";
     my $sth = $dbh->prepare($strsth);
@@ -1221,8 +1250,11 @@ sub ModSerialStatus {
             if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) {
                   _update_receivedlist($subscriptionid);
             }
-            if($status == 4 || $status == 5
-              || ($oldstatus == 4 && $status != 4)
+            my @missing_statuses = qw( 4 41 42 43 44 );
+            if ( (  grep { $_ == $status } ( @missing_statuses, 5 ) )
+              || (
+                  ( grep { $_ == $oldstatus } @missing_statuses )
+                  && ! ( grep { $_ == $status } @missing_statuses ) )
               || ($oldstatus == 5 && $status != 5)) {
                 _update_missinglist($subscriptionid);
             }
@@ -1429,7 +1461,7 @@ $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbu
     $startdate,$periodicity,$numberlength,$weeklength,$monthlength,
     $lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3,
     $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern,
-    $callnumber, $hemisphere, $manualhistory, $internalnotes, $serialsadditems,
+    $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems,
     $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq);
 
 Create a new subscription with value given on input args.
@@ -1978,7 +2010,7 @@ name,title,planneddate,serialseq,serial.subscriptionid from tables : subscriptio
 sub GetLateOrMissingIssues {
     my ( $supplierid, $serialid, $order ) = @_;
 
-    return unless ($supplierid);
+    return unless ( $supplierid or $serialid );
 
     my $dbh = C4::Context->dbh;
     my $sth;
@@ -1995,15 +2027,16 @@ sub GetLateOrMissingIssues {
         $sth = $dbh->prepare(
             "SELECT
                 serialid,      aqbooksellerid,        name,
-                biblio.title,  planneddate,           serialseq,
+                biblio.title,  biblioitems.issn,      planneddate,    serialseq,
                 serial.status, serial.subscriptionid, claimdate,
                 subscription.branchcode
             FROM      serial 
                 LEFT JOIN subscription  ON serial.subscriptionid=subscription.subscriptionid 
                 LEFT JOIN biblio        ON subscription.biblionumber=biblio.biblionumber
+                LEFT JOIN biblioitems   ON subscription.biblionumber=biblioitems.biblionumber
                 LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
                 WHERE subscription.subscriptionid = serial.subscriptionid 
-                AND (serial.STATUS = 4 OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
+                AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
                 AND subscription.aqbooksellerid=$supplierid
                 $byserial
                 ORDER BY $order"
@@ -2020,7 +2053,7 @@ sub GetLateOrMissingIssues {
                 LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
                 LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
                 WHERE subscription.subscriptionid = serial.subscriptionid 
-                        AND (serial.STATUS = 4 OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
+                        AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
                 $byserial
                 ORDER BY $order"
         );
@@ -2810,7 +2843,7 @@ sub can_edit_subscription {
     $userid ||= C4::Context->userenv->{'id'};
     my $independent_branches = C4::Context->preference('IndependentBranches');
     return 1 unless $independent_branches;
-    if( $flags % 2 == 1 # superlibrarian
+    if( C4::Context->IsSuperLibrarian()
         or C4::Auth::haspermission( $userid, {serials => 'superserials'}),
         or C4::Auth::haspermission( $userid, {serials => 'edit_subscription'}),
         or not defined $subscription->{branchcode}