View | Details | Raw Unified | Return to bug 11708
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-8 / +28 lines)
Lines 476-482 sub CloseBasketgroup { Link Here
476
    my $dbh        = C4::Context->dbh;
476
    my $dbh        = C4::Context->dbh;
477
    my $sth = $dbh->prepare("
477
    my $sth = $dbh->prepare("
478
        UPDATE aqbasketgroups
478
        UPDATE aqbasketgroups
479
        SET    closed=1
479
        SET closeddate=CAST(NOW() AS DATE)
480
        WHERE  id=?
480
        WHERE  id=?
481
    ");
481
    ");
482
    $sth->execute($basketgroupno);
482
    $sth->execute($basketgroupno);
Lines 497-503 sub ReOpenBasketgroup { Link Here
497
    my $dbh        = C4::Context->dbh;
497
    my $dbh        = C4::Context->dbh;
498
    my $sth = $dbh->prepare("
498
    my $sth = $dbh->prepare("
499
        UPDATE aqbasketgroups
499
        UPDATE aqbasketgroups
500
        SET    closed=0
500
        SET    closeddate=NULL
501
        WHERE  id=?
501
        WHERE  id=?
502
    ");
502
    ");
503
    $sth->execute($basketgroupno);
503
    $sth->execute($basketgroupno);
Lines 926-932 $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr Link Here
926
926
927
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
927
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
928
928
929
$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
929
$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false.
930
930
931
=cut
931
=cut
932
932
Lines 935-950 sub NewBasketgroup { Link Here
935
    die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
935
    die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
936
    my $query = "INSERT INTO aqbasketgroups (";
936
    my $query = "INSERT INTO aqbasketgroups (";
937
    my @params;
937
    my @params;
938
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
938
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) {
939
        if ( defined $basketgroupinfo->{$field} ) {
939
        if ( defined $basketgroupinfo->{$field} ) {
940
            $query .= "$field, ";
940
            $query .= "$field, ";
941
            push(@params, $basketgroupinfo->{$field});
941
            push(@params, $basketgroupinfo->{$field});
942
        }
942
        }
943
    }
943
    }
944
945
    if ($basketgroupinfo->{closed}) {
946
        $query .= "closeddate, ";
947
    }
944
    $query .= "booksellerid) VALUES (";
948
    $query .= "booksellerid) VALUES (";
945
    foreach (@params) {
949
    foreach (@params) {
946
        $query .= "?, ";
950
        $query .= "?, ";
947
    }
951
    }
952
    if ($basketgroupinfo->{closed}) {
953
        $query .= "CAST(NOW() AS DATE), ";
954
    }
948
    $query .= "?)";
955
    $query .= "?)";
949
    push(@params, $basketgroupinfo->{'booksellerid'});
956
    push(@params, $basketgroupinfo->{'booksellerid'});
950
    my $dbh = C4::Context->dbh;
957
    my $dbh = C4::Context->dbh;
Lines 983-989 $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr Link Here
983
990
984
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
991
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
985
992
986
$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
993
$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false.
987
994
988
=cut
995
=cut
989
996
Lines 993-999 sub ModBasketgroup { Link Here
993
    my $dbh = C4::Context->dbh;
1000
    my $dbh = C4::Context->dbh;
994
    my $query = "UPDATE aqbasketgroups SET ";
1001
    my $query = "UPDATE aqbasketgroups SET ";
995
    my @params;
1002
    my @params;
996
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
1003
1004
    if ($basketgroupinfo->{closed}) {
1005
        $query .= "closeddate = IF(closeddate IS NULL, CAST(NOW() AS DATE), closeddate), ";
1006
    } elsif (defined $basketgroupinfo->{closed}) {
1007
        $query .= "closeddate = NULL, ";
1008
    }
1009
1010
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) {
997
        if ( defined $basketgroupinfo->{$field} ) {
1011
        if ( defined $basketgroupinfo->{$field} ) {
998
            $query .= "$field=?, ";
1012
            $query .= "$field=?, ";
999
            push(@params, $basketgroupinfo->{$field});
1013
            push(@params, $basketgroupinfo->{$field});
Lines 1066-1072 sub GetBasketgroup { Link Here
1066
        { Slice => {} },
1080
        { Slice => {} },
1067
        $basketgroupid
1081
        $basketgroupid
1068
    );
1082
    );
1069
    return $result_set->[0];    # id is unique
1083
    my $basketgroup = $result_set->[0];    # id is unique
1084
    $basketgroup->{closed} = defined($basketgroup->{closeddate}) ? 1 : 0;
1085
    return $basketgroup;
1070
}
1086
}
1071
1087
1072
#------------------------------------------------------------#
1088
#------------------------------------------------------------#
Lines 1086-1092 sub GetBasketgroups { Link Here
1086
    my $dbh = C4::Context->dbh;
1102
    my $dbh = C4::Context->dbh;
1087
    my $sth = $dbh->prepare($query);
1103
    my $sth = $dbh->prepare($query);
1088
    $sth->execute($booksellerid);
1104
    $sth->execute($booksellerid);
1089
    return $sth->fetchall_arrayref({});
1105
    my $basketgroups = $sth->fetchall_arrayref({});
1106
    foreach my $bg (@$basketgroups) {
1107
        $bg->{closed} = defined($bg->{closeddate}) ? 1 : 0;
1108
    }
1109
    return $basketgroups;
1090
}
1110
}
1091
1111
1092
#------------------------------------------------------------#
1112
#------------------------------------------------------------#
(-)a/installer/data/mysql/atomicupdate/bug_11708.perl (+25 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    unless (column_exists('aqbasketgroups', 'closeddate')) {
4
        $dbh->do(q{
5
            ALTER TABLE aqbasketgroups
6
            ADD COLUMN closeddate DATE DEFAULT NULL AFTER name
7
        });
8
    }
9
10
    if (column_exists('aqbasketgroups', 'closed')) {
11
        $dbh->do(q{
12
            UPDATE aqbasketgroups
13
            SET closeddate = CAST(NOW() AS DATE)
14
            WHERE closed = 1
15
              AND closeddate IS NULL
16
        });
17
        $dbh->do(q{
18
            ALTER TABLE aqbasketgroups
19
            DROP COLUMN closed
20
        });
21
    }
22
23
    SetVersion( $DBversion );
24
    print "Upgrade to $DBversion done (Bug 11708 - Change aqbasketgroups.closed to closeddate)\n";
25
}
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 2820-2826 DROP TABLE IF EXISTS `aqbasketgroups`; Link Here
2820
CREATE TABLE `aqbasketgroups` (
2820
CREATE TABLE `aqbasketgroups` (
2821
  `id` int(11) NOT NULL auto_increment,
2821
  `id` int(11) NOT NULL auto_increment,
2822
  `name` varchar(50) default NULL,
2822
  `name` varchar(50) default NULL,
2823
  `closed` tinyint(1) default NULL,
2823
  `closeddate` date default NULL,
2824
  `booksellerid` int(11) NOT NULL,
2824
  `booksellerid` int(11) NOT NULL,
2825
  `deliveryplace` varchar(10) default NULL,
2825
  `deliveryplace` varchar(10) default NULL,
2826
  `freedeliveryplace` MEDIUMTEXT default NULL,
2826
  `freedeliveryplace` MEDIUMTEXT default NULL,
(-)a/t/db_dependent/Acquisition/Basketgroups.t (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use DateTime;
6
7
use Koha::Database;
8
9
use C4::Context;
10
use C4::Acquisition;
11
12
use Test::More tests => 13;
13
14
use t::lib::TestBuilder;
15
16
my $schema = Koha::Database->new->schema;
17
$schema->storage->txn_begin;
18
19
my $builder = t::lib::TestBuilder->new;
20
21
my $bookseller = $builder->build_object({
22
    class => 'Koha::Acquisition::Booksellers',
23
    value => {
24
        name => 'Bookseller test 1',
25
    }
26
});
27
28
my $booksellerid = $bookseller->id;
29
my $basketgroupid = NewBasketgroup({
30
    booksellerid => $booksellerid,
31
    name => "Basketgroup test 1",
32
});
33
34
my $basketgroup = GetBasketgroup($basketgroupid);
35
ok(!$basketgroup->{closed}, "basket group is open");
36
ok(!defined($basketgroup->{closeddate}), "basket group closed date is empty");
37
38
CloseBasketgroup($basketgroupid);
39
$basketgroup = GetBasketgroup($basketgroupid);
40
ok($basketgroup->{closed}, "basket group is closed");
41
ok(defined($basketgroup->{closeddate}), "basket group closed date is not empty");
42
my $today = DateTime->now(time_zone => C4::Context->tz);
43
is($basketgroup->{closeddate}, $today->ymd, "basket group closed date is correct");
44
45
ReOpenBasketgroup($basketgroupid);
46
$basketgroup = GetBasketgroup($basketgroupid);
47
ok(!$basketgroup->{closed}, "basket group is open");
48
ok(!defined($basketgroup->{closeddate}), "basket group closed date is empty");
49
50
$basketgroup->{closed} = 1;
51
ModBasketgroup($basketgroup);
52
$basketgroup = GetBasketgroup($basketgroupid);
53
ok($basketgroup->{closed}, "basket group is closed");
54
ok(defined($basketgroup->{closeddate}), "basket group closed date is not empty");
55
is($basketgroup->{closeddate}, $today->ymd, "basket group closed date is correct");
56
57
$basketgroupid = NewBasketgroup({
58
    booksellerid => $booksellerid,
59
    name => "Basketgroup test 1",
60
    closed => 1,
61
});
62
$basketgroup = GetBasketgroup($basketgroupid);
63
ok($basketgroup->{closed}, "basket group is closed");
64
ok(defined($basketgroup->{closeddate}), "basket group closed date is not empty");
65
is($basketgroup->{closeddate}, $today->ymd, "basket group closed date is correct");
66
67
$schema->storage->txn_rollback();

Return to bug 11708