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
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',
60 branchname => 'Sample Branch2',
61 branchaddress1 => 'sample adr1_2',
62 branchaddress2 => 'sample adr2_2',
63 branchaddress3 => 'sample adr3_2',
64 branchzip => 'sample zip2',
65 branchcity => 'sample city2',
66 branchstate => 'sample state2',
67 branchcountry => 'sample country2',
68 branchphone => 'sample phone2',
69 branchfax => 'sample fax2',
70 branchemail => 'sample email2',
71 branchurl => 'sample url2',
72 branchip => 'sample ip2',
73 branchprinter => undef,
74 opac_info => 'sample opac2',
76 ModBranch($samplebranch1);
77 ModBranch($samplebranch2);
80 categorycode => 'CAT1',
81 description => 'Description1',
82 enrolmentperiod => 'Null',
83 enrolmentperioddate => 'Null',
84 dateofbirthrequired => 'Null',
87 enrolmentfee => 'Null',
88 overduenoticerequired => 'Null',
92 category_type => 'Null'
95 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
98 $samplecat->{categorycode}, $samplecat->{description},
99 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
100 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
101 $samplecat->{bulk}, $samplecat->{enrolmentfee},
102 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
103 $samplecat->{reservefee}, $samplecat->{hidelostitems},
104 $samplecat->{category_type}
110 my $sampleissuingrule1 = {
111 reservecharge => '0.000000',
112 chargename => 'Null',
116 maxonsiteissueqty => 4,
118 lengthunit => 'Null',
120 norenewalbefore => 6,
124 rentaldiscount => '2.000000',
125 reservesallowed => 0,
126 hardduedate => '2013-01-01',
127 branchcode => $samplebranch1->{branchcode},
129 hardduedatecompare => 5,
130 overduefinescap => '0.000000',
131 renewalsallowed => 0,
134 categorycode => $samplecat->{categorycode},
135 maxsuspensiondays => 0,
137 opacitemholds => 'N',
139 my $sampleissuingrule2 = {
140 branchcode => $samplebranch2->{branchcode},
141 categorycode => $samplecat->{categorycode},
144 maxonsiteissueqty => 1,
145 renewalsallowed => 'Null',
147 norenewalbefore => 7,
149 reservesallowed => 'Null',
151 lengthunit => 'Null',
153 hardduedatecompare => 'Null',
156 firstremind => 'Null',
157 chargeperiod => 'Null',
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 rentaldiscount => 3.00,
188 overduefinescap => 'Null',
189 accountsent => 'Null',
190 reservecharge => 'Null',
191 chargename => 'Null',
192 restrictedtype => 'Null',
193 maxsuspensiondays => 0,
195 opacitemholds => 'F',
197 $query = 'INSERT INTO issuingrules (
223 ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
224 my $sth = $dbh->prepare($query);
226 $sampleissuingrule1->{branchcode},
227 $sampleissuingrule1->{categorycode},
228 $sampleissuingrule1->{itemtype},
229 $sampleissuingrule1->{maxissueqty},
230 $sampleissuingrule1->{maxonsiteissueqty},
231 $sampleissuingrule1->{renewalsallowed},
232 $sampleissuingrule1->{renewalperiod},
233 $sampleissuingrule1->{norenewalbefore},
234 $sampleissuingrule1->{auto_renew},
235 $sampleissuingrule1->{reservesallowed},
236 $sampleissuingrule1->{issuelength},
237 $sampleissuingrule1->{lengthunit},
238 $sampleissuingrule1->{hardduedate},
239 $sampleissuingrule1->{hardduedatecompare},
240 $sampleissuingrule1->{fine},
241 $sampleissuingrule1->{finedays},
242 $sampleissuingrule1->{firstremind},
243 $sampleissuingrule1->{chargeperiod},
244 $sampleissuingrule1->{rentaldiscount},
245 $sampleissuingrule1->{overduefinescap},
246 $sampleissuingrule1->{accountsent},
247 $sampleissuingrule1->{reservecharge},
248 $sampleissuingrule1->{chargename},
249 $sampleissuingrule1->{restrictedtype},
250 $sampleissuingrule1->{maxsuspensiondays},
253 $sampleissuingrule2->{branchcode},
254 $sampleissuingrule2->{categorycode},
255 $sampleissuingrule2->{itemtype},
256 $sampleissuingrule2->{maxissueqty},
257 $sampleissuingrule2->{maxonsiteissueqty},
258 $sampleissuingrule2->{renewalsallowed},
259 $sampleissuingrule2->{renewalperiod},
260 $sampleissuingrule2->{norenewalbefore},
261 $sampleissuingrule2->{auto_renew},
262 $sampleissuingrule2->{reservesallowed},
263 $sampleissuingrule2->{issuelength},
264 $sampleissuingrule2->{lengthunit},
265 $sampleissuingrule2->{hardduedate},
266 $sampleissuingrule2->{hardduedatecompare},
267 $sampleissuingrule2->{fine},
268 $sampleissuingrule2->{finedays},
269 $sampleissuingrule2->{firstremind},
270 $sampleissuingrule2->{chargeperiod},
271 $sampleissuingrule2->{rentaldiscount},
272 $sampleissuingrule2->{overduefinescap},
273 $sampleissuingrule2->{accountsent},
274 $sampleissuingrule2->{reservecharge},
275 $sampleissuingrule2->{chargename},
276 $sampleissuingrule2->{restrictedtype},
277 $sampleissuingrule2->{maxsuspensiondays},
280 $sampleissuingrule3->{branchcode},
281 $sampleissuingrule3->{categorycode},
282 $sampleissuingrule3->{itemtype},
283 $sampleissuingrule3->{maxissueqty},
284 $sampleissuingrule3->{maxonsiteissueqty},
285 $sampleissuingrule3->{renewalsallowed},
286 $sampleissuingrule3->{renewalperiod},
287 $sampleissuingrule3->{norenewalbefore},
288 $sampleissuingrule3->{auto_renew},
289 $sampleissuingrule3->{reservesallowed},
290 $sampleissuingrule3->{issuelength},
291 $sampleissuingrule3->{lengthunit},
292 $sampleissuingrule3->{hardduedate},
293 $sampleissuingrule3->{hardduedatecompare},
294 $sampleissuingrule3->{fine},
295 $sampleissuingrule3->{finedays},
296 $sampleissuingrule3->{firstremind},
297 $sampleissuingrule3->{chargeperiod},
298 $sampleissuingrule3->{rentaldiscount},
299 $sampleissuingrule3->{overduefinescap},
300 $sampleissuingrule3->{accountsent},
301 $sampleissuingrule3->{reservecharge},
302 $sampleissuingrule3->{chargename},
303 $sampleissuingrule3->{restrictedtype},
304 $sampleissuingrule3->{maxsuspensiondays},
309 $samplecat->{categorycode},
310 'Book', $samplebranch1->{branchcode}
313 "GetIssuingCharge returns issuingrule1's informations"
318 C4::Circulation::GetLoanLength(
319 $samplecat->{categorycode},
320 'BOOK', $samplebranch1->{branchcode}
322 { issuelength => 5, lengthunit => 'Null', renewalperiod => 5 },
326 C4::Circulation::GetLoanLength(),
330 lengthunit => 'days',
332 "Without parameters, GetLoanLength returns hardcoded values"
335 C4::Circulation::GetLoanLength( -1, -1 ),
339 lengthunit => 'days',
341 "With wrong parameters, GetLoanLength returns hardcoded values"
344 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
348 lengthunit => 'days',
350 "With only one parameter, GetLoanLength returns hardcoded values"
351 ); #NOTE : is that really what is expected?
353 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
357 lengthunit => 'days',
359 "With only one parameter, GetLoanLength returns hardcoded values"
360 ); #NOTE : is that really what is expected?
363 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
364 'BOOK', $samplebranch1->{branchcode} );
368 dt_from_string( $sampleissuingrule1->{hardduedate}, 'iso' ),
369 $sampleissuingrule1->{hardduedatecompare}
371 "GetHardDueDate returns the duedate and the duedatecompare"