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

(-)a/C4/Members.pm (-33 lines)
Lines 61-68 BEGIN { Link Here
61
        &GetMemberRelatives
61
        &GetMemberRelatives
62
        &GetMember
62
        &GetMember
63
63
64
        &GetGuarantees
65
66
        &GetMemberIssuesAndFines
64
        &GetMemberIssuesAndFines
67
        &GetPendingIssues
65
        &GetPendingIssues
68
        &GetAllIssues
66
        &GetAllIssues
Lines 931-967 sub fixup_cardnumber { Link Here
931
    return $cardnumber;     # just here as a fallback/reminder 
929
    return $cardnumber;     # just here as a fallback/reminder 
932
}
930
}
933
931
934
=head2 GetGuarantees
935
936
  ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
937
  $child0_cardno = $children_arrayref->[0]{"cardnumber"};
938
  $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
939
940
C<&GetGuarantees> takes a borrower number (e.g., that of a patron
941
with children) and looks up the borrowers who are guaranteed by that
942
borrower (i.e., the patron's children).
943
944
C<&GetGuarantees> returns two values: an integer giving the number of
945
borrowers guaranteed by C<$parent_borrno>, and a reference to an array
946
of references to hash, which gives the actual results.
947
948
=cut
949
950
#'
951
sub GetGuarantees {
952
    my ($borrowernumber) = @_;
953
    my $dbh              = C4::Context->dbh;
954
    my $sth              =
955
      $dbh->prepare(
956
"select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
957
      );
958
    $sth->execute($borrowernumber);
959
960
    my @dat;
961
    my $data = $sth->fetchall_arrayref({}); 
962
    return ( scalar(@$data), $data );
963
}
964
965
=head2 GetPendingIssues
932
=head2 GetPendingIssues
966
933
967
  my $issues = &GetPendingIssues(@borrowernumber);
934
  my $issues = &GetPendingIssues(@borrowernumber);
(-)a/Koha/Patron.pm (+12 lines)
Lines 54-59 sub image { Link Here
54
    return Koha::Patron::Images->find( $self->borrowernumber )
54
    return Koha::Patron::Images->find( $self->borrowernumber )
55
}
55
}
56
56
57
=head3 guarantees
58
59
Returns the guarantees (list of Koha::Patron) of this patron
60
61
=cut
62
63
sub guarantees {
64
    my ( $self ) = @_;
65
66
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
67
}
68
57
=head3 type
69
=head3 type
58
70
59
=cut
71
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-8 / +14 lines)
Lines 231-244 function validate1(date) { Link Here
231
    [% IF ( sex ) %]<li><span class="label">Gender:</span>
231
    [% IF ( sex ) %]<li><span class="label">Gender:</span>
232
    [% IF ( sex == 'F' ) %]Female[% ELSIF ( sex == 'M' ) %]Male[% ELSE %][% sex %][% END %]
232
    [% IF ( sex == 'F' ) %]Female[% ELSIF ( sex == 'M' ) %]Male[% ELSE %][% sex %][% END %]
233
    </li>[% END %][% END %]
233
    </li>[% END %][% END %]
234
    [% IF ( isguarantee ) %]
234
    [% IF guarantees %]
235
        [% IF ( guaranteeloop ) %]
235
        <li>
236
            <li><span class="label">Guarantees:</span><ul>[% FOREACH guaranteeloo IN guaranteeloop %]<li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guaranteeloo.borrowernumber %]">[% guaranteeloo.name %]  </a></li>[% END %]</ul></li>
236
            <span class="label">Guarantees:</span>
237
        [% END %]
237
            <ul>
238
    [% ELSE %]
238
                [% FOREACH guarantee IN guarantees %]
239
        [% IF ( guarantorborrowernumber ) %]
239
                    <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantee.borrowernumber %]">[% guarantee.firstname %] [% guarantee.surname %]</a></li>
240
            <li><span class="label">Guarantor:</span><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorborrowernumber %]">[% guarantorsurname %][%IF ( guarantorfirstname ) %], [% guarantorfirstname %] [% END %]</a></li>
240
                [% END %]
241
        [% END %]
