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 2873-2882 sub AddRenewal { Link Here
2873
    my $dbh = C4::Context->dbh;
2841
    my $dbh = C4::Context->dbh;
2874
2842
2875
    # Find the issues record for this book
2843
    # Find the issues record for this book
2876
    my $sth =
2844
    my $issuedata  = GetItemIssue($itemnumber);
2877
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2878
    $sth->execute( $itemnumber );
2879
    my $issuedata = $sth->fetchrow_hashref;
2880
2845
2881
    return unless ( $issuedata );
2846
    return unless ( $issuedata );
2882
2847
Lines 2887-2898 sub AddRenewal { Link Here
2887
        return;
2852
        return;
2888
    }
2853
    }
2889
2854
2855
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
2856
2857
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issuedata->{overdue} ) {
2858
        _CalculateAndUpdateFine( { issue => $issuedata, item => $item, borrower => $borrower } );
2859
    }
2860
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2861
2890
    # If the due date wasn't specified, calculate it by adding the
2862
    # If the due date wasn't specified, calculate it by adding the
2891
    # book's loan length to today's date or the current due date
2863
    # book's loan length to today's date or the current due date
2892
    # based on the value of the RenewalPeriodBase syspref.
2864
    # based on the value of the RenewalPeriodBase syspref.
2893
    unless ($datedue) {
2865
    unless ($datedue) {
2894
2866
2895
        my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
2896
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2867
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2897
2868
2898
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2869
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
Lines 2904-2910 sub AddRenewal { Link Here
2904
    # Update the issues record to have the new due date, and a new count
2875
    # Update the issues record to have the new due date, and a new count
2905
    # of how many times it has been renewed.
2876
    # of how many times it has been renewed.
2906
    my $renews = $issuedata->{'renewals'} + 1;
2877
    my $renews = $issuedata->{'renewals'} + 1;
2907
    $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2878
    my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2908
                            WHERE borrowernumber=? 
2879
                            WHERE borrowernumber=? 
2909
                            AND itemnumber=?"
2880
                            AND itemnumber=?"
2910
    );
2881
    );
Lines 2934-2956 sub AddRenewal { Link Here
2934
    }
2905
    }
2935
2906
2936
    # Send a renewal slip according to checkout alert preferencei
2907
    # Send a renewal slip according to checkout alert preferencei
2937
    if ( C4::Context->preference('RenewalSendNotice') eq '1') {
2908
    if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
2938
	my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 );
2909
        $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 );
2939
	my $circulation_alert = 'C4::ItemCirculationAlertPreference';
2910
        my $circulation_alert = 'C4::ItemCirculationAlertPreference';
2940
	my %conditions = (
2911
        my %conditions        = (
2941
		branchcode   => $branch,
2912
            branchcode   => $branch,
2942
		categorycode => $borrower->{categorycode},
2913
            categorycode => $borrower->{categorycode},
2943
		item_type    => $item->{itype},
2914
            item_type    => $item->{itype},
2944
		notification => 'CHECKOUT',
2915
            notification => 'CHECKOUT',
2945
	);
2916
        );
2946
	if ($circulation_alert->is_enabled_for(\%conditions)) {
2917
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2947
		SendCirculationAlert({
2918
            SendCirculationAlert(
2948
			type     => 'RENEWAL',
2919
                {
2949
			item     => $item,
2920
                    type     => 'RENEWAL',
2950
		borrower => $borrower,
2921
                    item     => $item,
2951
		branch   => $branch,
2922
                    borrower => $borrower,
2952
		});
2923
                    branch   => $branch,
2953
	}
2924
                }
2925
            );
2926
        }
2954
    }
2927
    }
2955
2928
2956
    # Remove any OVERDUES related debarment if the borrower has no overdues
2929
    # Remove any OVERDUES related debarment if the borrower has no overdues
Lines 4095-4100 sub GetTopIssues { Link Here
4095
    return @$rows;
4068
    return @$rows;
4096
}
4069
}
4097
4070
4071
sub _CalculateAndUpdateFine {
4072
    my ($params) = @_;
4073
4074
    my $borrower    = $params->{borrower};
4075
    my $item        = $params->{item};
4076
    my $issue       = $params->{issue};
4077
    my $return_date = $params->{return_date};
4078
4079
    unless ($borrower) { carp "No borrower passed in!" && return; }
4080
    unless ($item)     { carp "No item passed in!"     && return; }
4081
    unless ($issue)    { carp "No issue passed in!"    && return; }
4082
4083
    my $datedue = $issue->{date_due};
4084
4085
    # we only need to calculate and change the fines if we want to do that on return
4086
    # Should be on for hourly loans
4087
    my $control = C4::Context->preference('CircControl');
4088
    my $control_branchcode =
4089
        ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch}
4090
      : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
4091
      :                                     $issue->{branchcode};
4092
4093
    my $date_returned = $return_date ? dt_from_string($return_date) : dt_from_string();
4094
4095
    my ( $amount, $type, $unitcounttotal ) =
4096
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4097
4098
    $type ||= q{};
4099
4100
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4101
        if ( $amount > 0 ) {
4102
            C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber},
4103
                $amount, $type, output_pref($datedue) );
4104
        }
4105
        elsif ($return_date) {
4106
4107
            # Backdated returns may have fines that shouldn't exist,
4108
            # so in this case, we need to drop those fines to 0
4109
4110
            C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, 0, $type, output_pref($datedue) );
4111
        }
4112
    }
4113
}
4114
4098
__END__
4115
__END__
4099
4116
4100
=head1 AUTHOR
4117
=head1 AUTHOR
4101
- 

Return to bug 14390