From eaef80806580224e19eaa886e5802778e4a3ae1c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 22 Apr 2013 13:35:24 +0200 Subject: [PATCH] Bug 10092 Followup for NewIssue Same logic for new issue. Moves the shared code to a local subroutine. Test plan: Add an issue via Generate Next button. No changes to missing and received. Now add an issue via Edit Serials and Supplemental issue with status Arrived. Check the received list. Now add supplemental issue with status Missing or Not available. Check the missing list. Signed-off-by: Koha Team Amu --- C4/Serials.pm | 65 +++++++++++++++++++++++++------------------------------- 1 files changed, 29 insertions(+), 36 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index c012d80..abaea81 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1130,31 +1130,9 @@ sub ModSerialStatus { $query = "SELECT missinglist,recievedlist FROM subscriptionhistory WHERE subscriptionid=?"; $sth = $dbh->prepare($query); $sth->execute($subscriptionid); - my ( $missinglist, $recievedlist ) = $sth->fetchrow; - - #Arrived: add to received list, remove from missing - if($status==2) { - $recievedlist .= "; $serialseq" - if $recievedlist!~/(^|;)\s*$serialseq(?=;|$)/; - $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g; - } - #Expected,late,claimed: remove optionally from received+missing - if (grep /$status/, (1,3,7)) { - $recievedlist=~ s/(^|;)\s*$serialseq(?=;|$)//g; - $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g; - } - #Missing, not available: add to missing, remove from received - #No longer putting additional text into missing field - if($status==4 || $status==5) { - $missinglist .= "; $serialseq" - if $missinglist!~/(^|;)\s*$serialseq(?=;|$)/; - $recievedlist=~ s/(^|;)\s*$serialseq(?=;|$)//g; - } - + my ($missinglist, $recievedlist)= _update_missing_and_received_list($sth->fetchrow,$serialseq,$status); $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE subscriptionid=?"; $sth = $dbh->prepare($query); - $recievedlist =~ s/^; //; - $missinglist =~ s/^; //; $sth->execute( $recievedlist, $missinglist, $subscriptionid ); } } @@ -1189,6 +1167,32 @@ sub ModSerialStatus { return; } +sub _update_missing_and_received_list { + my ($missinglist, $recievedlist, $serialseq, $status)=@_; + + #Arrived: add to received list, remove from missing + if($status==2) { + $recievedlist .= "; $serialseq" + if $recievedlist!~/(^|;)\s*$serialseq(?=;|$)/; + $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g; + } + #Expected,late,claimed: remove optionally from received+missing + if (grep /$status/, (1,3,7)) { + $recievedlist=~ s/(^|;)\s*$serialseq(?=;|$)//g; + $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g; + } + #Missing, not available: add to missing, remove from received + #No longer putting additional text into missing field + if($status==4 || $status==5) { + $missinglist .= "; $serialseq" + if $missinglist!~/(^|;)\s*$serialseq(?=;|$)/; + $recievedlist=~ s/(^|;)\s*$serialseq(?=;|$)//g; + } + $missinglist =~ s/^; //; + $recievedlist =~ s/^; //; + return ($missinglist, $recievedlist); +} + =head2 GetNextExpected $nextexpected = GetNextExpected($subscriptionid) @@ -1503,25 +1507,14 @@ sub NewIssue { |; $sth = $dbh->prepare($query); $sth->execute($subscriptionid); - my ( $missinglist, $recievedlist ) = $sth->fetchrow; - - if ( $status == 2 ) { - ### TODO Add a feature that improves recognition and description. - ### As such count (serialseq) i.e. : N18,2(N19),N20 - ### Would use substr and index But be careful to previous presence of () - $recievedlist .= "; $serialseq" unless (index($recievedlist,$serialseq)>0); - } - if ( $status == 4 ) { - $missinglist .= "; $serialseq" unless (index($missinglist,$serialseq)>0); - } + my ($missinglist, $recievedlist)= _update_missing_and_received_list( + $sth->fetchrow, $serialseq, $status); $query = qq| UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE subscriptionid=? |; $sth = $dbh->prepare($query); - $recievedlist =~ s/^; //; - $missinglist =~ s/^; //; $sth->execute( $recievedlist, $missinglist, $subscriptionid ); return $serialid; } -- 1.7.2.5