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

(-)a/C4/Circulation.pm (-16 / +17 lines)
Lines 753-760 sub CanBookBeIssued { Link Here
753
    #
753
    #
754
754
755
    # DEBTS
755
    # DEBTS
756
    my ($balance, $non_issue_charges, $other_charges) =
756
    my $account = $patron->account;
757
      C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
757
    my $balance = $account->balance;
758
    my $non_issues_charges = $account->non_issues_charges;
759
    my $other_charges = $balance - $non_issues_charges;
758
760
759
    my $amountlimit = C4::Context->preference("noissuescharge");
761
    my $amountlimit = C4::Context->preference("noissuescharge");
760
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
762
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
Lines 767-774 sub CanBookBeIssued { Link Here
767
        my @guarantees = $patron->guarantees();
769
        my @guarantees = $patron->guarantees();
768
        my $guarantees_non_issues_charges;
770
        my $guarantees_non_issues_charges;
769
        foreach my $g ( @guarantees ) {
771
        foreach my $g ( @guarantees ) {
770
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
772
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
771
            $guarantees_non_issues_charges += $n;
772
        }
773
        }
773
774
774
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
775
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
Lines 781-801 sub CanBookBeIssued { Link Here
781
    }
782
    }
782
783
783
    if ( C4::Context->preference("IssuingInProcess") ) {
784
    if ( C4::Context->preference("IssuingInProcess") ) {
784
        if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
785
        if ( $non_issues_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
785
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
786
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issues_charges );
786
        } elsif ( $non_issue_charges > $amountlimit && !$inprocess && $allowfineoverride) {
787
        } elsif ( $non_issues_charges > $amountlimit && !$inprocess && $allowfineoverride) {
787
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
788
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
788
        } elsif ( $allfinesneedoverride && $non_issue_charges > 0 && $non_issue_charges <= $amountlimit && !$inprocess ) {
789
        } elsif ( $allfinesneedoverride && $non_issues_charges > 0 && $non_issues_charges <= $amountlimit && !$inprocess ) {
789
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
790
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
790
        }
791
        }
791
    }
792
    }
792
    else {
793
    else {
793
        if ( $non_issue_charges > $amountlimit && $allowfineoverride ) {
794
        if ( $non_issues_charges > $amountlimit && $allowfineoverride ) {
794
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
795
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
795
        } elsif ( $non_issue_charges > $amountlimit && !$allowfineoverride) {
796
        } elsif ( $non_issues_charges > $amountlimit && !$allowfineoverride) {
796
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
797
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issues_charges );
797
        } elsif ( $non_issue_charges > 0 && $allfinesneedoverride ) {
798
        } elsif ( $non_issues_charges > 0 && $allfinesneedoverride ) {
798
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
799
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
799
        }
800
        }
800
    }
801
    }
801
802
(-)a/C4/Members.pm (-45 / +5 lines)
Lines 176-182 sub patronflags { Link Here
176
    my %flags;
176
    my %flags;
177
    my ( $patroninformation) = @_;
177
    my ( $patroninformation) = @_;
178
    my $dbh=C4::Context->dbh;
178
    my $dbh=C4::Context->dbh;
179
    my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'});
179
    my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
180
    my $account = $patron->account;
181
    my $owing = $account->non_issues_charges;
180
    if ( $owing > 0 ) {
182
    if ( $owing > 0 ) {
181
        my %flaginfo;
183
        my %flaginfo;
182
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
184
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
Lines 187-193 sub patronflags { Link Here
187
        }
189
        }
188
        $flags{'CHARGES'} = \%flaginfo;
190
        $flags{'CHARGES'} = \%flaginfo;
189
    }
191
    }
