Lines 2901-2906
sub consent {
Link Here
|
2901 |
: Koha::Patron::Consent->new( { borrowernumber => $self->borrowernumber, type => $type } ); |
2901 |
: Koha::Patron::Consent->new( { borrowernumber => $self->borrowernumber, type => $type } ); |
2902 |
} |
2902 |
} |
2903 |
|
2903 |
|
|
|
2904 |
|
2905 |
=head3 can_borrow |
2906 |
|
2907 |
my $patron_borrowing_status = $patron->can_borrow( { patron => $patron } ); |
2908 |
|
2909 |
This method determines whether a borrower is able to borrow based on various parameters. |
2910 |
- Debarrments |
2911 |
- Expiry |
2912 |
- Charges |
2913 |
|
2914 |
If any blockers are found, these are returned in a hash |
2915 |
|
2916 |
=cut |
2917 |
|
2918 |
sub can_borrow { |
2919 |
my ( $self, $args ) = @_; |
2920 |
|
2921 |
my $patron = $args->{patron}; |
2922 |
my $status = { can_borrow => 1 }; |
2923 |
|
2924 |
$status->{debarred} = 1 if $patron->debarred; |
2925 |
$status->{expired} = 1 if $patron->is_expired; |
2926 |
$status->{can_borrow} = 0 if $status->{debarred} || $status->{expired}; |
2927 |
|
2928 |
# Patron charges |
2929 |
my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2930 |
%$status = ( %$status, %$patron_charge_limits ); |
2931 |
$status->{can_borrow} = 0 |
2932 |
if $patron_charge_limits->{noissuescharge}->{overlimit} |
2933 |
|| $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} |
2934 |
|| $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}; |
2935 |
|
2936 |
return $status; |
2937 |
} |
2938 |
|
2939 |
=head3 is_patron_inside_charge_limits |
2940 |
|
2941 |
my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2942 |
|
2943 |
Checks the current account balance for a patron and any guarantors/guarantees and compares it with any charge limits in place |
2944 |
Takes into account patron category level charge limits in the first instance and defaults to global sysprefs if not set |
2945 |
|
2946 |
=cut |
2947 |
|
2948 |
sub is_patron_inside_charge_limits { |
2949 |
my ( $self, $args ) = @_; |
2950 |
|
2951 |
my $borrowernumber = $args->{borrowernumber}; |
2952 |
my $patron = $args->{patron} || Koha::Patrons->find( { borrowernumber => $borrowernumber } ); |
2953 |
my $patron_category = $patron->category; |
2954 |
my $patron_charge_limits = {}; |
2955 |
|
2956 |
my $no_issues_charge = $patron_category->noissuescharge || C4::Context->preference('noissuescharge') || 0; |
2957 |
my $no_issues_charge_guarantees = |
2958 |
$patron_category->noissueschargeguarantees || C4::Context->preference('NoIssuesChargeGuarantees') || 0; |
2959 |
my $no_issues_charge_guarantors_with_guarantees = |
2960 |
$patron_category->noissueschargeguarantorswithguarantees |
2961 |
|| C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees') |
2962 |
|| 0; |
2963 |
|
2964 |
my $non_issues_charges = $patron->account->non_issues_charges; |
2965 |
my $guarantees_non_issues_charges = 0; |
2966 |
my $guarantors_non_issues_charges = 0; |
2967 |
|
2968 |
# Check the debt of this patrons guarantees |
2969 |
if ( defined $no_issues_charge_guarantees ) { |
2970 |
my @guarantees = map { $_->guarantee } $patron->guarantee_relationships->as_list; |
2971 |
foreach my $g (@guarantees) { |
2972 |
$guarantees_non_issues_charges += $g->account->non_issues_charges; |
2973 |
} |
2974 |
} |
2975 |
|
2976 |
# Check the debt of this patrons guarantors *and* the guarantees of those guarantors |
2977 |
if ( defined $no_issues_charge_guarantors_with_guarantees ) { |
2978 |
$guarantors_non_issues_charges = $patron->relationships_debt( |
2979 |
{ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 1 } ); |
2980 |
} |
2981 |
|
2982 |
# Return hash for each charge limit - limit, charge, overlimit |
2983 |
$patron_charge_limits->{noissuescharge} = |
2984 |
{ limit => $no_issues_charge, charge => $non_issues_charges, overlimit => 0 }; |
2985 |
$patron_charge_limits->{noissuescharge}->{overlimit} = 1 |
2986 |
if $no_issues_charge && $non_issues_charges > $no_issues_charge; |
2987 |
|
2988 |
$patron_charge_limits->{NoIssuesChargeGuarantees} = |
2989 |
{ limit => $no_issues_charge_guarantees, charge => $guarantees_non_issues_charges, overlimit => 0 }; |
2990 |
$patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} = 1 |
2991 |
if $no_issues_charge_guarantees && $guarantees_non_issues_charges > $no_issues_charge_guarantees; |
2992 |
|
2993 |
$patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees} = { |
2994 |
limit => $no_issues_charge_guarantors_with_guarantees, charge => $guarantors_non_issues_charges, |
2995 |
overlimit => 0 |
2996 |
}; |
2997 |
$patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} = 1 |
2998 |
if $no_issues_charge_guarantors_with_guarantees |
2999 |
&& $guarantors_non_issues_charges > $no_issues_charge_guarantors_with_guarantees; |
3000 |
|
3001 |
return $patron_charge_limits; |
3002 |
} |
3003 |
|
2904 |
=head2 Internal methods |
3004 |
=head2 Internal methods |
2905 |
|
3005 |
|
2906 |
=head3 _type |
3006 |
=head3 _type |
2907 |
- |
|
|