|
Lines 2782-2787
sub CanBookBeRenewed {
Link Here
|
| 2782 |
'no_auto_renewal_after_hard_limit', |
2782 |
'no_auto_renewal_after_hard_limit', |
| 2783 |
'lengthunit', |
2783 |
'lengthunit', |
| 2784 |
'norenewalbefore', |
2784 |
'norenewalbefore', |
|
|
2785 |
'unseen_renewals_allowed' |
| 2785 |
] |
2786 |
] |
| 2786 |
} |
2787 |
} |
| 2787 |
); |
2788 |
); |
|
Lines 2789-2794
sub CanBookBeRenewed {
Link Here
|
| 2789 |
return ( 0, "too_many" ) |
2790 |
return ( 0, "too_many" ) |
| 2790 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
2791 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
| 2791 |
|
2792 |
|
|
|
2793 |
return ( 0, "too_unseen" ) |
| 2794 |
if C4::Context->preference('UnseenRenewals') && |
| 2795 |
$issuing_rule->{unseen_renewals_allowed} && |
| 2796 |
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; |
| 2797 |
|
| 2792 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
2798 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2793 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
2799 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2794 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
2800 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
|
Lines 2879-2885
sub CanBookBeRenewed {
Link Here
|
| 2879 |
|
2885 |
|
| 2880 |
=head2 AddRenewal |
2886 |
=head2 AddRenewal |
| 2881 |
|
2887 |
|
| 2882 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
2888 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
| 2883 |
|
2889 |
|
| 2884 |
Renews a loan. |
2890 |
Renews a loan. |
| 2885 |
|
2891 |
|
|
Lines 2899-2904
this parameter is not supplied, lastreneweddate is set to the current date.
Link Here
|
| 2899 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
2905 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
| 2900 |
from the book's item type. |
2906 |
from the book's item type. |
| 2901 |
|
2907 |
|
|
|
2908 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
| 2909 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
| 2910 |
fallback to a true value |
| 2911 |
|
| 2902 |
=cut |
2912 |
=cut |
| 2903 |
|
2913 |
|
| 2904 |
sub AddRenewal { |
2914 |
sub AddRenewal { |
|
Lines 2907-2912
sub AddRenewal {
Link Here
|
| 2907 |
my $branch = shift; |
2917 |
my $branch = shift; |
| 2908 |
my $datedue = shift; |
2918 |
my $datedue = shift; |
| 2909 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); |
2919 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); |
|
|
2920 |
my $seen = shift; |
| 2921 |
|
| 2922 |
# Fallback on a 'seen' renewal |
| 2923 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
| 2910 |
|
2924 |
|
| 2911 |
my $item_object = Koha::Items->find($itemnumber) or return; |
2925 |
my $item_object = Koha::Items->find($itemnumber) or return; |
| 2912 |
my $biblio = $item_object->biblio; |
2926 |
my $biblio = $item_object->biblio; |
|
Lines 2959-2973
sub AddRenewal {
Link Here
|
| 2959 |
} |
2973 |
} |
| 2960 |
); |
2974 |
); |
| 2961 |
|
2975 |
|
|
|
2976 |
# Increment the unseen renewals, if appropriate |
| 2977 |
# We only do so if the syspref is enabled and |
| 2978 |
# a maximum value has been set in the circ rules |
| 2979 |
my $unseen_renewals = $issue->unseen_renewals; |
| 2980 |
if (C4::Context->preference('UnseenRenewals')) { |
| 2981 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 2982 |
{ categorycode => $patron->categorycode, |
| 2983 |
itemtype => $item_object->effective_itemtype, |
| 2984 |
branchcode => $circ_library->branchcode, |
| 2985 |
rule_name => 'unseen_renewals_allowed' |
| 2986 |
} |
| 2987 |
); |
| 2988 |
if (!$seen && $rule && $rule->rule_value) { |
| 2989 |
$unseen_renewals++; |
| 2990 |
} else { |
| 2991 |
# If the renewal is seen, unseen should revert to 0 |
| 2992 |
$unseen_renewals = 0; |
| 2993 |
} |
| 2994 |
} |
| 2995 |
|
| 2962 |
# Update the issues record to have the new due date, and a new count |
2996 |
# Update the issues record to have the new due date, and a new count |
| 2963 |
# of how many times it has been renewed. |
2997 |
# of how many times it has been renewed. |
| 2964 |
my $renews = ( $issue->renewals || 0 ) + 1; |
2998 |
my $renews = ( $issue->renewals || 0 ) + 1; |
| 2965 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2999 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
| 2966 |
WHERE borrowernumber=? |
3000 |
WHERE borrowernumber=? |
| 2967 |
AND itemnumber=?" |
3001 |
AND itemnumber=?" |
| 2968 |
); |
3002 |
); |
| 2969 |
|
3003 |
|
| 2970 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3004 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
| 2971 |
|
3005 |
|
| 2972 |
# Update the renewal count on the item, and tell zebra to reindex |
3006 |
# Update the renewal count on the item, and tell zebra to reindex |
| 2973 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3007 |
$renews = ( $item_object->renewals || 0 ) + 1; |
|
Lines 3049-3056
sub GetRenewCount {
Link Here
|
| 3049 |
my ( $bornum, $itemno ) = @_; |
3083 |
my ( $bornum, $itemno ) = @_; |
| 3050 |
my $dbh = C4::Context->dbh; |
3084 |
my $dbh = C4::Context->dbh; |
| 3051 |
my $renewcount = 0; |
3085 |
my $renewcount = 0; |
|
|
3086 |
my $unseencount = 0; |
| 3052 |
my $renewsallowed = 0; |
3087 |
my $renewsallowed = 0; |
|
|
3088 |
my $unseenallowed = 0; |
| 3053 |
my $renewsleft = 0; |
3089 |
my $renewsleft = 0; |
|
|
3090 |
my $unseenleft = 0; |
| 3054 |
|
3091 |
|
| 3055 |
my $patron = Koha::Patrons->find( $bornum ); |
3092 |
my $patron = Koha::Patrons->find( $bornum ); |
| 3056 |
my $item = Koha::Items->find($itemno); |
3093 |
my $item = Koha::Items->find($itemno); |
|
Lines 3069-3090
sub GetRenewCount {
Link Here
|
| 3069 |
$sth->execute( $bornum, $itemno ); |
3106 |
$sth->execute( $bornum, $itemno ); |
| 3070 |
my $data = $sth->fetchrow_hashref; |
3107 |
my $data = $sth->fetchrow_hashref; |
| 3071 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3108 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3109 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
| 3072 |
# $item and $borrower should be calculated |
3110 |
# $item and $borrower should be calculated |
| 3073 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3111 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
| 3074 |
|
3112 |
|
| 3075 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3113 |
my $rules = Koha::CirculationRules->get_effective_rules( |
| 3076 |
{ |
3114 |
{ |
| 3077 |
categorycode => $patron->categorycode, |
3115 |
categorycode => $patron->categorycode, |
| 3078 |
itemtype => $item->effective_itemtype, |
3116 |
itemtype => $item->effective_itemtype, |
| 3079 |
branchcode => $branchcode, |
3117 |
branchcode => $branchcode, |
| 3080 |
rule_name => 'renewalsallowed', |
3118 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
| 3081 |
} |
3119 |
} |
| 3082 |
); |
3120 |
); |
| 3083 |
|
3121 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
| 3084 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3122 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3123 |
$rules->{unseen_renewals_allowed} : |
| 3124 |
0; |
| 3085 |
$renewsleft = $renewsallowed - $renewcount; |
3125 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3126 |
$unseenleft = $unseenallowed - $unseencount; |
| 3086 |
if($renewsleft < 0){ $renewsleft = 0; } |
3127 |
if($renewsleft < 0){ $renewsleft = 0; } |
| 3087 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3128 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3129 |
return ( |
| 3130 |
$renewcount, |
| 3131 |
$renewsallowed, |
| 3132 |
$renewsleft, |
| 3133 |
$unseencount, |
| 3134 |
$unseenallowed, |
| 3135 |
$unseenleft |
| 3136 |
); |
| 3088 |
} |
3137 |
} |
| 3089 |
|
3138 |
|
| 3090 |
=head2 GetSoonestRenewDate |
3139 |
=head2 GetSoonestRenewDate |