@@ -, +, @@ --- C4/Acquisition.pm | 25 +++++++++++++++---------- installer/data/mysql/updatedatabase.pl | 11 ++++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -425,8 +425,7 @@ sub CloseBasketgroup { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare(" UPDATE aqbasketgroups - SET closed=1, - closeddate=CAST(NOW() AS DATE) + SET closeddate=CAST(NOW() AS DATE) WHERE id=? "); $sth->execute($basketgroupno); @@ -447,7 +446,7 @@ sub ReOpenBasketgroup { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare(" UPDATE aqbasketgroups - SET closed=0, closeddate=NULL + SET closeddate=NULL WHERE id=? "); $sth->execute($basketgroupno); @@ -864,7 +863,7 @@ $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table, -$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise. +$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false. =cut @@ -873,7 +872,7 @@ sub NewBasketgroup { die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'}; my $query = "INSERT INTO aqbasketgroups ("; my @params; - foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) { + foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) { if ( defined $basketgroupinfo->{$field} ) { $query .= "$field, "; push(@params, $basketgroupinfo->{$field}); @@ -928,7 +927,7 @@ $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table, -$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise. +$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false. =cut @@ -940,12 +939,12 @@ sub ModBasketgroup { my @params; if ($basketgroupinfo->{closed}) { - $query .= "closeddate = IF(closed = 0, CAST(NOW() AS DATE), closeddate), "; + $query .= "closeddate = IF(closeddate IS NULL, CAST(NOW() AS DATE), closeddate), "; } elsif (defined $basketgroupinfo->{closed}) { $query .= "closeddate = NULL, "; } - foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) { + foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) { if ( defined $basketgroupinfo->{$field} ) { $query .= "$field=?, "; push(@params, $basketgroupinfo->{$field}); @@ -1018,7 +1017,9 @@ sub GetBasketgroup { { Slice => {} }, $basketgroupid ); - return $result_set->[0]; # id is unique + my $basketgroup = $result_set->[0]; # id is unique + $basketgroup->{closed} = defined($basketgroup->{closeddate}) ? 1 : 0; + return $basketgroup; } #------------------------------------------------------------# @@ -1038,7 +1039,11 @@ sub GetBasketgroups { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare($query); $sth->execute($booksellerid); - return $sth->fetchall_arrayref({}); + my $basketgroups = $sth->fetchall_arrayref({}); + foreach my $bg (@$basketgroups) { + $bg->{closed} = defined($bg->{closeddate}) ? 1 : 0; + } + return $basketgroups; } #------------------------------------------------------------# --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -9779,7 +9779,16 @@ if (CheckVersion($DBversion)) { ALTER TABLE aqbasketgroups ADD COLUMN closeddate DATE DEFAULT NULL AFTER closed |); - print "Upgrade to $DBversion done (Bug 11708: Add aqbasketgroups.closeddate)\n"; + $dbh->do(q| + UPDATE aqbasketgroups + SET closeddate = CAST(NOW() AS DATE) + WHERE closed = 1 + |); + $dbh->do(q| + ALTER TABLE aqbasketgroups + DROP COLUMN closed + |); + print "Upgrade to $DBversion done (Bug 11708: Add aqbasketgroups.closeddate and remove aqbasketgroups.closed)\n"; SetVersion($DBversion); } --