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

(-)a/C4/Auth_with_ldap.pm (-1 lines)
Lines 463-469 C4::Auth - Authenticates Koha users Link Here
463
		| contactname         | mediumtext   | YES  |     | NULL    |                |
463
		| contactname         | mediumtext   | YES  |     | NULL    |                |
464
		| contactfirstname    | text         | YES  |     | NULL    |                |
464
		| contactfirstname    | text         | YES  |     | NULL    |                |
465
		| contacttitle        | text         | YES  |     | NULL    |                |
465
		| contacttitle        | text         | YES  |     | NULL    |                |
466
		| guarantorid         | int(11)      | YES  | MUL | NULL    |                |
467
		| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
466
		| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
468
		| relationship        | varchar(100) | YES  |     | NULL    |                |
467
		| relationship        | varchar(100) | YES  |     | NULL    |                |
469
		| ethnicity           | varchar(50)  | YES  |     | NULL    |                |
468
		| ethnicity           | varchar(50)  | YES  |     | NULL    |                |
(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 758-764 sub CanBookBeIssued { Link Here
758
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
758
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
759
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
759
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
760
    if ( defined $no_issues_charge_guarantees ) {
760
    if ( defined $no_issues_charge_guarantees ) {
761
        my @guarantees = $patron->guarantees();
761
        my @guarantees = map { $_->guarantee } $patron->guarantee_relationships();
762
        my $guarantees_non_issues_charges;
762
        my $guarantees_non_issues_charges;
763
        foreach my $g ( @guarantees ) {
763
        foreach my $g ( @guarantees ) {
764
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
764
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
(-)a/C4/Members.pm (-9 / +7 lines)
Lines 198-204 sub patronflags { Link Here
198
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
198
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
199
    if ( defined $no_issues_charge_guarantees ) {
199
    if ( defined $no_issues_charge_guarantees ) {
200
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
200
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
201
        my @guarantees = $p->guarantees();
201
        my @guarantees = map { $_->guarantee } $p->guarantee_relationships;
202
        my $guarantees_non_issues_charges;
202
        my $guarantees_non_issues_charges;
203
        foreach my $g ( @guarantees ) {
203
        foreach my $g ( @guarantees ) {
204
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
204
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
Lines 317-323 sub ModMember { Link Here
317
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
317
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
318
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
318
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
319
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
319
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
320
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
321
320
322
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
321
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
323
322
Lines 450-456 sub AddMember { Link Here
450
    $data{'dateofbirth'}     = undef if ( not $data{'dateofbirth'} );
449
    $data{'dateofbirth'}     = undef if ( not $data{'dateofbirth'} );
451
    $data{'debarred'}        = undef if ( not $data{'debarred'} );
450
    $data{'debarred'}        = undef if ( not $data{'debarred'} );
452
    $data{'sms_provider_id'} = undef if ( not $data{'sms_provider_id'} );
451
    $data{'sms_provider_id'} = undef if ( not $data{'sms_provider_id'} );
453
    $data{'guarantorid'}     = undef if ( not $data{'guarantorid'} );
454
452
455
    # get only the columns of Borrower
453
    # get only the columns of Borrower
456
    # FIXME Do we really need this check?
454
    # FIXME Do we really need this check?
Lines 657-674 sub GetBorrowersToExpunge { Link Here
657
            FROM   borrowers
655
            FROM   borrowers
658
            JOIN   categories USING (categorycode)
656
            JOIN   categories USING (categorycode)
659
            LEFT JOIN (
657
            LEFT JOIN (
660
                SELECT guarantorid
658
                SELECT guarantor_id
661
                FROM borrowers
659
                FROM relationships
662
                WHERE guarantorid IS NOT NULL
660
                WHERE guarantor_id IS NOT NULL
663
                    AND guarantorid <> 0
661
                    AND guarantor_id <> 0
664
            ) as tmp ON borrowers.borrowernumber=tmp.guarantorid
662
            ) as tmp ON borrowers.borrowernumber=tmp.guarantor_id
665
            LEFT JOIN old_issues USING (borrowernumber)
663
            LEFT JOIN old_issues USING (borrowernumber)
666
            LEFT JOIN issues USING (borrowernumber)|;
664
            LEFT JOIN issues USING (borrowernumber)|;
667
    if ( $filterpatronlist  ){
665
    if ( $filterpatronlist  ){
668
        $query .= q| LEFT JOIN patron_list_patrons USING (borrowernumber)|;
666
        $query .= q| LEFT JOIN patron_list_patrons USING (borrowernumber)|;
669
    }
667
    }
670
    $query .= q| WHERE  category_type <> 'S'
668
    $query .= q| WHERE  category_type <> 'S'
671
        AND tmp.guarantorid IS NULL
669
        AND tmp.guarantor_id IS NULL
672
    |;
670
    |;
673
    my @query_params;
671
    my @query_params;
674
    if ( $filterbranch && $filterbranch ne "" ) {
672
    if ( $filterbranch && $filterbranch ne "" ) {
(-)a/C4/SIP/ILS/Patron.pm (-1 lines)
Lines 616-622 __END__ Link Here
616
| contactname         | mediumtext   | YES  |     | NULL    |                |
616
| contactname         | mediumtext   | YES  |     | NULL    |                |
617
| contactfirstname    | text         | YES  |     | NULL    |                |
617
| contactfirstname    | text         | YES  |     | NULL    |                |
618
| contacttitle        | text         | YES  |     | NULL    |                |
618
| contacttitle        | text         | YES  |     | NULL    |                |
619
| guarantorid         | int(11)      | YES  | MUL | NULL    |                |
620
| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
619
| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
621
| relationship        | varchar(100) | YES  |     | NULL    |                |
620
| relationship        | varchar(100) | YES  |     | NULL    |                |
622
| ethnicity           | varchar(50)  | YES  |     | NULL    |                |
621
| ethnicity           | varchar(50)  | YES  |     | NULL    |                |
(-)a/Koha/Item.pm (+1 lines)
Lines 28-33 use C4::Context; Link Here
28
use Koha::Checkouts;
28
use Koha::Checkouts;
29
use Koha::IssuingRules;
29
use Koha::IssuingRules;
30
use Koha::Item::Transfer;
30
use Koha::Item::Transfer;
31
use Koha::Biblios;
31
use Koha::Patrons;
32
use Koha::Patrons;
32
use Koha::Libraries;
33
use Koha::Libraries;
33
34
(-)a/Koha/Object.pm (-2 / +6 lines)
Lines 72-79 sub new { Link Here
72
            next if not exists $attributes->{$column_name} or defined $attributes->{$column_name};
72
            next if not exists $attributes->{$column_name} or defined $attributes->{$column_name};
73
            delete $attributes->{$column_name};
73
            delete $attributes->{$column_name};
74
        }
74
        }
75
        $self->{_result} = $schema->resultset( $class->_type() )
75
76
          ->new($attributes);
76
        eval {
77
            $self->{_result} =
78
              $schema->resultset( $class->_type() )->new($attributes);
79
        };
80
        Carp::cluck("ERROR: $@") if $@;
77
    }
81
    }
78
82
79
    croak("No _type found! Koha::Object must be subclassed!")
83
    croak("No _type found! Koha::Object must be subclassed!")
(-)a/Koha/Patron.pm (-32 / +50 lines)
Lines 27-41 use Text::Unaccent qw( unac_string ); Link Here
27
use C4::Context;
27
use C4::Context;
28
use C4::Log;
28
use C4::Log;
29
use Koha::Checkouts;
29
use Koha::Checkouts;
30
use Koha::Old::Checkouts;
30
use Koha::Database;
31
use Koha::Database;
31
use Koha::DateUtils;
32
use Koha::DateUtils;
32
use Koha::Holds;
33
use Koha::Holds;
33
use Koha::Old::Checkouts;
34
use Koha::Patrons;
34
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
36
use Koha::Patron::Relationships;
35
use Koha::Patron::HouseboundProfile;
37
use Koha::Patron::HouseboundProfile;
36
use Koha::Patron::HouseboundRole;
38
use Koha::Patron::HouseboundRole;
37
use Koha::Patron::Images;
39
use Koha::Patron::Images;
38
use Koha::Patrons;
39
use Koha::Virtualshelves;
40
use Koha::Virtualshelves;
40
use Koha::Club::Enrollments;
41
use Koha::Club::Enrollments;
41
use Koha::Account;
42
use Koha::Account;
Lines 141-181 sub category { Link Here
141
    return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode );
142
    return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode );
142
}
143
}
143
144
144
=head3 guarantor
145
=head3 image
145
146
Returns a Koha::Patron object for this patron's guarantor
147
146
148
=cut
147
=cut
149
148
150
sub guarantor {
151
    my ( $self ) = @_;
152
153
    return unless $self->guarantorid();
154
155
    return Koha::Patrons->find( $self->guarantorid() );
156
}
157
158
sub image {
149
sub image {
159
    my ( $self ) = @_;
150
    my ( $self ) = @_;
160
151
161
    return scalar Koha::Patron::Images->find( $self->borrowernumber );
152
    return scalar Koha::Patron::Images->find( $self->borrowernumber );
162
}
153
}
163
154
155
=head3 library
156
157
=cut
158
164
sub library {
159
sub library {
165
    my ( $self ) = @_;
160
    my ( $self ) = @_;
166
    return Koha::Library->_new_from_dbic($self->_result->branchcode);
161
    return Koha::Library->_new_from_dbic($self->_result->branchcode);
167
}
162
}
168
163
169
=head3 guarantees
164
=head3 guarantor_relationships
165
166
Returns Koha::Patron::Relationships object for this patron's guarantors
170
167
171
Returns the guarantees (list of Koha::Patron) of this patron
168
Returns the set of relationships for the patrons that are guarantors for this patron.
169
170
This is returned instead of a Koha::Patron object because the guarantor
171
may not exist as a patron in Koha. If this is true, the guarantors name
172
exists in the Koha::Patron::Relationship object and will have no guarantor_id.
172
173
173
=cut
174
=cut
174
175
175
sub guarantees {
176
sub guarantor_relationships {
176
    my ( $self ) = @_;
177
    my ($self) = @_;
178
179
    return Koha::Patron::Relationships->search( { guarantee_id => $self->id } );
180
}
181
182
=head3 guarantee_relationships
183
184
Returns Koha::Patron::Relationships object for this patron's guarantors
185
186
Returns the set of relationships for the patrons that are guarantees for this patron.
187
188
The method returns Koha::Patron::Relationship objects for the sake
189
of consistency with the guantors method.
190
A guarantee by definition must exist as a patron in Koha.
191
192
=cut
193
194
sub guarantee_relationships {
195
    my ($self) = @_;
177
196
178
    return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
197
    return Koha::Patron::Relationships->search( { guarantor_id => $self->id } );
179
}
198
}
180
199
181
=head3 housebound_profile
200
=head3 housebound_profile
Lines 213-235 Returns the siblings of this patron. Link Here
213
=cut
232
=cut
214
233
215
sub siblings {
234
sub siblings {
216
    my ( $self ) = @_;
235
    my ($self) = @_;
217
236
218
    my $guarantor = $self->guarantor;
237
    my @guarantors = $self->guarantor_relationships()->guarantors();
219
238
220
    return unless $guarantor;
239
    return unless @guarantors;
221
240
222
    return Koha::Patrons->search(
241
    my @siblings =
223
        {
242
      map { $_->guarantee_relationships()->guarantees() } @guarantors;
224
            guarantorid => {
243
225
                '!=' => undef,
244
    return unless @siblings;
226
                '=' => $guarantor->id,
245
227
            },
246
    my %seen;
228
            borrowernumber => {
247
    @siblings =
229
                '!=' => $self->borrowernumber,
248
      grep { !$seen{ $_->id }++ && ( $_->id != $self->id ) } @siblings;
230
            }
249
231
        }
250
    return wantarray ? @siblings : Koha::Patrons->search( { borrowernumber => { -in => [ map { $_->id } @siblings ] } } );
232
    );
233
}
251
}
234
252
235
=head3 merge_with
253
=head3 merge_with
(-)a/Koha/Patron/Relationship.pm (+73 lines)
Line 0 Link Here
1
package Koha::Patron::Relationship;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Patron::Relationship - A class to represent relationships between patrons
29
30
Patrons in Koha may be guarantors or guarantees. This class models that relationship
31
and provides a way to access those relationships.
32
33
=head1 API
34
35
=head2 Class Methods
36
37
=cut
38
39
=head3 guarantor
40
41
Returns the Koha::Patron object for the guarantor, if there is one
42
43
=cut
44
45
sub guarantor {
46
    my ( $self ) = @_;
47
48
    return unless $self->guarantor_id;
49
50
    return scalar Koha::Patrons->find( $self->guarantor_id );
51
}
52
53
=head3 guarantee
54
55
Returns the Koha::Patron object for the guarantee
56
57
=cut
58
59
sub guarantee {
60
    my ( $self ) = @_;
61
62
    return scalar Koha::Patrons->find( $self->guarantee_id );
63
}
64
65
=head3 type
66
67
=cut
68
69
sub _type {
70
    return 'Relationship';
71
}
72
73
1;
(-)a/Koha/Patron/Relationships.pm (+94 lines)
Line 0 Link Here
1
package Koha::Patron::Relationships;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
use List::MoreUtils qw( uniq );
22
23
use Koha::Database;
24
use Koha::Patrons;
25
use Koha::Patron::Relationship;
26
27
use base qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::Patron::Relationships - Koha Patron Relationship Object set class
32
33
=head1 API
34
35
=head2 Class Methods
36
37
=cut
38
39
=head3 guarantors
40
41
Returns all the guarantors in this set of relationships as a list of Koha::Patron objects
42
or as a Koha::Patrons object depending on the calling context
43
44
=cut
45
46
sub guarantors {
47
    my ($self) = @_;
48
49
    my $rs = $self->_resultset();
50
51
    my @guarantor_ids = $rs->get_column('guarantor_id')->all();
52
    # Guarantors may not have a guarantor_id, strip out undefs
53
    @guarantor_ids = grep { defined $_ } @guarantor_ids;
54
    @guarantor_ids = uniq( @guarantor_ids );
55
56
    my $guarantors = Koha::Patrons->search( { borrowernumber => \@guarantor_ids } );
57
58
    return wantarray ? $guarantors->as_list : $guarantors;
59
}
60
61
=head3 guarantees
62
63
Returns all the guarantees in this set of relationships as a list of Koha::Patron objects
64
or as a Koha::Patrons object depending on the calling context
65
66
=cut
67
68
sub guarantees {
69
    my ($self) = @_;
70
71
    my $rs = $self->_resultset();
72
73
    my @guarantee_ids = uniq( $rs->get_column('guarantee_id')->all() );
74
75
    my $guarantees = Koha::Patrons->search( { borrowernumber => \@guarantee_ids } );
76
77
    return wantarray ? $guarantees->as_list : $guarantees;
78
}
79
80
=cut
81
82
=head3 type
83
84
=cut
85
86
sub _type {
87
    return 'Relationship';
88
}
89
90
sub object_class {
91
    return 'Koha::Patron::Relationship';
92
}
93
94
1;
(-)a/Koha/Patrons.pm (-12 lines)
Lines 124-141 sub search_upcoming_membership_expires { Link Here
124
    );
124
    );
125
}
125
}
126
126
127
=head3 guarantor
128
129
Returns a Koha::Patron object for this borrower's guarantor
130
131
=cut
132
133
sub guarantor {
134
    my ( $self ) = @_;
135
136
    return Koha::Patrons->find( $self->guarantorid() );
137
}
138
139
=head3 search_patrons_to_anonymise
127
=head3 search_patrons_to_anonymise
140
128
141
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
129
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
(-)a/Koha/Patrons/Import.pm (+23 lines)
Lines 213-218 sub import_patrons { Link Here
213
            next LINE;
213
            next LINE;
214
        }
214
        }
215
215
216
        my $relationship        = $borrower{relationship};
217
        my $guarantor_id        = $borrower{guarantor_id};
218
        my $guarantor_firstname = $borrower{guarantor_firstname};
219
        my $guarantor_surname   = $borrower{guarantor_surname};
220
        delete $borrower{relationship};
221
        delete $borrower{guarantor_id};
222
        delete $borrower{guarantor_firstname};
223
        delete $borrower{guarantor_surname};
224
216
        if ($borrowernumber) {
225
        if ($borrowernumber) {
217
226
218
            # borrower exists
227
            # borrower exists
Lines 348-353 sub import_patrons { Link Here
348
                );
357
                );
349
            }
358
            }
350
        }
359
        }
360
361
        # Add a guarantor if we are given a relationship
362
        if ( $relationship ) {
363
            $guarantor_id ||= undef;
364
            Koha::Patron::Relationship->new(
365
                {
366
                    guarantee_id => $borrowernumber,
367
                    relationship => $relationship,
368
                    guarantor_id => $guarantor_id,
369
                    firstname    => $guarantor_firstname,
370
                    surname      => $guarantor_surname,
371
                }
372
            )->store();
373
        }
351
    }
374
    }
352
375
353
    return {
376
    return {
(-)a/Koha/Schema/Result/Borrower.pm (-6 lines)
Lines 1419-1430 __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); Link Here
1419
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-06 14:12:40
1419
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-06 14:12:40
1420
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LaQWPXzF1Amzt8fgEEyHdg
1420
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LaQWPXzF1Amzt8fgEEyHdg
1421
1421
1422
__PACKAGE__->belongs_to(
1423
    "guarantor",
1424
    "Koha::Schema::Result::Borrower",
1425
    { borrowernumber => "guarantorid" },
1426
);
1427
1428
__PACKAGE__->add_columns(
1422
__PACKAGE__->add_columns(
1429
    '+lost' => { is_boolean => 1 },
1423
    '+lost' => { is_boolean => 1 },
1430
    '+gonenoaddress' => { is_boolean => 1 }
1424
    '+gonenoaddress' => { is_boolean => 1 }
(-)a/Koha/Schema/Result/Relationship.pm (+132 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::Relationship;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::Relationship
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<relationships>
19
20
=cut
21
22
__PACKAGE__->table("relationships");
23
24
=head1 ACCESSORS
25
26
=head2 id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 guarantor_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 1
37
38
=head2 guarantee_id
39
40
  data_type: 'integer'
41
  is_foreign_key: 1
42
  is_nullable: 0
43
44
=head2 relationship
45
46
  data_type: 'varchar'
47
  is_nullable: 0
48
  size: 100
49
50
=head2 surname
51
52
  data_type: 'mediumtext'
53
  is_nullable: 1
54
55
=head2 firstname
56
57
  data_type: 'mediumtext'
58
  is_nullable: 1
59
60
=cut
61
62
__PACKAGE__->add_columns(
63
  "id",
64
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
65
  "guarantor_id",
66
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
67
  "guarantee_id",
68
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
69
  "relationship",
70
  { data_type => "varchar", is_nullable => 0, size => 100 },
71
  "surname",
72
  { data_type => "mediumtext", is_nullable => 1 },
73
  "firstname",
74
  { data_type => "mediumtext", is_nullable => 1 },
75
);
76
77
=head1 PRIMARY KEY
78
79
=over 4
80
81
=item * L</id>
82
83
=back
84
85
=cut
86
87
__PACKAGE__->set_primary_key("id");
88
89
=head1 RELATIONS
90
91
=head2 guarantee
92
93
Type: belongs_to
94
95
Related object: L<Koha::Schema::Result::Borrower>
96
97
=cut
98
99
__PACKAGE__->belongs_to(
100
  "guarantee",
101
  "Koha::Schema::Result::Borrower",
102
  { borrowernumber => "guarantee_id" },
103
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
104
);
105
106
=head2 guarantor
107
108
Type: belongs_to
109
110
Related object: L<Koha::Schema::Result::Borrower>
111
112
=cut
113
114
__PACKAGE__->belongs_to(
115
  "guarantor",
116
  "Koha::Schema::Result::Borrower",
117
  { borrowernumber => "guarantor_id" },
118
  {
119
    is_deferrable => 1,
120
    join_type     => "LEFT",
121
    on_delete     => "CASCADE",
122
    on_update     => "CASCADE",
123
  },
124
);
125
126
127
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-05-03 13:19:34
128
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2Nv437KMrKHvpQleXLOjYw
129
130
131
# You can replace this text with custom code or comments, and it will be preserved on regeneration
132
1;
(-)a/api/v1/swagger/definitions/patron.json (-4 lines)
Lines 159-168 Link Here
159
      "readOnly": true,
159
      "readOnly": true,
160
      "description": "If any restriction applies to the patron"
160
      "description": "If any restriction applies to the patron"
161
    },
161
    },
162
    "guarantor_id": {
163
      "type": ["integer", "null"],
164
      "description": "patron_id used for children or professionals to link them to guarantor or organizations"
165
    },
166
    "staff_notes": {
162
    "staff_notes": {
167
      "type": ["string", "null"],
163
      "type": ["string", "null"],
168
      "description": "a note on the patron's account"
164
      "description": "a note on the patron's account"
(-)a/circ/circulation.pl (-8 / +6 lines)
Lines 571-584 my $view = $batch Link Here
571
    : 'circview';
571
    : 'circview';
572
572
573
my @relatives;
573
my @relatives;
574
if ( $borrowernumber ) {
574
if ( $patron ) {
575
    if ( $patron ) {
575
    if ( my @guarantors = $patron->guarantor_relationships()->guarantors() ) {
576
        if ( my $guarantor = $patron->guarantor ) {
576
        push( @relatives, $_->id ) for @guarantors;
577
            push @relatives, $guarantor->borrowernumber;
577
        push( @relatives, $_->id ) for $patron->siblings();
578
            push @relatives, $_->borrowernumber for $patron->siblings;
578
    } else {
579
        } else {
579
        push( @relatives, $_->id ) for $patron->guarantee_relationships()->guarantees();
580
            push @relatives, $_->borrowernumber for $patron->guarantees;
581
        }
582
    }
580
    }
583
}
581
}
584
my $relatives_issues_count =
582
my $relatives_issues_count =
(-)a/installer/data/mysql/atomicupdate/bug_14570.sql (+17 lines)
Line 0 Link Here
1
CREATE TABLE `relationships` (
2
      id INT(11) NOT NULL AUTO_INCREMENT,
3
      guarantor_id INT(11) NULL DEFAULT NULL,
4
      guarantee_id INT(11) NOT NULL,
5
      relationship VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL,
6
      surname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
7
      firstname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
8
      PRIMARY KEY (id),
9
      CONSTRAINT r_guarantor FOREIGN KEY ( guarantor_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE,
10
      CONSTRAINT r_guarantee FOREIGN KEY ( guarantee_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
11
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
12
13
UPDATE borrowers LEFT JOIN borrowers guarantor ON ( borrowers.guarantorid = guarantor.borrowernumber ) SET borrowers.guarantorid = NULL WHERE guarantor.borrowernumber IS NULL;
14
15
INSERT INTO relationships ( guarantor_id, guarantee_id, relationship, surname, firstname ) SELECT guarantorid, borrowernumber, relationship, contactname, contactfirstname FROM borrowers WHERE guarantorid IS NOT NULL OR contactname != "";
16
17
ALTER TABLE borrowers DROP guarantorid, DROP relationship, DROP contactname, DROP contactfirstname, DROP contacttitle;
(-)a/installer/data/mysql/kohastructure.sql (-16 / +17 lines)
Lines 579-590 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower Link Here
579
  `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
579
  `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
580
  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD)
580
  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD)
581
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
581
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
582
  `contactname` LONGTEXT, -- used for children and profesionals to include surname or last name of guarantor or organization name
583
  `contactfirstname` MEDIUMTEXT, -- used for children to include first name of guarantor
584
  `contacttitle` MEDIUMTEXT, -- used for children to include title (Mr., Mrs., etc) of guarantor
585
  `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarantors or organizations
586
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
582
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
587
  `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
588
  `sex` varchar(1) default NULL, -- patron/borrower's gender
583
  `sex` varchar(1) default NULL, -- patron/borrower's gender
589
  `password` varchar(60) default NULL, -- patron/borrower's encrypted password
584
  `password` varchar(60) default NULL, -- patron/borrower's encrypted password
590
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
585
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
Lines 1609-1620 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1609
  `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
1604
  `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
1610
  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD)
1605
  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD)
1611
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1606
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1612
  `contactname` LONGTEXT, -- used for children and profesionals to include surname or last name of guarantor or organization name
1613
  `contactfirstname` MEDIUMTEXT, -- used for children to include first name of guarantor
1614
  `contacttitle` MEDIUMTEXT, -- used for children to include title (Mr., Mrs., etc) of guarantor
1615
  `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarantors or organizations
1616
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
1607
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
1617
  `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
1618
  `sex` varchar(1) default NULL, -- patron/borrower's gender
1608
  `sex` varchar(1) default NULL, -- patron/borrower's gender
1619
  `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1609
  `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1620
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
1610
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
Lines 1647-1653 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1647
  KEY `categorycode` (`categorycode`),
1637
  KEY `categorycode` (`categorycode`),
1648
  KEY `branchcode` (`branchcode`),
1638
  KEY `branchcode` (`branchcode`),
1649
  UNIQUE KEY `userid` (`userid`),
1639
  UNIQUE KEY `userid` (`userid`),
1650
  KEY `guarantorid` (`guarantorid`),
1651
  KEY `surname_idx` (`surname` (191)),
1640
  KEY `surname_idx` (`surname` (191)),
1652
  KEY `firstname_idx` (`firstname` (191)),
1641
  KEY `firstname_idx` (`firstname` (191)),
1653
  KEY `othernames_idx` (`othernames` (191)),
1642
  KEY `othernames_idx` (`othernames` (191)),
Lines 3428-3439 CREATE TABLE IF NOT EXISTS `borrower_modifications` ( Link Here
3428
  `lost` tinyint(1) DEFAULT NULL,
3417
  `lost` tinyint(1) DEFAULT NULL,
3429
  `debarred` date DEFAULT NULL,
3418
  `debarred` date DEFAULT NULL,
3430
  `debarredcomment` varchar(255) DEFAULT NULL,
3419
  `debarredcomment` varchar(255) DEFAULT NULL,
3431
  `contactname` LONGTEXT,
3432
  `contactfirstname` MEDIUMTEXT,
3433
  `contacttitle` MEDIUMTEXT,
3434
  `guarantorid` int(11) DEFAULT NULL,
3435
  `borrowernotes` LONGTEXT,
3420
  `borrowernotes` LONGTEXT,
3436
  `relationship` varchar(100) DEFAULT NULL,
3437
  `sex` varchar(1) DEFAULT NULL,
3421
  `sex` varchar(1) DEFAULT NULL,
3438
  `password` varchar(30) DEFAULT NULL,
3422
  `password` varchar(30) DEFAULT NULL,
3439
  `flags` int(11) DEFAULT NULL,
3423
  `flags` int(11) DEFAULT NULL,
Lines 4113-4118 CREATE TABLE IF NOT EXISTS club_fields ( Link Here
4113
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4097
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4114
4098
4115
--
4099
--
4100
-- Table structure for table 'guarantors_guarantees'
4101
--
4102
4103
DROP TABLE IF EXISTS relationships;
4104
CREATE TABLE `relationships` (
4105
      id INT(11) NOT NULL AUTO_INCREMENT,
4106
      guarantor_id INT(11) NULL DEFAULT NULL,
4107
      guarantee_id INT(11) NOT NULL,
4108
      relationship VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL,
4109
      surname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
4110
      firstname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
4111
      PRIMARY KEY (id),
4112
      CONSTRAINT r_guarantor FOREIGN KEY ( guarantor_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE,
4113
      CONSTRAINT r_guarantee FOREIGN KEY ( guarantee_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
4114
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4115
4116
--
4116
-- Table structure for table `illrequests`
4117
-- Table structure for table `illrequests`
4117
--
4118
--
4118
4119
(-)a/koha-tmpl/intranet-tmpl/prog/en/columns.def (-1 lines)
Lines 7-13 Link Here
7
<field name="borrowers.othernames">Other name</field>
7
<field name="borrowers.othernames">Other name</field>
8
<field name="borrowers.sex">Gender</field>
8
<field name="borrowers.sex">Gender</field>
9
<field name="borrowers.relationship">Relationship</field>
9
<field name="borrowers.relationship">Relationship</field>
10
<field name="borrowers.guarantorid">Guarantor borrower number</field>
11
<field name="borrowers.streetnumber">Street number</field>
10
<field name="borrowers.streetnumber">Street number</field>
12
<field name="borrowers.streettype">Street type</field>
11
<field name="borrowers.streettype">Street type</field>
13
<field name="borrowers.address">Address</field>
12
<field name="borrowers.address">Address</field>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-9 / +5 lines)
Lines 6-26 Link Here
6
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
6
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
7
<div id="toolbar" class="btn-toolbar">
7
<div id="toolbar" class="btn-toolbar">
8
    [% IF CAN_user_borrowers_edit_borrowers %]
8
    [% IF CAN_user_borrowers_edit_borrowers %]
9
        [% IF ( guarantor ) %]
9
        <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]">
10
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% patron.borrowernumber %]&amp;guarantorid=[% guarantor.borrowernumber %]&amp;categorycode=[% patron.categorycode %]">
10
            <i class="fa fa-pencil"></i> Edit
11
        [% ELSE %]
11
        </a>
12
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]">
13
        [% END %]
14
        <i class="fa fa-pencil"></i> Edit</a>
15
    [% END %]
12
    [% END %]
16
13
17
    [% IF CAN_user_borrowers_edit_borrowers %]
14
    [% IF CAN_user_borrowers_edit_borrowers %]
18
        [% IF patron.is_adult AND Koha.Preference("borrowerRelationship") %]
15
        [% IF patron.is_adult AND Koha.Preference("borrowerRelationship") %]
19
            <a id="addchild" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;guarantorid=[% patron.borrowernumber %]"><i class="fa fa-plus"></i> Add child</a>
16
            <a id="addchild" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;guarantorid=[% patron.borrowernumber %]"><i class="fa fa-plus"></i> Add child</a>
20
        [% END %]
17
        [% END %]
21
        [% IF CAN_user_borrowers_edit_borrowers %]
18
22
            <a id="changepassword" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/member-password.pl?member=[% patron.borrowernumber %]"><i class="fa fa-lock"></i> Change password</a>
19
        <a id="changepassword" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/member-password.pl?member=[% patron.borrowernumber %]"><i class="fa fa-lock"></i> Change password</a>
23
        [% END %]
24
        <a id="duplicate" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=duplicate&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]"><i class="fa fa-copy"></i> Duplicate</a>
20
        <a id="duplicate" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=duplicate&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]"><i class="fa fa-copy"></i> Duplicate</a>
25
    [% END %]
21
    [% END %]
26
22
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +1 lines)
Lines 807-813 No patron matched <span class="ex">[% message | html %]</span> Link Here
807
    </li>
807
    </li>
808
808
809
    [% IF relatives_issues_count %]
809
    [% IF relatives_issues_count %]
810
        <li><a id="relatives-issues-tab" href="#relatives-issues">Relatives' checkouts</a></li>
810
        <li><a id="relatives-issues-tab" href="#relatives-issues">[% relatives_issues_count %] Relatives' checkouts</a></li>
811
    [% END %]
811
    [% END %]
812
812
813
    <li>
813
    <li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-103 / +169 lines)
Lines 1-4 Link Here
1
[% USE Asset %]
1
[% USE Asset %]
2
[% USE To %]
2
[% USE Koha %]
3
[% USE Koha %]
3
[% USE KohaDates %]
4
[% USE KohaDates %]
4
[% USE Branches %]
5
[% USE Branches %]
Lines 297-409 Link Here
297
	</fieldset>
298
	</fieldset>
298
[% END # hide fieldset %]
299
[% END # hide fieldset %]
299
300
300
[% IF ( showguarantor ) %]
301
[% IF show_guarantor || guarantor %]
301
    <input type="hidden" id="guarantorid" name="guarantorid"   value="[% guarantorid %]" />
302
    [% SET possible_relationships = Koha.Preference('borrowerRelationship') %]
302
    [% UNLESS step_6 %]
303
    <fieldset class="rows">
303
        <input type="hidden" name="branchcode" value="[% branchcode %]" />
304
        <legend>Guarantor information</legend>
304
    [% END %]
305
305
    <fieldset id="memberentry_guarantor" class="rows">
306
        <span id="guarantor_relationships">
306
        <legend id="guarantor_lgd">Guarantor information</legend>
307
            [% FOREACH r IN relationships %]
307
        <ol>
308
                <fieldset class="rows">
308
[% IF ( P ) %]
309
                    <ol>
309
	        [% IF ( guarantorid ) %]
310
                        [% IF category_type == 'P' %]
310
	        <li id="contact-details">
311
                            [% IF ( r.guarantor_id ) %]
311
	        [% ELSE %]
312
                                <li id="contact-details">
312
	        <li id="contact-details" style="display: none">
313
                            [% ELSE %]
313
	        [% END %]
314
                                <li id="contact-details" style="display: none">
314
	            <span class="label">Organization #:</span> [% IF ( guarantorid ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorid %]" target="blank">[% guarantorid %]</a>[% END %]
315
                            [% END %]
315
	        </li>
316
                                <span class="label">Organization #:</span> [% IF ( r.guarantor_id ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% r.guarantor_id %]" target="blank">[% r.guarantor_id %]</a>[% END %]
316
	        <li>
317
                            </li>
317
	            <label for="contactname">Organization name: </label>
318
318
	            [% IF ( guarantorid ) %]
319
                            <li>
319
	            <span>[% contactname %]</span>
320
                                <label for="guarantor_surname">Organization name: </label>
320
	            <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname | html %]" />
321
                                [% IF ( r.guarantor_id ) %]
321
	            [% ELSE %]
322
                                    <span>[% r.guarantor.surname %]</span>
322
                    <input name="contactname" id="contactname" type="text" size="20" value="[% contactname | html %]" />
323
                                [% END %]
323
	            [% END %]
324
                            </li>
324
	        </li>
325
                        [% ELSE %]
325
[% ELSE %]
326
                            [% IF ( r.guarantor_id ) %]
326
 [% IF ( C ) %]
327
                                <li id="contact-details">
327
 [% IF ( guarantorid ) %]
328
                            [% ELSE %]
328
 <li id="contact-details">
329
                                <li id="contact-details" style="display: none">
329
 [% ELSE %]
330
                            [% END %]
330
 <li id="contact-details" style="display: none">
331
331
 [% END %]
332
                                <span class="label">Patron #:</span>
332
     <span class="label">Patron #:</span>
333
                                [% IF ( r.guarantor_id ) %]
333
     [% IF guarantorid %]
334
                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% r.guarantor_id %]" target="blank">[% r.guarantor_id %]</a>
334
        [% IF logged_in_user.can_see_patron_infos( guarantor ) %]
335
                                [% END %]
335
            <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorid %]" target="blank">[% guarantorid | html %]</a>
