$dexpiry and $dexpiry =~ s/-//g; # YYYYMMDD
# Get fines and add fines for guarantees (depends on preference NoIssuesChargeGuarantees)
- my $fines_amount = $flags->{CHARGES}->{amount}; #TODO Replace with $patron->account->non_issues_charges
- $fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0;
- if ( C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees') ) {
+ my $fines_amount = ($patron->account->balance > 0) ? $patron->account->non_issues_charges : 0;
+ my $fee_limit = _fee_limit();
+ my $fine_blocked = $fines_amount > $fee_limit;
+ my $noissueschargeguarantorswithguarantees = C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees');
+ my $noissueschargeguarantees = C4::Context->preference('NoIssuesChargeGuarantees');
+ if ( $noissueschargeguarantorswithguarantees ) {
$fines_amount += $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 0 });
- } else {
- my $guarantees_fines_amount = $flags->{CHARGES_GUARANTEES} ? $flags->{CHARGES_GUARANTEES}->{amount} : 0; #TODO: Replace with $patron->relationships_debt
- $fines_amount += $guarantees_fines_amount;
+ $fine_blocked ||= $fines_amount > $noissueschargeguarantorswithguarantees;
+ } elsif ( $noissueschargeguarantees ) {
+ $fines_amount += $patron->relationships_debt({ include_guarantors => 0, only_this_guarantor => 0, include_this_patron => 0 });
+ $fine_blocked ||= $fines_amount > $noissueschargeguarantees;
}
- my $fee_limit = _fee_limit();
- my $fine_blocked = $fines_amount > $fee_limit;
my $circ_blocked =( C4::Context->preference('OverduesBlockCirc') ne "noblock" && defined $flags->{ODUES}->{itemlist} ) ? 1 : 0;
{
no warnings; # any of these $kp->{fields} being concat'd could be undef
# This needs to be extended! Your help is appreciated..
use Modern::Perl;
-use Test::More tests => 9;
+use Test::More tests => 10;
use t::lib::Mocks;
use t::lib::TestBuilder;
$schema->storage->txn_rollback;
+subtest "NoIssuesChargeGuarantees tests" => sub {
+
+ plan tests => 4;
+
+ t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
+
+ $schema->storage->txn_begin;
+
+ my $patron = $builder->build_object({ class => 'Koha::Patrons' });
+ my $child = $builder->build_object({ class => 'Koha::Patrons' });
+ $child->add_guarantor({ guarantor_id => $patron->borrowernumber, relationship => 'parent' });
+
+ t::lib::Mocks::mock_preference('NoIssuesChargeGuarantees', 1);
+
+ my $fee1 = $builder->build_object(
+ {
+ class => 'Koha::Account::Lines',
+ value => {
+ borrowernumber => $patron->borrowernumber,
+ amountoutstanding => 11,
+ }
+ }
+ )->store;
+
+ my $fee2 = $builder->build_object(
+ {
+ class => 'Koha::Account::Lines',
+ value => {
+ borrowernumber => $child->borrowernumber,
+ amountoutstanding => 0.11,
+ }
+ }
+ )->store;
+
+ my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
+
+ is( $sip_patron->fines_amount, 11.11,"Guarantor fines correctly included");
+ ok( !$sip_patron->charge_ok, "Guarantor blocked");
+
+ $sip_patron = C4::SIP::ILS::Patron->new( $child->cardnumber );
+
+ is( $sip_patron->fines_amount, 0.11,"Guarantee only fines correctly counted");
+ ok( $sip_patron->charge_ok, "Guarantee not blocked by guarantor fines");
+
+ $schema->storage->txn_rollback;
+};
+
subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub {
- plan tests => 1;
+ plan tests => 4;
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
is( $sip_patron->fines_amount, 11.11,"Guarantee fines correctly included");
+ ok( !$sip_patron->charge_ok, "Guarantor blocked");
+
+ $sip_patron = C4::SIP::ILS::Patron->new( $child->cardnumber );
+
+ is( $sip_patron->fines_amount, 11.11,"Guarantor fines correctly included");
+ ok( !$sip_patron->charge_ok, "Guarantee blocked");
$schema->storage->txn_rollback;
};