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

View file

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

View file

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

View file

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

View file

@ -242,13 +242,12 @@ my $issues = $patron->checkouts;
my $balance = 0; my $balance = 0;
$balance = $patron->account->balance; $balance = $patron->account->balance;
my $account = $patron->account; my $patron_charge_limits = $patron->is_patron_inside_charge_limits( { patron => $patron } );
if( ( my $owing = $account->non_issues_charges ) > 0 ) { if ( $patron_charge_limits->{noissuescharge}->{charge} > 0 ) {
my $noissuescharge = C4::Context->preference("noissuescharge") || 5; # FIXME If noissuescharge == 0 then 5, why??
$template->param( $template->param(
charges => 1, charges => 1,
chargesamount => $owing, chargesamount => $patron_charge_limits->{noissuescharge}->{charge},
) );
} elsif ( $balance < 0 ) { } elsif ( $balance < 0 ) {
$template->param( $template->param(
credits => 1, 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 # 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 ) { 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 ( $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} ) {
if ( $guarantors_non_issues_charges > $no_issues_charge_guarantors ) {
$template->param( $template->param(
noissues => 1, noissues => 1,
charges_guarantors_guarantees => $guarantors_non_issues_charges charges_guarantors_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}
); );
} }
} }