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

(-)a/C4/Circulation.pm (-16 / +17 lines)
Lines 766-773 sub CanBookBeIssued { Link Here
766
    #
766
    #
767
767
768
    # DEBTS
768
    # DEBTS
769
    my ($balance, $non_issue_charges, $other_charges) =
769
    my $account = $patron->account;
770
      C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
770
    my $balance = $account->balance;
771
    my $non_issues_charges = $account->non_issues_charges;
772
    my $other_charges = $balance - $non_issues_charges;
771
773
772
    my $amountlimit = C4::Context->preference("noissuescharge");
774
    my $amountlimit = C4::Context->preference("noissuescharge");
773
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
775
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
Lines 781-788 sub CanBookBeIssued { Link Here
781
        my @guarantees = $p->guarantees();
783
        my @guarantees = $p->guarantees();
782
        my $guarantees_non_issues_charges;
784
        my $guarantees_non_issues_charges;
783
        foreach my $g ( @guarantees ) {
785
        foreach my $g ( @guarantees ) {
784
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
786
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
785
            $guarantees_non_issues_charges += $n;
786
        }
787
        }
787
788
788
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
789
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
Lines 795-815 sub CanBookBeIssued { Link Here
795
    }
796
    }
796
797
797
    if ( C4::Context->preference("IssuingInProcess") ) {
798
    if ( C4::Context->preference("IssuingInProcess") ) {
798
        if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
799
        if ( $non_issues_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
799
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
800
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issues_charges );
800
        } elsif ( $non_issue_charges > $amountlimit && !$inprocess && $allowfineoverride) {
801
        } elsif ( $non_issues_charges > $amountlimit && !$inprocess && $allowfineoverride) {
801
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
802
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
802
        } elsif ( $allfinesneedoverride && $non_issue_charges > 0 && $non_issue_charges <= $amountlimit && !$inprocess ) {
803
        } elsif ( $allfinesneedoverride && $non_issues_charges > 0 && $non_issues_charges <= $amountlimit && !$inprocess ) {
803
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
804
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
804
        }
805
        }
805
    }
806
    }
806
    else {
807
    else {
807
        if ( $non_issue_charges > $amountlimit && $allowfineoverride ) {
808
        if ( $non_issues_charges > $amountlimit && $allowfineoverride ) {
808
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
809
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
809
        } elsif ( $non_issue_charges > $amountlimit && !$allowfineoverride) {
810
        } elsif ( $non_issues_charges > $amountlimit && !$allowfineoverride) {
810
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
811
            $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issues_charges );
811
        } elsif ( $non_issue_charges > 0 && $allfinesneedoverride ) {
812
        } elsif ( $non_issues_charges > 0 && $allfinesneedoverride ) {
812
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
813
            $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issues_charges );
813
        }
814
        }
814
    }
815
    }
815
816
(-)a/C4/Members.pm (-45 / +5 lines)
Lines 177-183 sub patronflags { Link Here
177
    my %flags;
177
    my %flags;
178
    my ( $patroninformation) = @_;
178
    my ( $patroninformation) = @_;
179
    my $dbh=C4::Context->dbh;
179
    my $dbh=C4::Context->dbh;
180
    my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'});
180
    my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
181
    my $account = $patron->account;
182
    my $owing = $account->non_issues_charges;
181
    if ( $owing > 0 ) {
183
    if ( $owing > 0 ) {
182
        my %flaginfo;
184
        my %flaginfo;
183
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
185
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
Lines 188-194 sub patronflags { Link Here
188
        }
190
        }
189
        $flags{'CHARGES'} = \%flaginfo;
191
        $flags{'CHARGES'} = \%flaginfo;
190
    }
192
    }
191
    elsif ( $balance < 0 ) {
193
    elsif ( ( my $balance = $account->balance ) < 0 ) {
192
        my %flaginfo;
194
        my %flaginfo;
193
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
195
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
194
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
196
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
Lines 203-210 sub patronflags { Link Here
203
        my @guarantees = $p->guarantees();
205
        my @guarantees = $p->guarantees();
204
        my $guarantees_non_issues_charges;
206
        my $guarantees_non_issues_charges;
205
        foreach my $g ( @guarantees ) {
207
        foreach my $g ( @guarantees ) {
206
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
208
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
207
            $guarantees_non_issues_charges += $n;
208
        }
209
        }
209
210
210
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
211
        if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
Lines 261-267 sub patronflags { Link Here
261
        $flags{'ODUES'} = \%flaginfo;
262
        $flags{'ODUES'} = \%flaginfo;
262
    }
263
    }
263
264
264
    my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
265
    my $waiting_holds = $patron->holds->search({ found => 'W' });
265
    my $waiting_holds = $patron->holds->search({ found => 'W' });
266
    my $nowaiting = $waiting_holds->count;
266
    my $nowaiting = $waiting_holds->count;
267
    if ( $nowaiting > 0 ) {
267
    if ( $nowaiting > 0 ) {
Lines 735-780 sub GetAllIssues { Link Here
735
    return $sth->fetchall_arrayref( {} );
735
    return $sth->fetchall_arrayref( {} );
736
}
736
}
737
737
738
739
=head2 GetMemberAccountBalance
740
741
  ($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber);
742
743
Calculates amount immediately owing by the patron - non-issue charges.
744
Based on GetMemberAccountRecords.
745
Charges exempt from non-issue are:
746
* Res (reserves)
747
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false
748
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
749
750
=cut
751
752
sub GetMemberAccountBalance {
753
    my ($borrowernumber) = @_;
754
755
    # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5
756
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
757
758
    my @not_fines;
759
    push @not_fines, 'Res' unless C4::Context->preference('HoldsInNoissuesCharge');
760
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
761
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
762
        my $dbh = C4::Context->dbh;
763
        push @not_fines, @{ $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}) };
764
    }
765
    @not_fines = map { substr($_, 0, $ACCOUNT_TYPE_LENGTH) } uniq (@not_fines);
766
767
    my $patron = Koha::Patrons->find( $borrowernumber );
768
    my $total = $patron->account->balance;
769
    my $other_charges = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, accounttype => { -in => \@not_fines } }, {
770
            select => [ { sum => 'amountoutstanding' } ],
771
            as => ['total_other_charges'],
772
        });
773
    $other_charges = $other_charges->count ? $other_charges->next->get_column('total_other_charges') : 0;
774
775
    return ( $total, $total - $other_charges, $other_charges);
776
}
777
778
sub checkcardnumber {
738
sub checkcardnumber {
779
    my ( $cardnumber, $borrowernumber ) = @_;
739
    my ( $cardnumber, $borrowernumber ) = @_;
780
740
(-)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