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 924-930 $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr Link Here
924
924
925
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
925
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
926
926
927
$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
927
$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false.
928
928
929
=cut
929
=cut
930
930
Lines 933-948 sub NewBasketgroup { Link Here
933
    die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
933
    die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
934
    my $query = "INSERT INTO aqbasketgroups (";
934
    my $query = "INSERT INTO aqbasketgroups (";
935
    my @params;
935
    my @params;
936
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
936
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) {
937
        if ( defined $basketgroupinfo->{$field} ) {
937
        if ( defined $basketgroupinfo->{$field} ) {
938
            $query .= "$field, ";
938
            $query .= "$field, ";
939
            push(@params, $basketgroupinfo->{$field});
939
            push(@params, $basketgroupinfo->{$field});
940
        }
940
        }
941
    }
941
    }
942
943
    if ($basketgroupinfo->{closed}) {
944
        $query .= "closeddate, ";
945
    }
942
    $query .= "booksellerid) VALUES (";
946
    $query .= "booksellerid) VALUES (";
943
    foreach (@params) {
947
    foreach (@params) {
944
        $query .= "?, ";
948
        $query .= "?, ";
945
    }
949
    }
950
    if ($basketgroupinfo->{closed}) {
951
        $query .= "CAST(NOW() AS DATE), ";
952
    }
946
    $query .= "?)";
953
    $query .= "?)";
947
    push(@params, $basketgroupinfo->{'booksellerid'});
954
    push(@params, $basketgroupinfo->{'booksellerid'});
948
    my $dbh = C4::Context->dbh;
955
    my $dbh = C4::Context->dbh;
Lines 981-987 $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr Link Here
981
988
982
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
989
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
983
990
984
$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
991
$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false.
985
992
986
=cut
993
=cut
987
994
Lines 991-997 sub ModBasketgroup { Link Here
991
    my $dbh = C4::Context->dbh;
998
    my $dbh = C4::Context->dbh;
992
    my $query = "UPDATE aqbasketgroups SET ";
999
    my $query = "UPDATE aqbasketgroups SET ";
993
    my @params;
1000
    my @params;
994
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
1001
1002
    if ($basketgroupinfo->{closed}) {
1003
        $query .= "closeddate = IF(closeddate IS NULL, CAST(NOW() AS DATE), closeddate), ";
1004
    } elsif (defined $basketgroupinfo->{closed}) {
1005
        $query .= "closeddate = NULL, ";
1006
    }
1007
1008
    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) {
995
        if ( defined $basketgroupinfo->{$field} ) {
1009
        if ( defined $basketgroupinfo->{$field} ) {
996
            $query .= "$field=?, ";
1010
            $query .= "$field=?, ";
997
            push(@params, $basketgroupinfo->{$field});
1011
            push(@params, $basketgroupinfo->{$field});
Lines 1064-1070 sub GetBasketgroup { Link Here
1064
        { Slice => {} },
1078
        { Slice => {} },
1065
        $basketgroupid
1079
        $basketgroupid
1066
    );
1080
    );
1067
    return $result_set->[0];    # id is unique
1081
    my $basketgroup = $result_set->[0];    # id is unique
1082
    $basketgroup->{closed} = defined($basketgroup->{closeddate}) ? 1 : 0;
1083
    return $basketgroup;
1068
}
1084
}
1069
1085
1070
#------------------------------------------------------------#
1086
#------------------------------------------------------------#
Lines 1084-1090 sub GetBasketgroups { Link Here
1084
    my $dbh = C4::Context->dbh;
1100
    my $dbh = C4::Context->dbh;
1085
    my $sth = $dbh->prepare($query);
1101
    my $sth = $dbh->prepare($query);
1086
    $sth->execute($booksellerid);
1102
    $sth->execute($booksellerid);
1087
    return $sth->fetchall_arrayref({});
1103
    my $basketgroups = $sth->fetchall_arrayref({});
1104
    foreach my $bg (@$basketgroups) {
1105
        $bg->{closed} = defined($bg->{closeddate}) ? 1 : 0;
1106
    }
1107
    return $basketgroups;
1088
}
1108
}
1089
1109
1090
#------------------------------------------------------------#
1110
#------------------------------------------------------------#
(-)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 2810-2816 DROP TABLE IF EXISTS `aqbasketgroups`; Link Here
2810
CREATE TABLE `aqbasketgroups` (
2810
CREATE TABLE `aqbasketgroups` (
2811
  `id` int(11) NOT NULL auto_increment,
2811
  `id` int(11) NOT NULL auto_increment,
2812
  `name` varchar(50) default NULL,
2812
  `name` varchar(50) default NULL,
2813
  `closed` tinyint(1) default NULL,
2813
  `closeddate` date default NULL,
2814
  `booksellerid` int(11) NOT NULL,
2814
  `booksellerid` int(11) NOT NULL,
2815
  `deliveryplace` varchar(10) default NULL,
2815
  `deliveryplace` varchar(10) default NULL,
2816
  `freedeliveryplace` MEDIUMTEXT default NULL,
2816
  `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