5 use Test
::More tests
=> 88;
11 use DateTime
::Duration
;
17 use Koha
::Acquisition
::Order
;
20 use_ok
('C4::Bookseller');
21 use_ok
('Koha::Acquisition::Bookseller');
29 GetBooksellersWithLateOrders
34 my $dbh = C4
::Context
->dbh;
35 $dbh->{RaiseError
} = 1;
36 $dbh->{AutoCommit
} = 0;
39 $dbh->do(q
|DELETE FROM aqorders
|);
40 $dbh->do(q
|DELETE FROM aqbasket
|);
41 $dbh->do(q
|DELETE FROM aqbooksellers
|);
42 $dbh->do(q
|DELETE FROM subscription
|);
45 my $count = scalar( Koha
::Acquisition
::Bookseller
->search() );
46 my $sample_supplier1 = {
48 address1
=> 'address1_1',
49 address2
=> 'address1-2',
50 address3
=> 'address1_2',
51 address4
=> 'address1_2',
54 accountnumber
=> 'accountnumber1',
66 my $sample_supplier2 = {
68 address1
=> 'address1_2',
69 address2
=> 'address2-2',
70 address3
=> 'address3_2',
71 address4
=> 'address4_2',
74 accountnumber
=> 'accountnumber2',
87 my $id_supplier1 = C4
::Bookseller
::AddBookseller
($sample_supplier1);
88 my $id_supplier2 = C4
::Bookseller
::AddBookseller
($sample_supplier2);
90 #my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null
92 like
( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
93 like
( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
94 my @b = Koha
::Acquisition
::Bookseller
->search();
96 $count + 2, "Supplier1 and Supplier2 have been added" );
99 my $del = C4
::Bookseller
::DelBookseller
($id_supplier1);
100 is
( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
101 my $b = Koha
::Acquisition
::Bookseller
->fetch({id
=> $id_supplier1});
103 undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" );
106 my @bookseller2 = Koha
::Acquisition
::Bookseller
->search({name
=> $sample_supplier2->{name
} });
107 is
( scalar(@bookseller2), 1, "Get only Supplier2" );
108 $bookseller2[0] = field_filter
( $bookseller2[0] );
110 $sample_supplier2->{id
} = $id_supplier2;
111 is_deeply
( $bookseller2[0], $sample_supplier2,
112 "Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" );
114 $id_supplier1 = C4
::Bookseller
::AddBookseller
($sample_supplier1);
115 my @booksellers = Koha
::Acquisition
::Bookseller
->search(); #NOTE :without params, it returns all the booksellers
116 for my $i ( 0 .. scalar(@booksellers) - 1 ) {
117 $booksellers[$i] = field_filter
( $booksellers[$i] );
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 = Koha
::Acquisition
::Bookseller
->search({name
=> $sample_supplier1->{name
} });
128 is
( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' );
130 C4
::Acquisition
::NewBasket
( $id_supplier1, 'authorisedby1', 'basketname1' );
132 C4
::Acquisition
::NewBasket
( $id_supplier1, 'authorisedby2', 'basketname2' );
133 @bookseller1 = Koha
::Acquisition
::Bookseller
::search
({ name
=> $sample_supplier1->{name
} });
134 is
( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' );
136 #Test Koha::Acquisition::Bookseller->new using id
137 my $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch;
138 is
( $bookseller1fromid, undef,
139 "fetch returns undef if no id given" );
140 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1});
141 $bookseller1fromid = field_filter
($bookseller1fromid);
142 is_deeply
( $bookseller1fromid, $sample_supplier1,
143 "Get Supplier1 (fetch a bookseller by id)" );
146 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1});
147 is
( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' );
149 #Test subscription_count
150 my $dt_today = dt_from_string
;
151 my $today = output_pref
({ dt
=> $dt_today, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
153 my $dt_today1 = dt_from_string
;
154 my $dur5 = DateTime
::Duration
->new( days
=> -5 );
155 $dt_today1->add_duration($dur5);
156 my $daysago5 = output_pref
({ dt
=> $dt_today1, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
158 my $budgetperiod = C4
::Budgets
::AddBudgetPeriod
({
159 budget_period_startdate
=> $daysago5,
160 budget_period_enddate
=> $today,
161 budget_period_description
=> "budget desc"
163 my $id_budget = AddBudget
({
164 budget_code
=> "CODE",
165 budget_amount
=> "123.132",
166 budget_name
=> "Budgetname",
167 budget_notes
=> "This is a note",
168 budget_period_id
=> $budgetperiod
170 my $bib = MARC
::Record
->new();
172 MARC
::Field
->new('245', ' ', ' ', a
=> 'Journal of ethnology'),
173 MARC
::Field
->new('500', ' ', ' ', a
=> 'bib notes'),
175 my ($biblionumber, $biblioitemnumber) = AddBiblio
($bib, '');
176 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1 });
177 is
( $bookseller1fromid->subscription_count,
178 0, 'Supplier1 has 0 subscription' );
180 my $id_subscription1 = NewSubscription
(
181 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
182 '01-01-2013',undef, undef, undef, undef,
183 undef, undef, undef, undef, undef, undef,
184 1, "subscription notes",undef, '01-01-2013', undef, undef,
185 undef, 'CALL ABC', 0, "intnotes", 0,
186 undef, undef, 0, undef, '2013-11-30', 0
189 my @subscriptions = SearchSubscriptions
({biblionumber
=> $biblionumber});
190 is
($subscriptions[0]->{publicnotes
}, 'subscription notes', 'subscription search results include public notes (bug 10689)');
192 my $id_subscription2 = NewSubscription
(
193 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
194 '01-01-2013',undef, undef, undef, undef,
195 undef, undef, undef, undef, undef, undef,
196 1, "subscription notes",undef, '01-01-2013', undef, undef,
197 undef, 'CALL DEF', 0, "intnotes", 0,
198 undef, undef, 0, undef, '2013-07-31', 0
201 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1 });
202 is
( $bookseller1fromid->subscription_count,
203 2, 'Supplier1 has 2 subscriptions' );
206 $sample_supplier2 = {
208 name
=> 'Name2 modified',
209 address1
=> 'address1_2 modified',
210 address2
=> 'address2-2 modified',
211 address3
=> 'address3_2 modified',
212 address4
=> 'address4_2 modified',
213 postal
=> 'postal2 modified',
214 phone
=> 'phone2 modified',
215 accountnumber
=> 'accountnumber2 modified',
216 fax
=> 'fax2 modified',
217 url
=> 'url2 modified',
222 gstrate
=> '2.0000 ',
223 discount
=> '2.0000',
224 notes
=> 'notes2 modified',
228 my $modif1 = C4
::Bookseller
::ModBookseller
();
230 "ModBookseller returns undef if no params given - Nothing happened" );
231 $modif1 = C4
::Bookseller
::ModBookseller
($sample_supplier2);
232 is
( $modif1, 1, "ModBookseller modifies only the supplier2" );
233 is
( scalar( Koha
::Acquisition
::Bookseller
->search ),
234 $count + 2, "Supplier2 has been modified - Nothing added" );
236 $modif1 = C4
::Bookseller
::ModBookseller
(
243 # "ModBookseller returns OEO if the id doesnt exist - Nothing modified" );
245 #Test GetBooksellersWithLateOrders
247 my $sample_supplier3 = {
249 address1
=> 'address1_3',
250 address2
=> 'address1-3',
251 address3
=> 'address1_3',
252 address4
=> 'address1_3',
255 accountnumber
=> 'accountnumber3',
263 discount
=> '3.0000',
267 my $sample_supplier4 = {
269 address1
=> 'address1_4',
270 address2
=> 'address1-4',
271 address3
=> 'address1_4',
272 address4
=> 'address1_4',
275 accountnumber
=> 'accountnumber4',
283 discount
=> '3.0000',
286 my $id_supplier3 = C4
::Bookseller
::AddBookseller
($sample_supplier3);
287 my $id_supplier4 = C4
::Bookseller
::AddBookseller
($sample_supplier4);
291 C4
::Acquisition
::NewBasket
( $id_supplier3, 'authorisedby3', 'basketname3',
294 C4
::Acquisition
::NewBasket
( $id_supplier4, 'authorisedby4', 'basketname4',
297 #Modify the basket to add a close date
299 basketno
=> $basketno1,
301 booksellerid
=> $id_supplier1
305 basketno
=> $basketno2,
306 closedate
=> $daysago5,
307 booksellerid
=> $id_supplier2
310 my $dt_today2 = dt_from_string
;
311 my $dur10 = DateTime
::Duration
->new( days
=> -10 );
312 $dt_today2->add_duration($dur10);
313 my $daysago10 = output_pref
({ dt
=> $dt_today2, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
315 basketno
=> $basketno3,
316 closedate
=> $daysago10,
320 basketno
=> $basketno4,
323 ModBasket
($basket1info);
324 ModBasket
($basket2info);
325 ModBasket
($basket3info);
326 ModBasket
($basket4info);
329 my $id_subscription3 = NewSubscription
(
330 undef, "BRANCH1", $id_supplier1, undef, $id_budget, $biblionumber,
331 '01-01-2013',undef, undef, undef, undef,
332 undef, undef, undef, undef, undef, undef,
333 1, "subscription notes",undef, '01-01-2013', undef, undef,
334 undef, undef, 0, "intnotes", 0,
335 undef, undef, 0, 'LOCA', '2013-12-31', 0
338 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
339 is
(scalar(@subscriptions), 3, 'search for subscriptions by expiration date');
340 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-08-15'});
341 is
(scalar(@subscriptions), 1, 'search for subscriptions by expiration date');
342 @subscriptions = SearchSubscriptions
({callnumber
=> 'CALL'});
343 is
(scalar(@subscriptions), 2, 'search for subscriptions by call number');
344 @subscriptions = SearchSubscriptions
({callnumber
=> 'DEF'});
345 is
(scalar(@subscriptions), 1, 'search for subscriptions by call number');
346 @subscriptions = SearchSubscriptions
({location
=> 'LOCA'});
347 is
(scalar(@subscriptions), 1, 'search for subscriptions by location');
350 my $order1 = Koha
::Acquisition
::Order
->new(
352 basketno
=> $basketno1,
354 biblionumber
=> $biblionumber,
355 budget_id
=> $id_budget,
356 entrydate
=> '01-01-2013',
358 notes
=> "This is a note1",
361 subscriptionid
=> $id_subscription1,
362 quantityreceived
=> 2,
365 datereceived
=> '01-06-2013'
368 my $ordernumber1 = $order1->{ordernumber
};
370 my $order2 = Koha
::Acquisition
::Order
->new(
372 basketno
=> $basketno2,
374 biblionumber
=> $biblionumber,
375 budget_id
=> $id_budget,
376 entrydate
=> '01-01-2013',
378 notes
=> "This is a note2",
381 subscriptionid
=> $id_subscription2,
386 my $ordernumber2 = $order2->{ordernumber
};
388 my $order3 = Koha
::Acquisition
::Order
->new(
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 my $ordernumber3 = $order3->{ordernumber
};
406 my $order4 = Koha
::Acquisition
::Order
->new(
408 basketno
=> $basketno4,
410 biblionumber
=> $biblionumber,
411 budget_id
=> $id_budget,
412 entrydate
=> '02-02-2013',
414 notes
=> "This is a note3",
417 subscriptionid
=> $id_subscription3,
420 quantityreceived
=> 20
423 my $ordernumber4 = $order4->{ordernumber
};
427 # Supplier1: delivery -> undef Basket1 : closedate -> today
428 # Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5
429 # Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10
430 #Case 1 : Without parameters:
431 # quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
432 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
433 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
434 # quantityreceived = quantity -NOT LATE-
435 my %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
();
436 ok
( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" );
437 ok
( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" );
438 ok
( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" );
439 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" )
440 ; # Quantity = quantityreceived
442 #Case 2: With $delay = 4
443 # today + 0 > now-$delay -NOT LATE-
444 # (today-5) + 2 <= now() - $delay -NOT LATE-
445 # (today-10) + 3 <= now() - $delay -LATE-
446 # quantityreceived = quantity -NOT LATE-
447 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( 4, undef, undef );
448 isnt
( exists( $suppliers{$id_supplier1} ),
449 1, "Supplier1 has late orders but today > now() - 4 days" );
450 isnt
( exists( $suppliers{$id_supplier2} ),
451 1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" );
452 ok
( exists( $suppliers{$id_supplier3} ),
453 "Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" );
454 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
456 #Case 3: With $delay = -1
459 { $bslo = C4
::Bookseller
::GetBooksellersWithLateOrders
( -1, undef, undef ) }
460 qr/^WARNING: GetBooksellerWithLateOrders is called with a negative value/,
461 "GetBooksellerWithLateOrders prints a warning on negative values";
463 is
( $bslo, undef, "-1 is a wrong value for a delay" );
465 #Case 4: With $delay = 0
466 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0)
467 # today-5 <= now() - $delay+2 -LATE-
468 # today-10 <= now() - $delay+3 -LATE-
469 # quantityreceived = quantity -NOT LATE-
470 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( 0, undef, undef );
472 ok
( exists( $suppliers{$id_supplier1} ),
473 "Supplier1 has late orders but $today == now() - 0 days" )
475 ok
( exists( $suppliers{$id_supplier2} ),
476 "Supplier2 has late orders and $daysago5 <= now() - 2" );
477 ok
( exists( $suppliers{$id_supplier3} ),
478 "Supplier3 has late orders and $daysago10 <= now() - 3" );
479 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
481 #Case 5 : With $estimateddeliverydatefrom = today-4
482 # today >= today-4 -NOT LATE-
483 # (today-5)+ 2 days >= today-4 -LATE-
484 # (today-10) + 3 days < today-4 -NOT LATE-
485 # quantityreceived = quantity -NOT LATE-
486 my $dt_today3 = dt_from_string
;
487 my $dur4 = DateTime
::Duration
->new( days
=> -4 );
488 $dt_today3->add_duration($dur4);
489 my $daysago4 = output_pref
({ dt
=> $dt_today3, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
491 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago4, undef );
493 ok
( exists( $suppliers{$id_supplier1} ),
494 "Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" );
495 ok
( exists( $suppliers{$id_supplier2} ),
496 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " );
497 isnt
( exists( $suppliers{$id_supplier3} ),
498 1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " );
499 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
501 #Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5
502 # $daysago10<$daysago5<today -NOT LATE-
503 # $daysago10<$daysago5<$daysago5 +2 -NOT lATE-
504 # $daysago10<$daysago10 +3 <$daysago5 -LATE-
505 # quantityreceived = quantity -NOT LATE-
506 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10,
508 isnt
( exists( $suppliers{$id_supplier1} ),
509 1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" );
511 exists( $suppliers{$id_supplier2} ),
513 "Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2"
516 exists( $suppliers{$id_supplier3} ),
517 "Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5"
519 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
521 #Case 7: With $estimateddeliverydateto = today-5
522 # $today >= $daysago5 -NOT LATE-
523 # $daysago5 + 2 days > $daysago5 -NOT LATE-
524 # $daysago10 + 3 <+ $daysago5 -LATE-
525 # quantityreceived = quantity -NOT LATE-
527 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, undef, $daysago5 );
528 isnt
( exists( $suppliers{$id_supplier1} ),
530 "Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" );
531 isnt
( exists( $suppliers{$id_supplier2} ),
532 1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " );
533 ok
( exists( $suppliers{$id_supplier3} ),
534 "Supplier3 has late orders and $daysago10 + 3 <= $daysago5" );
535 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
537 #Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay
538 #Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5
539 # $daysago4<today<=$today and $today<now()-3 -NOT LATE-
540 # $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE-
541 # $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE-
542 # quantityreceived = quantity -NOT LATE-
544 C4
::Bookseller
::GetBooksellersWithLateOrders
( 3, $daysago4, $today );
546 exists( $suppliers{$id_supplier1} ),
548 "Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3"
551 exists( $suppliers{$id_supplier2} ),
552 "Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days"
555 exists( $suppliers{$id_supplier3} ),
556 "Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days"
558 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
560 #Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3
561 # $today < $daysago5 and $today > $today-5 -NOT LATE-
562 # $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE-
563 # $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE-
564 # quantityreceived = quantity -NOT LATE-
566 C4
::Bookseller
::GetBooksellersWithLateOrders
( 3, $daysago5, undef );
567 isnt
( exists( $suppliers{$id_supplier1} ),
568 1, "$today < $daysago10 and $today > $today-3" );
570 exists( $suppliers{$id_supplier2} ),
571 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2"
574 exists( $suppliers{$id_supplier3} ),
576 "Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 "
578 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
580 #Test with $estimateddeliverydateto and $delay
581 #Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5
582 # today > $daysago5 today > now() -5 -NOT LATE-
583 # $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE-
584 # $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE-
585 # quantityreceived = quantity -NOT LATE-
587 C4
::Bookseller
::GetBooksellersWithLateOrders
( 5, undef, $daysago5 );
588 isnt
( exists( $suppliers{$id_supplier1} ),
589 1, "Supplier2 has late orders but today > $daysago5 today > now() -5" );
591 exists( $suppliers{$id_supplier2} ),
593 "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days"
596 exists( $suppliers{$id_supplier3} ),
597 "Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days "
599 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
601 #Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10
602 # $daysago10==$daysago10==$daysago10 -NOT LATE-
603 # $daysago10==$daysago10<$daysago5+2-NOT lATE-
604 # $daysago10==$daysago10 <$daysago10+3-LATE-
605 # quantityreceived = quantity -NOT LATE-
607 #Basket1 closedate -> $daysago10
609 basketno
=> $basketno1,
610 closedate
=> $daysago10,
612 ModBasket
($basket1info);
613 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10,
615 ok
( exists( $suppliers{$id_supplier1} ),
616 "Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " )
618 isnt
( exists( $suppliers{$id_supplier2} ),
620 "Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" );
621 isnt
( exists( $suppliers{$id_supplier3} ),
623 "Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" );
624 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
626 #Case 12: closedate == $estimateddeliverydatefrom =today-10
628 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10, undef );
629 ok
( exists( $suppliers{$id_supplier1} ),
630 "Supplier1 has late orders and $daysago10==$daysago10 " );
632 #Case 13: closedate == $estimateddeliverydateto =today-10
634 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, undef, $daysago10 );
635 ok
( exists( $suppliers{$id_supplier1} ),
636 "Supplier1 has late orders and $daysago10==$daysago10 " )
639 C4
::Context
->_new_userenv('DUMMY SESSION');
640 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', '');
641 my $userenv = C4
::Context
->userenv;
643 my $module = Test
::MockModule
->new('C4::Auth');
647 # simulate user that has serials permissions but
649 my ($userid, $flagsrequired) = @_;
650 return 0 if 'superserials' eq ($flagsrequired->{serials
} // 0);
651 return exists($flagsrequired->{serials
});
655 C4
::Context
->set_preference('IndependentBranches', 0);
656 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
658 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
660 'ordinary user can see all subscriptions with IndependentBranches off'
663 C4
::Context
->set_preference('IndependentBranches', 1);
664 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
666 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
668 'ordinary user can see only their library\'s subscriptions with IndependentBranches on'
671 # don the cape and turn into Superlibrarian!
672 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', '');
673 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
675 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
677 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
679 #Test contact editing
680 my $booksellerid = C4
::Bookseller
::AddBookseller
(
683 address1
=> "bookseller's address",
688 { name
=> 'John Smith', phone
=> '0123456x1' },
689 { name
=> 'Leo Tolstoy', phone
=> '0123456x2' },
693 @booksellers = Koha
::Acquisition
::Bookseller
->search({ name
=> 'my vendor' });
695 ( grep { $_->{'id'} == $booksellerid } @booksellers ),
696 'Koha::Acquisition::Bookseller->search returns correct record when passed a name'
699 my $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
700 is
( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' );
701 is
( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' );
702 my $contacts = $bookseller->contacts;
703 is
( ref $bookseller->contacts,
704 'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' );
706 ref $bookseller->{'contacts'}->[0],
707 'C4::Bookseller::Contact',
708 'First contact is a contact object'
710 is
( $bookseller->{'contacts'}->[0]->phone,
711 '0123456x1', 'Contact has expected phone number' );
712 is
( scalar @
{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' );
714 pop @
{ $bookseller->{'contacts'} };
715 $bookseller->{'name'} = 'your vendor';
716 $bookseller->{'contacts'}->[0]->phone('654321');
717 C4
::Bookseller
::ModBookseller
($bookseller);
719 $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
720 $contacts = $bookseller->contacts;
721 is
( $bookseller->{'name'}, 'your vendor',
722 'Successfully changed name of vendor' );
723 is
( $contacts->[0]->phone,
725 'Successfully changed contact phone number by modifying bookseller hash' );
726 is
( scalar @
$contacts,
727 1, 'Only one contact after modification' );
729 C4
::Bookseller
::ModBookseller
( $bookseller,
730 [ { name
=> 'John Jacob Jingleheimer Schmidt' } ] );
732 $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
733 $contacts = $bookseller->contacts;
735 $contacts->[0]->name,
736 'John Jacob Jingleheimer Schmidt',
737 'Changed name of contact'
739 is
( $contacts->[0]->phone,
740 undef, 'Removed phone number from contact' );
741 is
( scalar @
$contacts,
742 1, 'Only one contact after modification' );
747 #field_filter filters the useless fields or foreign keys
748 #NOTE: all the fields of aqbookseller arent considered
749 #returns a cleaned structure
754 'bookselleremail', 'booksellerfax',
755 'booksellerurl', 'othersupplier',
756 'currency', 'invoiceprice',
757 'listprice', 'contacts'
761 if ( grep { /^$field$/ } keys %$struct ) {
762 delete $struct->{$field};