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

(-)a/C4/Circulation.pm (-57 / +73 lines)
Lines 1911-1949 sub AddReturn { Link Here
1911
1911
1912
        if ($borrowernumber) {
1912
        if ($borrowernumber) {
1913
            if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
1913
            if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
1914
                # we only need to calculate and change the fines if we want to do that on return
1914
                _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } );
1915
                # Should be on for hourly loans
1916
                my $control = C4::Context->preference('CircControl');
1917
                my $control_branchcode =
1918
                    ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch}
1919
                  : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
1920
                  :                                     $issue->{branchcode};
1921
1922
                my $date_returned =
1923
                  $return_date ? dt_from_string($return_date) : $today;
1924
1925
                my ( $amount, $type, $unitcounttotal ) =
1926
                  C4::Overdues::CalcFine( $item, $borrower->{categorycode},
1927
                    $control_branchcode, $datedue, $date_returned );
1928
1929
                $type ||= q{};
1930
1931
                if ( C4::Context->preference('finesMode') eq 'production' ) {
1932
                    if ( $amount > 0 ) {
1933
                        C4::Overdues::UpdateFine( $issue->{itemnumber},
1934
                            $issue->{borrowernumber},
1935
                            $amount, $type, output_pref($datedue) );
1936
                    }
1937
                    elsif ($return_date) {
1938
1939
                       # Backdated returns may have fines that shouldn't exist,
1940
                       # so in this case, we need to drop those fines to 0
1941
1942
                        C4::Overdues::UpdateFine( $issue->{itemnumber},
1943
                            $issue->{borrowernumber},
1944
                            0, $type, output_pref($datedue) );
1945
                    }
1946
                }
1947
            }
1915
            }
1948
1916
1949
            eval {
1917
            eval {
Lines 2887-2896 sub AddRenewal { Link Here
2887
    my $dbh = C4::Context->dbh;
2855
    my $dbh = C4::Context->dbh;
2888
2856
2889
    # Find the issues record for this book
2857
    # Find the issues record for this book
2890
    my $sth =
2858
    my $issuedata  = GetItemIssue($itemnumber);
2891
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2892
    $sth->execute( $itemnumber );
2893
    my $issuedata = $sth->fetchrow_hashref;
2894
2859
2895
    return unless ( $issuedata );
2860
    return unless ( $issuedata );
2896
2861
Lines 2901-2912 sub AddRenewal { Link Here
2901
        return;
2866
        return;
2902
    }
2867
    }
2903
2868
2869
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
2870
2871
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issuedata->{overdue} ) {
2872
        _CalculateAndUpdateFine( { issue => $issuedata, item => $item, borrower => $borrower } );
2873
    }
2874
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2875
2904
    # If the due date wasn't specified, calculate it by adding the
2876
    # If the due date wasn't specified, calculate it by adding the
2905
    # book's loan length to today's date or the current due date
2877
    # book's loan length to today's date or the current due date
2906
    # based on the value of the RenewalPeriodBase syspref.
2878
    # based on the value of the RenewalPeriodBase syspref.
2907
    unless ($datedue) {
2879
    unless ($datedue) {
2908
2880
2909
        my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
2910
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2881
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2911
2882
2912
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2883
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
Lines 2918-2924 sub AddRenewal { Link Here
2918
    # Update the issues record to have the new due date, and a new count
2889
    # Update the issues record to have the new due date, and a new count
2919
    # of how many times it has been renewed.
2890
    # of how many times it has been renewed.
2920
    my $renews = $issuedata->{'renewals'} + 1;
2891
    my $renews = $issuedata->{'renewals'} + 1;
2921
    $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2892
    my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2922
                            WHERE borrowernumber=? 
2893
                            WHERE borrowernumber=? 
2923
                            AND itemnumber=?"
2894
                            AND itemnumber=?"
2924
    );
2895
    );
Lines 2948-2970 sub AddRenewal { Link Here
2948
    }
2919
    }
2949
2920
2950
    # Send a renewal slip according to checkout alert preferencei
2921
    # Send a renewal slip according to checkout alert preferencei
2951
    if ( C4::Context->preference('RenewalSendNotice') eq '1') {
2922
    if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
2952
	my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 );
2923
        $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 );
2953
	my $circulation_alert = 'C4::ItemCirculationAlertPreference';
2924
        my $circulation_alert = 'C4::ItemCirculationAlertPreference';
2954
	my %conditions = (
2925
        my %conditions        = (
2955
		branchcode   => $branch,
2926
            branchcode   => $branch,
2956
		categorycode => $borrower->{categorycode},
2927
            categorycode => $borrower->{categorycode},
2957
		item_type    => $item->{itype},
2928
            item_type    => $item->{itype},
2958
		notification => 'CHECKOUT',
2929
            notification => 'CHECKOUT',
2959
	);
2930
        );
2960
	if ($circulation_alert->is_enabled_for(\%conditions)) {
2931
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2961
		SendCirculationAlert({
2932
            SendCirculationAlert(
2962
			type     => 'RENEWAL',
2933
                {
2963
			item     => $item,
2934
                    type     => 'RENEWAL',
2964
		borrower => $borrower,
2935
                    item     => $item,
2965
		branch   => $branch,
2936
                    borrower => $borrower,
2966
		});
2937
                    branch   => $branch,
2967
	}
2938
                }
2939
            );
2940
        }
2968
    }
2941
    }
2969
2942
2970
    # Remove any OVERDUES related debarment if the borrower has no overdues
2943
    # Remove any OVERDUES related debarment if the borrower has no overdues
Lines 4025-4030 sub GetTopIssues { Link Here
4025
    return @$rows;
3998
    return @$rows;
4026
}
3999
}
4027
4000
4001
sub _CalculateAndUpdateFine {
4002
    my ($params) = @_;
4003
4004
    my $borrower    = $params->{borrower};
4005
    my $item        = $params->{item};
4006
    my $issue       = $params->{issue};
4007
    my $return_date = $params->{return_date};
4008
4009
    unless ($borrower) { carp "No borrower passed in!" && return; }
4010
    unless ($item)     { carp "No item passed in!"     && return; }
4011
    unless ($issue)    { carp "No issue passed in!"    && return; }
4012
4013
    my $datedue = $issue->{date_due};
4014
4015
    # we only need to calculate and change the fines if we want to do that on return
4016
    # Should be on for hourly loans
4017
    my $control = C4::Context->preference('CircControl');
4018
    my $control_branchcode =
4019
        ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch}
4020
      : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
4021
      :                                     $issue->{branchcode};
4022
4023
    my $date_returned = $return_date ? dt_from_string($return_date) : dt_from_string();
4024
4025
    my ( $amount, $type, $unitcounttotal ) =
4026
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4027
4028
    $type ||= q{};
4029
4030
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4031
        if ( $amount > 0 ) {
4032
            C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber},
4033
                $amount, $type, output_pref($datedue) );
4034
        }
4035
        elsif ($return_date) {
4036
4037
            # Backdated returns may have fines that shouldn't exist,
4038
            # so in this case, we need to drop those fines to 0
4039
4040
            C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, 0, $type, output_pref($datedue) );
4041
        }
4042
    }
4043
}
4044
4028
__END__
4045
__END__
4029
4046
4030
=head1 AUTHOR
4047
=head1 AUTHOR
4031
- 

Return to bug 14390