190
    elsif ( $balance < 0 ) {
192
    elsif ( ( my $balance = $account->balance ) < 0 ) {
191
        my %flaginfo;
193
        my %flaginfo;
192
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
194
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
193
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
195
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
Lines 202-209 sub patronflags { Link Here
202
        my @guarantees = $p->guarantees();
204
        my @guarantees = $p->guarantees();
203
        my $guarantees_non_issues_charges;
205
        my $guarantees_non_issues_charges;
204
        foreach my $g ( @guarantees ) {
206
        foreach my $g ( @guarantees ) {
205
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
207
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
206
            $guarantees_non_issues_charges += $n;
207
        }
208
        }
208
209
209
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
210
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
Lines 260-266 sub patronflags { Link Here
260
        $flags{'ODUES'} = \%flaginfo;
261
        $flags{'ODUES'} = \%flaginfo;
261
    }
262
    }
262
263
263
    my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
264
    my $waiting_holds = $patron->holds->search({ found => 'W' });
264
    my $waiting_holds = $patron->holds->search({ found => 'W' });
265
    my $nowaiting = $waiting_holds->count;
265
    my $nowaiting = $waiting_holds->count;
266
    if ( $nowaiting > 0 ) {
266
    if ( $nowaiting > 0 ) {
Lines 734-779 sub GetAllIssues { Link Here
734
    return $sth->fetchall_arrayref( {} );
734
    return $sth->fetchall_arrayref( {} );
735
}
735
}
736
736
737
738
=head2 GetMemberAccountBalance
739
740
  ($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber);
741
742
Calculates amount immediately owing by the patron - non-issue charges.
743
Based on GetMemberAccountRecords.
744
Charges exempt from non-issue are:
745
* Res (reserves)
746
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false
747
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
748
749
=cut
750
751
sub GetMemberAccountBalance {
752
    my ($borrowernumber) = @_;
753
754
    # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5
755
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
756
757
    my @not_fines;
758
    push @not_fines, 'Res' unless C4::Context->preference('HoldsInNoissuesCharge');
759
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
760
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
761
        my $dbh = C4::Context->dbh;
762
        push @not_fines, @{ $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}) };
763
    }
764
    @not_fines = map { substr($_, 0, $ACCOUNT_TYPE_LENGTH) } uniq (@not_fines);
765
766
    my $patron = Koha::Patrons->find( $borrowernumber );
767
    my $total = $patron->account->balance;
768
    my $other_charges = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, accounttype => { -in => \@not_fines } }, {
769
            select => [ { sum => 'amountoutstanding' } ],
770
            as => ['total_other_charges'],
771
        });
772
    $other_charges = $other_charges->count ? $other_charges->next->get_column('total_other_charges') : 0;
773
774
    return ( $total, $total - $other_charges, $other_charges);
775
}
776
777
sub checkcardnumber {
737
sub checkcardnumber {
778
    my ( $cardnumber, $borrowernumber ) = @_;
738
    my ( $cardnumber, $borrowernumber ) = @_;
779
739
(-)a/Koha/Account.pm (-1 / +52 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Carp;
22
use Carp;
23
use Data::Dumper;
23
use Data::Dumper;
24
use List::MoreUtils qw( uniq );
24
25
25
use C4::Log qw( logaction );
26
use C4::Log qw( logaction );
26
use C4::Stats qw( UpdateStats );
27
use C4::Stats qw( UpdateStats );
Lines 281-287 sub balance { Link Here
281
    );
282
    );
282
283
283
    my $total = $fines->count
284
    my $total = $fines->count
284
      ? $fines->next->get_column('total_amountoutstanding')
285
      ? $fines->next->get_column('total_amountoutstanding') + 0
286
      : 0;
287
}
288
289
=head3 non_issues_charges
290
291
my $non_issues_charges = $self->non_issues_charges
292
293
Calculates amount immediately owing by the patron - non-issue charges.
294
295
Charges exempt from non-issue are:
296
* Res (holds) if HoldsInNoissuesCharge syspref is set to false
297
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false
298
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
299
300
=cut
301
302
sub non_issues_charges {
303
    my ($self) = @_;
304
305
    # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5
306
    my $ACCOUNT_TYPE_LENGTH = 5;    # this is plain ridiculous...
307
308
    my @not_fines;
309
    push @not_fines, 'Res'
310
      unless C4::Context->preference('HoldsInNoissuesCharge');
311
    push @not_fines, 'Rent'
312
      unless C4::Context->preference('RentalsInNoissuesCharge');
313
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
314
        my $dbh = C4::Context->dbh;
315
        push @not_fines,
316
          @{
317
            $dbh->selectcol_arrayref(q|
318
                SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'
319
            |)
320
          };
321
    }
322
    @not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines);
