8 use Koha::IssuingRules;
11 use Test::More tests => 9;
14 use_ok('C4::Circulation');
24 my $schema = Koha::Database->new->schema;
25 $schema->storage->txn_begin;
26 my $dbh = C4::Context->dbh;
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',
120 lengthunit => 'days',
122 norenewalbefore => 6,
126 chargeperiod_charge_at => 0,
127 rentaldiscount => '2.000000',
128 reservesallowed => 0,
129 hardduedate => '2013-01-01',
130 branchcode => $samplebranch1->{branchcode},
132 hardduedatecompare => 0,
133 overduefinescap => '0.000000',
134 renewalsallowed => 0,
137 categorycode => $samplecat->{categorycode},
138 maxsuspensiondays => 0,
140 opacitemholds => 'N',
141 cap_fine_to_replacement_price => 0,
142 holds_per_record => 1,
143 article_requests => 'yes',
144 no_auto_renewal_after => undef,
145 no_auto_renewal_after_hard_limit => undef,
146 suspension_chargeperiod => 1,
147 holds_per_day => undef,
149 my $sampleissuingrule2 = {
150 branchcode => $samplebranch2->{branchcode},
151 categorycode => $samplecat->{categorycode},
153 renewalsallowed => 0,
155 norenewalbefore => 7,
157 reservesallowed => 0,
159 lengthunit => 'days',
160 hardduedate => undef,
161 hardduedatecompare => 0,
164 firstremind => undef,
165 chargeperiod => undef,
166 chargeperiod_charge_at => 0,
167 rentaldiscount => 2.00,
168 overduefinescap => undef,
169 accountsent => undef,
170 reservecharge => undef,
171 restrictedtype => undef,
172 maxsuspensiondays => 0,
174 opacitemholds => 'Y',
175 cap_fine_to_replacement_price => 0,
176 holds_per_record => 1,
177 article_requests => 'yes',
179 my $sampleissuingrule3 = {
180 branchcode => $samplebranch1->{branchcode},
181 categorycode => $samplecat->{categorycode},
183 renewalsallowed => 0,
185 norenewalbefore => 8,
187 reservesallowed => 0,
189 lengthunit => 'days',
190 hardduedate => undef,
191 hardduedatecompare => 0,
194 firstremind => undef,
195 chargeperiod => undef,
196 chargeperiod_charge_at => 0,
197 rentaldiscount => 3.00,
198 overduefinescap => undef,
199 accountsent => undef,
200 reservecharge => undef,
201 restrictedtype => undef,
202 maxsuspensiondays => 0,
204 opacitemholds => 'F',
205 cap_fine_to_replacement_price => 0,
206 holds_per_record => 1,
207 article_requests => 'yes',
210 $query = 'INSERT INTO issuingrules (
227 chargeperiod_charge_at,
236 cap_fine_to_replacement_price,
238 ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
239 my $sth = $dbh->prepare($query);
241 $sampleissuingrule1->{branchcode},
242 $sampleissuingrule1->{categorycode},
243 $sampleissuingrule1->{itemtype},
244 $sampleissuingrule1->{renewalsallowed},
245 $sampleissuingrule1->{renewalperiod},
246 $sampleissuingrule1->{norenewalbefore},
247 $sampleissuingrule1->{auto_renew},
248 $sampleissuingrule1->{reservesallowed},
249 $sampleissuingrule1->{issuelength},
250 $sampleissuingrule1->{lengthunit},
251 $sampleissuingrule1->{hardduedate},
252 $sampleissuingrule1->{hardduedatecompare},
253 $sampleissuingrule1->{fine},
254 $sampleissuingrule1->{finedays},
255 $sampleissuingrule1->{firstremind},
256 $sampleissuingrule1->{chargeperiod},
257 $sampleissuingrule1->{chargeperiod_charge_at},
258 $sampleissuingrule1->{rentaldiscount},
259 $sampleissuingrule1->{overduefinescap},
260 $sampleissuingrule1->{accountsent},
261 $sampleissuingrule1->{reservecharge},
262 $sampleissuingrule1->{restrictedtype},
263 $sampleissuingrule1->{maxsuspensiondays},
264 $sampleissuingrule1->{onshelfholds},
265 $sampleissuingrule1->{opacitemholds},
266 $sampleissuingrule1->{cap_fine_to_replacement_price},
267 $sampleissuingrule1->{article_requests},
270 $sampleissuingrule2->{branchcode},
271 $sampleissuingrule2->{categorycode},
272 $sampleissuingrule2->{itemtype},
273 $sampleissuingrule2->{renewalsallowed},
274 $sampleissuingrule2->{renewalperiod},
275 $sampleissuingrule2->{norenewalbefore},
276 $sampleissuingrule2->{auto_renew},
277 $sampleissuingrule2->{reservesallowed},
278 $sampleissuingrule2->{issuelength},
279 $sampleissuingrule2->{lengthunit},
280 $sampleissuingrule2->{hardduedate},
281 $sampleissuingrule2->{hardduedatecompare},
282 $sampleissuingrule2->{fine},
283 $sampleissuingrule2->{finedays},
284 $sampleissuingrule2->{firstremind},
285 $sampleissuingrule2->{chargeperiod},
286 $sampleissuingrule2->{chargeperiod_charge_at},
287 $sampleissuingrule2->{rentaldiscount},
288 $sampleissuingrule2->{overduefinescap},
289 $sampleissuingrule2->{accountsent},
290 $sampleissuingrule2->{reservecharge},
291 $sampleissuingrule2->{restrictedtype},
292 $sampleissuingrule2->{maxsuspensiondays},
293 $sampleissuingrule2->{onshelfholds},
294 $sampleissuingrule2->{opacitemholds},
295 $sampleissuingrule2->{cap_fine_to_replacement_price},
296 $sampleissuingrule2->{article_requests},
299 $sampleissuingrule3->{branchcode},
300 $sampleissuingrule3->{categorycode},
301 $sampleissuingrule3->{itemtype},
302 $sampleissuingrule3->{renewalsallowed},
303 $sampleissuingrule3->{renewalperiod},
304 $sampleissuingrule3->{norenewalbefore},
305 $sampleissuingrule3->{auto_renew},
306 $sampleissuingrule3->{reservesallowed},
307 $sampleissuingrule3->{issuelength},
308 $sampleissuingrule3->{lengthunit},
309 $sampleissuingrule3->{hardduedate},
310 $sampleissuingrule3->{hardduedatecompare},
311 $sampleissuingrule3->{fine},
312 $sampleissuingrule3->{finedays},
313 $sampleissuingrule3->{firstremind},
314 $sampleissuingrule3->{chargeperiod},
315 $sampleissuingrule3->{chargeperiod_charge_at},
316 $sampleissuingrule3->{rentaldiscount},
317 $sampleissuingrule3->{overduefinescap},
318 $sampleissuingrule3->{accountsent},
319 $sampleissuingrule3->{reservecharge},
320 $sampleissuingrule3->{restrictedtype},
321 $sampleissuingrule3->{maxsuspensiondays},
322 $sampleissuingrule3->{onshelfholds},
323 $sampleissuingrule3->{opacitemholds},
324 $sampleissuingrule3->{cap_fine_to_replacement_price},
325 $sampleissuingrule3->{article_requests},
330 C4::Circulation::GetLoanLength(
331 $samplecat->{categorycode},
332 'BOOK', $samplebranch1->{branchcode}
334 { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
339 C4::Circulation::GetLoanLength(),
341 "Without parameters, GetLoanLength returns hardcoded values"
344 C4::Circulation::GetLoanLength( -1, -1 ),
346 "With wrong parameters, GetLoanLength returns hardcoded values"
349 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
351 "With only one parameter, GetLoanLength returns hardcoded values"
352 ); #NOTE : is that really what is expected?
354 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
356 "With only two parameters, GetLoanLength returns hardcoded values"
357 ); #NOTE : is that really what is expected?
359 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK', $samplebranch1->{branchcode} ),
363 lengthunit => 'days',
365 "With the correct number of parameters, GetLoanLength returns the expected values"
369 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
370 'BOOK', $samplebranch1->{branchcode} );
374 dt_from_string( $sampleissuingrule1->{hardduedate}, 'iso' ),
375 $sampleissuingrule1->{hardduedatecompare}
377 "GetHardDueDate returns the duedate and the duedatecompare"