Bug 28924: Update all usages of the current sysprefs

This patch updates all instances where the current noissuescharge sysprefs are used. They will now use the is_patron_inside_charge_limits method to handle the patron category level limits

Sponsored-by: Cuyahoga County Public Library <https://cuyahogalibrary.org/>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2024-01-22 15:55:19 +00:00 committed by Katrin Fischer
parent 37057ade8b
commit ddaa75ecd4
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
5 changed files with 96 additions and 106 deletions

View file

@ -819,8 +819,8 @@ sub CanBookBeIssued {
#
# BORROWER STATUS
#
if ( $patron->category->category_type eq 'X' && ( $item_object->barcode ) ) {
my $patron_borrowing_status = $patron->can_borrow({ patron => $patron });
if ( $patron->category->category_type eq 'X' && ( $item_object->barcode )) {
# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 .
C4::Stats::UpdateStats(
{
@ -865,63 +865,72 @@ sub CanBookBeIssued {
my $non_issues_charges = $account->non_issues_charges;
my $other_charges = $balance - $non_issues_charges;
my $amountlimit = C4::Context->preference("noissuescharge");
my $allowfineoverride = C4::Context->preference("AllowFineOverride");
my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
# Check the debt of this patrons guarantees
my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
$no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
my $no_issues_charge_guarantees = $patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit};
$no_issues_charge_guarantees = undef unless looks_like_number($no_issues_charge_guarantees);
if ( defined $no_issues_charge_guarantees ) {
my @guarantees = map { $_->guarantee } $patron->guarantee_relationships->as_list;
my $guarantees_non_issues_charges = 0;
foreach my $g ( @guarantees ) {
$guarantees_non_issues_charges += $g->account->non_issues_charges;
}
if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
$issuingimpossible{DEBT_GUARANTEES} = $guarantees_non_issues_charges;
} elsif ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && $allowfineoverride) {
$needsconfirmation{DEBT_GUARANTEES} = $guarantees_non_issues_charges;
} elsif ( $allfinesneedoverride && $guarantees_non_issues_charges > 0 && $guarantees_non_issues_charges <= $no_issues_charge_guarantees && !$inprocess ) {
$needsconfirmation{DEBT_GUARANTEES} = $guarantees_non_issues_charges;
if ( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit} && !$inprocess && !$allowfineoverride ) {
$issuingimpossible{DEBT_GUARANTEES} = $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge};
} elsif ( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}
&& !$inprocess
&& $allowfineoverride )
{
$needsconfirmation{DEBT_GUARANTEES} = $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge};
} elsif ( $allfinesneedoverride
&& $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge} > 0
&& !$inprocess )
{
$needsconfirmation{DEBT_GUARANTEES} = $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge};
}
}
# Check the debt of this patrons guarantors *and* the guarantees of those guarantors
my $no_issues_charge_guarantors = C4::Context->preference("NoIssuesChargeGuarantorsWithGuarantees");
$no_issues_charge_guarantors = undef unless looks_like_number( $no_issues_charge_guarantors );
my $no_issues_charge_guarantors = $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit};
$no_issues_charge_guarantors = undef unless looks_like_number($no_issues_charge_guarantors);
if ( defined $no_issues_charge_guarantors ) {
my $guarantors_non_issues_charges = $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 1 });
if ( $guarantors_non_issues_charges > $no_issues_charge_guarantors && !$inprocess && !$allowfineoverride) {
$issuingimpossible{DEBT_GUARANTORS} = $guarantors_non_issues_charges;
} elsif ( $guarantors_non_issues_charges > $no_issues_charge_guarantors && !$inprocess && $allowfineoverride) {
$needsconfirmation{DEBT_GUARANTORS} = $guarantors_non_issues_charges;
} elsif ( $allfinesneedoverride && $guarantors_non_issues_charges > 0 && $guarantors_non_issues_charges <= $no_issues_charge_guarantors && !$inprocess ) {
$needsconfirmation{DEBT_GUARANTORS} = $guarantors_non_issues_charges;
if ( $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}
&& !$inprocess
&& !$allowfineoverride )
{
$issuingimpossible{DEBT_GUARANTORS} =
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge};
} elsif ( $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}
&& !$inprocess
&& $allowfineoverride )
{
$needsconfirmation{DEBT_GUARANTORS} =
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge};
} elsif ( $allfinesneedoverride
&& $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge} > 0
&& !$inprocess )
{
$needsconfirmation{DEBT_GUARANTORS} =
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge};
}
}
if ( C4::Context->preference("IssuingInProcess") ) {
if ( $non_issues_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
$issuingimpossible{DEBT} = $non_issues_charges;
} elsif ( $non_issues_charges > $amountlimit && !$inprocess && $allowfineoverride) {
$needsconfirmation{DEBT} = $non_issues_charges;
} elsif ( $allfinesneedoverride && $non_issues_charges > 0 && $non_issues_charges <= $amountlimit && !$inprocess ) {
$needsconfirmation{DEBT} = $non_issues_charges;
}
}
else {
if ( $non_issues_charges > $amountlimit && $allowfineoverride ) {
$needsconfirmation{DEBT} = $non_issues_charges;
} elsif ( $non_issues_charges > $amountlimit && !$allowfineoverride) {
$issuingimpossible{DEBT} = $non_issues_charges;
} elsif ( $non_issues_charges > 0 && $allfinesneedoverride ) {
$needsconfirmation{DEBT} = $non_issues_charges;
if ( $patron_borrowing_status->{noissuescharge}->{overlimit} && !$inprocess && !$allowfineoverride ) {
$issuingimpossible{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge};
} elsif ( $patron_borrowing_status->{noissuescharge}->{overlimit} && !$inprocess && $allowfineoverride ) {
$needsconfirmation{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge};
} elsif ( $allfinesneedoverride && $patron_borrowing_status->{noissuescharge}->{charge} > 0 && !$inprocess ) {
$needsconfirmation{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge};
}
} else {
if ( $patron_borrowing_status->{noissuescharge}->{overlimit} && $allowfineoverride ) {
$needsconfirmation{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge};
} elsif ( $patron_borrowing_status->{noissuescharge}->{overlimit} && !$allowfineoverride ) {
$issuingimpossible{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge};
} elsif ( $patron_borrowing_status->{noissuescharge}->{charge} > 0 && $allfinesneedoverride ) {
$needsconfirmation{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge};
}
}
if ($balance > 0 && $other_charges > 0) {
$alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
}

View file

@ -135,13 +135,13 @@ sub patronflags {
my $dbh=C4::Context->dbh;
my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
my $account = $patron->account;
my $owing = $account->non_issues_charges;
if ( $owing > 0 ) {
my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } );
if ( $patron_charge_limits->{noissuescharge}->{charge} > 0 ) {
my %flaginfo;
my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
$flaginfo{'message'} = sprintf 'Patron owes %.02f', $owing;
$flaginfo{'amount'} = sprintf "%.02f", $owing;
if ( $owing > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
my $noissuescharge = $patron_charge_limits->{noissuescharge}->{limit} || 5;
$flaginfo{'message'} = sprintf 'Patron owes %.02f', $patron_charge_limits->{noissuescharge}->{charge};
$flaginfo{'amount'} = sprintf "%.02f", $patron_charge_limits->{noissuescharge}->{charge};
if ( $patron_charge_limits->{noissuescharge}->{overlimit} && !C4::Context->preference("AllowFineOverride") ) {
$flaginfo{'noissues'} = 1;
}
$flags{'CHARGES'} = \%flaginfo;
@ -153,21 +153,14 @@ sub patronflags {
$flags{'CREDITS'} = \%flaginfo;
}
# Check the debt of the guarntees of this patron
my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
$no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
# Check the debt of this patrons guarantees
my $no_issues_charge_guarantees = $patron_charge_limits->{NoIssuesChargeGuarantees}->{limit};
$no_issues_charge_guarantees = undef unless looks_like_number($no_issues_charge_guarantees);
if ( defined $no_issues_charge_guarantees ) {
my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
my @guarantees = map { $_->guarantee } $p->guarantee_relationships->as_list;
my $guarantees_non_issues_charges = 0;
foreach my $g ( @guarantees ) {
$guarantees_non_issues_charges += $g->account->non_issues_charges;
}
if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
if ( $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} ) {
my %flaginfo;
$flaginfo{'message'} = sprintf 'patron guarantees owe %.02f', $guarantees_non_issues_charges;
$flaginfo{'amount'} = $guarantees_non_issues_charges;
$flaginfo{'message'} = sprintf 'patron guarantees owe %.02f', $patron_charge_limits->{NoIssuesChargeGuarantees}->{charge};
$flaginfo{'amount'} = $patron_charge_limits->{NoIssuesChargeGuarantees}->{charge};
$flaginfo{'noissues'} = 1 unless C4::Context->preference("allowfineoverride");
$flags{'CHARGES_GUARANTEES'} = \%flaginfo;
}

View file

@ -99,24 +99,25 @@ sub new {
$dexpiry and $dexpiry =~ s/-//g; # YYYYMMDD
# Get fines and add fines for guarantees (depends on preference NoIssuesChargeGuarantees)
my $fines_amount = ($patron->account->balance > 0) ? $patron->account->non_issues_charges : 0;
my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } );
my $fines_amount = $patron_charge_limits->{noissuescharge}->{charge};
my $personal_fines_amount = $fines_amount;
my $fee_limit = _fee_limit();
my $noissueschargeguarantorswithguarantees = C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees');
my $fee_limit = $patron_charge_limits->{noissuescharge}->{limit} || 5;
my $noissueschargeguarantorswithguarantees = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{limit};
my $noissueschargeguarantees = $patron_charge_limits->{NoIssuesChargeGuarantees}->{limit};
my $fines_msg = "";
my $fine_blocked = 0;
my $noissueschargeguarantees = C4::Context->preference('NoIssuesChargeGuarantees');
if( $fines_amount > $fee_limit ){
if( $patron_charge_limits->{noissuescharge}->{overlimit} ){
$fine_blocked = 1;
$fines_msg .= " -- " . "Patron blocked by fines" if $fine_blocked;
} elsif ( $noissueschargeguarantorswithguarantees ) {
$fines_amount += $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 0 });
$fine_blocked ||= $fines_amount > $noissueschargeguarantorswithguarantees;
$fines_amount = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{charge};
$fine_blocked = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit};
$fines_msg .= " -- " . "Patron blocked by fines ($fines_amount) on related accounts" if $fine_blocked;
} elsif ( $noissueschargeguarantees ) {
if( $patron->guarantee_relationships->count ){
$fines_amount += $patron->relationships_debt({ include_guarantors => 0, only_this_guarantor => 1, include_this_patron => 0 });
$fine_blocked ||= $fines_amount > $noissueschargeguarantees;
$fines_amount += $patron_charge_limits->{NoIssuesChargeGuarantees}->{charge};
$fine_blocked = $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit};
$fines_msg .= " -- " . "Patron blocked by fines ($fines_amount) on guaranteed accounts" if $fine_blocked;
}
}
@ -499,10 +500,6 @@ sub inet_privileges {
return $self->{inet} ? 'Y' : 'N';
}
sub _fee_limit {
return C4::Context->preference('noissuescharge') || 5;
}
sub excessive_fees {
my $self = shift;
return ($self->fee_amount and $self->fee_amount > $self->fee_limit);

View file

@ -594,13 +594,13 @@ if ( $patron ) {
$template->param( is_anonymous => 1 );
$noissues = 1;
}
my $account = $patron->account;
if( ( my $owing = $account->non_issues_charges ) > 0 ) {
my $noissuescharge = C4::Context->preference("noissuescharge") || 5; # FIXME If noissuescharge == 0 then 5, why??
$noissues ||= ( not C4::Context->preference("AllowFineOverride") and ( $owing > $noissuescharge ) );
my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } );
if( $patron_charge_limits->{noissuescharge}->{charge} > 0 ) {
my $noissuescharge = $patron_charge_limits->{noissuescharge}->{limit} || 5; # FIXME If noissuescharge == 0 then 5, why??
$noissues ||= ( not C4::Context->preference("AllowFineOverride") and $patron_charge_limits->{noissuescharge}->{overlimit} );
$template->param(
charges => 1,
chargesamount => $owing,
chargesamount => $patron_charge_limits->{noissuescharge}->{charge},
)
} elsif ( $balance < 0 ) {
$template->param(
@ -610,30 +610,24 @@ if ( $patron ) {
}
# Check the debt of this patrons guarantors *and* the guarantees of those guarantors
my $no_issues_charge_guarantors = C4::Context->preference("NoIssuesChargeGuarantorsWithGuarantees");
if ( $no_issues_charge_guarantors ) {
my $guarantors_non_issues_charges = $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 1 });
if ( $guarantors_non_issues_charges > $no_issues_charge_guarantors ) {
my $no_issues_charge_guarantors = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{limit};
if ($no_issues_charge_guarantors) {
if ( $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} ) {
$template->param(
charges_guarantors_guarantees => $guarantors_non_issues_charges
noissues => 1,
charges_guarantors_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}
);
$noissues = 1 unless C4::Context->preference("allowfineoverride");
}
}
my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
my $no_issues_charge_guarantees = $patron_charge_limits->{NoIssuesChargeGuarantees}->{limit};
$no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
if ( defined $no_issues_charge_guarantees ) {
my $guarantees_non_issues_charges = 0;
my $guarantees = $patron->guarantee_relationships->guarantees;
while ( my $g = $guarantees->next ) {
$guarantees_non_issues_charges += $g->account->non_issues_charges;
}
if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
if ( $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} ) {
$template->param(
charges_guarantees => 1,
chargesamount_guarantees => $guarantees_non_issues_charges,
chargesamount_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantees}->{charge},
);
$noissues = 1 unless C4::Context->preference("allowfineoverride");
}