336
336
        [% ELSE %]
337
                            </li>
337
            [% guarantorid | html %]
338
338
        [% END %]
339
                            [% IF r.surname || r.guarantor.surname %]
339
    [% END %]
340
                                <li>
340
 </li>
341
                                    <label for="guarantor_surname">Surname: </label>
341
        [% UNLESS nocontactname %]
342
                                    <span>[% r.surname || r.guarantor.surname %]</span>
342
 <li>
343
                                </li>
343
     <label for="contactname">Surname: </label>
344
                            [% END %]
344
     [% IF ( guarantorid ) %]
345
345
     <span>[% contactname %]</span>
346
                            [% IF r.firstname || r.guarantor.firstname  %]
346
     <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname | html %]" />
347
                                <li>
347
     [% ELSE %]
348
                                    <label for="guarantor_firstname">First name: </label>
348
        <input name="contactname" id="contactname" type="text" size="20" value="[% contactname | html %]" />
349
                                    <span>[% r.firstname || r.guarantor.firstname %]</span>
349
     [% END %]
350
                                </li>
350
 </li>
351
                            [% END %]
351
        [% END %]
352
352
        [% UNLESS nocontactfirstname %]
353
                            <li>
353
 <li>
354
                                <label for="relationship">Relationship: </label>
354
     <label for="contactfirstname">First name: </label>
