5 use Test::More tests => 72;
9 use DateTime::Duration;
16 use_ok('C4::Bookseller');
26 GetBooksellersWithLateOrders
31 my $dbh = C4::Context->dbh;
32 $dbh->{RaiseError} = 1;
33 $dbh->{AutoCommit} = 0;
36 $dbh->do(q|DELETE FROM aqorders|);
37 $dbh->do(q|DELETE FROM aqbasket|);
38 $dbh->do(q|DELETE FROM aqbooksellers|);
39 $dbh->do(q|DELETE FROM subscription|);
42 my $count = scalar( C4::Bookseller::GetBookSeller('') );
43 my $sample_supplier1 = {
45 address1 => 'address1_1',
46 address2 => 'address1-2',
47 address3 => 'address1_2',
48 address4 => 'address1_2',
51 accountnumber => 'accountnumber1',
54 contact => 'contact1',
55 contpos => 'contpos1',
56 contphone => 'contphone1',
57 contfax => 'contefax1',
58 contaltphone => 'contaltphone1',
59 contemail => 'contemail1',
60 contnotes => 'contnotes1',
70 my $sample_supplier2 = {
72 address1 => 'address1_2',
73 address2 => 'address2-2',
74 address3 => 'address3_2',
75 address4 => 'address4_2',
78 accountnumber => 'accountnumber2',
81 contact => 'contact2',
82 contpos => 'contpos2',
83 contphone => 'contphone2',
84 contfax => 'contefax2',
85 contaltphone => 'contaltphone2',
86 contemail => 'contemail2',
87 contnotes => 'contnotes2',
98 my $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1);
99 my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2);
101 #my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null
103 like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
104 like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
105 is( scalar( C4::Bookseller::GetBookSeller('') ),
106 $count + 2, "Supplier1 and Supplier2 have been added" );
109 my $del = C4::Bookseller::DelBookseller($id_supplier1);
110 is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
111 is( C4::Bookseller::GetBookSellerFromId($id_supplier1),
112 undef, "Supplier1 has been deleted - id_supplier1 doesnt exist anymore" );
115 my @bookseller2 = C4::Bookseller::GetBookSeller( $sample_supplier2->{name} );
116 is( scalar(@bookseller2), 1, "Get only Supplier2" );
117 $bookseller2[0] = field_filter( $bookseller2[0] );
118 delete $bookseller2[0]->{basketcount};
120 $sample_supplier2->{id} = $id_supplier2;
121 is_deeply( $bookseller2[0], $sample_supplier2,
122 "GetBookSeller returns the right informations about $sample_supplier2" );
124 $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1);
125 my @booksellers = C4::Bookseller::GetBookSeller('')
126 ; #NOTE :without params, it returns all the booksellers
127 for my $i ( 0 .. scalar(@booksellers) - 1 ) {
128 $booksellers[$i] = field_filter( $booksellers[$i] );
129 delete $booksellers[$i]->{basketcount};
132 $sample_supplier1->{id} = $id_supplier1;
133 is( scalar(@booksellers), $count + 2, "Get Supplier1 and Supplier2" );
134 my @tab = ( $sample_supplier1, $sample_supplier2 );
135 is_deeply( \@booksellers, \@tab,
136 "Returns right fields of Supplier1 and Supplier2" );
139 my @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} );
140 #FIXME : if there is 0 basket, GetBookSeller returns 1 as basketcount
141 #is( $bookseller1[0]->{basketcount}, 0, 'Supplier1 has 0 basket' );
143 C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' );
145 C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' );
146 @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} );
147 is( $bookseller1[0]->{basketcount}, 2, 'Supplier1 has 2 baskets' );
149 #Test GetBookSellerFromId
150 my $bookseller1fromid = C4::Bookseller::GetBookSellerFromId();
151 is( $bookseller1fromid, undef,
152 "GetBookSellerFromId returns undef if no id given" );
153 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
154 $bookseller1fromid = field_filter($bookseller1fromid);
155 delete $bookseller1fromid->{basketcount};
156 delete $bookseller1fromid->{subscriptioncount};
157 is_deeply( $bookseller1fromid, $sample_supplier1,
158 "Get Supplier1 (GetBookSellerFromId)" );
161 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
162 is( $bookseller1fromid->{basketcount}, 2, 'Supplier1 has 2 baskets' );
164 #Test subscriptioncount
165 my $dt_today = dt_from_string;
166 my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
168 my $dt_today1 = dt_from_string;
169 my $dur5 = DateTime::Duration->new( days => -5 );
170 $dt_today1->add_duration($dur5);
171 my $daysago5 = output_pref({ dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
173 my $budgetperiod = C4::Budgets::AddBudgetPeriod({
174 budget_period_startdate => $daysago5,
175 budget_period_enddate => $today,
176 budget_period_description => "budget desc"
178 my $id_budget = AddBudget({
179 budget_code => "CODE",
180 budget_amount => "123.132",
181 budget_name => "Budgetname",
182 budget_notes => "This is a note",
183 budget_period_id => $budgetperiod
185 my $bib = MARC::Record->new();
187 MARC::Field->new('245', ' ', ' ', a => 'Journal of ethnology'),
188 MARC::Field->new('500', ' ', ' ', a => 'bib notes'),
190 my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, '');
191 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
192 is( $bookseller1fromid->{subscriptioncount},
193 0, 'Supplier1 has 0 subscription' );
195 my $id_subscription1 = NewSubscription(
196 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
197 '01-01-2013',undef, undef, undef, undef,
198 undef, undef, undef, undef, undef, undef,
199 1, "subscription notes",undef, '01-01-2013', undef, undef,
200 undef, 'CALL ABC', 0, "intnotes", 0,
201 undef, undef, 0, undef, '2013-11-30', 0
204 my @subscriptions = SearchSubscriptions({biblionumber => $biblionumber});
205 is($subscriptions[0]->{publicnotes}, 'subscription notes', 'subscription search results include public notes (bug 10689)');
207 my $id_subscription2 = NewSubscription(
208 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
209 '01-01-2013',undef, undef, undef, undef,
210 undef, undef, undef, undef, undef, undef,
211 1, "subscription notes",undef, '01-01-2013', undef, undef,
212 undef, 'CALL DEF', 0, "intnotes", 0,
213 undef, undef, 0, undef, '2013-07-31', 0
216 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
217 is( $bookseller1fromid->{subscriptioncount},
218 2, 'Supplier1 has 2 subscriptions' );
221 $sample_supplier2 = {
223 name => 'Name2 modified',
224 address1 => 'address1_2 modified',
225 address2 => 'address2-2 modified',
226 address3 => 'address3_2 modified',
227 address4 => 'address4_2 modified',
228 postal => 'postal2 modified',
229 phone => 'phone2 modified',
230 accountnumber => 'accountnumber2 modified',
231 fax => 'fax2 modified',
232 url => 'url2 modified',
233 contact => 'contact2 modified',
234 contpos => 'contpos2 modified',
235 contphone => 'contphone2 modified',
236 contfax => 'contefax2 modified',
237 contaltphone => 'contaltphone2 modified',
238 contemail => 'contemail2 modified',
239 contnotes => 'contnotes2 modified',
244 gstrate => '2.0000 ',
245 discount => '2.0000',
246 notes => 'notes2 modified',
250 my $modif1 = C4::Bookseller::ModBookseller();
252 "ModBookseller returns undef if no params given - Nothing happened" );
253 $modif1 = C4::Bookseller::ModBookseller($sample_supplier2);
254 is( $modif1, 1, "ModBookseller modifies only the supplier2" );
255 is( scalar( C4::Bookseller::GetBookSeller('') ),
256 $count + 2, "Supplier2 has been modified - Nothing added" );
258 $modif1 = C4::Bookseller::ModBookseller(
265 # "ModBookseller returns OEO if the id doesnt exist - Nothing modified" );
267 #Test GetBooksellersWithLateOrders
269 my $sample_supplier3 = {
271 address1 => 'address1_3',
272 address2 => 'address1-3',
273 address3 => 'address1_3',
274 address4 => 'address1_3',
277 accountnumber => 'accountnumber3',
280 contact => 'contact3',
281 contpos => 'contpos3',
282 contphone => 'contphone3',
283 contfax => 'contefax3',
284 contaltphone => 'contaltphone3',
285 contemail => 'contemail3',
286 contnotes => 'contnotes3',
292 discount => '3.0000',
296 my $sample_supplier4 = {
298 address1 => 'address1_4',
299 address2 => 'address1-4',
300 address3 => 'address1_4',
301 address4 => 'address1_4',
304 accountnumber => 'accountnumber4',
307 contact => 'contact4',
308 contpos => 'contpos4',
309 contphone => 'contphone4',
310 contfax => 'contefax4',
311 contaltphone => 'contaltphone4',
312 contemail => 'contemail4',
313 contnotes => 'contnotes4',
319 discount => '3.0000',
322 my $id_supplier3 = C4::Bookseller::AddBookseller($sample_supplier3);
323 my $id_supplier4 = C4::Bookseller::AddBookseller($sample_supplier4);
327 C4::Acquisition::NewBasket( $id_supplier3, 'authorisedby3', 'basketname3',
330 C4::Acquisition::NewBasket( $id_supplier4, 'authorisedby4', 'basketname4',
333 #Modify the basket to add a close date
335 basketno => $sample_basket1,
337 booksellerid => $id_supplier1
341 basketno => $sample_basket2,
342 closedate => $daysago5,
343 booksellerid => $id_supplier2
346 my $dt_today2 = dt_from_string;
347 my $dur10 = DateTime::Duration->new( days => -10 );
348 $dt_today2->add_duration($dur10);
349 my $daysago10 = output_pref({ dt => $dt_today2, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
351 basketno => $sample_basket3,
352 closedate => $daysago10,
356 basketno => $sample_basket4,
359 ModBasket($basket1info);
360 ModBasket($basket2info);
361 ModBasket($basket3info);
362 ModBasket($basket4info);
365 my $id_subscription3 = NewSubscription(
366 undef, "BRANCH1", $id_supplier1, undef, $id_budget, $biblionumber,
367 '01-01-2013',undef, undef, undef, undef,
368 undef, undef, undef, undef, undef, undef,
369 1, "subscription notes",undef, '01-01-2013', undef, undef,
370 undef, undef, 0, "intnotes", 0,
371 undef, undef, 0, 'LOCA', '2013-12-31', 0
374 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
375 is(scalar(@subscriptions), 3, 'search for subscriptions by expiration date');
376 @subscriptions = SearchSubscriptions({expiration_date => '2013-08-15'});
377 is(scalar(@subscriptions), 1, 'search for subscriptions by expiration date');
378 @subscriptions = SearchSubscriptions({callnumber => 'CALL'});
379 is(scalar(@subscriptions), 2, 'search for subscriptions by call number');
380 @subscriptions = SearchSubscriptions({callnumber => 'DEF'});
381 is(scalar(@subscriptions), 1, 'search for subscriptions by call number');
382 @subscriptions = SearchSubscriptions({location => 'LOCA'});
383 is(scalar(@subscriptions), 1, 'search for subscriptions by location');
386 my ( $ordernumber1, $ordernumber2, $ordernumber3, $ordernumber4 );
387 my ( $basketno1, $basketno2, $basketno3, $basketno4 );
388 ( $basketno1, $ordernumber1 ) = C4::Acquisition::NewOrder(
390 basketno => $sample_basket1,
392 biblionumber => $biblionumber,
393 budget_id => $id_budget,
394 entrydate => '01-01-2013',
396 notes => "This is a note1",
399 subscriptionid => $id_subscription1,
400 quantityreceived => 2,
403 datereceived => '01-06-2013'
406 ( $basketno2, $ordernumber2 ) = C4::Acquisition::NewOrder(
408 basketno => $sample_basket2,
410 biblionumber => $biblionumber,
411 budget_id => $id_budget,
412 entrydate => '01-01-2013',
414 notes => "This is a note2",
417 subscriptionid => $id_subscription2,
422 ( $basketno3, $ordernumber3 ) = C4::Acquisition::NewOrder(
424 basketno => $sample_basket3,
426 biblionumber => $biblionumber,
427 budget_id => $id_budget,
428 entrydate => '02-02-2013',
430 notes => "This is a note3",
433 subscriptionid => $id_subscription3,
438 ( $basketno4, $ordernumber4 ) = C4::Acquisition::NewOrder(
440 basketno => $sample_basket4,
442 biblionumber => $biblionumber,
443 budget_id => $id_budget,
444 entrydate => '02-02-2013',
446 notes => "This is a note3",
449 subscriptionid => $id_subscription3,
452 quantityreceived => 20
458 # Supplier1: delivery -> undef Basket1 : closedate -> today
459 # Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5
460 # Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10
461 #Case 1 : Without parameters:
462 # quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
463 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
464 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
465 # quantityreceived = quantity -NOT LATE-
466 my %suppliers = C4::Bookseller::GetBooksellersWithLateOrders();
467 ok( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" );
468 ok( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" );
469 ok( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" );
470 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" )
471 ; # Quantity = quantityreceived
473 #Case 2: With $delay = 4
474 # today + 0 > now-$delay -NOT LATE-
475 # (today-5) + 2 <= now() - $delay -NOT LATE-
476 # (today-10) + 3 <= now() - $delay -LATE-
477 # quantityreceived = quantity -NOT LATE-
478 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 4, undef, undef );
479 isnt( exists( $suppliers{$id_supplier1} ),
480 1, "Supplier1 has late orders but today > now() - 4 days" );
481 isnt( exists( $suppliers{$id_supplier2} ),
482 1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" );
483 ok( exists( $suppliers{$id_supplier3} ),
484 "Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" );
485 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
487 #Case 3: With $delay = -1
488 is( C4::Bookseller::GetBooksellersWithLateOrders( -1, undef, undef ),
489 undef, "-1 is a wrong value for a delay" );
491 #Case 4: With $delay = 0
492 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0)
493 # today-5 <= now() - $delay+2 -LATE-
494 # today-10 <= now() - $delay+3 -LATE-
495 # quantityreceived = quantity -NOT LATE-
496 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 0, undef, undef );
498 ok( exists( $suppliers{$id_supplier1} ),
499 "Supplier1 has late orders but $today == now() - 0 days" )
501 ok( exists( $suppliers{$id_supplier2} ),
502 "Supplier2 has late orders and $daysago5 <= now() - 2" );
503 ok( exists( $suppliers{$id_supplier3} ),
504 "Supplier3 has late orders and $daysago10 <= now() - 3" );
505 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
507 #Case 5 : With $estimateddeliverydatefrom = today-4
508 # today >= today-4 -NOT LATE-
509 # (today-5)+ 2 days >= today-4 -LATE-
510 # (today-10) + 3 days < today-4 -NOT LATE-
511 # quantityreceived = quantity -NOT LATE-
512 my $dt_today3 = dt_from_string;
513 my $dur4 = DateTime::Duration->new( days => -4 );
514 $dt_today3->add_duration($dur4);
515 my $daysago4 = output_pref({ dt => $dt_today3, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
517 C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago4, undef );
519 ok( exists( $suppliers{$id_supplier1} ),
520 "Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" );
521 ok( exists( $suppliers{$id_supplier2} ),
522 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " );
523 isnt( exists( $suppliers{$id_supplier3} ),
524 1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " );
525 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
527 #Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5
528 # $daysago10<$daysago5<today -NOT LATE-
529 # $daysago10<$daysago5<$daysago5 +2 -NOT lATE-
530 # $daysago10<$daysago10 +3 <$daysago5 -LATE-
531 # quantityreceived = quantity -NOT LATE-
532 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10,
534 isnt( exists( $suppliers{$id_supplier1} ),
535 1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" );
537 exists( $suppliers{$id_supplier2} ),
539 "Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2"
542 exists( $suppliers{$id_supplier3} ),
543 "Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5"
545 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
547 #Case 7: With $estimateddeliverydateto = today-5
548 # $today >= $daysago5 -NOT LATE-
549 # $daysago5 + 2 days > $daysago5 -NOT LATE-
550 # $daysago10 + 3 <+ $daysago5 -LATE-
551 # quantityreceived = quantity -NOT LATE-
553 C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago5 );
554 isnt( exists( $suppliers{$id_supplier1} ),
556 "Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" );
557 isnt( exists( $suppliers{$id_supplier2} ),
558 1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " );
559 ok( exists( $suppliers{$id_supplier3} ),
560 "Supplier3 has late orders and $daysago10 + 3 <= $daysago5" );
561 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
563 #Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay
564 #Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5
565 # $daysago4<today<=$today and $today<now()-3 -NOT LATE-
566 # $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE-
567 # $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE-
568 # quantityreceived = quantity -NOT LATE-
570 C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago4, $today );
572 exists( $suppliers{$id_supplier1} ),
574 "Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3"
577 exists( $suppliers{$id_supplier2} ),
578 "Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days"
581 exists( $suppliers{$id_supplier3} ),
582 "Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days"
584 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
586 #Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3
587 # $today < $daysago5 and $today > $today-5 -NOT LATE-
588 # $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE-
589 # $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE-
590 # quantityreceived = quantity -NOT LATE-
592 C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago5, undef );
593 isnt( exists( $suppliers{$id_supplier1} ),
594 1, "$today < $daysago10 and $today > $today-3" );
596 exists( $suppliers{$id_supplier2} ),
597 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2"
600 exists( $suppliers{$id_supplier3} ),
602 "Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 "
604 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
606 #Test with $estimateddeliverydateto and $delay
607 #Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5
608 # today > $daysago5 today > now() -5 -NOT LATE-
609 # $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE-
610 # $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE-
611 # quantityreceived = quantity -NOT LATE-
613 C4::Bookseller::GetBooksellersWithLateOrders( 5, undef, $daysago5 );
614 isnt( exists( $suppliers{$id_supplier1} ),
615 1, "Supplier2 has late orders but today > $daysago5 today > now() -5" );
617 exists( $suppliers{$id_supplier2} ),
619 "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days"
622 exists( $suppliers{$id_supplier3} ),
623 "Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days "
625 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
627 #Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10
628 # $daysago10==$daysago10==$daysago10 -NOT LATE-
629 # $daysago10==$daysago10<$daysago5+2-NOT lATE-
630 # $daysago10==$daysago10 <$daysago10+3-LATE-
631 # quantityreceived = quantity -NOT LATE-
633 #Basket1 closedate -> $daysago10
635 basketno => $sample_basket1,
636 closedate => $daysago10,
638 ModBasket($basket1info);
639 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10,
641 ok( exists( $suppliers{$id_supplier1} ),
642 "Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " )
644 isnt( exists( $suppliers{$id_supplier2} ),
646 "Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" );
647 isnt( exists( $suppliers{$id_supplier3} ),
649 "Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" );
650 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
652 #Case 12: closedate == $estimateddeliverydatefrom =today-10
654 C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10, undef );
655 ok( exists( $suppliers{$id_supplier1} ),
656 "Supplier1 has late orders and $daysago10==$daysago10 " );
658 #Case 13: closedate == $estimateddeliverydateto =today-10
660 C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago10 );
661 ok( exists( $suppliers{$id_supplier1} ),
662 "Supplier1 has late orders and $daysago10==$daysago10 " )
665 C4::Context->_new_userenv('DUMMY SESSION');
666 C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', '');
667 my $userenv = C4::Context->userenv;
669 my $module = Test::MockModule->new('C4::Auth');
673 # simulate user that has serials permissions but
675 my ($userid, $flagsrequired) = @_;
676 return 0 if 'superserials' eq ($flagsrequired->{serials} // 0);
677 return exists($flagsrequired->{serials});
681 C4::Context->set_preference('IndependentBranches', 0);
682 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
684 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
686 'ordinary user can see all subscriptions with IndependentBranches off'
689 C4::Context->set_preference('IndependentBranches', 1);
690 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
692 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
694 'ordinary user can see only their library\'s subscriptions with IndependentBranches on'
697 # don the cape and turn into Superlibrarian!
698 C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', '');
699 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
701 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
703 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
709 #field_filter filters the useless fields or foreign keys
710 #NOTE: all the fields of aqbookseller arent considered
711 #returns a cleaned structure
716 'bookselleremail', 'booksellerfax',
717 'booksellerurl', 'othersupplier',
718 'currency', 'invoiceprice',
723 if ( grep { /^$field$/ } keys %$struct ) {
724 delete $struct->{$field};