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

(-)a/C4/Members.pm (-42 lines)
Lines 456-503 sub GetMember { Link Here
456
    return;
456
    return;
457
}
457
}
458
458
459
=head2 GetMemberRelatives
460
461
 @borrowernumbers = GetMemberRelatives($borrowernumber);
462
463
 C<GetMemberRelatives> returns a borrowersnumber's list of guarantor/guarantees of the member given in parameter
464
465
=cut
466
467
sub GetMemberRelatives {
468
    my $borrowernumber = shift;
469
    my $dbh = C4::Context->dbh;
470
    my @glist;
471
472
    # Getting guarantor
473
    my $query = "SELECT guarantorid FROM borrowers WHERE borrowernumber=?";
474
    my $sth = $dbh->prepare($query);
475
    $sth->execute($borrowernumber);
476
    my $data = $sth->fetchrow_arrayref();
477
    push @glist, $data->[0] if $data->[0];
478
    my $guarantor = $data->[0] ? $data->[0] : undef;
479
480
    # Getting guarantees
481
    $query = "SELECT borrowernumber FROM borrowers WHERE guarantorid=?";
482
    $sth = $dbh->prepare($query);
483
    $sth->execute($borrowernumber);
484
    while ($data = $sth->fetchrow_arrayref()) {
485
       push @glist, $data->[0];
486
    }
487
488
    # Getting sibling guarantees
489
    if ($guarantor) {
490
        $query = "SELECT borrowernumber FROM borrowers WHERE guarantorid=?";
491
        $sth = $dbh->prepare($query);
492
        $sth->execute($guarantor);
493
        while ($data = $sth->fetchrow_arrayref()) {
494
           push @glist, $data->[0] if ($data->[0] != $borrowernumber);
495
        }
496
    }
497
498
    return @glist;
499
}
500
501
=head2 IsMemberBlocked
459
=head2 IsMemberBlocked
502
460
503
  my ($block_status, $count) = IsMemberBlocked( $borrowernumber );
461
  my ($block_status, $count) = IsMemberBlocked( $borrowernumber );
(-)a/Koha/Patron.pm (+25 lines)
Lines 59-64 sub guarantees { Link Here
59
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
59
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
60
}
60
}
61
61
62
=head3 siblings
63
64
Returns the siblings of this patron.
65
66
=cut
67
68
sub siblings {
69
    my ( $self ) = @_;
70
71
    my $guarantor = $self->guarantor;
72
    my $guarantorid = $guarantor ? $guarantor->borrowernumber : undef;
73
74
    return Koha::Patrons->search(
75
        {
76
            guarantorid => {
77
                '!=' => undef,
78
                '=' => $guarantorid,
79
            },
80
            borrowernumber => {
81
                '!=' => $self->borrowernumber,
82
            }
83
        }
84
    );
85
}
86
62
=head3 type
87
=head3 type
63
88
64
=cut
89
=cut
(-)a/circ/circulation.pl (-1 / +9 lines)
Lines 43-48 use Koha::Holds; Link Here
43
use C4::Context;
43
use C4::Context;
44
use CGI::Session;
44
use CGI::Session;
45
use C4::Members::Attributes qw(GetBorrowerAttributes);
45
use C4::Members::Attributes qw(GetBorrowerAttributes);
46
use Koha::Patron;
46
use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
47
use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
47
use Koha::DateUtils;
48
use Koha::DateUtils;
48
use Koha::Database;
49
use Koha::Database;
Lines 570-576 my $view = $batch Link Here
570
    ?'batch_checkout_view'
571
    ?'batch_checkout_view'
571
    : 'circview';
572
    : 'circview';
572
573
573
my @relatives = GetMemberRelatives( $borrower->{'borrowernumber'} );
574
my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
575
my @relatives;
576
if ( my $guarantor = $patron->guarantor ) {
577
    push @relatives, $guarantor->borrowernumber;
578
    push @relatives, $_->borrowernumber for $patron->siblings;
579
} else {
580
    push @relatives, $_->borrowernumber for $patron->guarantees;
581
}
574
my $relatives_issues_count =
582
my $relatives_issues_count =
575
  Koha::Database->new()->schema()->resultset('Issue')
583
  Koha::Database->new()->schema()->resultset('Issue')
576
  ->count( { borrowernumber => \@relatives } );
584
  ->count( { borrowernumber => \@relatives } );
(-)a/members/moremember.pl (-10 / +12 lines)
Lines 163-175 if ( $category_type eq 'C') { Link Here
163
}
163
}
164
164
165
my $patron = Koha::Patrons->find($data->{borrowernumber});
165
my $patron = Koha::Patrons->find($data->{borrowernumber});
166
my @guarantees = $patron->guarantees;
166
my @relatives;
167
if ( @guarantees ) {
167
if ( my $guarantor = $patron->guarantor ) {
168
    $template->param( guarantor => $guarantor );
169
    push @relatives, $guarantor->borrowernumber;
170
    push @relatives, $_->borrowernumber for $patron->siblings;
171
} else {
172
    my @guarantees = $patron->guarantees;
168
    $template->param( guarantees => \@guarantees );
173
    $template->param( guarantees => \@guarantees );
174
    push @relatives, $_->borrowernumber for @guarantees;
169
}
175
}
170
elsif ( $patron->guarantorid ) {
176
171
    $template->param( guarantor => $patron->guarantor );
177
my $relatives_issues_count =
172
}
178
  Koha::Database->new()->schema()->resultset('Issue')
179
  ->count( { borrowernumber => \@relatives } );
173
180
174
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
181
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
175
182
Lines 218-228 if ( C4::Context->preference('OPACPrivacy') ) { Link Here
218
    $template->param( "privacy".$data->{'privacy'} => 1);
225
    $template->param( "privacy".$data->{'privacy'} => 1);
219
}
226
}
220
227
221
my @relatives = GetMemberRelatives($borrowernumber);
222
my $relatives_issues_count =
223
  Koha::Database->new()->schema()->resultset('Issue')
224
  ->count( { borrowernumber => \@relatives } );
225
226
my $today       = DateTime->now( time_zone => C4::Context->tz);
228
my $today       = DateTime->now( time_zone => C4::Context->tz);
227
$today->truncate(to => 'day');
229
$today->truncate(to => 'day');
228
my $overdues_exist = 0;
230
my $overdues_exist = 0;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +21 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use Koha::Patron;
24
use Koha::Patron;
25
use Koha::Patrons;
25
use Koha::Patrons;
Lines 77-82 subtest 'guarantees' => sub { Link Here
77
    $_->delete for @guarantees;
77
    $_->delete for @guarantees;
78
};
78
};
79
79
80
subtest 'siblings' => sub {
81
    plan tests => 7;
82
    my $siblings = $new_patron_1->siblings;
83
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should not crashed if the patron has not guarantor' );
84
    my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
85
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
86
    $siblings = $retrieved_guarantee_1->siblings;
87
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
88
    my @siblings = $retrieved_guarantee_1->siblings;
89
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
90
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
91
    my $guarantee_2 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
92
    my $guarantee_3 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
93
    $siblings = $retrieved_guarantee_1->siblings;
94
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
95
    is( $guarantee_2->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_2 should exist in the guarantees' );
96
    is( $guarantee_3->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_3 should exist in the guarantees' );
97
    $_->delete for $retrieved_guarantee_1->siblings;
98
    $retrieved_guarantee_1->delete;
99
};
80
100
81
$retrieved_patron_1->delete;
101
$retrieved_patron_1->delete;
82
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
102
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
83
- 

Return to bug 15656