355
                                <span>[% r.relationship %]</span>
355
     [% IF ( guarantorid ) %]
356
                            </li>
356
     <span>[% contactfirstname %]</span>
357
357
     <input name="contactfirstname" id="contactfirstname" type="hidden" size="20" value="[% contactfirstname | html %]" />
358
                            <li>
358
     [% ELSE %]
359
                                <label for="delete_guarantor">Delete: </label>
359
        <input name="contactfirstname" id="contactfirstname" type="text" size="20" value="[% contactfirstname | html %]" />
360
                                <input type="checkbox" name="delete_guarantor" value="[% r.id %]" />
360
     [% END %]
361
                            </li>
361
 </li>
362
                        [% END %]
362
        [% END %]
363
                    </ol>
363
 [% IF ( relshiploop ) %]
364
                </fieldset>
364
 <li>
365
            [% END # END relationships foreach %]
365
     <label for="relationship">Relationship: </label>
366
        </span>
366
     <select name="relationship" id="relationship" >
367
367
         [% FOREACH relshiploo IN relshiploop %]
368
        <fieldset class="rows guarantor" id="guarantor_template">
368
         [% IF ( relshiploo.selected ) %]
369
            <ol>
369
         <option value="[% relshiploo.relationship %]" selected="selected" >[% relshiploo.relationship %]</option>
370
                <li class="guarantor_id">
370
         [% ELSE %]
371
                    <span class="label">Patron #:</span>
371
         <option value="[% relshiploo.relationship %]">[% relshiploo.relationship %]</option>
372
                    <span class="new_guarantor_id_text"></span>
372
         [% END %]
373
                    <input type="hidden" class="new_guarantor_id" name="new_guarantor_id" value=""/>
373
         [% END %]
374
                </li>
374
     </select>
375
375
 </li>
376
                <li>
376
 [% END %]
377
                    <label for="guarantor_surname">Surname: </label>
377
 [% END %]
378
                    <span class="new_guarantor_surname_text"></span>
378
[% END %]
379
                    <input type="hidden" class="new_guarantor_surname" name="new_guarantor_surname" value=""/>
379
        <li>
380
                </li>
380
            <span class="label">&nbsp;</span>
381
381
            [% IF ( guarantorid ) %]
382
                <li>
382
            <input id="guarantorsearch" type="button" value="Change" onclick="Dopopguarantor('guarantor_search.pl');" />
383
                    <label for="guarantor_firstname">First name: </label>
383
            [% ELSE %]
384
                    <span class="new_guarantor_firstname_text"></span>
384
            <input id="guarantorsearch" type="button" value="Set to patron" onclick="Dopopguarantor('guarantor_search.pl');" />
385
                    <input type="hidden" class="new_guarantor_firstname" name="new_guarantor_firstname" value=""/>
385
            [% END %]
386
                </li>
386
            <input id="guarantordelete" type="button" value="Delete" />
387
387
        </li>
388
                <li>
388
    [% IF guarantorid && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
389
                    <label for="guarantor_relationship">Relationship: </label>
389
        <li>
390
                    <select class="new_guarantor_relationship" name="new_guarantor_relationship">
390
            <label for="privacy_guarantor_checkouts">Show checkouts to guarantor</label>
391
                        [% FOREACH pr IN possible_relationships.split('\|') %]
391
            <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
392
                            <option value="[% pr %]">[% pr %]</option>
392
                [% IF privacy_guarantor_checkouts %]
393
                        [% END %]
393
                    <option value="0">No</option>
394
                    </select>
394
                    <option value="1" selected>Yes</option>
395
                </li>
396
397
                <li>
398
                    <label for="guarantor_cancel">&nbsp;</label>
399
                    <span><a href="#" class="guarantor_cancel">Cancel</a></span>
400
                </li>
401
            </ol>
402
        </fieldset>
403
404
        <fieldset class="rows">
405
            <legend>Add new guarantor</legend>
406
            <ol>
407
                <input type="hidden" id="guarantor_id" value=""/>
408
409
                [% IF catetory_type == 'P' %]
410
                    <li>
411
                        <label for="guarantor_surname">Organization name: </label>
412
                        <input name="guarantor_surname" id="guarantor_surname" type="hidden" size="20"/>
413
                    </li>
395
                [% ELSE %]
414
                [% ELSE %]
396
                    <option value="0" selected>No</option>
415
                    <li>
397
                    <option value="1">Yes</option>
416
                        <label for="guarantor_surname">Surname: </label>
417
                        <input name="guarantor_surname" id="guarantor_surname" type="text" size="20" />
418
                    </li>
419
420
                    <li>
421
                        <label for="guarantor_firstname">First name: </label>
422
                        <input name="guarantor_firstname" id="guarantor_firstname" type="text" size="20" />
423
                    </li>
424
425
                    [% IF ( possible_relationships ) %]
426
                        <li>
427
                            <label for="relationship">Relationship: </label>
428
                            <select name="relationship" id="relationship" >
429
                                [% FOREACH pr IN possible_relationships.split('\|') %]
430
                                    <option value="[% pr %]">[% pr %]</option>
431
                                [% END %]
432
                            </select>
433
                        </li>
434
                    [% END %]
398
                [% END %]
435
                [% END %]
399
            </select>
400
            <div class="hint">Allow guarantor of this patron to view this patron's checkouts from the OPAC</div>
401
        </li>
402
    [% END %]
403
        </ol>
404
    </fieldset>
405
436
437
                <li>
438
                    <span class="label">&nbsp;</span>
439
                    <a href="#" id="guarantor_add" class="btn btn-sm"><i class="fa fa-plus"></i> Add guarantor</a>
440
                    <a href="#" id="guarantor_search" class="btn btn-sm"><i class="fa fa-search"></i> Set to patron</a>
441
                    <a href="#" id="guarantor_clear">Clear</a>
442
                </li>
443
444
                [% IF relationships && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
445
                    <li>
446
                        <label for="privacy_guarantor_checkouts">Show checkouts to guarantors</label>
447
                        <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
448
                            [% IF privacy_guarantor_checkouts %]
449
                                <option value="0">No</option>
450
                                <option value="1" selected>Yes</option>
451
                            [% ELSE %]
452
                                <option value="0" selected>No</option>
453
                                <option value="1">Yes</option>
454
                            [% END %]
455
                        </select>
456
                        <div class="hint">Allow guarantors of this patron to view this patron's checkouts from the OPAC</div>
457
                    </li>
458
                [% END %]
459
            </ol>
460
        </fieldset>
461
    </fieldset>
406
[% END %]
462
[% END %]
463
464
407
[% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
465
[% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
408
    [% IF Koha.Preference( 'AddressFormat' ) %]
466
    [% IF Koha.Preference( 'AddressFormat' ) %]
409
        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
467
        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
Lines 1193-1198 Link Here
1193
                    update_category_code( category_code );
1251
                    update_category_code( category_code );
1194
                }
1252
                }
1195
            [% END %]
1253
            [% END %]
1254
1255
            [% IF guarantor %]
1256
                select_user( '[% guarantor.borrowernumber %]', [% To.json( guarantor.unblessed ) %] );
1257
                $('#guarantor_add').ready(function() {
1258
                    $('#guarantor_add').click();
1259
                });
1260
            [% END %]
1261
1196
        });
1262
        });
