| Filename | /mnt/catalyst/koha/C4/Stats.pm |
| Statements | Executed 16 statements in 439µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 420µs | 432µs | C4::Stats::BEGIN@21 |
| 1 | 1 | 1 | 10µs | 10µs | C4::Stats::BEGIN@30 |
| 1 | 1 | 1 | 9µs | 101µs | C4::Stats::BEGIN@25 |
| 1 | 1 | 1 | 8µs | 10µs | C4::Stats::BEGIN@24 |
| 1 | 1 | 1 | 7µs | 12µs | C4::Stats::BEGIN@22 |
| 1 | 1 | 1 | 7µs | 44µs | C4::Stats::BEGIN@26 |
| 0 | 0 | 0 | 0s | 0s | C4::Stats::TotalPaid |
| 0 | 0 | 0 | 0s | 0s | C4::Stats::UpdateStats |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package C4::Stats; | ||||
| 2 | |||||
| 3 | |||||
| 4 | # Copyright 2000-2002 Katipo Communications | ||||
| 5 | # | ||||
| 6 | # This file is part of Koha. | ||||
| 7 | # | ||||
| 8 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
| 9 | # terms of the GNU General Public License as published by the Free Software | ||||
| 10 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
| 11 | # version. | ||||
| 12 | # | ||||
| 13 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
| 14 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
| 15 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
| 16 | # | ||||
| 17 | # You should have received a copy of the GNU General Public License along | ||||
| 18 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
| 20 | |||||
| 21 | 2 | 27µs | 2 | 444µs | # spent 432µs (420+12) within C4::Stats::BEGIN@21 which was called:
# once (420µs+12µs) by C4::Circulation::BEGIN@26 at line 21 # spent 432µs making 1 call to C4::Stats::BEGIN@21
# spent 12µs making 1 call to strict::import |
| 22 | 2 | 24µs | 2 | 16µs | # spent 12µs (7+4) within C4::Stats::BEGIN@22 which was called:
# once (7µs+4µs) by C4::Circulation::BEGIN@26 at line 22 # spent 12µs making 1 call to C4::Stats::BEGIN@22
# spent 4µs making 1 call to warnings::import |
| 23 | 1 | 900ns | require Exporter; | ||
| 24 | 2 | 20µs | 2 | 13µs | # spent 10µs (8+2) within C4::Stats::BEGIN@24 which was called:
# once (8µs+2µs) by C4::Circulation::BEGIN@26 at line 24 # spent 10µs making 1 call to C4::Stats::BEGIN@24
# spent 2µs making 1 call to C4::Context::import |
| 25 | 2 | 29µs | 2 | 193µs | # spent 101µs (9+92) within C4::Stats::BEGIN@25 which was called:
# once (9µs+92µs) by C4::Circulation::BEGIN@26 at line 25 # spent 101µs making 1 call to C4::Stats::BEGIN@25
# spent 92µs making 1 call to Exporter::import |
| 26 | 2 | 51µs | 2 | 80µs | # spent 44µs (7+37) within C4::Stats::BEGIN@26 which was called:
# once (7µs+37µs) by C4::Circulation::BEGIN@26 at line 26 # spent 44µs making 1 call to C4::Stats::BEGIN@26
# spent 37µs making 1 call to vars::import |
| 27 | |||||
| 28 | 1 | 0s | our $debug; | ||
| 29 | |||||
| 30 | # spent 10µs within C4::Stats::BEGIN@30 which was called:
# once (10µs+0s) by C4::Circulation::BEGIN@26 at line 38 | ||||
| 31 | # set the version for version checking | ||||
| 32 | 1 | 700ns | $VERSION = 3.07.00.049; | ||
| 33 | 1 | 6µs | @ISA = qw(Exporter); | ||
| 34 | 1 | 3µs | @EXPORT = qw( | ||
| 35 | &UpdateStats | ||||
| 36 | &TotalPaid | ||||
| 37 | ); | ||||
| 38 | 1 | 275µs | 1 | 10µs | } # spent 10µs making 1 call to C4::Stats::BEGIN@30 |
| 39 | |||||
| 40 | |||||
| 41 | =head1 NAME | ||||
| 42 | |||||
| 43 | C4::Stats - Update Koha statistics (log) | ||||
| 44 | |||||
| 45 | =head1 SYNOPSIS | ||||
| 46 | |||||
| 47 | use C4::Stats; | ||||
| 48 | |||||
| 49 | =head1 DESCRIPTION | ||||
| 50 | |||||
| 51 | The C<&UpdateStats> function adds an entry to the statistics table in | ||||
| 52 | the Koha database, which acts as an activity log. | ||||
| 53 | |||||
| 54 | =head1 FUNCTIONS | ||||
| 55 | |||||
| 56 | =over 2 | ||||
| 57 | |||||
| 58 | =item UpdateStats | ||||
| 59 | |||||
| 60 | &UpdateStats($branch, $type, $value, $other, $itemnumber, | ||||
| 61 | $itemtype, $borrowernumber); | ||||
| 62 | |||||
| 63 | Adds a line to the statistics table of the Koha database. In effect, | ||||
| 64 | it logs an event. | ||||
| 65 | |||||
| 66 | C<$branch>, C<$type>, C<$value>, C<$other>, C<$itemnumber>, | ||||
| 67 | C<$itemtype>, and C<$borrowernumber> correspond to the fields of the | ||||
| 68 | statistics table in the Koha database. | ||||
| 69 | |||||
| 70 | =cut | ||||
| 71 | |||||
| 72 | #' | ||||
| 73 | sub UpdateStats { | ||||
| 74 | |||||
| 75 | #module to insert stats data into stats table | ||||
| 76 | my ( | ||||
| 77 | $branch, $type, | ||||
| 78 | $amount, $other, $itemnum, | ||||
| 79 | $itemtype, $borrowernumber, $accountno, $ccode | ||||
| 80 | ) | ||||
| 81 | = @_; | ||||
| 82 | my $dbh = C4::Context->dbh; | ||||
| 83 | my $sth = $dbh->prepare( | ||||
| 84 | "INSERT INTO statistics | ||||
| 85 | (datetime, branch, type, value, | ||||
| 86 | other, itemnumber, itemtype, borrowernumber, proccode, ccode) | ||||
| 87 | VALUES (now(),?,?,?,?,?,?,?,?,?)" | ||||
| 88 | ); | ||||
| 89 | $sth->execute( | ||||
| 90 | $branch, $type, $amount, | ||||
| 91 | $other, $itemnum, $itemtype, $borrowernumber, | ||||
| 92 | $accountno, $ccode | ||||
| 93 | ); | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | # Otherwise, it'd need a POD. | ||||
| 97 | sub TotalPaid { | ||||
| 98 | my ( $time, $time2, $spreadsheet ) = @_; | ||||
| 99 | $time2 = $time unless $time2; | ||||
| 100 | my $dbh = C4::Context->dbh; | ||||
| 101 | my $query = "SELECT * FROM statistics | ||||
| 102 | LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber | ||||
| 103 | WHERE (statistics.type='payment' OR statistics.type='writeoff') "; | ||||
| 104 | if ( $time eq 'today' ) { | ||||
| 105 | $query .= " AND datetime = now()"; | ||||
| 106 | } else { | ||||
| 107 | $query .= " AND datetime > '$time'"; # FIXME: use placeholders | ||||
| 108 | } | ||||
| 109 | if ( $time2 ne '' ) { | ||||
| 110 | $query .= " AND datetime < '$time2'"; # FIXME: use placeholders | ||||
| 111 | } | ||||
| 112 | if ($spreadsheet) { | ||||
| 113 | $query .= " ORDER BY branch, type"; | ||||
| 114 | } | ||||
| 115 | $debug and warn "TotalPaid query: $query"; | ||||
| 116 | my $sth = $dbh->prepare($query); | ||||
| 117 | $sth->execute(); | ||||
| 118 | return @{$sth->fetchall_arrayref({})}; | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | 1 | 3µs | 1; | ||
| 122 | __END__ |