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

(-)a/C4/Circulation.pm (-72 / +74 lines)
Lines 2005-2057 sub AddReturn { Link Here
2005
2005
2006
        if ($borrowernumber) {
2006
        if ($borrowernumber) {
2007
            if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
2007
            if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
2008
                # we only need to calculate and change the fines if we want to do that on return
2008
                _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } );
2009
                # Should be on for hourly loans
2010
                my $control = C4::Context->preference('CircControl');
2011
                my $control_branchcode =
2012
                    ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch}
2013
                  : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
2014
                  :                                     $issue->{branchcode};
2015
2016
                my $date_returned =
2017
                  $return_date ? dt_from_string($return_date) : $today;
2018
2019
                my ( $amount, $type, $unitcounttotal ) =
2020
                  C4::Overdues::CalcFine( $item, $borrower->{categorycode},
2021
                    $control_branchcode, $datedue, $date_returned );
2022
2023
                $type ||= q{};
2024
2025
                if ( C4::Context->preference('finesMode') eq 'production' ) {
2026
                    if ( $amount > 0 ) {
2027
                        C4::Overdues::UpdateFine(
2028
                            {
2029
                                issue_id       => $issue->{issue_id},
2030
                                itemnumber     => $issue->{itemnumber},
2031
                                borrowernumber => $issue->{borrowernumber},
2032
                                amount         => $amount,
2033
                                type           => $type,
2034
                                due            => output_pref($datedue),
2035
                            }
2036
                        );
2037
                    }
2038
                    elsif ($return_date) {
2039
2040
                        # Backdated returns may have fines that shouldn't exist,
2041
                        # so in this case, we need to drop those fines to 0
2042
2043
                        C4::Overdues::UpdateFine(
2044
                            {
2045
                                issue_id       => $issue->{issue_id},
2046
                                itemnumber     => $issue->{itemnumber},
2047
                                borrowernumber => $issue->{borrowernumber},
2048
                                amount         => 0,
2049
                                type           => $type,
2050
                                due            => output_pref($datedue),
2051
                            }
2052
                        );
2053
                    }
2054
                }
2055
            }
2009
            }
2056
2010
2057
            eval {
2011
            eval {
Lines 3007-3016 sub AddRenewal { Link Here
3007
    my $dbh = C4::Context->dbh;
2961
    my $dbh = C4::Context->dbh;
3008
2962
3009
    # Find the issues record for this book
2963
    # Find the issues record for this book
3010
    my $sth =
2964
    my $issuedata  = GetItemIssue($itemnumber);
3011
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
3012
    $sth->execute( $itemnumber );
3013
    my $issuedata = $sth->fetchrow_hashref;
3014
2965
3015
    return unless ( $issuedata );
2966
    return unless ( $issuedata );
3016
2967
Lines 3021-3032 sub AddRenewal { Link Here
3021
        return;
2972
        return;
3022
    }
2973
    }
3023
2974
2975
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
2976
2977
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issuedata->{overdue} ) {
2978
        _CalculateAndUpdateFine( { issue => $issuedata, item => $item, borrower => $borrower } );
2979
    }
2980
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2981
3024
    # If the due date wasn't specified, calculate it by adding the
2982
    # If the due date wasn't specified, calculate it by adding the
3025
    # book's loan length to today's date or the current due date
2983
    # book's loan length to today's date or the current due date
3026
    # based on the value of the RenewalPeriodBase syspref.
2984
    # based on the value of the RenewalPeriodBase syspref.
3027
    unless ($datedue) {
2985
    unless ($datedue) {
3028
2986
3029
        my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
3030
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2987
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
3031
2988
3032
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2989
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
Lines 3038-3044 sub AddRenewal { Link Here
3038
    # Update the issues record to have the new due date, and a new count
2995
    # Update the issues record to have the new due date, and a new count
3039
    # of how many times it has been renewed.
2996
    # of how many times it has been renewed.
3040
    my $renews = $issuedata->{'renewals'} + 1;
2997
    my $renews = $issuedata->{'renewals'} + 1;
3041
    $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2998
    my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
3042
                            WHERE borrowernumber=? 
2999
                            WHERE borrowernumber=? 
3043
                            AND itemnumber=?"
3000
                            AND itemnumber=?"
3044
    );
3001
    );
Lines 3068-3090 sub AddRenewal { Link Here
3068
    }
3025
    }
3069
3026
3070
    # Send a renewal slip according to checkout alert preferencei
3027
    # Send a renewal slip according to checkout alert preferencei
3071
    if ( C4::Context->preference('RenewalSendNotice') eq '1') {
3028
    if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
3072
	my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 );
3029
        $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 );