1197
1263
1198
        function update_cardnumber_warning(size){
1264
        function update_cardnumber_warning(size){
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt (-2 / +21 lines)
Lines 47-54 Link Here
47
            <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>
47
            <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>
48
        [% END %]
48
        [% END %]
49
    [% ELSE %]
49
    [% ELSE %]
50
        [% IF ( guarantor.borrowernumber ) %]
50
        [% IF guarantees %]
51
            <li><span class="label">Guarantor:</span><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.surname %], [% guarantor.firstname %]</a></li>
51
            <li>
52
                <span class="label">Guarantees:</span>
53
                <ul>
54
                    [% FOREACH guarantee IN guarantees %]
55
                        <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantee.borrowernumber %]">[% guarantee.firstname %] [% guarantee.surname %]</a></li>
56
                    [% END %]
57
                </ul>
58
            </li>
59
        [% ELSIF guarantor_relationships %]
60
            [% FOREACH gr IN guarantor_relationships %]
61
                <li>
62
                    <span class="label">Guarantor:</span>
63
                    [% IF gr.guarantor_id %]
64
                        [% SET guarantor = gr.guarantor %]
65
                        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.id %]">[% guarantor.firstname %] [% guarantor.surname %]</a>
66
                    [% ELSE %]
67
                        [% gr.firstname %] [% gr.surname %]
68
                    [% END %]
69
                </li>
70
            [% END %]
52
        [% END %]
71
        [% END %]
53
    [% END %]
72
    [% END %]
54
	</ol>
73
	</ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-9 / +14 lines)
Lines 218-232 Link Here
218
                                                    [% END %]
218
                                                    [% END %]
219
                                                </ul>
219
                                                </ul>
220
                                            </li>
220
                                            </li>
221
                                        [% ELSIF guarantor %]
221
                                        [% ELSIF guarantor_relationships %]
222
                                            <li>
222
                                            [% FOREACH gr IN guarantor_relationships %]
223
                                                <span class="label">Guarantor:</span>
223
                                                <li>
224
                                                [% IF guarantor.borrowernumber AND logged_in_user.can_see_patron_infos( guarantor ) %]
224
                                                    <span class="label">Guarantor:</span>
225
                                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.firstname | html %] [% guarantor.surname | html %]</a>
225
                                                    [% IF gr.guarantor_id %]
226
                                                [% ELSE %]
226
                                                        [% SET guarantor = gr.guarantor %]
227
                                                    [% guarantor.firstname | html %] [% guarantor.surname | html %]
227
                                                        [% IF logged_in_user.can_see_patron_infos( guarantor ) %]
228
                                                [% END %]
228
                                                            <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.id %]">[% guarantor.firstname | html %] [% guarantor.surname | html %]</a>
229
                                            </li>
229
                                                        [% END %]
230
                                                    [% ELSE %]
231
                                                        [% gr.firstname | html %] [% gr.surname | html %]
232
                                                    [% END %]
233
                                                </li>
234
                                            [% END %]
230
                                        [% END %]
235
                                        [% END %]
231
                                    </ol>
236
                                    </ol>
232
                                </div> [% # /div.rows %]
237
                                </div> [% # /div.rows %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (-52 / +53 lines)
Lines 129-138 function Dopop(link) { Link Here
129
    var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=no,top');
129
    var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=no,top');
130
}
130
}
131
131
132
function Dopopguarantor(link) {
133
    var newin=window.open(link,'popup','width=800,height=500,resizable=no,toolbar=false,scrollbars=yes,top');
134
}
135
136
function clear_entry(node) {
132
function clear_entry(node) {
137
    var original = $(node).parent();
133
    var original = $(node).parent();
138
    $("textarea", original).attr('value', '');
134
    $("textarea", original).attr('value', '');
Lines 170-217 function update_category_code(category_code) { Link Here
170
}
166
}
171
167
172
function select_user(borrowernumber, borrower) {
168
function select_user(borrowernumber, borrower) {
173
    var form = $('#entryform').get(0);
169
    $('#guarantor_id').val(borrower.borrowernumber);
174
    if (form.guarantorid.value) {
170
    $('#guarantor_surname').val(borrower.surname);
175
        $("#contact-details, #quick_add_form #contact-details").find('a').remove();
171
    $('#guarantor_firstname').val(borrower.firstname);
176
        $("#contactname, #contactfirstname, #quick_add_form #contactname, #quick_add_form #contactfirstname").parent().find('span').remove();
177
    }
178
172
179
    var id = borrower.borrowernumber;
173
    $('#guarantor_add').click();
180
    form.guarantorid.value = id;
181
    $('#contact-details, #quick_add_form #contact-details')
182
        .show()
183
        .find('span')
184
        .after('<a target="blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + id + '">' + id + '</a>');
185
186
    $(form.contactname)
187
        .val(borrower.surname)
188
        .before('<span>' + borrower.surname + '</span>').get(0).type = 'hidden';
189
    $("#quick_add_form #contactname").val(borrower.surname).before('<span>'+borrower.surname+'</span.').attr({type:"hidden"});
190
    $(form.contactfirstname,"#quick_add_form #contactfirstname")
191
        .val(borrower.firstname)
192
        .before('<span>' + borrower.firstname + '</span>').get(0).type = 'hidden';
193
    $("#quick_add_form #contactfirstname").val(borrower.firstname).before('<span>'+borrower.firstname+'</span.').attr({type:"hidden"});
194
195
    form.streetnumber.value = borrower.streetnumber;
196
    form.address.value = borrower.address;
197
    form.address2.value = borrower.address2;
198
    form.city.value = borrower.city;
199
    form.state.value = borrower.state;
200
    form.zipcode.value = borrower.zipcode;
201
    form.country.value = borrower.country;
202
    form.branchcode.value = borrower.branchcode;
203
204
    $("#quick_add_form #streetnumber").val(borrower.streetnumber);
205
    $("#quick_add_form #address").val(borrower.address);
206
    $("#quick_add_form #address2").val(borrower.address2);
207
    $("#quick_add_form #city").val(borrower.city);
208
    $("#quick_add_form #state").val(borrower.state);
209
    $("#quick_add_form #zipcode").val(borrower.zipcode);
210
    $("#quick_add_form #country").val(borrower.country);
211
    $("#quick_add_form select[name='branchcode']").val(borrower.branchcode);
212
213
    form.guarantorsearch.value = LABEL_CHANGE;
214
    $("#quick_add_form #guarantorsearch").val(LABEL_CHANGE);
215
174
216
    return 0;
175
    return 0;
217
}
176
}
Lines 284-296 $(document).ready(function(){ Link Here
284
    });
243
    });
285
244
286
    $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
245
    $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
287
    $("#guarantordelete").click(function() {
246
288
        $("#quick_add_form #contact-details, #contact-details").hide().find('a').remove();
247
    $('#guarantor_template').hide();
289
        $("#quick_add_form #guarantorid, #quick_add_form  #contactname, #quick_add_form #contactfirstname, #guarantorid, #contactname, #contactfirstname").each(function () { this.value = ""; });
248
290
        $("#quick_add_form #contactname, #quick_add_form #contactfirstname, #contactname, #contactfirstname")
249
    $('#guarantor_search').on('click', function(e) {
291
            .each(function () { this.type = 'text'; })
250
        e.preventDefault();
292
            .parent().find('span').remove();
251
        var newin = window.open('guarantor_search.pl','popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
293
        $("#quick_add_form #guarantorsearch, #guarantorsearch").val(LABEL_SET_TO_PATRON);
252
    });
253
254
    $('#guarantor_relationships').on('click', '.guarantor_cancel', function(e) {
255
        e.preventDefault();
256
        $(this).parents('fieldset').first().remove();
257
    });
258
259
    $('#guarantor_add').on('click', function(e) {
260
        e.preventDefault();
261
        var fieldset = $('#guarantor_template').clone();
262
        fieldset.removeAttr('id');
263
264
        var guarantor_id = $('#guarantor_id').val();
265
        if ( guarantor_id ) {
266
            fieldset.find('.new_guarantor_id').first().val( guarantor_id );
267
            fieldset.find('.new_guarantor_id_text').first().text( guarantor_id );
268
        } else {
269
            fieldset.find('.guarantor_id').first().hide();
270
        }
271
        $('#guarantor_id').val("");
272
273
        var guarantor_surname = $('#guarantor_surname').val();
274
        fieldset.find('.new_guarantor_surname').first().val( guarantor_surname );
275
        fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname );
276
        $('#guarantor_surname').val("");
277
278
        var guarantor_firstname = $('#guarantor_firstname').val();
279
        fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname );
280
        fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname );
281
        $('#guarantor_firstname').val("");
282
283
        var guarantor_relationship = $('#relationship').val();
284
        fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship );
285
        $('#relationship').find('option:eq(0)').prop('selected', true);;
286
287
        $('#guarantor_relationships').append( fieldset );
288
        fieldset.show();
289
    });
290
291
    $("#guarantor_clear").click(function(e) {
292
        e.preventDefault();
293
        $("#contact-details").hide().find('a').remove();
294
        $("#guarantor_id, #guarantor_surname, #guarantor_firstname").val("");
294
    });
295
    });
