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

(-)a/C4/Overdues.pm (-32 lines)
Lines 58-70 BEGIN { Link Here
58
      &parse_overdues_letter
58
      &parse_overdues_letter
59
    );
59
    );
60
60
61
    # subs to remove
62
    push @EXPORT, qw(
63
      &BorType
64
    );
65
66
    # check that an equivalent don't exist already before moving
67
68
    # subs to move to Circulation.pm
61
    # subs to move to Circulation.pm
69
    push @EXPORT, qw(
62
    push @EXPORT, qw(
70
      &GetIssuesIteminfo
63
      &GetIssuesIteminfo
Lines 603-633 sub UpdateFine { Link Here
603
    }
596
    }
604
}
597
}
605
598
606
=head2 BorType
607
608
    $borrower = &BorType($borrowernumber);
609
610
Looks up a patron by borrower number.
611
612
C<$borrower> is a reference-to-hash whose keys are all of the fields
613
from the borrowers and categories tables of the Koha database. Thus,
614
C<$borrower> contains all information about both the borrower and
615
category they belong to.
616
617
=cut
618
619
sub BorType {
620
    my ($borrowernumber) = @_;
621
    my $dbh              = C4::Context->dbh;
622
    my $sth              = $dbh->prepare(
623
        "SELECT * from borrowers
624
      LEFT JOIN categories ON borrowers.categorycode=categories.categorycode 
625
      WHERE borrowernumber=?"
626
    );
627
    $sth->execute($borrowernumber);
628
    return $sth->fetchrow_hashref;
629
}
630
631
=head2 GetFine
599
=head2 GetFine
632
600
633
    $data->{'sum(amountoutstanding)'} = &GetFine($itemnum,$borrowernumber);
601
    $data->{'sum(amountoutstanding)'} = &GetFine($itemnum,$borrowernumber);
(-)a/installer/data/mysql/fix_unclosed_nonaccruing_fines_bug17135.pl (-4 / +5 lines)
Lines 21-30 Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use C4::Context;
23
use C4::Context;
24
use C4::Overdues qw/CalcFine BorType/;
24
use C4::Overdues qw/CalcFine/;
25
use C4::Log qw/logaction/;
25
use C4::Log qw/logaction/;
26
26
27
use Koha::DateUtils;
27
use Koha::DateUtils;
28
use Koha::Patrons;
28
use Getopt::Long;
29
use Getopt::Long;
29
30
30
my ($help, $verbose, $confirm, $log, $stdout_log);
31
my ($help, $verbose, $confirm, $log, $stdout_log);
Lines 151-163 sub Bug_17135_fix { Link Here
151
            my $overdue = $overdues->[0];
152
            my $overdue = $overdues->[0];
152
153
153
            ### last if $overdue->{itemlost}; ## arguable
154
            ### last if $overdue->{itemlost}; ## arguable
154
            my $borrower = BorType( $overdue->{borrowernumber} );
155
            my $patron = Koha::Patron->find( $overdue->{borrowernumber} );
155
            my $branchcode =
156
            my $branchcode =
156
             ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
157
             ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
157
             : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
158
             : ( $control eq 'PatronLibrary' )   ? $patron->branchcode
158
             :                                     $overdue->{branchcode};
159
             :                                     $overdue->{branchcode};
159
160
160
            my ($amount) = CalcFine( $overdue, $borrower->{categorycode}, $branchcode, $datedue, $today );
161
            my ($amount) = CalcFine( $overdue, $patron->categorycode, $branchcode, $datedue, $today );
161
            ### Warn("CalcFine() returned '$amount'");
162
            ### Warn("CalcFine() returned '$amount'");
162
            last if ($amount > 0); ## accruing fine, skip closing
163
            last if ($amount > 0); ## accruing fine, skip closing
163
164
(-)a/misc/cronjobs/fines.pl (-3 / +5 lines)
Lines 38-43 use File::Spec; Link Here
38
38
39
use Koha::Calendar;
39
use Koha::Calendar;
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::Patrons;
41
use C4::Log;
42
use C4::Log;
42
43
43
my $help;
44
my $help;
Lines 105-114 for my $overdue ( @{$overdues} ) { Link Here
105
"ERROR in Getoverdues : issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
106
"ERROR in Getoverdues : issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
106
        next;
107
        next;
107
    }
108
    }
108
    my $borrower = BorType( $overdue->{borrowernumber} );
109
    my $patron = Koha::Patrons->find( $overdue->{borrowernumber} );
109
    my $branchcode =
110
    my $branchcode =
110
        ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