3073
	my $circulation_alert = 'C4::ItemCirculationAlertPreference';
3030
        my $circulation_alert = 'C4::ItemCirculationAlertPreference';
3074
	my %conditions = (
3031
        my %conditions        = (
3075
		branchcode   => $branch,
3032
            branchcode   => $branch,
3076
		categorycode => $borrower->{categorycode},
3033
            categorycode => $borrower->{categorycode},
3077
		item_type    => $item->{itype},
3034
            item_type    => $item->{itype},
3078
		notification => 'CHECKOUT',
3035
            notification => 'CHECKOUT',
3079
	);
3036
        );
3080
	if ($circulation_alert->is_enabled_for(\%conditions)) {
3037
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
3081
		SendCirculationAlert({
3038
            SendCirculationAlert(
3082
			type     => 'RENEWAL',
3039
                {
3083
			item     => $item,
3040
                    type     => 'RENEWAL',
3084
		borrower => $borrower,
3041
                    item     => $item,
3085
		branch   => $branch,
3042
                    borrower => $borrower,
3086
		});
3043
                    branch   => $branch,
3087
	}
3044
                }
3045
            );
3046
        }
3088
    }
3047
    }
3089
3048
3090
    # Remove any OVERDUES related debarment if the borrower has no overdues
3049
    # Remove any OVERDUES related debarment if the borrower has no overdues
Lines 4150-4156 sub GetTopIssues { Link Here
4150
    return @$rows;
4109
    return @$rows;
4151
}
4110
}
4152
4111
4112
sub _CalculateAndUpdateFine {
4113
    my ($params) = @_;
4114
4115
    my $borrower    = $params->{borrower};
4116
    my $item        = $params->{item};
4117
    my $issue       = $params->{issue};
4118
    my $return_date = $params->{return_date};
4119
4120
    unless ($borrower) { carp "No borrower passed in!" && return; }
4121
    unless ($item)     { carp "No item passed in!"     && return; }
4122
    unless ($issue)    { carp "No issue passed in!"    && return; }
4123
4124
    my $datedue = $issue->{date_due};
4125
4126
    # we only need to calculate and change the fines if we want to do that on return
4127
    # Should be on for hourly loans
4128
    my $control = C4::Context->preference('CircControl');
4129
    my $control_branchcode =
4130
        ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch}
4131
      : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
4132
      :                                     $issue->{branchcode};
4133
4134
    my $date_returned = $return_date ? dt_from_string($return_date) : dt_from_string();
4135
4136
    my ( $amount, $type, $unitcounttotal ) =
4137
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4138
4139
    $type ||= q{};
4140
4141
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4142
        if ( $amount > 0 ) {
4143
            C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber},
4144
                $amount, $type, output_pref($datedue) );
4145
        }
4146
        elsif ($return_date) {
4147
4148
            # Backdated returns may have fines that shouldn't exist,
4149
            # so in this case, we need to drop those fines to 0
4150
4151
            C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, 0, $type, output_pref($datedue) );
4152
        }
4153
    }
4154
}
4155
4153
1;
4156
1;
4157
4154
__END__
4158
__END__
4155
4159
4156
=head1 AUTHOR
4160
=head1 AUTHOR
Lines 4158-4161 __END__ Link Here
4158
Koha Development Team <http://koha-community.org/>
4162
Koha Development Team <http://koha-community.org/>
4159
4163
4160
=cut
4164
=cut
4161
4162
- 

Return to bug 14390