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

(-)a/C4/Members.pm (-42 lines)
Lines 62-68 BEGIN { Link Here
62
    push @EXPORT, qw(
62
    push @EXPORT, qw(
63
        &GetMember
63
        &GetMember
64
64
65
        &GetMemberIssuesAndFines
66
        &GetPendingIssues
65
        &GetPendingIssues
67
        &GetAllIssues
66
        &GetAllIssues
68
67
Lines 349-395 sub GetMember { Link Here
349
    return;
348
    return;
350
}
349
}
351
350
352
=head2 GetMemberIssuesAndFines
353
354
  ($overdue_count, $issue_count, $total_fines) = &GetMemberIssuesAndFines($borrowernumber);
355
356
Returns aggregate data about items borrowed by the patron with the
357
given borrowernumber.
358
359
C<&GetMemberIssuesAndFines> returns a three-element array.  C<$overdue_count> is the
360
number of overdue items the patron currently has borrowed. C<$issue_count> is the
361
number of books the patron currently has borrowed.  C<$total_fines> is
362
the total fine currently due by the borrower.
363
364
=cut
365
366
#'
367
sub GetMemberIssuesAndFines {
368
    my ( $borrowernumber ) = @_;
369
    my $dbh   = C4::Context->dbh;
370
    my $query = "SELECT COUNT(*) FROM issues WHERE borrowernumber = ?";
371
372
    $debug and warn $query."\n";
373
    my $sth = $dbh->prepare($query);
374
    $sth->execute($borrowernumber);
375
    my $issue_count = $sth->fetchrow_arrayref->[0];
376
377
    $sth = $dbh->prepare(
378
        "SELECT COUNT(*) FROM issues 
379
         WHERE borrowernumber = ? 
380
         AND date_due < now()"
381
    );
382
    $sth->execute($borrowernumber);
383
    my $overdue_count = $sth->fetchrow_arrayref->[0];
384
385
    $sth = $dbh->prepare("SELECT SUM(amountoutstanding) FROM accountlines WHERE borrowernumber = ?");
386
    $sth->execute($borrowernumber);
387
    my $total_fines = $sth->fetchrow_arrayref->[0];
388
389
    return ($overdue_count, $issue_count, $total_fines);
390
}
391
392
393
=head2 ModMember
351
=head2 ModMember
394
352
395
  my $success = ModMember(borrowernumber => $borrowernumber,
353
  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 119-126 my $borrowernumber = $input->param('borrowernumber'); Link Here
119
my $error = $input->param('error');
119
my $error = $input->param('error');
120
$template->param( error => $error ) if ( $error );
120
$template->param( error => $error ) if ( $error );
121
121
122
my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
122
my $patron        = Koha::Patrons->find($borrowernumber);
123
$template->param( issuecount => $issue, fines => $fines );
123
my $issues        = $patron->get_issues;
124
my $balance       = $patron->get_account_lines->get_balance;
125
$template->param(
126
    issuecount => $issues->count,
127
    fines      => $balance,
128
);
129
124
130
125
my $data = GetMember( 'borrowernumber' => $borrowernumber );
131
my $data = GetMember( 'borrowernumber' => $borrowernumber );
126
132
Lines 148-154 for (qw(gonenoaddress lost borrowernotes)) { Link Here
148
	 $data->{$_} and $template->param(flagged => 1) and last;
154
	 $data->{$_} and $template->param(flagged => 1) and last;
149
}
155
}
150
156
151
if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) {
157
if ( $patron->is_debarred ) {
152
    $template->param( 'userdebarred' => 1, 'flagged' => 1 );
158
    $template->param( 'userdebarred' => 1, 'flagged' => 1 );
153
    my $debar = $data->{'debarred'};
159
    my $debar = $data->{'debarred'};
154
    if ( $debar ne "9999-12-31" ) {
160
    if ( $debar ne "9999-12-31" ) {
Lines 165-171 if ( $category_type eq 'C') { Link Here
165
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
171
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
166
}
172
}
167
173
168
my $patron = Koha::Patrons->find($data->{borrowernumber});
169
my @relatives;
174
my @relatives;
170
if ( my $guarantor = $patron->guarantor ) {
175
if ( my $guarantor = $patron->guarantor ) {
171
    $template->param( guarantor => $guarantor );
176
    $template->param( guarantor => $guarantor );
Lines 323-329 if (C4::Context->preference('EnhancedMessagingPreferences')) { Link Here
323
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
328
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
324
}
329
}
325
330
326
# in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children) 
331
# in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children)
327
$template->param( $data->{'categorycode'} => 1 );
332
$template->param( $data->{'categorycode'} => 1 );
328
$template->param(
333
$template->param(
329
    patron          => $patron,
334
    patron          => $patron,
(-)a/t/db_dependent/Reserves.t (-4 / +5 lines)
Lines 572-578 ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() Link Here
572
# Tests for bug 14464
572
# Tests for bug 14464
573
573
574
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
574
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
575
my ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
575
my $patron = Koha::Patrons->find( $borrowernumber );
576
my $bz14464_fines = $patron->get_account_lines->get_balance;
576
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning' );
577
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning' );
577
578
578
# First, test cancelling a reserve when there's no charge configured.
579
# First, test cancelling a reserve when there's no charge configured.
Lines 599-605 CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 }); Link Here
599
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
600
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
600
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
601
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
601
602
602
( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
603
$bz14464_fines = $patron->get_account_lines->get_balance;
603
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
604
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
604
605
605
# Then, test cancelling a reserve when there's no charge desired.
606
# Then, test cancelling a reserve when there's no charge desired.
Lines 623-629 ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' ); Link Here
623
624
624
CancelReserve({ reserve_id => $bz14464_reserve });
625
CancelReserve({ reserve_id => $bz14464_reserve });
625
626
626
( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
627
$bz14464_fines = $patron->get_account_lines->get_balance;
627
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
628
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
628
629
629
# Finally, test cancelling a reserve when there's a charge desired and configured.
630
# Finally, test cancelling a reserve when there's a charge desired and configured.
Lines 645-651 ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' ); Link Here
645
646
646
CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
647
CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
647
648
648
( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
649
$bz14464_fines = $patron->get_account_lines->get_balance;
649
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
650
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
650
651
651
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
652
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
(-)a/tools/cleanborrowers.pl (-2 / +2 lines)
Lines 199-205 sub _skip_borrowers_with_nonzero_balance { Link Here
199
    my $borrowers = shift;
199
    my $borrowers = shift;
200
    my $balance;
200
    my $balance;
201
    @$borrowers = map {
201
    @$borrowers = map {
202
        (undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} );
202
        my $patron = Koha::Patrons->find( $_->{borrowernumber} );
203
        my $balance = $patron->get_account_lines->get_balance;
203
        (defined $balance && $balance != 0) ? (): ($_);
204
        (defined $balance && $balance != 0) ? (): ($_);
204
    } @$borrowers;
205
    } @$borrowers;
205
}
206
}
206
- 

Return to bug 17588