295
296
296
    $(document.body).on('change','select[name="select_city"]',function(){
297
    $(document.body).on('change','select[name="select_city"]',function(){
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt (-2 / +7 lines)
Lines 99-105 Link Here
99
                    <div class="alert">You typed in the wrong characters in the box before submitting. Please try again.</div>
99
                    <div class="alert">You typed in the wrong characters in the box before submitting. Please try again.</div>
100
                [% END %]
100
                [% END %]
101
101
102
                [% IF borrower.guarantorid && !Koha.Preference('OPACPrivacy') && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
102
                [% IF patron.guarantor_relationships && !Koha.Preference('OPACPrivacy') && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
103
                    <fieldset class="rows" id="memberentry_privacy">
103
                    <fieldset class="rows" id="memberentry_privacy">
104
                        <legend id="privacy_legend">Privacy</legend>
104
                        <legend id="privacy_legend">Privacy</legend>
105
                        <ol>
105
                        <ol>
Lines 118-124 Link Here
118
                                    <span id="update_privacy_guarantor_checkouts_message" class="alert" style="display:none"></span>
118
                                    <span id="update_privacy_guarantor_checkouts_message" class="alert" style="display:none"></span>
119
                                </span>
119
                                </span>
120
                                <span class="hint">
120
                                <span class="hint">
121
                                    Your guarantor is <i>[% guarantor.firstname %] [% guarantor.surname %]</i>
121
                                    Guaranteed by
122
                                    [% FOREACH gr IN patron.guarantor_relationships %]
123
                                        [% SET g = gr.guarantor %]
124
                                        [% g.firstname || gr.firstname %] [% g.surname || gr.surname %]
125
                                        [%- IF ! loop.last %], [% END %]
126
                                    [% END %]
122
                                </span>
127
                                </span>
123
                            </li>
128
                            </li>
124
                        </ol>
129
                        </ol>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-privacy.tt (-2 / +7 lines)
Lines 71-77 Link Here
71
                                        </select>
71
                                        </select>
72
                                    </div>
72
                                    </div>
73
73
74
                                    [% IF borrower.guarantorid && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
74
                                    [% IF borrower.guarantor_relationships && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
75
                                        <div>
75
                                        <div>
76
                                            <label for="privacy_guarantor_checkouts">Allow your guarantor to view your current checkouts?</label>
76
                                            <label for="privacy_guarantor_checkouts">Allow your guarantor to view your current checkouts?</label>
77
                                            <select name="privacy_guarantor_checkouts">
77
                                            <select name="privacy_guarantor_checkouts">
Lines 84-90 Link Here
84
                                                [% END %]
84
                                                [% END %]
85
                                            </select>
85
                                            </select>
86
                                            <span class="hint">
86
                                            <span class="hint">
87
                                                Your guarantor is <i>[% borrower.guarantor.firstname %] [% borrower.guarantor.surname %]</i>
87
                                                Guaranteed by
88
                                                [% FOREACH gr IN borrower.guarantor_relationships %]
89
                                                    [% SET g = gr.guarantor %]
90
                                                    [% g.firstname || gr.firstname %] [% g.surname || gr.surname %]
91
                                                    [%- IF ! loop.last %], [% END %]
92
                                                [% END %]
88
                                            </span>
93
                                            </span>
89
                                        </div>
94
                                        </div>
90
                                    [% END %]
95
                                    [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (-5 / +5 lines)
Lines 428-451 Link Here
428
428
429
                                    <tbody>
429
                                    <tbody>
430
                                        [% FOREACH r IN relatives %]
430
                                        [% FOREACH r IN relatives %]
431
                                            [% FOREACH i IN r.issues %]
431
                                            [% FOREACH c IN r.checkouts %]
432
                                                <tr>
432
                                                <tr>
433
                                                    <td>
433
                                                    <td>
434
                                                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% i.item.biblio.biblionumber %]">
434
                                                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% i.item.biblio.biblionumber %]">
435
                                                            [% i.item.biblio.title %][% IF ( i.item.enumchron ) %] [% i.item.enumchron %][% END %]
435
                                                            [% c.item.biblio.title %][% IF ( c.item.enumchron ) %] [% c.item.enumchron %][% END %]
436
                                                        </a>
436
                                                        </a>
437
                                                    </td>
437
                                                    </td>
438
438
439
                                                    <td>
439
                                                    <td>
440
                                                        [% i.date_due | $KohaDates %]
440
                                                        [% c.date_due | $KohaDates %]
441
                                                    </td>
441
                                                    </td>
442
442
443
                                                    <td>
443
                                                    <td>
444
                                                        [% i.item.barcode %]
444
                                                        [% c.item.barcode %]
445
                                                    </td>
445
                                                    </td>
446
446
447
                                                    <td>
447
                                                    <td>
448
                                                        [% i.item.itemcallnumber %]
448
                                                        [% c.item.itemcallnumber %]
449
                                                    </td>
449
                                                    </td>
450
450
451
                                                    <td>
451
                                                    <td>
(-)a/members/deletemem.pl (-3 / +3 lines)
Lines 109-115 if ( $patron->is_child ) { Link Here
109
109
110
my $op = $input->param('op') || 'delete_confirm';
110
my $op = $input->param('op') || 'delete_confirm';
111
my $dbh = C4::Context->dbh;
111
my $dbh = C4::Context->dbh;
112
my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member);
112
my $is_guarantor = $patron->guarantee_relationships->count;
113
if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or $deletelocal == 0) {
113
if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or $deletelocal == 0) {
114
114
115
    $template->param(
115
    $template->param(
Lines 121-128 if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or Link Here
121
    if ( $charges > 0 ) {
121
    if ( $charges > 0 ) {
122
        $template->param(charges => $charges);
122
        $template->param(charges => $charges);
123
    }
123
    }
124
    if ($is_guarantor) {
124
    if ( $is_guarantor ) {
125
        $template->param(guarantees => 1);
125
        $template->param( guarantees => 1 );
126
    }
126
    }
127
    if ($deletelocal == 0) {
127
    if ($deletelocal == 0) {
128
        $template->param(keeplocal => 1);
128
        $template->param(keeplocal => 1);
(-)a/members/memberentry.pl (-51 / +77 lines)
Lines 83-89 if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { Link Here
83
    $template->param( sms_providers => \@providers );
83
    $template->param( sms_providers => \@providers );
84
}
84
}
85
85
86
my $guarantorid    = $input->param('guarantorid');
87
my $actionType     = $input->param('actionType') || '';
86
my $actionType     = $input->param('actionType') || '';
88
my $modify         = $input->param('modify');
87
my $modify         = $input->param('modify');
89
my $delete         = $input->param('delete');
88
my $delete         = $input->param('delete');
Lines 99-111 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to rep Link Here
99
                                     # isn't a duplicate.  Marking FIXME because this
98
                                     # isn't a duplicate.  Marking FIXME because this
100
                                     # script needs to be refactored.
99
                                     # script needs to be refactored.
101
my $nok           = $input->param('nok');
100
my $nok           = $input->param('nok');
102
my $guarantorinfo = $input->param('guarantorinfo');
103
my $step          = $input->param('step') || 0;
101
my $step          = $input->param('step') || 0;
104
my @errors;
102
my @errors;
105
my $borrower_data;
103
my $borrower_data;
106
my $NoUpdateLogin;
104
my $NoUpdateLogin;
107
my $userenv = C4::Context->userenv;
105
my $userenv = C4::Context->userenv;
108
106
107
## Deal with guarantor stuff
108
$template->param( relationships => scalar $patron->guarantor_relationships ) if $patron;
109
110
my $guarantor_id = $input->param('guarantor_id');
111
my $guarantor = Koha::Patrons->find( $guarantor_id ) if $guarantor_id;
112
$template->param( guarantor => $guarantor );
113
114
my @delete_guarantor = $input->param('delete_guarantor');
115
foreach my $id ( @delete_guarantor ) {
116
    my $r = Koha::Patron::Relationships->find( $id );
117
    $r->delete() if $r;
118
}
119
109
## Deal with debarments
120
## Deal with debarments
110
$template->param(
121
$template->param(
111
    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) );
122
    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) );
Lines 137-150 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnam Link Here
137
my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
148
my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
138
my @field_check=split(/\|/,$check_BorrowerMandatoryField);
149
my @field_check=split(/\|/,$check_BorrowerMandatoryField);
139
foreach (@field_check) {
150
foreach (@field_check) {
140
	$template->param( "mandatory$_" => 1);    
151
    $template->param( "mandatory$_" => 1 );
141
}
152
}
142
# function to designate unwanted fields
153
# function to designate unwanted fields
143
my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
154
my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
144
@field_check=split(/\|/,$check_BorrowerUnwantedField);
155
@field_check=split(/\|/,$check_BorrowerUnwantedField);
145
foreach (@field_check) {
156
foreach (@field_check) {
146
    next unless m/\w/o;
157
    next unless m/\w/o;
147
	$template->param( "no$_" => 1);
158
    $template->param( "no$_" => 1 );
148
}
159
}
149
$template->param( "add" => 1 ) if ( $op eq 'add' );
160
$template->param( "add" => 1 ) if ( $op eq 'add' );
150
$template->param( "quickadd" => 1 ) if ( $quickadd );
161
$template->param( "quickadd" => 1 ) if ( $quickadd );
Lines 246-271 if ( ( $op eq 'insert' ) and !$nodouble ) { Link Here
246
    }
257
    }
247
}
258
}
248
259
249
  #recover all data from guarantor address phone ,fax... 
250
if ( $guarantorid ) {
251
    if (my $guarantor = Koha::Patrons->find( $guarantorid )) {
252
        my $guarantordata = $guarantor->unblessed;
253
        $category_type = $guarantordata->{categorycode} eq 'I' ? 'P' : 'C';
254
        $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
255
        $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
256
        $newdata{'contactname'}     = $guarantordata->{'surname'};
257
        $newdata{'contacttitle'}    = $guarantordata->{'title'};
258
        if ( $op eq 'add' ) {
259
	        foreach (qw(streetnumber address streettype address2
260
                        zipcode country city state phone phonepro mobile fax email emailpro branchcode
261
                        B_streetnumber B_streettype B_address B_address2
262
                        B_city B_state B_zipcode B_country B_email B_phone)) {
263
		        $newdata{$_} = $guarantordata->{$_};
264
	        }
265
        }
266
    }
267
}
268
269
###############test to take the right zipcode, country and city name ##############
260
###############test to take the right zipcode, country and city name ##############
270
# set only if parameter was passed from the form
261
# set only if parameter was passed from the form
271
$newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
262
$newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
Lines 423-428 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
423
	if ($op eq 'insert'){
414
	if ($op eq 'insert'){
424
		# we know it's not a duplicate borrowernumber or there would already be an error
415
		# we know it's not a duplicate borrowernumber or there would already be an error
425
        $borrowernumber = &AddMember(%newdata);
416
        $borrowernumber = &AddMember(%newdata);
417
        add_guarantors( $borrowernumber, $input );
426
        $newdata{'borrowernumber'} = $borrowernumber;
418
        $newdata{'borrowernumber'} = $borrowernumber;
427
419
428
        # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
420
        # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
Lines 520-525 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
520
                                                                # updating any columns in the borrowers table,
512
                                                                # updating any columns in the borrowers table,
521
                                                                # which can happen if we're only editing the
513
                                                                # which can happen if we're only editing the
522
                                                                # patron attributes or messaging preferences sections
514
                                                                # patron attributes or messaging preferences sections
515
        add_guarantors( $borrowernumber, $input );
523
        if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
516
        if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
524
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
517
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
525
        }
518
        }
Lines 627-637 foreach my $category_type (qw(C A S P I X)) { Link Here
627
        'categoryloop'   => \@categoryloop
620
        'categoryloop'   => \@categoryloop
628
      };
621
      };
629
}
622
}
630
623
$template->param(
631
$template->param('typeloop' => \@typeloop,
624
    typeloop      => \@typeloop,
632
        no_categories => $no_categories);
625
    no_categories => $no_categories,
633
if($no_categories){ $no_add = 1; }
626
);
634
635
627
636
my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
628
my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
637
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
629
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
Lines 656-679 while (@relationships) { Link Here
656
  push(@relshipdata, \%row);
648
  push(@relshipdata, \%row);
657
}
649
}
658
650
659
my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
651
my %flags = (
660
        'lost'          => ['lost']);
652
    'gonenoaddress' => ['gonenoaddress'],
653
    'lost'          => ['lost']
654
);
661
655
662
 
