/
GetHistory.pm
208 lines (149 loc) · 8.96 KB
/
GetHistory.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package KohaTest::Acquisition::GetHistory;
use base qw( KohaTest::Acquisition );
use strict;
use warnings;
use Test::More;
use C4::Acquisition;
use C4::Context;
use C4::Members;
use C4::Biblio;
use C4::Bookseller;
=head3 no_history
=cut
sub no_history : Test( 4 ) {
my $self = shift;
# my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory();
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 0, 'order_loop is empty' );
is( $total_qty, 0, 'total_qty' );
is( $total_price, 0, 'total_price' );
is( $total_qtyreceived, 0, 'total_qtyreceived' );
}
=head3 one_order
=cut
my $INVOICE = "1234-56 AB";
sub one_order : Test( 55 ) {
my $self = shift;
my ( $basketno, $ordernumber ) = $self->create_new_basket(invoice => $INVOICE);
ok( $basketno, "basketno is $basketno" );
ok( $ordernumber, "ordernumber is $ordernumber" );
# No arguments fetches no history.
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = eval { GetHistory() };
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( $order_loop, undef, 'order_loop is empty' );
}
my $bibliodata = GetBiblioData( $self->{'biblios'}[0] );
ok( $bibliodata->{'title'}, 'the biblio has a title' )
or diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
# searching by title should find it.
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( title => $bibliodata->{'title'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by title' );
is( $total_qty, 1, 'total_qty searched by title' );
is( $total_price, 1, 'total_price searched by title' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by title' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# searching by isbn
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( isbn => $bibliodata->{'isbn'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by isbn' );
is( $total_qty, 1, 'total_qty searched by isbn' );
is( $total_price, 1, 'total_price searched by isbn' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by isbn' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# searching by ean
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( ean => $bibliodata->{'ean'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by ean' );
is( $total_qty, 1, 'total_qty searched by ean' );
is( $total_price, 1, 'total_price searched by ean' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by ean' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# searching by basket number
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( basket => $basketno );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by basket no' );
is( $total_qty, 1, 'total_qty searched by basket no' );
is( $total_price, 1, 'total_price searched by basket no' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by basket no' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# searching by invoice number
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( booksellerinvoicenumber => $INVOICE );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by invoice no' );
is( $total_qty, 1, 'total_qty searched by invoice no' );
is( $total_price, 1, 'total_price searched by invoice no' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by invoice no' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# searching by author
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( author => $bibliodata->{'author'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by author' );
is( $total_qty, 1, 'total_qty searched by author' );
is( $total_price, 1, 'total_price searched by author' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by author' );
}
# searching by name
{
# diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
my $bookseller = GetBookSellerFromId( $self->{'booksellerid'} );
ok( $bookseller->{'name'}, 'bookseller name' )
or diag( Data::Dumper->Dump( [ $bookseller ], [ 'bookseller' ] ) );
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( name => $bookseller->{'name'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by name' );
is( $total_qty, 1, 'total_qty searched by name' );
is( $total_price, 1, 'total_price searched by name' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by name' );
}
# searching by from_date
{
my $tomorrow = $self->tomorrow();
# diag( "tomorrow is $tomorrow" );
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( to_placed_on => $tomorrow );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by to_date' );
is( $total_qty, 1, 'total_qty searched by to_date' );
is( $total_price, 1, 'total_price searched by to_date' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by to_date' );
}
# searching by from_date
{
my $yesterday = $self->yesterday();
# diag( "yesterday was $yesterday" );
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( from_placed_on => $yesterday );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by from_date' );
is( $total_qty, 1, 'total_qty searched by from_date' );
is( $total_price, 1, 'total_price searched by from_date' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by from_date' );
}
# set up some things necessary to make GetHistory use the IndependantBranches
$self->enable_independant_branches();
# just search by title here, we need to search by something.
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( title => $bibliodata->{'title'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by title' );
is( $total_qty, 1, 'total_qty searched by title' );
is( $total_price, 1, 'total_price searched by title' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by title' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# reset that.
$self->disable_independant_branches();
}
1;