View | Details | Raw Unified | Return to bug 15230
Collapse All | Expand All

(-)a/circ/stats.pl (-189 lines)
Lines 1-189 Link Here
1
#!/usr/bin/perl
2
3
4
#written 14/1/2000
5
#script to display reports
6
7
# Copyright 2000-2002 Katipo Communications
8
#
9
# This file is part of Koha.
10
#
11
# Koha is free software; you can redistribute it and/or modify it
12
# under the terms of the GNU General Public License as published by
13
# the Free Software Foundation; either version 3 of the License, or
14
# (at your option) any later version.
15
#
16
# Koha is distributed in the hope that it will be useful, but
17
# WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
20
#
21
# You should have received a copy of the GNU General Public License
22
# along with Koha; if not, see <http://www.gnu.org/licenses>.
23
24
use strict;
25
#use warnings; FIXME - Bug 2505
26
use CGI qw ( -utf8 );
27
use C4::Context;
28
use C4::Output;
29
use C4::Auth;
30
use Date::Manip;
31
use C4::Stats;
32
use C4::Debug;
33
34
use vars qw($debug);
35
36
my $input = new CGI;
37
my $time  = $input->param('time') || '';
38
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40
    {
41
        template_name   => "circ/stats.tt",
42
        query           => $input,
43
        type            => "intranet",
44
        authnotrequired => 0,
45
        flagsrequired   => { reports => 1 },
46
        debug           => 1,
47
    }
48
);
49
50
my $date;
51
my $date2;
52
if ( $time eq 'yesterday' ) {
53
    $date  = ParseDate('yesterday');
54
    $date2 = ParseDate('today');
55
}
56
elsif ( $time eq 'today' ) {
57
    $date  = ParseDate('today');
58
    $date2 = ParseDate('tomorrow');
59
}
60
elsif ( $time eq 'daybefore' ) {
61
    $date  = ParseDate('2 days ago');
62
    $date2 = ParseDate('yesterday');
63
}
64
elsif ( $time eq 'month' ) {
65
    $date  = ParseDate('1 month ago');
66
    $date2 = ParseDate('today');
67
}
68
elsif ( $time =~ /\// ) {
69
    $date  = ParseDate($time);
70
    $date2 = ParseDateDelta('+ 1 day');
71
    $date2 = DateCalc( $date, $date2 );
72
} else {
73
    $template->param(notime => '1');    # TODO: add error feedback if time sent, but unrecognized
74
    output_html_with_http_headers $input, $cookie, $template->output;
75
    exit;
76
}
77
78
$debug and warn "d : $date // d2 : $date2";
79
$date  = UnixDate( $date,  '%Y-%m-%d' );
80
$date2 = UnixDate( $date2, '%Y-%m-%d' );
81
$debug and warn "d : $date // d2 : $date2";
82
my @payments = TotalPaid( $date, $date2 );
83
my $count    = @payments;
84
my $total    = 0;
85
my $totalw   = 0;
86
my $oldtime;
87
my @loop;
88
my %row;
89
my $i = 0;
90
91
while ( $i < $count ) {
92
    $debug and warn " pay : " . $payments[$i]{'timestamp'};
93
    my $time     = $payments[$i]{'datetime'};
94
    my $payments = $payments[$i]{'value'};
95
    my $charge   = 0;
96
    my @temp     = split(/ /, $payments[$i]{'datetime'});
97
    my $date     = $temp[0];
98
    my @charges  =
99
      getcharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} );
100
    my $count        = @charges;
101
    my $temptotalf   = 0;
102
    my $temptotalr   = 0;
103
    my $temptotalres = 0;
104
    my $temptotalren = 0;
105
    my $temptotalw   = 0;
106
107
    # FIXME: way too much logic to live only here in a report script
108
    for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
109
        $charge += $charges[$i2]->{'amount'};
110
        %row = (
111
            name   => $charges[$i2]->{'description'},
112
            type   => $charges[$i2]->{'accounttype'},
113
            time   => $charges[$i2]->{'timestamp'},
114
            amount => $charges[$i2]->{'amount'},
115
            branch => $charges[$i2]->{'amountoutstanding'}
116
        );
117
        push( @loop, \%row );
118
        if ( $payments[$i]{'accountytpe'} ne 'W' ) {
119
            if ( $charges[$i2]->{'accounttype'} eq 'Rent' ) {
120
                $temptotalr +=
121
                  $charges[$i2]->{'amount'} -
122
                  $charges[$i2]->{'amountoutstanding'};
123
            }
124
            if (   $charges[$i2]->{'accounttype'} eq 'F'
125
                || $charges[$i2]->{'accounttype'} eq 'FU'
126
                || $charges[$i2]->{'accounttype'} eq 'FN' )
127
            {
128
                $temptotalf +=
129
                  $charges[$i2]->{'amount'} -
130
                  $charges[$i2]->{'amountoutstanding'};
131
            }
132
            if ( $charges[$i2]->{'accounttype'} eq 'Res' ) {
133
                $temptotalres +=
134
                  $charges[$i2]->{'amount'} -
135
                  $charges[$i2]->{'amountoutstanding'};
136
            }
137
            if ( $charges[$i2]->{'accounttype'} eq 'R' ) {
138
                $temptotalren +=
139
                  $charges[$i2]->{'amount'} -
140
                  $charges[$i2]->{'amountoutstanding'};
141
            }
142
        }