View file

@ -242,13 +242,12 @@ my $issues = $patron->checkouts;
my $balance = 0;
$balance = $patron->account->balance;
my $account = $patron->account;
if( ( my $owing = $account->non_issues_charges ) > 0 ) {
my $noissuescharge = C4::Context->preference("noissuescharge") || 5; # FIXME If noissuescharge == 0 then 5, why??
my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } );
if ( $patron_charge_limits->{noissuescharge}->{charge} > 0 ) {
$template->param(
charges => 1,
chargesamount => $owing,
)
chargesamount => $patron_charge_limits->{noissuescharge}->{charge},
);
} elsif ( $balance < 0 ) {
$template->param(
credits => 1,
@ -257,14 +256,12 @@ if( ( my $owing = $account->non_issues_charges ) > 0 ) {
}
# Check the debt of this patrons guarantors *and* the guarantees of those guarantors
my $no_issues_charge_guarantors = C4::Context->preference("NoIssuesChargeGuarantorsWithGuarantees");
my $no_issues_charge_guarantors = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{limit};
if ( $no_issues_charge_guarantors ) {
my $guarantors_non_issues_charges = $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 1 });
if ( $guarantors_non_issues_charges > $no_issues_charge_guarantors ) {
if ( $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} ) {
$template->param(
noissues => 1,
charges_guarantors_guarantees => $guarantors_non_issues_charges
charges_guarantors_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}
);
}
}