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

(-)a/misc/cronjobs/create_koc_db.pl (-40 / +1 lines)
Lines 256-265 SELECT borrowernumber, Link Here
256
       city,
256
       city,
257
       phone,
257
       phone,
258
       dateofbirth,
258
       dateofbirth,
259
       sum( accountlines.amountoutstanding ) as total_fines
259
       account_balance as total_fines
260
FROM borrowers
260
FROM borrowers
261
LEFT JOIN accountlines USING (borrowernumber)
262
GROUP BY borrowernumber;
263
END_SQL
261
END_SQL
264
262
265
    my $fields_count = $sth_mysql->execute();
263
    my $fields_count = $sth_mysql->execute();
Lines 278-320 END_SQL Link Here
278
    }
276
    }
279
    $dbh_sqlite->commit();
277
    $dbh_sqlite->commit();
280
    print "inserted $count borrowers\n" if $verbose;
278
    print "inserted $count borrowers\n" if $verbose;
281
    # add_fines_to_borrowers_table();
282
}
283
284
=head2 add_fines_to_borrowers_table
285
286
Import the fines from koha.accountlines into the sqlite db
287
288
=cut
289
290
sub add_fines_to_borrowers_table {
291
292
    print "preparing to update borrowers\n" if $verbose;
293
    my $sth_mysql = $dbh_mysql->prepare(
294
        "SELECT DISTINCT borrowernumber, SUM( amountoutstanding ) AS total_fines
295
                                    FROM accountlines
296
                                    GROUP BY borrowernumber"
297
    );
298
    $sth_mysql->execute();
299
    my $count;
300
    while ( my $result = $sth_mysql->fetchrow_hashref() ) {
301
        $count++;
302
        if ( $verbose ) {
303
            print '.' unless ( $count % 10 );
304
            print "$count\n" unless ( $count % 1000 );
305
        }
306
307
        my $borrowernumber = $result->{'borrowernumber'};
308
        my $total_fines    = $result->{'total_fines'};
309
310
        # warn "Fines for Borrower # $borrowernumber are \$ $total_fines \n" if $verbose;
311
        my $sql = "UPDATE borrowers SET total_fines = ? WHERE borrowernumber = ?";
312
313
        my $sth_sqlite = $dbh_sqlite->prepare($sql);
314
        $sth_sqlite->execute( $total_fines, $borrowernumber );
315
        $sth_sqlite->finish();
316
    }
317
    print "updated $count borrowers\n" if ( $verbose && $count );
318
}
279
}
319
280
320
=head2 create_issue_table
281
=head2 create_issue_table
(-)a/misc/cronjobs/fines.pl (-3 / +7 lines)
Lines 129-137 for my $overdue ( @{$overdues} ) { Link Here
129
    if ( $mode eq 'production' && !$is_holiday{$branchcode} ) {
129
    if ( $mode eq 'production' && !$is_holiday{$branchcode} ) {
130
        if ( $amount > 0 ) {
130
        if ( $amount > 0 ) {
131
            UpdateFine(
131
            UpdateFine(
132
                $overdue->{itemnumber},
132
                {
133
                $overdue->{borrowernumber},
133
                    itemnumber     => $overdue->{itemnumber},
134
                $amount, $type, output_pref($datedue)
134
                    borrowernumber => $overdue->{borrowernumber},
135
                    amount         => $amount,
136
                    due            => output_pref($datedue),
137
                    issue_id       => $overdue->{issue_id}
138
                }
135
            );
139
            );
136
        }
140
        }
137
    }
141
    }
(-)a/misc/cronjobs/recalculate_account_balances.pl (-1 / +72 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl -w
2
3
# Copyright 2010 Biblibre SARL
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 3 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
use strict;
21
use warnings;
22
use utf8;
23
use v5.10;
24
25
BEGIN {
26
27
    # find Koha's Perl modules
28
    # test carefully before changing this
29
    use FindBin;
30
    eval { require "$FindBin::Bin/../kohalib.pl" };
31
}
32
33
use Getopt::Long;
34
35
use Pod::Usage;
36
use Koha::Database;
37
use Koha::Accounts;
38
39
my ($help, $verbose, $borrower);
40
41
GetOptions(
42
    'h|help'         => \$help,
43
    'v|verbose'      => \$verbose,
44
    'b|borrower:s'   => \$borrower,
45
);
46
47
if($help){
48
    print <<EOF
49
    This script recalculates all patron account balances
50
    Parameters :
51
    -h --help This message
52
    -v --verbose
53
    -b --borrower - Recalculate only this borrower's account balance
54
EOF
55
;
56
    exit;
57
}
58
59
say "Finding borrowers..." if ( $verbose );
60
61
my $params;
62
$params->{borrowernumber} = $borrower if ( $borrower );
63
64
my $borrowers_rs = Koha::Database->new()->schema->resultset('Borrower')->search( $params );
65
66
while ( my $borrower = $borrowers_rs->next() ) {
67
    print "Setting balance for " . $borrower->firstname() . " " . $borrower->surname() . " ( " . $borrower->cardnumber() . " ) to " if ( $verbose );
68
    my $account_balance = RecalculateAccountBalance({
69
        borrower => $borrower
70
    });
71
    say $account_balance if ( $verbose );
72
}

Return to bug 6427