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

(-)a/C4/Serials/RoutingLists.pm (-2 / +15 lines)
Lines 49-62 this function create a new routing list for a subscription. Link Here
49
sub AddRoutingList {
49
sub AddRoutingList {
50
    my ($subscriptionid, $title) = @_;
50
    my ($subscriptionid, $title) = @_;
51
51
52
    return unless $subscriptionid and $title;
53
52
    my $dbh = C4::Context->dbh();
54
    my $dbh = C4::Context->dbh();
53
    my $query = qq{
55
    my $query = qq{
54
        INSERT INTO subscriptionroutinglist (subscriptionid, title)
56
        INSERT INTO subscriptionroutinglist (subscriptionid, title)
55
        VALUES (?, ?)
57
        VALUES (?, ?)
56
    };
58
    };
57
    my $sth = $dbh->prepare($query);
59
    my $sth = $dbh->prepare($query);
58
    $sth->execute($subscriptionid, $title);
60
    my $rv = $sth->execute($subscriptionid, $title);
59
61
62
    return unless $rv;
60
    return $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef);
63
    return $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef);
61
}
64
}
62
65
Lines 71-76 this function modifies a routing list. Link Here
71
sub ModRoutingList {
74
sub ModRoutingList {
72
    my ($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers) = @_;
75
    my ($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers) = @_;
73
76
77
    return unless $routinglistid;
78
74
    my $dbh = C4::Context->dbh;
79
    my $dbh = C4::Context->dbh;
75
    my $query = 'UPDATE subscriptionroutinglist';
80
    my $query = 'UPDATE subscriptionroutinglist';
76
    my @setstrings = ();
81
    my @setstrings = ();
Lines 127-132 this function delete a routing list. Link Here
127
sub DelRoutingList {
132
sub DelRoutingList {
128
    my ($routinglistid) = @_;
133
    my ($routinglistid) = @_;
129
134
135
    return unless $routinglistid;
136
130
    my $dbh = C4::Context->dbh;
137
    my $dbh = C4::Context->dbh;
131
    my $query = qq{
138
    my $query = qq{
132
        DELETE FROM subscriptionroutinglist
139
        DELETE FROM subscriptionroutinglist
Lines 150-155 to this routing list. Link Here
150
sub GetRoutingList {
157
sub GetRoutingList {
151
    my ($routinglistid) = @_;
158
    my ($routinglistid) = @_;
152
159
160
    return unless $routinglistid;
161
153
    my $dbh = C4::Context->dbh;
162
    my $dbh = C4::Context->dbh;
154
    my $query = qq{
163
    my $query = qq{
155
        SELECT *
164
        SELECT *
Lines 177-183 sub GetRoutingList { Link Here
177
186
178
=head2 GetRoutingLists
187
=head2 GetRoutingLists
179
188
180
$routinglists = &GetRoutingLists($subscriptionid);
189
@routinglists = &GetRoutingLists($subscriptionid);
181
190
182
this function get all routing lists for a subscription.
191
this function get all routing lists for a subscription.
183
192
Lines 186-191 this function get all routing lists for a subscription. Link Here
186
sub GetRoutingLists {
195
sub GetRoutingLists {
187
    my ($subscriptionid) = @_;
196
    my ($subscriptionid) = @_;
188
197
198
    return () unless $subscriptionid;
199
189
    my $dbh = C4::Context->dbh;
200
    my $dbh = C4::Context->dbh;
190
    my $query = qq{
201
    my $query = qq{
191
        SELECT routinglistid
202
        SELECT routinglistid
Lines 240-245 this function return the routing list as a CSV file. Link Here
240
sub GetRoutingListAsCSV {
251
sub GetRoutingListAsCSV {
241
    my ($routinglistid) = @_;
252
    my ($routinglistid) = @_;
242
253
254
    return unless $routinglistid;
255
243
    require C4::Biblio;
256
    require C4::Biblio;
244
    require C4::Serials;
257
    require C4::Serials;
245
    require C4::Members;
258
    require C4::Members;
(-)a/t/db_dependent/Serials.t (-1 / +40 lines)
Lines 14-21 use C4::Debug; Link Here
14
use C4::Bookseller;
14
use C4::Bookseller;
15
use C4::Biblio;
15
use C4::Biblio;
16
use C4::Budgets;
16
use C4::Budgets;
17
use C4::Items;
17
use Koha::DateUtils;
18
use Koha::DateUtils;
18
use Test::More tests => 43;
19
use Test::More tests => 45;
19
20
20
BEGIN {
21
BEGIN {
21
    use_ok('C4::Serials');
22
    use_ok('C4::Serials');
Lines 240-243 for my $am ( @arrived_missing ) { Link Here
240
}
241
}
241
is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" );
242
is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" );
242
243
244
subtest 'GetSerial' => sub {
245
    plan tests => 6;
246
247
    my $serial;
248
249
    $serial = GetSerial;
250
    ok(not (defined $serial), 'GetSerial() returns undef');
251
252
    $serial = GetSerial(-1);
253
    ok(not (defined $serial), 'GetSerial(-1) returns undef');
254
255
    my ($total_issues, @serials) = C4::Serials::GetSerials( $subscriptionid );
256
    $serial = GetSerial($serials[0]->{serialid});
257
    is($serial->{serialid}, $serials[0]->{serialid}, 'serialid is ok');
258
    is($serial->{serialseq}, $serials[0]->{serialseq}, 'serialseq is ok');
259
    is($serial->{status}, $serials[0]->{status}, 'status is ok');
260
    is($serial->{notes}, $serials[0]->{notes}, 'notes is ok');
261
};
262
263
subtest 'GetSerialItemnumber' => sub {
264
    plan tests => 3;
265
266
    my $itemnumber;
267
268
    $itemnumber = GetSerialItemnumber;
269
    ok(not (defined $itemnumber), 'GetSerialItemnumber() returns undef');
270
271
    $itemnumber = GetSerialItemnumber(-1);
272
    ok(not (defined $itemnumber), 'GetSerialItemnumber(-1) returns undef');
273
274
    my $item_itemnumber = C4::Items::AddItem({}, $biblionumber);
275
    my ($total_issues, @serials) = C4::Serials::GetSerials( $subscriptionid );
276
    AddItem2Serial($serials[0]->{serialid}, $item_itemnumber);
277
    $itemnumber = GetSerialItemnumber($serials[0]->{serialid});
278
    is($itemnumber, $item_itemnumber,
279
        'GetSerialItemnumber($serialid) returns itemnumber');
280
};
281
243
$dbh->rollback;
282
$dbh->rollback;
(-)a/t/db_dependent/Serials/RoutingLists.t (-1 / +240 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 7;
6
7
use C4::Serials;
8
use C4::Serials::RoutingLists;
9
10
use C4::Biblio;
11
use C4::Members;
12
13
use Koha::Database;
14
15
my $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
18
my $record = MARC::Record->new;
19
my $field = C4::Context->preference('marcflavour') eq 'UNIMARC'
20
    ? MARC::Field->new(200, '', '', a => 'Title')
21
    : MARC::Field->new(245, '', '', a => 'Title');
22
$record->append_fields($field);
23
my ($biblionumber) = AddBiblio($record, '');
24
25
my $subscriptionid = C4::Serials::NewSubscription(undef, '', (undef)x3,
26
    $biblionumber, '2015-04-23', (undef)x10, '', '', (undef)x6, 0, '', 0,
27
    undef, undef, 0, undef, undef, 0);
28
29
my $schema = Koha::Database->new->schema;
30
my $categorycode = $schema->resultset('Category')->search->first->categorycode;
31
my $branchcode = $schema->resultset('Branch')->search->first->branchcode;
32
33
my $borrowernumber1 = C4::Members::AddMember(
34
    surname => 'Doe',
35
    firstname => 'John',
36
    categorycode => $categorycode,
37
    branchcode => $branchcode,
38
);
39
my $borrowernumber2 = C4::Members::AddMember(
40
    surname => 'Smith',
41
    firstname => 'Jane',
42
    categorycode => $categorycode,
43
    branchcode => $branchcode,
44
);
45
46
subtest 'AddRoutingList' => sub {
47
    plan tests => 9;
48
49
    my $routinglistid;
50
51
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList;
52
    ok(not (defined $routinglistid),
53
        'AddRoutingList with bad parameters should return undef');
54
55
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList(-1);
56
    ok(not (defined $routinglistid),
57
        'AddRoutingList with bad parameters should return undef');
58
59
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid);
60
    ok(not (defined $routinglistid),
61
        'AddRoutingList with bad parameters should return undef');
62
63
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, '');
64
    ok(not (defined $routinglistid),
65
        'AddRoutingList with bad parameters should return undef');
66
67
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
68
    ok((defined $routinglistid),
69
        'AddRoutingList with good parameters should return an id');
70
71
    my $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
72
    is($routinglist->{routinglistid}, $routinglistid,
73
        'new routing list id is ok');
74
    is($routinglist->{subscriptionid}, $subscriptionid,
75
        'new routing list subscriptionid is ok');
76
    is($routinglist->{title},
77
        'Title', 'new routing list title is ok');
78
    ok(not (defined $routinglist->{notes}),
79
        'new routing list has not notes');
80
};
81
82
subtest 'ModRoutingList' => sub {
83
    plan tests => 5;
84
85
    my ($routinglist, $expected);
86
87
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
88
89
    C4::Serials::RoutingLists::ModRoutingList($routinglistid);
90
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
91
    $expected = {
92
        routinglistid => $routinglistid,
93
        subscriptionid => $subscriptionid,
94
        title => 'Title',
95
        notes => undef,
96
    };
97
    is_deeply($routinglist, $expected, 'routing list is as expected');
98
99
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, 'Title 2');
100
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
101
    $expected = {
102
        routinglistid => $routinglistid,
103
        subscriptionid => $subscriptionid,
104
        title => 'Title 2',
105
        notes => undef,
106
    };
107
    is_deeply($routinglist, $expected, 'routing list is as expected');
108
109
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef, 'notes');
110
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
111
    $expected = {
112
        routinglistid => $routinglistid,
113
        subscriptionid => $subscriptionid,
114
        title => 'Title 2',
115
        notes => 'notes',
116
    };
117
    is_deeply($routinglist, $expected, 'routing list is as expected');
118
119
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
120
        undef, $borrowernumber1, $borrowernumber2);
121
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
122
    $expected = {
123
        routinglistid => $routinglistid,
124
        subscriptionid => $subscriptionid,
125
        title => 'Title 2',
126
        notes => 'notes',
127
        borrowers => [$borrowernumber1, $borrowernumber2],
128
    };
129
    is_deeply($routinglist, $expected, 'routing list is as expected');
130
131
    C4::Serials::RoutingLists::ModRoutingList($routinglistid);
132
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
133
    $expected = {
134
        routinglistid => $routinglistid,
135
        subscriptionid => $subscriptionid,
136
        title => 'Title 2',
137
        notes => 'notes',
138
    };
139
    is_deeply($routinglist, $expected, 'routing list is as expected');
140
};
141
142
subtest 'DelRoutingList' => sub {
143
    plan tests => 1;
144
145
    my $routinglist;
146
147
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
148
    C4::Serials::RoutingLists::DelRoutingList($routinglistid);
149
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
150
    ok(not (defined $routinglist), 'routing list is deleted');
151
};
152
153
subtest 'GetRoutingList' => sub {
154
    plan tests => 3;
155
156
    my $routinglist;
157
158
    $routinglist = C4::Serials::RoutingLists::GetRoutingList;
159
    ok (not (defined $routinglist), 'GetRoutingList() returns undef');
160
161
    $routinglist = C4::Serials::RoutingLists::GetRoutingList(-1);
162
    ok (not (defined $routinglist), 'GetRoutingList(-1) returns undef');
163
164
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
165
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
166
    ok ((defined $routinglist), 'GetRoutingList($routinglistid) returns undef');
167
};
168
169
subtest 'GetRoutingLists' => sub {
170
    plan tests => 4;
171
172
    my (@routinglists, $routinglistid);
173
174
    # Remove routing lists from previous tests
175
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
176
    foreach my $routinglist (@routinglists) {
177
        C4::Serials::RoutingLists::DelRoutingList($routinglist->{routinglistid});
178
    }
179
180
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists;
181
    is(scalar @routinglists, 0, 'GetRoutingLists() returns an empty list');
182
183
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
184
    is(scalar @routinglists, 0,
185
        'GetRoutingLists($subscriptionid) returns an empty list');
186
187
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 1');
188
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
189
        undef, $borrowernumber1);
190
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 2');
191
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
192
        undef, $borrowernumber1);
193
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
194
    is(scalar @routinglists, 2,
195
        'GetRoutingLists($subscriptionid) returns all routing lists');
196
    is_deeply($routinglists[0]->{borrowers}, [$borrowernumber1],
197
        'GetRoutingLists returns borrower list for each routing list');
198
};
199
200
subtest 'GetRoutingListsCount' => sub {
201
    plan tests => 3;
202
203
    my $count;
204
205
    # Remove routing lists from previous tests
206
    my @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
207
    foreach my $routinglist (@routinglists) {
208
        C4::Serials::RoutingLists::DelRoutingList($routinglist->{routinglistid});
209
    }
210
211
    $count = C4::Serials::RoutingLists::GetRoutingListsCount;
212
    is($count, undef, 'GetRoutingListsCount() returns undef');
213
214
    $count = C4::Serials::RoutingLists::GetRoutingListsCount($subscriptionid);
215
    is($count, 0, 'GetRoutingListsCount($subscriptionid) returns 0');
216
217
    C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 1');
218
    C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 2');
219
    $count = C4::Serials::RoutingLists::GetRoutingListsCount($subscriptionid);
220
    is($count, 2, 'GetRoutingListsCount($subscriptionid) returns 2');
221
};
222
223
subtest 'GetRoutingListAsCSV' => sub {
224
    plan tests => 1;
225
226
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList(
227
        $subscriptionid, 'list 1');
228
229
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
230
        'notes', $borrowernumber1, $borrowernumber2);
231
232
    my $csv = C4::Serials::RoutingLists::GetRoutingListAsCSV($routinglistid);
233
    my $expected =
234
        q|"Subscription title","Routing list",Surname,Firstname,Notes| . "\n"
235
        . q|Title,"list 1",Doe,John,notes| . "\n"
236
        . q|Title,"list 1",Smith,Jane,notes| . "\n";
237
    is($csv, $expected, 'csv is as expected');
238
};
239
240
$dbh->rollback;

Return to bug 7957