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 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 $p = Koha::Patrons->find( $borrower->{borrowernumber} );
858
        my @guarantees = $p->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 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 498-503 foreach my $flag ( sort keys %$flags ) { Link Here
498
                charges_is_blocker => 1
498
                charges_is_blocker => 1
499
            );
499
            );
500
        }
500
        }
501
        elsif ( $flag eq 'CHARGES_GUARANTEES' ) {
502
            $template->param(
503
                charges_guarantees    => 'true',
504
                chargesmsg_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'message'},
505
                chargesamount_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'amount'},
506
                charges_guarantees_is_blocker => 1
507
            );
508
        }
501
        elsif ( $flag eq 'CREDITS' ) {
509
        elsif ( $flag eq 'CREDITS' ) {
502
            $template->param(
510
            $template->param(
503
                credits    => 'true',
511
                credits    => 'true',
Lines 514-519 foreach my $flag ( sort keys %$flags ) { Link Here
514
                chargesamount => $flags->{'CHARGES'}->{'amount'},
522
                chargesamount => $flags->{'CHARGES'}->{'amount'},
515
            );
523
            );
516
        }
524
        }
525
        elsif ( $flag eq 'CHARGES_GUARANTEES' ) {
526
            $template->param(
527
                charges_guarantees    => 'true',
528
                chargesmsg_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'message'},
529
                chargesamount_guarantees => $flags->{'CHARGES_GUARANTEES'}->{'amount'},
530
            );
531
        }
517
        elsif ( $flag eq 'CREDITS' ) {
532
        elsif ( $flag eq 'CREDITS' ) {
518
            $template->param(
533
            $template->param(
519
                credits    => 'true',
534
                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 242-247 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
242
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
242
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
243
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
243
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
244
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
244
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
245
('NoIssuesChargeGuarantees','','','Define maximum amount withstanding before check outs are blocked','Integer'),
245
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
246
('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'),
246
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
247
('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'),
247
('NorwegianPatronDBEnable','0',NULL,'Enable communication with the Norwegian national patron database.', 'YesNo'),
248
('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 234-239 $(document).ready(function() { Link Here
234
[% IF ( DEBT ) %]
234
[% IF ( DEBT ) %]
235
    <li>The patron has a debt of [% DEBT %].</li>
235
    <li>The patron has a debt of [% DEBT %].</li>
236
[% END %]
236
[% END %]
237
238
[% IF ( DEBT_GUARANTEES ) %]
239
    <li>The patron's guarantees collectively have a debt of [% DEBT_GUARANTEES %].</li>
240
[% END %]
241
237
[% IF ( RENTALCHARGE && RENTALCHARGE > 0 ) %]
242
[% IF ( RENTALCHARGE && RENTALCHARGE > 0 ) %]
238
    <li>Rental charge for this item: [% RENTALCHARGE %]</li>
243
    <li>Rental charge for this item: [% RENTALCHARGE %]</li>
239
[% END %]
244
[% END %]
Lines 783-803 No patron matched <span class="ex">[% message %]</span> Link Here
783
                [% 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
                [% 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>
784
            [% END %]
789
            [% END %]
785
790
786
        	[% IF ( charges ) %]
791
            [% IF ( charges ) %]
787
			    <li>
792
                <li>
788
            <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
                    <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>.
789
                [% IF ( charges_is_blocker ) %]
794
                        [% IF ( charges_is_blocker ) %]
790
                    <span class="circ-hlt">Checkouts are BLOCKED because fine balance is OVER THE LIMIT.</span>
795
                            <span class="circ-hlt">Checkouts are BLOCKED because fine balance is OVER THE LIMIT.</span>
791
                [% END %]
796
                        [% END %]
792
            <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]">Make payment</a> or
797
                    <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]">Make payment</a> or
793
            <a href="/cgi-bin/koha/members/paycollect.pl?borrowernumber=[% borrowernumber %]">Pay all fines</a></li>
798
                    <a href="/cgi-bin/koha/members/paycollect.pl?borrowernumber=[% borrowernumber %]">Pay all fines</a>
794
			[% END %]
799
                </li>
800
            [% END %]
795
801
796
        	[% IF ( credits ) %]
802
            [% IF ( charges_guarantees ) %]
797
			<li>
803
                <li>
798
                <span class="circ-hlt">Credits:</span> Patron has a credit[% IF ( creditsamount ) %] of [% creditsamount %][% END %]
804
                    <span class="circ-hlt">Fees &amp; Charges:</span> Patron's guarantees collectively owe [% chargesamount_guarantees %].
799
            </li>
805
                        [% IF ( charges_guarantees_is_blocker ) %]
800
			[% END %]
806
                            <span class="circ-hlt">Checkouts are BLOCKED because fine balance is OVER THE LIMIT.</span>
807
                        [% END %]
808
                </li>
809
            [% END %]
810
811
812
            [% IF ( credits ) %]
813
                <li>
814
                    <span class="circ-hlt">Credits:</span> Patron has a credit[% IF ( creditsamount ) %] of [% creditsamount %][% END %]
815
                </li>
816
            [% END %]
801
817
802
			</ul>
818
			</ul>
803
        </div>
819
        </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