9 use Test::More tests => 9;
12 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 branches|);
32 $dbh->do(q|DELETE FROM categories|);
33 $dbh->do(q|DELETE FROM issuingrules|);
37 #Add branch and category
40 branchname => 'Sample Branch',
41 branchaddress1 => 'sample adr1',
42 branchaddress2 => 'sample adr2',
43 branchaddress3 => 'sample adr3',
44 branchzip => 'sample zip',
45 branchcity => 'sample city',
46 branchstate => 'sample state',
47 branchcountry => 'sample country',
48 branchphone => 'sample phone',
49 branchfax => 'sample fax',
50 branchemail => 'sample email',
51 branchurl => 'sample url',
52 branchip => 'sample ip',
53 branchprinter => undef,
54 opac_info => 'sample opac',
58 branchname => 'Sample Branch2',
59 branchaddress1 => 'sample adr1_2',
60 branchaddress2 => 'sample adr2_2',
61 branchaddress3 => 'sample adr3_2',
62 branchzip => 'sample zip2',
63 branchcity => 'sample city2',
64 branchstate => 'sample state2',
65 branchcountry => 'sample country2',
66 branchphone => 'sample phone2',
67 branchfax => 'sample fax2',
68 branchemail => 'sample email2',
69 branchurl => 'sample url2',
70 branchip => 'sample ip2',
71 branchprinter => undef,
72 opac_info => 'sample opac2',
74 Koha::Library->new($samplebranch1)->store;
75 Koha::Library->new($samplebranch2)->store;
78 categorycode => 'CAT1',
79 description => 'Description1',
80 enrolmentperiod => 'Null',
81 enrolmentperioddate => 'Null',
82 dateofbirthrequired => 'Null',
85 enrolmentfee => 'Null',
86 overduenoticerequired => 'Null',
90 category_type => 'Null'
93 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
96 $samplecat->{categorycode}, $samplecat->{description},
97 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
98 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
99 $samplecat->{bulk}, $samplecat->{enrolmentfee},
100 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
101 $samplecat->{reservefee}, $samplecat->{hidelostitems},
102 $samplecat->{category_type}
108 my $sampleissuingrule1 = {
109 reservecharge => '0.000000',
110 chargename => 'Null',
114 maxonsiteissueqty => 4,
116 lengthunit => 'Null',
118 norenewalbefore => 6,
122 chargeperiod_charge_at => 0,
123 rentaldiscount => '2.000000',
124 reservesallowed => 0,
125 hardduedate => '2013-01-01',
126 branchcode => $samplebranch1->{branchcode},
128 hardduedatecompare => 5,
129 overduefinescap => '0.000000',
130 renewalsallowed => 0,
133 categorycode => $samplecat->{categorycode},
134 maxsuspensiondays => 0,
136 opacitemholds => 'N',
138 my $sampleissuingrule2 = {
139 branchcode => $samplebranch2->{branchcode},
140 categorycode => $samplecat->{categorycode},
143 maxonsiteissueqty => 1,
144 renewalsallowed => 'Null',
146 norenewalbefore => 7,
148 reservesallowed => 'Null',
150 lengthunit => 'Null',
152 hardduedatecompare => 'Null',
155 firstremind => 'Null',
156 chargeperiod => 'Null',
157 chargeperiod_charge_at => 0,
158 rentaldiscount => 2.00,
159 overduefinescap => 'Null',
160 accountsent => 'Null',
161 reservecharge => 'Null',
162 chargename => 'Null',
163 restrictedtype => 'Null',
164 maxsuspensiondays => 0,
166 opacitemholds => 'Y',
168 my $sampleissuingrule3 = {
169 branchcode => $samplebranch1->{branchcode},
170 categorycode => $samplecat->{categorycode},
173 maxonsiteissueqty => 2,
174 renewalsallowed => 'Null',
176 norenewalbefore => 8,
178 reservesallowed => 'Null',
180 lengthunit => 'Null',
182 hardduedatecompare => 'Null',
185 firstremind => 'Null',
186 chargeperiod => 'Null',
187 chargeperiod_charge_at => 0,
188 rentaldiscount => 3.00,
189 overduefinescap => 'Null',
190 accountsent => 'Null',
191 reservecharge => 'Null',
192 chargename => 'Null',
193 restrictedtype => 'Null',
194 maxsuspensiondays => 0,
196 opacitemholds => 'F',
199 $query = 'INSERT INTO issuingrules (
218 chargeperiod_charge_at,
226 ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
227 my $sth = $dbh->prepare($query);
229 $sampleissuingrule1->{branchcode},
230 $sampleissuingrule1->{categorycode},
231 $sampleissuingrule1->{itemtype},
232 $sampleissuingrule1->{maxissueqty},
233 $sampleissuingrule1->{maxonsiteissueqty},
234 $sampleissuingrule1->{renewalsallowed},
235 $sampleissuingrule1->{renewalperiod},
236 $sampleissuingrule1->{norenewalbefore},
237 $sampleissuingrule1->{auto_renew},
238 $sampleissuingrule1->{reservesallowed},
239 $sampleissuingrule1->{issuelength},
240 $sampleissuingrule1->{lengthunit},
241 $sampleissuingrule1->{hardduedate},
242 $sampleissuingrule1->{hardduedatecompare},
243 $sampleissuingrule1->{fine},
244 $sampleissuingrule1->{finedays},
245 $sampleissuingrule1->{firstremind},
246 $sampleissuingrule1->{chargeperiod},
247 $sampleissuingrule1->{chargeperiod_charge_at},
248 $sampleissuingrule1->{rentaldiscount},
249 $sampleissuingrule1->{overduefinescap},
250 $sampleissuingrule1->{accountsent},
251 $sampleissuingrule1->{reservecharge},
252 $sampleissuingrule1->{chargename},
253 $sampleissuingrule1->{restrictedtype},
254 $sampleissuingrule1->{maxsuspensiondays},
257 $sampleissuingrule2->{branchcode},
258 $sampleissuingrule2->{categorycode},
259 $sampleissuingrule2->{itemtype},
260 $sampleissuingrule2->{maxissueqty},
261 $sampleissuingrule2->{maxonsiteissueqty},
262 $sampleissuingrule2->{renewalsallowed},
263 $sampleissuingrule2->{renewalperiod},
264 $sampleissuingrule2->{norenewalbefore},
265 $sampleissuingrule2->{auto_renew},
266 $sampleissuingrule2->{reservesallowed},
267 $sampleissuingrule2->{issuelength},
268 $sampleissuingrule2->{lengthunit},
269 $sampleissuingrule2->{hardduedate},
270 $sampleissuingrule2->{hardduedatecompare},
271 $sampleissuingrule2->{fine},
272 $sampleissuingrule2->{finedays},
273 $sampleissuingrule2->{firstremind},
274 $sampleissuingrule2->{chargeperiod},
275 $sampleissuingrule2->{chargeperiod_charge_at},
276 $sampleissuingrule2->{rentaldiscount},
277 $sampleissuingrule2->{overduefinescap},
278 $sampleissuingrule2->{accountsent},
279 $sampleissuingrule2->{reservecharge},
280 $sampleissuingrule2->{chargename},
281 $sampleissuingrule2->{restrictedtype},
282 $sampleissuingrule2->{maxsuspensiondays},
285 $sampleissuingrule3->{branchcode},
286 $sampleissuingrule3->{categorycode},
287 $sampleissuingrule3->{itemtype},
288 $sampleissuingrule3->{maxissueqty},
289 $sampleissuingrule3->{maxonsiteissueqty},
290 $sampleissuingrule3->{renewalsallowed},
291 $sampleissuingrule3->{renewalperiod},
292 $sampleissuingrule3->{norenewalbefore},
293 $sampleissuingrule3->{auto_renew},
294 $sampleissuingrule3->{reservesallowed},
295 $sampleissuingrule3->{issuelength},
296 $sampleissuingrule3->{lengthunit},
297 $sampleissuingrule3->{hardduedate},
298 $sampleissuingrule3->{hardduedatecompare},
299 $sampleissuingrule3->{fine},
300 $sampleissuingrule3->{finedays},
301 $sampleissuingrule3->{firstremind},
302 $sampleissuingrule3->{chargeperiod},
303 $sampleissuingrule3->{chargeperiod_charge_at},
304 $sampleissuingrule3->{rentaldiscount},
305 $sampleissuingrule3->{overduefinescap},
306 $sampleissuingrule3->{accountsent},
307 $sampleissuingrule3->{reservecharge},
308 $sampleissuingrule3->{chargename},
309 $sampleissuingrule3->{restrictedtype},
310 $sampleissuingrule3->{maxsuspensiondays},
315 $samplecat->{categorycode},
316 'Book', $samplebranch1->{branchcode}
319 "GetIssuingCharge returns issuingrule1's informations"
324 C4::Circulation::GetLoanLength(
325 $samplecat->{categorycode},
326 'BOOK', $samplebranch1->{branchcode}
328 { issuelength => 5, lengthunit => 'Null', renewalperiod => 5 },
332 C4::Circulation::GetLoanLength(),
336 lengthunit => 'days',
338 "Without parameters, GetLoanLength returns hardcoded values"
341 C4::Circulation::GetLoanLength( -1, -1 ),
345 lengthunit => 'days',
347 "With wrong parameters, GetLoanLength returns hardcoded values"
350 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
354 lengthunit => 'days',
356 "With only one parameter, GetLoanLength returns hardcoded values"
357 ); #NOTE : is that really what is expected?
359 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
363 lengthunit => 'days',
365 "With only one parameter, GetLoanLength returns hardcoded values"
366 ); #NOTE : is that really what is expected?
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"