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

(-)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 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
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