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 777-783 sub CanBookBeIssued { Link Here
777
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
777
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
778
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
778
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
779
    if ( defined $no_issues_charge_guarantees ) {
779
    if ( defined $no_issues_charge_guarantees ) {
780
        my @guarantees = $patron->guarantees();
780
        my @guarantees = map { $_->guarantee } $patron->guarantee_relationships();
781
        my $guarantees_non_issues_charges;
781
        my $guarantees_non_issues_charges;
782
        foreach my $g ( @guarantees ) {
782
        foreach my $g ( @guarantees ) {
783
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
783
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
(-)a/C4/Members.pm (-9 / +7 lines)
Lines 200-206 sub patronflags { Link Here
200
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
200
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
201
    if ( defined $no_issues_charge_guarantees ) {
201
    if ( defined $no_issues_charge_guarantees ) {
202
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
202
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
203
        my @guarantees = $p->guarantees();
203
        my @guarantees = map { $_->guarantee } $p->guarantee_relationships;
204
        my $guarantees_non_issues_charges;
204
        my $guarantees_non_issues_charges;
205
        foreach my $g ( @guarantees ) {
205
        foreach my $g ( @guarantees ) {
206
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
206
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
Lines 321-327 sub ModMember { Link Here
321
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
321
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
322
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
322
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
323
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
323
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
324
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
325
324
326
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
325
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
327
326
Lines 434-440 sub AddMember { Link Here
434
    $data{'dateofbirth'}     = undef if ( not $data{'dateofbirth'} );
433
    $data{'dateofbirth'}     = undef if ( not $data{'dateofbirth'} );
435
    $data{'debarred'}        = undef if ( not $data{'debarred'} );
434
    $data{'debarred'}        = undef if ( not $data{'debarred'} );
436
    $data{'sms_provider_id'} = undef if ( not $data{'sms_provider_id'} );
435
    $data{'sms_provider_id'} = undef if ( not $data{'sms_provider_id'} );
437
    $data{'guarantorid'}     = undef if ( not $data{'guarantorid'} );
438
436
439
    # get only the columns of Borrower
437
    # get only the columns of Borrower
440
    # FIXME Do we really need this check?
438
    # FIXME Do we really need this check?
Lines 913-930 sub GetBorrowersToExpunge { Link Here
913
        FROM   borrowers
911
        FROM   borrowers
914
        JOIN   categories USING (categorycode)
912
        JOIN   categories USING (categorycode)
915
        LEFT JOIN (
913
        LEFT JOIN (
916
            SELECT guarantorid
914
            SELECT guarantor_id
917
            FROM borrowers
915
            FROM relationships
918
            WHERE guarantorid IS NOT NULL
916
            WHERE guarantor_id IS NOT NULL
919
                AND guarantorid <> 0
917
                AND guarantor_id <> 0
920
        ) as tmp ON borrowers.borrowernumber=tmp.guarantorid
918
        ) as tmp ON borrowers.borrowernumber=tmp.guarantor_id
921
        LEFT JOIN old_issues USING (borrowernumber)
919
        LEFT JOIN old_issues USING (borrowernumber)
922
        LEFT JOIN issues USING (borrowernumber)|;
920
        LEFT JOIN issues USING (borrowernumber)|;
923
    if ( $filterpatronlist  ){
921
    if ( $filterpatronlist  ){
924
        $query .= q| LEFT JOIN patron_list_patrons USING (borrowernumber)|;
922
        $query .= q| LEFT JOIN patron_list_patrons USING (borrowernumber)|;
925
    }
923
    }
926
    $query .= q| WHERE  category_type <> 'S'
924
    $query .= q| WHERE  category_type <> 'S'
927
        AND tmp.guarantorid IS NULL
925
        AND tmp.guarantor_id IS NULL
928
   |;
926
   |;
929
    my @query_params;
927
    my @query_params;
930
    if ( $filterbranch && $filterbranch ne "" ) {
928
    if ( $filterbranch && $filterbranch ne "" ) {
(-)a/C4/SIP/ILS/Patron.pm (-1 lines)
Lines 557-563 __END__ Link Here
557
| contactname         | mediumtext   | YES  |     | NULL    |                |
557
| contactname         | mediumtext   | YES  |     | NULL    |                |
558
| contactfirstname    | text         | YES  |     | NULL    |                |
558
| contactfirstname    | text         | YES  |     | NULL    |                |
559
| contacttitle        | text         | YES  |     | NULL    |                |
559
| contacttitle        | text         | YES  |     | NULL    |                |
560
| guarantorid         | int(11)      | YES  | MUL | NULL    |                |
561
| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
560
| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
562
| relationship        | varchar(100) | YES  |     | NULL    |                |
561
| relationship        | varchar(100) | YES  |     | NULL    |                |
563
| ethnicity           | varchar(50)  | YES  |     | NULL    |                |
562
| 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 71-78 sub new { Link Here
71
            next if not exists $attributes->{$column_name} or defined $attributes->{$column_name};
71
            next if not exists $attributes->{$column_name} or defined $attributes->{$column_name};
72
            delete $attributes->{$column_name};
72
            delete $attributes->{$column_name};
73
        }
73
        }
74
        $self->{_result} = $schema->resultset( $class->_type() )
74
75
          ->new($attributes);
75
        eval {
76
            $self->{_result} =
77
              $schema->resultset( $class->_type() )->new($attributes);
78
        };
79
        Carp::cluck("ERROR: $@") if $@;
76
    }
80
    }
77
81
78
    croak("No _type found! Koha::Object must be subclassed!")
82
    croak("No _type found! Koha::Object must be subclassed!")
(-)a/Koha/Patron.pm (-32 / +50 lines)
Lines 25-39 use Carp; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Log;
26
use C4::Log;
27
use Koha::Checkouts;
27
use Koha::Checkouts;
28
use Koha::Old::Checkouts;
28
use Koha::Database;
29
use Koha::Database;
29
use Koha::DateUtils;
30
use Koha::DateUtils;
30
use Koha::Holds;
31
use Koha::Holds;
31
use Koha::Old::Checkouts;
32
use Koha::Patrons;
32
use Koha::Patron::Categories;
33
use Koha::Patron::Categories;
34
use Koha::Patron::Relationships;
33
use Koha::Patron::HouseboundProfile;
35
use Koha::Patron::HouseboundProfile;
34
use Koha::Patron::HouseboundRole;
36
use Koha::Patron::HouseboundRole;
35
use Koha::Patron::Images;
37
use Koha::Patron::Images;
36
use Koha::Patrons;
37
use Koha::Virtualshelves;
38
use Koha::Virtualshelves;
38
use Koha::Club::Enrollments;
39
use Koha::Club::Enrollments;
39
use Koha::Account;
40
use Koha::Account;
Lines 108-148 sub category { Link Here
108
    return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode );
109
    return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode );
109
}
110
}
110
111
111
=head3 guarantor
112
=head3 image
112
113
Returns a Koha::Patron object for this patron's guarantor
114
113
115
=cut
114
=cut
116
115
117
sub guarantor {
116
sub image {
118
    my ( $self ) = @_;
117
    my ( $self ) = @_;
119
118
120
    return unless $self->guarantorid();
119
    return Koha::Patron::Images->find( $self->borrowernumber )
121
122
    return Koha::Patrons->find( $self->guarantorid() );
123
}
120
}
124
121
125
sub image {
122
=head3 library
126
    my ( $self ) = @_;
127
123
128
    return Koha::Patron::Images->find( $self->borrowernumber );
124
=cut
129
}
130
125
131
sub library {
126
sub library {
132
    my ( $self ) = @_;
127
    my ( $self ) = @_;
133
    return Koha::Library->_new_from_dbic($self->_result->branchcode);
128
    return Koha::Library->_new_from_dbic($self->_result->branchcode);
134
}
129
}
135
130
136
=head3 guarantees
131
=head3 guarantor_relationships
132
133
Returns Koha::Patron::Relationships object for this patron's guarantors
134
135
Returns the set of relationships for the patrons that are guarantors for this patron.
137
136
138
Returns the guarantees (list of Koha::Patron) of this patron
137
This is returned instead of a Koha::Patron object because the guarantor
138
may not exist as a patron in Koha. If this is true, the guarantors name
139
exists in the Koha::Patron::Relationship object and will have no guarantor_id.
139
140
140
=cut
141
=cut
141
142
142
sub guarantees {
143
sub guarantor_relationships {
143
    my ( $self ) = @_;
144
    my ($self) = @_;
144
145
145
    return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
146
    return Koha::Patron::Relationships->search( { guarantee_id => $self->id } );
147
}
148
149
=head3 guarantee_relationships
150
151
Returns Koha::Patron::Relationships object for this patron's guarantors
152
153
Returns the set of relationships for the patrons that are guarantees for this patron.
154
155
The method returns Koha::Patron::Relationship objects for the sake
156
of consistency with the guantors method.
157
A guarantee by definition must exist as a patron in Koha.
158
159
=cut
160
161
sub guarantee_relationships {
162
    my ($self) = @_;
163
164
    return Koha::Patron::Relationships->search( { guarantor_id => $self->id } );
146
}
165
}
147
166
148
=head3 housebound_profile
167
=head3 housebound_profile
Lines 180-202 Returns the siblings of this patron. Link Here
180
=cut
199
=cut
181
200
182
sub siblings {
201
sub siblings {
183
    my ( $self ) = @_;
202
    my ($self) = @_;
184
203
185
    my $guarantor = $self->guarantor;
204
    my @guarantors = $self->guarantor_relationships()->guarantors();
186
205
187
    return unless $guarantor;
206
    return unless @guarantors;
188
207
189
    return Koha::Patrons->search(
208
    my @siblings =
190
        {
209
      map { $_->guarantee_relationships()->guarantees() } @guarantors;
191
            guarantorid => {
210
192
                '!=' => undef,
211
    return unless @siblings;
193
                '=' => $guarantor->id,
212
194
            },
213
    my %seen;
195
            borrowernumber => {
214
    @siblings =
196
                '!=' => $self->borrowernumber,
215
      grep { !$seen{ $_->id }++ && ( $_->id != $self->id ) } @siblings;
197
            }
216
198
        }
217
    return wantarray ? @siblings : Koha::Patrons->search( { borrowernumber => { -in => [ map { $_->id } @siblings ] } } );
199
    );
200
}
218
}
201
219
202
=head3 wants_check_for_previous_checkout
220
=head3 wants_check_for_previous_checkout
(-)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 103-120 sub search_upcoming_membership_expires { Link Here
103
    );
103
    );
104
}
104
}
105
105
106
=head3 guarantor
107
108
Returns a Koha::Patron object for this borrower's guarantor
109
110
=cut
111
112
sub guarantor {
113
    my ( $self ) = @_;
114
115
    return Koha::Patrons->find( $self->guarantorid() );
116
}
117
118
=head3 search_patrons_to_anonymise
106
=head3 search_patrons_to_anonymise
119
107
120
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
108
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
(-)a/Koha/Schema/Result/Borrower.pm (-6 lines)
Lines 1389-1400 __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); Link Here
1389
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-11-09 11:42:45
1389
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-11-09 11:42:45
1390
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UitEC1xK/a76Ff4ZCS2BKA
1390
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UitEC1xK/a76Ff4ZCS2BKA
1391
1391
1392
__PACKAGE__->belongs_to(
1393
    "guarantor",
1394
    "Koha::Schema::Result::Borrower",
1395
    { borrowernumber => "guarantorid" },
1396
);
1397
1398
__PACKAGE__->add_columns(
1392
__PACKAGE__->add_columns(
1399
    '+lost' => { is_boolean => 1 },
1393
    '+lost' => { is_boolean => 1 },
1400
    '+gonenoaddress' => { is_boolean => 1 }
1394
    '+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 171-180 Link Here
171
      "type": ["string", "null"],
171
      "type": ["string", "null"],
172
      "description": "used for children to include title of guarantor"
172
      "description": "used for children to include title of guarantor"
173
    },
173
    },
174
    "guarantorid": {
175
      "type": ["integer", "null"],
176
      "description": "borrowernumber used for children or professionals to link them to guarantor or organizations"
177
    },
178
    "borrowernotes": {
174
    "borrowernotes": {
179
      "type": ["string", "null"],
175
      "type": ["string", "null"],
180
      "description": "a note on the patron's account"
176
      "description": "a note on the patron's account"
(-)a/circ/circulation.pl (-8 / +6 lines)
Lines 579-592 my $view = $batch Link Here
579
    : 'circview';
579
    : 'circview';
580
580
581
my @relatives;
581
my @relatives;
582
if ( $borrowernumber ) {
582
if ( $patron ) {
583
    if ( $patron ) {
583
    if ( my @guarantors = $patron->guarantor_relationships()->guarantors() ) {
584
        if ( my $guarantor = $patron->guarantor ) {
584
        push( @relatives, $_->id ) for @guarantors;
585
            push @relatives, $guarantor->borrowernumber;
585
        push( @relatives, $_->id ) for $patron->siblings();
586
            push @relatives, $_->borrowernumber for $patron->siblings;
586
    } else {
587
        } else {
587
        push( @relatives, $_->id ) for $patron->guarantee_relationships()->guarantees();
588
            push @relatives, $_->borrowernumber for $patron->guarantees;
589
        }
590
    }
588
    }
591
}
589
}
592
my $relatives_issues_count =
590
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 / +15 lines)
Lines 608-619 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower Link Here
608
  `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
608
  `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
609
  `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)
609
  `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)
610
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
610
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
611
  `contactname` mediumtext, -- used for children and profesionals to include surname or last name of guarantor or organization name
612
  `contactfirstname` text, -- used for children to include first name of guarantor
613
  `contacttitle` text, -- used for children to include title (Mr., Mrs., etc) of guarantor
614
  `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarantors or organizations
615
  `borrowernotes` mediumtext, -- a note on the patron/borrower's account that is only visible in the staff client
611
  `borrowernotes` mediumtext, -- a note on the patron/borrower's account that is only visible in the staff client
616
  `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
617
  `sex` varchar(1) default NULL, -- patron/borrower's gender
612
  `sex` varchar(1) default NULL, -- patron/borrower's gender
618
  `password` varchar(60) default NULL, -- patron/borrower's encrypted password
613
  `password` varchar(60) default NULL, -- patron/borrower's encrypted password
619
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
614
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
Lines 1633-1644 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1633
  `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
1628
  `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
1634
  `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)
1629
  `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)
1635
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1630
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1636
  `contactname` mediumtext, -- used for children and profesionals to include surname or last name of guarantor or organization name
1637
  `contactfirstname` text, -- used for children to include first name of guarantor
1638
  `contacttitle` text, -- used for children to include title (Mr., Mrs., etc) of guarantor
1639
  `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarantors or organizations
1640
  `borrowernotes` mediumtext, -- a note on the patron/borrower's account that is only visible in the staff client
1631
  `borrowernotes` mediumtext, -- a note on the patron/borrower's account that is only visible in the staff client
1641
  `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
1642
  `sex` varchar(1) default NULL, -- patron/borrower's gender
1632
  `sex` varchar(1) default NULL, -- patron/borrower's gender
1643
  `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1633
  `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1644
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
1634
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
Lines 1671-1677 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1671
  KEY `categorycode` (`categorycode`),
1661
  KEY `categorycode` (`categorycode`),
1672
  KEY `branchcode` (`branchcode`),
1662
  KEY `branchcode` (`branchcode`),
1673
  UNIQUE KEY `userid` (`userid`),
1663
  UNIQUE KEY `userid` (`userid`),
1674
  KEY `guarantorid` (`guarantorid`),
1675
  KEY `surname_idx` (`surname`(255)),
1664
  KEY `surname_idx` (`surname`(255)),
1676
  KEY `firstname_idx` (`firstname`(255)),
1665
  KEY `firstname_idx` (`firstname`(255)),
1677
  KEY `othernames_idx` (`othernames`(255)),
1666
  KEY `othernames_idx` (`othernames`(255)),
Lines 3429-3440 CREATE TABLE IF NOT EXISTS `borrower_modifications` ( Link Here
3429
  `lost` tinyint(1) DEFAULT NULL,
3418
  `lost` tinyint(1) DEFAULT NULL,
3430
  `debarred` date DEFAULT NULL,
3419
  `debarred` date DEFAULT NULL,
3431
  `debarredcomment` varchar(255) DEFAULT NULL,
3420
  `debarredcomment` varchar(255) DEFAULT NULL,
3432
  `contactname` mediumtext,
3433
  `contactfirstname` text,
3434
  `contacttitle` text,
3435
  `guarantorid` int(11) DEFAULT NULL,
3436
  `borrowernotes` mediumtext,
3421
  `borrowernotes` mediumtext,
3437
  `relationship` varchar(100) DEFAULT NULL,
3438
  `sex` varchar(1) DEFAULT NULL,
3422
  `sex` varchar(1) DEFAULT NULL,
3439
  `password` varchar(30) DEFAULT NULL,
3423
  `password` varchar(30) DEFAULT NULL,
3440
  `flags` int(11) DEFAULT NULL,
3424
  `flags` int(11) DEFAULT NULL,
Lines 4112-4117 CREATE TABLE IF NOT EXISTS club_fields ( Link Here
4112
  CONSTRAINT club_fields_ibfk_3 FOREIGN KEY (club_template_field_id) REFERENCES club_template_fields (id) ON DELETE CASCADE ON UPDATE CASCADE,
4096
  CONSTRAINT club_fields_ibfk_3 FOREIGN KEY (club_template_field_id) REFERENCES club_template_fields (id) ON DELETE CASCADE ON UPDATE CASCADE,
4113
  CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE
4097
  CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE
4114
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4098
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4099
-- Table structure for table 'guarantors_guarantees'
4100
--
4101
4102
DROP TABLE IF EXISTS relationships;
4103
CREATE TABLE `relationships` (
4104
      id INT(11) NOT NULL AUTO_INCREMENT,
4105
      guarantor_id INT(11) NULL DEFAULT NULL,
4106
      guarantee_id INT(11) NOT NULL,
4107
      relationship VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL,
4108
      surname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
4109
      firstname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
4110
      PRIMARY KEY (id),
4111
      CONSTRAINT r_guarantor FOREIGN KEY ( guarantor_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE,
4112
      CONSTRAINT r_guarantee FOREIGN KEY ( guarantee_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
4113
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4115
4114
4116
--
4115
--
4117
-- Table structure for table `illrequests`
4116
-- Table structure for table `illrequests`
(-)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 (-6 / +3 lines)
Lines 133-149 function searchToHold(){ Link Here
133
133
134
<div id="toolbar" class="btn-toolbar">
134
<div id="toolbar" class="btn-toolbar">
135
    [% IF ( CAN_user_borrowers ) %]
135
    [% IF ( CAN_user_borrowers ) %]
136
        [% IF ( guarantor ) %]
137
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% borrowernumber %]&amp;guarantorid=[% guarantor.borrowernumber %]&amp;categorycode=[% categorycode %]">
138
        [% ELSE %]
139
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% borrowernumber %]&amp;categorycode=[% categorycode %]">
136
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% borrowernumber %]&amp;categorycode=[% categorycode %]">
140
        [% END %]
137
                <i class="fa fa-pencil"></i> Edit
141
        <i class="fa fa-pencil"></i> Edit</a>
138
            </a>
142
    [% END %]
139
    [% END %]
143
140
144
    [% IF ( CAN_user_borrowers ) %]
141
    [% IF ( CAN_user_borrowers ) %]
145
        [% IF adultborrower AND Koha.Preference("borrowerRelationship") %]
142
        [% IF adultborrower AND Koha.Preference("borrowerRelationship") %]
146
            <a id="addchild" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;guarantorid=[% borrowernumber %]"><i class="fa fa-plus"></i> Add child</a>
143
            <a id="addchild" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;guarantor_id=[% borrowernumber %]"><i class="fa fa-plus"></i> Add child</a>
147
        [% END %]
144
        [% END %]
148
        [% IF ( CAN_user_borrowers ) %]
145
        [% IF ( CAN_user_borrowers ) %]
149
            <a id="changepassword" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/member-password.pl?member=[% borrowernumber %]"><i class="fa fa-lock"></i> Change password</a>
146
            <a id="changepassword" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/member-password.pl?member=[% borrowernumber %]"><i class="fa fa-lock"></i> Change password</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +1 lines)
Lines 932-938 No patron matched <span class="ex">[% message | html %]</span> Link Here
932
    </li>
932
    </li>
933
933
934
    [% IF relatives_issues_count %]
934
    [% IF relatives_issues_count %]
935
        <li><a id="relatives-issues-tab" href="#relatives-issues">Relatives' checkouts</a></li>
935
        <li><a id="relatives-issues-tab" href="#relatives-issues">[% relatives_issues_count %] Relatives' checkouts</a></li>
936
    [% END %]
936
    [% END %]
937
937
938
    <li>
938
    <li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-104 / +179 lines)
Lines 1-3 Link Here
1
[% USE To %]
1
[% USE Koha %]
2
[% USE Koha %]
2
[% USE KohaDates %]
3
[% USE KohaDates %]
3
[% USE Branches %]
4
[% USE Branches %]
Lines 25-38 $(document).ready(function() { Link Here
25
            $('#toolbar').fixFloat({ 'originalOffset': original_offset });
26
            $('#toolbar').fixFloat({ 'originalOffset': original_offset });
26
        })
27
        })
27
28
28
	[% IF categorycode %]
29
    [% IF categorycode %]
29
		update_category_code( "[% categorycode %]" );
30
        update_category_code( "[% categorycode %]" );
30
	[% ELSE %]
31
    [% ELSE %]
31
		if ( $("#categorycode_entry").length > 0 ){
32
        if ( $("#categorycode_entry").length > 0 ) {
32
			var category_code = $("#categorycode_entry").find("option:selected").val();
33
            var category_code = $("#categorycode_entry").find("option:selected").val();
33
			update_category_code( category_code );
34
            update_category_code( category_code );
34
		}
35
        }
35
	[% END %]
36
    [% END %]
37
38
    [% IF guarantor %]
39
        select_user( '[% guarantor.borrowernumber %]', [% To.json( guarantor.unblessed ) %] );
40
        $('#guarantor_add').ready(function() {
41
            $('#guarantor_add').click();
42
        });
43
    [% END %]
44
36
});
45
});
37
46
38
function update_cardnumber_warning(size){
47
function update_cardnumber_warning(size){
Lines 428-533 $(document).ready(function() { Link Here
428
	</fieldset>
437
	</fieldset>
429
[% END # hide fieldset %]
438
[% END # hide fieldset %]
430
439
431
[% IF ( showguarantor ) %]
440
[% IF show_guarantor || guarantor %]
432
    <input type="hidden" id="guarantorid" name="guarantorid"   value="[% guarantorid %]" />
441
    [% SET possible_relationships = Koha.Preference('borrowerRelationship') %]
433
    [% UNLESS step_6 %]
442
    <fieldset class="rows">
434
        <input type="hidden" name="branchcode" value="[% branchcode %]" />
443
        <legend>Guarantor information</legend>
435
    [% END %]
444
436
    <fieldset id="memberentry_guarantor" class="rows">
445
        <span id="guarantor_relationships">
437
        <legend id="guarantor_lgd">Guarantor information</legend>
446
            [% FOREACH r IN relationships %]
438
        <ol>
447
                <fieldset class="rows">
439
[% IF ( P ) %]
448
                    <ol>
440
	        [% IF ( guarantorid ) %]
449
                        [% IF catetory_type == 'P' %]
441
	        <li id="contact-details">
450
                            [% IF ( r.guarantor_id ) %]
442
	        [% ELSE %]
451
                                <li id="contact-details">
443
	        <li id="contact-details" style="display: none">
452
                            [% ELSE %]
444
	        [% END %]
453
                                <li id="contact-details" style="display: none">
445
	            <span class="label">Organization #:</span> [% IF ( guarantorid ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorid %]" target="blank">[% guarantorid %]</a>[% END %]
454
                            [% END %]
446
	        </li>
455
                                <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 %]
447
	        <li>
456
                            </li>
448
	            <label for="contactname">Organization name: </label>
457
449
	            [% IF ( guarantorid ) %]
458
                            <li>
450
	            <span>[% contactname %]</span>
459
                                <label for="guarantor_surname">Organization name: </label>
451
	            <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname | html %]" />
460
                                [% IF ( r.guarantor_id ) %]
452
	            [% ELSE %]
461
                                    <span>[% r.guarantor.surname %]</span>
453
                    <input name="contactname" id="contactname" type="text" size="20" value="[% contactname | html %]" />
462
                                [% END %]
454
	            [% END %]
463
                            </li>
455
	        </li>
464
                        [% ELSE %]
456
[% ELSE %]
465
                            [% IF category_type == 'C'  %]
457
 [% IF ( C ) %]
466
                                [% IF ( r.guarantor_id ) %]
458
 [% IF ( guarantorid ) %]
467
                                    <li id="contact-details">
459
 <li id="contact-details">
468
                                [% ELSE %]
460
 [% ELSE %]
469
                                    <li id="contact-details" style="display: none">
461
 <li id="contact-details" style="display: none">
470
                                [% END %]
462
 [% END %]
471
463
     <span class="label">Patron #:</span> [% IF ( guarantorid ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorid %]" target="blank">[% guarantorid |html %]</a>[% END %]
472
                                    <span class="label">Patron #:</span>
464
 </li>
473
                                    [% IF ( r.guarantor_id ) %]
465
        [% UNLESS nocontactname %]
474
                                        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% r.guarantor_id %]" target="blank">[% r.guarantor_id %]</a>
466
 <li>
475
                                    [% END %]
467
     <label for="contactname">Surname: </label>
476
468
     [% IF ( guarantorid ) %]
477
                                </li>
469
     <span>[% contactname %]</span>
478
470
     <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname | html %]" />
479
                                [% IF r.surname || r.guarantor.surname %]
471
     [% ELSE %]
480
                                    <li>
472
        <input name="contactname" id="contactname" type="text" size="20" value="[% contactname | html %]" />
481
                                        <label for="guarantor_surname">Surname: </label>
473
     [% END %]
482
                                        <span>[% r.surname || r.guarantor.surname %]</span>
474
 </li>
483
                                    </li>
475
        [% END %]
484
                                [% END %]
476
        [% UNLESS nocontactfirstname %]
485
477
 <li>
486
                                [% IF r.firstname || r.guarantor.firstname  %]
478
     <label for="contactfirstname">First name: </label>
487
                                    <li>
479
     [% IF ( guarantorid ) %]
488
                                        <label for="guarantor_firstname">First name: </label>
480
     <span>[% contactfirstname %]</span>
489
                                        <span>[% r.firstname || r.guarantor.firstname %]</span>
481
     <input name="contactfirstname" id="contactfirstname" type="hidden" size="20" value="[% contactfirstname | html %]" />
490
                                    </li>
482
     [% ELSE %]
491
                                [% END %]
483
        <input name="contactfirstname" id="contactfirstname" type="text" size="20" value="[% contactfirstname | html %]" />
492
484
     [% END %]
493
                                <li>
485
 </li>
494
                                    <label for="relationship">Relationship: </label>
486
        [% END %]
495
                                    <span>[% r.relationship %]</span>
487
 [% IF ( relshiploop ) %]
496
                                </li>
488
 <li>
497
489
     <label for="relationship">Relationship: </label>
498
                                <li>
490
     <select name="relationship" id="relationship" >
499
                                    <label for="delete_guarantor">Delete: </label>
491
         [% FOREACH relshiploo IN relshiploop %]
500
                                    <input type="checkbox" name="delete_guarantor" value="[% r.id %]" />
492
         [% IF ( relshiploo.selected ) %]
501
                                </li>
493
         <option value="[% relshiploo.relationship %]" selected="selected" >[% relshiploo.relationship %]</option>
502
                            [% END %]
494
         [% ELSE %]
503
                        [% END %]
495
         <option value="[% relshiploo.relationship %]">[% relshiploo.relationship %]</option>
504
                    </ol>
496
         [% END %]
505
                </fieldset>
497
         [% END %]
506
            [% END # END relationships foreach %]
498
     </select>
507
        </span>
499
 </li>
508
500
 [% END %]
509
        <fieldset class="rows guarantor" id="guarantor_template">
501
 [% END %]
510
            <ol>
502
[% END %]
511
                <li class="guarantor_id">
503
        <li>
512
                    <span class="label">Patron #:</span>
504
            <span class="label">&nbsp;</span>
513
                    <span class="new_guarantor_id_text"></span>
505
            [% IF ( guarantorid ) %]
514
                    <input type="hidden" class="new_guarantor_id" name="new_guarantor_id" value=""/>
506
            <input id="guarantorsearch" type="button" value="Change" onclick="Dopopguarantor('guarantor_search.pl');" />
515
                </li>
507
            [% ELSE %]
516
508
            <input id="guarantorsearch" type="button" value="Set to patron" onclick="Dopopguarantor('guarantor_search.pl');" />
517
                <li>
509
            [% END %]
518
                    <label for="guarantor_surname">Surname: </label>
510
            <input id="guarantordelete" type="button" value="Delete" />
519
                    <span class="new_guarantor_surname_text"></span>
511
        </li>
520
                    <input type="hidden" class="new_guarantor_surname" name="new_guarantor_surname" value=""/>
512
    [% IF guarantorid && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
521
                </li>
513
        <li>
522
514
            <label for="privacy_guarantor_checkouts">Show checkouts to guarantor</label>
523
                <li>
515
            <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
524
                    <label for="guarantor_firstname">First name: </label>
516
                [% IF privacy_guarantor_checkouts %]
525
                    <span class="new_guarantor_firstname_text"></span>
517
                    <option value="0">No</option>
526
                    <input type="hidden" class="new_guarantor_firstname" name="new_guarantor_firstname" value=""/>
518
                    <option value="1" selected>Yes</option>
527
                </li>
528
529
                <li>
530
                    <label for="guarantor_relationship">Relationship: </label>
531
                    <select class="new_guarantor_relationship" name="new_guarantor_relationship">
532
                        [% FOREACH pr IN possible_relationships.split('\|') %]
533
                            <option value="[% pr %]">[% pr %]</option>
534
                        [% END %]
535
                    </select>
536
                </li>
537
538
                <li>
539
                    <label for="guarantor_cancel">&nbsp;</label>
540
                    <span><a href="#" class="guarantor_cancel">Cancel</a></span>
541
                </li>
542
            </ol>
543
        </fieldset>
544
545
        <fieldset class="rows">
546
            <legend>Add new guarantor</legend>
547
            <ol>
548
                <input type="hidden" id="guarantor_id" value=""/>
549
550
                [% IF catetory_type == 'P' %]
551
                    <li>
552
                        <label for="guarantor_surname">Organization name: </label>
553
                        <input name="guarantor_surname" id="guarantor_surname" type="hidden" size="20"/>
554
                    </li>
519
                [% ELSE %]
555
                [% ELSE %]
520
                    <option value="0" selected>No</option>
556
                    <li>
521
                    <option value="1">Yes</option>
557
                        <label for="guarantor_surname">Surname: </label>
558
                        <input name="guarantor_surname" id="guarantor_surname" type="text" size="20" />
559
                    </li>
560
561
                    <li>
562
                        <label for="guarantor_firstname">First name: </label>
563
                        <input name="guarantor_firstname" id="guarantor_firstname" type="text" size="20" />
564
                    </li>
565
566
                    [% IF ( possible_relationships ) %]
567
                        <li>
568
                            <label for="relationship">Relationship: </label>
569
                            <select name="relationship" id="relationship" >
570
                                [% FOREACH pr IN possible_relationships.split('\|') %]
571
                                    <option value="[% pr %]">[% pr %]</option>
572
                                [% END %]
573
                            </select>
574
                        </li>
575
                    [% END %]
522
                [% END %]
576
                [% END %]
523
            </select>
524
            <div class="hint">Allow guarantor of this patron to view this patron's checkouts from the OPAC</div>
525
        </li>
526
    [% END %]
527
        </ol>
528
    </fieldset>
529
577
578
                <li>
579
                    <span class="label">&nbsp;</span>
580
                    <a href="#" id="guarantor_add" class="btn btn-small"><i class="fa fa-plus"></i> Add guarantor</a>
581
                    <a href="#" id="guarantor_search" class="btn btn-small"><i class="fa fa-search"></i> Set to patron</a>
582
                    <a href="#" id="guarantor_clear">Clear</a>
583
                </li>
584
585
                [% IF relationships && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
586
                    <li>
587
                        <label for="privacy_guarantor_checkouts">Show checkouts to guarantors</label>
588
                        <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
589
                            [% IF privacy_guarantor_checkouts %]
590
                                <option value="0">No</option>
591
                                <option value="1" selected>Yes</option>
592
                            [% ELSE %]
593
                                <option value="0" selected>No</option>
594
                                <option value="1">Yes</option>
595
                            [% END %]
596
                        </select>
597
                        <div class="hint">Allow guarantors of this patron to view this patron's checkouts from the OPAC</div>
598
                    </li>
599
                [% END %]
600
            </ol>
601
        </fieldset>
602
    </fieldset>
530
[% END %]
603
[% END %]
604
605
531
[% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
606
[% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
532
    [% IF Koha.Preference( 'AddressFormat' ) %]
607
    [% IF Koha.Preference( 'AddressFormat' ) %]
533
        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
608
        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt (-2 / +20 lines)
Lines 42-49 Link Here
42
            <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>
42
            <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>
43
        [% END %]
43
        [% END %]
44
    [% ELSE %]
44
    [% ELSE %]
45
        [% IF ( guarantor.borrowernumber ) %]
45
    [% IF guarantees %]
46
            <li><span class="label">Guarantor:</span><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.surname %], [% guarantor.firstname %]</a></li>
46
        <li>
47
            <span class="label">Guarantees:</span>
48
            <ul>
49
                [% FOREACH guarantee IN guarantees %]
50
                    <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantee.borrowernumber %]">[% guarantee.firstname %] [% guarantee.surname %]</a></li>
51
                [% END %]
52
            </ul>
53
        </li>
54
    [% ELSIF guarantor_relationships %]
55
        [% FOREACH gr IN guarantor_relationships %]
56
            <li>
57
                <span class="label">Guarantor:</span>
58
                [% IF gr.guarantor_id %]
59
                    [% SET guarantor = gr.guarantor %]
60
                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.id %]">[% guarantor.firstname %] [% guarantor.surname %]</a>
61
                [% ELSE %]
62
                    [% gr.firstname %] [% gr.surname %]
63
                [% END %]
64
            </li>
47
        [% END %]
65
        [% END %]
48
    [% END %]
66
    [% END %]
49
	</ol>
67
	</ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-17 / +13 lines)
Lines 257-281 function validate1(date) { Link Here
257
                    [% END %]
257
                    [% END %]
258
                </ul>
258
                </ul>
259
            </li>
259
            </li>
260
        [% ELSIF guarantor %]
260
        [% ELSIF guarantor_relationships %]
261
            <li>
261
            [% FOREACH gr IN guarantor_relationships %]
262
                <span class="label">Guarantor:</span>
262
                <li>
263
                [% IF guarantor.borrowernumber %]
263
                    <span class="label">Guarantor:</span>
264
                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.firstname | html %] [% guarantor.surname | html %]</a>
264
                    [% IF gr.guarantor_id %]
265
                [% ELSE %]
265
                        [% SET guarantor = gr.guarantor %]
266
                    [% guarantor.firstname | html %] [% guarantor.surname | html %]
266
                        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.id %]">[% guarantor.firstname %] [% guarantor.surname %]</a>
267
                [% END %]
267
                    [% ELSE %]
268
            </li>
268
                        [% gr.firstname %] [% gr.surname %]
269
                    [% END %]
270
                </li>
271
            [% END %]
269
        [% END %]
272
        [% END %]
270
    </ol>
273
    </ol>
271
</div>
274
</div>
272
      <div class="action">
273
        [% IF ( guarantor.borrowernumber ) %]
274
        <a href="memberentry.pl?op=modify&amp;borrowernumber=[% borrowernumber %]&amp;step=1&amp;guarantorid=[% guarantor.borrowernumber %]">Edit</a>
275
        [% ELSE %]
276
        <a href="memberentry.pl?op=modify&amp;borrowernumber=[% borrowernumber %]&amp;step=1">Edit</a>
277
        [% END %]</div>
278
279
</div>
275
</div>
280
276
281
<!-- Begin Upload Patron Image Section -->
277
<!-- Begin Upload Patron Image Section -->
Lines 505-511 function validate1(date) { Link Here
505
    <ul>
501
    <ul>
506
        <li><a href="#checkouts">[% issuecount %] Checkout(s)</a></li>
502
        <li><a href="#checkouts">[% issuecount %] Checkout(s)</a></li>
507
        [% IF relatives_issues_count %]
503
        [% IF relatives_issues_count %]
508
            <li><a href="#relatives-issues" id="relatives-issues-tab">Relatives' checkouts</a></li>
504
            <li><a href="#relatives-issues" id="relatives-issues-tab">[% relatives_issues_count %] Relatives' checkouts</a></li>
509
        [% END %]
505
        [% END %]
510
        <li><a href="#finesandcharges">Fines &amp; Charges</a></li>
506
        <li><a href="#finesandcharges">Fines &amp; Charges</a></li>
511
        <li>
507
        <li>
(-)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 98-104 Link Here
98
                    <div class="alert">You typed in the wrong characters in the box before submitting. Please try again.</div>
98
                    <div class="alert">You typed in the wrong characters in the box before submitting. Please try again.</div>
99
                [% END %]
99
                [% END %]
100
100
101
                [% IF borrower.guarantorid && !Koha.Preference('OPACPrivacy') && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
101
                [% IF patron.guarantor_relationships && !Koha.Preference('OPACPrivacy') && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
102
                    <fieldset class="rows" id="memberentry_privacy">
102
                    <fieldset class="rows" id="memberentry_privacy">
103
                        <legend id="privacy_legend">Privacy</legend>
103
                        <legend id="privacy_legend">Privacy</legend>
104
                        <ol>
104
                        <ol>
Lines 117-123 Link Here
117
                                    <span id="update_privacy_guarantor_checkouts_message" class="alert" style="display:none"></span>
117
                                    <span id="update_privacy_guarantor_checkouts_message" class="alert" style="display:none"></span>
118
                                </span>
118
                                </span>
119
                                <span class="hint">
119
                                <span class="hint">
120
                                    Your guarantor is <i>[% guarantor.firstname %] [% guarantor.surname %]</i>
120
                                    Guaranteed by
121
                                    [% FOREACH gr IN patron.guarantor_relationships %]
122
                                        [% SET g = gr.guarantor %]
123
                                        [% g.firstname || gr.firstname %] [% g.surname || gr.surname %]
124
                                        [%- IF ! loop.last %], [% END %]
125
                                    [% END %]
121
                                </span>
126
                                </span>
122
                            </li>
127
                            </li>
123
                        </ol>
128
                        </ol>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-privacy.tt (-2 / +7 lines)
Lines 69-75 Link Here
69
                                        </select>
69
                                        </select>
70
                                    </div>
70
                                    </div>
71
71
72
                                    [% IF borrower.guarantorid && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
72
                                    [% IF borrower.guarantor_relationships && Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
73
                                        <div>
73
                                        <div>
74
                                            <label for="privacy_guarantor_checkouts">Allow your guarantor to view your current checkouts?</label>
74
                                            <label for="privacy_guarantor_checkouts">Allow your guarantor to view your current checkouts?</label>
75
                                            <select name="privacy_guarantor_checkouts">
75
                                            <select name="privacy_guarantor_checkouts">
Lines 82-88 Link Here
82
                                                [% END %]
82
                                                [% END %]
83
                                            </select>
83
                                            </select>
84
                                            <span class="hint">
84
                                            <span class="hint">
85
                                                Your guarantor is <i>[% borrower.guarantor.firstname %] [% borrower.guarantor.surname %]</i>
85
                                                Guaranteed by
86
                                                [% FOREACH gr IN borrower.guarantor_relationships %]
87
                                                    [% SET g = gr.guarantor %]
88
                                                    [% g.firstname || gr.firstname %] [% g.surname || gr.surname %]
89
                                                    [%- IF ! loop.last %], [% END %]
90
                                                [% END %]
86
                                            </span>
91
                                            </span>
87
                                        </div>
92
                                        </div>
88
                                    [% END %]
93
                                    [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (-5 / +5 lines)
Lines 423-446 Using this account is not recommended because some parts of Koha will not functi Link Here
423
423
424
                                    <tbody>
424
                                    <tbody>
425
                                        [% FOREACH r IN relatives %]
425
                                        [% FOREACH r IN relatives %]
426
                                            [% FOREACH i IN r.issues %]
426
                                            [% FOREACH c IN r.checkouts %]
427
                                                <tr>
427
                                                <tr>
428
                                                    <td>
428
                                                    <td>
429
                                                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% i.item.biblio.biblionumber %]">
429
                                                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% i.item.biblio.biblionumber %]">
430
                                                            [% i.item.biblio.title %][% IF ( i.item.enumchron ) %] [% i.item.enumchron %][% END %]
430
                                                            [% c.item.biblio.title %][% IF ( c.item.enumchron ) %] [% c.item.enumchron %][% END %]
431
                                                        </a>
431
                                                        </a>
432
                                                    </td>
432
                                                    </td>
433
433
434
                                                    <td>
434
                                                    <td>
435
                                                        [% i.date_due | $KohaDates %]
435
                                                        [% c.date_due | $KohaDates %]
436
                                                    </td>
436
                                                    </td>
437
437
438
                                                    <td>
438
                                                    <td>
439
                                                        [% i.item.barcode %]
439
                                                        [% c.item.barcode %]
440
                                                    </td>
440
                                                    </td>
441
441
442
                                                    <td>
442
                                                    <td>
443
                                                        [% i.item.itemcallnumber %]
443
                                                        [% c.item.itemcallnumber %]
444
                                                    </td>
444
                                                    </td>
445
445
446
                                                    <td>
446
                                                    <td>
(-)a/members/deletemem.pl (-6 / +4 lines)
Lines 82-89 unless ( $patron ) { Link Here
82
my $flags = C4::Members::patronflags( $patron->unblessed );
82
my $flags = C4::Members::patronflags( $patron->unblessed );
83
my $userenv = C4::Context->userenv;
83
my $userenv = C4::Context->userenv;
84
84
85
 
86
87
if ($patron->category->category_type eq "S") {
85
if ($patron->category->category_type eq "S") {
88
    unless(C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) {
86
    unless(C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) {
89
        print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
87
        print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
Lines 108-115 if (C4::Context->preference("IndependentBranches")) { Link Here
108
106
109
my $op = $input->param('op') || 'delete_confirm';
107
my $op = $input->param('op') || 'delete_confirm';
110
my $dbh = C4::Context->dbh;
108
my $dbh = C4::Context->dbh;
111
my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member);
109
my $is_guarantor = $patron->guarantee_relationships->count;
112
if ( $op eq 'delete_confirm' or $countissues > 0 or $flags->{'CHARGES'}  or $is_guarantor or $deletelocal == 0) {
110
if ( $op eq 'delete_confirm' or $countissues > 0 or $flags->{'CHARGES'} or $is_guarantor or $deletelocal == 0) {
113
    $template->param( picture => 1 ) if $patron->image;
111
    $template->param( picture => 1 ) if $patron->image;
114
112
115
    $template->param( adultborrower => 1 ) if $patron->category->category_type =~ /^(A|I)$/;
113
    $template->param( adultborrower => 1 ) if $patron->category->category_type =~ /^(A|I)$/;
Lines 139-146 if ( $op eq 'delete_confirm' or $countissues > 0 or $flags->{'CHARGES'} or $is_ Link Here
139
    if ($flags->{'CHARGES'} ne '') {
137
    if ($flags->{'CHARGES'} ne '') {
140
        $template->param(charges => $flags->{'CHARGES'}->{'amount'});
138
        $template->param(charges => $flags->{'CHARGES'}->{'amount'});
141
    }
139
    }
142
    if ($is_guarantor) {
140
    if ( $is_guarantor ) {
143
        $template->param(guarantees => 1);
141
        $template->param( guarantees => 1 );
144
    }
142
    }
145
    if ($deletelocal == 0) {
143
    if ($deletelocal == 0) {
146
        $template->param(keeplocal => 1);
144
        $template->param(keeplocal => 1);
(-)a/members/memberentry.pl (-58 / +87 lines)
Lines 81-87 if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { Link Here
81
    $template->param( sms_providers => \@providers );
81
    $template->param( sms_providers => \@providers );
82
}
82
}
83
83
84
my $guarantorid    = $input->param('guarantorid');
85
my $borrowernumber = $input->param('borrowernumber');
84
my $borrowernumber = $input->param('borrowernumber');
86
my $actionType     = $input->param('actionType') || '';
85
my $actionType     = $input->param('actionType') || '';
87
my $modify         = $input->param('modify');
86
my $modify         = $input->param('modify');
Lines 98-110 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to rep Link Here
98
                                     # isn't a duplicate.  Marking FIXME because this
97
                                     # isn't a duplicate.  Marking FIXME because this
99
                                     # script needs to be refactored.
98
                                     # script needs to be refactored.
100
my $nok           = $input->param('nok');
99
my $nok           = $input->param('nok');
101
my $guarantorinfo = $input->param('guarantorinfo');
102
my $step          = $input->param('step') || 0;
100
my $step          = $input->param('step') || 0;
103
my @errors;
101
my @errors;
104
my $borrower_data;
102
my $borrower_data;
105
my $NoUpdateLogin;
103
my $NoUpdateLogin;
106
my $userenv = C4::Context->userenv;
104
my $userenv = C4::Context->userenv;
107
105
106
## Deal with guarantor stuff
107
my $patron = Koha::Patrons->find($borrowernumber);
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
}
108
119
109
## Deal with debarments
120
## Deal with debarments
110
$template->param(
121
$template->param(
Lines 138-151 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnam Link Here
138
my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
149
my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
139
my @field_check=split(/\|/,$check_BorrowerMandatoryField);
150
my @field_check=split(/\|/,$check_BorrowerMandatoryField);
140
foreach (@field_check) {
151
foreach (@field_check) {
141
	$template->param( "mandatory$_" => 1);    
152
    $template->param( "mandatory$_" => 1 );
142
}
153
}
143
# function to designate unwanted fields
154
# function to designate unwanted fields
144
my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
155
my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
145
@field_check=split(/\|/,$check_BorrowerUnwantedField);
156
@field_check=split(/\|/,$check_BorrowerUnwantedField);
146
foreach (@field_check) {
157
foreach (@field_check) {
147
    next unless m/\w/o;
158
    next unless m/\w/o;
148
	$template->param( "no$_" => 1);
159
    $template->param( "no$_" => 1 );
149
}
160
}
150
$template->param( "add" => 1 ) if ( $op eq 'add' );
161
$template->param( "add" => 1 ) if ( $op eq 'add' );
151
$template->param( "quickadd" => 1 ) if ( $quickadd );
162
$template->param( "quickadd" => 1 ) if ( $quickadd );
Lines 248-273 if ( ( $op eq 'insert' ) and !$nodouble ) { Link Here
248
    }
259
    }
249
}
260
}
250
261
251
  #recover all data from guarantor address phone ,fax... 
252
if ( $guarantorid ) {
253
    if (my $guarantor = Koha::Patrons->find( $guarantorid )) {
254
        my $guarantordata = $guarantor->unblessed;
255
        $category_type = $guarantordata->{categorycode} eq 'I' ? 'P' : 'C';
256
        $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
257
        $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
258
        $newdata{'contactname'}     = $guarantordata->{'surname'};
259
        $newdata{'contacttitle'}    = $guarantordata->{'title'};
260
        if ( $op eq 'add' ) {
261
	        foreach (qw(streetnumber address streettype address2
262
                        zipcode country city state phone phonepro mobile fax email emailpro branchcode
263
                        B_streetnumber B_streettype B_address B_address2
264
                        B_city B_state B_zipcode B_country B_email B_phone)) {
265
		        $newdata{$_} = $guarantordata->{$_};
266
	        }
267
        }
268
    }
269
}
270
271
###############test to take the right zipcode, country and city name ##############
262
###############test to take the right zipcode, country and city name ##############
272
# set only if parameter was passed from the form
263
# set only if parameter was passed from the form
273
$newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
264
$newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
Lines 419-424 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
419
	if ($op eq 'insert'){
410
	if ($op eq 'insert'){
420
		# we know it's not a duplicate borrowernumber or there would already be an error
411
		# we know it's not a duplicate borrowernumber or there would already be an error
421
        $borrowernumber = &AddMember(%newdata);
412
        $borrowernumber = &AddMember(%newdata);
413
        add_guarantors( $borrowernumber, $input );
422
        $newdata{'borrowernumber'} = $borrowernumber;
414
        $newdata{'borrowernumber'} = $borrowernumber;
423
415
424
        # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
416
        # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
Lines 516-521 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
516
                                                                # updating any columns in the borrowers table,
508
                                                                # updating any columns in the borrowers table,
517
                                                                # which can happen if we're only editing the
509
                                                                # which can happen if we're only editing the
518
                                                                # patron attributes or messaging preferences sections
510
                                                                # patron attributes or messaging preferences sections
511
        add_guarantors( $borrowernumber, $input );
519
        if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
512
        if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
520
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
513
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
521
        }
514
        }
Lines 623-633 foreach my $category_type (qw(C A S P I X)) { Link Here
623
        'categoryloop'   => \@categoryloop
616
        'categoryloop'   => \@categoryloop
624
      };
617
      };
625
}
618
}
626
619
$template->param(
627
$template->param('typeloop' => \@typeloop,
620
    typeloop      => \@typeloop,
628
        no_categories => $no_categories);
621
    no_categories => $no_categories,
629
if($no_categories){ $no_add = 1; }
622
);
630
631
623
632
my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
624
my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
633
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
625
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
Lines 652-675 while (@relationships) { Link Here
652
  push(@relshipdata, \%row);
644
  push(@relshipdata, \%row);
653
}
645
}
654
646
655
my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
647
my %flags = (
656
        'lost'          => ['lost']);
648
    'gonenoaddress' => ['gonenoaddress'],
649
    'lost'          => ['lost']
650
);
657
651
658
 
659
my @flagdata;
652
my @flagdata;
660
foreach (keys(%flags)) {
653
foreach ( keys(%flags) ) {
661
	my $key = $_;
654
    my $key = $_;
662
	my %row =  ('key'   => $key,
655
    my %row = (
663
		    'name'  => $flags{$key}[0]);
656
        'key'  => $key,
664
	if ($data{$key}) {
657
        'name' => $flags{$key}[0]
665
		$row{'yes'}=' checked';
658
    );
666
		$row{'no'}='';
659
    if ( $data{$key} ) {
667
    }
660
        $row{'yes'} = ' checked';
668
	else {
661
        $row{'no'}  = '';
669
		$row{'yes'}='';
662
    }
670
		$row{'no'}=' checked';
663
    else {
671
	}
664
        $row{'yes'} = '';
672
	push @flagdata,\%row;
665
        $row{'no'}  = ' checked';
666
    }
667
    push @flagdata, \%row;
673
}
668
}
674
669
675
# get Branch Loop
670
# get Branch Loop
Lines 745-751 if (C4::Context->preference('EnhancedMessagingPreferences')) { Link Here
745
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
740
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
746
}
741
}
747
742
748
$template->param( "showguarantor"  => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
743
$template->param( "show_guarantor" => ( $category_type =~ /A|I|S|X/ ) ? 0 : 1 ); # associate with step to know where you are
749
$debug and warn "memberentry step: $step";
744
$debug and warn "memberentry step: $step";
750
$template->param(%data);
745
$template->param(%data);
751
$template->param( "step_$step"  => 1) if $step;	# associate with step to know where u are
746
$template->param( "step_$step"  => 1) if $step;	# associate with step to know where u are
Lines 760-777 $template->param( Link Here
760
  "op$op"   => 1);
755
  "op$op"   => 1);
761
756
762
$template->param(
757
$template->param(
763
  nodouble  => $nodouble,
758
    nodouble       => $nodouble,
764
  borrowernumber  => $borrowernumber, #register number
759
    borrowernumber => $borrowernumber,          #register number
765
  guarantorid => ($borrower_data->{'guarantorid'} || $guarantorid),
760
    relshiploop    => \@relshipdata,
766
  relshiploop => \@relshipdata,
761
    btitle         => $default_borrowertitle,
767
  btitle=> $default_borrowertitle,
762
    flagloop       => \@flagdata,
768
  guarantorinfo   => $guarantorinfo,
763
    category_type  => $category_type,
769
  flagloop  => \@flagdata,
764
    modify         => $modify,
770
  category_type =>$category_type,
765
    nok            => $nok,                     #flag to know if an error
771
  modify          => $modify,
766
    NoUpdateLogin  => $NoUpdateLogin,
772
  nok     => $nok,#flag to know if an error
767
);
773
  NoUpdateLogin =>  $NoUpdateLogin,
774
  );
775
768
776
# Generate CSRF token
769
# Generate CSRF token
777
$template->param( csrf_token =>
770
$template->param( csrf_token =>
Lines 893-898 sub patron_attributes_form { Link Here
893
886
894
}
887
}
895
888
889
sub add_guarantors {
890
    my ( $borrowernumber, $input ) = @_;
891
892
    my @new_guarantor_id           = scalar $input->param('new_guarantor_id');
893
    my @new_guarantor_surname      = scalar $input->param('new_guarantor_surname');
894
    my @new_guarantor_firstname    = scalar $input->param('new_guarantor_firstname');
895
    my @new_guarantor_relationship = scalar $input->param('new_guarantor_relationship');
896
897
    for ( my $i = 0 ; $i < scalar @new_guarantor_id; $i++ ) {
898
        my $guarantor_id = $new_guarantor_id[$i];
899
        my $surname      = $new_guarantor_surname[$i];
900
        my $firstname    = $new_guarantor_firstname[$i];
901
        my $relationship = $new_guarantor_relationship[$i];
902
903
        if ($guarantor_id) {
904
            Koha::Patron::Relationship->new(
905
                {
906
                    guarantee_id => $borrowernumber,
907
                    guarantor_id => $guarantor_id,
908
                    relationship => $relationship
909
                }
910
            )->store();
911
        }
912
        elsif ($surname) {
913
            Koha::Patron::Relationship->new(
914
                {
915
                    guarantee_id => $borrowernumber,
916
                    surname      => $surname,
917
                    firstname    => $firstname,
918
                    relationship => $relationship
919
                }
920
            )->store();
921
        }
922
    }
923
}
924
896
# Local Variables:
925
# Local Variables:
897
# tab-width: 8
926
# tab-width: 8
898
# End:
927
# End:
(-)a/members/moremember.pl (-15 / +13 lines)
Lines 176-197 if ( $category_type eq 'C') { Link Here
176
}
176
}
177
177
178
my @relatives;
178
my @relatives;
179
if ( my $guarantor = $patron->guarantor ) {
179
my $guarantor_relationships = $patron->guarantor_relationships;
180
    $template->param( guarantor => $guarantor );
180
my @guarantees              = $patron->guarantee_relationships->guarantees;
181
    push @relatives, $guarantor->borrowernumber;
181
my @guarantors              = $guarantor_relationships->guarantors;
182
    push @relatives, $_->borrowernumber for $patron->siblings;
182
if (@guarantors) {
183
} elsif ( $patron->contactname || $patron->contactfirstname ) {
183
    push( @relatives, $_->id ) for @guarantors;
184
    $template->param(
184
    push( @relatives, $_->id ) for $patron->siblings();
185
        guarantor => {
186
            firstname => $patron->contactfirstname,
187
            surname   => $patron->contactname,
188
        }
189
    );
190
} else {
191
    my @guarantees = $patron->guarantees;
192
    $template->param( guarantees => \@guarantees );
193
    push @relatives, $_->borrowernumber for @guarantees;
194
}
185
}
186
else {
187
    push( @relatives, $_->id ) for @guarantees;
188
}
189
$template->param(
190
    guarantor_relationships => $guarantor_relationships,
191
    guarantees              => \@guarantees,
192
);
195
193
196
my $relatives_issues_count =
194
my $relatives_issues_count =
197
  Koha::Database->new()->schema()->resultset('Issue')
195
  Koha::Database->new()->schema()->resultset('Issue')
(-)a/members/update-child.pl (-8 / +14 lines)
Lines 35-40 use C4::Output; Link Here
35
use C4::Members;
35
use C4::Members;
36
use Koha::Patrons;
36
use Koha::Patrons;
37
use Koha::Patron::Categories;
37
use Koha::Patron::Categories;
38
use Koha::Patrons;
38
39
39
# use Smart::Comments;
40
# use Smart::Comments;
40
41
Lines 55-61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
55
my $borrowernumber = $input->param('borrowernumber');
56
my $borrowernumber = $input->param('borrowernumber');
56
my $catcode        = $input->param('catcode');
57
my $catcode        = $input->param('catcode');
57
my $cattype        = $input->param('cattype');
58
my $cattype        = $input->param('cattype');
58
my $catcode_multi = $input->param('catcode_multi');
59
my $catcode_multi  = $input->param('catcode_multi');
59
my $op             = $input->param('op');
60
my $op             = $input->param('op');
60
61
61
if ( $op eq 'multi' ) {
62
if ( $op eq 'multi' ) {
Lines 70-82 if ( $op eq 'multi' ) { Link Here
70
    );
71
    );
71
    output_html_with_http_headers $input, $cookie, $template->output;
72
    output_html_with_http_headers $input, $cookie, $template->output;
72
}
73
}
73
74
elsif ( $op eq 'update' ) {
74
elsif ( $op eq 'update' ) {
75
    my $patron = Koha::Patrons->find( $borrowernumber );
75
    my $patron = Koha::Patrons->find( $borrowernumber );
76
    unless ( $patron ) {
76
    unless ( $patron ) {
77
        print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
77
        print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
78
        exit;
78
        exit;
79
    }
79
    }
80
81
    $_->delete() for $patrons->guarantor_relationships();
82
80
    my $member = $patron->unblessed;
83
    my $member = $patron->unblessed;
81
    $member->{'guarantorid'}  = 0;
84
    $member->{'guarantorid'}  = 0;
82
    $member->{'categorycode'} = $catcode;
85
    $member->{'categorycode'} = $catcode;
Lines 86-99 elsif ( $op eq 'update' ) { Link Here
86
    delete $member->{password};
89
    delete $member->{password};
87
    ModMember(%$member);
90
    ModMember(%$member);
88
91
89
    if (  $catcode_multi ) {
92
    if ($catcode_multi) {
90
        $template->param(
93
        $template->param(
91
                SUCCESS        => 1,
94
            SUCCESS        => 1,
92
                borrowernumber => $borrowernumber,
95
            borrowernumber => $borrowernumber,
93
                );
96
        );
94
        output_html_with_http_headers $input, $cookie, $template->output;
97
        output_html_with_http_headers $input, $cookie, $template->output;
95
    } else {
98
    }
96
        print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
99
    else {
100
        print $input->redirect(
101
            "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"
102
        );
97
    }
103
    }
98
}
104
}
99
105
(-)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 305-311 elsif ( $action eq 'edit' ) { #Display logged in borrower's data Link Here
305
305
306
    $template->param(
306
    $template->param(
307
        borrower  => $borrower,
307
        borrower  => $borrower,
308
        guarantor => scalar Koha::Patrons->find($borrowernumber)->guarantor(),
309
        hidden => GetHiddenFields( $mandatory, 'modification' ),
308
        hidden => GetHiddenFields( $mandatory, 'modification' ),
310
        csrf_token => Koha::Token->new->generate_csrf({
309
        csrf_token => Koha::Token->new->generate_csrf({
311
            session_id => scalar $cgi->cookie('CGISESSID'),
310
            session_id => scalar $cgi->cookie('CGISESSID'),
Lines 326-332 my $captcha = random_string("CCCCC"); Link Here
326
325
327
$template->param(
326
$template->param(
328
    captcha        => $captcha,
327
    captcha        => $captcha,
329
    captcha_digest => md5_base64($captcha)
328
    captcha_digest => md5_base64($captcha),
329
    patron         => Koha::Patrons->find( $borrowernumber ),
330
);
330
);
331
331
332
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
332
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-user.pl (-8 / +9 lines)
Lines 39-44 use Koha::Holds; Link Here
39
use Koha::Database;
39
use Koha::Database;
40
use Koha::ItemTypes;
40
use Koha::ItemTypes;
41
use Koha::Patron::Attribute::Types;
41
use Koha::Patron::Attribute::Types;
42
use Koha::Patrons;
42
use Koha::Patron::Messages;
43
use Koha::Patron::Messages;
43
use Koha::Patron::Discharge;
44
use Koha::Patron::Discharge;
44
use Koha::Patrons;
45
use Koha::Patrons;
Lines 71-76 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
71
    }
72
    }
72
);
73
);
73
74
75
my $patron = Koha::Patrons->find( $borrowernumber );
76
74
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
77
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
75
78
76
my $show_priority;
79
my $show_priority;
Lines 333-346 my $patron_messages = Koha::Patron::Messages->search( Link Here
333
if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
336
if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
334
    || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
337
    || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
335
{
338
{
336
    my @relatives =
339
    my @relatives;
337
      Koha::Database->new()->schema()->resultset("Borrower")->search(
340
    # Filter out guarantees that don't want guarantor to see checkouts
338
        {
341
    foreach my $gr ( $patron->guarantee_relationships() ) {
339
            privacy_guarantor_checkouts => 1,
342
        my $g = $gr->guarantee;
340
            'me.guarantorid'           => $borrowernumber
343
        push( @relatives, $g ) if $g->privacy_guarantor_checkouts;
341
        },
344
    }
342
        { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] }
343
      );
344
    $template->param( relatives => \@relatives );
345
    $template->param( relatives => \@relatives );
345
}
346
}
346
347
(-)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 51-62 my $patron = $builder->build_object( Link Here
51
        }
52
        }
52
    }
53
    }
53
);
54
);
54
my $guarantee = $builder->build(
55
56
my $guarantee = $builder->build_object(
55
    {
57
    {
56
        source => 'Borrower',
58
        class => 'Koha::Patrons',
57
        value  => {
59
        value => {
58
            guarantorid => $patron->borrowernumber,
59
            patron_category => $patron_category->{categorycode},
60
            patron_category => $patron_category->{categorycode},
61
            guarantorid => $patron->borrowernumber,
62
        }
63
    }
64
);
65
66
my $r = $builder->build_object(
67
    {
68
        class => 'Koha::Patron::Relationships',
69
        value => {
70
            guarantor_id => $patron->id,
71
            guarantee_id => $guarantee->id,
72
            relationship => 'parent',
60
        }
73
        }
61
    }
74
    }
62
);
75
);
Lines 67-77 t::lib::Mocks::mock_preference( 'AllowFineOverride', '' ); Link Here
67
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
80
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
68
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
81
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
69
82
70
manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
83
manualinvoice( $guarantee->id, undef, undef, 'L', 10.00 );
71
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
84
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
72
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
85
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
73
86
74
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
87
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
75
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
88
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
76
is( $accountline->accounttype, "L", "Account type is L" );
89
is( $accountline->accounttype, "L", "Account type is L" );
77
90
(-)a/t/db_dependent/Items.t (-1 / +5 lines)
Lines 470-476 subtest 'SearchItems test' => sub { Link Here
470
470
471
subtest 'Koha::Item(s) tests' => sub {
471
subtest 'Koha::Item(s) tests' => sub {
472
472
473
    plan tests => 5;
473
    plan tests => 7;
474
474
475
    $schema->storage->txn_begin();
475
    $schema->storage->txn_begin();
476
476
Lines 509-514 subtest 'Koha::Item(s) tests' => sub { Link Here
509
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
509
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
510
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
510
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
511
511
512
    my $biblio = $item->biblio();
513
    is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
514
    is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );
515
512
    $schema->storage->txn_rollback;
516
    $schema->storage->txn_rollback;
513
};
517
};
514
518
(-)a/t/db_dependent/Koha/Patrons.t (-15 / +21 lines)
Lines 33-38 use Koha::Holds; Link Here
33
use Koha::Patron;
33
use Koha::Patron;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
36
use Koha::Patron::Relationship;
36
use Koha::Database;
37
use Koha::Database;
37
use Koha::DateUtils;
38
use Koha::DateUtils;
38
use Koha::Virtualshelves;
39
use Koha::Virtualshelves;
Lines 82-104 subtest 'library' => sub { Link Here
82
83
83
subtest 'guarantees' => sub {
84
subtest 'guarantees' => sub {
84
    plan tests => 8;
85
    plan tests => 8;
85
    my $guarantees = $new_patron_1->guarantees;
86
    my $guarantees = $new_patron_1->guarantee_relationships;
86
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
87
    is( ref($guarantees), 'Koha::Patron::Relationships', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
87
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee' );
88
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee relationships' );
88
    my @guarantees = $new_patron_1->guarantees;
89
    my @guarantees = $new_patron_1->guarantee_relationships;
89
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
90
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantee_relationships should return an array in a list context' );
90
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
91
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
91
92
92
    my $guarantee_1 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
93
    my $guarantee_1 = $builder->build({ source => 'Borrower' });
93
    my $guarantee_2 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
94
    my $relationship_1 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->id, guarantee_id => $guarantee_1->{borrowernumber} } )->store();
95
    my $guarantee_2 = $builder->build({ source => 'Borrower' });
96
    my $relationship_2 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->id, guarantee_id => $guarantee_2->{borrowernumber} } )->store();
94
97
95
    $guarantees = $new_patron_1->guarantees;
98
    $guarantees = $new_patron_1->guarantee_relationships;
96
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
99
    is( ref($guarantees), 'Koha::Patron::Relationships', 'Koha::Patron->guarantee_relationships should return a Koha::Patrons result set in a scalar context' );
97
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
100
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
98
    @guarantees = $new_patron_1->guarantees;
101
    @guarantees = $new_patron_1->guarantee_relationships;
99
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
102
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantee_relationships should return an array in a list context' );
100
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
103
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
101
    $_->delete for @guarantees;
104
    map { $_->guarantee->delete } @guarantees;
102
};
105
};
103
106
104
subtest 'category' => sub {
107
subtest 'category' => sub {
Lines 112-126 subtest 'siblings' => sub { Link Here
112
    plan tests => 7;
115
    plan tests => 7;
113
    my $siblings = $new_patron_1->siblings;
116
    my $siblings = $new_patron_1->siblings;
114
    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
117
    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
115
    my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
118
    my $guarantee_1 = $builder->build( { source => 'Borrower' } );
119
    my $relationship_1 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_1->{borrowernumber} } )->store();
116
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
120
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
117
    $siblings = $retrieved_guarantee_1->siblings;
121
    $siblings = $retrieved_guarantee_1->siblings;
118
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
122
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
119
    my @siblings = $retrieved_guarantee_1->siblings;
123
    my @siblings = $retrieved_guarantee_1->siblings;
120
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
124
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
121
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
125
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
122
    my $guarantee_2 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
126
    my $guarantee_2 = $builder->build( { source => 'Borrower' } );
123
    my $guarantee_3 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
127
    my $relationship_2 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_2->{borrowernumber} } )->store();
128
    my $guarantee_3 = $builder->build( { source => 'Borrower' } );
129
    my $relationship_3 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_3->{borrowernumber} } )->store();
124
    $siblings = $retrieved_guarantee_1->siblings;
130
    $siblings = $retrieved_guarantee_1->siblings;
125
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
131
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
126
    is( $guarantee_2->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_2 should exist in the guarantees' );
132
    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 248-254 my $borrower1 = $builder->build({ Link Here
248
            categorycode=>'STAFFER',
246
            categorycode=>'STAFFER',
249
            branchcode => $library3->{branchcode},
247
            branchcode => $library3->{branchcode},
250
            dateexpiry => '2015-01-01',
248
            dateexpiry => '2015-01-01',
251
            guarantorid=> undef,
252
        },
249
        },
253
});
250
});
254
my $bor1inlist = $borrower1->{borrowernumber};
251
my $bor1inlist = $borrower1->{borrowernumber};
Lines 258-264 my $borrower2 = $builder->build({ Link Here
258
            categorycode=>'STAFFER',
255
            categorycode=>'STAFFER',
259
            branchcode => $library3->{branchcode},
256
            branchcode => $library3->{branchcode},
260
            dateexpiry => '2015-01-01',
257
            dateexpiry => '2015-01-01',
261
            guarantorid=> undef,
262
        },
258
        },
