From 4a4dbbf1237c93e0233eef0600015c9be3320bf0 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Tue, 20 Oct 2015 14:19:35 +0100 Subject: [PATCH] Bug 15036: Do not overwrite complete status in basket ops Reopening or closing a basket should preserve the completed status for receipted orders. This patch excludes orderlines with the completed status from having their status rewritten as a result of the change in basket status Made the subroutines involved more efficient by removing an unnecessary loop and by not fetching a large amount of superfluous data Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Acquisition.pm | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 0f2b1612a8..4044556559 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -236,24 +236,11 @@ close a basket (becomes unmodifiable, except for receives) sub CloseBasket { my ($basketno) = @_; my $dbh = C4::Context->dbh; - my $query = " - UPDATE aqbasket - SET closedate=now() - WHERE basketno=? - "; - my $sth = $dbh->prepare($query); - $sth->execute($basketno); + $dbh->do('UPDATE aqbasket SET closedate=now() WHERE basketno=?', {}, $basketno ); - my @orders = GetOrders($basketno); - foreach my $order (@orders) { - $query = qq{ - UPDATE aqorders - SET orderstatus = 'ordered' - WHERE ordernumber = ?; - }; - $sth = $dbh->prepare($query); - $sth->execute($order->{'ordernumber'}); - } + $dbh->do( q{UPDATE aqorders SET orderstatus = 'ordered' WHERE basketno = ? AND orderstatus != 'complete'}, + {}, $basketno); + return; } =head3 ReopenBasket @@ -267,24 +254,15 @@ reopen a basket sub ReopenBasket { my ($basketno) = @_; my $dbh = C4::Context->dbh; - my $query = " - UPDATE aqbasket - SET closedate=NULL - WHERE basketno=? - "; - my $sth = $dbh->prepare($query); - $sth->execute($basketno); + $dbh->do( q{UPDATE aqbasket SET closedate=NULL WHERE basketno=?}, {}, $basketno ); - my @orders = GetOrders($basketno); - foreach my $order (@orders) { - $query = qq{ - UPDATE aqorders - SET orderstatus = 'new' - WHERE ordernumber = ?; - }; - $sth = $dbh->prepare($query); - $sth->execute($order->{'ordernumber'}); - } + $dbh->do( q{ + UPDATE aqorders + SET orderstatus = 'new' + WHERE basketno = ? + AND orderstatus != 'complete' + }, {}, $basketno); + return; } #------------------------------------------------------------# -- 2.39.5