5 use Test::More tests => 86;
11 use DateTime::Duration;
18 use_ok('C4::Bookseller');
28 GetBooksellersWithLateOrders
33 my $dbh = C4::Context->dbh;
34 $dbh->{RaiseError} = 1;
35 $dbh->{AutoCommit} = 0;
38 $dbh->do(q|DELETE FROM aqorders|);
39 $dbh->do(q|DELETE FROM aqbasket|);
40 $dbh->do(q|DELETE FROM aqbooksellers|);
41 $dbh->do(q|DELETE FROM subscription|);
44 my $count = scalar( C4::Bookseller::GetBookSeller('') );
45 my $sample_supplier1 = {
47 address1 => 'address1_1',
48 address2 => 'address1-2',
49 address3 => 'address1_2',
50 address4 => 'address1_2',
53 accountnumber => 'accountnumber1',
65 my $sample_supplier2 = {
67 address1 => 'address1_2',
68 address2 => 'address2-2',
69 address3 => 'address3_2',
70 address4 => 'address4_2',
73 accountnumber => 'accountnumber2',
86 my $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1);
87 my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2);
89 #my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null
91 like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
92 like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
93 is( scalar( C4::Bookseller::GetBookSeller('') ),
94 $count + 2, "Supplier1 and Supplier2 have been added" );
97 my $del = C4::Bookseller::DelBookseller($id_supplier1);
98 is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
99 is( C4::Bookseller::GetBookSellerFromId($id_supplier1),
100 undef, "Supplier1 has been deleted - id_supplier1 doesnt exist anymore" );
103 my @bookseller2 = C4::Bookseller::GetBookSeller( $sample_supplier2->{name} );
104 is( scalar(@bookseller2), 1, "Get only Supplier2" );
105 $bookseller2[0] = field_filter( $bookseller2[0] );
106 delete $bookseller2[0]->{basketcount};
108 $sample_supplier2->{id} = $id_supplier2;
109 is_deeply( $bookseller2[0], $sample_supplier2,
110 "GetBookSeller returns the right informations about $sample_supplier2" );
112 $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1);
113 my @booksellers = C4::Bookseller::GetBookSeller('')
114 ; #NOTE :without params, it returns all the booksellers
115 for my $i ( 0 .. scalar(@booksellers) - 1 ) {
116 $booksellers[$i] = field_filter( $booksellers[$i] );
117 delete $booksellers[$i]->{basketcount};
120 $sample_supplier1->{id} = $id_supplier1;
121 is( scalar(@booksellers), $count + 2, "Get Supplier1 and Supplier2" );
122 my @tab = ( $sample_supplier1, $sample_supplier2 );
123 is_deeply( \@booksellers, \@tab,
124 "Returns right fields of Supplier1 and Supplier2" );
127 my @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} );
128 #FIXME : if there is 0 basket, GetBookSeller returns 1 as basketcount
129 #is( $bookseller1[0]->{basketcount}, 0, 'Supplier1 has 0 basket' );
131 C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' );
133 C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' );
134 @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} );
135 is( $bookseller1[0]->{basketcount}, 2, 'Supplier1 has 2 baskets' );
137 #Test GetBookSellerFromId
138 my $bookseller1fromid = C4::Bookseller::GetBookSellerFromId();
139 is( $bookseller1fromid, undef,
140 "GetBookSellerFromId returns undef if no id given" );
141 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
142 $bookseller1fromid = field_filter($bookseller1fromid);
143 delete $bookseller1fromid->{basketcount};
144 delete $bookseller1fromid->{subscriptioncount};
145 is_deeply( $bookseller1fromid, $sample_supplier1,
146 "Get Supplier1 (GetBookSellerFromId)" );
149 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
150 is( $bookseller1fromid->{basketcount}, 2, 'Supplier1 has 2 baskets' );
152 #Test subscriptioncount
153 my $dt_today = dt_from_string;
154 my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
156 my $dt_today1 = dt_from_string;
157 my $dur5 = DateTime::Duration->new( days => -5 );
158 $dt_today1->add_duration($dur5);
159 my $daysago5 = output_pref({ dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
161 my $budgetperiod = C4::Budgets::AddBudgetPeriod({
162 budget_period_startdate => $daysago5,
163 budget_period_enddate => $today,
164 budget_period_description => "budget desc"
166 my $id_budget = AddBudget({
167 budget_code => "CODE",
168 budget_amount => "123.132",
169 budget_name => "Budgetname",
170 budget_notes => "This is a note",
171 budget_period_id => $budgetperiod
173 my $bib = MARC::Record->new();
175 MARC::Field->new('245', ' ', ' ', a => 'Journal of ethnology'),
176 MARC::Field->new('500', ' ', ' ', a => 'bib notes'),
178 my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, '');
179 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
180 is( $bookseller1fromid->{subscriptioncount},
181 0, 'Supplier1 has 0 subscription' );
183 my $id_subscription1 = NewSubscription(
184 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
185 '01-01-2013',undef, undef, undef, undef,
186 undef, undef, undef, undef, undef, undef,
187 1, "subscription notes",undef, '01-01-2013', undef, undef,
188 undef, 'CALL ABC', 0, "intnotes", 0,
189 undef, undef, 0, undef, '2013-11-30', 0
192 my @subscriptions = SearchSubscriptions({biblionumber => $biblionumber});
193 is($subscriptions[0]->{publicnotes}, 'subscription notes', 'subscription search results include public notes (bug 10689)');
195 my $id_subscription2 = 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 DEF', 0, "intnotes", 0,
201 undef, undef, 0, undef, '2013-07-31', 0
204 $bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1);
205 is( $bookseller1fromid->{subscriptioncount},
206 2, 'Supplier1 has 2 subscriptions' );
209 $sample_supplier2 = {
211 name => 'Name2 modified',
212 address1 => 'address1_2 modified',
213 address2 => 'address2-2 modified',
214 address3 => 'address3_2 modified',
215 address4 => 'address4_2 modified',
216 postal => 'postal2 modified',
217 phone => 'phone2 modified',
218 accountnumber => 'accountnumber2 modified',
219 fax => 'fax2 modified',
220 url => 'url2 modified',
225 gstrate => '2.0000 ',
226 discount => '2.0000',
227 notes => 'notes2 modified',
231 my $modif1 = C4::Bookseller::ModBookseller();
233 "ModBookseller returns undef if no params given - Nothing happened" );
234 $modif1 = C4::Bookseller::ModBookseller($sample_supplier2);
235 is( $modif1, 1, "ModBookseller modifies only the supplier2" );
236 is( scalar( C4::Bookseller::GetBookSeller('') ),
237 $count + 2, "Supplier2 has been modified - Nothing added" );
239 $modif1 = C4::Bookseller::ModBookseller(
246 # "ModBookseller returns OEO if the id doesnt exist - Nothing modified" );
248 #Test GetBooksellersWithLateOrders
250 my $sample_supplier3 = {
252 address1 => 'address1_3',
253 address2 => 'address1-3',
254 address3 => 'address1_3',
255 address4 => 'address1_3',
258 accountnumber => 'accountnumber3',
266 discount => '3.0000',
270 my $sample_supplier4 = {
272 address1 => 'address1_4',
273 address2 => 'address1-4',
274 address3 => 'address1_4',
275 address4 => 'address1_4',
278 accountnumber => 'accountnumber4',
286 discount => '3.0000',
289 my $id_supplier3 = C4::Bookseller::AddBookseller($sample_supplier3);
290 my $id_supplier4 = C4::Bookseller::AddBookseller($sample_supplier4);
294 C4::Acquisition::NewBasket( $id_supplier3, 'authorisedby3', 'basketname3',
297 C4::Acquisition::NewBasket( $id_supplier4, 'authorisedby4', 'basketname4',
300 #Modify the basket to add a close date
302 basketno => $sample_basket1,
304 booksellerid => $id_supplier1
308 basketno => $sample_basket2,
309 closedate => $daysago5,
310 booksellerid => $id_supplier2
313 my $dt_today2 = dt_from_string;
314 my $dur10 = DateTime::Duration->new( days => -10 );
315 $dt_today2->add_duration($dur10);
316 my $daysago10 = output_pref({ dt => $dt_today2, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
318 basketno => $sample_basket3,
319 closedate => $daysago10,
323 basketno => $sample_basket4,
326 ModBasket($basket1info);
327 ModBasket($basket2info);
328 ModBasket($basket3info);
329 ModBasket($basket4info);
332 my $id_subscription3 = NewSubscription(
333 undef, "BRANCH1", $id_supplier1, undef, $id_budget, $biblionumber,
334 '01-01-2013',undef, undef, undef, undef,
335 undef, undef, undef, undef, undef, undef,
336 1, "subscription notes",undef, '01-01-2013', undef, undef,
337 undef, undef, 0, "intnotes", 0,
338 undef, undef, 0, 'LOCA', '2013-12-31', 0
341 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
342 is(scalar(@subscriptions), 3, 'search for subscriptions by expiration date');
343 @subscriptions = SearchSubscriptions({expiration_date => '2013-08-15'});
344 is(scalar(@subscriptions), 1, 'search for subscriptions by expiration date');
345 @subscriptions = SearchSubscriptions({callnumber => 'CALL'});
346 is(scalar(@subscriptions), 2, 'search for subscriptions by call number');
347 @subscriptions = SearchSubscriptions({callnumber => 'DEF'});
348 is(scalar(@subscriptions), 1, 'search for subscriptions by call number');
349 @subscriptions = SearchSubscriptions({location => 'LOCA'});
350 is(scalar(@subscriptions), 1, 'search for subscriptions by location');
353 my ( $ordernumber1, $ordernumber2, $ordernumber3, $ordernumber4 );
354 my ( $basketno1, $basketno2, $basketno3, $basketno4 );
355 ( $basketno1, $ordernumber1 ) = C4::Acquisition::NewOrder(
357 basketno => $sample_basket1,
359 biblionumber => $biblionumber,
360 budget_id => $id_budget,
361 entrydate => '01-01-2013',
363 notes => "This is a note1",
366 subscriptionid => $id_subscription1,
367 quantityreceived => 2,
370 datereceived => '01-06-2013'
373 ( $basketno2, $ordernumber2 ) = C4::Acquisition::NewOrder(
375 basketno => $sample_basket2,
377 biblionumber => $biblionumber,
378 budget_id => $id_budget,
379 entrydate => '01-01-2013',
381 notes => "This is a note2",
384 subscriptionid => $id_subscription2,
389 ( $basketno3, $ordernumber3 ) = C4::Acquisition::NewOrder(
391 basketno => $sample_basket3,
393 biblionumber => $biblionumber,
394 budget_id => $id_budget,
395 entrydate => '02-02-2013',
397 notes => "This is a note3",
400 subscriptionid => $id_subscription3,
405 ( $basketno4, $ordernumber4 ) = C4::Acquisition::NewOrder(
407 basketno => $sample_basket4,
409 biblionumber => $biblionumber,
410 budget_id => $id_budget,
411 entrydate => '02-02-2013',
413 notes => "This is a note3",
416 subscriptionid => $id_subscription3,
419 quantityreceived => 20
425 # Supplier1: delivery -> undef Basket1 : closedate -> today
426 # Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5
427 # Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10
428 #Case 1 : Without parameters:
429 # quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
430 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
431 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
432 # quantityreceived = quantity -NOT LATE-
433 my %suppliers = C4::Bookseller::GetBooksellersWithLateOrders();
434 ok( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" );
435 ok( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" );
436 ok( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" );
437 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" )
438 ; # Quantity = quantityreceived
440 #Case 2: With $delay = 4
441 # today + 0 > now-$delay -NOT LATE-
442 # (today-5) + 2 <= now() - $delay -NOT LATE-
443 # (today-10) + 3 <= now() - $delay -LATE-
444 # quantityreceived = quantity -NOT LATE-
445 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 4, undef, undef );
446 isnt( exists( $suppliers{$id_supplier1} ),
447 1, "Supplier1 has late orders but today > now() - 4 days" );
448 isnt( exists( $suppliers{$id_supplier2} ),
449 1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" );
450 ok( exists( $suppliers{$id_supplier3} ),
451 "Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" );
452 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
454 #Case 3: With $delay = -1
457 { $bslo = C4::Bookseller::GetBooksellersWithLateOrders( -1, undef, undef ) }
458 qr/^WARNING: GetBooksellerWithLateOrders is called with a negative value/,
459 "GetBooksellerWithLateOrders prints a warning on negative values";
461 is( $bslo, undef, "-1 is a wrong value for a delay" );
463 #Case 4: With $delay = 0
464 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0)
465 # today-5 <= now() - $delay+2 -LATE-
466 # today-10 <= now() - $delay+3 -LATE-
467 # quantityreceived = quantity -NOT LATE-
468 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 0, undef, undef );
470 ok( exists( $suppliers{$id_supplier1} ),
471 "Supplier1 has late orders but $today == now() - 0 days" )
473 ok( exists( $suppliers{$id_supplier2} ),
474 "Supplier2 has late orders and $daysago5 <= now() - 2" );
475 ok( exists( $suppliers{$id_supplier3} ),
476 "Supplier3 has late orders and $daysago10 <= now() - 3" );
477 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
479 #Case 5 : With $estimateddeliverydatefrom = today-4
480 # today >= today-4 -NOT LATE-
481 # (today-5)+ 2 days >= today-4 -LATE-
482 # (today-10) + 3 days < today-4 -NOT LATE-
483 # quantityreceived = quantity -NOT LATE-
484 my $dt_today3 = dt_from_string;
485 my $dur4 = DateTime::Duration->new( days => -4 );
486 $dt_today3->add_duration($dur4);
487 my $daysago4 = output_pref({ dt => $dt_today3, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
489 C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago4, undef );
491 ok( exists( $suppliers{$id_supplier1} ),
492 "Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" );
493 ok( exists( $suppliers{$id_supplier2} ),
494 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " );
495 isnt( exists( $suppliers{$id_supplier3} ),
496 1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " );
497 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
499 #Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5
500 # $daysago10<$daysago5<today -NOT LATE-
501 # $daysago10<$daysago5<$daysago5 +2 -NOT lATE-
502 # $daysago10<$daysago10 +3 <$daysago5 -LATE-
503 # quantityreceived = quantity -NOT LATE-
504 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10,
506 isnt( exists( $suppliers{$id_supplier1} ),
507 1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" );
509 exists( $suppliers{$id_supplier2} ),
511 "Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2"
514 exists( $suppliers{$id_supplier3} ),
515 "Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5"
517 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
519 #Case 7: With $estimateddeliverydateto = today-5
520 # $today >= $daysago5 -NOT LATE-
521 # $daysago5 + 2 days > $daysago5 -NOT LATE-
522 # $daysago10 + 3 <+ $daysago5 -LATE-
523 # quantityreceived = quantity -NOT LATE-
525 C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago5 );
526 isnt( exists( $suppliers{$id_supplier1} ),
528 "Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" );
529 isnt( exists( $suppliers{$id_supplier2} ),
530 1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " );
531 ok( exists( $suppliers{$id_supplier3} ),
532 "Supplier3 has late orders and $daysago10 + 3 <= $daysago5" );
533 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
535 #Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay
536 #Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5
537 # $daysago4<today<=$today and $today<now()-3 -NOT LATE-
538 # $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE-
539 # $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE-
540 # quantityreceived = quantity -NOT LATE-
542 C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago4, $today );
544 exists( $suppliers{$id_supplier1} ),
546 "Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3"
549 exists( $suppliers{$id_supplier2} ),
550 "Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days"
553 exists( $suppliers{$id_supplier3} ),
554 "Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days"
556 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
558 #Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3
559 # $today < $daysago5 and $today > $today-5 -NOT LATE-
560 # $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE-
561 # $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE-
562 # quantityreceived = quantity -NOT LATE-
564 C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago5, undef );
565 isnt( exists( $suppliers{$id_supplier1} ),
566 1, "$today < $daysago10 and $today > $today-3" );
568 exists( $suppliers{$id_supplier2} ),
569 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2"
572 exists( $suppliers{$id_supplier3} ),
574 "Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 "
576 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
578 #Test with $estimateddeliverydateto and $delay
579 #Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5
580 # today > $daysago5 today > now() -5 -NOT LATE-
581 # $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE-
582 # $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE-
583 # quantityreceived = quantity -NOT LATE-
585 C4::Bookseller::GetBooksellersWithLateOrders( 5, undef, $daysago5 );
586 isnt( exists( $suppliers{$id_supplier1} ),
587 1, "Supplier2 has late orders but today > $daysago5 today > now() -5" );
589 exists( $suppliers{$id_supplier2} ),
591 "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days"
594 exists( $suppliers{$id_supplier3} ),
595 "Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days "
597 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
599 #Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10
600 # $daysago10==$daysago10==$daysago10 -NOT LATE-
601 # $daysago10==$daysago10<$daysago5+2-NOT lATE-
602 # $daysago10==$daysago10 <$daysago10+3-LATE-
603 # quantityreceived = quantity -NOT LATE-
605 #Basket1 closedate -> $daysago10
607 basketno => $sample_basket1,
608 closedate => $daysago10,
610 ModBasket($basket1info);
611 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10,
613 ok( exists( $suppliers{$id_supplier1} ),
614 "Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " )
616 isnt( exists( $suppliers{$id_supplier2} ),
618 "Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" );
619 isnt( exists( $suppliers{$id_supplier3} ),
621 "Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" );
622 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
624 #Case 12: closedate == $estimateddeliverydatefrom =today-10
626 C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10, undef );
627 ok( exists( $suppliers{$id_supplier1} ),
628 "Supplier1 has late orders and $daysago10==$daysago10 " );
630 #Case 13: closedate == $estimateddeliverydateto =today-10
632 C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago10 );
633 ok( exists( $suppliers{$id_supplier1} ),
634 "Supplier1 has late orders and $daysago10==$daysago10 " )
637 C4::Context->_new_userenv('DUMMY SESSION');
638 C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', '');
639 my $userenv = C4::Context->userenv;
641 my $module = Test::MockModule->new('C4::Auth');
645 # simulate user that has serials permissions but
647 my ($userid, $flagsrequired) = @_;
648 return 0 if 'superserials' eq ($flagsrequired->{serials} // 0);
649 return exists($flagsrequired->{serials});
653 C4::Context->set_preference('IndependentBranches', 0);
654 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
656 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
658 'ordinary user can see all subscriptions with IndependentBranches off'
661 C4::Context->set_preference('IndependentBranches', 1);
662 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
664 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
666 'ordinary user can see only their library\'s subscriptions with IndependentBranches on'
669 # don the cape and turn into Superlibrarian!
670 C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', '');
671 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
673 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
675 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
677 #Test contact editing
678 my $booksellerid = C4::Bookseller::AddBookseller(
681 address1 => "bookseller's address",
686 { name => 'John Smith', phone => '0123456x1' },
687 { name => 'Leo Tolstoy', phone => '0123456x2' },
691 @booksellers = C4::Bookseller::GetBookSeller('my vendor');
693 ( grep { $_->{'id'} == $booksellerid } @booksellers ),
694 'GetBookSeller returns correct record when passed a name'
697 my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
698 is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' );
699 is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' );
700 is( ref $bookseller->{'contacts'},
701 'ARRAY', 'GetBookSellerFromId returns arrayref of contacts' );
703 ref $bookseller->{'contacts'}->[0],
704 'C4::Bookseller::Contact',
705 'First contact is a contact object'
707 is( $bookseller->{'contacts'}->[0]->phone,
708 '0123456x1', 'Contact has expected phone number' );
709 is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' );
711 pop @{ $bookseller->{'contacts'} };
712 $bookseller->{'name'} = 'your vendor';
713 $bookseller->{'contacts'}->[0]->phone('654321');
714 C4::Bookseller::ModBookseller($bookseller);
716 $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
717 is( $bookseller->{'name'}, 'your vendor',
718 'Successfully changed name of vendor' );
719 is( $bookseller->{'contacts'}->[0]->phone,
721 'Successfully changed contact phone number by modifying bookseller hash' );
722 is( scalar @{ $bookseller->{'contacts'} },
723 1, 'Only one contact after modification' );
725 C4::Bookseller::ModBookseller( $bookseller,
726 [ { name => 'John Jacob Jingleheimer Schmidt' } ] );
728 $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
730 $bookseller->{'contacts'}->[0]->name,
731 'John Jacob Jingleheimer Schmidt',
732 'Changed name of contact'
734 is( $bookseller->{'contacts'}->[0]->phone,
735 undef, 'Removed phone number from contact' );
736 is( scalar @{ $bookseller->{'contacts'} },
737 1, 'Only one contact after modification' );
742 #field_filter filters the useless fields or foreign keys
743 #NOTE: all the fields of aqbookseller arent considered
744 #returns a cleaned structure
749 'bookselleremail', 'booksellerfax',
750 'booksellerurl', 'othersupplier',
751 'currency', 'invoiceprice',
752 'listprice', 'contacts'
756 if ( grep { /^$field$/ } keys %$struct ) {
757 delete $struct->{$field};