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 => $basketno1,
304 booksellerid => $id_supplier1
308 basketno => $basketno2,
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 => $basketno3,
319 closedate => $daysago10,
323 basketno => $basketno4,
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 $ordernumber1 = C4::Acquisition::NewOrder(
356 basketno => $basketno1,
358 biblionumber => $biblionumber,
359 budget_id => $id_budget,
360 entrydate => '01-01-2013',
362 notes => "This is a note1",
365 subscriptionid => $id_subscription1,
366 quantityreceived => 2,
369 datereceived => '01-06-2013'
372 $ordernumber2 = C4::Acquisition::NewOrder(
374 basketno => $basketno2,
376 biblionumber => $biblionumber,
377 budget_id => $id_budget,
378 entrydate => '01-01-2013',
380 notes => "This is a note2",
383 subscriptionid => $id_subscription2,
388 $ordernumber3 = C4::Acquisition::NewOrder(
390 basketno => $basketno3,
392 biblionumber => $biblionumber,
393 budget_id => $id_budget,
394 entrydate => '02-02-2013',
396 notes => "This is a note3",
399 subscriptionid => $id_subscription3,
404 $ordernumber4 = C4::Acquisition::NewOrder(
406 basketno => $basketno4,
408 biblionumber => $biblionumber,
409 budget_id => $id_budget,
410 entrydate => '02-02-2013',
412 notes => "This is a note3",
415 subscriptionid => $id_subscription3,
418 quantityreceived => 20
424 # Supplier1: delivery -> undef Basket1 : closedate -> today
425 # Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5
426 # Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10
427 #Case 1 : Without parameters:
428 # quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
429 # datereceived !null 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 # quantityreceived = quantity -NOT LATE-
432 my %suppliers = C4::Bookseller::GetBooksellersWithLateOrders();
433 ok( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" );
434 ok( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" );
435 ok( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" );
436 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" )
437 ; # Quantity = quantityreceived
439 #Case 2: With $delay = 4
440 # today + 0 > now-$delay -NOT LATE-
441 # (today-5) + 2 <= now() - $delay -NOT LATE-
442 # (today-10) + 3 <= now() - $delay -LATE-
443 # quantityreceived = quantity -NOT LATE-
444 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 4, undef, undef );
445 isnt( exists( $suppliers{$id_supplier1} ),
446 1, "Supplier1 has late orders but today > now() - 4 days" );
447 isnt( exists( $suppliers{$id_supplier2} ),
448 1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" );
449 ok( exists( $suppliers{$id_supplier3} ),
450 "Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" );
451 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
453 #Case 3: With $delay = -1
456 { $bslo = C4::Bookseller::GetBooksellersWithLateOrders( -1, undef, undef ) }
457 qr/^WARNING: GetBooksellerWithLateOrders is called with a negative value/,
458 "GetBooksellerWithLateOrders prints a warning on negative values";
460 is( $bslo, undef, "-1 is a wrong value for a delay" );
462 #Case 4: With $delay = 0
463 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0)
464 # today-5 <= now() - $delay+2 -LATE-
465 # today-10 <= now() - $delay+3 -LATE-
466 # quantityreceived = quantity -NOT LATE-
467 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( 0, undef, undef );
469 ok( exists( $suppliers{$id_supplier1} ),
470 "Supplier1 has late orders but $today == now() - 0 days" )
472 ok( exists( $suppliers{$id_supplier2} ),
473 "Supplier2 has late orders and $daysago5 <= now() - 2" );
474 ok( exists( $suppliers{$id_supplier3} ),
475 "Supplier3 has late orders and $daysago10 <= now() - 3" );
476 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
478 #Case 5 : With $estimateddeliverydatefrom = today-4
479 # today >= today-4 -NOT LATE-
480 # (today-5)+ 2 days >= today-4 -LATE-
481 # (today-10) + 3 days < today-4 -NOT LATE-
482 # quantityreceived = quantity -NOT LATE-
483 my $dt_today3 = dt_from_string;
484 my $dur4 = DateTime::Duration->new( days => -4 );
485 $dt_today3->add_duration($dur4);
486 my $daysago4 = output_pref({ dt => $dt_today3, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
488 C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago4, undef );
490 ok( exists( $suppliers{$id_supplier1} ),
491 "Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" );
492 ok( exists( $suppliers{$id_supplier2} ),
493 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " );
494 isnt( exists( $suppliers{$id_supplier3} ),
495 1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " );
496 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
498 #Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5
499 # $daysago10<$daysago5<today -NOT LATE-
500 # $daysago10<$daysago5<$daysago5 +2 -NOT lATE-
501 # $daysago10<$daysago10 +3 <$daysago5 -LATE-
502 # quantityreceived = quantity -NOT LATE-
503 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10,
505 isnt( exists( $suppliers{$id_supplier1} ),
506 1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" );
508 exists( $suppliers{$id_supplier2} ),
510 "Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2"
513 exists( $suppliers{$id_supplier3} ),
514 "Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5"
516 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
518 #Case 7: With $estimateddeliverydateto = today-5
519 # $today >= $daysago5 -NOT LATE-
520 # $daysago5 + 2 days > $daysago5 -NOT LATE-
521 # $daysago10 + 3 <+ $daysago5 -LATE-
522 # quantityreceived = quantity -NOT LATE-
524 C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago5 );
525 isnt( exists( $suppliers{$id_supplier1} ),
527 "Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" );
528 isnt( exists( $suppliers{$id_supplier2} ),
529 1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " );
530 ok( exists( $suppliers{$id_supplier3} ),
531 "Supplier3 has late orders and $daysago10 + 3 <= $daysago5" );
532 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
534 #Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay
535 #Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5
536 # $daysago4<today<=$today and $today<now()-3 -NOT LATE-
537 # $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE-
538 # $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE-
539 # quantityreceived = quantity -NOT LATE-
541 C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago4, $today );
543 exists( $suppliers{$id_supplier1} ),
545 "Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3"
548 exists( $suppliers{$id_supplier2} ),
549 "Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days"
552 exists( $suppliers{$id_supplier3} ),
553 "Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days"
555 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
557 #Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3
558 # $today < $daysago5 and $today > $today-5 -NOT LATE-
559 # $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE-
560 # $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE-
561 # quantityreceived = quantity -NOT LATE-
563 C4::Bookseller::GetBooksellersWithLateOrders( 3, $daysago5, undef );
564 isnt( exists( $suppliers{$id_supplier1} ),
565 1, "$today < $daysago10 and $today > $today-3" );
567 exists( $suppliers{$id_supplier2} ),
568 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2"
571 exists( $suppliers{$id_supplier3} ),
573 "Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 "
575 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
577 #Test with $estimateddeliverydateto and $delay
578 #Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5
579 # today > $daysago5 today > now() -5 -NOT LATE-
580 # $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE-
581 # $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE-
582 # quantityreceived = quantity -NOT LATE-
584 C4::Bookseller::GetBooksellersWithLateOrders( 5, undef, $daysago5 );
585 isnt( exists( $suppliers{$id_supplier1} ),
586 1, "Supplier2 has late orders but today > $daysago5 today > now() -5" );
588 exists( $suppliers{$id_supplier2} ),
590 "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days"
593 exists( $suppliers{$id_supplier3} ),
594 "Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days "
596 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
598 #Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10
599 # $daysago10==$daysago10==$daysago10 -NOT LATE-
600 # $daysago10==$daysago10<$daysago5+2-NOT lATE-
601 # $daysago10==$daysago10 <$daysago10+3-LATE-
602 # quantityreceived = quantity -NOT LATE-
604 #Basket1 closedate -> $daysago10
606 basketno => $basketno1,
607 closedate => $daysago10,
609 ModBasket($basket1info);
610 %suppliers = C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10,
612 ok( exists( $suppliers{$id_supplier1} ),
613 "Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " )
615 isnt( exists( $suppliers{$id_supplier2} ),
617 "Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" );
618 isnt( exists( $suppliers{$id_supplier3} ),
620 "Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" );
621 isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
623 #Case 12: closedate == $estimateddeliverydatefrom =today-10
625 C4::Bookseller::GetBooksellersWithLateOrders( undef, $daysago10, undef );
626 ok( exists( $suppliers{$id_supplier1} ),
627 "Supplier1 has late orders and $daysago10==$daysago10 " );
629 #Case 13: closedate == $estimateddeliverydateto =today-10
631 C4::Bookseller::GetBooksellersWithLateOrders( undef, undef, $daysago10 );
632 ok( exists( $suppliers{$id_supplier1} ),
633 "Supplier1 has late orders and $daysago10==$daysago10 " )
636 C4::Context->_new_userenv('DUMMY SESSION');
637 C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', '');
638 my $userenv = C4::Context->userenv;
640 my $module = Test::MockModule->new('C4::Auth');
644 # simulate user that has serials permissions but
646 my ($userid, $flagsrequired) = @_;
647 return 0 if 'superserials' eq ($flagsrequired->{serials} // 0);
648 return exists($flagsrequired->{serials});
652 C4::Context->set_preference('IndependentBranches', 0);
653 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
655 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
657 'ordinary user can see all subscriptions with IndependentBranches off'
660 C4::Context->set_preference('IndependentBranches', 1);
661 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
663 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
665 'ordinary user can see only their library\'s subscriptions with IndependentBranches on'
668 # don the cape and turn into Superlibrarian!
669 C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', '');
670 @subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'});
672 scalar(grep { !$_->{cannotdisplay} } @subscriptions ),
674 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
676 #Test contact editing
677 my $booksellerid = C4::Bookseller::AddBookseller(
680 address1 => "bookseller's address",
685 { name => 'John Smith', phone => '0123456x1' },
686 { name => 'Leo Tolstoy', phone => '0123456x2' },
690 @booksellers = C4::Bookseller::GetBookSeller('my vendor');
692 ( grep { $_->{'id'} == $booksellerid } @booksellers ),
693 'GetBookSeller returns correct record when passed a name'
696 my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
697 is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' );
698 is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' );
699 is( ref $bookseller->{'contacts'},
700 'ARRAY', 'GetBookSellerFromId returns arrayref of contacts' );
702 ref $bookseller->{'contacts'}->[0],
703 'C4::Bookseller::Contact',
704 'First contact is a contact object'
706 is( $bookseller->{'contacts'}->[0]->phone,
707 '0123456x1', 'Contact has expected phone number' );
708 is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' );
710 pop @{ $bookseller->{'contacts'} };
711 $bookseller->{'name'} = 'your vendor';
712 $bookseller->{'contacts'}->[0]->phone('654321');
713 C4::Bookseller::ModBookseller($bookseller);
715 $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
716 is( $bookseller->{'name'}, 'your vendor',
717 'Successfully changed name of vendor' );
718 is( $bookseller->{'contacts'}->[0]->phone,
720 'Successfully changed contact phone number by modifying bookseller hash' );
721 is( scalar @{ $bookseller->{'contacts'} },
722 1, 'Only one contact after modification' );
724 C4::Bookseller::ModBookseller( $bookseller,
725 [ { name => 'John Jacob Jingleheimer Schmidt' } ] );
727 $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid);
729 $bookseller->{'contacts'}->[0]->name,
730 'John Jacob Jingleheimer Schmidt',
731 'Changed name of contact'
733 is( $bookseller->{'contacts'}->[0]->phone,
734 undef, 'Removed phone number from contact' );
735 is( scalar @{ $bookseller->{'contacts'} },
736 1, 'Only one contact after modification' );
741 #field_filter filters the useless fields or foreign keys
742 #NOTE: all the fields of aqbookseller arent considered
743 #returns a cleaned structure
748 'bookselleremail', 'booksellerfax',
749 'booksellerurl', 'othersupplier',
750 'currency', 'invoiceprice',
751 'listprice', 'contacts'
755 if ( grep { /^$field$/ } keys %$struct ) {
756 delete $struct->{$field};