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

(-)a/C4/Circulation.pm (+25 lines)
Lines 55-60 use Koha::Libraries; Link Here
55
use Koha::Holds;
55
use Koha::Holds;
56
use Carp;
56
use Carp;
57
use List::MoreUtils qw( uniq );
57
use List::MoreUtils qw( uniq );
58
use Scalar::Util qw( looks_like_number );
58
use Date::Calc qw(
59
use Date::Calc qw(
59
  Today
60
  Today
60
  Today_and_Now
61
  Today_and_Now
Lines 845-853 sub CanBookBeIssued { Link Here
845
    # DEBTS
846
    # DEBTS
846
    my ($balance, $non_issue_charges, $other_charges) =
847
    my ($balance, $non_issue_charges, $other_charges) =
847
      C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
848
      C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
849
848
    my $amountlimit = C4::Context->preference("noissuescharge");
850
    my $amountlimit = C4::Context->preference("noissuescharge");
849
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
851
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
850
    my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
852
    my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
853
854
    # Check the debt of this patrons guarantees
855
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
856
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
857
    if ( defined $no_issues_charge_guarantees ) {
858
        my $p = Koha::Patrons->find( $borrower->{borrowernumber} );
859
        my @guarantees = $p->guarantees();
860
        my $guarantees_non_issues_charges;
861
        foreach my $g ( @guarantees ) {
862
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
863
            $guarantees_non_issues_charges += $n;
864
        }
865
866
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
867
            $issuingimpossible{DEBT_GUARANTEES} = sprintf( "%.2f", $guarantees_non_issues_charges );
868
        } elsif ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && $allowfineoverride) {
869
            $needsconfirmation{DEBT_GUARANTEES} = sprintf( "%.2f", $guarantees_non_issues_charges );
870
        } elsif ( $allfinesneedoverride && $guarantees_non_issues_charges > 0 && $guarantees_non_issues_charges <= $no_issues_charge_guarantees && !$inprocess ) {
871
            $needsconfirmation{DEBT_GUARANTEES} = sprintf( "%.2f", $guarantees_non_issues_charges );
872
        }
873
    }
874
851
    if ( C4::Context->preference("IssuingInProcess") ) {
875
    if ( C4::Context->preference("IssuingInProcess") ) {
852
        if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
876
        if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
853
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
877
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
Lines 866-871 sub CanBookBeIssued { Link Here
866
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
890
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
867
        }
891
        }
868
    }
892
    }
893
869
    if ($balance > 0 && $other_charges > 0) {
894
    if ($balance > 0 && $other_charges > 0) {
870
        $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
895
        $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
871
    }
896
    }
(-)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 326-331 sub patronflags { Link Here
326
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
327
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
327
        $flags{'CREDITS'} = \%flaginfo;
328
        $flags{'CREDITS'} = \%flaginfo;
328
    }
329
    }
330
331
    # Check the debt of the guarntees of this patron
332
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
333
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
334
    if ( defined $no_issues_charge_guarantees ) {
335
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
336
        my @guarantees = $p->guarantees();
337
        my $guarantees_non_issues_charges;
338
        foreach my $g ( @guarantees ) {
339
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
340
            $guarantees_non_issues_charges += $n;
341
        }
342
343
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
344
            my %flaginfo;
345
            $flaginfo{'message'} = sprintf 'patron guarantees owe %.02f', $guarantees_non_issues_charges;
346
            $flaginfo{'amount'}  = sprintf "%.02f", $guarantees_non_issues_charges;
347
            $flaginfo{'noissues'} = 1 unless C4::Context->preference("allowfineoverride");
348
            $flags{'CHARGES_GUARANTEES'} = \%flaginfo;
349
        }
350
    }
351
329
    if (   $patroninformation->{'gonenoaddress'}
352
    if (   $patroninformation->{'gonenoaddress'}
330
        && $patroninformation->{'gonenoaddress'} == 1 )
353
        && $patroninformation->{'gonenoaddress'} == 1 )
331
    {
354
    {
(-)a/Koha/Patron.pm (-1 / +2 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::Patrons;
25
use Koha::Patron::Images;
26
use Koha::Patron::Images;
26
27
27
use base qw(Koha::Object);
28
use base qw(Koha::Object);
Lines 65-71 Returns the guarantees (list of Koha::Patron) of this patron Link Here
65
sub guarantees {
66
sub guarantees {
66
    my ( $self ) = @_;
67
    my ( $self ) = @_;
67
68
68
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
69
    return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
69
}
70
}
70
71
71
=head3 siblings
72
=head3 siblings
(-)a/circ/circulation.pl (+15 lines)
Lines 494-499 foreach my $flag ( sort keys %$flags ) { Link Here
494
                charges_is_blocker => 1
494
                charges_is_blocker => 1
495
            );
495
            );
496
        }
496
        }
497
        elsif ( $flag eq 'CHARGES_GUARANTEES' ) {
498
            $template->param(
499
                charges_guarantees    => 'true',
500
                chargesmsg_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'message'},
501
                chargesamount_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'amount'},
502
                charges_guarantees_is_blocker => 1
503
            );
504
        }
497
        elsif ( $flag eq 'CREDITS' ) {
505
        elsif ( $flag eq 'CREDITS' ) {
498
            $template->param(
506
            $template->param(
499
                credits    => 'true',
507
                credits    => 'true',
Lines 510-515 foreach my $flag ( sort keys %$flags ) { Link Here
510
                chargesamount => $flags->{'CHARGES'}->{'amount'},
518
                chargesamount => $flags->{'CHARGES'}->{'amount'},
511
            );
519
            );
512
        }
520
        }
521
        elsif ( $flag eq 'CHARGES_GUARANTEES' ) {
522
            $template->param(
523
                charges_guarantees    => 'true',
524
                chargesmsg_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'message'},
525
                chargesamount_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'amount'},
526
            );
527
        }
513
        elsif ( $flag eq 'CREDITS' ) {
528
        elsif ( $flag eq 'CREDITS' ) {
514
            $template->param(
529
            $template->param(
515
                credits    => 'true',
530
                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 235-240 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
235
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
235
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
236
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
236
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
237
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
237
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
238
('NoIssuesChargeGuarantees','','','Define maximum amount withstanding before check outs are blocked','Integer'),
238
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
239
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
239
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
240
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
240
('NorwegianPatronDBEnable','0',NULL,'Enable communication with the Norwegian national patron database.', 'YesNo'),
241
('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/Circulation/NoIssuesChargeGuarantees.t (+67 lines)
Line 0 Link Here
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;
(-)a/t/db_dependent/Patron.t (-2 / +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::Patron->new(
48
    {
49
        categorycode => $categorycode,
50
        branchcode   => $branchcode,
51
        guarantorid  => $object->id
52
    }
53
)->store();
54
my $guarantee2 = Koha::Patron->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
50
- 

Return to bug 14577