111
        ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
111
      : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
112
      : ( $control eq 'PatronLibrary' )   ? $patron->branchcode
112
      :                                     $overdue->{branchcode};
113
      :                                     $overdue->{branchcode};
113
114
114
# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
115
# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
Lines 123-129 for my $overdue ( @{$overdues} ) { Link Here
123
    ++$counted;
124
    ++$counted;
124
125
125
    my ( $amount, $unitcounttotal, $unitcount ) =
126
    my ( $amount, $unitcounttotal, $unitcount ) =
126
      CalcFine( $overdue, $borrower->{categorycode},
127
      CalcFine( $overdue, $patron->categorycode,
127
        $branchcode, $datedue, $today );
128
        $branchcode, $datedue, $today );
128
129
129
    # Don't update the fine if today is a holiday.
130
    # Don't update the fine if today is a holiday.
Lines 141-146 for my $overdue ( @{$overdues} ) { Link Here
141
            );
142
            );
142
        }
143
        }
143
    }
144
    }
145
    my $borrower = $patron->unblessed;
144
    if ($filename) {
146
    if ($filename) {
145
        my @cells;
147
        my @cells;
146
        push @cells,
148
        push @cells,
(-)a/misc/cronjobs/staticfines.pl (-8 / +8 lines)
Lines 47-52 use C4::Log; Link Here
47
use Getopt::Long;
47
use Getopt::Long;
48
use List::MoreUtils qw/none/;
48
use List::MoreUtils qw/none/;
49
use Koha::DateUtils;
49
use Koha::DateUtils;
50
use Koha::Patrons;
50
51
51
my $help    = 0;
52
my $help    = 0;
52
my $verbose = 0;
53
my $verbose = 0;
Lines 157-172 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
157
        print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
158
        print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
158
        next;    # Note: this doesn't solve everything.  After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
159
        next;    # Note: this doesn't solve everything.  After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
159
    }
160
    }
160
    my $borrower = BorType( $data->[$i]->{'borrowernumber'} );
161
    my $patron = Koha::Patrons->find( $data->[$i]->{'borrowernumber'} );
161
162
162
    # Skipping borrowers that are not in @categories
163
    # Skipping borrowers that are not in @categories
163
    $bigdebug and warn "Skipping borrower from category " . $borrower->{categorycode} if none { $borrower->{categorycode} eq $_ } @categories;
164
    $bigdebug and warn "Skipping borrower from category " . $patron->categorycode if none { $patron->categorycode eq $_ } @categories;
164
    next if none { $borrower->{categorycode} eq $_ } @categories;
165
    next if none { $patron->categorycode eq $_ } @categories;
165
166
166
    my $branchcode =
167
    my $branchcode =
167
        ( $useborrowerlibrary )           ? $borrower->{branchcode}
168
        ( $useborrowerlibrary )           ? $patron->branchcode
168
      : ( $control eq 'ItemHomeLibrary' ) ? $data->[$i]->{homebranch}
169
      : ( $control eq 'ItemHomeLibrary' ) ? $data->[$i]->{homebranch}
169
      : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
170
      : ( $control eq 'PatronLibrary' )   ? $patron->branchcode
170
      :                                     $data->[$i]->{branchcode};
171
      :                                     $data->[$i]->{branchcode};
171
    # In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
172
    # In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
172
173
Lines 190-203 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
190
    $overdueItemsCounted++;
191
    $overdueItemsCounted++;
191
    my ( $amount, $unitcounttotal, $unitcount ) = CalcFine(
192
    my ( $amount, $unitcounttotal, $unitcount ) = CalcFine(
192
        $data->[$i],
193
        $data->[$i],
193
        $borrower->{'categorycode'},
194
        $patron->categorycode,
194
        $branchcode,
195
        $branchcode,
195
        $datedue,
196
        $datedue,
196
        $today,
197
        $today,
197
    );
198
    );
198
199
199
    # Reassign fine's amount if specified in command-line
200
    # Reassign fine's amount if specified in command-line
200
    $amount = $catamounts{$borrower->{'categorycode'}} if (defined $catamounts{$borrower->{'categorycode'}});
201
    $amount = $catamounts{$patron->categorycode} if (defined $catamounts{$patron->categorycode});
201
202
202
    # We check if there is already a fine for the given borrower
203
    # We check if there is already a fine for the given borrower
203
    my $fine = GetFine(undef, $data->[$i]->{'borrowernumber'});
204
    my $fine = GetFine(undef, $data->[$i]->{'borrowernumber'});
204
- 

Return to bug 22589