5 use Test
::More tests
=> 86;
11 use DateTime
::Duration
;
18 use Koha
::Acquisition
::Booksellers
;
19 use Koha
::Acquisition
::Order
;
23 use_ok
('C4::Bookseller');
29 GetBooksellersWithLateOrders
34 my $dbh = C4
::Context
->dbh;
35 my $database = Koha
::Database
->new();
36 my $schema = $database->schema();
37 $schema->storage->txn_begin();
39 $dbh->{RaiseError
} = 1;
42 $dbh->do(q
|DELETE FROM aqorders
|);
43 $dbh->do(q
|DELETE FROM aqbasket
|);
44 $dbh->do(q
|DELETE FROM aqbooksellers
|);
45 $dbh->do(q
|DELETE FROM subscription
|);
48 my $count = Koha
::Acquisition
::Booksellers
->search()->count();
49 my $sample_supplier1 = {
51 address1
=> 'address1_1',
52 address2
=> 'address1-2',
53 address3
=> 'address1_2',
54 address4
=> 'address1_2',
57 accountnumber
=> 'accountnumber1',
69 my $sample_supplier2 = {
71 address1
=> 'address1_2',
72 address2
=> 'address2-2',
73 address3
=> 'address3_2',
74 address4
=> 'address4_2',
77 accountnumber
=> 'accountnumber2',
90 my $supplier1 = Koha
::Acquisition
::Bookseller
->new($sample_supplier1)->store;
91 my $id_supplier1 = $supplier1->id;
92 my $supplier2 = Koha
::Acquisition
::Bookseller
->new($sample_supplier2)->store;
93 my $id_supplier2 = $supplier2->id;
95 like
( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" );
96 like
( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" );
97 is
( Koha
::Acquisition
::Booksellers
->search()->count,
98 $count + 2, "Supplier1 and Supplier2 have been added" );
101 my $del = $supplier1->delete;
102 is
( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " );
103 my $b = Koha
::Acquisition
::Booksellers
->find( $id_supplier1 );
105 undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" );
108 my @bookseller2 = Koha
::Acquisition
::Booksellers
->search({name
=> $sample_supplier2->{name
} });
109 is
( scalar(@bookseller2), 1, "Get only Supplier2" );
110 for my $bookseller ( @bookseller2 ) {
111 $bookseller = field_filter
( $bookseller->unblessed );
114 $sample_supplier2->{id
} = $id_supplier2;
115 is_deeply
( $bookseller2[0], $sample_supplier2,
116 "Koha::Acquisition::Booksellers->search returns the right informations about supplier $sample_supplier2->{name}" );
118 $supplier1 = Koha
::Acquisition
::Bookseller
->new($sample_supplier1)->store;
119 $id_supplier1 = $supplier1->id;
120 my @booksellers = Koha
::Acquisition
::Booksellers
->search();
121 for my $bookseller ( @booksellers ) {
122 $bookseller = field_filter
( $bookseller->unblessed );
125 $sample_supplier1->{id
} = $id_supplier1;
126 is
( scalar(@booksellers), $count + 2, "Get Supplier1 and Supplier2" );
127 my @tab = ( $sample_supplier1, $sample_supplier2 );
128 is_deeply
( \
@booksellers, \
@tab,
129 "Returns right fields of Supplier1 and Supplier2" );
132 my @bookseller1 = Koha
::Acquisition
::Booksellers
->search({name
=> $sample_supplier1->{name
} });
133 is
( $bookseller1[0]->baskets->count, 0, 'Supplier1 has 0 basket' );
135 C4
::Acquisition
::NewBasket
( $id_supplier1, 'authorisedby1', 'basketname1' );
137 C4
::Acquisition
::NewBasket
( $id_supplier1, 'authorisedby2', 'basketname2' );
138 @bookseller1 = Koha
::Acquisition
::Booksellers
->search({ name
=> $sample_supplier1->{name
} });
139 is
( $bookseller1[0]->baskets->count, 2, 'Supplier1 has 2 baskets' );
141 #Test Koha::Acquisition::Bookseller->new using id
142 my $bookseller1fromid = Koha
::Acquisition
::Booksellers
->find;
143 is
( $bookseller1fromid, undef,
144 "find returns undef if no id given" );
145 $bookseller1fromid = Koha
::Acquisition
::Booksellers
->find( $id_supplier1 );
146 $bookseller1fromid = field_filter
($bookseller1fromid->unblessed);
147 is_deeply
( $bookseller1fromid, $sample_supplier1,
148 "Get Supplier1 (find a bookseller by id)" );
150 $bookseller1fromid = Koha
::Acquisition
::Booksellers
->find( $id_supplier1 );
151 is
( $bookseller1fromid->baskets->count, 2, 'Supplier1 has 2 baskets' );
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
::Booksellers
->find( $id_supplier1 );
181 is
( $bookseller1fromid->subscriptions->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
::Booksellers
->find( $id_supplier1 );
206 is
( $bookseller1fromid->subscriptions->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 tax_rate
=> '2.0000 ',
227 discount
=> '2.0000',
228 notes
=> 'notes2 modified',
232 my $modif1 = Koha
::Acquisition
::Booksellers
->find($id_supplier2)->set($sample_supplier2)->store;
233 is
( ref $modif1, 'Koha::Acquisition::Bookseller', "ModBookseller has updated the bookseller" );
234 is
( Koha
::Acquisition
::Booksellers
->search->count,
235 $count + 2, "Supplier2 has been modified - Nothing added" );
236 $supplier2 = Koha
::Acquisition
::Booksellers
->find($id_supplier2);
237 is
( $supplier2->name, 'Name2 modified', "supplier's name should have been modified" );
239 #Test GetBooksellersWithLateOrders
241 my $sample_supplier3 = {
243 address1
=> 'address1_3',
244 address2
=> 'address1-3',
245 address3
=> 'address1_3',
246 address4
=> 'address1_3',
249 accountnumber
=> 'accountnumber3',
256 tax_rate
=> '3.0000',
257 discount
=> '3.0000',
261 my $sample_supplier4 = {
263 address1
=> 'address1_4',
264 address2
=> 'address1-4',
265 address3
=> 'address1_4',
266 address4
=> 'address1_4',
269 accountnumber
=> 'accountnumber4',
276 tax_rate
=> '3.0000',
277 discount
=> '3.0000',
280 my $supplier3 = Koha
::Acquisition
::Bookseller
->new($sample_supplier3)->store;
281 my $id_supplier3 = $supplier3->id;
282 my $supplier4 = Koha
::Acquisition
::Bookseller
->new($sample_supplier4)->store;
283 my $id_supplier4 = $supplier4->id;
287 C4
::Acquisition
::NewBasket
( $id_supplier3, 'authorisedby3', 'basketname3',
290 C4
::Acquisition
::NewBasket
( $id_supplier4, 'authorisedby4', 'basketname4',
293 #Modify the basket to add a close date
295 basketno
=> $basketno1,
297 booksellerid
=> $id_supplier1
301 basketno
=> $basketno2,
302 closedate
=> $daysago5,
303 booksellerid
=> $id_supplier2
306 my $dt_today2 = dt_from_string
;
307 my $dur10 = DateTime
::Duration
->new( days
=> -10 );
308 $dt_today2->add_duration($dur10);
309 my $daysago10 = output_pref
({ dt
=> $dt_today2, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
311 basketno
=> $basketno3,
312 closedate
=> $daysago10,
316 basketno
=> $basketno4,
319 ModBasket
($basket1info);
320 ModBasket
($basket2info);
321 ModBasket
($basket3info);
322 ModBasket
($basket4info);
325 my $id_subscription3 = NewSubscription
(
326 undef, "BRANCH1", $id_supplier1, undef, $id_budget, $biblionumber,
327 '01-01-2013',undef, undef, undef, undef,
328 undef, undef, undef, undef, undef, undef,
329 1, "subscription notes",undef, '01-01-2013', undef, undef,
330 undef, undef, 0, "intnotes", 0,
331 undef, undef, 0, 'LOCA', '2013-12-31', 0
334 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
335 is
(scalar(@subscriptions), 3, 'search for subscriptions by expiration date');
336 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-08-15'});
337 is
(scalar(@subscriptions), 1, 'search for subscriptions by expiration date');
338 @subscriptions = SearchSubscriptions
({callnumber
=> 'CALL'});
339 is
(scalar(@subscriptions), 2, 'search for subscriptions by call number');
340 @subscriptions = SearchSubscriptions
({callnumber
=> 'DEF'});
341 is
(scalar(@subscriptions), 1, 'search for subscriptions by call number');
342 @subscriptions = SearchSubscriptions
({location
=> 'LOCA'});
343 is
(scalar(@subscriptions), 1, 'search for subscriptions by location');
346 my $order1 = Koha
::Acquisition
::Order
->new(
348 basketno
=> $basketno1,
350 biblionumber
=> $biblionumber,
351 budget_id
=> $id_budget,
352 entrydate
=> '01-01-2013',
354 notes
=> "This is a note1",
357 subscriptionid
=> $id_subscription1,
358 quantityreceived
=> 2,
361 datereceived
=> '01-06-2013'
364 my $ordernumber1 = $order1->{ordernumber
};
366 my $order2 = Koha
::Acquisition
::Order
->new(
368 basketno
=> $basketno2,
370 biblionumber
=> $biblionumber,
371 budget_id
=> $id_budget,
372 entrydate
=> '01-01-2013',
374 notes
=> "This is a note2",
377 subscriptionid
=> $id_subscription2,
382 my $ordernumber2 = $order2->{ordernumber
};
384 my $order3 = Koha
::Acquisition
::Order
->new(
386 basketno
=> $basketno3,
388 biblionumber
=> $biblionumber,
389 budget_id
=> $id_budget,
390 entrydate
=> '02-02-2013',
392 notes
=> "This is a note3",
395 subscriptionid
=> $id_subscription3,
400 my $ordernumber3 = $order3->{ordernumber
};
402 my $order4 = Koha
::Acquisition
::Order
->new(
404 basketno
=> $basketno4,
406 biblionumber
=> $biblionumber,
407 budget_id
=> $id_budget,
408 entrydate
=> '02-02-2013',
410 notes
=> "This is a note3",
413 subscriptionid
=> $id_subscription3,
416 quantityreceived
=> 20
419 my $ordernumber4 = $order4->{ordernumber
};
423 # Supplier1: delivery -> undef Basket1 : closedate -> today
424 # Supplier2: delivery -> 2 Basket2 : closedate -> $daysago5
425 # Supplier3: delivery -> 3 Basket3 : closedate -> $daysago10
426 #Case 1 : Without parameters:
427 # quantityreceived < quantity AND rrp <> 0 AND ecost <> 0 AND quantity - COALESCE(quantityreceived,0) <> 0 AND closedate IS NOT NULL -LATE-
428 # datereceived !null 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 # quantityreceived = quantity -NOT LATE-
431 my %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
();
432 ok
( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders" );
433 ok
( exists( $suppliers{$id_supplier2} ), "Supplier2 has late orders" );
434 ok
( exists( $suppliers{$id_supplier3} ), "Supplier3 has late orders" );
435 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" )
436 ; # Quantity = quantityreceived
438 #Case 2: With $delay = 4
439 # today + 0 > now-$delay -NOT LATE-
440 # (today-5) + 2 <= now() - $delay -NOT LATE-
441 # (today-10) + 3 <= now() - $delay -LATE-
442 # quantityreceived = quantity -NOT LATE-
443 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( 4, undef, undef );
444 isnt
( exists( $suppliers{$id_supplier1} ),
445 1, "Supplier1 has late orders but today > now() - 4 days" );
446 isnt
( exists( $suppliers{$id_supplier2} ),
447 1, "Supplier2 has late orders and $daysago5 <= now() - (4 days+2)" );
448 ok
( exists( $suppliers{$id_supplier3} ),
449 "Supplier3 has late orders and $daysago10 <= now() - (4 days+3)" );
450 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
452 #Case 3: With $delay = -1
455 { $bslo = C4
::Bookseller
::GetBooksellersWithLateOrders
( -1, undef, undef ) }
456 qr/^WARNING: GetBooksellerWithLateOrders is called with a negative value/,
457 "GetBooksellerWithLateOrders prints a warning on negative values";
459 is
( $bslo, undef, "-1 is a wrong value for a delay" );
461 #Case 4: With $delay = 0
462 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0)
463 # today-5 <= now() - $delay+2 -LATE-
464 # today-10 <= now() - $delay+3 -LATE-
465 # quantityreceived = quantity -NOT LATE-
466 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( 0, undef, undef );
468 ok
( exists( $suppliers{$id_supplier1} ),
469 "Supplier1 has late orders but $today == now() - 0 days" )
471 ok
( exists( $suppliers{$id_supplier2} ),
472 "Supplier2 has late orders and $daysago5 <= now() - 2" );
473 ok
( exists( $suppliers{$id_supplier3} ),
474 "Supplier3 has late orders and $daysago10 <= now() - 3" );
475 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
477 #Case 5 : With $estimateddeliverydatefrom = today-4
478 # today >= today-4 -NOT LATE-
479 # (today-5)+ 2 days >= today-4 -LATE-
480 # (today-10) + 3 days < today-4 -NOT LATE-
481 # quantityreceived = quantity -NOT LATE-
482 my $dt_today3 = dt_from_string
;
483 my $dur4 = DateTime
::Duration
->new( days
=> -4 );
484 $dt_today3->add_duration($dur4);
485 my $daysago4 = output_pref
({ dt
=> $dt_today3, dateformat
=> 'iso', timeformat
=> '24hr', dateonly
=> 1 });
487 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago4, undef );
489 ok
( exists( $suppliers{$id_supplier1} ),
490 "Supplier1 has late orders and $today >= $daysago4 -deliverytime undef" );
491 ok
( exists( $suppliers{$id_supplier2} ),
492 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago4 " );
493 isnt
( exists( $suppliers{$id_supplier3} ),
494 1, "Supplier3 has late orders and $daysago10 + 5 days < $daysago4 " );
495 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
497 #Case 6: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 5
498 # $daysago10<$daysago5<today -NOT LATE-
499 # $daysago10<$daysago5<$daysago5 +2 -NOT lATE-
500 # $daysago10<$daysago10 +3 <$daysago5 -LATE-
501 # quantityreceived = quantity -NOT LATE-
502 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10,
504 isnt
( exists( $suppliers{$id_supplier1} ),
505 1, "Supplier1 has late orders but $daysago10 < $daysago5 < $today" );
507 exists( $suppliers{$id_supplier2} ),
509 "Supplier2 has late orders but $daysago10 < $daysago5 < $daysago5+2"
512 exists( $suppliers{$id_supplier3} ),
513 "Supplier3 has late orders and $daysago10 <= $daysago10 +3 <= $daysago5"
515 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
517 #Case 7: With $estimateddeliverydateto = today-5
518 # $today >= $daysago5 -NOT LATE-
519 # $daysago5 + 2 days > $daysago5 -NOT LATE-
520 # $daysago10 + 3 <+ $daysago5 -LATE-
521 # quantityreceived = quantity -NOT LATE-
523 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, undef, $daysago5 );
524 isnt
( exists( $suppliers{$id_supplier1} ),
526 "Supplier1 has late orders but $today >= $daysago5 - deliverytime undef" );
527 isnt
( exists( $suppliers{$id_supplier2} ),
528 1, "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 " );
529 ok
( exists( $suppliers{$id_supplier3} ),
530 "Supplier3 has late orders and $daysago10 + 3 <= $daysago5" );
531 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
533 #Test with $estimateddeliverydatefrom and $estimateddeliverydateto and $delay
534 #Case 8 :With $estimateddeliverydatefrom = 2013-07-05 and $estimateddeliverydateto = 2013-07-08 and $delay =5
535 # $daysago4<today<=$today and $today<now()-3 -NOT LATE-
536 # $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days -LATE-
537 # $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days -NOT LATE-
538 # quantityreceived = quantity -NOT LATE-
540 C4
::Bookseller
::GetBooksellersWithLateOrders
( 3, $daysago4, $today );
542 exists( $suppliers{$id_supplier1} ),
544 "Supplier1 has late orders but $daysago4<today<=$today and $today<now()-3"
547 exists( $suppliers{$id_supplier2} ),
548 "Supplier2 has late orders and $daysago4 < $daysago5 + 2days <= today and $daysago5 <= now()-3+2 days"
551 exists( $suppliers{$id_supplier3} ),
552 "Supplier3 has late orders but $daysago4 > $daysago10 + 3days < today and $daysago10 <= now()-3+3 days"
554 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
556 #Case 9 :With $estimateddeliverydatefrom = $daysago5 and $delay = 3
557 # $today < $daysago5 and $today > $today-5 -NOT LATE-
558 # $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2 -LATE-
559 # $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2-NOT LATE-
560 # quantityreceived = quantity -NOT LATE-
562 C4
::Bookseller
::GetBooksellersWithLateOrders
( 3, $daysago5, undef );
563 isnt
( exists( $suppliers{$id_supplier1} ),
564 1, "$today < $daysago10 and $today > $today-3" );
566 exists( $suppliers{$id_supplier2} ),
567 "Supplier2 has late orders and $daysago5 + 2 days >= $daysago5 and $daysago5 < today - 3+2"
570 exists( $suppliers{$id_supplier3} ),
572 "Supplier2 has late orders but $daysago10 + 3 days < $daysago5 and $daysago10 < today -3+2 "
574 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
576 #Test with $estimateddeliverydateto and $delay
577 #Case 10:With $estimateddeliverydateto = $daysago5 and $delay = 5
578 # today > $daysago5 today > now() -5 -NOT LATE-
579 # $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days -NOT LATE-
580 # $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days -LATE-
581 # quantityreceived = quantity -NOT LATE-
583 C4
::Bookseller
::GetBooksellersWithLateOrders
( 5, undef, $daysago5 );
584 isnt
( exists( $suppliers{$id_supplier1} ),
585 1, "Supplier2 has late orders but today > $daysago5 today > now() -5" );
587 exists( $suppliers{$id_supplier2} ),
589 "Supplier2 has late orders but $daysago5 + 2 days > $daysago5 and $daysago5 > now() - 2+5 days"
592 exists( $suppliers{$id_supplier3} ),
593 "Supplier2 has late orders and $daysago10 + 3 days <= $daysago5 and $daysago10 <= now() - 3+5 days "
595 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
597 #Case 11: With $estimateddeliverydatefrom =today-10 and $estimateddeliverydateto = today - 10
598 # $daysago10==$daysago10==$daysago10 -NOT LATE-
599 # $daysago10==$daysago10<$daysago5+2-NOT lATE-
600 # $daysago10==$daysago10 <$daysago10+3-LATE-
601 # quantityreceived = quantity -NOT LATE-
603 #Basket1 closedate -> $daysago10
605 basketno
=> $basketno1,
606 closedate
=> $daysago10,
608 ModBasket
($basket1info);
609 %suppliers = C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10,
611 ok
( exists( $suppliers{$id_supplier1} ),
612 "Supplier1 has late orders and $daysago10==$daysago10==$daysago10 " )
614 isnt
( exists( $suppliers{$id_supplier2} ),
616 "Supplier2 has late orders but $daysago10==$daysago10<$daysago5+2" );
617 isnt
( exists( $suppliers{$id_supplier3} ),
619 "Supplier3 has late orders but $daysago10==$daysago10 <$daysago10+3" );
620 isnt
( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" );
622 #Case 12: closedate == $estimateddeliverydatefrom =today-10
624 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, $daysago10, undef );
625 ok
( exists( $suppliers{$id_supplier1} ),
626 "Supplier1 has late orders and $daysago10==$daysago10 " );
628 #Case 13: closedate == $estimateddeliverydateto =today-10
630 C4
::Bookseller
::GetBooksellersWithLateOrders
( undef, undef, $daysago10 );
631 ok
( exists( $suppliers{$id_supplier1} ),
632 "Supplier1 has late orders and $daysago10==$daysago10 " )
635 C4
::Context
->_new_userenv('DUMMY SESSION');
636 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', '');
637 my $userenv = C4
::Context
->userenv;
639 my $module = Test
::MockModule
->new('C4::Auth');
643 # simulate user that has serials permissions but
645 my ($userid, $flagsrequired) = @_;
646 return 0 if 'superserials' eq ($flagsrequired->{serials
} // 0);
647 return exists($flagsrequired->{serials
});
651 t
::lib
::Mocks
::mock_preference
('IndependentBranches', 0);
652 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
654 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
656 'ordinary user can see all subscriptions with IndependentBranches off'
659 t
::lib
::Mocks
::mock_preference
('IndependentBranches', 1);
660 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
662 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
664 'ordinary user can see only their library\'s subscriptions with IndependentBranches on'
667 # don the cape and turn into Superlibrarian!
668 C4
::Context
->set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', '');
669 @subscriptions = SearchSubscriptions
({expiration_date
=> '2013-12-31'});
671 scalar(grep { !$_->{cannotdisplay
} } @subscriptions ),
673 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)'
676 #Test contact editing
677 my $sample_supplier = {
679 address1
=> "bookseller's address",
683 my $supplier = Koha
::Acquisition
::Bookseller
->new($sample_supplier)->store;
684 my $booksellerid = $supplier->id;
685 my $contact1 = Koha
::Acquisition
::Bookseller
::Contact
->new({
686 name
=> 'John Smith',
687 phone
=> '0123456x1',
688 booksellerid
=> $booksellerid,
690 my $contact2 = Koha
::Acquisition
::Bookseller
::Contact
->new({
691 name
=> 'Leo Tolstoy',
692 phone
=> '0123456x2',
693 booksellerid
=> $booksellerid,
696 @booksellers = Koha
::Acquisition
::Booksellers
->search({ name
=> 'my vendor' });
698 ( grep { $_->id == $booksellerid } @booksellers ),
699 'Koha::Acquisition::Booksellers->search returns correct record when passed a name'
702 my $bookseller = Koha
::Acquisition
::Booksellers
->find( $booksellerid );
703 is
( $bookseller->id, $booksellerid, 'Retrieved desired record' );
704 is
( $bookseller->phone, '0123456', 'New bookseller has expected phone' );
705 my $contacts = $bookseller->contacts;
706 is
( $contacts->count,
707 2, 'bookseller should have 2 contacts' );
708 my $first_contact = $contacts->next;
711 'Koha::Acquisition::Bookseller::Contact',
712 'First contact is a AqContact'
714 is
( $first_contact->phone,
715 '0123456x1', 'Contact has expected phone number' );
717 my $second_contact = $contacts->next;
718 $second_contact->delete;
719 $bookseller = Koha
::Acquisition
::Booksellers
->find( $booksellerid );
720 $bookseller->name('your vendor')->store;
721 $contacts = $bookseller->contacts;
722 $first_contact = $contacts->next;
723 $first_contact->phone('654321');
724 $first_contact->store;
726 $bookseller = Koha
::Acquisition
::Booksellers
->find( $booksellerid );
727 is
( $bookseller->name, 'your vendor',
728 'Successfully changed name of vendor' );
729 $contacts = $bookseller->contacts;
730 is
( $contacts->count,
731 1, 'Only one contact after modification' );
732 $first_contact = $contacts->next;
733 is
( $first_contact->phone,
735 'Successfully changed contact phone number by modifying bookseller hash' );
737 $first_contact->name( 'John Jacob Jingleheimer Schmidt' );
738 $first_contact->phone(undef);
739 $first_contact->store;
741 $bookseller = Koha
::Acquisition
::Booksellers
->find( $booksellerid );
742 $contacts = $bookseller->contacts;
743 $first_contact = $contacts->next;
745 $first_contact->name,
746 'John Jacob Jingleheimer Schmidt',
747 'Changed name of contact'
749 is
( $first_contact->phone,
750 undef, 'Removed phone number from contact' );
751 is
( $contacts->count,
752 1, 'Only one contact after modification' );
755 $schema->storage->txn_rollback();
757 #field_filter filters the useless fields or foreign keys
758 #NOTE: all the fields of aqbookseller arent considered
759 #returns a cleaned structure
764 'bookselleremail', 'booksellerfax',
765 'booksellerurl', 'othersupplier',
766 'currency', 'invoiceprice',
767 'listprice', 'contacts'
771 if ( grep { /^$field$/ } keys %$struct ) {
772 delete $struct->{$field};