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