Lines 32-38
BEGIN {
Link Here
|
32 |
@ISA = qw(Exporter); |
32 |
@ISA = qw(Exporter); |
33 |
@EXPORT = qw( |
33 |
@EXPORT = qw( |
34 |
&UpdateStats |
34 |
&UpdateStats |
35 |
&TotalPaid |
|
|
36 |
); |
35 |
); |
37 |
} |
36 |
} |
38 |
|
37 |
|
Lines 143-193
sub UpdateStats {
Link Here
|
143 |
); |
142 |
); |
144 |
} |
143 |
} |
145 |
|
144 |
|
146 |
=head2 TotalPaid |
|
|
147 |
|
148 |
@total = &TotalPaid ( $time, [$time2], [$spreadsheet ]); |
149 |
|
150 |
Returns an array containing the payments and writeoffs made between two dates |
151 |
C<$time> and C<$time2>, or on a specific one, or from C<$time> onwards. |
152 |
|
153 |
C<$time> param is mandatory. |
154 |
If C<$time> eq 'today', returns are limited to the current day |
155 |
If C<$time2> eq '', results are returned from C<$time> onwards. |
156 |
If C<$time2> is undef, returns are limited to C<$time> |
157 |
C<$spreadsheet> param is optional and controls the sorting of the results. |
158 |
|
159 |
Returns undef if no param is given |
160 |
|
161 |
=cut |
162 |
|
163 |
sub TotalPaid { |
164 |
my ( $time, $time2, $spreadsheet ) = @_; |
165 |
return () unless (defined $time); |
166 |
$time2 = $time unless $time2; |
167 |
my $dbh = C4::Context->dbh; |
168 |
my $query = "SELECT * FROM statistics |
169 |
LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber |
170 |
WHERE (statistics.type='payment' OR statistics.type='writeoff') "; |
171 |
if ( $time eq 'today' ) { |
172 |
# FIXME wrong condition. Now() will not get all the payments of the day but of a specific timestamp |
173 |
$query .= " AND datetime = now()"; |
174 |
} else { |
175 |
$query .= " AND datetime > '$time'"; # FIXME: use placeholders |
176 |
} |
177 |
if ( $time2 ne '' ) { |
178 |
$query .= " AND datetime < '$time2'"; # FIXME: use placeholders |
179 |
} |
180 |
# FIXME if $time2 is undef, query will be "AND datetime > $time AND AND datetime < $time" |
181 |
# Operators should probably be <= and >= |
182 |
if ($spreadsheet) { |
183 |
$query .= " ORDER BY branch, type"; |
184 |
} |
185 |
$debug and warn "TotalPaid query: $query"; |
186 |
my $sth = $dbh->prepare($query); |
187 |
$sth->execute(); |
188 |
return @{$sth->fetchall_arrayref({})}; |
189 |
} |
190 |
|
191 |
1; |
145 |
1; |
192 |
__END__ |
146 |
__END__ |
193 |
|
147 |
|