View | Details | Raw Unified | Return to bug 14577
Collapse All | Expand All

(-)a/C4/Circulation.pm (+25 lines)
Lines 54-59 use Koha::Database; Link Here
54
use Koha::Libraries;
54
use Koha::Libraries;
55
use Carp;
55
use Carp;
56
use List::MoreUtils qw( uniq );
56
use List::MoreUtils qw( uniq );
57
use Scalar::Util qw( looks_like_number );
57
use Date::Calc qw(
58
use Date::Calc qw(
58
  Today
59
  Today
59
  Today_and_Now
60
  Today_and_Now
Lines 844-852 sub CanBookBeIssued { Link Here
844
    # DEBTS
845
    # DEBTS
845
    my ($balance, $non_issue_charges, $other_charges) =
846
    my ($balance, $non_issue_charges, $other_charges) =
846
      C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
847
      C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
848
847
    my $amountlimit = C4::Context->preference("noissuescharge");
849
    my $amountlimit = C4::Context->preference("noissuescharge");
848
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
850
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
849
    my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
851
    my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
852
853
    # Check the debt of this patrons guarantees
854
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
855
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
856
    if ( defined $no_issues_charge_guarantees ) {
857
        my $b = Koha::Borrowers->find( $borrower->{borrowernumber} );
858
        my @guarantees = $b->guarantees();
859
        my $guarantees_non_issues_charges;
860
        foreach my $g ( @guarantees ) {
861
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
862
            $guarantees_non_issues_charges += $n;
863
        }
864
865
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
866
            $issuingimpossible{DEBT_GUARANTEES} = sprintf( "%.2f", $guarantees_non_issues_charges );
867
        } elsif ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && $allowfineoverride) {
868
            $needsconfirmation{DEBT_GUARANTEES} = sprintf( "%.2f", $guarantees_non_issues_charges );
869
        } elsif ( $allfinesneedoverride && $guarantees_non_issues_charges > 0 && $guarantees_non_issues_charges <= $no_issues_charge_guarantees && !$inprocess ) {
870
            $needsconfirmation{DEBT_GUARANTEES} = sprintf( "%.2f", $guarantees_non_issues_charges );
871
        }
872
    }
873
850
    if ( C4::Context->preference("IssuingInProcess") ) {
874
    if ( C4::Context->preference("IssuingInProcess") ) {
851
        if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
875
        if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
852
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
876
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
Lines 865-870 sub CanBookBeIssued { Link Here
865
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
889
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
866
        }
890
        }
867
    }
891
    }
892
868
    if ($balance > 0 && $other_charges > 0) {
893
    if ($balance > 0 && $other_charges > 0) {
869
        $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
894
        $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
870
    }
895
    }
(-)a/C4/Members.pm (+23 lines)
Lines 24-29 use strict; Link Here
24
#use warnings; FIXME - Bug 2505
24
#use warnings; FIXME - Bug 2505
25
use C4::Context;
25
use C4::Context;
26
use String::Random qw( random_string );
26
use String::Random qw( random_string );
27
use Scalar::Util qw( looks_like_number );
27
use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/;
28
use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/;
28
use C4::Log; # logaction
29
use C4::Log; # logaction
29
use C4::Overdues;
30
use C4::Overdues;
Lines 337-342 sub patronflags { Link Here
337
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
338
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
338
        $flags{'CREDITS'} = \%flaginfo;
339
        $flags{'CREDITS'} = \%flaginfo;
339
    }
340
    }
341
342
    # Check the debt of the guarntees of this patron
343
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
344
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
345
    if ( defined $no_issues_charge_guarantees ) {
346
        my $b = Koha::Borrowers->find( $patroninformation->{borrowernumber} );
347
        my @guarantees = $b->guarantees();
348
        my $guarantees_non_issues_charges;
349
        foreach my $g ( @guarantees ) {
350
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
351
            $guarantees_non_issues_charges += $n;
352
        }
353
354
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
355
            my %flaginfo;
356
            $flaginfo{'message'} = sprintf 'patron guarantees owe %.02f', $guarantees_non_issues_charges;
357
            $flaginfo{'amount'}  = sprintf "%.02f", $guarantees_non_issues_charges;
358
            $flaginfo{'noissues'} = 1 unless C4::Context->preference("allowfineoverride");
359
            $flags{'CHARGES_GUARANTEES'} = \%flaginfo;
360
        }
361
    }
362
340
    if (   $patroninformation->{'gonenoaddress'}
363
    if (   $patroninformation->{'gonenoaddress'}
341
        && $patroninformation->{'gonenoaddress'} == 1 )
364
        && $patroninformation->{'gonenoaddress'} == 1 )
