/
stats.pl
executable file
·160 lines (147 loc) · 4.93 KB
/
stats.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/perl
# $Id$
#written 14/1/2000
#script to display reports
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use CGI;
use C4::Output;
use HTML::Template;
use C4::Auth;
use C4::Interface::CGI::Output;
use C4::Context;
use Date::Manip;
use C4::Stats;
my $input=new CGI;
my $time=$input->param('time');
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "stats.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {borrowers => 1},
debug => 1,
});
my $date;
my $date2;
if ($time eq 'yesterday'){
$date=ParseDate('yesterday');
$date2=ParseDate('today');
}
if ($time eq 'today'){
$date=ParseDate('today');
$date2=ParseDate('tomorrow');
}
if ($time eq 'daybefore'){
$date=ParseDate('2 days ago');
$date2=ParseDate('yesterday');
}
if ($time eq 'month') {
$date = ParseDate('1 month ago');
$date2 = ParseDate('today');
warn "d : $date // d2 : $date2";
}
if ($time=~ /\//){
$date=ParseDate($time);
$date2=ParseDateDelta('+ 1 day');
$date2=DateCalc($date,$date2);
}
$date=UnixDate($date,'%Y-%m-%d');
$date2=UnixDate($date2,'%Y-%m-%d');
warn "d : $date // d2 : $date2";
my @payments=TotalPaid($date,$date2);
my $count=@payments;
my $total=0;
my $oldtime;
my $totalw=0;
my @loop;
my %row;
my $i=0;
while ($i<$count){
warn " pay : ".$payments[$i]{'timestamp'};
my $time=$payments[$i]{'datetime'};
my $payments=$payments[$i]{'value'};
my $charge=0;
my @temp=split(/ /,$payments[$i]{'datetime'});
my $date=$temp[0];
my @charges=getcharges($payments[$i]{'borrowernumber'},$payments[$i]{'timestamp'});
my $count=@charges;
my $temptotalf=0;
my $temptotalr=0;
my $temptotalres=0;
my $temptotalren=0;
my $temptotalw=0;
for (my $i2=0;$i2<$count;$i2++){
$charge+=$charges[$i2]->{'amount'};
%row = ( name => $charges[$i2]->{'description'},
type => $charges[$i2]->{'accounttype'},
time => $charges[$i2]->{'timestamp'},
amount => $charges[$i2]->{'amount'},
branch => $charges[$i2]->{'amountoutstanding'} );
push(@loop, \%row);
if ($payments[$i]{'accountytpe'} ne 'W'){
if ($charges[$i2]->{'accounttype'} eq 'Rent'){
$temptotalr+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
}
if ($charges[$i2]->{'accounttype'} eq 'F' || $charges[$i2]->{'accounttype'} eq 'FU' || $charges[$i2]->{'accounttype'} eq 'FN' ){
$temptotalf+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
}
if ($charges[$i2]->{'accounttype'} eq 'Res'){
$temptotalres+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
}
if ($charges[$i2]->{'accounttype'} eq 'R'){
$temptotalren+=$charges[$i2]->{'amount'}-$charges[$i2]->{'amountoutstanding'};
}
}
}
my $hour=substr($payments[$i]{'timestamp'},8,2);
my $min=substr($payments[$i]{'timestamp'},10,2);
my $sec=substr($payments[$i]{'timestamp'},12,2);
my $time="$hour:$min:$sec";
my $time2="$payments[$i]{'date'}";
my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
my $bornum=$payments[$i]{'borrowernumber'};
my $oldtime=$payments[$i]{'timestamp'};
my $oldtype=$payments[$i]{'accounttype'};
while ($bornum eq $payments[$i]{'borrowernumber'} && $oldtype == $payments[$i]{'accounttype'} && $oldtime eq $payments[$i]{'timestamp'}){
my $hour=substr($payments[$i]{'timestamp'},8,2);
my $min=substr($payments[$i]{'timestamp'},10,2);
my $sec=substr($payments[$i]{'timestamp'},12,2);
my $time="$hour:$min:$sec";
my $time2="$payments[$i]{'date'}";
my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
if ($payments[$i]{'accounttype'} eq 'W'){
$totalw+=$payments[$i]{'amount'};
} else {
$payments[$i]{'amount'}=$payments[$i]{'amount'}*-1;
$total+=$payments[$i]{'amount'};
}
%row = ( name => "<b>".$payments[$i]{'firstname'}.$payments[$i]{'surname'} . "</b>",
type => $payments[$i]{'accounttype'}, time => $payments[$i]{'date'},
amount => $payments[$i]{'amount'}, branch => $branch );
push(@loop, \%row);
$oldtype=$payments[$i]{'accounttype'};
$oldtime=$payments[$i]{'timestamp'};
$bornum=$payments[$i]{'borrowernumber'};
$i++;
}
}
$template->param( loop1 => \@loop,
totalw => $totalw,
total => $total );
output_html_with_http_headers $input, $cookie, $template->output;