5 use Test
::More tests
=> 88;
11 use DateTime
::Duration
;
17 use Koha
::Acquisition
::Order
;
21 use_ok
('C4::Bookseller');
22 use_ok
('Koha::Acquisition::Bookseller');
30 GetBooksellersWithLateOrders
35 my $dbh = C4
::Context
->dbh;
36 my $database = Koha
::Database
->new();
37 my $schema = $database->schema();
38 $schema->storage->txn_begin();
40 $dbh->{RaiseError
} = 1;
43 $dbh->do(q
|DELETE FROM aqorders
|);
44 $dbh->do(q
|DELETE FROM aqbasket
|);
45 $dbh->do(q
|DELETE FROM aqbooksellers
|);
46 $dbh->do(q
|DELETE FROM subscription
|);
49 my $count = scalar( Koha
::Acquisition
::Bookseller
->search() );
50 my $sample_supplier1 = {
52 address1
=> 'address1_1',
53 address2
=> 'address1-2',
54 address3
=> 'address1_2',
55 address4
=> 'address1_2',
58 accountnumber
=> 'accountnumber1',
70 my $sample_supplier2 = {
72 address1
=> 'address1_2',
73 address2
=> 'address2-2',
74 address3
=> 'address3_2',
75 address4
=> 'address4_2',
78 accountnumber
=> 'accountnumber2',
91 my $id_supplier1 = C4
::Bookseller
::AddBookseller
($sample_supplier1);
92 my $id_supplier2 = C4
::Bookseller
::AddBookseller
($sample_supplier2);
94 #my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null
96 like
( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
97 like
( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
98 my @b = Koha
::Acquisition
::Bookseller
->search();
100 $count + 2, "Supplier1 and Supplier2 have been added" );
103 my $del = C4
::Bookseller
::DelBookseller
($id_supplier1);
104 is
( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
105 my $b = Koha
::Acquisition
::Bookseller
->fetch({id
=> $id_supplier1});
107 undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" );
110 my @bookseller2 = Koha
::Acquisition
::Bookseller
->search({name
=> $sample_supplier2->{name
} });
111 is
( scalar(@bookseller2), 1, "Get only Supplier2" );
112 $bookseller2[0] = field_filter
( $bookseller2[0] );
114 $sample_supplier2->{id
} = $id_supplier2;
115 is_deeply
( $bookseller2[0], $sample_supplier2,
116 "Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" );
118 $id_supplier1 = C4
::Bookseller
::AddBookseller
($sample_supplier1);
119 my @booksellers = Koha
::Acquisition
::Bookseller
->search(); #NOTE :without params, it returns all the booksellers
120 for my $i ( 0 .. scalar(@booksellers) - 1 ) {
121 $booksellers[$i] = field_filter
( $booksellers[$i] );
124 $sample_supplier1->{id
} = $id_supplier1;
125 is
( scalar(@booksellers), $count + 2, "Get Supplier1 and Supplier2" );
126 my @tab = ( $sample_supplier1, $sample_supplier2 );
127 is_deeply
( \
@booksellers, \
@tab,
128 "Returns right fields of Supplier1 and Supplier2" );
131 my @bookseller1 = Koha
::Acquisition
::Bookseller
->search({name
=> $sample_supplier1->{name
} });
132 is
( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' );
134 C4
::Acquisition
::NewBasket
( $id_supplier1, 'authorisedby1', 'basketname1' );
136 C4
::Acquisition
::NewBasket
( $id_supplier1, 'authorisedby2', 'basketname2' );
137 @bookseller1 = Koha
::Acquisition
::Bookseller
::search
({ name
=> $sample_supplier1->{name
} });
138 is
( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' );
140 #Test Koha::Acquisition::Bookseller->new using id
141 my $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch;
142 is
( $bookseller1fromid, undef,
143 "fetch returns undef if no id given" );
144 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1});
145 $bookseller1fromid = field_filter
($bookseller1fromid);
146 is_deeply
( $bookseller1fromid, $sample_supplier1,
147 "Get Supplier1 (fetch a bookseller by id)" );
150 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1});
151 is
( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' );
153 #Test subscription_count
154 my $dt_today = dt_from_string
;
155 my $today = output_pref
({ dt
=> $dt_today, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
157 my $dt_today1 = dt_from_string
;
158 my $dur5 = DateTime
::Duration
->new( days
=> -5 );
159 $dt_today1->add_duration($dur5);
160 my $daysago5 = output_pref
({ dt
=> $dt_today1, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
162 my $budgetperiod = C4
::Budgets
::AddBudgetPeriod
({
163 budget_period_startdate
=> $daysago5,
164 budget_period_enddate
=> $today,
165 budget_period_description
=> "budget desc"
167 my $id_budget = AddBudget
({
168 budget_code
=> "CODE",
169 budget_amount
=> "123.132",
170 budget_name
=> "Budgetname",
171 budget_notes
=> "This is a note",
172 budget_period_id
=> $budgetperiod
174 my $bib = MARC
::Record
->new();
176 MARC
::Field
->new('245', ' ', ' ', a
=> 'Journal of ethnology'),
177 MARC
::Field
->new('500', ' ', ' ', a
=> 'bib notes'),
179 my ($biblionumber, $biblioitemnumber) = AddBiblio
($bib, '');
180 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1 });
181 is
( $bookseller1fromid->subscription_count,
182 0, 'Supplier1 has 0 subscription' );
184 my $id_subscription1 = NewSubscription
(
185 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
186 '01-01-2013',undef, undef, undef, undef,
187 undef, undef, undef, undef, undef, undef,
188 1, "subscription notes",undef, '01-01-2013', undef, undef,
189 undef, 'CALL ABC', 0, "intnotes", 0,
190 undef, undef, 0, undef, '2013-11-30', 0
193 my @subscriptions = SearchSubscriptions
({biblionumber
=> $biblionumber});
194 is
($subscriptions[0]->{publicnotes
}, 'subscription notes', 'subscription search results include public notes (bug 10689)');
196 my $id_subscription2 = NewSubscription
(
197 undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber,
198 '01-01-2013',undef, undef, undef, undef,
199 undef, undef, undef, undef, undef, undef,
200 1, "subscription notes",undef, '01-01-2013', undef, undef,
201 undef, 'CALL DEF', 0, "intnotes", 0,
202 undef, undef, 0, undef, '2013-07-31', 0
205 $bookseller1fromid = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $id_supplier1 });
206 is
( $bookseller1fromid->subscription_count,
207 2, 'Supplier1 has 2 subscriptions' );
210 $sample_supplier2 = {
212 name
=> 'Name2 modified',
213 address1
=> 'address1_2 modified',
214 address2
=> 'address2-2 modified',
215 address3
=> 'address3_2 modified',
216 address4
=> 'address4_2 modified',
217 postal
=> 'postal2 modified',
218 phone
=> 'phone2 modified',
219 accountnumber
=> 'accountnumber2 modified',
220 fax
=> 'fax2 modified',
221 url
=> 'url2 modified',
226 gstrate
=> '2.0000 ',
227 discount
=> '2.0000',
228 notes
=> 'notes2 modified',
232 my $modif1 = C4
::Bookseller
::ModBookseller
();
234 "ModBookseller returns undef if no params given - Nothing happened" );
235 $modif1 = C4
::Bookseller
::ModBookseller
($sample_supplier2);
236 is
( $modif1, 1, "ModBookseller modifies only the supplier2" );
237 is
( scalar( Koha
::Acquisition
::Bookseller
->search ),
238 $count + 2, "Supplier2 has been modified - Nothing added" );
240 $modif1 = C4
::Bookseller
::ModBookseller
(
247 # "ModBookseller returns OEO if the id doesnt exist - Nothing modified" );
249 #Test GetBooksellersWithLateOrders
251 my $sample_supplier3 = {
253 address1
=> 'address1_3',
254 address2
=> 'address1-3',
255 address3
=> 'address1_3',
256 address4
=> 'address1_3',
259 accountnumber
=> 'accountnumber3',
267 discount
=> '3.0000',
271 my $sample_supplier4 = {
273 address1
=> 'address1_4',
274 address2
=> 'address1-4',
275 address3
=> 'address1_4',
276 address4
=> 'address1_4',
279 accountnumber
=> 'accountnumber4',
287 discount
=> '3.0000',
290 my $id_supplier3 = C4
::Bookseller
::AddBookseller
($sample_supplier3);
291 my $id_supplier4 = C4
::Bookseller
::AddBookseller
($sample_supplier4);
295 C4
::Acquisition
::NewBasket
( $id_supplier3, 'authorisedby3', 'basketname3',
298 C4
::Acquisition
::NewBasket
( $id_supplier4, 'authorisedby4', 'basketname4',
301 #Modify the basket to add a close date
303 basketno
=> $basketno1,
305 booksellerid
=> $id_supplier1
309 basketno
=> $basketno2,
310 closedate
=> $daysago5,
311 booksellerid
=> $id_supplier2
314 my $dt_today2 = dt_from_string
;
315 my $dur10 = DateTime
::Duration
->new( days
=> -10 );
316 $dt_today2->add_duration($dur10);
317 my $daysago10 = output_pref
({ dt
=> $dt_today2, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
319 basketno
=> $basketno3,
320 closedate
=> $daysago10,
324 basketno
=> $basketno4,
327 ModBasket
($basket1info);
328 ModBasket
($basket2info);
329 ModBasket
($basket3info);
330 ModBasket
($basket4info);
333 my $id_subscription3 = NewSubscription
(
334 undef, "BRANCH1", $id_supplier1, undef, $id_budget, $biblionumber,
335 '01-01-2013',undef, undef, undef, undef,
336 undef, undef, undef, undef, undef, undef,
337 1, "subscription notes",undef, '01-01-2013', undef, undef,
338 undef, undef, 0, "intnotes", 0,
339 undef, undef, 0, 'LOCA', '2013-12-31', 0
342 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
343 is
(scalar(@subscriptions), 3, 'search for subscriptions by expiration date');
344 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-08-15'});
345 is
(scalar(@subscriptions), 1, 'search for subscriptions by expiration date');
346 @subscriptions = SearchSubscriptions
({callnumber
=> 'CALL'});
347 is
(scalar(@subscriptions), 2, 'search for subscriptions by call number');
348 @subscriptions = SearchSubscriptions
({callnumber
=> 'DEF'});
349 is
(scalar(@subscriptions), 1, 'search for subscriptions by call number');
350 @subscriptions = SearchSubscriptions
({location
=> 'LOCA'});
351 is
(scalar(@subscriptions), 1, 'search for subscriptions by location');
354 my $order1 = Koha
::Acquisition
::Order
->new(
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 my $ordernumber1 = $order1->{ordernumber
};
374 my $order2 = Koha
::Acquisition
::Order
->new(
376 basketno
=> $basketno2,
378 biblionumber
=> $biblionumber,
379 budget_id
=> $id_budget,
380 entrydate
=> '01-01-2013',
382 notes
=> "This is a note2",
385 subscriptionid
=> $id_subscription2,
390 my $ordernumber2 = $order2->{ordernumber
};
392 my $order3 = Koha
::Acquisition
::Order
->new(
394 basketno
=> $basketno3,
396 biblionumber
=> $biblionumber,
397 budget_id
=> $id_budget,
398 entrydate
=> '02-02-2013',
400 notes
=> "This is a note3",
403 subscriptionid
=> $id_subscription3,
408 my $ordernumber3 = $order3->{ordernumber
};
410 my $order4 = Koha
::Acquisition
::Order
->new(
412 basketno
=> $basketno4,
414 biblionumber
=> $biblionumber,
415 budget_id
=> $id_budget,
416 entrydate
=> '02-02-2013',
418 notes
=> "This is a note3",
421 subscriptionid
=> $id_subscription3,
424 quantityreceived
=> 20
427 my $ordernumber4 = $order4->{ordernumber
};
431 # Supplier1: delivery -> undef Basket1 : closedate -> today
432 # Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5
433 # Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10
434 #Case 1 : Without parameters:
435 # quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
436 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
437 # datereceived !null AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
438 # quantityreceived = quantity -NOT LATE-
439 my %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
();
440 ok
( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" );
441 ok
( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" );
442 ok
( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" );
443 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" )
444 ; # Quantity = quantityreceived
446 #Case 2: With $delay = 4
447 # today + 0 > now-$delay -NOT LATE-
448 # (today-5) + 2 <= now() - $delay -NOT LATE-
449 # (today-10) + 3 <= now() - $delay -LATE-
450 # quantityreceived = quantity -NOT LATE-
451 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( 4, undef, undef );
452 isnt
( exists( $suppliers{$id_supplier1} ),
453 1, "Supplier1 has late orders but today > now() - 4 days" );
454 isnt
( exists( $suppliers{$id_supplier2} ),
455 1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" );
456 ok
( exists( $suppliers{$id_supplier3} ),
457 "Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" );
458 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
460 #Case 3: With $delay = -1
463 { $bslo = C4
::Bookseller
::GetBooksellersWithLateOrders
( -1, undef, undef ) }
464 qr/^WARNING: GetBooksellerWithLateOrders is called with a negative value/,
465 "GetBooksellerWithLateOrders prints a warning on negative values";
467 is
( $bslo, undef, "-1 is a wrong value for a delay" );
469 #Case 4: With $delay = 0
470 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0)
471 # today-5 <= now() - $delay+2 -LATE-
472 # today-10 <= now() - $delay+3 -LATE-
473 # quantityreceived = quantity -NOT LATE-
474 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( 0, undef, undef );
476 ok
( exists( $suppliers{$id_supplier1} ),
477 "Supplier1 has late orders but $today == now() - 0 days" )
479 ok
( exists( $suppliers{$id_supplier2} ),
480 "Supplier2 has late orders and $daysago5 <= now() - 2" );
481 ok
( exists( $suppliers{$id_supplier3} ),
482 "Supplier3 has late orders and $daysago10 <= now() - 3" );
483 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
485 #Case 5 : With $estimateddeliverydatefrom = today-4
486 # today >= today-4 -NOT LATE-
487 # (today-5)+ 2 days >= today-4 -LATE-
488 # (today-10) + 3 days < today-4 -NOT LATE-
489 # quantityreceived = quantity -NOT LATE-
490 my $dt_today3 = dt_from_string
;
491 my $dur4 = DateTime
::Duration
->new( days
=> -4 );
492 $dt_today3->add_duration($dur4);
493 my $daysago4 = output_pref
({ dt
=> $dt_today3, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
495 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago4, undef );
497 ok
( exists( $suppliers{$id_supplier1} ),
498 "Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" );
499 ok
( exists( $suppliers{$id_supplier2} ),
500 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " );
501 isnt
( exists( $suppliers{$id_supplier3} ),
502 1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " );
503 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
505 #Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5
506 # $daysago10<$daysago5<today -NOT LATE-
507 # $daysago10<$daysago5<$daysago5 +2 -NOT lATE-
508 # $daysago10<$daysago10 +3 <$daysago5 -LATE-
509 # quantityreceived = quantity -NOT LATE-
510 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10,
512 isnt
( exists( $suppliers{$id_supplier1} ),
513 1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" );
515 exists( $suppliers{$id_supplier2} ),
517 "Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2"
520 exists( $suppliers{$id_supplier3} ),
521 "Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5"
523 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
525 #Case 7: With $estimateddeliverydateto = today-5
526 # $today >= $daysago5 -NOT LATE-
527 # $daysago5 + 2 days > $daysago5 -NOT LATE-
528 # $daysago10 + 3 <+ $daysago5 -LATE-
529 # quantityreceived = quantity -NOT LATE-
531 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, undef, $daysago5 );
532 isnt
( exists( $suppliers{$id_supplier1} ),
534 "Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" );
535 isnt
( exists( $suppliers{$id_supplier2} ),
536 1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " );
537 ok
( exists( $suppliers{$id_supplier3} ),
538 "Supplier3 has late orders and $daysago10 + 3 <= $daysago5" );
539 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
541 #Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay
542 #Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5
543 # $daysago4<today<=$today and $today<now()-3 -NOT LATE-
544 # $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE-
545 # $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE-
546 # quantityreceived = quantity -NOT LATE-
548 C4
::Bookseller
::GetBooksellersWithLateOrders
( 3, $daysago4, $today );
550 exists( $suppliers{$id_supplier1} ),
552 "Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3"
555 exists( $suppliers{$id_supplier2} ),
556 "Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days"
559 exists( $suppliers{$id_supplier3} ),
560 "Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days"
562 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
564 #Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3
565 # $today < $daysago5 and $today > $today-5 -NOT LATE-
566 # $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE-
567 # $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE-
568 # quantityreceived = quantity -NOT LATE-
570 C4
::Bookseller
::GetBooksellersWithLateOrders
( 3, $daysago5, undef );
571 isnt
( exists( $suppliers{$id_supplier1} ),
572 1, "$today < $daysago10 and $today > $today-3" );
574 exists( $suppliers{$id_supplier2} ),
575 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2"
578 exists( $suppliers{$id_supplier3} ),
580 "Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 "
582 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
584 #Test with $estimateddeliverydateto and $delay
585 #Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5
586 # today > $daysago5 today > now() -5 -NOT LATE-
587 # $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE-
588 # $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE-
589 # quantityreceived = quantity -NOT LATE-
591 C4
::Bookseller
::GetBooksellersWithLateOrders
( 5, undef, $daysago5 );
592 isnt
( exists( $suppliers{$id_supplier1} ),
593 1, "Supplier2 has late orders but today > $daysago5 today > now() -5" );
595 exists( $suppliers{$id_supplier2} ),
597 "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days"
600 exists( $suppliers{$id_supplier3} ),
601 "Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days "
603 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
605 #Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10
606 # $daysago10==$daysago10==$daysago10 -NOT LATE-
607 # $daysago10==$daysago10<$daysago5+2-NOT lATE-
608 # $daysago10==$daysago10 <$daysago10+3-LATE-
609 # quantityreceived = quantity -NOT LATE-
611 #Basket1 closedate -> $daysago10
613 basketno
=> $basketno1,
614 closedate
=> $daysago10,
616 ModBasket
($basket1info);
617 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10,
619 ok
( exists( $suppliers{$id_supplier1} ),
620 "Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " )
622 isnt
( exists( $suppliers{$id_supplier2} ),
624 "Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" );
625 isnt
( exists( $suppliers{$id_supplier3} ),
627 "Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" );
628 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
630 #Case 12: closedate == $estimateddeliverydatefrom =today-10
632 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10, undef );
633 ok
( exists( $suppliers{$id_supplier1} ),
634 "Supplier1 has late orders and $daysago10==$daysago10 " );
636 #Case 13: closedate == $estimateddeliverydateto =today-10
638 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, undef, $daysago10 );
639 ok
( exists( $suppliers{$id_supplier1} ),
640 "Supplier1 has late orders and $daysago10==$daysago10 " )
643 C4
::Context
->_new_userenv('DUMMY SESSION');
644 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', '');
645 my $userenv = C4
::Context
->userenv;
647 my $module = Test
::MockModule
->new('C4::Auth');
651 # simulate user that has serials permissions but
653 my ($userid, $flagsrequired) = @_;
654 return 0 if 'superserials' eq ($flagsrequired->{serials
} // 0);
655 return exists($flagsrequired->{serials
});
659 C4
::Context
->set_preference('IndependentBranches', 0);
660 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
662 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
664 'ordinary user can see all subscriptions with IndependentBranches off'
667 C4
::Context
->set_preference('IndependentBranches', 1);
668 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
670 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
672 'ordinary user can see only their library\'s subscriptions with IndependentBranches on'
675 # don the cape and turn into Superlibrarian!
676 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', '');
677 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
679 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
681 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
683 #Test contact editing
684 my $booksellerid = C4
::Bookseller
::AddBookseller
(
687 address1
=> "bookseller's address",
692 { name
=> 'John Smith', phone
=> '0123456x1' },
693 { name
=> 'Leo Tolstoy', phone
=> '0123456x2' },
697 @booksellers = Koha
::Acquisition
::Bookseller
->search({ name
=> 'my vendor' });
699 ( grep { $_->{'id'} == $booksellerid } @booksellers ),
700 'Koha::Acquisition::Bookseller->search returns correct record when passed a name'
703 my $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
704 is
( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' );
705 is
( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' );
706 my $contacts = $bookseller->contacts;
707 is
( ref $bookseller->contacts,
708 'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' );
710 ref $bookseller->{'contacts'}->[0],
711 'C4::Bookseller::Contact',
712 'First contact is a contact object'
714 is
( $bookseller->{'contacts'}->[0]->phone,
715 '0123456x1', 'Contact has expected phone number' );
716 is
( scalar @
{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' );
718 pop @
{ $bookseller->{'contacts'} };
719 $bookseller->{'name'} = 'your vendor';
720 $bookseller->{'contacts'}->[0]->phone('654321');
721 C4
::Bookseller
::ModBookseller
($bookseller);
723 $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
724 $contacts = $bookseller->contacts;
725 is
( $bookseller->{'name'}, 'your vendor',
726 'Successfully changed name of vendor' );
727 is
( $contacts->[0]->phone,
729 'Successfully changed contact phone number by modifying bookseller hash' );
730 is
( scalar @
$contacts,
731 1, 'Only one contact after modification' );
733 C4
::Bookseller
::ModBookseller
( $bookseller,
734 [ { name
=> 'John Jacob Jingleheimer Schmidt' } ] );
736 $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
737 $contacts = $bookseller->contacts;
739 $contacts->[0]->name,
740 'John Jacob Jingleheimer Schmidt',
741 'Changed name of contact'
743 is
( $contacts->[0]->phone,
744 undef, 'Removed phone number from contact' );
745 is
( scalar @
$contacts,
746 1, 'Only one contact after modification' );
749 $schema->storage->txn_rollback();
751 #field_filter filters the useless fields or foreign keys
752 #NOTE: all the fields of aqbookseller arent considered
753 #returns a cleaned structure
758 'bookselleremail', 'booksellerfax',
759 'booksellerurl', 'othersupplier',
760 'currency', 'invoiceprice',
761 'listprice', 'contacts'
765 if ( grep { /^$field$/ } keys %$struct ) {
766 delete $struct->{$field};