Line 0
Link Here
|
|
|
1 |
package C4::DashBoard; |
2 |
|
3 |
# Copyright 2000-2002 Katipo Communications |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# terms of the GNU General Public License as published by the Free Software |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
10 |
# version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
# |
20 |
|
21 |
use strict; |
22 |
use warnings; |
23 |
use C4::Context; |
24 |
use C4::Dates qw(format_date); |
25 |
|
26 |
use vars qw($VERSION @ISA @EXPORT); |
27 |
|
28 |
BEGIN { |
29 |
$VERSION = 3.01; |
30 |
@ISA = qw(Exporter); |
31 |
@EXPORT = qw(&number_of_items_library_xml &number_of_borrowers_library_xml &number_of_issues_library_xml &number_of_biblios_xml &number_of_loan_history_system_xml |
32 |
&number_of_overdues_library_xml &number_of_biblios_7days_xml &number_of_items_7days_system_xml &number_of_overdues_7days_library_xml |
33 |
&number_of_borrowers_system_xml &number_of_items_system_xml &number_of_items_7days_library_xml &number_of_overdues_system_xml |
34 |
&number_of_overdues_14days_library_xml &number_of_overdues_21days_library_xml &number_of_veryoverdue_library_xml &expired_borrowers_library_xml |
35 |
&expired_borrowers_system_xml &number_of_issues_system_xml &number_of_loan_history_library_xml &number_of_overdues_7days_system_xml |
36 |
&number_of_overdues_14days_system_xml &number_of_overdues_21days_system_xml &number_of_veryoverdue_system_xml &last_update_xml |
37 |
); |
38 |
} |
39 |
|
40 |
|
41 |
sub number_of_items_library_xml { |
42 |
my $dbh = C4::Context->dbh; |
43 |
my $items = $dbh->selectall_arrayref ('select branches.branchcode as BranchCode, IFNULL(SubTotal.items,0) as NumberOfItems |
44 |
from branches |
45 |
left join |
46 |
(select homebranch, count(*) as Items |
47 |
from items |
48 |
group by homebranch) SubTotal |
49 |
on branches.branchcode=SubTotal.homebranch',{ Columns => {} }); |
50 |
$dbh->disconnect(); |
51 |
return $items; |
52 |
|
53 |
} |
54 |
|
55 |
sub number_of_items_system_xml { |
56 |
my $dbh = C4::Context->dbh; |
57 |
my $items_system = $dbh->selectall_arrayref('select count(*) as NumberOfItemsSystem from items', {Columns => {} }); |
58 |
$dbh->disconnect; |
59 |
return $items_system; |
60 |
|
61 |
} |
62 |
|
63 |
sub number_of_borrowers_library_xml { |
64 |
my $dbh = C4::Context->dbh; |
65 |
my $borrowers = $dbh->selectall_arrayref ('select branches.branchcode as BranchCode, IFNULL(SubTotal.Borrowers,0) as NumberOfBorrowers |
66 |
from branches |
67 |
left join |
68 |
(select branchcode, count(*) as Borrowers |
69 |
from borrowers |
70 |
group by branchcode) SubTotal |
71 |
on branches.branchcode=SubTotal.branchcode',{ Columns => {} }); |
72 |
$dbh->disconnect; |
73 |
return $borrowers; |
74 |
|
75 |
} |
76 |
|
77 |
sub number_of_borrowers_system_xml { |
78 |
my $dbh = C4::Context->dbh; |
79 |
my $number_of_borrowers_system = $dbh->selectall_arrayref('select count(*) as NumberofBorrowersSystem |
80 |
from borrowers',{ Columns => {} } ); |
81 |
$dbh->disconnect; |
82 |
return $number_of_borrowers_system; |
83 |
|
84 |
} |
85 |
|
86 |
sub number_of_issues_library_xml { |
87 |
my $dbh = C4::Context->dbh; |
88 |
my $issues_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.issues,0) as NumberOfIssues |
89 |
from branches |
90 |
left join |
91 |
(select branchcode, count(*) as Issues |
92 |
from issues |
93 |
group by branchcode) SubTotal |
94 |
on branches.branchcode=SubTotal.branchcode',{ Columns => {} }); |
95 |
$dbh->disconnect(); |
96 |
return $issues_library; |
97 |
|
98 |
} |
99 |
|
100 |
sub number_of_issues_system_xml { |
101 |
my $dbh = C4::Context->dbh; |
102 |
my $issues_system = $dbh->selectall_arrayref('select count(*) as NumberOfIssuesSystem |
103 |
from issues',{Columns => {}}); |
104 |
$dbh->disconnect; |
105 |
return $issues_system; |
106 |
|
107 |
} |
108 |
|
109 |
sub number_of_biblios_xml { |
110 |
my $dbh = C4::Context->dbh; |
111 |
my $biblios = $dbh->selectall_arrayref('select count(*) as NumberOfBiblios from biblio',{ Columns => {} } ); |
112 |
$dbh->disconnect; |
113 |
return $biblios; |
114 |
|
115 |
} |
116 |
|
117 |
sub number_of_loan_history_system_xml { |
118 |
my $dbh = C4::Context->dbh; |
119 |
my $loan_history = $dbh->selectall_arrayref('select count(*) as NumberOfLoans from old_issues', { Columns => {} }); |
120 |
$dbh->disconnect; |
121 |
return $loan_history; |
122 |
|
123 |
} |
124 |
|
125 |
sub number_of_loan_history_library_xml { |
126 |
my $dbh = C4::Context->dbh; |
127 |
my $loan_history_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.oldissues,0) as NumberOfLoans |
128 |
from branches |
129 |
left join |
130 |
(select branchcode, count(*) as OldIssues |
131 |
from old_issues |
132 |
group by branchcode) SubTotal |
133 |
on branches.branchcode=SubTotal.branchcode', {Columns => {}} ); |
134 |
$dbh->disconnect; |
135 |
return $loan_history_library; |
136 |
|
137 |
} |
138 |
|
139 |
sub number_of_overdues_library_xml { |
140 |
my $dbh = C4::Context->dbh; |
141 |
my $overdues_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.Overdues,0) as NumberOfOverdues |
142 |
from branches |
143 |
left join |
144 |
(select branchcode, count(*) as Overdues |
145 |
from issues |
146 |
where date_due < date(now()) |
147 |
group by branchcode) SubTotal |
148 |
on branches.branchcode=SubTotal.branchcode', {Columns => {} }); |
149 |
$dbh->disconnect; |
150 |
return $overdues_library; |
151 |
|
152 |
} |
153 |
|
154 |
sub number_of_overdues_system_xml { |
155 |
my $dbh = C4::Context->dbh; |
156 |
my $overdues_system = $dbh->selectall_arrayref('select count(*) as NumberOfOverdues |
157 |
from issues |
158 |
where date_due < date(now())',{Columns => {}} ); |
159 |
$dbh->disconnect; |
160 |
return $overdues_system; |
161 |
|
162 |
} |
163 |
|
164 |
sub number_of_overdues_7days_library_xml { |
165 |
my $dbh = C4::Context->dbh; |
166 |
my $overdues_library_7days = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.Overdues,0) as NumberOfOverdues7Days |
167 |
from branches |
168 |
left join |
169 |
(select branchcode, count(*) as Overdues |
170 |
from issues |
171 |
where date_due between DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY) |
172 |
group by branchcode) SubTotal |
173 |
on branches.branchcode=SubTotal.branchcode', {Columns => {} }); |
174 |
$dbh->disconnect; |
175 |
return $overdues_library_7days; |
176 |
|
177 |
} |
178 |
|
179 |
sub number_of_overdues_7days_system_xml { |
180 |
my $dbh = C4::Context->dbh; |
181 |
my $overdues_7days_system = $dbh->selectall_arrayref('select count(*) as NumberOfOverdues |
182 |
from issues |
183 |
where date_due |
184 |
between DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY)', {Columns => {}} ); |
185 |
return $overdues_7days_system; |
186 |
|
187 |
} |
188 |
|
189 |
sub number_of_overdues_14days_library_xml { |
190 |
my $dbh = C4::Context->dbh; |
191 |
my $overdues_14days = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.Overdues,0) as NumberOfOverdues14Days |
192 |
from branches |
193 |
left join |
194 |
(select branchcode, count(*) as Overdues |
195 |
from issues |
196 |
where date_due |
197 |
between DATE_SUB(CURDATE(), INTERVAL 14 DAY) AND DATE_SUB(CURDATE(), INTERVAL 8 DAY) |
198 |
group by branchcode) SubTotal |
199 |
on branches.branchcode=SubTotal.branchcode', {Columns => {} }); |
200 |
$dbh->disconnect; |
201 |
return $overdues_14days; |
202 |
|
203 |
} |
204 |
|
205 |
sub number_of_overdues_14days_system_xml { |
206 |
my $dbh = C4::Context->dbh; |
207 |
my $overdues_14days_system = $dbh->selectall_arrayref('select count(*) as NumberOfOverdues14Days |
208 |
from issues |
209 |
where date_due |
210 |
between DATE_SUB(CURDATE(), INTERVAL 14 DAY) AND DATE_SUB(CURDATE(), INTERVAL 8 DAY)', {Columns => {}} ); |
211 |
$dbh->disconnect; |
212 |
return $overdues_14days_system; |
213 |
|
214 |
} |
215 |
|
216 |
sub number_of_overdues_21days_library_xml { |
217 |
my $dbh = C4::Context->dbh; |
218 |
my $overdues_21days_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.Overdues,0) as NumberOfOverdues21Days |
219 |
from branches |
220 |
left join |
221 |
(select branchcode, count(*) as Overdues |
222 |
from issues |
223 |
where date_due between DATE_SUB(CURDATE(), INTERVAL 21 DAY) AND DATE_SUB(CURDATE(), INTERVAL 15 DAY) |
224 |
group by branchcode) SubTotal |
225 |
on branches.branchcode=SubTotal.branchcode', {Columns => {} }); |
226 |
$dbh->disconnect; |
227 |
return $overdues_21days_library; |
228 |
|
229 |
} |
230 |
|
231 |
sub number_of_overdues_21days_system_xml { |
232 |
my $dbh = C4::Context->dbh; |
233 |
my $overdues_21days_system = $dbh->selectall_arrayref('select count(*) as NumberOfOverdues21Days |
234 |
from issues |
235 |
where date_due between DATE_SUB(CURDATE(), INTERVAL 21 DAY) AND DATE_SUB(CURDATE(), INTERVAL 15 DAY)' |
236 |
, {Columns => {} }); |
237 |
return $overdues_21days_system; |
238 |
|
239 |
} |
240 |
|
241 |
sub number_of_veryoverdue_library_xml { |
242 |
my $dbh = C4::Context->dbh; |
243 |
my $very_overdue_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.Overdues,0) as NumberOfVeryOverdue |
244 |
from branches |
245 |
left join |
246 |
(select branchcode, count(*) as Overdues |
247 |
from issues |
248 |
where date_due < DATE_SUB(CURDATE(), INTERVAL 22 DAY) |
249 |
group by branchcode) SubTotal |
250 |
on branches.branchcode=SubTotal.branchcode', {Columns => {} }); |
251 |
$dbh->disconnect; |
252 |
return $very_overdue_library; |
253 |
|
254 |
} |
255 |
|
256 |
sub number_of_veryoverdue_system_xml { |
257 |
my $dbh = C4::Context->dbh; |
258 |
my $very_overdue_system = $dbh->selectall_arrayref('select count(*) as Overdues |
259 |
from issues |
260 |
where date_due < DATE_SUB(CURDATE(), INTERVAL 22 DAY)' ,{Columns => {} }); |
261 |
$dbh->disconnect; |
262 |
return $very_overdue_system; |
263 |
|
264 |
} |
265 |
|
266 |
|
267 |
sub number_of_biblios_7days_xml { |
268 |
my $dbh = C4::Context->dbh; |
269 |
my $biblio_7days = $dbh->selectall_arrayref('SELECT count(*) as NumberOfBiblio7Days |
270 |
FROM biblio |
271 |
WHERE datecreated |
272 |
between DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE()', {Columns => {} } ); |
273 |
$dbh->disconnect; |
274 |
return $biblio_7days; |
275 |
|
276 |
} |
277 |
|
278 |
sub number_of_items_7days_system_xml { |
279 |
my $dbh = C4::Context->dbh; |
280 |
my $items_7days_system = $dbh->selectall_arrayref('SELECT count(*) as NumberOfItems7Days |
281 |
FROM items |
282 |
WHERE dateaccessioned |
283 |
between DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE()',{Columns =>{} } ); |
284 |
$dbh->disconnect; |
285 |
return $items_7days_system; |
286 |
|
287 |
} |
288 |
|
289 |
sub number_of_items_7days_library_xml { |
290 |
my $dbh = C4::Context->dbh; |
291 |
my $items_7days_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.items,0) as NumberOfItems7DaysLibrary |
292 |
from branches |
293 |
left join |
294 |
(select homebranch, count(*) as Items |
295 |
from items |
296 |
where dateaccessioned > DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() |
297 |
group by homebranch) SubTotal |
298 |
on branches.branchcode=SubTotal.homebranch', {Columns => {} }); |
299 |
$dbh->disconnect; |
300 |
return $items_7days_library; |
301 |
|
302 |
} |
303 |
|
304 |
sub expired_borrowers_library_xml { |
305 |
my $dbh = C4::Context->dbh; |
306 |
my $expired_borrowers_library = $dbh->selectall_arrayref('select branches.branchcode as BranchCode, IFNULL(SubTotal.ExpiredBorrowers,0) as ExpiredBorrowers |
307 |
from branches |
308 |
left join |
309 |
(select branchcode, count(*) as ExpiredBorrowers |
310 |
from borrowers |
311 |
where dateexpiry < date(now()) |
312 |
group by branchcode) SubTotal |
313 |
on branches.branchcode=SubTotal.branchcode;',{Columns => {} } ); |
314 |
$dbh->disconnect; |
315 |
return $expired_borrowers_library; |
316 |
|
317 |
} |
318 |
|
319 |
sub expired_borrowers_system_xml { |
320 |
my $dbh = C4::Context->dbh; |
321 |
my $expired_borrowers_system = $dbh->selectall_arrayref('select count(*) as ExpiredBorrowers |
322 |
from borrowers |
323 |
where dateexpiry < date(now())', {Columns => {} }); |
324 |
$dbh->disconnect; |
325 |
return $expired_borrowers_system; |
326 |
|
327 |
} |
328 |
|
329 |
sub last_update_xml { |
330 |
my $dbh = C4::Context->dbh; |
331 |
my $updated = $dbh->selectall_arrayref('SELECT DATE_FORMAT(now(), "%W %M %D %Y %T") as UpdatedTime', |
332 |
{Columns => {} }); |
333 |
$dbh->disconnect; |
334 |
return $updated; |
335 |
|
336 |
} |
337 |
|
338 |
1; |
339 |
__END__ |