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

(-)a/C4/Overdues.pm (-32 lines)
Lines 56-68 BEGIN { Link Here
56
      &parse_overdues_letter
56
      &parse_overdues_letter
57
    );
57
    );
58
58
59
    # subs to remove
60
    push @EXPORT, qw(
61
      &BorType
62
    );
63
64
    # check that an equivalent don't exist already before moving
65
66
    # subs to move to Circulation.pm
59
    # subs to move to Circulation.pm
67
    push @EXPORT, qw(
60
    push @EXPORT, qw(
68
      &GetIssuesIteminfo
61
      &GetIssuesIteminfo
Lines 618-648 sub UpdateFine { Link Here
618
    }
611
    }
619
}
612
}
620
613
621
=head2 BorType
622
623
    $borrower = &BorType($borrowernumber);
624
625
Looks up a patron by borrower number.
626
627
C<$borrower> is a reference-to-hash whose keys are all of the fields
628
from the borrowers and categories tables of the Koha database. Thus,
629
C<$borrower> contains all information about both the borrower and
630
category they belong to.
631
632
=cut
633
634
sub BorType {
635
    my ($borrowernumber) = @_;
636
    my $dbh              = C4::Context->dbh;
637
    my $sth              = $dbh->prepare(
638
        "SELECT * from borrowers
639
      LEFT JOIN categories ON borrowers.categorycode=categories.categorycode 
640
      WHERE borrowernumber=?"
641
    );
642
    $sth->execute($borrowernumber);
643
    return $sth->fetchrow_hashref;
644
}
645
646
=head2 GetFine
614
=head2 GetFine
647
615
648
    $data->{'sum(amountoutstanding)'} = &GetFine($itemnum,$borrowernumber);
616
    $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 39-44 use File::Spec; Link Here
39
39
40
use Koha::Calendar;
40
use Koha::Calendar;
41
use Koha::DateUtils;
41
use Koha::DateUtils;
42
use Koha::Patrons;
42
use C4::Log;
43
use C4::Log;
43
44
44
my $help;
45
my $help;
Lines 111-120 for my $overdue ( @{$overdues} ) { Link Here
111
"ERROR in Getoverdues : issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
112
"ERROR in Getoverdues : issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
112
        next;
113
        next;
113
    }
114
    }
114
    my $borrower = BorType( $overdue->{borrowernumber} );
115
    my $patron = Koha::Patrons->find( $overdue->{borrowernumber} );
115
    my $branchcode =
116
    my $branchcode =
116
        ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
117
        ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
117
      : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
118
      : ( $control eq 'PatronLibrary' )   ? $patron->branchcode
118
      :                                     $overdue->{branchcode};
119
      :                                     $overdue->{branchcode};
119
120
120
# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
121
# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here).
Lines 129-135 for my $overdue ( @{$overdues} ) { Link Here
129
    ++$counted;
130
    ++$counted;
130
131
131
    my ( $amount, $unitcounttotal, $unitcount ) =
132
    my ( $amount, $unitcounttotal, $unitcount ) =
132
      CalcFine( $overdue, $borrower->{categorycode},
133
      CalcFine( $overdue, $patron->categorycode,
133
        $branchcode, $datedue, $today );
134
        $branchcode, $datedue, $today );
134
135
135
    # Don't update the fine if today is a holiday.
136
    # Don't update the fine if today is a holiday.
Lines 147-152 for my $overdue ( @{$overdues} ) { Link Here
147
            );
148
            );
148
        }
149
        }
149
    }
150
    }
151
    my $borrower = $patron->unblessed;
150
    if ($filename) {
152
    if ($filename) {
151
        my @cells;
153
        my @cells;
152
        push @cells,
154
        push @cells,
(-)a/misc/cronjobs/staticfines.pl (-8 / +8 lines)
Lines 48-53 use C4::Log; Link Here
48
use Getopt::Long;
48
use Getopt::Long;
49
use List::MoreUtils qw/none/;
49
use List::MoreUtils qw/none/;
50
use Koha::DateUtils;
50
use Koha::DateUtils;
51
use Koha::Patrons;
51
52
52
my $help    = 0;
53
my $help    = 0;
53
my $verbose = 0;
54
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