From e73726e829d744f2a1e00dcf023159a70742c4ce Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 21 Feb 2014 09:19:09 -0500 Subject: [PATCH] Bug 11814 - Use constants to describe statuses Make the code a bit more understandable by using constants to define the status values and reference those. Adds self-documentation. --- C4/Serials.pm | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index bfbf21f..ec21e8a 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -33,6 +33,29 @@ use C4::Serials::Numberpattern; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); +# Define statuses +use constant { + EXPECTED => 1, + ARRIVED => 2, + LATE => 3, + MISSING => 4, + MISSING_NEVER_RECIEVED => 41, + MISSING_SOLD_OUT => 42, + MISSING_DAMAGED => 43, + MISSING_LOST => 44, + NOT_ISSUED => 5, + DELETED => 6, + CLAIMED => 7, + STOPPED => 8, +}; + +use constant MISSING_STATUSES => ( + MISSING, MISSING_NEVER_RECIEVED, + MISSING_SOLD_OUT, MISSING_DAMAGED, + MISSING_LOST +); + + BEGIN { $VERSION = 3.07.00.049; # set version for version checking require Exporter; @@ -94,6 +117,7 @@ the array is in name order sub GetSuppliersWithLateIssues { my $dbh = C4::Context->dbh; + my $statuses = join(',', ( LATE, MISSING_STATUSES ) ); my $query = qq| SELECT DISTINCT id, name FROM subscription @@ -102,7 +126,7 @@ sub GetSuppliersWithLateIssues { WHERE id > 0 AND ( (planneddate < now() AND serial.status=1) - OR serial.STATUS IN (3, 4, 41, 42, 43, 44) + OR serial.STATUS IN ( $statuses ) ) AND subscription.closed = 0 ORDER BY name|; @@ -425,7 +449,7 @@ sub PrepareSerialsData { } } $subs->{ "status" . $subs->{'status'} } = 1; - if ( grep { $_ == $subs->{status} } qw( 1 3 4 41 42 43 44 7 ) ) { + if ( grep { $_ == $subs->{status} } ( EXPECTED, LATE, MISSING_STATUSES, CLAIMED ) ) { $subs->{"checked"} = 1; } @@ -770,9 +794,10 @@ sub GetSerials { my $counter = 0; $count = 5 unless ($count); my @serials; + my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) ); my $query = "SELECT serialid,serialseq, status, publisheddate, planneddate,notes, routingnotes FROM serial - WHERE subscriptionid = ? AND status NOT IN (2, 4, 41, 42, 43, 44, 5) + WHERE subscriptionid = ? AND status NOT IN ( $statuses ) ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC"; my $sth = $dbh->prepare($query); $sth->execute($subscriptionid); @@ -793,7 +818,7 @@ sub GetSerials { $query = "SELECT serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes FROM serial WHERE subscriptionid = ? - AND (status in (2, 4, 41, 42, 43, 44, 5)) + AND status IN ( $statuses ) ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC "; $sth = $dbh->prepare($query); -- 1.7.10.4