263
});
259
});
264
260
Lines 268-274 my $guarantee = $builder->build({ Link Here
268
            categorycode=>'KIDclamp',
264
            categorycode=>'KIDclamp',
269
            branchcode => $library3->{branchcode},
265
            branchcode => $library3->{branchcode},
270
            dateexpiry => '2015-01-01',
266
            dateexpiry => '2015-01-01',
271
            guarantorid=> undef, # will be filled later
272
        },
267
        },
273
});
268
});
274
269
Lines 303-309 $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_ Link Here
303
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
298
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
304
299
305
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
300
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
306
ModMember( borrowernumber => $guarantee->{borrowernumber} ,guarantorid=>$bor1inlist );
301
my $relationship = Koha::Patron::Relationship->new( { guarantor_id => $bor1inlist, guarantee_id => $guarantee->{borrowernumber} } )->store();
307
302
308
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
303
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
309
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
304
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
Lines 313-319 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list Link Here
313
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
308
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
314
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
309
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
315
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
310
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
316
ModMember( borrowernumber => $guarantee->{borrowernumber}, guarantorid=>'' );
311
312
$relationship->delete();
317
313
318
$builder->build({
314
$builder->build({
319
        source => 'Issue',
315
        source => 'Issue',
Lines 341-349 is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date') Link Here
341
337
342
# Test GetBorrowersToExpunge and TrackLastPatronActivity
338
# Test GetBorrowersToExpunge and TrackLastPatronActivity
343
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
339
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
344
$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN', guarantorid => undef } } );
340
$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN' } } );
345
$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN', guarantorid => undef } } );
341
$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN' } } );
346
$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN', guarantorid => undef } } );
342
$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN' } } );
347
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
343
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
348
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
344
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
349
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' });
345
$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 / +24 lines)
Lines 69-74 my @columnkeys = Koha::Patrons->columns(); Link Here
69
if ($extended) {
69
if ($extended) {
70
    push @columnkeys, 'patron_attributes';
70
    push @columnkeys, 'patron_attributes';
71
}
71
}
72
push( @columnkeys, qw( relationship guarantor_id  guarantor_firstname guarantor_surname ) );
72
73
73
my $input = CGI->new();
74
my $input = CGI->new();
74
our $csv  = Text::CSV->new({binary => 1});  # binary needed for non-ASCII Unicode
75
our $csv  = Text::CSV->new({binary => 1});  # binary needed for non-ASCII Unicode
Lines 268-273 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
268
            next;
269
            next;
269
        }
270
        }
270
271
272
        my $relationship        = $borrower{relationship};
273
        my $guarantor_id        = $borrower{guarantor_id};
274
        my $guarantor_firstname = $borrower{guarantor_firstname};
275
        my $guarantor_surname   = $borrower{guarantor_surname};
276
        delete $borrower{relationship};
277
        delete $borrower{guarantor_id};
278
        delete $borrower{guarantor_firstname};
279
        delete $borrower{guarantor_surname};
280
271
        if ($borrowernumber) {
281
        if ($borrowernumber) {
272
            # borrower exists
282
            # borrower exists
273
            unless ($overwrite_cardnumber) {
283
            unless ($overwrite_cardnumber) {
Lines 372-377 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
372
                $template->param('lastinvalid'=>$borrower{'surname'}.' / AddMember');
382
                $template->param('lastinvalid'=>$borrower{'surname'}.' / AddMember');
373
            }
383
            }
374
        }
384
        }
385
386
        # Add a guarantor if we are given a relationship
387
        if ( $relationship ) {
388
            $guarantor_id ||= undef;
389
            Koha::Patron::Relationship->new(
390
                {
391
                    guarantee_id => $borrowernumber,
392
                    relationship => $relationship,
393
                    guarantor_id => $guarantor_id,
394
                    firstname    => $guarantor_firstname,
395
                    surname      => $guarantor_surname,
396
                }
397
            )->store();
398
        }
375
    }
399
    }
376
400
377
    if ( $imported && $createpatronlist ) {
401
    if ( $imported && $createpatronlist ) {
378
- 

Return to bug 14570