342
    {
365
    {
(-)a/Koha/Borrower.pm (+7 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Borrowers;
25
26
26
use base qw(Koha::Object);
27
use base qw(Koha::Object);
27
28
Lines 47-52 sub guarantor { Link Here
47
    return Koha::Borrowers->find( $self->guarantorid() );
48
    return Koha::Borrowers->find( $self->guarantorid() );
48
}
49
}
49
50
51
sub guarantees {
52
    my ( $self ) = @_;
53
54
    return Koha::Borrowers->search( { guarantorid => $self->id } );
55
}
56
50
=head3 type
57
=head3 type
51
58
52
=cut
59
=cut
(-)a/circ/circulation.pl (+15 lines)
Lines 491-496 foreach my $flag ( sort keys %$flags ) { Link Here
491
                charges_is_blocker => 1
491
                charges_is_blocker => 1
492
            );
492
            );
493
        }
493
        }
494
        elsif ( $flag eq 'CHARGES_GUARANTEES' ) {
495
            $template->param(
496
                charges_guarantees    => 'true',
497
                chargesmsg_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'message'},
498
                chargesamount_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'amount'},
499
                charges_guarantees_is_blocker => 1
500
            );
501
        }
494
        elsif ( $flag eq 'CREDITS' ) {
502
        elsif ( $flag eq 'CREDITS' ) {
495
            $template->param(
503
            $template->param(
496
                credits    => 'true',
504
                credits    => 'true',
Lines 507-512 foreach my $flag ( sort keys %$flags ) { Link Here
507
                chargesamount => $flags->{'CHARGES'}->{'amount'},
515
                chargesamount => $flags->{'CHARGES'}->{'amount'},
508
            );
516
            );
509
        }
517
        }
518
        elsif ( $flag eq 'CHARGES_GUARANTEES' ) {
519
            $template->param(
520
                charges_guarantees    => 'true',
521
                chargesmsg_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'message'},
522
                chargesamount_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'amount'},
523
            );
524
        }