241
            </ul>
242
        </li>
243
    [% ELSIF guarantor %]
244
        <li>
245
            <span class="label">Guarantor:</span>
246
            <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.firstname %] [% guarantor.surname %]</a>
247
        </li>
242
    [% END %]
248
    [% END %]
243
</ol>
249
</ol>
244
</div>
250
</div>
(-)a/members/moremember.pl (-31 / +6 lines)
Lines 163-200 if ( $category_type eq 'C') { Link Here
163
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
163
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
164
}
164
}
165
165
166
my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
166
my $patron = Koha::Patrons->find($data->{borrowernumber});
167
if ( $count ) {
167
my @guarantees = $patron->guarantees;
168
    $template->param( isguarantee => 1 );
168
if ( @guarantees ) {
169
169
    $template->param( guarantees => \@guarantees );
170
    # FIXME
171
    # It looks like the $i is only being returned to handle walking through
172
    # the array, which is probably better done as a foreach loop.
173
    #
174
    my @guaranteedata;
175
    for ( my $i = 0 ; $i < $count ; $i++ ) {
176
        push(@guaranteedata,
177
            {
178
                borrowernumber => $guarantees->[$i]->{'borrowernumber'},
179
                cardnumber     => $guarantees->[$i]->{'cardnumber'},
180
                name           => $guarantees->[$i]->{'firstname'} . " "
181
                                . $guarantees->[$i]->{'surname'}
182
            }
183
        );
184
    }
185
    $template->param( guaranteeloop => \@guaranteedata );
186
}
170
}
187
else {
171
elsif ( $patron->guarantorid ) {
188
    if ($data->{'guarantorid'}){
172
    $template->param( guarantor => $patron->guarantor );
189
	    my ($guarantor) = GetMember( 'borrowernumber' =>$data->{'guarantorid'});
190
		$template->param(guarantor => 1);
191
		foreach (qw(borrowernumber cardnumber firstname surname)) {        
192
			  $template->param("guarantor$_" => $guarantor->{$_});
193
        }
194
    }
195
	if ($category_type eq 'C'){
196
		$template->param('C' => 1);
197
	}
198
}
173
}
199
174
200
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
175
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
(-)a/t/db_dependent/Koha/Patrons.t (-1 / +86 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 4;
23
24
use Koha::Patron;
25
use Koha::Patrons;
26
use Koha::Database;
27
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
33
my $builder       = t::lib::TestBuilder->new;
34
my $library = $builder->build({source => 'Branch' });
35
my $category = $builder->build({source => 'Category' });
36
my $nb_of_patrons = Koha::Patrons->search->count;
37
my $new_patron_1  = Koha::Patron->new(
38
    {   cardnumber => 'test_cn_1',
39
        branchcode => $library->{branchcode},
40
        categorycode => $category->{categorycode},
41
        surname => 'surname for patron1',
42
        firstname => 'firstname for patron1',
43
    }
44
)->store;
45
my $new_patron_2  = Koha::Patron->new(
46
    {   cardnumber => 'test_cn_2',
47
        branchcode => $library->{branchcode},
48
        categorycode => $category->{categorycode},
49
        surname => 'surname for patron2',
50
        firstname => 'firstname for patron2',
51
    }
52
)->store;
53
54
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
55
56
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
57
is( $retrieved_patron_1->cardnumber, $new_patron_1->cardnumber, 'Find a patron by borrowernumber should return the correct patron' );
58
59
subtest 'guarantees' => sub {
60
    plan tests => 8;
61
    my $guarantees = $new_patron_1->guarantees;
62
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
63
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee' );
64
    my @guarantees = $new_patron_1->guarantees;
65
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
66
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
67
68
    my $guarantee_1 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
69
    my $guarantee_2 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
70
71
    $guarantees = $new_patron_1->guarantees;
72
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
73
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
74
    @guarantees = $new_patron_1->guarantees;
75
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
76
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
77
    $_->delete for @guarantees;
78
};
79
80
81
$retrieved_patron_1->delete;
82
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
83
84
$schema->storage->txn_rollback;
85
86
1;

Return to bug 15656