|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use Test::More tests => 65; |
| 6 |
use C4::Context; |
| 7 |
use Koha::DateUtils; |
| 8 |
use DateTime::Duration; |
| 9 |
use C4::Acquisition; |
| 10 |
use C4::Serials; |
| 11 |
use C4::Budgets; |
| 12 |
use C4::Biblio; |
| 13 |
|
| 14 |
BEGIN { |
| 15 |
use_ok('C4::Bookseller'); |
| 16 |
} |
| 17 |
|
| 18 |
can_ok( |
| 19 |
|
| 20 |
'C4::Bookseller', qw( |
| 21 |
AddBookseller |
| 22 |
DelBookseller |
| 23 |
GetBookSeller |
| 24 |
GetBookSellerFromId |
| 25 |
GetBooksellersWithLateOrders |
| 26 |
ModBookseller ) |
| 27 |
); |
| 28 |
|
| 29 |
#Start transaction |
| 30 |
my $dbh = C4::Context->dbh; |
| 31 |
$dbh->{RaiseError} = 1; |
| 32 |
$dbh->{AutoCommit} = 0; |
| 33 |
|
| 34 |
#Start tests |
| 35 |
$dbh->do(q|DELETE FROM aqorders|); |
| 36 |
$dbh->do(q|DELETE FROM aqbasket|); |
| 37 |
$dbh->do(q|DELETE FROM aqbooksellers|); |
| 38 |
#Test AddBookseller |
| 39 |
my $count = scalar( C4::Bookseller::GetBookSeller('') ); |
| 40 |
my $sample_supplier1 = { |
| 41 |
name => 'Name1', |
| 42 |
address1 => 'address1_1', |
| 43 |
address2 => 'address1-2', |
| 44 |
address3 => 'address1_2', |
| 45 |
address4 => 'address1_2', |
| 46 |
postal => 'postal1', |
| 47 |
phone => 'phone1', |
| 48 |
accountnumber => 'accountnumber1', |
| 49 |
fax => 'fax1', |
| 50 |
url => 'url1', |
| 51 |
contact => 'contact1', |
| 52 |
contpos => 'contpos1', |
| 53 |
contphone => 'contphone1', |
| 54 |
contfax => 'contefax1', |
| 55 |
contaltphone => 'contaltphone1', |
| 56 |
contemail => 'contemail1', |
| 57 |
contnotes => 'contnotes1', |
| 58 |
active => 1, |
| 59 |
gstreg => 1, |
| 60 |
listincgst => 1, |
| 61 |
invoiceincgst => 1, |
| 62 |
gstrate => '1.0000', |
| 63 |
discount => '1.0000', |
| 64 |
notes => 'notes1', |
| 65 |
deliverytime => undef |
| 66 |
}; |
| 67 |
my $sample_supplier2 = { |
| 68 |
name => 'Name2', |
| 69 |
address1 => 'address1_2', |
| 70 |
address2 => 'address2-2', |
| 71 |
address3 => 'address3_2', |
| 72 |
address4 => 'address4_2', |
| 73 |
postal => 'postal2', |
| 74 |
phone => 'phone2', |
| 75 |
accountnumber => 'accountnumber2', |
| 76 |
fax => 'fax2', |
| 77 |
url => 'url2', |
| 78 |
contact => 'contact2', |
| 79 |
contpos => 'contpos2', |
| 80 |
contphone => 'contphone2', |
| 81 |
contfax => 'contefax2', |
| 82 |
contaltphone => 'contaltphone2', |
| 83 |
contemail => 'contemail2', |
| 84 |
contnotes => 'contnotes2', |
| 85 |
active => 1, |
| 86 |
gstreg => 1, |
| 87 |
listincgst => 1, |
| 88 |
invoiceincgst => 1, |
| 89 |
gstrate => '2.0000', |
| 90 |
discount => '2.0000', |
| 91 |
notes => 'notes2', |
| 92 |
deliverytime => 2, |
| 93 |
}; |
| 94 |
|
| 95 |
my $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); |
| 96 |
my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2); |
| 97 |
|
| 98 |
#my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null |
| 99 |
|
| 100 |
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); |
| 101 |
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); |
| 102 |
is( scalar( C4::Bookseller::GetBookSeller('') ), |
| 103 |
$count + 2, "Supplier1 and Supplier2 have been added" ); |
| 104 |
|
| 105 |
#Test DelBookseller |
| 106 |
my $del = C4::Bookseller::DelBookseller($id_supplier1); |
| 107 |
is( $del, 1, "DelBookseller returns 1" ); |
| 108 |
is( C4::Bookseller::GetBookSellerFromId($id_supplier1), |
| 109 |
undef, "Supplier1 has been deleted - id_supplier1 doesnt exist anymore" ); |
| 110 |
|
| 111 |
#Test GetBookSeller |
| 112 |
my @bookseller2 = C4::Bookseller::GetBookSeller( $sample_supplier2->{name} ); |
| 113 |
is( scalar(@bookseller2), 1, "Get only Supplier2" ); |
| 114 |
$bookseller2[0] = field_filter( $bookseller2[0] ); |
| 115 |
delete $bookseller2[0]->{basketcount}; |
| 116 |
|
| 117 |
$sample_supplier2->{id} = $id_supplier2; |
| 118 |
is_deeply( $bookseller2[0], $sample_supplier2, |
| 119 |
"GetBookSeller returns the right informations about $sample_supplier2" ); |
| 120 |
|
| 121 |
$id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); |
| 122 |
my @booksellers = C4::Bookseller::GetBookSeller('') |
| 123 |
; #NOTE :without params, it returns all the booksellers |
| 124 |
for my $i ( 0 .. scalar(@booksellers) - 1 ) { |
| 125 |
$booksellers[$i] = field_filter( $booksellers[$i] ); |
| 126 |
delete $booksellers[$i]->{basketcount}; |
| 127 |
} |
| 128 |
|
| 129 |
$sample_supplier1->{id} = $id_supplier1; |
| 130 |
is( scalar(@booksellers), $count + 2, "Get Supplier1 and Supplier2" ); |
| 131 |
my @tab = ( $sample_supplier1, $sample_supplier2 ); |
| 132 |
is_deeply( \@booksellers, \@tab, |
| 133 |
"Returns right fields of Supplier1 and Supplier2" ); |
| 134 |
|
| 135 |
#Test basketcount |
| 136 |
my @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} ); |
| 137 |
is( $bookseller1[0]->{basketcount}, 0, 'Supplier1 has 0 basket' ); |
| 138 |
my $sample_basket1 = |
| 139 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); |
| 140 |
my $sample_basket2 = |
| 141 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); |
| 142 |
@bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} ); |
| 143 |
is( $bookseller1[0]->{basketcount}, 2, 'Supplier1 has 2 baskets' ); |
| 144 |
|
| 145 |
#Test GetBookSellerFromId |
| 146 |
my $bookseller1fromid = C4::Bookseller::GetBookSellerFromId(); |
| 147 |
is( $bookseller1fromid, undef, |
| 148 |
"GetBookSellerFromId returns undef if no id given" ); |
| 149 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
| 150 |
$bookseller1fromid = field_filter($bookseller1fromid); |
| 151 |
delete $bookseller1fromid->{basketcount}; |
| 152 |
delete $bookseller1fromid->{subscriptioncount}; |
| 153 |
is_deeply( $bookseller1fromid, $sample_supplier1, |
| 154 |
"Get Supplier1 (GetBookSellerFromId)" ); |
| 155 |
|
| 156 |
#Test basketcount |
| 157 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
| 158 |
is( $bookseller1fromid->{basketcount}, 2, 'Supplier1 has 2 baskets' ); |
| 159 |
|
| 160 |
#Test subscriptioncount |
| 161 |
my $dt_today = dt_from_string; |
| 162 |
my $today = output_pref( $dt_today, 'iso', '24hr', 1 ); |
| 163 |
|
| 164 |
my $dt_today1 = dt_from_string; |
| 165 |
my $dur5 = DateTime::Duration->new( days => -5 ); |
| 166 |
$dt_today1->add_duration($dur5); |
| 167 |
my $daysago5 = output_pref( $dt_today1, 'iso', '24hr', 1 ); |
| 168 |
|
| 169 |
my $budgetperiod = C4::Budgets::AddBudgetPeriod({ |
| 170 |
budget_period_startdate => $daysago5, |
| 171 |
budget_period_enddate => $today, |
| 172 |
budget_description => "budget desc" |
| 173 |
}); |
| 174 |
my $id_budget = AddBudget({ |
| 175 |
budget_code => "CODE", |
| 176 |
budget_amount => "123.132", |
| 177 |
budget_name => "Budgetname", |
| 178 |
budget_notes => "This is a note", |
| 179 |
budget_description => "BudgetDescription", |
| 180 |
budget_active => 1, |
| 181 |
budget_period_id => $budgetperiod |
| 182 |
}); |
| 183 |
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); |
| 184 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
| 185 |
is( $bookseller1fromid->{subscriptioncount}, |
| 186 |
0, 'Supplier1 has 0 subscription' ); |
| 187 |
my $id_subscription1 = C4::Serials::NewSubscription( |
| 188 |
undef, "", $id_supplier1, undef, |
| 189 |
$id_budget, $biblionumber, '01-01-2013', undef, |
| 190 |
undef, undef, undef, undef, |
| 191 |
undef, undef, undef, undef, |
| 192 |
undef, undef, undef, undef, |
| 193 |
undef, undef, undef, undef, |
| 194 |
undef, undef, undef, undef, |
| 195 |
undef, undef, undef, 1, |
| 196 |
"notes", undef, undef, undef, |
| 197 |
undef, undef, undef, 0, |
| 198 |
"intnotes", 0, undef, undef, |
| 199 |
0, undef, '31-12-2013', |
| 200 |
); |
| 201 |
my $id_subscription2 = C4::Serials::NewSubscription( |
| 202 |
undef, "", $id_supplier1, undef, |
| 203 |
$id_budget, $biblionumber, '01-01-2013', undef, |
| 204 |
undef, undef, undef, undef, |
| 205 |
undef, undef, undef, undef, |
| 206 |
undef, undef, undef, undef, |
| 207 |
undef, undef, undef, undef, |
| 208 |
undef, undef, undef, undef, |
| 209 |
undef, undef, undef, 1, |
| 210 |
"notes", undef, undef, undef, |
| 211 |
undef, undef, undef, 0, |
| 212 |
"intnotes", 0, undef, undef, |
| 213 |
0, undef, '31-12-2013', |
| 214 |
); |
| 215 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
| 216 |
is( $bookseller1fromid->{subscriptioncount}, |
| 217 |
2, 'Supplier1 has 2 subscriptions' ); |
| 218 |
|
| 219 |
#Test ModBookseller |
| 220 |
$sample_supplier2 = { |
| 221 |
id => $id_supplier2, |
| 222 |
name => 'Name2 modified', |
| 223 |
address1 => 'address1_2 modified', |
| 224 |
address2 => 'address2-2 modified', |
| 225 |
address3 => 'address3_2 modified', |
| 226 |
address4 => 'address4_2 modified', |
| 227 |
postal => 'postal2 modified', |
| 228 |
phone => 'phone2 modified', |
| 229 |
accountnumber => 'accountnumber2 modified', |
| 230 |
fax => 'fax2 modified', |
| 231 |
url => 'url2 modified', |
| 232 |
contact => 'contact2 modified', |
| 233 |
contpos => 'contpos2 modified', |
| 234 |
contphone => 'contphone2 modified', |
| 235 |
contfax => 'contefax2 modified', |
| 236 |
contaltphone => 'contaltphone2 modified', |
| 237 |
contemail => 'contemail2 modified', |
| 238 |
contnotes => 'contnotes2 modified', |
| 239 |
active => 1, |
| 240 |
gstreg => 1, |
| 241 |
listincgst => 1, |
| 242 |
invoiceincgst => 1, |
| 243 |
gstrate => '2.0000 ', |
| 244 |
discount => '2.0000', |
| 245 |
notes => 'notes2 modified', |
| 246 |
deliverytime => 2, |
| 247 |
}; |
| 248 |
|
| 249 |
my $modif1 = C4::Bookseller::ModBookseller(); |
| 250 |
is( $modif1, undef, |
| 251 |
"ModBookseller returns undef if no params given - Nothing happened" ); |
| 252 |
$modif1 = C4::Bookseller::ModBookseller($sample_supplier2); |
| 253 |
is( $modif1, 1, "ModBookseller modifies only the supplier2" ); |
| 254 |
is( scalar( C4::Bookseller::GetBookSeller('') ), |
| 255 |
$count + 2, "Supplier2 has been modified - Nothing added" ); |
| 256 |
|
| 257 |
$modif1 = C4::Bookseller::ModBookseller( |
| 258 |
{ |
| 259 |
id => -1, |
| 260 |
name => 'name3' |
| 261 |
} |
| 262 |
); |
| 263 |
is( $modif1, '0E0', |
| 264 |
"ModBookseller returns OEO if the id doesnt exist - Nothing modified" ); |
| 265 |
|
| 266 |
#Test GetBooksellersWithLateOrders |
| 267 |
#Add 2 suppliers |
| 268 |
my $sample_supplier3 = { |
| 269 |
name => 'Name3', |
| 270 |
address1 => 'address1_3', |
| 271 |
address2 => 'address1-3', |
| 272 |
address3 => 'address1_3', |
| 273 |
address4 => 'address1_3', |
| 274 |
postal => 'postal3', |
| 275 |
phone => 'phone3', |
| 276 |
accountnumber => 'accountnumber3', |
| 277 |
fax => 'fax3', |
| 278 |
url => 'url3', |
| 279 |
contact => 'contact3', |
| 280 |
contpos => 'contpos3', |
| 281 |
contphone => 'contphone3', |
| 282 |
contfax => 'contefax3', |
| 283 |
contaltphone => 'contaltphone3', |
| 284 |
contemail => 'contemail3', |
| 285 |
contnotes => 'contnotes3', |
| 286 |
active => 1, |
| 287 |
gstreg => 1, |
| 288 |
listincgst => 1, |
| 289 |
invoiceincgst => 1, |
| 290 |
gstrate => '3.0000', |
| 291 |
discount => '3.0000', |
| 292 |
notes => 'notes3', |
| 293 |
deliverytime => 3 |
| 294 |
}; |
| 295 |
my $sample_supplier4 = { |
| 296 |
name => 'Name4', |
| 297 |
address1 => 'address1_4', |
| 298 |
address2 => 'address1-4', |
| 299 |
address3 => 'address1_4', |
| 300 |
address4 => 'address1_4', |
| 301 |
postal => 'postal4', |
| 302 |
phone => 'phone4', |
| 303 |
accountnumber => 'accountnumber4', |
| 304 |
fax => 'fax4', |
| 305 |
url => 'url4', |
| 306 |
contact => 'contact4', |
| 307 |
contpos => 'contpos4', |
| 308 |
contphone => 'contphone4', |
| 309 |
contfax => 'contefax4', |
| 310 |
contaltphone => 'contaltphone4', |
| 311 |
contemail => 'contemail4', |
| 312 |
contnotes => 'contnotes4', |
| 313 |
active => 1, |
| 314 |
gstreg => 1, |
| 315 |
listincgst => 1, |
| 316 |
invoiceincgst => 1, |
| 317 |
gstrate => '3.0000', |
| 318 |
discount => '3.0000', |
| 319 |
notes => 'notes3', |
| 320 |
}; |
| 321 |
my $id_supplier3 = C4::Bookseller::AddBookseller($sample_supplier3); |
| 322 |
my $id_supplier4 = C4::Bookseller::AddBookseller($sample_supplier4); |
| 323 |
|
| 324 |
#Add 2 baskets |
| 325 |
my $sample_basket3 = |
| 326 |
C4::Acquisition::NewBasket( $id_supplier3, 'authorisedby3', 'basketname3', |
| 327 |
'basketnote3' ); |
| 328 |
my $sample_basket4 = |
| 329 |
C4::Acquisition::NewBasket( $id_supplier4, 'authorisedby4', 'basketname4', |
| 330 |
'basketnote4' ); |
| 331 |
|
| 332 |
#Modify the basket to add a close date |
| 333 |
my $basket1info = { |
| 334 |
basketno => $sample_basket1, |
| 335 |
closedate => $today, |
| 336 |
booksellerid => $id_supplier1 |
| 337 |
}; |
| 338 |
|
| 339 |
my $basket2info = { |
| 340 |
basketno => $sample_basket2, |
| 341 |
closedate => $daysago5, |
| 342 |
booksellerid => $id_supplier2 |
| 343 |
}; |
| 344 |
|
| 345 |
my $dt_today2 = dt_from_string; |
| 346 |
my $dur10 = DateTime::Duration->new( days => -10 ); |
| 347 |
$dt_today2->add_duration($dur10); |
| 348 |
my $daysago10 = output_pref( $dt_today2, 'iso', '24hr', 1 ); |
| 349 |
my $basket3info = { |
| 350 |
basketno => $sample_basket3, |
| 351 |
closedate => $daysago10, |
| 352 |
}; |
| 353 |
|
| 354 |
my $basket4info = { |
| 355 |
basketno => $sample_basket4, |
| 356 |
closedate => $today, |
| 357 |
}; |
| 358 |
ModBasket($basket1info); |
| 359 |
ModBasket($basket2info); |
| 360 |
ModBasket($basket3info); |
| 361 |
ModBasket($basket4info); |
| 362 |
|
| 363 |
#Add 1 subscription |
| 364 |
my $id_subscription3 = C4::Serials::NewSubscription( |
| 365 |
undef, "", $id_supplier3, undef, |
| 366 |
$id_budget, $biblionumber, '01-01-2013', undef, |
| 367 |
undef, undef, undef, undef, |
| 368 |
undef, undef, undef, undef, |
| 369 |
undef, undef, undef, undef, |
| 370 |
undef, undef, undef, undef, |
| 371 |
undef, undef, undef, undef, |
| 372 |
undef, undef, undef, 1, |
| 373 |
"notes", undef, undef, undef, |
| 374 |
undef, undef, undef, 0, |
| 375 |
"intnotes", 0, undef, undef, |
| 376 |
0, undef, '31-12-2013', |
| 377 |
); |
| 378 |
|
| 379 |
#Add 4 orders |
| 380 |
my ( $ordernumber1, $ordernumber2, $ordernumber3, $ordernumber4 ); |
| 381 |
my ( $basketno1, $basketno2, $basketno3, $basketno4 ); |
| 382 |
( $basketno1, $ordernumber1 ) = C4::Acquisition::NewOrder( |
| 383 |
{ |
| 384 |
basketno => $sample_basket1, |
| 385 |
quantity => 24, |
| 386 |
biblionumber => $biblionumber, |
| 387 |
budget_id => $id_budget, |
| 388 |
entrydate => '01-01-2013', |
| 389 |
currency => 'EUR', |
| 390 |
notes => "This is a note1", |
| 391 |
gstrate => 0.0500, |
| 392 |
orderstatus => 1, |
| 393 |
subscriptionid => $id_subscription1, |
| 394 |
quantityreceived => 2, |
| 395 |
rrp => 10, |
| 396 |
ecost => 10, |
| 397 |
datereceived => '01-06-2013' |
| 398 |
} |
| 399 |
); |
| 400 |
( $basketno2, $ordernumber2 ) = C4::Acquisition::NewOrder( |
| 401 |
{ |
| 402 |
basketno => $sample_basket2, |
| 403 |
quantity => 20, |
| 404 |
biblionumber => $biblionumber, |
| 405 |
budget_id => $id_budget, |
| 406 |
entrydate => '01-01-2013', |
| 407 |
currency => 'EUR', |
| 408 |
notes => "This is a note2", |
| 409 |
gstrate => 0.0500, |
| 410 |
orderstatus => 1, |
| 411 |
subscriptionid => $id_subscription2, |
| 412 |
rrp => 10, |
| 413 |
ecost => 10, |
| 414 |
} |
| 415 |
); |
| 416 |
( $basketno3, $ordernumber3 ) = C4::Acquisition::NewOrder( |
| 417 |
{ |
| 418 |
basketno => $sample_basket3, |
| 419 |
quantity => 20, |
| 420 |
biblionumber => $biblionumber, |
| 421 |
budget_id => $id_budget, |
| 422 |
entrydate => '02-02-2013', |
| 423 |
currency => 'EUR', |
| 424 |
notes => "This is a note3", |
| 425 |
gstrate => 0.0500, |
| 426 |
orderstatus => 2, |
| 427 |
subscriptionid => $id_subscription3, |
| 428 |
rrp => 11, |
| 429 |
ecost => 11, |
| 430 |
} |
| 431 |
); |
| 432 |
( $basketno4, $ordernumber4 ) = C4::Acquisition::NewOrder( |
| 433 |
{ |
| 434 |
basketno => $sample_basket4, |
| 435 |
quantity => 20, |
| 436 |
biblionumber => $biblionumber, |
| 437 |
budget_id => $id_budget, |
| 438 |
entrydate => '02-02-2013', |
| 439 |
currency => 'EUR', |
| 440 |
notes => "This is a note3", |
| 441 |
gstrate => 0.0500, |
| 442 |
orderstatus => 2, |
| 443 |
subscriptionid => $id_subscription3, |
| 444 |
rrp => 11, |
| 445 |
ecost => 11, |
| 446 |
quantityreceived => 20 |
| 447 |
} |
| 448 |
); |
| 449 |
|
| 450 |
#Test cases: |
| 451 |
# Sample datas : |
| 452 |
# Supplier1: delivery -> undef Basket1 : closedate -> today |
| 453 |
# Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5 |
| 454 |
# Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10 |
| 455 |
#Case 1 : Without parameters: |
| 456 |
# quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE- |
| 457 |
# datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE- |
| 458 |
# datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE- |
| 459 |
# quantityreceived = quantity -NOT LATE- |
| 460 |
my %suppliers = C4::Bookseller::GetBooksellersWithLateOrders(); |
| 461 |
ok( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" ); |
| 462 |
ok( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" ); |
| 463 |
ok( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" ); |
| 464 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ) |
| 465 |
; # Quantity = quantityreceived |
| 466 |
|
| 467 |
#Case 2: With $delay = 4 |
| 468 |
# today + 0 > now-$delay -NOT LATE- |
| 469 |
# (today-5) + 2 <= now() - $delay -NOT LATE- |
| 470 |
# (today-10) + 3 <= now() - $delay -LATE- |
| 471 |
# quantityreceived = quantity -NOT LATE- |
| 472 |
%suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 4, undef, undef ); |
| 473 |
isnt( exists( $suppliers{$id_supplier1} ), |
| 474 |
1, "Supplier1 has late orders but today > now() - 4 days" ); |
| 475 |
isnt( exists( $suppliers{$id_supplier2} ), |
| 476 |
1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" ); |
| 477 |
ok( exists( $suppliers{$id_supplier3} ), |
| 478 |
"Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" ); |
| 479 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 480 |
|
| 481 |
#Case 3: With $delay = -1 |
| 482 |
is( C4::Bookseller::GetBooksellersWithLateOrders( -1, undef, undef ), |
| 483 |
undef, "-1 is a wrong value for a delay" ); |
| 484 |
|
| 485 |
#Case 4: With $delay = 0 |
| 486 |
# today == now-0 -LATE- (if no deliverytime or deliverytime == 0) |
| 487 |
# today-5 <= now() - $delay+2 -LATE- |
| 488 |
# today-10 <= now() - $delay+3 -LATE- |
| 489 |
# quantityreceived = quantity -NOT LATE- |
| 490 |
%suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 0, undef, undef ); |
| 491 |
|
| 492 |
ok( exists( $suppliers{$id_supplier1} ), |
| 493 |
"Supplier1 has late orders but $today == now() - 0 days" ) |
| 494 |
; |
| 495 |
ok( exists( $suppliers{$id_supplier2} ), |
| 496 |
"Supplier2 has late orders and $daysago5 <= now() - 2" ); |
| 497 |
ok( exists( $suppliers{$id_supplier3} ), |
| 498 |
"Supplier3 has late orders and $daysago10 <= now() - 3" ); |
| 499 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 500 |
|
| 501 |
#Case 5 : With $estimateddeliverydatefrom = today-4 #NOTE if a supplier didnt fill in deliverytime is it late? |
| 502 |
# today >= today-4 -NOT LATE- |
| 503 |
# (today-5)+ 2 days >= today-4 -LATE- |
| 504 |
# (today-10) + 3 days < today-4 -NOT LATE- |
| 505 |
# quantityreceived = quantity -NOT LATE- |
| 506 |
my $dt_today3 = dt_from_string; |
| 507 |
my $dur4 = DateTime::Duration->new( days => -4 ); |
| 508 |
$dt_today3->add_duration($dur4); |
| 509 |
my $daysago4 = output_pref( $dt_today3, 'iso', '24hr', 1 ); |
| 510 |
%suppliers = |
| 511 |
C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago4, undef ); |
| 512 |
ok( exists( $suppliers{$id_supplier1} ), |
| 513 |
"Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" ); |
| 514 |
ok( exists( $suppliers{$id_supplier2} ), |
| 515 |
"Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " ); |
| 516 |
isnt( exists( $suppliers{$id_supplier3} ), |
| 517 |
1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " ); |
| 518 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 519 |
|
| 520 |
#Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5 |
| 521 |
# $daysago10<$daysago5<today -NOT LATE- |
| 522 |
# $daysago10<$daysago5<$daysago5 +2 -NOT lATE- |
| 523 |
# $daysago10<$daysago10 +3 <$daysago5 -LATE- |
| 524 |
# quantityreceived = quantity -NOT LATE- |
| 525 |
%suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10, |
| 526 |
$daysago5 ); |
| 527 |
isnt( exists( $suppliers{$id_supplier1} ), |
| 528 |
1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" ); |
| 529 |
isnt( |
| 530 |
exists( $suppliers{$id_supplier2} ), |
| 531 |
1, |
| 532 |
"Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2" |
| 533 |
); |
| 534 |
ok( |
| 535 |
exists( $suppliers{$id_supplier3} ), |
| 536 |
"Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5" |
| 537 |
); |
| 538 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 539 |
|
| 540 |
#Case 7: With $estimateddeliverydateto = today-5 |
| 541 |
# $today >= $daysago5 -NOT LATE- |
| 542 |
# $daysago5 + 2 days > $daysago5 -NOT LATE- |
| 543 |
# $daysago10 + 3 <+ $daysago5 -LATE- |
| 544 |
# quantityreceived = quantity -NOT LATE- |
| 545 |
%suppliers = |
| 546 |
C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago5 ); |
| 547 |
isnt( exists( $suppliers{$id_supplier1} ), |
| 548 |
1, |
| 549 |
"Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" ); |
| 550 |
isnt( exists( $suppliers{$id_supplier2} ), |
| 551 |
1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " ); |
| 552 |
ok( exists( $suppliers{$id_supplier3} ), |
| 553 |
"Supplier3 has late orders and $daysago10 + 3 <= $daysago5" ); |
| 554 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 555 |
|
| 556 |
#Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay |
| 557 |
#Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5 |
| 558 |
# $daysago4<today<=$today and $today<now()-3 -NOT LATE- |
| 559 |
# $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE- |
| 560 |
# $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE- |
| 561 |
# quantityreceived = quantity -NOT LATE- |
| 562 |
%suppliers = |
| 563 |
C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago4, $today ); |
| 564 |
isnt( |
| 565 |
exists( $suppliers{$id_supplier1} ), |
| 566 |
1, |
| 567 |
"Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3" |
| 568 |
); |
| 569 |
ok( |
| 570 |
exists( $suppliers{$id_supplier2} ), |
| 571 |
"Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days" |
| 572 |
); |
| 573 |
isnt( |
| 574 |
exists( $suppliers{$id_supplier3} ), |
| 575 |
"Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days" |
| 576 |
); |
| 577 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 578 |
|
| 579 |
#Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3 |
| 580 |
# $today < $daysago5 and $today > $today-5 -NOT LATE- |
| 581 |
# $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE- |
| 582 |
# $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE- |
| 583 |
# quantityreceived = quantity -NOT LATE- |
| 584 |
%suppliers = |
| 585 |
C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago5, undef ); |
| 586 |
isnt( exists( $suppliers{$id_supplier1} ), |
| 587 |
1, "$today < $daysago10 and $today > $today-3" ); |
| 588 |
ok( |
| 589 |
exists( $suppliers{$id_supplier2} ), |
| 590 |
"Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2" |
| 591 |
); |
| 592 |
isnt( |
| 593 |
exists( $suppliers{$id_supplier3} ), |
| 594 |
1, |
| 595 |
"Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 " |
| 596 |
); |
| 597 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 598 |
|
| 599 |
#Test with $estimateddeliverydateto and $delay |
| 600 |
#Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5 |
| 601 |
# today > $daysago5 today > now() -5 -NOT LATE- |
| 602 |
# $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE- |
| 603 |
# $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE- |
| 604 |
# quantityreceived = quantity -NOT LATE- |
| 605 |
%suppliers = |
| 606 |
C4::Bookseller::GetBooksellersWithLateOrders( 5, undef, $daysago5 ); |
| 607 |
isnt( exists( $suppliers{$id_supplier1} ), |
| 608 |
1, "Supplier2 has late orders but today > $daysago5 today > now() -5" ); |
| 609 |
isnt( |
| 610 |
exists( $suppliers{$id_supplier2} ), |
| 611 |
1, |
| 612 |
"Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days" |
| 613 |
); |
| 614 |
ok( |
| 615 |
exists( $suppliers{$id_supplier3} ), |
| 616 |
"Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days " |
| 617 |
); |
| 618 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 619 |
|
| 620 |
#Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10 |
| 621 |
# $daysago10==$daysago10==$daysago10 -NOT LATE- |
| 622 |
# $daysago10==$daysago10<$daysago5+2-NOT lATE- |
| 623 |
# $daysago10==$daysago10 <$daysago10+3-LATE- |
| 624 |
# quantityreceived = quantity -NOT LATE- |
| 625 |
|
| 626 |
#Basket1 closedate -> $daysago10 |
| 627 |
$basket1info = { |
| 628 |
basketno => $sample_basket1, |
| 629 |
closedate => $daysago10, |
| 630 |
}; |
| 631 |
ModBasket($basket1info); |
| 632 |
%suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10, |
| 633 |
$daysago10 ); |
| 634 |
ok( exists( $suppliers{$id_supplier1} ), |
| 635 |
"Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " ) |
| 636 |
; |
| 637 |
isnt( exists( $suppliers{$id_supplier2} ), |
| 638 |
1, |
| 639 |
"Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" ); |
| 640 |
isnt( exists( $suppliers{$id_supplier3} ), |
| 641 |
1, |
| 642 |
"Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" ); |
| 643 |
isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); |
| 644 |
|
| 645 |
#Case 12: closedate == $estimateddeliverydatefrom =today-10 |
| 646 |
%suppliers = |
| 647 |
C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10, undef ); |
| 648 |
ok( exists( $suppliers{$id_supplier1} ), |
| 649 |
"Supplier1 has late orders and $daysago10==$daysago10 " ); |
| 650 |
|
| 651 |
#Case 13: closedate == $estimateddeliverydateto =today-10 |
| 652 |
%suppliers = |
| 653 |
C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago10 ); |
| 654 |
ok( exists( $suppliers{$id_supplier1} ), |
| 655 |
"Supplier1 has late orders and $daysago10==$daysago10 " ) |
| 656 |
; |
| 657 |
|
| 658 |
#End transaction |
| 659 |
$dbh->rollback; |
| 660 |
|
| 661 |
#field_filter filters the useless fields or foreign keys |
| 662 |
#NOTE: all the fields of aqbookseller arent considered |
| 663 |
#returns a cleaned structure |
| 664 |
sub field_filter { |
| 665 |
my ($struct) = @_; |
| 666 |
|
| 667 |
for my $field ( |
| 668 |
'bookselleremail', 'booksellerfax', |
| 669 |
'booksellerurl', 'othersupplier', |
| 670 |
'currency', 'invoiceprice', |
| 671 |
'listprice' |
| 672 |
) |
| 673 |
{ |
| 674 |
|
| 675 |
if ( grep { /^$field$/ } keys %$struct ) { |
| 676 |
delete $struct->{$field}; |
| 677 |
} |
| 678 |
} |
| 679 |
return $struct; |
| 680 |
} |