510
        elsif ( $flag eq 'CREDITS' ) {
525
        elsif ( $flag eq 'CREDITS' ) {
511
            $template->param(
526
            $template->param(
512
                credits    => 'true',
527
                credits    => 'true',
(-)a/installer/data/mysql/atomicupdate/bug_14577.sql (+2 lines)
Line 0 Link Here
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
2
('NoIssuesChargeGuarantees','','','Define maximum amount withstanding before check outs are blocked','Integer');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 232-237 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
232
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
232
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
233
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
233
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
234
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
234
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
235
('NoIssuesChargeGuarantees','','','Define maximum amount withstanding before check outs are blocked','Integer'),
235
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
236
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
236
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
237
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
237
('NorwegianPatronDBEnable','0',NULL,'Enable communication with the Norwegian national patron database.', 'YesNo'),
238
('NorwegianPatronDBEnable','0',NULL,'Enable communication with the Norwegian national patron database.', 'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+5 lines)
Lines 304-309 Circulation: Link Here
304
              class: integer
304
              class: integer
305
            - '[% local_currency %] in fines.'
305
            - '[% local_currency %] in fines.'
306
        -
306
        -
307
            - Prevent a patron from checking out if the patron has guarantees owing in total more than
308
            - pref: NoIssuesChargeGuarantees
309
              class: integer
310
            - '[% local_currency %] in fines.'
311
        -
307
            - pref: RentalsInNoissuesCharge
312
            - pref: RentalsInNoissuesCharge
308
              choices:
313
              choices:
309
                  yes: Include
314
                  yes: Include
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-14 / +30 lines)
Lines 229-234 $(document).ready(function() { Link Here
229
[% IF ( DEBT ) %]
229
[% IF ( DEBT ) %]
230
    <li>The patron has a debt of [% DEBT %].</li>
230
    <li>The patron has a debt of [% DEBT %].</li>
231
[% END %]
231
[% END %]
232
233
[% IF ( DEBT_GUARANTEES ) %]
234
    <li>The patron's guarantees collectively have a debt of [% DEBT_GUARANTEES %].</li>
235
[% END %]
236
232
[% IF ( RENTALCHARGE && RENTALCHARGE > 0 ) %]
237
[% IF ( RENTALCHARGE && RENTALCHARGE > 0 ) %]
233
    <li>Rental charge for this item: [% RENTALCHARGE %]</li>
238
    <li>Rental charge for this item: [% RENTALCHARGE %]</li>
234
[% END %]
239
[% END %]
Lines 787-807 No patron matched <span class="ex">[% message %]</span> Link Here
787
                [% IF ( odues ) %]<li>[% IF ( nonreturns ) %]<span class="circ-hlt">Overdues: Patron has ITEMS OVERDUE</span>. See highlighted items <a href="#checkouts">below</a>[% END %]</li>
792
                [% IF ( odues ) %]<li>[% IF ( nonreturns ) %]<span class="circ-hlt">Overdues: Patron has ITEMS OVERDUE</span>. See highlighted items <a href="#checkouts">below</a>[% END %]</li>
788
            [% END %]
793
            [% END %]
789
794
790
        	[% IF ( charges ) %]
795
            [% IF ( charges ) %]
791
			    <li>
796
                <li>
792
            <span class="circ-hlt">Fees &amp; Charges:</span> Patron has  <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Outstanding fees &amp; charges[% IF ( chargesamount ) %] of [% chargesamount %][% END %]</a>.
797
                    <span class="circ-hlt">Fees &amp; Charges:</span> Patron has  <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Outstanding fees &amp; charges[% IF ( chargesamount ) %] of [% chargesamount %][% END %]</a>.
793
                [% IF ( charges_is_blocker ) %]
798
                        [% IF ( charges_is_blocker ) %]
794
                    <span class="circ-hlt">Checkouts are BLOCKED because fine balance is OVER THE LIMIT.</span>
799
                            <span class="circ-hlt">Checkouts are BLOCKED because fine balance is OVER THE LIMIT.</span>
795
                [% END %]
800
                        [% END %]
796
            <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]">Make payment</a> or
801
                    <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]">Make payment</a> or
797
            <a href="/cgi-bin/koha/members/paycollect.pl?borrowernumber=[% borrowernumber %]">Pay all fines</a></li>
802
                    <a href="/cgi-bin/koha/members/paycollect.pl?borrowernumber=[% borrowernumber %]">Pay all fines</a>
798
			[% END %]
803
                </li>
804
            [% END %]
799
805
800
        	[% IF ( credits ) %]
806
            [% IF ( charges_guarantees ) %]
801
			<li>
807
                <li>
802
                <span class="circ-hlt">Credits:</span> Patron has a credit[% IF ( creditsamount ) %] of [% creditsamount %][% END %]
808
                    <span class="circ-hlt">Fees &amp; Charges:</span> Patron's guarantees collectively owe [% chargesamount_guarantees %].
803
            </li>
809
                        [% IF ( charges_guarantees_is_blocker ) %]
804
			[% END %]
810
                            <span class="circ-hlt">Checkouts are BLOCKED because fine balance is OVER THE LIMIT.</span>
811
                        [% END %]
812
                </li>
813
            [% END %]
814
815
816
            [% IF ( credits ) %]
817
                <li>
818
                    <span class="circ-hlt">Credits:</span> Patron has a credit[% IF ( creditsamount ) %] of [% creditsamount %][% END %]
819
                </li>
820
            [% END %]
805
821
806
			</ul>
822
			</ul>
807
        </div>
823
        </div>
(-)a/t/db_dependent/Borrower.t (-1 / +18 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 13;
20
use Test::More tests => 15;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Context;
23
use C4::Context;
Lines 44-49 $object->surname("Test Surname"); Link Here
44
$object->store();
44
$object->store();
45
45
46
is( $object->in_storage, 1, "Object is now stored" );
46
is( $object->in_storage, 1, "Object is now stored" );
47
my $guarantee1 = Koha::Borrower->new(
48
    {
49
        categorycode => $categorycode,
50
        branchcode   => $branchcode,
51
        guarantorid  => $object->id
52
    }
53
)->store();
54
my $guarantee2 = Koha::Borrower->new(
55
    {
56
        categorycode => $categorycode,
57
        branchcode   => $branchcode,
58
        guarantorid  => $object->id
59
    }
60
)->store();
61
my @guarantees = $object->guarantees();
62
is( $guarantees[0]->id, $guarantee1->id, "First guarantee matchs" );
63
is( $guarantees[1]->id, $guarantee2->id, "Second guarantee matchs" );
47
64
48
my $borrowernumber = $object->borrowernumber;
65
my $borrowernumber = $object->borrowernumber;
49
66
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
22
use t::lib::TestBuilder;
23
24
use C4::Accounts qw( manualinvoice );
25
use C4::Circulation qw( CanBookBeIssued );
26
27
my $schema = Koha::Database->new->schema;
28
$schema->storage->txn_begin;
29
30
my $builder = t::lib::TestBuilder->new();
31
32
my $item = $builder->build(
33
    {
34
        source => 'Item',
35
        value  => {
36
            notforloan => 0,
37
            withdrawn  => 0
38
        }
39
    }
40
);
41
42
my $patron = $builder->build(
43
    {
44
        source => 'Borrower',
45
    }
46
);
47
my $guarantee = $builder->build(
48
    {
49
        source => 'Borrower',
50
        value  => {
51
            guarantorid => $patron->{borrowernumber},
52
        }
53
    }
54
);
55
56
C4::Context->set_preference( 'NoIssuesChargeGuarantees', '5.00' );
57
58
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
59
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
60
61
manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
62
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
63
is( $issuingimpossible->{DEBT_GUARANTEES}, '10.00', "Patron cannot check out item due to debt for guarantee" );
64
65
$schema->storage->txn_rollback;
66
67
1;

Return to bug 14577