|
Lines 1938-1990
sub AddReturn {
Link Here
|
| 1938 |
|
1938 |
|
| 1939 |
if ($borrowernumber) { |
1939 |
if ($borrowernumber) { |
| 1940 |
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |
1940 |
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |
| 1941 |
# we only need to calculate and change the fines if we want to do that on return |
1941 |
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); |
| 1942 |
# Should be on for hourly loans |
|
|
| 1943 |
my $control = C4::Context->preference('CircControl'); |
| 1944 |
my $control_branchcode = |
| 1945 |
( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch} |
| 1946 |
: ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} |
| 1947 |
: $issue->{branchcode}; |
| 1948 |
|
| 1949 |
my $date_returned = |
| 1950 |
$return_date ? dt_from_string($return_date) : $today; |
| 1951 |
|
| 1952 |
my ( $amount, $type, $unitcounttotal ) = |
| 1953 |
C4::Overdues::CalcFine( $item, $borrower->{categorycode}, |
| 1954 |
$control_branchcode, $datedue, $date_returned ); |
| 1955 |
|
| 1956 |
$type ||= q{}; |
| 1957 |
|
| 1958 |
if ( C4::Context->preference('finesMode') eq 'production' ) { |
| 1959 |
if ( $amount > 0 ) { |
| 1960 |
C4::Overdues::UpdateFine( |
| 1961 |
{ |
| 1962 |
issue_id => $issue->{issue_id}, |
| 1963 |
itemnumber => $issue->{itemnumber}, |
| 1964 |
borrowernumber => $issue->{borrowernumber}, |
| 1965 |
amount => $amount, |
| 1966 |
type => $type, |
| 1967 |
due => output_pref($datedue), |
| 1968 |
} |
| 1969 |
); |
| 1970 |
} |
| 1971 |
elsif ($return_date) { |
| 1972 |
|
| 1973 |
# Backdated returns may have fines that shouldn't exist, |
| 1974 |
# so in this case, we need to drop those fines to 0 |
| 1975 |
|
| 1976 |
C4::Overdues::UpdateFine( |
| 1977 |
{ |
| 1978 |
issue_id => $issue->{issue_id}, |
| 1979 |
itemnumber => $issue->{itemnumber}, |
| 1980 |
borrowernumber => $issue->{borrowernumber}, |
| 1981 |
amount => 0, |
| 1982 |
type => $type, |
| 1983 |
due => output_pref($datedue), |
| 1984 |
} |
| 1985 |
); |
| 1986 |
} |
| 1987 |
} |
| 1988 |
} |
1942 |
} |
| 1989 |
|
1943 |
|
| 1990 |
eval { |
1944 |
eval { |
|
Lines 2953-2962
sub AddRenewal {
Link Here
|
| 2953 |
my $dbh = C4::Context->dbh; |
2907 |
my $dbh = C4::Context->dbh; |
| 2954 |
|
2908 |
|
| 2955 |
# Find the issues record for this book |
2909 |
# Find the issues record for this book |
| 2956 |
my $sth = |
2910 |
my $issuedata = GetItemIssue($itemnumber); |
| 2957 |
$dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); |
|
|
| 2958 |
$sth->execute( $itemnumber ); |
| 2959 |
my $issuedata = $sth->fetchrow_hashref; |
| 2960 |
|
2911 |
|
| 2961 |
return unless ( $issuedata ); |
2912 |
return unless ( $issuedata ); |
| 2962 |
|
2913 |
|
|
Lines 2967-2978
sub AddRenewal {
Link Here
|
| 2967 |
return; |
2918 |
return; |
| 2968 |
} |
2919 |
} |
| 2969 |
|
2920 |
|
|
|
2921 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; |
| 2922 |
|
| 2923 |
if ( C4::Context->preference('CalculateFinesOnReturn') && $issuedata->{overdue} ) { |
| 2924 |
_CalculateAndUpdateFine( { issue => $issuedata, item => $item, borrower => $borrower } ); |
| 2925 |
} |
| 2926 |
_FixOverduesOnReturn( $borrowernumber, $itemnumber ); |
| 2927 |
|
| 2970 |
# If the due date wasn't specified, calculate it by adding the |
2928 |
# If the due date wasn't specified, calculate it by adding the |
| 2971 |
# book's loan length to today's date or the current due date |
2929 |
# book's loan length to today's date or the current due date |
| 2972 |
# based on the value of the RenewalPeriodBase syspref. |
2930 |
# based on the value of the RenewalPeriodBase syspref. |
| 2973 |
unless ($datedue) { |
2931 |
unless ($datedue) { |
| 2974 |
|
2932 |
|
| 2975 |
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; |
|
|
| 2976 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
2933 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
| 2977 |
|
2934 |
|
| 2978 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2935 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
|
Lines 2984-2990
sub AddRenewal {
Link Here
|
| 2984 |
# Update the issues record to have the new due date, and a new count |
2941 |
# Update the issues record to have the new due date, and a new count |
| 2985 |
# of how many times it has been renewed. |
2942 |
# of how many times it has been renewed. |
| 2986 |
my $renews = $issuedata->{'renewals'} + 1; |
2943 |
my $renews = $issuedata->{'renewals'} + 1; |
| 2987 |
$sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2944 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
| 2988 |
WHERE borrowernumber=? |
2945 |
WHERE borrowernumber=? |
| 2989 |
AND itemnumber=?" |
2946 |
AND itemnumber=?" |
| 2990 |
); |
2947 |
); |
|
Lines 3014-3036
sub AddRenewal {
Link Here
|
| 3014 |
} |
2971 |
} |
| 3015 |
|
2972 |
|
| 3016 |
# Send a renewal slip according to checkout alert preferencei |
2973 |
# Send a renewal slip according to checkout alert preferencei |
| 3017 |
if ( C4::Context->preference('RenewalSendNotice') eq '1') { |
2974 |
if ( C4::Context->preference('RenewalSendNotice') eq '1' ) { |
| 3018 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); |
2975 |
$borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); |
| 3019 |
my $circulation_alert = 'C4::ItemCirculationAlertPreference'; |
2976 |
my $circulation_alert = 'C4::ItemCirculationAlertPreference'; |
| 3020 |
my %conditions = ( |
2977 |
my %conditions = ( |
| 3021 |
branchcode => $branch, |
2978 |
branchcode => $branch, |
| 3022 |
categorycode => $borrower->{categorycode}, |
2979 |
categorycode => $borrower->{categorycode}, |
| 3023 |
item_type => $item->{itype}, |
2980 |
item_type => $item->{itype}, |
| 3024 |
notification => 'CHECKOUT', |
2981 |
notification => 'CHECKOUT', |
| 3025 |
); |
2982 |
); |
| 3026 |
if ($circulation_alert->is_enabled_for(\%conditions)) { |
2983 |
if ( $circulation_alert->is_enabled_for( \%conditions ) ) { |
| 3027 |
SendCirculationAlert({ |
2984 |
SendCirculationAlert( |
| 3028 |
type => 'RENEWAL', |
2985 |
{ |
| 3029 |
item => $item, |
2986 |
type => 'RENEWAL', |
| 3030 |
borrower => $borrower, |
2987 |
item => $item, |
| 3031 |
branch => $branch, |
2988 |
borrower => $borrower, |
| 3032 |
}); |
2989 |
branch => $branch, |
| 3033 |
} |
2990 |
} |
|
|
2991 |
); |
| 2992 |
} |
| 3034 |
} |
2993 |
} |
| 3035 |
|
2994 |
|
| 3036 |
# Remove any OVERDUES related debarment if the borrower has no overdues |
2995 |
# Remove any OVERDUES related debarment if the borrower has no overdues |
|
Lines 4096-4102
sub GetTopIssues {
Link Here
|
| 4096 |
return @$rows; |
4055 |
return @$rows; |
| 4097 |
} |
4056 |
} |
| 4098 |
|
4057 |
|
|
|
4058 |
sub _CalculateAndUpdateFine { |
| 4059 |
my ($params) = @_; |
| 4060 |
|
| 4061 |
my $borrower = $params->{borrower}; |
| 4062 |
my $item = $params->{item}; |
| 4063 |
my $issue = $params->{issue}; |
| 4064 |
my $return_date = $params->{return_date}; |
| 4065 |
|
| 4066 |
unless ($borrower) { carp "No borrower passed in!" && return; } |
| 4067 |
unless ($item) { carp "No item passed in!" && return; } |
| 4068 |
unless ($issue) { carp "No issue passed in!" && return; } |
| 4069 |
|
| 4070 |
my $datedue = $issue->{date_due}; |
| 4071 |
|
| 4072 |
# we only need to calculate and change the fines if we want to do that on return |
| 4073 |
# Should be on for hourly loans |
| 4074 |
my $control = C4::Context->preference('CircControl'); |
| 4075 |
my $control_branchcode = |
| 4076 |
( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch} |
| 4077 |
: ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} |
| 4078 |
: $issue->{branchcode}; |
| 4079 |
|
| 4080 |
my $date_returned = $return_date ? dt_from_string($return_date) : dt_from_string(); |
| 4081 |
|
| 4082 |
my ( $amount, $type, $unitcounttotal ) = |
| 4083 |
C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned ); |
| 4084 |
|
| 4085 |
$type ||= q{}; |
| 4086 |
|
| 4087 |
if ( C4::Context->preference('finesMode') eq 'production' ) { |
| 4088 |
if ( $amount > 0 ) { |
| 4089 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, |
| 4090 |
$amount, $type, output_pref($datedue) ); |
| 4091 |
} |
| 4092 |
elsif ($return_date) { |
| 4093 |
|
| 4094 |
# Backdated returns may have fines that shouldn't exist, |
| 4095 |
# so in this case, we need to drop those fines to 0 |
| 4096 |
|
| 4097 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, 0, $type, output_pref($datedue) ); |
| 4098 |
} |
| 4099 |
} |
| 4100 |
} |
| 4101 |
|
| 4099 |
1; |
4102 |
1; |
|
|
4103 |
|
| 4100 |
__END__ |
4104 |
__END__ |
| 4101 |
|
4105 |
|
| 4102 |
=head1 AUTHOR |
4106 |
=head1 AUTHOR |
|
Lines 4104-4107
__END__
Link Here
|
| 4104 |
Koha Development Team <http://koha-community.org/> |
4108 |
Koha Development Team <http://koha-community.org/> |
| 4105 |
|
4109 |
|
| 4106 |
=cut |
4110 |
=cut |
| 4107 |
|
|
|
| 4108 |
- |