663
my @flagdata;
656
my @flagdata;
664
foreach (keys(%flags)) {
657
foreach ( keys(%flags) ) {
665
	my $key = $_;
658
    my $key = $_;
666
	my %row =  ('key'   => $key,
659
    my %row = (
667
		    'name'  => $flags{$key}[0]);
660
        'key'  => $key,
668
	if ($data{$key}) {
661
        'name' => $flags{$key}[0]
669
		$row{'yes'}=' checked';
662
    );
670
		$row{'no'}='';
663
    if ( $data{$key} ) {
671
    }
664
        $row{'yes'} = ' checked';
672
	else {
665
        $row{'no'}  = '';
673
		$row{'yes'}='';
666
    }
674
		$row{'no'}=' checked';
667
    else {
675
	}
668
        $row{'yes'} = '';
676
	push @flagdata,\%row;
669
        $row{'no'}  = ' checked';
670
    }
671
    push @flagdata, \%row;
677
}
672
}
678
673
679
# get Branch Loop
674
# get Branch Loop
Lines 749-755 if (C4::Context->preference('EnhancedMessagingPreferences')) { Link Here
749
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
744
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
750
}
745
}
751
746
752
$template->param( "showguarantor"  => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
747
$template->param( "show_guarantor" => ( $category_type =~ /A|I|S|X/ ) ? 1 : 0 ); # associate with step to know where you are
753
$debug and warn "memberentry step: $step";
748
$debug and warn "memberentry step: $step";
754
$template->param(%data);
749
$template->param(%data);
755
$template->param( "step_$step"  => 1) if $step;	# associate with step to know where u are
750
$template->param( "step_$step"  => 1) if $step;	# associate with step to know where u are
Lines 763-779 $template->param( Link Here
763
  check_member    => $check_member,#to know if the borrower already exist(=>1) or not (=>0) 
758
  check_member    => $check_member,#to know if the borrower already exist(=>1) or not (=>0) 
764
  "op$op"   => 1);
759
  "op$op"   => 1);
765
760
766
$guarantorid = $borrower_data->{'guarantorid'} || $guarantorid;
767
my $guarantor = $guarantorid ? Koha::Patrons->find( $guarantorid ) : undef;
768
$template->param(
761
$template->param(
769
  patron => $patron, # Used by address include templates now
762
  patron => $patron, # Used by address include templates now
770
  nodouble  => $nodouble,
763
  nodouble  => $nodouble,
771
  borrowernumber  => $borrowernumber, #register number
764
  borrowernumber  => $borrowernumber, #register number
772
  guarantor   => $guarantor,
773
  guarantorid => $guarantorid,
774
  relshiploop => \@relshipdata,
765
  relshiploop => \@relshipdata,
775
  btitle=> $default_borrowertitle,
766
  btitle=> $default_borrowertitle,
776
  guarantorinfo   => $guarantorinfo,
777
  flagloop  => \@flagdata,
767
  flagloop  => \@flagdata,
778
  category_type =>$category_type,
768
  category_type =>$category_type,
779
  modify          => $modify,
769
  modify          => $modify,
Lines 901-906 sub patron_attributes_form { Link Here
901
891
902
}
892
}
903
893
894
sub add_guarantors {
895
    my ( $borrowernumber, $input ) = @_;
896
897
    my @new_guarantor_id           = scalar $input->param('new_guarantor_id');
898
    my @new_guarantor_surname      = scalar $input->param('new_guarantor_surname');
899
    my @new_guarantor_firstname    = scalar $input->param('new_guarantor_firstname');
900
    my @new_guarantor_relationship = scalar $input->param('new_guarantor_relationship');
901
902
    for ( my $i = 0 ; $i < scalar @new_guarantor_id; $i++ ) {
903
        my $guarantor_id = $new_guarantor_id[$i];
904
        my $surname      = $new_guarantor_surname[$i];
905
        my $firstname    = $new_guarantor_firstname[$i];
906
        my $relationship = $new_guarantor_relationship[$i];
907
908
        if ($guarantor_id) {
909
            Koha::Patron::Relationship->new(
910
                {
911
                    guarantee_id => $borrowernumber,
912
                    guarantor_id => $guarantor_id,
913
                    relationship => $relationship
914
                }
915
            )->store();
916
        }
917
        elsif ($surname) {
918
            Koha::Patron::Relationship->new(
919
                {
920
                    guarantee_id => $borrowernumber,
921
                    surname      => $surname,
922
                    firstname    => $firstname,
923
                    relationship => $relationship
924
                }
925
            )->store();
926
        }
927
    }
928
}
929
904
# Local Variables:
930
# Local Variables:
905
# tab-width: 8
931
# tab-width: 8
906
# End:
932
# End:
(-)a/members/moremember.pl (-15 / +13 lines)
Lines 172-193 if ( $patron->is_child ) { Link Here
172
}
172
}
173
173
174
my @relatives;
174
my @relatives;
175
if ( my $guarantor = $patron->guarantor ) {
175
my $guarantor_relationships = $patron->guarantor_relationships;
176
    $template->param( guarantor => $guarantor );
176
my @guarantees              = $patron->guarantee_relationships->guarantees;
177
    push @relatives, $guarantor->borrowernumber;
177
my @guarantors              = $guarantor_relationships->guarantors;
178
    push @relatives, $_->borrowernumber for $patron->siblings;
178
if (@guarantors) {
179
} elsif ( $patron->contactname || $patron->contactfirstname ) {
179
    push( @relatives, $_->id ) for @guarantors;
180
    $template->param(
180
    push( @relatives, $_->id ) for $patron->siblings();
181
        guarantor => {
182
            firstname => $patron->contactfirstname,
183
            surname   => $patron->contactname,
184
        }
185
    );
186
} else {
187
    my @guarantees = $patron->guarantees;
188
    $template->param( guarantees => \@guarantees );
189
    push @relatives, $_->borrowernumber for @guarantees;
190
}
181
}
182
else {
183
    push( @relatives, $_->id ) for @guarantees;
184
}
185
$template->param(
186
    guarantor_relationships => $guarantor_relationships,
187
    guarantees              => \@guarantees,
188
);
191
189
192
my $relatives_issues_count =
190
my $relatives_issues_count =
193
  Koha::Database->new()->schema()->resultset('Issue')
191
  Koha::Database->new()->schema()->resultset('Issue')
(-)a/members/update-child.pl (-8 / +13 lines)
Lines 34-39 use C4::Output; Link Here
34
use C4::Members;
34
use C4::Members;
35
use Koha::Patrons;
35
use Koha::Patrons;
36
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
37
use Koha::Patrons;
37
38
38
# use Smart::Comments;
39
# use Smart::Comments;
39
40
Lines 54-60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
54
my $borrowernumber = $input->param('borrowernumber');
55
my $borrowernumber = $input->param('borrowernumber');
55
my $catcode        = $input->param('catcode');
56
my $catcode        = $input->param('catcode');
56
my $cattype        = $input->param('cattype');
57
my $cattype        = $input->param('cattype');
57
my $catcode_multi = $input->param('catcode_multi');
58
my $catcode_multi  = $input->param('catcode_multi');
58
my $op             = $input->param('op');
59
my $op             = $input->param('op');
59
60
60
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
61
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
Lines 71-81 if ( $op eq 'multi' ) { Link Here
71
    );
72
    );
72
    output_html_with_http_headers $input, $cookie, $template->output;
73
    output_html_with_http_headers $input, $cookie, $template->output;
