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

(-)a/C4/Members.pm (-33 lines)
Lines 60-67 BEGIN { Link Here
60
        &GetMemberRelatives
60
        &GetMemberRelatives
61
        &GetMember
61
        &GetMember
62
62
63
        &GetGuarantees
64
65
        &GetMemberIssuesAndFines
63
        &GetMemberIssuesAndFines
66
        &GetPendingIssues
64
        &GetPendingIssues
67
        &GetAllIssues
65
        &GetAllIssues
Lines 935-971 sub fixup_cardnumber { Link Here
935
    return $cardnumber;     # just here as a fallback/reminder 
933
    return $cardnumber;     # just here as a fallback/reminder 
936
}
934
}
937
935
938
=head2 GetGuarantees
939
940
  ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
941
  $child0_cardno = $children_arrayref->[0]{"cardnumber"};
942
  $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
943
944
C<&GetGuarantees> takes a borrower number (e.g., that of a patron
945
with children) and looks up the borrowers who are guaranteed by that
946
borrower (i.e., the patron's children).
947
948
C<&GetGuarantees> returns two values: an integer giving the number of
949
borrowers guaranteed by C<$parent_borrno>, and a reference to an array
950
of references to hash, which gives the actual results.
951
952
=cut
953
954
#'
955
sub GetGuarantees {
956
    my ($borrowernumber) = @_;
957
    my $dbh              = C4::Context->dbh;
958
    my $sth              =
959
      $dbh->prepare(
960
"select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
961
      );
962
    $sth->execute($borrowernumber);
963
964
    my @dat;
965
    my $data = $sth->fetchall_arrayref({}); 
966
    return ( scalar(@$data), $data );
967
}
968
969
=head2 GetPendingIssues
936
=head2 GetPendingIssues
970
937
971
  my $issues = &GetPendingIssues(@borrowernumber);
938
  my $issues = &GetPendingIssues(@borrowernumber);
(-)a/Koha/Patron.pm (+12 lines)
Lines 47-52 sub guarantor { Link Here
47
    return Koha::Patrons->find( $self->guarantorid() );
47
    return Koha::Patrons->find( $self->guarantorid() );
48
}
48
}
49
49
50
=head3 guarantees
51
52
Returns the guarantees (list of Koha::Patron) of this patron
53
54
=cut
55
56
sub guarantees {
57
    my ( $self ) = @_;
58
59
    return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
60
}
61
50
=head3 type
62
=head3 type
51
63
52
=cut
64
=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 162-199 if ( $category_type eq 'C') { Link Here
162
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
162
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
163
}
163
}
164
164
165
my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
165
my $patron = Koha::Patrons->find($data->{borrowernumber});
166
if ( $count ) {
166
my @guarantees = $patron->guarantees;
167
    $template->param( isguarantee => 1 );
167
if ( @guarantees ) {
168
168
    $template->param( guarantees => \@guarantees );
169
    # FIXME
170
    # It looks like the $i is only being returned to handle walking through
171
    # the array, which is probably better done as a foreach loop.
172
    #
173
    my @guaranteedata;
174
    for ( my $i = 0 ; $i < $count ; $i++ ) {
175
        push(@guaranteedata,
176
            {
177
                borrowernumber => $guarantees->[$i]->{'borrowernumber'},
178
                cardnumber     => $guarantees->[$i]->{'cardnumber'},
179
                name           => $guarantees->[$i]->{'firstname'} . " "
180
                                . $guarantees->[$i]->{'surname'}
181
            }
182
        );
183
    }
184
    $template->param( guaranteeloop => \@guaranteedata );
185
}
169
}
186
else {
170
elsif ( $patron->guarantorid ) {
187
    if ($data->{'guarantorid'}){
171
    $template->param( guarantor => $patron->guarantor );
188
	    my ($guarantor) = GetMember( 'borrowernumber' =>$data->{'guarantorid'});
189
		$template->param(guarantor => 1);
190
		foreach (qw(borrowernumber cardnumber firstname surname)) {        
191
			  $template->param("guarantor$_" => $guarantor->{$_});
192
        }
193
    }
194
	if ($category_type eq 'C'){
195
		$template->param('C' => 1);
196
	}
197
}
172
}
198
173
199
$template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
174
$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