Lines 2864-2977
sub AddRenewal {
Link Here
|
2864 |
|
2864 |
|
2865 |
my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) ); |
2865 |
my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) ); |
2866 |
|
2866 |
|
2867 |
if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { |
2867 |
my $schema = Koha::Database->new->schema; |
2868 |
_CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } ); |
2868 |
$schema->txn_do(sub{ |
2869 |
} |
|
|
2870 |
_FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' ); |
2871 |
|
2872 |
# If the due date wasn't specified, calculate it by adding the |
2873 |
# book's loan length to today's date or the current due date |
2874 |
# based on the value of the RenewalPeriodBase syspref. |
2875 |
my $itemtype = $item_object->effective_itemtype; |
2876 |
unless ($datedue) { |
2877 |
|
2878 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2879 |
dt_from_string( $issue->date_due, 'sql' ) : |
2880 |
DateTime->now( time_zone => C4::Context->tz()); |
2881 |
$datedue = CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal'); |
2882 |
} |
2883 |
|
2869 |
|
2884 |
my $fees = Koha::Charges::Fees->new( |
2870 |
if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { |
2885 |
{ |
2871 |
_CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } ); |
2886 |
patron => $patron, |
2872 |
} |
2887 |
library => $circ_library, |
2873 |
_FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' ); |
2888 |
item => $item_object, |
2874 |
|
2889 |
from_date => dt_from_string( $issue->date_due, 'sql' ), |
2875 |
# If the due date wasn't specified, calculate it by adding the |
2890 |
to_date => dt_from_string($datedue), |
2876 |
# book's loan length to today's date or the current due date |
|
|
2877 |
# based on the value of the RenewalPeriodBase syspref. |
2878 |
my $itemtype = $item_object->effective_itemtype; |
2879 |
unless ($datedue) { |
2880 |
|
2881 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2882 |
dt_from_string( $issue->date_due, 'sql' ) : |
2883 |
DateTime->now( time_zone => C4::Context->tz()); |
2884 |
$datedue = CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal'); |
2891 |
} |
2885 |
} |
2892 |
); |
|
|
2893 |
|
2886 |
|
2894 |
# Update the issues record to have the new due date, and a new count |
2887 |
my $fees = Koha::Charges::Fees->new( |
2895 |
# of how many times it has been renewed. |
2888 |
{ |
2896 |
my $renews = $issue->renewals + 1; |
2889 |
patron => $patron, |
2897 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2890 |
library => $circ_library, |
2898 |
WHERE borrowernumber=? |
2891 |
item => $item_object, |
2899 |
AND itemnumber=?" |
2892 |
from_date => dt_from_string( $issue->date_due, 'sql' ), |
2900 |
); |
2893 |
to_date => dt_from_string($datedue), |
|
|
2894 |
} |
2895 |
); |
2901 |
|
2896 |
|
2902 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
2897 |
# Update the issues record to have the new due date, and a new count |
|
|
2898 |
# of how many times it has been renewed. |
2899 |
my $renews = $issue->renewals + 1; |
2900 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2901 |
WHERE borrowernumber=? |
2902 |
AND itemnumber=?" |
2903 |
); |
2903 |
|
2904 |
|
2904 |
# Update the renewal count on the item, and tell zebra to reindex |
2905 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
2905 |
$renews = $item_object->renewals + 1; |
|
|
2906 |
ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item_object->biblionumber, $itemnumber, { log_action => 0 } ); |
2907 |
|
2906 |
|
2908 |
# Charge a new rental fee, if applicable |
2907 |
# Update the renewal count on the item, and tell zebra to reindex |
2909 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2908 |
$renews = $item_object->renewals + 1; |
2910 |
if ( $charge > 0 ) { |
2909 |
ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item_object->biblionumber, $itemnumber, { log_action => 0 } ); |
2911 |
AddIssuingCharge($issue, $charge, 'rent_renew'); |
|
|
2912 |
} |
2913 |
|
2910 |
|
2914 |
# Charge a new accumulate rental fee, if applicable |
2911 |
# Charge a new rental fee, if applicable |
2915 |
my $itemtype_object = Koha::ItemTypes->find( $itemtype ); |
2912 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2916 |
if ( $itemtype_object ) { |
2913 |
if ( $charge > 0 ) { |
2917 |
my $accumulate_charge = $fees->accumulate_rentalcharge(); |
2914 |
AddIssuingCharge($issue, $charge, 'rent_renew'); |
2918 |
if ( $accumulate_charge > 0 ) { |
|
|
2919 |
AddIssuingCharge( $issue, $accumulate_charge, 'rent_daily_renew' ) |
2920 |
} |
2915 |
} |
2921 |
$charge += $accumulate_charge; |
|
|
2922 |
} |
2923 |
|
2916 |
|
2924 |
# Send a renewal slip according to checkout alert preferencei |
2917 |
# Charge a new accumulate rental fee, if applicable |
2925 |
if ( C4::Context->preference('RenewalSendNotice') eq '1' ) { |
2918 |
my $itemtype_object = Koha::ItemTypes->find( $itemtype ); |
2926 |
my $circulation_alert = 'C4::ItemCirculationAlertPreference'; |
2919 |
if ( $itemtype_object ) { |
2927 |
my %conditions = ( |
2920 |
my $accumulate_charge = $fees->accumulate_rentalcharge(); |
2928 |
branchcode => $branch, |
2921 |
if ( $accumulate_charge > 0 ) { |
2929 |
categorycode => $patron->categorycode, |
2922 |
AddIssuingCharge( $issue, $accumulate_charge, 'rent_daily_renew' ) |
2930 |
item_type => $itemtype, |
2923 |
} |
2931 |
notification => 'CHECKOUT', |
2924 |
$charge += $accumulate_charge; |
2932 |
); |
|
|
2933 |
if ( $circulation_alert->is_enabled_for( \%conditions ) ) { |
2934 |
SendCirculationAlert( |
2935 |
{ |
2936 |
type => 'RENEWAL', |
2937 |
item => $item_unblessed, |
2938 |
borrower => $patron->unblessed, |
2939 |
branch => $branch, |
2940 |
} |
2941 |
); |
2942 |
} |
2925 |
} |
2943 |
} |
|
|
2944 |
|
2926 |
|
2945 |
# Remove any OVERDUES related debarment if the borrower has no overdues |
2927 |
# Send a renewal slip according to checkout alert preferencei |
2946 |
if ( $patron |
2928 |
if ( C4::Context->preference('RenewalSendNotice') eq '1' ) { |
2947 |
&& $patron->is_debarred |
2929 |
my $circulation_alert = 'C4::ItemCirculationAlertPreference'; |
2948 |
&& ! $patron->has_overdues |
2930 |
my %conditions = ( |
2949 |
&& @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } |
2931 |
branchcode => $branch, |
2950 |
) { |
2932 |
categorycode => $patron->categorycode, |
2951 |
DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); |
2933 |
item_type => $itemtype, |
2952 |
} |
2934 |
notification => 'CHECKOUT', |
|
|
2935 |
); |
2936 |
if ( $circulation_alert->is_enabled_for( \%conditions ) ) { |
2937 |
SendCirculationAlert( |
2938 |
{ |
2939 |
type => 'RENEWAL', |
2940 |
item => $item_unblessed, |
2941 |
borrower => $patron->unblessed, |
2942 |
branch => $branch, |
2943 |
} |
2944 |
); |
2945 |
} |
2946 |
} |
2953 |
|
2947 |
|
2954 |
unless ( C4::Context->interface eq 'opac' ) { #if from opac we are obeying OpacRenewalBranch as calculated in opac-renew.pl |
2948 |
# Remove any OVERDUES related debarment if the borrower has no overdues |
2955 |
$branch = C4::Context->userenv ? C4::Context->userenv->{branch} : $branch; |
2949 |
if ( $patron |
2956 |
} |
2950 |
&& $patron->is_debarred |
|
|
2951 |
&& ! $patron->has_overdues |
2952 |
&& @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } |
2953 |
) { |
2954 |
DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); |
2955 |
} |
2957 |
|
2956 |
|
2958 |
# Add the renewal to stats |
2957 |
unless ( C4::Context->interface eq 'opac' ) { #if from opac we are obeying OpacRenewalBranch as calculated in opac-renew.pl |
2959 |
UpdateStats( |
2958 |
$branch = C4::Context->userenv ? C4::Context->userenv->{branch} : $branch; |
2960 |
{ |
|
|
2961 |
branch => $branch, |
2962 |
type => 'renew', |
2963 |
amount => $charge, |
2964 |
itemnumber => $itemnumber, |
2965 |
itemtype => $itemtype, |
2966 |
location => $item_object->location, |
2967 |
borrowernumber => $borrowernumber, |
2968 |
ccode => $item_object->ccode, |
2969 |
} |
2959 |
} |
2970 |
); |
|
|
2971 |
|
2960 |
|
2972 |
#Log the renewal |
2961 |
# Add the renewal to stats |
2973 |
logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog"); |
2962 |
UpdateStats( |
2974 |
return $datedue; |
2963 |
{ |
|
|
2964 |
branch => $branch, |
2965 |
type => 'renew', |
2966 |
amount => $charge, |
2967 |
itemnumber => $itemnumber, |
2968 |
itemtype => $itemtype, |
2969 |
location => $item_object->location, |
2970 |
borrowernumber => $borrowernumber, |
2971 |
ccode => $item_object->ccode, |
2972 |
} |
2973 |
); |
2974 |
|
2975 |
#Log the renewal |
2976 |
logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog"); |
2977 |
}); |
2978 |
return $datedue; |
2975 |
} |
2979 |
} |
2976 |
|
2980 |
|
2977 |
sub GetRenewCount { |
2981 |
sub GetRenewCount { |
2978 |
- |
|
|