7 use Koha::IssuingRules;
10 use Test::More tests => 10;
13 use_ok('C4::Circulation');
24 my $dbh = C4::Context->dbh;
25 $dbh->{RaiseError} = 1;
26 $dbh->{AutoCommit} = 0;
28 $dbh->do(q|DELETE FROM issues|);
29 $dbh->do(q|DELETE FROM items|);
30 $dbh->do(q|DELETE FROM borrowers|);
31 $dbh->do(q|DELETE FROM edifact_ean|);
32 $dbh->do(q|DELETE FROM branches|);
33 $dbh->do(q|DELETE FROM categories|);
34 $dbh->do(q|DELETE FROM issuingrules|);
38 #Add branch and category
41 branchname => 'Sample Branch',
42 branchaddress1 => 'sample adr1',
43 branchaddress2 => 'sample adr2',
44 branchaddress3 => 'sample adr3',
45 branchzip => 'sample zip',
46 branchcity => 'sample city',
47 branchstate => 'sample state',
48 branchcountry => 'sample country',
49 branchphone => 'sample phone',
50 branchfax => 'sample fax',
51 branchemail => 'sample email',
52 branchurl => 'sample url',
53 branchip => 'sample ip',
54 branchprinter => undef,
55 opac_info => 'sample opac',
59 branchname => 'Sample Branch2',
60 branchaddress1 => 'sample adr1_2',
61 branchaddress2 => 'sample adr2_2',
62 branchaddress3 => 'sample adr3_2',
63 branchzip => 'sample zip2',
64 branchcity => 'sample city2',
65 branchstate => 'sample state2',
66 branchcountry => 'sample country2',
67 branchphone => 'sample phone2',
68 branchfax => 'sample fax2',
69 branchemail => 'sample email2',
70 branchurl => 'sample url2',
71 branchip => 'sample ip2',
72 branchprinter => undef,
73 opac_info => 'sample opac2',
75 Koha::Library->new($samplebranch1)->store;
76 Koha::Library->new($samplebranch2)->store;
79 categorycode => 'CAT1',
80 description => 'Description1',
81 enrolmentperiod => undef,
82 enrolmentperioddate => undef,
83 dateofbirthrequired => undef,
86 enrolmentfee => undef,
87 overduenoticerequired => undef,
94 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
97 $samplecat->{categorycode}, $samplecat->{description},
98 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
99 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
100 $samplecat->{bulk}, $samplecat->{enrolmentfee},
101 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
102 $samplecat->{reservefee}, $samplecat->{hidelostitems},
103 $samplecat->{category_type}
115 my $sampleissuingrule1 = {
116 reservecharge => '0.000000',
121 maxonsiteissueqty => 4,
123 lengthunit => 'days',
125 norenewalbefore => 6,
129 chargeperiod_charge_at => 0,
130 rentaldiscount => '2.000000',
131 reservesallowed => 0,
132 hardduedate => '2013-01-01',
133 branchcode => $samplebranch1->{branchcode},
135 hardduedatecompare => 0,
136 overduefinescap => '0.000000',
137 renewalsallowed => 0,
140 categorycode => $samplecat->{categorycode},
141 maxsuspensiondays => 0,
143 opacitemholds => 'N',
144 cap_fine_to_replacement_price => 0,
145 holds_per_record => 1,
146 article_requests => 'yes',
147 no_auto_renewal_after => undef,
148 no_auto_renewal_after_hard_limit => undef,
149 suspension_chargeperiod => 1,
150 holds_per_day => undef,
153 my $sampleissuingrule2 = {
154 branchcode => $samplebranch2->{branchcode},
155 categorycode => $samplecat->{categorycode},
158 maxonsiteissueqty => 1,
159 renewalsallowed => 0,
161 norenewalbefore => 7,
163 reservesallowed => 0,
165 lengthunit => 'days',
166 hardduedate => undef,
167 hardduedatecompare => 0,
170 firstremind => undef,
171 chargeperiod => undef,
172 chargeperiod_charge_at => 0,
173 rentaldiscount => 2.00,
174 overduefinescap => undef,
175 accountsent => undef,
176 reservecharge => undef,
178 restrictedtype => undef,
179 maxsuspensiondays => 0,
181 opacitemholds => 'Y',
182 cap_fine_to_replacement_price => 0,
183 holds_per_record => 1,
184 article_requests => 'yes',
186 my $sampleissuingrule3 = {
187 branchcode => $samplebranch1->{branchcode},
188 categorycode => $samplecat->{categorycode},
191 maxonsiteissueqty => 2,
192 renewalsallowed => 0,
194 norenewalbefore => 8,
196 reservesallowed => 0,
198 lengthunit => 'days',
199 hardduedate => undef,
200 hardduedatecompare => 0,
203 firstremind => undef,
204 chargeperiod => undef,
205 chargeperiod_charge_at => 0,
206 rentaldiscount => 3.00,
207 overduefinescap => undef,
208 accountsent => undef,
209 reservecharge => undef,
211 restrictedtype => undef,
212 maxsuspensiondays => 0,
214 opacitemholds => 'F',
215 cap_fine_to_replacement_price => 0,
216 holds_per_record => 1,
217 article_requests => 'yes',
220 $query = 'INSERT INTO issuingrules (
239 chargeperiod_charge_at,
249 cap_fine_to_replacement_price,
251 ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
252 my $sth = $dbh->prepare($query);
254 $sampleissuingrule1->{branchcode},
255 $sampleissuingrule1->{categorycode},
256 $sampleissuingrule1->{itemtype},
257 $sampleissuingrule1->{maxissueqty},
258 $sampleissuingrule1->{maxonsiteissueqty},
259 $sampleissuingrule1->{renewalsallowed},
260 $sampleissuingrule1->{renewalperiod},
261 $sampleissuingrule1->{norenewalbefore},
262 $sampleissuingrule1->{auto_renew},
263 $sampleissuingrule1->{reservesallowed},
264 $sampleissuingrule1->{issuelength},
265 $sampleissuingrule1->{lengthunit},
266 $sampleissuingrule1->{hardduedate},
267 $sampleissuingrule1->{hardduedatecompare},
268 $sampleissuingrule1->{fine},
269 $sampleissuingrule1->{finedays},
270 $sampleissuingrule1->{firstremind},
271 $sampleissuingrule1->{chargeperiod},
272 $sampleissuingrule1->{chargeperiod_charge_at},
273 $sampleissuingrule1->{rentaldiscount},
274 $sampleissuingrule1->{overduefinescap},
275 $sampleissuingrule1->{accountsent},
276 $sampleissuingrule1->{reservecharge},
277 $sampleissuingrule1->{chargename},
278 $sampleissuingrule1->{restrictedtype},
279 $sampleissuingrule1->{maxsuspensiondays},
280 $sampleissuingrule1->{onshelfholds},
281 $sampleissuingrule1->{opacitemholds},
282 $sampleissuingrule1->{cap_fine_to_replacement_price},
283 $sampleissuingrule1->{article_requests},
286 $sampleissuingrule2->{branchcode},
287 $sampleissuingrule2->{categorycode},
288 $sampleissuingrule2->{itemtype},
289 $sampleissuingrule2->{maxissueqty},
290 $sampleissuingrule2->{maxonsiteissueqty},
291 $sampleissuingrule2->{renewalsallowed},
292 $sampleissuingrule2->{renewalperiod},
293 $sampleissuingrule2->{norenewalbefore},
294 $sampleissuingrule2->{auto_renew},
295 $sampleissuingrule2->{reservesallowed},
296 $sampleissuingrule2->{issuelength},
297 $sampleissuingrule2->{lengthunit},
298 $sampleissuingrule2->{hardduedate},
299 $sampleissuingrule2->{hardduedatecompare},
300 $sampleissuingrule2->{fine},
301 $sampleissuingrule2->{finedays},
302 $sampleissuingrule2->{firstremind},
303 $sampleissuingrule2->{chargeperiod},
304 $sampleissuingrule2->{chargeperiod_charge_at},
305 $sampleissuingrule2->{rentaldiscount},
306 $sampleissuingrule2->{overduefinescap},
307 $sampleissuingrule2->{accountsent},
308 $sampleissuingrule2->{reservecharge},
309 $sampleissuingrule2->{chargename},
310 $sampleissuingrule2->{restrictedtype},
311 $sampleissuingrule2->{maxsuspensiondays},
312 $sampleissuingrule2->{onshelfholds},
313 $sampleissuingrule2->{opacitemholds},
314 $sampleissuingrule2->{cap_fine_to_replacement_price},
315 $sampleissuingrule2->{article_requests},
318 $sampleissuingrule3->{branchcode},
319 $sampleissuingrule3->{categorycode},
320 $sampleissuingrule3->{itemtype},
321 $sampleissuingrule3->{maxissueqty},
322 $sampleissuingrule3->{maxonsiteissueqty},
323 $sampleissuingrule3->{renewalsallowed},
324 $sampleissuingrule3->{renewalperiod},
325 $sampleissuingrule3->{norenewalbefore},
326 $sampleissuingrule3->{auto_renew},
327 $sampleissuingrule3->{reservesallowed},
328 $sampleissuingrule3->{issuelength},
329 $sampleissuingrule3->{lengthunit},
330 $sampleissuingrule3->{hardduedate},
331 $sampleissuingrule3->{hardduedatecompare},
332 $sampleissuingrule3->{fine},
333 $sampleissuingrule3->{finedays},
334 $sampleissuingrule3->{firstremind},
335 $sampleissuingrule3->{chargeperiod},
336 $sampleissuingrule3->{chargeperiod_charge_at},
337 $sampleissuingrule3->{rentaldiscount},
338 $sampleissuingrule3->{overduefinescap},
339 $sampleissuingrule3->{accountsent},
340 $sampleissuingrule3->{reservecharge},
341 $sampleissuingrule3->{chargename},
342 $sampleissuingrule3->{restrictedtype},
343 $sampleissuingrule3->{maxsuspensiondays},
344 $sampleissuingrule3->{onshelfholds},
345 $sampleissuingrule3->{opacitemholds},
346 $sampleissuingrule3->{cap_fine_to_replacement_price},
347 $sampleissuingrule3->{article_requests},
351 Koha::IssuingRules->find({ categorycode => $samplecat->{categorycode}, itemtype => 'Book', branchcode => $samplebranch1->{branchcode} })->unblessed,
353 "GetIssuingCharge returns issuingrule1's informations"
358 C4::Circulation::GetLoanLength(
359 $samplecat->{categorycode},
360 'BOOK', $samplebranch1->{branchcode}
362 { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
367 C4::Circulation::GetLoanLength(),
369 "Without parameters, GetLoanLength returns hardcoded values"
372 C4::Circulation::GetLoanLength( -1, -1 ),
374 "With wrong parameters, GetLoanLength returns hardcoded values"
377 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
379 "With only one parameter, GetLoanLength returns hardcoded values"
380 ); #NOTE : is that really what is expected?
382 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
384 "With only two parameters, GetLoanLength returns hardcoded values"
385 ); #NOTE : is that really what is expected?
387 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK', $samplebranch1->{branchcode} ),
391 lengthunit => 'days',
393 "With the correct number of parameters, GetLoanLength returns the expected values"
397 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
398 'BOOK', $samplebranch1->{branchcode} );
402 dt_from_string( $sampleissuingrule1->{hardduedate}, 'iso' ),
403 $sampleissuingrule1->{hardduedatecompare}
405 "GetHardDueDate returns the duedate and the duedatecompare"