143
    }
144
    my $time2 = $payments[$i]{'date'};
145
    my $branch = Getpaidbranch( $time2, $payments[$i]{'borrowernumber'} );
146
    my $borrowernumber = $payments[$i]{'borrowernumber'};
147
    my $oldtime        = $payments[$i]{'timestamp'};
148
    my $oldtype        = $payments[$i]{'accounttype'};
149
150
    while ($borrowernumber eq $payments[$i]{'borrowernumber'}
151
        && $oldtype == $payments[$i]{'accounttype'}
152
        && $oldtime eq $payments[$i]{'timestamp'} )
153
    {
154
        my $xtime2 = $payments[$i]{'date'};
155
        my $branch = Getpaidbranch( $xtime2, $payments[$i]{'borrowernumber'} );
156
        if ( $payments[$i]{'accounttype'} eq 'W' ) {
157
            $totalw += $payments[$i]{'amount'};
158
        }
159
        else {
160
            $payments[$i]{'amount'} = $payments[$i]{'amount'} * -1;
161
            $total += $payments[$i]{'amount'};
162
        }
163
164
        #FIXME: display layer HTML
165
        %row = (
166
            name => "<b>"
167
              . $payments[$i]{'firstname'}
168
              . $payments[$i]{'surname'} . "</b>",
169
            type   => $payments[$i]{'accounttype'},
170
            time   => $payments[$i]{'date'},
171
            amount => $payments[$i]{'amount'},
172
            branch => $branch
173
        );
174
        push( @loop, \%row );
175
        $oldtype        = $payments[$i]{'accounttype'};
176
        $oldtime        = $payments[$i]{'timestamp'};
177
        $borrowernumber = $payments[$i]{'borrowernumber'};
178
        $i++;
179
    }
180
}
181
182
$template->param(
183
    loop1  => \@loop,
184
    totalw => $totalw,
185
    total  => $total
186
);
187
188
output_html_with_http_headers $input, $cookie, $template->output;
189
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt (-1 lines)
Lines 46-52 Link Here
46
	- <b>Warning:</b> This report is very resource intensive on
46
	- <b>Warning:</b> This report is very resource intensive on
47
	systems with large numbers of overdue items.</li>[% END %]
47
	systems with large numbers of overdue items.</li>[% END %]
48
	<li>    <a href="/cgi-bin/koha/circ/branchoverdues.pl">Overdues with fines</a> - Limited to your library.  See report help for other details.</li>
48
	<li>    <a href="/cgi-bin/koha/circ/branchoverdues.pl">Overdues with fines</a> - Limited to your library.  See report help for other details.</li>
49
<!--	<li>    <a href="/cgi-bin/koha/circ/stats.pl?time=yesterday">Daily reconciliation</a></li> -->
50
    [% IF Koha.Preference('OnSiteCheckouts') %]
49
    [% IF Koha.Preference('OnSiteCheckouts') %]
51
        <li><a href="/cgi-bin/koha/circ/on-site_checkouts.pl">Pending on-site checkouts</a></li>
50
        <li><a href="/cgi-bin/koha/circ/on-site_checkouts.pl">Pending on-site checkouts</a></li>
52
    [% END %]
51
    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/stats.tt (-56 lines)
Lines 1-55 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Circulation &rsaquo; Statistics</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body id="circ_stats" class="circ">
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'circ-search.inc' %]
8
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a>  &rsaquo; Statistics</div>
10
11
<div id="doc3" class="yui-t2">
12
   
13
   <div id="bd">
14
	<div id="yui-main">
15
	<div class="yui-b">
16
17
    [% IF ( notime ) %]
18
        <h1>Display statistics for:</h1>
19
        <ul>
20
            <li><a href="/cgi-bin/koha/circ/stats.pl?time=yesterday">yesterday</a></li>
21
            <li><a href="/cgi-bin/koha/circ/stats.pl?time=today">today</a></li>
22
    [% ELSE %]
23
    	[% IF ( loop1 ) %]
24
    	<table>
25
    	<caption>Statistics</caption>
26
    		<tr>
27
    			<th>Name</th>
28
    			<th>Type</th>
29
    			<th>Date/time</th>
30
    			<th>Amount</th>
31
    			<th>Library</th>
32
    		<tr>
33
    		[% FOREACH loop IN loop1 %]
34
    		<tr>
35
    			<td>[% loop.name %]</td>
36
    			<td>[% loop.type %]</td>
37
    			<td>[% loop.time %]</td>
38
    			<td>[% loop.amount %]</td>
39
    			<td>[% loop.branch %]</td>
40
    		</tr>
41
    		[% END %]
42
    		</table>
43
    		<p>Total paid: [% total %]<br />Total written off: [% totalw %]</p>
44
    	[% ELSE %]
45
    	<h3>No statistics to report</h3>
46
    	[% END %]
47
	
48
    [% END %]
49
</div>
50
</div>
51
<div class="yui-b">
52
[% INCLUDE 'circ-menu.inc' %]
53
</div>
54
</div>
55
[% INCLUDE 'intranet-bottom.inc' %]
56
- 

Return to bug 15230