323
324
    my $non_issues_charges = Koha::Account::Lines->search(
325
        {
326
            borrowernumber => $self->{patron_id},
327
            accounttype    => { -not_in => \@not_fines }
328
        },
329
        {
330
            select => [ { sum => 'amountoutstanding' } ],
331
            as     => ['non_issues_charges'],
332
        }
333
    );
334
    return $non_issues_charges->count
335
      ? $non_issues_charges->next->get_column('non_issues_charges') + 0
285
      : 0;
336
      : 0;
286
}
337
}
287
338
(-)a/t/db_dependent/ILSDI_Services.t (-2 / +11 lines)
Lines 166-173 subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes Link Here
166
        }
166
        }
167
    } );
167
    } );
168
168
169
    my $members = Test::MockModule->new('C4::Members');
169
    $builder->build(
170
    $members->mock( 'GetMemberAccountBalance', sub { return ( 10, 10, 0 ); } );
170
        {
171
            source => 'Accountline',
172
            value  => {
173
                borrowernumber    => $brwr->{borrowernumber},
174
                accountno         => 1,
175
                accounttype       => 'xxx',
176
                amountoutstanding => 10
177
            }
178
        }
179
    );
171
180
172
    # Prepare and send web request for IL-SDI server:
181
    # Prepare and send web request for IL-SDI server:
173
    my $query = new CGI;
182
    my $query = new CGI;
(-)a/t/db_dependent/Members.t (-39 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 61;
20
use Test::More tests => 60;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 373-415 ok( $borrower->{userid}, 'A userid should have been generated correctly' ); Link Here
373
is( Check_Userid( C4::Context->config('user'), '' ), 0,
373
is( Check_Userid( C4::Context->config('user'), '' ), 0,
374
    'Check_Userid should return 0 for the DB user (Bug 12226)');
374
    'Check_Userid should return 0 for the DB user (Bug 12226)');
375
375
376
subtest 'GetMemberAccountBalance' => sub {
377
378
    plan tests => 6;
379
380
    my $members_mock = new Test::MockModule('C4::Members');
381
    $members_mock->mock( 'GetMemberAccountRecords', sub {
382
        my ($borrowernumber) = @_;
383
        if ($borrowernumber) {
384
            my @accountlines = (
385
            { amountoutstanding => '7', accounttype => 'Rent' },
386
            { amountoutstanding => '5', accounttype => 'Res' },
387
            { amountoutstanding => '3', accounttype => 'Pay' } );
388
            return ( 15, \@accountlines );
389
        }
390
        else {
391
            my @accountlines;
392
            return ( 0, \@accountlines );
393
        }
394
    });
395
396
    # do not count holds charges
397
    t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', '1' );
398
    t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', '0' );
399
    my ($total, $total_minus_charges,
400
        $other_charges) = C4::Members::GetMemberAccountBalance(123);
401
    is( $total, 15 , "Total calculated correctly");
402
    is( $total_minus_charges, 15, "Holds charges are not count if HoldsInNoissuesCharge=1");
403
    is( $other_charges, 0, "Holds charges are not considered if HoldsInNoissuesCharge=1");
404
405
    t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', '0' );
406
    ($total, $total_minus_charges,
407
        $other_charges) = C4::Members::GetMemberAccountBalance(123);
408
    is( $total, 15 , "Total calculated correctly");
409
    is( $total_minus_charges, 10, "Holds charges are count if HoldsInNoissuesCharge=0");
410
    is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
411
};
412
413
subtest 'purgeSelfRegistration' => sub {
376
subtest 'purgeSelfRegistration' => sub {
414
    plan tests => 2;
377
    plan tests => 2;
415
378
416
- 

Return to bug 12001