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

(-)a/C4/Circulation.pm (-4 lines)
Lines 2010-2019 of the return. It is ignored when a dropbox_branch is passed in. Link Here
2010
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,
2010
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,
2011
the old_issue is immediately anonymised
2011
the old_issue is immediately anonymised
2012
2012
2013
Ideally, this function would be internal to C<C4::Circulation>,
2014
not exported, but it is currently needed by one 
2015
routine in C<C4::Accounts>.
2016
2017
=cut
2013
=cut
2018
2014
2019
sub MarkIssueReturned {
2015
sub MarkIssueReturned {
(-)a/circ/add_message.pl (-5 lines)
Lines 26-36 use C4::Context; Link Here
26
use C4::Auth;
26
use C4::Auth;
27
use C4::Output;
27
use C4::Output;
28
use C4::Members;
28
use C4::Members;
29
use C4::Accounts;
30
use C4::Stats;
31
use C4::Koha;
32
use C4::Overdues;
33
use C4::Branch;    # GetBranches
34
29
35
my $input = new CGI;
30
my $input = new CGI;
36
31
(-)a/circ/del_message.pl (-5 lines)
Lines 26-36 use C4::Context; Link Here
26
use C4::Auth;
26
use C4::Auth;
27
use C4::Output;
27
use C4::Output;
28
use C4::Members;
28
use C4::Members;
29
use C4::Accounts;
30
use C4::Stats;
31
use C4::Koha;
32
use C4::Overdues;
33
use C4::Branch;    # GetBranches
34
29
35
my $input = new CGI;
30
my $input = new CGI;
36
31
(-)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 under the
12
# terms of the GNU General Public License as published by the Free Software
13
# Foundation; either version 2 of the License, or (at your option) any later
14
# version.
15
#
16
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License along
21
# with Koha; if not, write to the Free Software Foundation, Inc.,
22
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24
use strict;
25
#use warnings; FIXME - Bug 2505
26
use CGI;
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.tmpl",
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 45-51 Link Here
45
	- <b>Warning:</b> This report is very resource intensive on
45
	- <b>Warning:</b> This report is very resource intensive on
46
	systems with large numbers of overdue items.</li>[% END %]
46
	systems with large numbers of overdue items.</li>[% END %]
47
	<li>    <a href="/cgi-bin/koha/circ/branchoverdues.pl">Overdues with fines</a> - Limited to your library.  See report help for other details.</li>
47
	<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/stats.pl?time=yesterday">Daily reconciliation</a></li> -->
49
</ul>
48
</ul>
50
	
49
	
51
	</div>
50
	</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/stats.tt (-55 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' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (-1 lines)
Lines 65-71 Link Here
65
		<li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
65
		<li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
66
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
66
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
67
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
67
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
68
        <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
69
	</ul></div>
68
	</ul></div>
70
</div>
69
</div>
71
70
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/stats_screen.tt (-131 lines)
Lines 1-131 Link Here
1
[% INCLUDE 'doc-head-open.inc' %] 
2
<title>Koha &rsaquo; Reports &rsaquo; Till reconciliation</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'calendar.inc' %]
5
</head>
6
<body id="rep_stats_screen" class="rep">
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'circ-search.inc' %]
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> &rsaquo; Till reconciliation
10
</div>
11
12
<div id="doc3" class="yui-t2">
13
   
14
   <div id="bd">
15
	<div id="yui-main">
16
	<div class="yui-b">
17
18
<h1>Till reconciliation</h1>
19
20
<fieldset><legend>Search between two dates</legend>
21
<form action="stats.screen.pl" method="post">
22
  <label for="from">Start Date: </label>
23
  <input type="text" name="time" size="10" value="[% IF ( date ) %][% date %][% ELSE %]today[% END %]" id="from" class="datepickerfrom" />
24
  <label for="to">End Date: </label>
25
  <input type="text" name="time2" size="10" value="[% IF ( date2 ) %][% date2 %][% ELSE %]tomorrow[% END %]" class="datepickerto" id="to" />
26
  <input type="submit" value="To screen" name="submit" class="submit" />
27
<!--  <input type="submit" value="To Excel" name="submit" class="button"> --></fieldset>
28
</form>
29
30
<h2>Payments</h2>
31
32
        <table>
33
                <tr>
34
                        <th>Library</th>
35
                        <th>Date/time</th>
36
                        <th>Surname</th>
37
                        <th>First name</th>
38
                        <th>Description</th>
39
                        <th>Charge type</th>
40
                        <th>Invoice amount</th>
41
                        <th>Payment type</th>
42
                        <th>Payment amount</th>
43
                </tr>
44
45
                [% FOREACH loop IN loop1 %]
46
                <tr>
47
                     <td>[% loop.branch %]</td>
48
                        <td>[% loop.datetime %]</td>
49
                        <td>[% loop.surname %]</td>
50
                        <td>[% loop.firstname %]</td>
51
                        <td>[% loop.description %]</td>
52
                        <td>[% loop.accounttype %]</td>
53
                        <td>[% loop.amount %]</td>
54
                        <td>[% loop.type %]</td>
55
                        <td>[% loop.value %]</td>
56
                </tr>
57
                [% END %]
58
        </table>
59
60
<p>
61
        <b>Total amount paid: [% totalpaid %]</b>
62
</p>
63
64
65
<h2>Credits</h2>
66
67
        <table>
68
                <tr>
69
                        <th>Library</th>
70
                        <th>Date/time</th>
71
                        <th>Surname</th>
72
                        <th>First name</th>
73
                        <th>Description</th>
74
                        <th>Charge type</th>
75
                        <th>Invoice amount</th>
76
                </tr>
77
78
                [% FOREACH loop IN loop2 %]
79
                <tr>
80
                     <td>[% loop.creditbranch %]</td>
81
                        <td>[% loop.creditdate %]</td>
82
                        <td>[% loop.creditsurname %]</td>
83
                        <td>[% loop.creditfirstname %]</td>
84
                        <td>[% loop.creditdescription %]</td>
85
                        <td>[% loop.creditaccounttype %]</td>
86
                        <td>[% loop.creditamount %]</td>
87
                </tr>
88
                [% END %]
89
        </table>
90
<p>
91
       <ul><li> <b>Total amount credits: [% totalcredits %]</b></li>
92
        <li><b>Total number written off: [% totalwritten %] charges</b></li></ul>
93
</p>
94
95
96
<h2>Refunds</h2>
97
98
        <table>
99
                <tr>
100
                        <th>Library</th>
101
                        <th>Date/time</th>
102
                        <th>Surname</th>
103
                        <th>First name</th>
104
                        <th>Description</th>
105
                        <th>Charge type</th>
106
                        <th>Invoice amount</th>
107
                </tr>
108
109
                [% FOREACH loop IN loop3 %]
110
                <tr>
111
                     <td>[% loop.refundbranch %]</td>
112
                        <td>[% loop.refunddate %]</td>
113
                        <td>[% loop.refundsurname %]</td>
114
                        <td>[% loop.refundfirstname %]</td>
115
                        <td>[% loop.refunddescription %]</td>
116
                        <td>[% loop.refundaccounttype %]</td>
117
                        <td>[% loop.refundamount %]</td>
118
                </tr>
119
                [% END %]
120
        </table>
121
<p>
122
        <ul><li><b>Total amount refunds: [% totalrefund %]</b></li>
123
        <li><b>Total amount of cash collected: [% totalcash %] </b></li></ul>
124
</p>
125
</div>
126
</div>
127
<div class="yui-b">
128
[% INCLUDE 'reports-menu.inc' %]
129
</div>
130
</div>
131
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/offline_circ/enqueue_koc.pl (-1 lines)
Lines 27-33 use C4::Auth; Link Here
27
use C4::Koha;
27
use C4::Koha;
28
use C4::Context;
28
use C4::Context;
29
use C4::Biblio;
29
use C4::Biblio;
30
use C4::Accounts;
31
use C4::Circulation;
30
use C4::Circulation;
32
use C4::Items;
31
use C4::Items;
33
use C4::Members;
32
use C4::Members;
(-)a/offline_circ/process_koc.pl (-3 / +9 lines)
Lines 27-39 use C4::Auth; Link Here
27
use C4::Koha;
27
use C4::Koha;
28
use C4::Context;
28
use C4::Context;
29
use C4::Biblio;
29
use C4::Biblio;
30
use C4::Accounts;
31
use C4::Circulation;
30
use C4::Circulation;
32
use C4::Items;
31
use C4::Items;
33
use C4::Members;
32
use C4::Members;
34
use C4::Stats;
33
use C4::Stats;
35
use C4::UploadedFile;
34
use C4::UploadedFile;
36
use C4::BackgroundJob;
35
use C4::BackgroundJob;
36
use Koha::Accounts;
37
use Koha::Database;
37
38
38
use Date::Calc qw( Add_Delta_Days Date_to_Days );
39
use Date::Calc qw( Add_Delta_Days Date_to_Days );
39
40
Lines 357-364 sub kocReturnItem { Link Here
357
358
358
sub kocMakePayment {
359
sub kocMakePayment {
359
    my ( $circ ) = @_;
360
    my ( $circ ) = @_;
360
    my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } );
361
361
    recordpayment( $borrower->{'borrowernumber'}, $circ->{'amount'} );
362
    my $borrower =
363
      Koha::Database->new()->schema()->resultset('Borrower')
364
      ->single( { cardnumber => $circ->{'cardnumber'} } );
365
366
    AddCredit({ borrower => $borrower, amount => $circ->{'amount'} });
367
362
    push @output, {
368
    push @output, {
363
        payment => 1,
369
        payment => 1,
364
        amount => $circ->{'amount'},
370
        amount => $circ->{'amount'},
(-)a/reports/stats.print.pl (-178 lines)
Lines 1-178 Link Here
1
#!/usr/bin/perl
2
3
use strict;
4
#use warnings; FIXME - Bug 2505
5
use CGI;
6
use C4::Output;
7
8
use C4::Auth;
9
use C4::Context;
10
use Date::Manip;
11
use C4::Stats;
12
use Text::CSV_XS;
13
&Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
14
15
my $csv = Text::CSV_XS->new(
16
    {
17
        'quote_char'  => '"',
18
        'escape_char' => '"',
19
        'sep_char'    => ',',
20
        'binary'      => 1
21
    }
22
);
23
24
my $input=new CGI;
25
my $time=$input->param('time');
26
my $time2=$input->param('time2');
27
28
my @loop1;
29
my @loop2;
30
my $date;
31
my $date2;
32
if ($time eq 'yesterday'){
33
        $date=ParseDate('yesterday');
34
        $date2=ParseDate('today');
35
}
36
if ($time eq 'today'){
37
        $date=ParseDate('today');
38
        $date2=ParseDate('tomorrow');
39
}
40
if ($time eq 'daybefore'){
41
        $date=ParseDate('2 days ago');
42
        $date2=ParseDate('yesterday');
43
}
44
if ($time eq 'month') {
45
        $date = ParseDate('1 month ago');
46
        $date2 = ParseDate('today');
47
48
}
49
if ($time=~ /\//){
50
        $date=ParseDate($time);
51
        $date2=ParseDateDelta('+ 1 day');
52
        $date2=DateCalc($date,$date2);
53
}
54
55
if ($time eq ''){
56
        $date=ParseDate('today');
57
        $date2=ParseDate('tomorrow');
58
}
59
60
if ($time2 ne ''){
61
            $date=ParseDate($time);
62
            $date2=ParseDate($time2);
63
}
64
65
my $date=UnixDate($date,'%Y-%m-%d');
66
my $date2=UnixDate($date2,'%Y-%m-%d');
67
68
#warn "MASON: DATE: $date, $date2";
69
70
#get a list of every payment
71
my @payments=TotalPaid($date,$date2);
72
73
my $count=@payments;
74
# print "MASON: number of payments=$count\n";
75
76
my $i=0;
77
my $totalcharges=0;
78
my $totalcredits=0;
79
my $totalpaid=0;
80
my $totalwritten=0;
81
82
# lets get a a list of all individual item charges paid for by that payment
83
while ($i<$count ){
84
85
       my $count;
86
       my @charges;
87
88
       if ($payments[$i]{'type'} ne 'writeoff'){         # lets ignore writeoff payments!.
89
           @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'});
90
           $totalcharges++;
91
           $count=@charges;
92
93
           # getting each of the charges and putting them into a array to be printed out
94
           #this loops per charge per person
95
           for (my $i2=0;$i2<$count;$i2++){
96
97
               my $hour=substr($payments[$i]{'timestamp'},8,2);
98
               my $min=substr($payments[$i]{'timestamp'},10,2);
99
               my $sec=substr($payments[$i]{'timestamp'},12,2);
100
               my $time="$hour:$min:$sec";
101
               my $time2="$payments[$i]{'date'}";
102
#               my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'});
103
	       my $branch=$payments[$i]{'branch'};
104
105
               my @rows1 = ($branch,          # lets build up a row
106
                            $payments[$i]->{'datetime'},
107
                            $payments[$i]->{'surname'},
108
                            $payments[$i]->{'firstname'},
109
                            $charges[$i2]->{'description'},
110
                            $charges[$i2]->{'accounttype'},
111
   # rounding amounts to 2dp and adding dollar sign to make excel read it as currency format
112
                            "\$".sprintf("%.2f", $charges[$i2]->{'amount'}), 
113
                            $payments[$i]->{'type'},
114
                            "\$".$payments[$i]->{'value'});
115
116
               push (@loop1, \@rows1);
117
	       $totalpaid = $totalpaid + $payments[$i]->{'value'};
118
           }
119
       } else {
120
         ++$totalwritten;
121
       }
122
123
       $i++; #increment the while loop
124
}
125
126
#get credits and append to the bottom of payments
127
my @credits=getcredits($date,$date2);
128
129
my $count=@credits;
130
my $i=0;
131
132
while ($i<$count ){
133
134
       my @rows2 = ($credits[$i]->{'branchcode'},
135
                    $credits[$i]->{'date'},
136
                    $credits[$i]->{'surname'},
137
                    $credits[$i]->{'firstname'},
138
                    $credits[$i]->{'description'},
139
                    $credits[$i]->{'accounttype'},
140
                    "\$".$credits[$i]->{'amount'});
141
142
       push (@loop2, \@rows2);
143
       $totalcredits = $totalcredits + $credits[$i]->{'amount'};
144
       $i++;
145
}
146
147
#takes off first char minus sign "-100.00"
148
$totalcredits = substr($totalcredits, 1);
149
150
print $input->header(
151
    -type       => 'application/vnd.ms-excel',
152
    -attachment => "stats.csv",
153
);
154
print "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
155
156
157
for my $row ( @loop1 ) {
158
159
    $csv->combine(@$row);
160
    my $string = $csv->string;
161
    print $string, "\n";
162
}
163
164
print ",,,,,,,\n";
165
166
for my $row ( @loop2 ) {
167
168
    $csv->combine(@$row);
169
    my $string = $csv->string;
170
    print $string, "\n";
171
}
172
173
print ",,,,,,,\n";
174
print ",,,,,,,\n";
175
print ",,Total Amount Paid, $totalpaid\n";
176
print ",,Total Number Written, $totalwritten\n";
177
print ",,Total Amount Credits, $totalcredits\n";
178
(-)a/reports/stats.screen.pl (-268 lines)
Lines 1-267 Link Here
1
#!/usr/bin/perl
2
3
# Copyright Katipo Communications 2006
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; FIXME - Bug 2505
23
use CGI;
24
use C4::Output;
25
use C4::Auth;
26
use C4::Context;
27
use C4::Stats;
28
use C4::Accounts;
29
use C4::Debug;
30
use Date::Manip;
31
32
my $input = new CGI;
33
my $time  = $input->param('time');
34
my $time2 = $input->param('time2');
35
my $op    = $input->param('submit');
36
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
    {
39
        template_name   => "reports/stats_screen.tmpl",
40
        query           => $input,
41
        type            => "intranet",
42
        authnotrequired => 1,
43
        flagsrequired   => { reports => '*' },
44
        debug           => 1,
45
    }
46
);
47
48
( $time  = "today" )    if !$time;
49
( $time2 = "tomorrow" ) if !$time2;
50
51
my $date  = ParseDate($time);
52
my $date2 = ParseDate($time2);
53
$date  = UnixDate( $date,  '%Y-%m-%d' );
54
$date2 = UnixDate( $date2, '%Y-%m-%d' );
55
$debug and warn "MASON: TIME: $time, $time2";
56
$debug and warn "MASON: DATE: $date, $date2";
57
58
# get a list of every payment
59
my @payments = TotalPaid( $date, $date2 );
60
61
my $count = @payments;
62
63
$debug and warn "MASON: number of payments=$count\n";
64
65
my $i            = 0;
66
my $totalcharges = 0;
67
my $totalcredits = 0;
68
my $totalpaid    = 0;
69
my $totalwritten = 0;
70
my @loop1;
71
my @loop2;
72
73
# lets get a a list of all individual item charges paid for by that payment
74
75
foreach my $payment (@payments) {
76
77
    my @charges;
78
    if ( $payment->{'type'} ne 'writeoff' ) {
79
80
        @charges = getcharges(
81
            $payment->{'borrowernumber'},
82
            $payment->{'timestamp'},
83
            $payment->{'proccode'}
84
        );
85
        $totalcharges++;
86
        my $count = @charges;
87
88
   # getting each of the charges and putting them into a array to be printed out
89
   #this loops per charge per person
90
        for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) {
91
            my $hour = substr( $payment->{'timestamp'}, 8,  2 );
92
            my $min  = substr( $payment->{'timestamp'}, 10, 2 );
93
            my $sec  = substr( $payment->{'timestamp'}, 12, 2 );
94
            my $time = "$hour:$min:$sec";
95
            my $time2 = "$payment->{'date'}";
96
97
  #               my $branch=Getpaidbranch($time2,$payment->{'borrowernumber'});
98
            my $branch = $payment->{'branch'};
99
100
            # lets build up a row
101
            my %rows1 = (
102
                branch      => $branch,
103
                datetime    => $payment->{'datetime'},
104
                surname     => $payment->{'surname'},
105
                firstname   => $payment->{'firstname'},
106
                description => $charges[$i2]->{'description'},
107
                accounttype => $charges[$i2]->{'accounttype'},
108
                amount      => sprintf( "%.2f", $charges[$i2]->{'amount'} )
109
                ,    # rounding amounts to 2dp
110
                type  => $payment->{'type'},
111
                value => sprintf( "%.2f", $payment->{'value'} )
112
            );       # rounding amounts to 2dp
113
114
            push( @loop1, \%rows1 );
115
116
        }
117
            $totalpaid = $totalpaid + $payment->{'value'};
118
			$debug and warn "totalpaid = $totalpaid";		
119
    }
120
    else {
121
        ++$totalwritten;
122
    }
123
124
}
125
126
#get credits and append to the bottom of payments
127
my @credits = getcredits( $date, $date2 );
128
129
my $count = @credits;
130
my $i     = 0;
131
132
while ( $i < $count ) {
133
134
    my %rows2 = (
135
        creditbranch      => $credits[$i]->{'branchcode'},
136
        creditdate        => $credits[$i]->{'date'},
137
        creditsurname     => $credits[$i]->{'surname'},
138
        creditfirstname   => $credits[$i]->{'firstname'},
139
        creditdescription => $credits[$i]->{'description'},
140
        creditaccounttype => $credits[$i]->{'accounttype'},
141
        creditamount      => sprintf( "%.2f", $credits[$i]->{'amount'} )
142
    );
143
144
    push( @loop2, \%rows2 );
145
    $totalcredits = $totalcredits + $credits[$i]->{'amount'};
146
    $i++;    #increment the while loop
147
}
148
149
#takes off first char minus sign "-100.00"
150
$totalcredits = substr( $totalcredits, 1 );
151
152
my $totalrefunds = 0;
153
my @loop3;
154
my @refunds = getrefunds( $date, $date2 );
155
$count = @refunds;
156
$i     = 0;
157
158
while ( $i < $count ) {
159
160
    my %rows3 = (
161
        refundbranch      => $refunds[$i]->{'branchcode'},
162
        refunddate        => $refunds[$i]->{'datetime'},
163
        refundsurname     => $refunds[$i]->{'surname'},
164
        refundfirstname   => $refunds[$i]->{'firstname'},
165
        refunddescription => $refunds[$i]->{'description'},
166
        refundaccounttype => $refunds[$i]->{'accounttype'},
167
        refundamount      => sprintf( "%.2f", $refunds[$i]->{'amount'} )
168
    );
169
170
    push( @loop3, \%rows3 );
171
    $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'};
172
    $i++;    #increment the while loop
173
}
174
175
my $totalcash = $totalpaid - $totalrefunds;
176
177
if ( $op eq 'To Excel' ) {
178
179
    my $csv = Text::CSV_XS->new(
180
        {
181
            'quote_char'  => '"',
182
            'escape_char' => '"',
183
            'sep_char'    => ',',
184
            'binary'      => 1
185
        }
186
    );
187
188
    print $input->header(
189
        -type       => 'application/vnd.ms-excel',
190
        -attachment => "stats.csv",
191
    );
192
    print
193
"Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n";
194
195
    $DB::single = 1;
196
197
    for my $row (@loop1) {
198
        my @array = (
199
            $row->{'branch'},      $row->{'datetime'},
200
            $row->{'surname'},     $row->{'firstname'},
201
            $row->{'description'}, $row->{'accounttype'},
202
            $row->{'amount'},      $row->{'type'},
203
            $row->{'value'}
204
        );
205
206
        $csv->combine(@array);
207
        my $string = $csv->string(@array);
208
        print $string, "\n";
209
    }
210
    print ",,,,,,,\n";
211
    print
212
"Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
213
214
    for my $row (@loop2) {
215
216
        my @array = (
217
            $row->{'creditbranch'},      $row->{'creditdate'},
218
            $row->{'creditsurname'},     $row->{'creditfirstname'},
219
            $row->{'creditdescription'}, $row->{'creditaccounttype'},
220
            $row->{'creditamount'}
221
        );
222
223
        $csv->combine(@array);
224
        my $string = $csv->string(@array);
225
        print $string, "\n";
226
    }
227
    print ",,,,,,,\n";
228
    print
229
"Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n";
230
231
    for my $row (@loop3) {
232
        my @array = (
233
            $row->{'refundbranch'},      $row->{'refunddate'},
234
            $row->{'refundsurname'},     $row->{'refundfirstname'},
235
            $row->{'refunddescription'}, $row->{'refundaccounttype'},
236
            $row->{'refundamount'}
237
        );
238
239
        $csv->combine(@array);
240
        my $string = $csv->string(@array);
241
        print $string, "\n";
242
243
    }
244
245
    print ",,,,,,,\n";
246
    print ",,,,,,,\n";
247
    print ",,Total Amount Paid, $totalpaid\n";
248
    print ",,Total Number Written, $totalwritten\n";
249
    print ",,Total Amount Credits, $totalcredits\n";
250
    print ",,Total Amount Refunds, $totalrefunds\n";
251
}
252
else {
253
    $template->param(
254
        date         => $time,
255
        date2        => $time2,
256
        loop1        => \@loop1,
257
        loop2        => \@loop2,
258
        loop3        => \@loop3,
259
        totalpaid    => $totalpaid,
260
        totalcredits => $totalcredits,
261
        totalwritten => $totalwritten,
262
        totalrefund  => $totalrefunds,
263
        totalcash    => $totalcash,
264
    );
265
    output_html_with_http_headers $input, $cookie, $template->output;
266
}
267
268
- 

Return to bug 6427