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

(-)a/C4/Members.pm (-42 lines)
Lines 61-67 BEGIN { Link Here
61
    push @EXPORT, qw(
61
    push @EXPORT, qw(
62
        &GetMember
62
        &GetMember
63
63
64
        &GetMemberIssuesAndFines
65
        &GetPendingIssues
64
        &GetPendingIssues
66
        &GetAllIssues
65
        &GetAllIssues
67
66
Lines 347-393 sub GetMember { Link Here
347
    return;
346
    return;
348
}
347
}
349
348
350
=head2 GetMemberIssuesAndFines
351
352
  ($overdue_count, $issue_count, $total_fines) = &GetMemberIssuesAndFines($borrowernumber);
353
354
Returns aggregate data about items borrowed by the patron with the
355
given borrowernumber.
356
357
C<&GetMemberIssuesAndFines> returns a three-element array.  C<$overdue_count> is the
358
number of overdue items the patron currently has borrowed. C<$issue_count> is the
359
number of books the patron currently has borrowed.  C<$total_fines> is
360
the total fine currently due by the borrower.
361
362
=cut
363
364
#'
365
sub GetMemberIssuesAndFines {
366
    my ( $borrowernumber ) = @_;
367
    my $dbh   = C4::Context->dbh;
368
    my $query = "SELECT COUNT(*) FROM issues WHERE borrowernumber = ?";
369
370
    $debug and warn $query."\n";
371
    my $sth = $dbh->prepare($query);
372
    $sth->execute($borrowernumber);
373
    my $issue_count = $sth->fetchrow_arrayref->[0];
374
375
    $sth = $dbh->prepare(
376
        "SELECT COUNT(*) FROM issues 
377
         WHERE borrowernumber = ? 
378
         AND date_due < now()"
379
    );
380
    $sth->execute($borrowernumber);
381
    my $overdue_count = $sth->fetchrow_arrayref->[0];
382
383
    $sth = $dbh->prepare("SELECT SUM(amountoutstanding) FROM accountlines WHERE borrowernumber = ?");
384
    $sth->execute($borrowernumber);
385
    my $total_fines = $sth->fetchrow_arrayref->[0];
386
387
    return ($overdue_count, $issue_count, $total_fines);
388
}
389
390
391
=head2 ModMember
349
=head2 ModMember
392
350
393
  my $success = ModMember(borrowernumber => $borrowernumber,
351
  my $success = ModMember(borrowernumber => $borrowernumber,
(-)a/C4/Utils/DataTables/Members.pm (-4 / +7 lines)
Lines 2-8 package C4::Utils::DataTables::Members; Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Context;
4
use C4::Context;
5
use C4::Members qw/GetMemberIssuesAndFines/;
6
use C4::Utils::DataTables;
5
use C4::Utils::DataTables;
7
use Koha::DateUtils;
6
use Koha::DateUtils;
8
7
Lines 169-182 sub search { Link Here
169
168
170
    # Get some information on patrons
169
    # Get some information on patrons
171
    foreach my $patron (@$patrons) {
170
    foreach my $patron (@$patrons) {
172
        ($patron->{overdues}, $patron->{issues}, $patron->{fines}) =
171
        my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
173
            GetMemberIssuesAndFines($patron->{borrowernumber});
172
        $patron->{overdues} = $patron_object->get_overdues->count;
173
        $patron->{issues} = $patron_object->get_issues->count;
174
        my $balance = $patron_object->get_account_lines->get_balance;
175
        # FIXME Should be formatted from the template
176
        $patron->{fines} = sprintf("%.2f", $balance);
177
174
        if($patron->{dateexpiry} and $patron->{dateexpiry} ne '0000-00-00') {
178
        if($patron->{dateexpiry} and $patron->{dateexpiry} ne '0000-00-00') {
175
            $patron->{dateexpiry} = output_pref( { dt => dt_from_string( $patron->{dateexpiry}, 'iso'), dateonly => 1} );
179
            $patron->{dateexpiry} = output_pref( { dt => dt_from_string( $patron->{dateexpiry}, 'iso'), dateonly => 1} );
176
        } else {
180
        } else {
177
            $patron->{dateexpiry} = '';
181
            $patron->{dateexpiry} = '';
178
        }
182
        }
179
        $patron->{fines} = sprintf("%.2f", $patron->{fines} || 0);
180
    }
183
    }
181
184
182
    return {
185
    return {
(-)a/C4/Utils/DataTables/VirtualShelves.pm (-1 lines)
Lines 2-8 package C4::Utils::DataTables::VirtualShelves; Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Context;
4
use C4::Context;
5
use C4::Members qw/GetMemberIssuesAndFines/;
6
use C4::Utils::DataTables;
5
use C4::Utils::DataTables;
7
use Koha::Virtualshelves;
6
use Koha::Virtualshelves;
8
7
(-)a/circ/circulation.pl (-9 / +10 lines)
Lines 266-272 my $patron; Link Here
266
if ($borrowernumber) {
266
if ($borrowernumber) {
267
    $patron = Koha::Patrons->find( $borrowernumber );
267
    $patron = Koha::Patrons->find( $borrowernumber );
268
    $borrower = GetMember( borrowernumber => $borrowernumber );
268
    $borrower = GetMember( borrowernumber => $borrowernumber );
269
    my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
269
    my $overdues = $patron->get_overdues;
270
    my $issues = $patron->get_issues;
271
    my $balance = $patron->get_account_lines->get_balance;
272
270
273
271
    # if the expiry date is before today ie they have expired
274
    # if the expiry date is before today ie they have expired
272
    if ( $patron->is_expired ) {
275
    if ( $patron->is_expired ) {
Lines 287-295 if ($borrowernumber) { Link Here
287
        }
290
        }
288
    }
291
    }
289
    $template->param(
292
    $template->param(
290
        overduecount => $od,
293
        overduecount => $overdues->count,
291
        issuecount   => $issue,
294
        issuecount   => $issues->count,
292
        finetotal    => $fines
295
        finetotal    => $balance,
293
    );
296
    );
294
297
295
    if ( $patron and $patron->is_debarred ) {
298
    if ( $patron and $patron->is_debarred ) {
Lines 407-415 if (@$barcodes) { Link Here
407
        }
410
        }
408
    }
411
    }
409
412
410
    # FIXME If the issue is confirmed, we launch another time GetMemberIssuesAndFines, now display the issue count after issue
411
    my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
412
413
    if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
413
    if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
414
        $template->param(
414
        $template->param(
415
            reserveborrowernumber => $question->{'resborrowernumber'}
415
            reserveborrowernumber => $question->{'resborrowernumber'}
Lines 421-428 if (@$barcodes) { Link Here
421
    );
421
    );
422
422
423
423
424
424
    # FIXME If the issue is confirmed, we launch another time get_issues->count, now display the issue count after issue
425
    $template_params->{issuecount} = $issue;
425
    $patron = Koha::Patrons->find( $borrowernumber );
426
    $template_params->{issuecount} = $patron->get_issues->count;
426
427
427
    if ( $iteminfo ) {
428
    if ( $iteminfo ) {
428
        $iteminfo->{subtitle} = GetRecordValue('subtitle', GetMarcBiblio($iteminfo->{biblionumber}), GetFrameworkCode($iteminfo->{biblionumber}));
429
        $iteminfo->{subtitle} = GetRecordValue('subtitle', GetMarcBiblio($iteminfo->{biblionumber}), GetFrameworkCode($iteminfo->{biblionumber}));
(-)a/circ/returns.pl (-3 / +6 lines)
Lines 323-331 if ($barcode) { Link Here
323
        push( @inputloop, \%input );
323
        push( @inputloop, \%input );
324
324
325
        if ( C4::Context->preference("FineNotifyAtCheckin") ) {
325
        if ( C4::Context->preference("FineNotifyAtCheckin") ) {
326
            my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrower->{'borrowernumber'} );
326
            my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
327
            if ($fines && $fines > 0) {
327
            my $account_lines = $patron->get_account_lines;
328
                $template->param( fines => sprintf("%.2f",$fines) );
328
            my $balance = $patron->get_account_lines->get_balance;
329
330
            if ($balance > 0) {
331
                $template->param( fines => sprintf("%.2f", $balance) );
329
                $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
332
                $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
330
            }
333
            }
331
        }
334
        }
(-)a/members/moremember.pl (-5 / +10 lines)
Lines 118-125 my $borrowernumber = $input->param('borrowernumber'); Link Here
118
my $error = $input->param('error');
118
my $error = $input->param('error');
119
$template->param( error => $error ) if ( $error );
119
$template->param( error => $error ) if ( $error );
120
120
121
my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
121
my $patron        = Koha::Patrons->find($borrowernumber);
122
$template->param( issuecount => $issue, fines => $fines );
122
my $issues        = $patron->get_issues;
123
my $balance       = $patron->get_account_lines->get_balance;
124
$template->param(
125
    issuecount => $issues->count,
126
    fines      => $balance,
127
);
128
123
129
124
my $data = GetMember( 'borrowernumber' => $borrowernumber );
130
my $data = GetMember( 'borrowernumber' => $borrowernumber );
125
131
Lines 147-153 for (qw(gonenoaddress lost borrowernotes)) { Link Here
147
	 $data->{$_} and $template->param(flagged => 1) and last;
153
	 $data->{$_} and $template->param(flagged => 1) and last;
148
}
154
}
149
155
150
if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) {
156
if ( $patron->is_debarred ) {
151
    $template->param( 'userdebarred' => 1, 'flagged' => 1 );
157
    $template->param( 'userdebarred' => 1, 'flagged' => 1 );
152
    my $debar = $data->{'debarred'};
158
    my $debar = $data->{'debarred'};
153
    if ( $debar ne "9999-12-31" ) {
159
    if ( $debar ne "9999-12-31" ) {
Lines 164-170 if ( $category_type eq 'C') { Link Here
164
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
170
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
165
}
171
}
166
172
167
my $patron = Koha::Patrons->find($data->{borrowernumber});
168
my @relatives;
173
my @relatives;
169
if ( my $guarantor = $patron->guarantor ) {
174
if ( my $guarantor = $patron->guarantor ) {
170
    $template->param( guarantor => $guarantor );
175
    $template->param( guarantor => $guarantor );
Lines 322-328 if (C4::Context->preference('EnhancedMessagingPreferences')) { Link Here
322
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
327
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
323
}
328
}
324
329
325
# in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children) 
330
# in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children)
326
$template->param( $data->{'categorycode'} => 1 );
331
$template->param( $data->{'categorycode'} => 1 );
327
$template->param(
332
$template->param(
328
    patron          => $patron,
333
    patron          => $patron,
(-)a/t/db_dependent/Reserves.t (-4 / +5 lines)
Lines 569-575 ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() Link Here
569
# Tests for bug 14464
569
# Tests for bug 14464
570
570
571
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
571
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
572
my ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
572
my $patron = Koha::Patrons->find( $borrowernumber );
573
my $bz14464_fines = $patron->get_account_lines->get_balance;
573
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning' );
574
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning' );
574
575
575
# First, test cancelling a reserve when there's no charge configured.
576
# First, test cancelling a reserve when there's no charge configured.
Lines 596-602 CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 }); Link Here
596
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
597
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
597
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
598
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
598
599
599
( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
600
$bz14464_fines = $patron->get_account_lines->get_balance;
600
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
601
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
601
602
602
# Then, test cancelling a reserve when there's no charge desired.
603
# Then, test cancelling a reserve when there's no charge desired.
Lines 620-626 ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' ); Link Here
620
621
621
CancelReserve({ reserve_id => $bz14464_reserve });
622
CancelReserve({ reserve_id => $bz14464_reserve });
622
623
623
( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
624
$bz14464_fines = $patron->get_account_lines->get_balance;
624
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
625
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
625
626
626
# Finally, test cancelling a reserve when there's a charge desired and configured.
627
# Finally, test cancelling a reserve when there's a charge desired and configured.
Lines 642-648 ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' ); Link Here
642
643
643
CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
644
CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
644
645
645
( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
646
$bz14464_fines = $patron->get_account_lines->get_balance;
646
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
647
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
647
648
648
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
649
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
(-)a/tools/cleanborrowers.pl (-2 / +2 lines)
Lines 197-203 sub _skip_borrowers_with_nonzero_balance { Link Here
197
    my $borrowers = shift;
197
    my $borrowers = shift;
198
    my $balance;
198
    my $balance;
199
    @$borrowers = map {
199
    @$borrowers = map {
200
        (undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} );
200
        my $patron = Koha::Patrons->find( $_->{borrowernumber} );
201
        my $balance = $patron->get_account_lines->get_balance;
201
        (defined $balance && $balance != 0) ? (): ($_);
202
        (defined $balance && $balance != 0) ? (): ($_);
202
    } @$borrowers;
203
    } @$borrowers;
203
}
204
}
204
- 

Return to bug 17588