73
}
74
}
74
75
elsif ( $op eq 'update' ) {
75
elsif ( $op eq 'update' ) {
76
    my $patron         = Koha::Patrons->find( $borrowernumber );
76
    my $patron         = Koha::Patrons->find( $borrowernumber );
77
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
77
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
78
78
79
    $_->delete() for $patron->guarantor_relationships();
80
79
    my $member = $patron->unblessed;
81
    my $member = $patron->unblessed;
80
    $member->{'guarantorid'}  = 0;
82
    $member->{'guarantorid'}  = 0;
81
    $member->{'categorycode'} = $catcode;
83
    $member->{'categorycode'} = $catcode;
Lines 85-98 elsif ( $op eq 'update' ) { Link Here
85
    delete $member->{password};
87
    delete $member->{password};
86
    ModMember(%$member);
88
    ModMember(%$member);
87
89
88
    if (  $catcode_multi ) {
90
    if ($catcode_multi) {
89
        $template->param(
91
        $template->param(
90
                SUCCESS        => 1,
92
            SUCCESS        => 1,
91
                borrowernumber => $borrowernumber,
93
            borrowernumber => $borrowernumber,
92
                );
94
        );
93
        output_html_with_http_headers $input, $cookie, $template->output;
95
        output_html_with_http_headers $input, $cookie, $template->output;
94
    } else {
96
    }
95
        print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
97
    else {
98
        print $input->redirect(
99
            "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"
100
        );
96
    }
101
    }
97
}
102
}
98
103
(-)a/misc/cronjobs/j2a.pl (-12 / +45 lines)
Lines 163-174 $verbose and print "The age limit for category $fromcat is $agelimit\n"; Link Here
163
my $itsyourbirthday = "$year-$mon-$mday";
163
my $itsyourbirthday = "$year-$mon-$mday";
164
164
165
if ( not $noaction ) {
165
if ( not $noaction ) {
166
    # Start a transaction since we need to delete from relationships and update borrowers atomically
167
    $dbh->{AutoCommit} = 0;
168
166
    if ($mybranch) {    #yep, we received a specific branch to work on.
169
    if ($mybranch) {    #yep, we received a specific branch to work on.
167
        $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
170
        $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
168
        my $query = qq|
171
        my $where = qq|
169
            UPDATE borrowers
170
            SET guarantorid ='0',
171
                categorycode = ?
172
            WHERE dateofbirth <= ?
172
            WHERE dateofbirth <= ?
173
              AND dateofbirth != '0000-00-00'
173
              AND dateofbirth != '0000-00-00'
174
              AND branchcode = ?
174
              AND branchcode = ?
Lines 177-186 if ( not $noaction ) { Link Here
177
                FROM categories
177
                FROM categories
178
                WHERE category_type = 'C'
178
                WHERE category_type = 'C'
179
                  AND categorycode = ?
179
                  AND categorycode = ?
180
              )|;
180
              )
181
        |;
182
183
        my $query = qq|
184
            DELETE relationships FROM relationships
185
            LEFT JOIN borrowers ON ( borrowers.borrowernumber = relationships.guarantee_id )
186
            $where
187
        |;
181
        my $sth = $dbh->prepare($query);
188
        my $sth = $dbh->prepare($query);
189
        $sth->execute( $itsyourbirthday, $mybranch, $fromcat )
190
          or ( $dbh->rollback && die "can't execute" );
191
192
        $query = qq|
193
            UPDATE borrowers
194
            SET categorycode = ?
195
            $where
196
        |;
197
        $sth = $dbh->prepare($query);
182
        my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
198
        my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
183
          or die "can't execute";
199
          or ( $dbh->rollback && die "can't execute" );
200
201
        $dbh->commit;
184
202
185
        if ( $res eq '0E0' ) {
203
        if ( $res eq '0E0' ) {
186
            print "No patrons updated\n";
204
            print "No patrons updated\n";
Lines 191-200 if ( not $noaction ) { Link Here
191
    }
209
    }
192
    else {    # branch was not supplied, processing all branches
210
    else {    # branch was not supplied, processing all branches
193
        $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
211
        $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
194
        my $query = qq|
212
        my $where = qq|
195
            UPDATE borrowers
196
            SET guarantorid = '0',
197
                categorycode = ?
198
            WHERE dateofbirth <= ?
213
            WHERE dateofbirth <= ?
199
              AND dateofbirth!='0000-00-00'
214
              AND dateofbirth!='0000-00-00'
200
              AND categorycode IN (
215
              AND categorycode IN (
Lines 202-211 if ( not $noaction ) { Link Here
202
                FROM categories
217
                FROM categories
203
                WHERE category_type = 'C'
218
                WHERE category_type = 'C'
204
                  AND categorycode = ?
219
                  AND categorycode = ?
205
              )|;
220
              )
221
        |;
222
223
        my $query = qq|
224
            DELETE relationships FROM relationships
225
            LEFT JOIN borrowers ON ( borrowers.borrowernumber = relationships.guarantee_id )
226
            $where
227
        |;
206
        my $sth = $dbh->prepare($query);
228
        my $sth = $dbh->prepare($query);
229
        $sth->execute( $itsyourbirthday, $fromcat )
230
          or ( $dbh->rollback && die "can't execute" );
231
232
        $query = qq|
233
            UPDATE borrowers
234
            SET categorycode = ?
235
            $where
236
        |;
237
        $sth = $dbh->prepare($query);
207
        my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
238
        my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
208
          or die "can't execute";
239
          or ( $dbh->rollback && die "can't execute" );
240
        $dbh->commit;
209
241
210
        if ( $res eq '0E0' ) {
242
        if ( $res eq '0E0' ) {
211
            print "No patrons updated\n";
243
            print "No patrons updated\n";
Lines 267-272 else { Link Here
267
        my $sth = $dbh->prepare($query);
299
        my $sth = $dbh->prepare($query);
268
        $sth->execute( $itsyourbirthday, $fromcat )
300
        $sth->execute( $itsyourbirthday, $fromcat )
269
          or die "Couldn't execute statement: " . $sth->errstr;
301
          or die "Couldn't execute statement: " . $sth->errstr;
302
        $dbh->commit;
270
303
271
        while ( my @res = $sth->fetchrow_array() ) {
304
        while ( my @res = $sth->fetchrow_array() ) {
272
            my $firstname = $res[0];
305
            my $firstname = $res[0];
(-)a/opac/opac-memberentry.pl (-2 / +2 lines)
Lines 299-305 elsif ( $action eq 'edit' ) { #Display logged in borrower's data Link Here
299
299
300
    $template->param(
300
    $template->param(
301
        borrower  => $borrower,
301
        borrower  => $borrower,
302
        guarantor => scalar Koha::Patrons->find($borrowernumber)->guarantor(),
303
        hidden => GetHiddenFields( $mandatory, 'modification' ),
302
        hidden => GetHiddenFields( $mandatory, 'modification' ),
304
        csrf_token => Koha::Token->new->generate_csrf({
303
        csrf_token => Koha::Token->new->generate_csrf({
305
            session_id => scalar $cgi->cookie('CGISESSID'),
304
            session_id => scalar $cgi->cookie('CGISESSID'),
Lines 320-326 my $captcha = random_string("CCCCC"); Link Here
320
319
321
$template->param(
320
$template->param(
322
    captcha        => $captcha,
321
    captcha        => $captcha,
323
    captcha_digest => md5_base64($captcha)
322
    captcha_digest => md5_base64($captcha),
323
    patron         => Koha::Patrons->find( $borrowernumber ),
324
);
324
);
325
325
326
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
326
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-user.pl (-8 / +9 lines)
Lines 40-45 use Koha::Holds; Link Here
40
use Koha::Database;
40
use Koha::Database;
41
use Koha::ItemTypes;
41
use Koha::ItemTypes;
42
use Koha::Patron::Attribute::Types;
42
use Koha::Patron::Attribute::Types;
43
use Koha::Patrons;
43
use Koha::Patron::Messages;
44
use Koha::Patron::Messages;
44
use Koha::Patron::Discharge;
45
use Koha::Patron::Discharge;
45
use Koha::Patrons;
46
use Koha::Patrons;
Lines 76-81 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
76
    }
77
    }
77
);
78
);
78
79
80
my $patron = Koha::Patrons->find( $borrowernumber );
81
79
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
82
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
80
83
81
my $show_priority;
84
my $show_priority;
Lines 338-351 my $patron_messages = Koha::Patron::Messages->search( Link Here
338
if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
341
if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
339
    || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
342
    || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
340
{
343
{
341
    my @relatives =
344
    my @relatives;
342
      Koha::Database->new()->schema()->resultset("Borrower")->search(
345
    # Filter out guarantees that don't want guarantor to see checkouts
343
        {
346
    foreach my $gr ( $patron->guarantee_relationships() ) {
344
            privacy_guarantor_checkouts => 1,
347
        my $g = $gr->guarantee;
345
            'me.guarantorid'           => $borrowernumber
348
        push( @relatives, $g ) if $g->privacy_guarantor_checkouts;
346
        },
349
    }
347
        { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] }
348
      );
349
    $template->param( relatives => \@relatives );
350
    $template->param( relatives => \@relatives );
350
}
351
}
351
352
(-)a/t/Patron.t (-22 / +2 lines)
Lines 95-106 my $patron = Koha::Patron->new( Link Here
95
        lost                => '0',
95
        lost                => '0',
96
        debarred            => '2015-04-19',
96
        debarred            => '2015-04-19',
97
        debarredcomment     => 'You are debarred',
97
        debarredcomment     => 'You are debarred',
98
        contactname         => 'myContactname',
99
        contactfirstname    => 'myContactfirstname',
100
        contacttitle        => 'myContacttitle',
101
        guarantorid         => '123454321',
102
        borrowernotes       => 'borrowernotes',
98
        borrowernotes       => 'borrowernotes',
103
        relationship        => 'myRelationship',
104
        sex                 => 'M',
99
        sex                 => 'M',
105
        password            => 'hfkurhfe976634èj!',
100
        password            => 'hfkurhfe976634èj!',
106
        flags               => '55555',
101
        flags               => '55555',
Lines 125-131 my $patron = Koha::Patron->new( Link Here
125
120
126
# patron Accessor tests
121
# patron Accessor tests
127
subtest 'Accessor tests' => sub {
122
subtest 'Accessor tests' => sub {
128
    plan tests => 65;
123
    plan tests => 60;
129
    is( $patron->borrowernumber, '12345',                           'borrowernumber accessor returns correct value' );
124
    is( $patron->borrowernumber, '12345',                           'borrowernumber accessor returns correct value' );
130
    is( $patron->cardnumber,     '1234567890',                      'cardnumber accessor returns correct value' );
125
    is( $patron->cardnumber,     '1234567890',                      'cardnumber accessor returns correct value' );
131
    is( $patron->surname,        'mySurname',                       'surname accessor returns correct value' );
126
    is( $patron->surname,        'mySurname',                       'surname accessor returns correct value' );
Lines 166-177 subtest 'Accessor tests' => sub { Link Here
166
    is( $patron->lost,           '0',                               'lost accessor returns correct value' );
161
    is( $patron->lost,           '0',                               'lost accessor returns correct value' );
167
    is( $patron->debarred,       '2015-04-19',                      'debarred accessor returns correct value' );
162
    is( $patron->debarred,       '2015-04-19',                      'debarred accessor returns correct value' );
168
    is( $patron->debarredcomment,     'You are debarred',      'debarredcomment accessor returns correct value' );
163
    is( $patron->debarredcomment,     'You are debarred',      'debarredcomment accessor returns correct value' );
169
    is( $patron->contactname,         'myContactname',         'contactname accessor returns correct value' );
170
    is( $patron->contactfirstname,    'myContactfirstname',    'contactfirstname accessor returns correct value' );
171
    is( $patron->contacttitle,        'myContacttitle',        'contacttitle accessor returns correct value' );
172
    is( $patron->guarantorid,         '123454321',             'guarantorid accessor returns correct value' );
173
    is( $patron->borrowernotes,       'borrowernotes',         'borrowernotes accessor returns correct value' );
164
    is( $patron->borrowernotes,       'borrowernotes',         'borrowernotes accessor returns correct value' );
174
    is( $patron->relationship,        'myRelationship',        'relationship accessor returns correct value' );
175
    is( $patron->sex,                 'M',                     'sex accessor returns correct value' );
165
    is( $patron->sex,                 'M',                     'sex accessor returns correct value' );
176
    is( $patron->password,            'hfkurhfe976634èj!',    'password accessor returns correct value' );
166
    is( $patron->password,            'hfkurhfe976634èj!',    'password accessor returns correct value' );
177
    is( $patron->flags,               '55555',                 'flags accessor returns correct value' );
167
    is( $patron->flags,               '55555',                 'flags accessor returns correct value' );
Lines 195-201 subtest 'Accessor tests' => sub { Link Here
195
185
196
# patron Set tests
186
# patron Set tests
197
subtest 'Set tests' => sub {
187
subtest 'Set tests' => sub {
198
    plan tests => 65;
188
    plan tests => 60;
199
189
200
    $patron->set(
190
    $patron->set(
201
        {
191
        {
Lines 239-250 subtest 'Set tests' => sub { Link Here
239
            lost                => '1',
229
            lost                => '1',
240
            debarred            => '2016-04-19',
230
            debarred            => '2016-04-19',
241
            debarredcomment     => 'You are still debarred',
231
            debarredcomment     => 'You are still debarred',
242
            contactname         => 'SmyContactname',
243
            contactfirstname    => 'SmyContactfirstname',
244
            contacttitle        => 'SmyContacttitle',
245
            guarantorid         => '223454321',
246
            borrowernotes       => 'Sborrowernotes',
232
            borrowernotes       => 'Sborrowernotes',
247
            relationship        => 'SmyRelationship',
248
            sex                 => 'F',
233
            sex                 => 'F',
249
            password            => 'zerzerzer#',
234
            password            => 'zerzerzer#',
250
            flags               => '666666',
235
            flags               => '666666',
Lines 307-318 subtest 'Set tests' => sub { Link Here
307
    is( $patron->lost,                '1',                                'lost field set ok' );
292
    is( $patron->lost,                '1',                                'lost field set ok' );
308
    is( $patron->debarred,            '2016-04-19',                       'debarred field set ok' );
293
    is( $patron->debarred,            '2016-04-19',                       'debarred field set ok' );
309
    is( $patron->debarredcomment,     'You are still debarred',           'debarredcomment field set ok' );
294
    is( $patron->debarredcomment,     'You are still debarred',           'debarredcomment field set ok' );
310
    is( $patron->contactname,         'SmyContactname',                   'contactname field set ok' );
311
    is( $patron->contactfirstname,    'SmyContactfirstname',              'contactfirstname field set ok' );
312
    is( $patron->contacttitle,        'SmyContacttitle',                  'contacttitle field set ok' );
313
    is( $patron->guarantorid,         '223454321',                        'guarantorid field set ok' );
314
    is( $patron->borrowernotes,       'Sborrowernotes',                   'borrowernotes field set ok' );
295
    is( $patron->borrowernotes,       'Sborrowernotes',                   'borrowernotes field set ok' );
315
    is( $patron->relationship,        'SmyRelationship',                  'relationship field set ok' );
316
    is( $patron->sex,                 'F',                                'sex field set ok' );
296
    is( $patron->sex,                 'F',                                'sex field set ok' );
317
    is( $patron->password,            'zerzerzer#',                       'password field set ok' );
297
    is( $patron->password,            'zerzerzer#',                       'password field set ok' );
318
    is( $patron->flags,               '666666',                           'flags field set ok' );
298
    is( $patron->flags,               '666666',                           'flags field set ok' );
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-6 / +19 lines)
Lines 26-31 use C4::Accounts qw( manualinvoice ); Link Here
26
use C4::Circulation qw( CanBookBeIssued );
26
use C4::Circulation qw( CanBookBeIssued );
27
use Koha::Account::Lines;
27
use Koha::Account::Lines;
28
use Koha::Account::Offsets;
28
use Koha::Account::Offsets;
29
use Koha::Patron::Relationship;
29
30
30
my $schema = Koha::Database->new->schema;
31
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
$schema->storage->txn_begin;
Lines 52-63 my $patron = $builder->build_object( Link Here
52
        }
53
        }
53
    }
54
    }
54
);
55
);
55
my $guarantee = $builder->build(
56
57
my $guarantee = $builder->build_object(
56
    {
58
    {
57
        source => 'Borrower',
59
        class => 'Koha::Patrons',
58
        value  => {
60
        value => {
61
            patron_category => $patron_category->{categorycode},
59
            guarantorid => $patron->borrowernumber,
62
            guarantorid => $patron->borrowernumber,
60
            categorycode => $patron_category->{categorycode},
63
        }
64
    }
65
);
66
67
my $r = $builder->build_object(
68
    {
69
        class => 'Koha::Patron::Relationships',
70
        value => {
71
            guarantor_id => $patron->id,
72
            guarantee_id => $guarantee->id,
73
            relationship => 'parent',
61
        }
74
        }
62
    }
75
    }
63
);
76
);
Lines 68-78 t::lib::Mocks::mock_preference( 'AllowFineOverride', '' ); Link Here
68
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
81
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
69
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
82
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
70
83
71
manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
84
manualinvoice( $guarantee->id, undef, undef, 'L', 10.00 );
72
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
85
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
73
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
86
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
74
87
75
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
88
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
76
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
89
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
77
is( $accountline->accounttype, "L", "Account type is L" );
90
is( $accountline->accounttype, "L", "Account type is L" );
78
91
(-)a/t/db_dependent/Items.t (-1 / +5 lines)
Lines 507-513 subtest 'SearchItems test' => sub { Link Here
507
507
508
subtest 'Koha::Item(s) tests' => sub {
508
subtest 'Koha::Item(s) tests' => sub {
509
509
510
    plan tests => 5;
510
    plan tests => 7;
511
511
512
    $schema->storage->txn_begin();
512
    $schema->storage->txn_begin();
513
513
Lines 546-551 subtest 'Koha::Item(s) tests' => sub { Link Here
546
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
546
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
547
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
547
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
548
548
549
    my $biblio = $item->biblio();
550
    is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
551
    is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );
552
549
    $schema->storage->txn_rollback;
553
    $schema->storage->txn_rollback;
550
};
554
};
551
555
(-)a/t/db_dependent/Koha/Patrons.t (-15 / +21 lines)
Lines 35-40 use Koha::Holds; Link Here
35
use Koha::Patron;
35
use Koha::Patron;
36
use Koha::Patrons;
36
use Koha::Patrons;
37
use Koha::Patron::Categories;
37
use Koha::Patron::Categories;
38
use Koha::Patron::Relationship;
38
use Koha::Database;
39
use Koha::Database;
39
use Koha::DateUtils;
40
use Koha::DateUtils;
40
use Koha::Virtualshelves;
41
use Koha::Virtualshelves;
Lines 85-107 subtest 'library' => sub { Link Here
85
86
86
subtest 'guarantees' => sub {
87
subtest 'guarantees' => sub {
87
    plan tests => 8;
88
    plan tests => 8;
88
    my $guarantees = $new_patron_1->guarantees;
89
    my $guarantees = $new_patron_1->guarantee_relationships;
89
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
90
    is( ref($guarantees), 'Koha::Patron::Relationships', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
90
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee' );
91
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee relationships' );
91
    my @guarantees = $new_patron_1->guarantees;
92
    my @guarantees = $new_patron_1->guarantee_relationships;
92
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
93
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantee_relationships should return an array in a list context' );
93
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
94
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
94
95
95
    my $guarantee_1 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
96
    my $guarantee_1 = $builder->build({ source => 'Borrower' });
96
    my $guarantee_2 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
97
    my $relationship_1 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->id, guarantee_id => $guarantee_1->{borrowernumber} } )->store();
98
    my $guarantee_2 = $builder->build({ source => 'Borrower' });
99
    my $relationship_2 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->id, guarantee_id => $guarantee_2->{borrowernumber} } )->store();
97
100
98
    $guarantees = $new_patron_1->guarantees;
101
    $guarantees = $new_patron_1->guarantee_relationships;
99
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
102
    is( ref($guarantees), 'Koha::Patron::Relationships', 'Koha::Patron->guarantee_relationships should return a Koha::Patrons result set in a scalar context' );
100
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
103
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
101
    @guarantees = $new_patron_1->guarantees;
104
    @guarantees = $new_patron_1->guarantee_relationships;
102
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
105
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantee_relationships should return an array in a list context' );
103
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
106
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
104
    $_->delete for @guarantees;
107
    map { $_->guarantee->delete } @guarantees;
105
};
108
};
106
109
107
subtest 'category' => sub {
110
subtest 'category' => sub {
Lines 115-129 subtest 'siblings' => sub { Link Here
115
    plan tests => 7;
118
    plan tests => 7;
116
    my $siblings = $new_patron_1->siblings;
119
    my $siblings = $new_patron_1->siblings;
117
    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
120
    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
118
    my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
121
    my $guarantee_1 = $builder->build( { source => 'Borrower' } );
122
    my $relationship_1 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_1->{borrowernumber} } )->store();
119
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
123
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
120
    $siblings = $retrieved_guarantee_1->siblings;
124
    $siblings = $retrieved_guarantee_1->siblings;
121
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
125
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
122
    my @siblings = $retrieved_guarantee_1->siblings;
126
    my @siblings = $retrieved_guarantee_1->siblings;
123
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
127
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
124
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
128
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
125
    my $guarantee_2 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
129
    my $guarantee_2 = $builder->build( { source => 'Borrower' } );
126
    my $guarantee_3 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
130
    my $relationship_2 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_2->{borrowernumber} } )->store();
131
    my $guarantee_3 = $builder->build( { source => 'Borrower' } );
132
    my $relationship_3 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_3->{borrowernumber} } )->store();
127
    $siblings = $retrieved_guarantee_1->siblings;
133
    $siblings = $retrieved_guarantee_1->siblings;
128
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
134
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
129
    is( $guarantee_2->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_2 should exist in the guarantees' );
135
    is( $guarantee_2->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_2 should exist in the guarantees' );
(-)a/t/db_dependent/Members.t (-11 / +7 lines)
Lines 27-32 use Koha::Database; Link Here
27
use Koha::Holds;
27
use Koha::Holds;
28
use Koha::List::Patron;
28
use Koha::List::Patron;
29
use Koha::Patrons;
29
use Koha::Patrons;
30
use Koha::Patron::Relationship;
30
31
31
use t::lib::Mocks;
32
use t::lib::Mocks;
32
use t::lib::TestBuilder;
33
use t::lib::TestBuilder;
Lines 40-48 $schema->storage->txn_begin; Link Here
40
my $builder = t::lib::TestBuilder->new;
41
my $builder = t::lib::TestBuilder->new;
41
my $dbh = C4::Context->dbh;
42
my $dbh = C4::Context->dbh;
42
43
43
# Remove invalid guarantorid's as long as we have no FK
44
$dbh->do("UPDATE borrowers b1 LEFT JOIN borrowers b2 ON b2.borrowernumber=b1.guarantorid SET b1.guarantorid=NULL where b1.guarantorid IS NOT NULL AND b2.borrowernumber IS NULL");
45
46
my $library1 = $builder->build({
44
my $library1 = $builder->build({
47
    source => 'Branch',
45
    source => 'Branch',
48
});
46
});
Lines 228-234 my $borrower1 = $builder->build({ Link Here
228
            categorycode=>'STAFFER',
226
            categorycode=>'STAFFER',
229
            branchcode => $library3->{branchcode},
227
            branchcode => $library3->{branchcode},
230
            dateexpiry => '2015-01-01',
228
            dateexpiry => '2015-01-01',
231
            guarantorid=> undef,
232
        },
229
        },
233
});
230
});
234
my $bor1inlist = $borrower1->{borrowernumber};
231
my $bor1inlist = $borrower1->{borrowernumber};
Lines 238-244 my $borrower2 = $builder->build({ Link Here
238
            categorycode=>'STAFFER',
235
            categorycode=>'STAFFER',
239
            branchcode => $library3->{branchcode},
236
            branchcode => $library3->{branchcode},
240
            dateexpiry => '2015-01-01',
237
            dateexpiry => '2015-01-01',
241
            guarantorid=> undef,
242
        },
238
        },
243
});
239
});
244
240
Lines 248-254 my $guarantee = $builder->build({ Link Here
248
            categorycode=>'KIDclamp',
244
            categorycode=>'KIDclamp',
249
            branchcode => $library3->{branchcode},
245
            branchcode => $library3->{branchcode},
250
            dateexpiry => '2015-01-01',
246
            dateexpiry => '2015-01-01',
251
            guarantorid=> undef, # will be filled later
252
        },
247
        },
253
});
248
});
254
249
Lines 283-289 $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_ Link Here
283
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
278
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
284
279
285
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
280
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
286
ModMember( borrowernumber => $guarantee->{borrowernumber} ,guarantorid=>$bor1inlist );
281
my $relationship = Koha::Patron::Relationship->new( { guarantor_id => $bor1inlist, guarantee_id => $guarantee->{borrowernumber} } )->store();
287
282
288
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
283
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
289
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
284
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
Lines 293-299 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list Link Here
293
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
288
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
294
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
289
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
295
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
290
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
296
ModMember( borrowernumber => $guarantee->{borrowernumber}, guarantorid=>'' );
291
292
$relationship->delete();
297
293
298
$builder->build({
294
$builder->build({
299
        source => 'Issue',
295
        source => 'Issue',
Lines 321-329 is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date') Link Here
321
317
322
# Test GetBorrowersToExpunge and TrackLastPatronActivity
318
# Test GetBorrowersToExpunge and TrackLastPatronActivity
323
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
319
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
324
$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN', guarantorid => undef } } );
320
$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN' } } );
325
$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN', guarantorid => undef } } );
321
$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN' } } );
326
$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN', guarantorid => undef } } );
322
$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN' } } );
327
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
323
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
328
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
324
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
329
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' });
325
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' });
(-)a/t/db_dependent/Patron/Relationships.t (+181 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 67;
21
22
use C4::Context;
23
24
use t::lib::TestBuilder;
25
26
BEGIN {
27
    use_ok('Koha::Objects');
28
    use_ok('Koha::Patrons');
29
    use_ok('Koha::Patron::Relationship');
30
    use_ok('Koha::Patron::Relationships');
31
}
32
33
# Start transaction
34
my $dbh = C4::Context->dbh;
35
$dbh->{AutoCommit} = 0;
36
$dbh->{RaiseError} = 1;
37
38
my $builder = t::lib::TestBuilder->new();
39
40
# Father
41
my $kyle = Koha::Patrons->find(
42
    $builder->build(
43
        {
44
            source => 'Borrower',
45
            value  => {
46
                firstname => 'Kyle',
47
                surname   => 'Hall',
48
            }
49
        }
50
    )->{borrowernumber}
51
);
52
53
# Mother
54
my $chelsea = Koha::Patrons->find(
55
    $builder->build(
56
        {
57
            source => 'Borrower',
58
            value  => {
59
                firstname => 'Chelsea',
60
                surname   => 'Hall',
61
            }
62
        }
63
    )->{borrowernumber}
64
);
65
66
# Children
67
my $daria = Koha::Patrons->find(
68
    $builder->build(
69
        {
70
            source => 'Borrower',
71
            value  => {
72
                firstname => 'Daria',
73
                surname   => 'Hall',
74
            }
75
        }
76
    )->{borrowernumber}
77
);
78
79
my $kylie = Koha::Patrons->find(
80
    $builder->build(
81
        {
82
            source => 'Borrower',
83
            value  => {
84
                firstname => 'Kylie',
85
                surname   => 'Hall',
86
            }
87
        }
88
    )->{borrowernumber}
89
);
90
91
Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $daria->id, relationship => 'father' })->store();
92
Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $kylie->id, relationship => 'father' })->store();
93
Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => $daria->id, relationship => 'mother' })->store();
94
Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => $kylie->id, relationship => 'mother' })->store();
95
Koha::Patron::Relationship->new({ firstname => 'John', surname => 'Hall', guarantee_id => $daria->id, relationship => 'grandfather' })->store();
96
Koha::Patron::Relationship->new({ firstname => 'Debra', surname => 'Hall', guarantee_id => $daria->id, relationship => 'grandmother' })->store();
97
Koha::Patron::Relationship->new({ firstname => 'John', surname => 'Hall', guarantee_id => $kylie->id, relationship => 'grandfather' })->store();
98
Koha::Patron::Relationship->new({ firstname => 'Debra', surname => 'Hall', guarantee_id => $kylie->id, relationship => 'grandmother' })->store();
99
100
my @gr;
101
102
@gr = $kyle->guarantee_relationships();
103
is( @gr, 2, 'Found 2 guarantee relationships for father' );
104
is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
105
is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
106
is( $gr[0]->relationship, 'father', 'Relationship is father' );
107
is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
108
is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
109
is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
110
is( $gr[0]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
111
112
is( $gr[1]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
113
is( $gr[1]->guarantee_id, $kylie->id, 'Guarantee matches for first relationship' );
114
is( $gr[1]->relationship, 'father', 'Relationship is father' );
115
is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
116
is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct guarantee' );
117
is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
118
is( $gr[1]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
119
120
@gr = $chelsea->guarantee_relationships();
121
is( @gr, 2, 'Found 2 guarantee relationships for mother' );
122
is( $gr[0]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
123
is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
124
is( $gr[0]->relationship, 'mother', 'Relationship is mother' );
125
is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
126
is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
127
is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
128
is( $gr[0]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
129
130
is( $gr[1]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
131
is( $gr[1]->guarantee_id, $kylie->id, 'Guarantee matches for first relationship' );
132
is( $gr[1]->relationship, 'mother', 'Relationship is mother' );
133
is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
134
is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct guarantee' );
135
is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
136
is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
137
138
@gr = $daria->guarantor_relationships();
139
is( @gr, 4, 'Found 4 guarantor relationships for child' );
140
is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
141
is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
142
is( $gr[0]->relationship, 'father', 'Relationship is father' );
143
is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
144
is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
145
is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
146
is( $gr[0]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
147
148
is( $gr[1]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
149
is( $gr[1]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
150
is( $gr[1]->relationship, 'mother', 'Relationship is mother' );
151
is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
152
is( $gr[1]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
153
is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
154
is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
155
156
is( $gr[2]->guarantor_id, undef, 'Grandfather has no id, not a Koha patron' );
157
is( $gr[2]->firstname, 'John', 'Grandfather has first name of John' );
158
is( $gr[2]->surname, 'Hall', 'Grandfather has surname of Hall' );
159
is( $gr[2]->guarantor, undef, 'Calling guarantor method for Grandfather returns undef' );
160
161
is( $gr[3]->guarantor_id, undef, 'Grandmother has no id, not a Koha patron' );
162
is( $gr[3]->firstname, 'Debra', 'Grandmother has first name of John' );
163
is( $gr[3]->surname, 'Hall', 'Grandmother has surname of Hall' );
164
is( $gr[3]->guarantor, undef, 'Calling guarantor method for Grandmother returns undef' );
165
166
my @siblings = $daria->siblings;
167
is( @siblings, 1, 'Method siblings called in list context returns list' );
168
is( ref($siblings[0]), 'Koha::Patron', 'List contains a Koha::Patron' );
169
is( $siblings[0]->firstname, 'Kylie', 'Sibling from list first name matches correctly' );
170
is( $siblings[0]->surname, 'Hall', 'Sibling from list surname matches correctly' );
171
is( $siblings[0]->id, $kylie->id, 'Sibling from list patron id matches correctly' );
172
173
my $siblings = $daria->siblings;
174
my $sibling = $siblings->next();
175
is( ref($siblings), 'Koha::Patrons', 'Calling siblings in scalar context results in a Koha::Patrons object' );
176
is( ref($sibling), 'Koha::Patron', 'Method next returns a Koha::Patron' );
177
is( $sibling->firstname, 'Kylie', 'Sibling from scalar first name matches correctly' );
178
is( $sibling->surname, 'Hall', 'Sibling from scalar surname matches correctly' );
179
is( $sibling->id, $kylie->id, 'Sibling from scalar patron id matches correctly' );
180
181
1;
(-)a/tools/import_borrowers.pl (-1 / +1 lines)
Lines 62-67 my $extended = C4::Context->preference('ExtendedPatronAttributes'); Link Here
62
62
63
my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } Koha::Patrons->columns();
63
my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } Koha::Patrons->columns();
64
push( @columnkeys, 'patron_attributes' ) if $extended;
64
push( @columnkeys, 'patron_attributes' ) if $extended;
65
push( @columnkeys, qw( relationship guarantor_id  guarantor_firstname guarantor_surname ) );
65
66
66
my $input = CGI->new();
67
my $input = CGI->new();
67
68
68
- 

Return to bug 14570