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 757-763 sub CanBookBeIssued { Link Here
757
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
757
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
758
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
758
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
759
    if ( defined $no_issues_charge_guarantees ) {
759
    if ( defined $no_issues_charge_guarantees ) {
760
        my @guarantees = $patron->guarantees();
760
        my @guarantees = map { $_->guarantee } $patron->guarantee_relationships();
761
        my $guarantees_non_issues_charges;
761
        my $guarantees_non_issues_charges;
762
        foreach my $g ( @guarantees ) {
762
        foreach my $g ( @guarantees ) {
763
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
763
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
(-)a/C4/Members.pm (-9 / +7 lines)
Lines 203-209 sub patronflags { Link Here
203
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
203
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
204
    if ( defined $no_issues_charge_guarantees ) {
204
    if ( defined $no_issues_charge_guarantees ) {
205
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
205
        my $p = Koha::Patrons->find( $patroninformation->{borrowernumber} );
206
        my @guarantees = $p->guarantees();
206
        my @guarantees = map { $_->guarantee } $p->guarantee_relationships;
207
        my $guarantees_non_issues_charges;
207
        my $guarantees_non_issues_charges;
208
        foreach my $g ( @guarantees ) {
208
        foreach my $g ( @guarantees ) {
209
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
209
            $guarantees_non_issues_charges += $g->account->non_issues_charges;
Lines 322-328 sub ModMember { Link Here
322
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
322
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
323
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
323
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
324
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
324
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
325
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
326
325
327
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
326
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
328
327
Lines 454-460 sub AddMember { Link Here
454
    $data{'dateofbirth'}     = undef if ( not $data{'dateofbirth'} );
453
    $data{'dateofbirth'}     = undef if ( not $data{'dateofbirth'} );
455
    $data{'debarred'}        = undef if ( not $data{'debarred'} );
454
    $data{'debarred'}        = undef if ( not $data{'debarred'} );
456
    $data{'sms_provider_id'} = undef if ( not $data{'sms_provider_id'} );
455
    $data{'sms_provider_id'} = undef if ( not $data{'sms_provider_id'} );
457
    $data{'guarantorid'}     = undef if ( not $data{'guarantorid'} );
458
456
459
    # get only the columns of Borrower
457
    # get only the columns of Borrower
460
    # FIXME Do we really need this check?
458
    # FIXME Do we really need this check?
Lines 810-827 sub GetBorrowersToExpunge { Link Here
810
            FROM   borrowers
808
            FROM   borrowers
811
            JOIN   categories USING (categorycode)
809
            JOIN   categories USING (categorycode)
812
            LEFT JOIN (
810
            LEFT JOIN (
813
                SELECT guarantorid
811
                SELECT guarantor_id
814
                FROM borrowers
812
                FROM relationships
815
                WHERE guarantorid IS NOT NULL
813
                WHERE guarantor_id IS NOT NULL
816
                    AND guarantorid <> 0
814
                    AND guarantor_id <> 0
817
            ) as tmp ON borrowers.borrowernumber=tmp.guarantorid
815
            ) as tmp ON borrowers.borrowernumber=tmp.guarantor_id
818
            LEFT JOIN old_issues USING (borrowernumber)
816
            LEFT JOIN old_issues USING (borrowernumber)
819
            LEFT JOIN issues USING (borrowernumber)|;
817
            LEFT JOIN issues USING (borrowernumber)|;
820
    if ( $filterpatronlist  ){
818
    if ( $filterpatronlist  ){
821
        $query .= q| LEFT JOIN patron_list_patrons USING (borrowernumber)|;
819
        $query .= q| LEFT JOIN patron_list_patrons USING (borrowernumber)|;
822
    }
820
    }
823
    $query .= q| WHERE  category_type <> 'S'
821
    $query .= q| WHERE  category_type <> 'S'
824
        AND tmp.guarantorid IS NULL
822
        AND tmp.guarantor_id IS NULL
825
    |;
823
    |;
826
    my @query_params;
824
    my @query_params;
827
    if ( $filterbranch && $filterbranch ne "" ) {
825
    if ( $filterbranch && $filterbranch ne "" ) {
(-)a/C4/SIP/ILS/Patron.pm (-1 lines)
Lines 601-607 __END__ Link Here
601
| contactname         | mediumtext   | YES  |     | NULL    |                |
601
| contactname         | mediumtext   | YES  |     | NULL    |                |
602
| contactfirstname    | text         | YES  |     | NULL    |                |
602
| contactfirstname    | text         | YES  |     | NULL    |                |
603
| contacttitle        | text         | YES  |     | NULL    |                |
603
| contacttitle        | text         | YES  |     | NULL    |                |
604
| guarantorid         | int(11)      | YES  | MUL | NULL    |                |
605
| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
604
| borrowernotes       | mediumtext   | YES  |     | NULL    |                |
606
| relationship        | varchar(100) | YES  |     | NULL    |                |
605
| relationship        | varchar(100) | YES  |     | NULL    |                |
607
| ethnicity           | varchar(50)  | YES  |     | NULL    |                |
606
| 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 26-40 use List::MoreUtils qw( uniq ); Link Here
26
use C4::Context;
26
use C4::Context;
27
use C4::Log;
27
use C4::Log;
28
use Koha::Checkouts;
28
use Koha::Checkouts;
29
use Koha::Old::Checkouts;
29
use Koha::Database;
30
use Koha::Database;
30
use Koha::DateUtils;
31
use Koha::DateUtils;
31
use Koha::Holds;
32
use Koha::Holds;
32
use Koha::Old::Checkouts;
33
use Koha::Patrons;
33
use Koha::Patron::Categories;
34
use Koha::Patron::Categories;
35
use Koha::Patron::Relationships;
34
use Koha::Patron::HouseboundProfile;
36
use Koha::Patron::HouseboundProfile;
35
use Koha::Patron::HouseboundRole;
37
use Koha::Patron::HouseboundRole;
36
use Koha::Patron::Images;
38
use Koha::Patron::Images;
37
use Koha::Patrons;
38
use Koha::Virtualshelves;
39
use Koha::Virtualshelves;
39
use Koha::Club::Enrollments;
40
use Koha::Club::Enrollments;
40
use Koha::Account;
41
use Koha::Account;
Lines 109-149 sub category { Link Here
109
    return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode );
110
    return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode );
110
}
111
}
111
112
112
=head3 guarantor
113
=head3 image
113
114
Returns a Koha::Patron object for this patron's guarantor
115
114
116
=cut
115
=cut
117
116
118
sub guarantor {
119
    my ( $self ) = @_;
120
121
    return unless $self->guarantorid();
122
123
    return Koha::Patrons->find( $self->guarantorid() );
124
}
125
126
sub image {
117
sub image {
127
    my ( $self ) = @_;
118
    my ( $self ) = @_;
128
119
129
    return scalar Koha::Patron::Images->find( $self->borrowernumber );
120
    return scalar Koha::Patron::Images->find( $self->borrowernumber );
130
}
121
}
131
122
123
=head3 library
124
125
=cut
126
132
sub library {
127
sub library {
133
    my ( $self ) = @_;
128
    my ( $self ) = @_;
134
    return Koha::Library->_new_from_dbic($self->_result->branchcode);
129
    return Koha::Library->_new_from_dbic($self->_result->branchcode);
135
}
130
}
136
131
137
=head3 guarantees
132
=head3 guarantor_relationships
133
134
Returns Koha::Patron::Relationships object for this patron's guarantors
138
135
139
Returns the guarantees (list of Koha::Patron) of this patron
136
Returns the set of relationships for the patrons that are guarantors for this patron.
137
138
This is returned instead of a Koha::Patron object because the guarantor
139
may not exist as a patron in Koha. If this is true, the guarantors name
140
exists in the Koha::Patron::Relationship object and will have no guarantor_id.
140
141
141
=cut
142
=cut
142
143
143
sub guarantees {
144
sub guarantor_relationships {
144
    my ( $self ) = @_;
145
    my ($self) = @_;
146
147
    return Koha::Patron::Relationships->search( { guarantee_id => $self->id } );
148
}
149
150
=head3 guarantee_relationships
151
152
Returns Koha::Patron::Relationships object for this patron's guarantors
153
154
Returns the set of relationships for the patrons that are guarantees for this patron.
155
156
The method returns Koha::Patron::Relationship objects for the sake
157
of consistency with the guantors method.
158
A guarantee by definition must exist as a patron in Koha.
159
160
=cut
161
162
sub guarantee_relationships {
163
    my ($self) = @_;
145
164
146
    return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
165
    return Koha::Patron::Relationships->search( { guarantor_id => $self->id } );
147
}
166
}
148
167
149
=head3 housebound_profile
168
=head3 housebound_profile
Lines 181-203 Returns the siblings of this patron. Link Here
181
=cut
200
=cut
182
201
183
sub siblings {
202
sub siblings {
184
    my ( $self ) = @_;
203
    my ($self) = @_;
185
204
186
    my $guarantor = $self->guarantor;
205
    my @guarantors = $self->guarantor_relationships()->guarantors();
187
206
188
    return unless $guarantor;
207
    return unless @guarantors;
189
208
190
    return Koha::Patrons->search(
209
    my @siblings =
191
        {
210
      map { $_->guarantee_relationships()->guarantees() } @guarantors;
192
            guarantorid => {
211
193
                '!=' => undef,
212
    return unless @siblings;
194
                '=' => $guarantor->id,
213
195
            },
214
    my %seen;
196
            borrowernumber => {
215
    @siblings =
197
                '!=' => $self->borrowernumber,
216
      grep { !$seen{ $_->id }++ && ( $_->id != $self->id ) } @siblings;
198
            }
217
199
        }
218
    return wantarray ? @siblings : Koha::Patrons->search( { borrowernumber => { -in => [ map { $_->id } @siblings ] } } );
200
    );
201
}
219
}
202
220
203
=head3 wants_check_for_previous_checkout
221
=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 124-141 sub search_upcoming_membership_expires { Link Here
124
    );
124
    );
125
}
125
}
126
126
127
=head3 guarantor
128
129
Returns a Koha::Patron object for this borrower's guarantor
130
131
=cut
132
133
sub guarantor {
134
    my ( $self ) = @_;
135
136
    return Koha::Patrons->find( $self->guarantorid() );
137
}
138
139
=head3 search_patrons_to_anonymise
127
=head3 search_patrons_to_anonymise
140
128
141
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
129
    my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } );
(-)a/Koha/Patrons/Import.pm (+23 lines)
Lines 209-214 sub import_patrons { Link Here
209
             next LINE;
209
             next LINE;
210
        }
210
        }
211
211
212
        my $relationship        = $borrower{relationship};
213
        my $guarantor_id        = $borrower{guarantor_id};
214
        my $guarantor_firstname = $borrower{guarantor_firstname};
215
        my $guarantor_surname   = $borrower{guarantor_surname};
216
        delete $borrower{relationship};
217
        delete $borrower{guarantor_id};
218
        delete $borrower{guarantor_firstname};
219
        delete $borrower{guarantor_surname};
220
212
        if ($borrowernumber) {
221
        if ($borrowernumber) {
213
222
214
            # borrower exists
223
            # borrower exists
Lines 344-349 sub import_patrons { Link Here
344
                );
353
                );
345
            }
354
            }
346
        }
355
        }
356
357
        # Add a guarantor if we are given a relationship
358
        if ( $relationship ) {
359
            $guarantor_id ||= undef;
360
            Koha::Patron::Relationship->new(
361
                {
362
                    guarantee_id => $borrowernumber,
363
                    relationship => $relationship,
364
                    guarantor_id => $guarantor_id,
365
                    firstname    => $guarantor_firstname,
366
                    surname      => $guarantor_surname,
367
                }
368
            )->store();
369
        }
347
    }
370
    }
348
371
349
    return {
372
    return {
(-)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 @ 2018-02-16 17:54:53
1389
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
1390
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wM40W+toV8ca5LFwinkHxA
1390
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wM40W+toV8ca5LFwinkHxA
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 571-584 my $view = $batch Link Here
571
    : 'circview';
571
    : 'circview';
572
572
573
my @relatives;
573
my @relatives;
574
if ( $borrowernumber ) {
574
if ( $patron ) {
575
    if ( $patron ) {
575
    if ( my @guarantors = $patron->guarantor_relationships()->guarantors() ) {
576
        if ( my $guarantor = $patron->guarantor ) {
576
        push( @relatives, $_->id ) for @guarantors;
577
            push @relatives, $guarantor->borrowernumber;
577
        push( @relatives, $_->id ) for $patron->siblings();
578
            push @relatives, $_->borrowernumber for $patron->siblings;
578
    } else {
579
        } else {
579
        push( @relatives, $_->id ) for $patron->guarantee_relationships()->guarantees();
580
            push @relatives, $_->borrowernumber for $patron->guarantees;
581
        }
582
    }
580
    }
583
}
581
}
584
my $relatives_issues_count =
582
my $relatives_issues_count =
(-)a/installer/data/mysql/atomicupdate/bug_14570.sql (+17 lines)
Line 0 Link Here
1
CREATE TABLE `relationships` (
2
      id INT(11) NOT NULL AUTO_INCREMENT,
3
      guarantor_id INT(11) NULL DEFAULT NULL,
4
      guarantee_id INT(11) NOT NULL,
5
      relationship VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL,
6
      surname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
7
      firstname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
8
      PRIMARY KEY (id),
9
      CONSTRAINT r_guarantor FOREIGN KEY ( guarantor_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE,
10
      CONSTRAINT r_guarantee FOREIGN KEY ( guarantee_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
11
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
12
13
UPDATE borrowers LEFT JOIN borrowers guarantor ON ( borrowers.guarantorid = guarantor.borrowernumber ) SET borrowers.guarantorid = NULL WHERE guarantor.borrowernumber IS NULL;
14
15
INSERT INTO relationships ( guarantor_id, guarantee_id, relationship, surname, firstname ) SELECT guarantorid, borrowernumber, relationship, contactname, contactfirstname FROM borrowers WHERE guarantorid IS NOT NULL OR contactname != "";
16
17
ALTER TABLE borrowers DROP guarantorid, DROP relationship, DROP contactname, DROP contactfirstname, DROP contacttitle;
(-)a/installer/data/mysql/kohastructure.sql (-16 / +17 lines)
Lines 579-590 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower Link Here
579
  `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
579
  `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
580
  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD)
580
  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD)
581
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
581
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
582
  `contactname` LONGTEXT, -- used for children and profesionals to include surname or last name of guarantor or organization name
583
  `contactfirstname` MEDIUMTEXT, -- used for children to include first name of guarantor
584
  `contacttitle` MEDIUMTEXT, -- used for children to include title (Mr., Mrs., etc) of guarantor
585
  `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarantors or organizations
586
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
582
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
587
  `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
588
  `sex` varchar(1) default NULL, -- patron/borrower's gender
583
  `sex` varchar(1) default NULL, -- patron/borrower's gender
589
  `password` varchar(60) default NULL, -- patron/borrower's encrypted password
584
  `password` varchar(60) default NULL, -- patron/borrower's encrypted password
590
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
585
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
Lines 1606-1617 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1606
  `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
1601
  `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
1607
  `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)
1602
  `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)
1608
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1603
  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1609
  `contactname` LONGTEXT, -- used for children and profesionals to include surname or last name of guarantor or organization name
1610
  `contactfirstname` MEDIUMTEXT, -- used for children to include first name of guarantor
1611
  `contacttitle` MEDIUMTEXT, -- used for children to include title (Mr., Mrs., etc) of guarantor
1612
  `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarantors or organizations
1613
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
1604
  `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
1614
  `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
1615
  `sex` varchar(1) default NULL, -- patron/borrower's gender
1605
  `sex` varchar(1) default NULL, -- patron/borrower's gender
1616
  `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1606
  `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1617
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
1607
  `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
Lines 1644-1650 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1644
  KEY `categorycode` (`categorycode`),
1634
  KEY `categorycode` (`categorycode`),
1645
  KEY `branchcode` (`branchcode`),
1635
  KEY `branchcode` (`branchcode`),
1646
  UNIQUE KEY `userid` (`userid`),
1636
  UNIQUE KEY `userid` (`userid`),
1647
  KEY `guarantorid` (`guarantorid`),
1648
  KEY `surname_idx` (`surname` (191)),
1637
  KEY `surname_idx` (`surname` (191)),
1649
  KEY `firstname_idx` (`firstname` (191)),
1638
  KEY `firstname_idx` (`firstname` (191)),
1650
  KEY `othernames_idx` (`othernames` (191)),
1639
  KEY `othernames_idx` (`othernames` (191)),
Lines 3402-3413 CREATE TABLE IF NOT EXISTS `borrower_modifications` ( Link Here
3402
  `lost` tinyint(1) DEFAULT NULL,
3391
  `lost` tinyint(1) DEFAULT NULL,
3403
  `debarred` date DEFAULT NULL,
3392
  `debarred` date DEFAULT NULL,
3404
  `debarredcomment` varchar(255) DEFAULT NULL,
3393
  `debarredcomment` varchar(255) DEFAULT NULL,
3405
  `contactname` LONGTEXT,
3406
  `contactfirstname` MEDIUMTEXT,
3407
  `contacttitle` MEDIUMTEXT,
3408
  `guarantorid` int(11) DEFAULT NULL,
3409
  `borrowernotes` LONGTEXT,
3394
  `borrowernotes` LONGTEXT,
3410
  `relationship` varchar(100) DEFAULT NULL,
3411
  `sex` varchar(1) DEFAULT NULL,
3395
  `sex` varchar(1) DEFAULT NULL,
3412
  `password` varchar(30) DEFAULT NULL,
3396
  `password` varchar(30) DEFAULT NULL,
3413
  `flags` int(11) DEFAULT NULL,
3397
  `flags` int(11) DEFAULT NULL,
Lines 4086-4091 CREATE TABLE IF NOT EXISTS club_fields ( Link Here
4086
  CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE
4070
  CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE
4087
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4071
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4088
4072
4073
--
4074
-- Table structure for table 'guarantors_guarantees'
4075
--
4076
4077
DROP TABLE IF EXISTS relationships;
4078
CREATE TABLE `relationships` (
4079
      id INT(11) NOT NULL AUTO_INCREMENT,
4080
      guarantor_id INT(11) NULL DEFAULT NULL,
4081
      guarantee_id INT(11) NOT NULL,
4082
      relationship VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL,
4083
      surname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
4084
      firstname MEDIUMTEXT COLLATE utf8_unicode_ci NULL DEFAULT NULL,
4085
      PRIMARY KEY (id),
4086
      CONSTRAINT r_guarantor FOREIGN KEY ( guarantor_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE,
4087
      CONSTRAINT r_guarantee FOREIGN KEY ( guarantee_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
4088
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4089
4089
--
4090
--
4090
-- Table structure for table `illrequests`
4091
-- Table structure for table `illrequests`
4091
--
4092
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/columns.def (-1 lines)
Lines 7-13 Link Here
7
<field name="borrowers.othernames">Other name</field>
7
<field name="borrowers.othernames">Other name</field>
8
<field name="borrowers.sex">Gender</field>
8
<field name="borrowers.sex">Gender</field>
9
<field name="borrowers.relationship">Relationship</field>
9
<field name="borrowers.relationship">Relationship</field>
10
<field name="borrowers.guarantorid">Guarantor borrower number</field>
11
<field name="borrowers.streetnumber">Street number</field>
10
<field name="borrowers.streetnumber">Street number</field>
12
<field name="borrowers.streettype">Street type</field>
11
<field name="borrowers.streettype">Street type</field>
13
<field name="borrowers.address">Address</field>
12
<field name="borrowers.address">Address</field>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc (-9 / +5 lines)
Lines 6-26 Link Here
6
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
6
[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
7
<div id="toolbar" class="btn-toolbar">
7
<div id="toolbar" class="btn-toolbar">
8
    [% IF CAN_user_borrowers_edit_borrowers %]
8
    [% IF CAN_user_borrowers_edit_borrowers %]
9
        [% IF ( guarantor ) %]
9
        <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]">
10
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% patron.borrowernumber %]&amp;guarantorid=[% guarantor.borrowernumber %]&amp;categorycode=[% patron.categorycode %]">
10
            <i class="fa fa-pencil"></i> Edit
11
        [% ELSE %]
11
        </a>
12
            <a id="editpatron" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]">
13
        [% END %]
14
        <i class="fa fa-pencil"></i> Edit</a>
15
    [% END %]
12
    [% END %]
16
13
17
    [% IF CAN_user_borrowers_edit_borrowers %]
14
    [% IF CAN_user_borrowers_edit_borrowers %]
18
        [% IF patron.is_adult AND Koha.Preference("borrowerRelationship") %]
15
        [% IF patron.is_adult AND Koha.Preference("borrowerRelationship") %]
19
            <a id="addchild" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;guarantorid=[% patron.borrowernumber %]"><i class="fa fa-plus"></i> Add child</a>
16
            <a id="addchild" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;guarantorid=[% patron.borrowernumber %]"><i class="fa fa-plus"></i> Add child</a>
20
        [% END %]
17
        [% END %]
21
        [% IF CAN_user_borrowers_edit_borrowers %]
18
22
            <a id="changepassword" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/member-password.pl?member=[% patron.borrowernumber %]"><i class="fa fa-lock"></i> Change password</a>
19
        <a id="changepassword" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/member-password.pl?member=[% patron.borrowernumber %]"><i class="fa fa-lock"></i> Change password</a>
23
        [% END %]
24
        <a id="duplicate" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=duplicate&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]"><i class="fa fa-copy"></i> Duplicate</a>
20
        <a id="duplicate" class="btn btn-default btn-sm" href="/cgi-bin/koha/members/memberentry.pl?op=duplicate&amp;borrowernumber=[% patron.borrowernumber %]&amp;categorycode=[% patron.categorycode %]"><i class="fa fa-copy"></i> Duplicate</a>
25
    [% END %]
21
    [% END %]
26
22
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +1 lines)
Lines 806-812 No patron matched <span class="ex">[% message | html %]</span> Link Here
806
    </li>
806
    </li>
807
807
808
    [% IF relatives_issues_count %]
808
    [% IF relatives_issues_count %]
809
        <li><a id="relatives-issues-tab" href="#relatives-issues">Relatives' checkouts</a></li>
809
        <li><a id="relatives-issues-tab" href="#relatives-issues">[% relatives_issues_count %] Relatives' checkouts</a></li>
810
    [% END %]
810
    [% END %]
811
811
812
    <li>
812
    <li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-103 / +169 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 288-400 Link Here
288
	</fieldset>
289
	</fieldset>
289
[% END # hide fieldset %]
290
[% END # hide fieldset %]
290
291
291
[% IF ( showguarantor ) %]
292
[% IF show_guarantor || guarantor %]
292
    <input type="hidden" id="guarantorid" name="guarantorid"   value="[% guarantorid %]" />
293
    [% SET possible_relationships = Koha.Preference('borrowerRelationship') %]
293
    [% UNLESS step_6 %]
294
    <fieldset class="rows">
294
        <input type="hidden" name="branchcode" value="[% branchcode %]" />
295
        <legend>Guarantor information</legend>
295
    [% END %]
296
296
    <fieldset id="memberentry_guarantor" class="rows">
297
        <span id="guarantor_relationships">
297
        <legend id="guarantor_lgd">Guarantor information</legend>
298
            [% FOREACH r IN relationships %]
298
        <ol>
299
                <fieldset class="rows">
299
[% IF ( P ) %]
300
                    <ol>
300
	        [% IF ( guarantorid ) %]
301
                        [% IF category_type == 'P' %]
301
	        <li id="contact-details">
302
                            [% IF ( r.guarantor_id ) %]
302
	        [% ELSE %]
303
                                <li id="contact-details">
303
	        <li id="contact-details" style="display: none">
304
                            [% ELSE %]
304
	        [% END %]
305
                                <li id="contact-details" style="display: none">
305
	            <span class="label">Organization #:</span> [% IF ( guarantorid ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorid %]" target="blank">[% guarantorid %]</a>[% END %]
306
                            [% END %]
306
	        </li>
307
                                <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 %]
307
	        <li>
308
                            </li>
308
	            <label for="contactname">Organization name: </label>
309
309
	            [% IF ( guarantorid ) %]
310
                            <li>
310
	            <span>[% contactname %]</span>
311
                                <label for="guarantor_surname">Organization name: </label>
311
	            <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname | html %]" />
312
                                [% IF ( r.guarantor_id ) %]
312
	            [% ELSE %]
313
                                    <span>[% r.guarantor.surname %]</span>
313
                    <input name="contactname" id="contactname" type="text" size="20" value="[% contactname | html %]" />
314
                                [% END %]
314
	            [% END %]
315
                            </li>
315
	        </li>
316
                        [% ELSE %]
316
[% ELSE %]
317
                            [% IF ( r.guarantor_id ) %]
317
 [% IF ( C ) %]
318
                                <li id="contact-details">
318
 [% IF ( guarantorid ) %]
319
                            [% ELSE %]
319
 <li id="contact-details">
320
                                <li id="contact-details" style="display: none">
320
 [% ELSE %]
321
                            [% END %]
321
 <li id="contact-details" style="display: none">
322
322
 [% END %]
323
                                <span class="label">Patron #:</span>
323
     <span class="label">Patron #:</span>
324
                                [% IF ( r.guarantor_id ) %]
324
     [% IF guarantorid %]
325
                                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% r.guarantor_id %]" target="blank">[% r.guarantor_id %]</a>
325
        [% IF logged_in_user.can_see_patron_infos( guarantor ) %]
326
                                [% END %]
326
            <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantorid %]" target="blank">[% guarantorid | html %]</a>
327
327
        [% ELSE %]
328
                            </li>
328
            [% guarantorid | html %]
329
329
        [% END %]
330
                            [% IF r.surname || r.guarantor.surname %]
330
    [% END %]
331
                                <li>
331
 </li>
332
                                    <label for="guarantor_surname">Surname: </label>
332
        [% UNLESS nocontactname %]
333
                                    <span>[% r.surname || r.guarantor.surname %]</span>
333
 <li>
334
                                </li>
334
     <label for="contactname">Surname: </label>
335
                            [% END %]
335
     [% IF ( guarantorid ) %]
336
336
     <span>[% contactname %]</span>
337
                            [% IF r.firstname || r.guarantor.firstname  %]
337
     <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname | html %]" />
338
                                <li>
338
     [% ELSE %]
339
                                    <label for="guarantor_firstname">First name: </label>
339
        <input name="contactname" id="contactname" type="text" size="20" value="[% contactname | html %]" />
340
                                    <span>[% r.firstname || r.guarantor.firstname %]</span>
340
     [% END %]
341
                                </li>
341
 </li>
342
                            [% END %]
342
        [% END %]
343
343
        [% UNLESS nocontactfirstname %]
344
                            <li>
344
 <li>
345
                                <label for="relationship">Relationship: </label>
345
     <label for="contactfirstname">First name: </label>
346
                                <span>[% r.relationship %]</span>
346
     [% IF ( guarantorid ) %]
347
                            </li>
347
     <span>[% contactfirstname %]</span>
348
348
     <input name="contactfirstname" id="contactfirstname" type="hidden" size="20" value="[% contactfirstname | html %]" />
349
                            <li>
349
     [% ELSE %]
350
                                <label for="delete_guarantor">Delete: </label>
350
        <input name="contactfirstname" id="contactfirstname" type="text" size="20" value="[% contactfirstname | html %]" />
351
                                <input type="checkbox" name="delete_guarantor" value="[% r.id %]" />
351
     [% END %]
352
                            </li>
352
 </li>
353
                        [% END %]
353
        [% END %]
354
                    </ol>
354
 [% IF ( relshiploop ) %]
355
                </fieldset>
355
 <li>
356
            [% END # END relationships foreach %]
356
     <label for="relationship">Relationship: </label>
357
        </span>
357
     <select name="relationship" id="relationship" >
358
358
         [% FOREACH relshiploo IN relshiploop %]
359
        <fieldset class="rows guarantor" id="guarantor_template">
359
         [% IF ( relshiploo.selected ) %]
360
            <ol>
360
         <option value="[% relshiploo.relationship %]" selected="selected" >[% relshiploo.relationship %]</option>
361
                <li class="guarantor_id">
361
         [% ELSE %]
362
                    <span class="label">Patron #:</span>
362
         <option value="[% relshiploo.relationship %]">[% relshiploo.relationship %]</option>
363
                    <span class="new_guarantor_id_text"></span>
363
         [% END %]
364
                    <input type="hidden" class="new_guarantor_id" name="new_guarantor_id" value=""/>
364
         [% END %]
365
                </li>
365
     </select>
366
366
 </li>
367
                <li>
367
 [% END %]
368
                    <label for="guarantor_surname">Surname: </label>
368
 [% END %]
369
                    <span class="new_guarantor_surname_text"></span>
369
[% END %]
370
                    <input type="hidden" class="new_guarantor_surname" name="new_guarantor_surname" value=""/>
370
        <li>
371
                </li>
371
            <span class="label">&nbsp;</span>
372
372
            [% IF ( guarantorid ) %]
373
                <li>
373
            <input id="guarantorsearch" type="button" value="Change" onclick="Dopopguarantor('guarantor_search.pl');" />
374
                    <label for="guarantor_firstname">First name: </label>
374
            [% ELSE %]
375
                    <span class="new_guarantor_firstname_text"></span>
375
            <input id="guarantorsearch" type="button" value="Set to patron" onclick="Dopopguarantor('guarantor_search.pl');" />
376
                    <input type="hidden" class="new_guarantor_firstname" name="new_guarantor_firstname" value=""/>
376
            [% END %]
377
                </li>
377
            <input id="guarantordelete" type="button" value="Delete" />
378
378
        </li>
379
                <li>
379
    [% IF guarantorid && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
380
                    <label for="guarantor_relationship">Relationship: </label>
380
        <li>
381
                    <select class="new_guarantor_relationship" name="new_guarantor_relationship">
381
            <label for="privacy_guarantor_checkouts">Show checkouts to guarantor</label>
382
                        [% FOREACH pr IN possible_relationships.split('\|') %]
382
            <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
383
                            <option value="[% pr %]">[% pr %]</option>
383
                [% IF privacy_guarantor_checkouts %]
384
                        [% END %]
384
                    <option value="0">No</option>
385
                    </select>
385
                    <option value="1" selected>Yes</option>
386
                </li>
387
388
                <li>
389
                    <label for="guarantor_cancel">&nbsp;</label>
390
                    <span><a href="#" class="guarantor_cancel">Cancel</a></span>
391
                </li>
392
            </ol>
393
        </fieldset>
394
395
        <fieldset class="rows">
396
            <legend>Add new guarantor</legend>
397
            <ol>
398
                <input type="hidden" id="guarantor_id" value=""/>
399
400
                [% IF catetory_type == 'P' %]
401
                    <li>
402
                        <label for="guarantor_surname">Organization name: </label>
403
                        <input name="guarantor_surname" id="guarantor_surname" type="hidden" size="20"/>
404
                    </li>
386
                [% ELSE %]
405
                [% ELSE %]
387
                    <option value="0" selected>No</option>
406
                    <li>
388
                    <option value="1">Yes</option>
407
                        <label for="guarantor_surname">Surname: </label>
408
                        <input name="guarantor_surname" id="guarantor_surname" type="text" size="20" />
409
                    </li>
410
411
                    <li>
412
                        <label for="guarantor_firstname">First name: </label>
413
                        <input name="guarantor_firstname" id="guarantor_firstname" type="text" size="20" />
414
                    </li>
415
416
                    [% IF ( possible_relationships ) %]
417
                        <li>
418
                            <label for="relationship">Relationship: </label>
419
                            <select name="relationship" id="relationship" >
420
                                [% FOREACH pr IN possible_relationships.split('\|') %]
421
                                    <option value="[% pr %]">[% pr %]</option>
422
                                [% END %]
423
                            </select>
424
                        </li>
425
                    [% END %]
389
                [% END %]
426
                [% END %]
390
            </select>
391
            <div class="hint">Allow guarantor of this patron to view this patron's checkouts from the OPAC</div>
392
        </li>
393
    [% END %]
394
        </ol>
395
    </fieldset>
396
427
428
                <li>
429
                    <span class="label">&nbsp;</span>
430
                    <a href="#" id="guarantor_add" class="btn btn-sm"><i class="fa fa-plus"></i> Add guarantor</a>
431
                    <a href="#" id="guarantor_search" class="btn btn-sm"><i class="fa fa-search"></i> Set to patron</a>
432
                    <a href="#" id="guarantor_clear">Clear</a>
433
                </li>
434
435
                [% IF relationships && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
436
                    <li>
437
                        <label for="privacy_guarantor_checkouts">Show checkouts to guarantors</label>
438
                        <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
439
                            [% IF privacy_guarantor_checkouts %]
440
                                <option value="0">No</option>
441
                                <option value="1" selected>Yes</option>
442
                            [% ELSE %]
443
                                <option value="0" selected>No</option>
444
                                <option value="1">Yes</option>
445
                            [% END %]
446
                        </select>
447
                        <div class="hint">Allow guarantors of this patron to view this patron's checkouts from the OPAC</div>
448
                    </li>
449
                [% END %]
450
            </ol>
451
        </fieldset>
452
    </fieldset>
397
[% END %]
453
[% END %]
454
455
398
[% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
456
[% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
399
    [% IF Koha.Preference( 'AddressFormat' ) %]
457
    [% IF Koha.Preference( 'AddressFormat' ) %]
400
        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
458
        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
Lines 1183-1188 Link Here
1183
                    update_category_code( category_code );
1241
                    update_category_code( category_code );
1184
                }
1242
                }
1185
            [% END %]
1243
            [% END %]
1244
1245
            [% IF guarantor %]
1246
                select_user( '[% guarantor.borrowernumber %]', [% To.json( guarantor.unblessed ) %] );
1247
                $('#guarantor_add').ready(function() {
1248
                    $('#guarantor_add').click();
1249
                });
1250
            [% END %]
1251
1186
        });
1252
        });
1187
1253
1188
        function update_cardnumber_warning(size){
1254
        function update_cardnumber_warning(size){
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt (-2 / +21 lines)
Lines 47-54 Link Here
47
            <li><span class="label">Guarantees:</span><ul>[% FOREACH guaranteeloo IN guaranteeloop %]<li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guaranteeloo.borrowernumber %]">[% guaranteeloo.name %]  </a></li>[% END %]</ul></li>
47
            <li><span class="label">Guarantees:</span><ul>[% FOREACH guaranteeloo IN guaranteeloop %]<li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guaranteeloo.borrowernumber %]">[% guaranteeloo.name %]  </a></li>[% END %]</ul></li>
48
        [% END %]
48
        [% END %]
49
    [% ELSE %]
49
    [% ELSE %]
50
        [% IF ( guarantor.borrowernumber ) %]
50
        [% IF guarantees %]
51
            <li><span class="label">Guarantor:</span><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.surname %], [% guarantor.firstname %]</a></li>
51
            <li>
52
                <span class="label">Guarantees:</span>
53
                <ul>
54
                    [% FOREACH guarantee IN guarantees %]
55
                        <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantee.borrowernumber %]">[% guarantee.firstname %] [% guarantee.surname %]</a></li>
56
                    [% END %]
57
                </ul>
58
            </li>
59
        [% ELSIF guarantor_relationships %]
60
            [% FOREACH gr IN guarantor_relationships %]
61
                <li>
62
                    <span class="label">Guarantor:</span>
63
                    [% IF gr.guarantor_id %]
64
                        [% SET guarantor = gr.guarantor %]
65
                        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.id %]">[% guarantor.firstname %] [% guarantor.surname %]</a>
66
                    [% ELSE %]
67
                        [% gr.firstname %] [% gr.surname %]
68
                    [% END %]
69
                </li>
70
            [% END %]
52
        [% END %]
71
        [% END %]
53
    [% END %]
72
    [% END %]
54
	</ol>
73
	</ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-17 / +13 lines)
Lines 158-182 Link Here
158
                    [% END %]
158
                    [% END %]
159
                </ul>
159
                </ul>
160
            </li>
160
            </li>
161
        [% ELSIF guarantor %]
161
        [% ELSIF guarantor_relationships %]
162
            <li>
162
            [% FOREACH gr IN guarantor_relationships %]
163
                <span class="label">Guarantor:</span>
163
                <li>
164
                [% IF guarantor.borrowernumber AND logged_in_user.can_see_patron_infos( guarantor ) %]
164
                    <span class="label">Guarantor:</span>
165
                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.borrowernumber %]">[% guarantor.firstname | html %] [% guarantor.surname | html %]</a>
165
                    [% IF gr.guarantor_id %]
166
                [% ELSE %]
166
                        [% SET guarantor = gr.guarantor %]
167
                    [% guarantor.firstname | html %] [% guarantor.surname | html %]
167
                        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% guarantor.id %]">[% guarantor.firstname %] [% guarantor.surname %]</a>
168
                [% END %]
168
                    [% ELSE %]
169
            </li>
169
                        [% gr.firstname %] [% gr.surname %]
170
                    [% END %]
171
                </li>
172
            [% END %]
170
        [% END %]
173
        [% END %]
171
    </ol>
174
    </ol>
172
</div>
175
</div>
173
      <div class="action">
174
        [% IF ( guarantor.borrowernumber ) %]
175
        <a href="memberentry.pl?op=modify&amp;borrowernumber=[% patron.borrowernumber %]&amp;step=1&amp;guarantorid=[% guarantor.borrowernumber %]">Edit</a>
176
        [% ELSE %]
177
        <a href="memberentry.pl?op=modify&amp;borrowernumber=[% patron.borrowernumber %]&amp;step=1">Edit</a>
178
        [% END %]</div>
179
180
</div>
176
</div>
181
177
182
<!-- Begin Upload Patron Image Section -->
178
<!-- Begin Upload Patron Image Section -->
Lines 405-411 Link Here
405
    <ul>
401
    <ul>
406
        <li><a href="#checkouts">[% issuecount %] Checkout(s)</a></li>
402
        <li><a href="#checkouts">[% issuecount %] Checkout(s)</a></li>
407
        [% IF relatives_issues_count %]
403
        [% IF relatives_issues_count %]
408
            <li><a href="#relatives-issues" id="relatives-issues-tab">Relatives' checkouts</a></li>
404
            <li><a href="#relatives-issues" id="relatives-issues-tab">[% relatives_issues_count %] Relatives' checkouts</a></li>
409
        [% END %]
405
        [% END %]
410
        <li><a href="#finesandcharges">Fines &amp; Charges</a></li>
406
        <li><a href="#finesandcharges">Fines &amp; Charges</a></li>
411
        <li>
407
        <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 (-3 / +3 lines)
Lines 104-110 if (C4::Context->preference("IndependentBranches")) { Link Here
104
104
105
my $op = $input->param('op') || 'delete_confirm';
105
my $op = $input->param('op') || 'delete_confirm';
106
my $dbh = C4::Context->dbh;
106
my $dbh = C4::Context->dbh;
107
my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member);
107
my $is_guarantor = $patron->guarantee_relationships->count;
108
if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or $deletelocal == 0) {
108
if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or $deletelocal == 0) {
109
109
110
    $template->param(
110
    $template->param(
Lines 116-123 if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or Link Here
116
    if ( $charges > 0 ) {
116
    if ( $charges > 0 ) {
117
        $template->param(charges => $charges);
117
        $template->param(charges => $charges);
118
    }
118
    }
119
    if ($is_guarantor) {
119
    if ( $is_guarantor ) {
120
        $template->param(guarantees => 1);
120
        $template->param( guarantees => 1 );
121
    }
121
    }
122
    if ($deletelocal == 0) {
122
    if ($deletelocal == 0) {
123
        $template->param(keeplocal => 1);
123
        $template->param(keeplocal => 1);
(-)a/members/memberentry.pl (-51 / +77 lines)
Lines 83-89 if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) { Link Here
83
    $template->param( sms_providers => \@providers );
83
    $template->param( sms_providers => \@providers );
84
}
84
}
85
85
86
my $guarantorid    = $input->param('guarantorid');
87
my $actionType     = $input->param('actionType') || '';
86
my $actionType     = $input->param('actionType') || '';
88
my $modify         = $input->param('modify');
87
my $modify         = $input->param('modify');
89
my $delete         = $input->param('delete');
88
my $delete         = $input->param('delete');
Lines 99-111 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to rep Link Here
99
                                     # isn't a duplicate.  Marking FIXME because this
98
                                     # isn't a duplicate.  Marking FIXME because this
100
                                     # script needs to be refactored.
99
                                     # script needs to be refactored.
101
my $nok           = $input->param('nok');
100
my $nok           = $input->param('nok');
102
my $guarantorinfo = $input->param('guarantorinfo');
103
my $step          = $input->param('step') || 0;
101
my $step          = $input->param('step') || 0;
104
my @errors;
102
my @errors;
105
my $borrower_data;
103
my $borrower_data;
106
my $NoUpdateLogin;
104
my $NoUpdateLogin;
107
my $userenv = C4::Context->userenv;
105
my $userenv = C4::Context->userenv;
108
106
107
## Deal with guarantor stuff
108
$template->param( relationships => scalar $patron->guarantor_relationships ) if $patron;
109
110
my $guarantor_id = $input->param('guarantor_id');
111
my $guarantor = Koha::Patrons->find( $guarantor_id ) if $guarantor_id;
112
$template->param( guarantor => $guarantor );
113
114
my @delete_guarantor = $input->param('delete_guarantor');
115
foreach my $id ( @delete_guarantor ) {
116
    my $r = Koha::Patron::Relationships->find( $id );
117
    $r->delete() if $r;
118
}
119
109
## Deal with debarments
120
## Deal with debarments
110
$template->param(
121
$template->param(
111
    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) );
122
    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) );
Lines 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 247-272 if ( ( $op eq 'insert' ) and !$nodouble ) { Link Here
247
    }
258
    }
248
}
259
}
249
260
250
  #recover all data from guarantor address phone ,fax... 
251
if ( $guarantorid ) {
252
    if (my $guarantor = Koha::Patrons->find( $guarantorid )) {
253
        my $guarantordata = $guarantor->unblessed;
254
        $category_type = $guarantordata->{categorycode} eq 'I' ? 'P' : 'C';
255
        $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
256
        $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
257
        $newdata{'contactname'}     = $guarantordata->{'surname'};
258
        $newdata{'contacttitle'}    = $guarantordata->{'title'};
259
        if ( $op eq 'add' ) {
260
	        foreach (qw(streetnumber address streettype address2
261
                        zipcode country city state phone phonepro mobile fax email emailpro branchcode
262
                        B_streetnumber B_streettype B_address B_address2
263
                        B_city B_state B_zipcode B_country B_email B_phone)) {
264
		        $newdata{$_} = $guarantordata->{$_};
265
	        }
266
        }
267
    }
268
}
269
270
###############test to take the right zipcode, country and city name ##############
261
###############test to take the right zipcode, country and city name ##############
271
# set only if parameter was passed from the form
262
# set only if parameter was passed from the form
272
$newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
263
$newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
Lines 417-422 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
417
	if ($op eq 'insert'){
408
	if ($op eq 'insert'){
418
		# we know it's not a duplicate borrowernumber or there would already be an error
409
		# we know it's not a duplicate borrowernumber or there would already be an error
419
        $borrowernumber = &AddMember(%newdata);
410
        $borrowernumber = &AddMember(%newdata);
411
        add_guarantors( $borrowernumber, $input );
420
        $newdata{'borrowernumber'} = $borrowernumber;
412
        $newdata{'borrowernumber'} = $borrowernumber;
421
413
422
        # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
414
        # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
Lines 514-519 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
514
                                                                # updating any columns in the borrowers table,
506
                                                                # updating any columns in the borrowers table,
515
                                                                # which can happen if we're only editing the
507
                                                                # which can happen if we're only editing the
516
                                                                # patron attributes or messaging preferences sections
508
                                                                # patron attributes or messaging preferences sections
509
        add_guarantors( $borrowernumber, $input );
517
        if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
510
        if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
518
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
511
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
519
        }
512
        }
Lines 621-631 foreach my $category_type (qw(C A S P I X)) { Link Here
621
        'categoryloop'   => \@categoryloop
614
        'categoryloop'   => \@categoryloop
622
      };
615
      };
623
}
616
}
624
617
$template->param(
625
$template->param('typeloop' => \@typeloop,
618
    typeloop      => \@typeloop,
626
        no_categories => $no_categories);
619
    no_categories => $no_categories,
627
if($no_categories){ $no_add = 1; }
620
);
628
629
621
630
my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
622
my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
631
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
623
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
Lines 650-673 while (@relationships) { Link Here
650
  push(@relshipdata, \%row);
642
  push(@relshipdata, \%row);
651
}
643
}
652
644
653
my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
645
my %flags = (
654
        'lost'          => ['lost']);
646
    'gonenoaddress' => ['gonenoaddress'],
647
    'lost'          => ['lost']
648
);
655
649
656
 
657
my @flagdata;
650
my @flagdata;
658
foreach (keys(%flags)) {
651
foreach ( keys(%flags) ) {
659
	my $key = $_;
652
    my $key = $_;
660
	my %row =  ('key'   => $key,
653
    my %row = (
661
		    'name'  => $flags{$key}[0]);
654
        'key'  => $key,
662
	if ($data{$key}) {
655
        'name' => $flags{$key}[0]
663
		$row{'yes'}=' checked';
656
    );
664
		$row{'no'}='';
657
    if ( $data{$key} ) {
665
    }
658
        $row{'yes'} = ' checked';
666
	else {
659
        $row{'no'}  = '';
667
		$row{'yes'}='';
660
    }
668
		$row{'no'}=' checked';
661
    else {
669
	}
662
        $row{'yes'} = '';
670
	push @flagdata,\%row;
663
        $row{'no'}  = ' checked';
664
    }
665
    push @flagdata, \%row;
671
}
666
}
672
667
673
# get Branch Loop
668
# get Branch Loop
Lines 743-749 if (C4::Context->preference('EnhancedMessagingPreferences')) { Link Here
743
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
738
    $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
744
}
739
}
745
740
746
$template->param( "showguarantor"  => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
741
$template->param( "show_guarantor" => ( $category_type =~ /A|I|S|X/ ) ? 1 : 0 ); # associate with step to know where you are
747
$debug and warn "memberentry step: $step";
742
$debug and warn "memberentry step: $step";
748
$template->param(%data);
743
$template->param(%data);
749
$template->param( "step_$step"  => 1) if $step;	# associate with step to know where u are
744
$template->param( "step_$step"  => 1) if $step;	# associate with step to know where u are
Lines 757-773 $template->param( Link Here
757
  check_member    => $check_member,#to know if the borrower already exist(=>1) or not (=>0) 
752
  check_member    => $check_member,#to know if the borrower already exist(=>1) or not (=>0) 
758
  "op$op"   => 1);
753
  "op$op"   => 1);
759
754
760
$guarantorid = $borrower_data->{'guarantorid'} || $guarantorid;
761
my $guarantor = $guarantorid ? Koha::Patrons->find( $guarantorid ) : undef;
762
$template->param(
755
$template->param(
763
  patron => $patron, # Used by address include templates now
756
  patron => $patron, # Used by address include templates now
764
  nodouble  => $nodouble,
757
  nodouble  => $nodouble,
765
  borrowernumber  => $borrowernumber, #register number
758
  borrowernumber  => $borrowernumber, #register number
766
  guarantor   => $guarantor,
767
  guarantorid => $guarantorid,
768
  relshiploop => \@relshipdata,
759
  relshiploop => \@relshipdata,
769
  btitle=> $default_borrowertitle,
760
  btitle=> $default_borrowertitle,
770
  guarantorinfo   => $guarantorinfo,
771
  flagloop  => \@flagdata,
761
  flagloop  => \@flagdata,
772
  category_type =>$category_type,
762
  category_type =>$category_type,
773
  modify          => $modify,
763
  modify          => $modify,
Lines 895-900 sub patron_attributes_form { Link Here
895
885
896
}
886
}
897
887
888
sub add_guarantors {
889
    my ( $borrowernumber, $input ) = @_;
890
891
    my @new_guarantor_id           = scalar $input->param('new_guarantor_id');
892
    my @new_guarantor_surname      = scalar $input->param('new_guarantor_surname');
893
    my @new_guarantor_firstname    = scalar $input->param('new_guarantor_firstname');
894
    my @new_guarantor_relationship = scalar $input->param('new_guarantor_relationship');
895
896
    for ( my $i = 0 ; $i < scalar @new_guarantor_id; $i++ ) {
897
        my $guarantor_id = $new_guarantor_id[$i];
898
        my $surname      = $new_guarantor_surname[$i];
899
        my $firstname    = $new_guarantor_firstname[$i];
900
        my $relationship = $new_guarantor_relationship[$i];
901
902
        if ($guarantor_id) {
903
            Koha::Patron::Relationship->new(
904
                {
905
                    guarantee_id => $borrowernumber,
906
                    guarantor_id => $guarantor_id,
907
                    relationship => $relationship
908
                }
909
            )->store();
910
        }
911
        elsif ($surname) {
912
            Koha::Patron::Relationship->new(
913
                {
914
                    guarantee_id => $borrowernumber,
915
                    surname      => $surname,
916
                    firstname    => $firstname,
917
                    relationship => $relationship
918
                }
919
            )->store();
920
        }
921
    }
922
}
923
898
# Local Variables:
924
# Local Variables:
899
# tab-width: 8
925
# tab-width: 8
900
# End:
926
# End:
(-)a/members/moremember.pl (-15 / +13 lines)
Lines 175-196 if ( $patron->is_child ) { Link Here
175
}
175
}
176
176
177
my @relatives;
177
my @relatives;
178
if ( my $guarantor = $patron->guarantor ) {
178
my $guarantor_relationships = $patron->guarantor_relationships;
179
    $template->param( guarantor => $guarantor );
179
my @guarantees              = $patron->guarantee_relationships->guarantees;
180
    push @relatives, $guarantor->borrowernumber;
180
my @guarantors              = $guarantor_relationships->guarantors;
181
    push @relatives, $_->borrowernumber for $patron->siblings;
181
if (@guarantors) {
182
} elsif ( $patron->contactname || $patron->contactfirstname ) {
182
    push( @relatives, $_->id ) for @guarantors;
183
    $template->param(
183
    push( @relatives, $_->id ) for $patron->siblings();
184
        guarantor => {
185
            firstname => $patron->contactfirstname,
186
            surname   => $patron->contactname,
187
        }
188
    );
189
} else {
190
    my @guarantees = $patron->guarantees;
191
    $template->param( guarantees => \@guarantees );
192
    push @relatives, $_->borrowernumber for @guarantees;
193
}
184
}
185
else {
186
    push( @relatives, $_->id ) for @guarantees;
187
}
188
$template->param(
189
    guarantor_relationships => $guarantor_relationships,
190
    guarantees              => \@guarantees,
191
);
194
192
195
my $relatives_issues_count =
193
my $relatives_issues_count =
196
  Koha::Database->new()->schema()->resultset('Issue')
194
  Koha::Database->new()->schema()->resultset('Issue')
(-)a/members/update-child.pl (-8 / +13 lines)
Lines 34-39 use C4::Output; Link Here
34
use C4::Members;
34
use C4::Members;
35
use Koha::Patrons;
35
use Koha::Patrons;
36
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
37
use Koha::Patrons;
37
38
38
# use Smart::Comments;
39
# use Smart::Comments;
39
40
Lines 54-60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
54
my $borrowernumber = $input->param('borrowernumber');
55
my $borrowernumber = $input->param('borrowernumber');
55
my $catcode        = $input->param('catcode');
56
my $catcode        = $input->param('catcode');
56
my $cattype        = $input->param('cattype');
57
my $cattype        = $input->param('cattype');
57
my $catcode_multi = $input->param('catcode_multi');
58
my $catcode_multi  = $input->param('catcode_multi');
58
my $op             = $input->param('op');
59
my $op             = $input->param('op');
59
60
60
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
61
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
Lines 71-81 if ( $op eq 'multi' ) { Link Here
71
    );
72
    );
72
    output_html_with_http_headers $input, $cookie, $template->output;
73
    output_html_with_http_headers $input, $cookie, $template->output;
73
}
74
}
74
75
elsif ( $op eq 'update' ) {
75
elsif ( $op eq 'update' ) {
76
    my $patron         = Koha::Patrons->find( $borrowernumber );
76
    my $patron         = Koha::Patrons->find( $borrowernumber );
77
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
77
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
78
78
79
    $_->delete() for $patron->guarantor_relationships();
80
79
    my $member = $patron->unblessed;
81
    my $member = $patron->unblessed;
80
    $member->{'guarantorid'}  = 0;
82
    $member->{'guarantorid'}  = 0;
81
    $member->{'categorycode'} = $catcode;
83
    $member->{'categorycode'} = $catcode;
Lines 85-98 elsif ( $op eq 'update' ) { Link Here
85
    delete $member->{password};
87
    delete $member->{password};
86
    ModMember(%$member);
88
    ModMember(%$member);
87
89
88
    if (  $catcode_multi ) {
90
    if ($catcode_multi) {
89
        $template->param(
91
        $template->param(
90
                SUCCESS        => 1,
92
            SUCCESS        => 1,
91
                borrowernumber => $borrowernumber,
93
            borrowernumber => $borrowernumber,
92
                );
94
        );
93
        output_html_with_http_headers $input, $cookie, $template->output;
95
        output_html_with_http_headers $input, $cookie, $template->output;
94
    } else {
96
    }
95
        print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
97
    else {
98
        print $input->redirect(
99
            "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"
100
        );
96
    }
101
    }
97
}
102
}
98
103
(-)a/misc/cronjobs/j2a.pl (-12 / +45 lines)
Lines 163-174 $verbose and print "The age limit for category $fromcat is $agelimit\n"; Link Here
163
my $itsyourbirthday = "$year-$mon-$mday";
163
my $itsyourbirthday = "$year-$mon-$mday";
164
164
165
if ( not $noaction ) {
165
if ( not $noaction ) {
166
    # Start a transaction since we need to delete from relationships and update borrowers atomically
167
    $dbh->{AutoCommit} = 0;
168
166
    if ($mybranch) {    #yep, we received a specific branch to work on.
169
    if ($mybranch) {    #yep, we received a specific branch to work on.
167
        $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
170
        $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
168
        my $query = qq|
171
        my $where = qq|
169
            UPDATE borrowers
170
            SET guarantorid ='0',
171
                categorycode = ?
172
            WHERE dateofbirth <= ?
172
            WHERE dateofbirth <= ?
173
              AND dateofbirth != '0000-00-00'
173
              AND dateofbirth != '0000-00-00'
174
              AND branchcode = ?
174
              AND branchcode = ?
Lines 177-186 if ( not $noaction ) { Link Here
177
                FROM categories
177
                FROM categories
178
                WHERE category_type = 'C'
178
                WHERE category_type = 'C'
179
                  AND categorycode = ?
179
                  AND categorycode = ?
180
              )|;
180
              )
181
        |;
182
183
        my $query = qq|
184
            DELETE relationships FROM relationships
185
            LEFT JOIN borrowers ON ( borrowers.borrowernumber = relationships.guarantee_id )
186
            $where
187
        |;
181
        my $sth = $dbh->prepare($query);
188
        my $sth = $dbh->prepare($query);
189
        $sth->execute( $itsyourbirthday, $mybranch, $fromcat )
190
          or ( $dbh->rollback && die "can't execute" );
191
192
        $query = qq|
193
            UPDATE borrowers
194
            SET categorycode = ?
195
            $where
196
        |;
197
        $sth = $dbh->prepare($query);
182
        my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
198
        my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
183
          or die "can't execute";
199
          or ( $dbh->rollback && die "can't execute" );
200
201
        $dbh->commit;
184
202
185
        if ( $res eq '0E0' ) {
203
        if ( $res eq '0E0' ) {
186
            print "No patrons updated\n";
204
            print "No patrons updated\n";
Lines 191-200 if ( not $noaction ) { Link Here
191
    }
209
    }
192
    else {    # branch was not supplied, processing all branches
210
    else {    # branch was not supplied, processing all branches
193
        $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
211
        $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
194
        my $query = qq|
212
        my $where = qq|
195
            UPDATE borrowers
196
            SET guarantorid = '0',
197
                categorycode = ?
198
            WHERE dateofbirth <= ?
213
            WHERE dateofbirth <= ?
199
              AND dateofbirth!='0000-00-00'
214
              AND dateofbirth!='0000-00-00'
200
              AND categorycode IN (
215
              AND categorycode IN (
Lines 202-211 if ( not $noaction ) { Link Here
202
                FROM categories
217
                FROM categories
203
                WHERE category_type = 'C'
218
                WHERE category_type = 'C'
204
                  AND categorycode = ?
219
                  AND categorycode = ?
205
              )|;
220
              )
221
        |;
222
223
        my $query = qq|
224
            DELETE relationships FROM relationships
225
            LEFT JOIN borrowers ON ( borrowers.borrowernumber = relationships.guarantee_id )
226
            $where
227
        |;
206
        my $sth = $dbh->prepare($query);
228
        my $sth = $dbh->prepare($query);
229
        $sth->execute( $itsyourbirthday, $fromcat )
230
          or ( $dbh->rollback && die "can't execute" );
231
232
        $query = qq|
233
            UPDATE borrowers
234
            SET categorycode = ?
235
            $where
236
        |;
237
        $sth = $dbh->prepare($query);
207
        my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
238
        my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
208
          or die "can't execute";
239
          or ( $dbh->rollback && die "can't execute" );
240
        $dbh->commit;
209
241
210
        if ( $res eq '0E0' ) {
242
        if ( $res eq '0E0' ) {
211
            print "No patrons updated\n";
243
            print "No patrons updated\n";
Lines 267-272 else { Link Here
267
        my $sth = $dbh->prepare($query);
299
        my $sth = $dbh->prepare($query);
268
        $sth->execute( $itsyourbirthday, $fromcat )
300
        $sth->execute( $itsyourbirthday, $fromcat )
269
          or die "Couldn't execute statement: " . $sth->errstr;
301
          or die "Couldn't execute statement: " . $sth->errstr;
302
        $dbh->commit;
270
303
271
        while ( my @res = $sth->fetchrow_array() ) {
304
        while ( my @res = $sth->fetchrow_array() ) {
272
            my $firstname = $res[0];
305
            my $firstname = $res[0];
(-)a/opac/opac-memberentry.pl (-2 / +2 lines)
Lines 299-305 elsif ( $action eq 'edit' ) { #Display logged in borrower's data Link Here
299
299
300
    $template->param(
300
    $template->param(
301
        borrower  => $borrower,
301
        borrower  => $borrower,
302
        guarantor => scalar Koha::Patrons->find($borrowernumber)->guarantor(),
303
        hidden => GetHiddenFields( $mandatory, 'modification' ),
302
        hidden => GetHiddenFields( $mandatory, 'modification' ),
304
        csrf_token => Koha::Token->new->generate_csrf({
303
        csrf_token => Koha::Token->new->generate_csrf({
305
            session_id => scalar $cgi->cookie('CGISESSID'),
304
            session_id => scalar $cgi->cookie('CGISESSID'),
Lines 320-326 my $captcha = random_string("CCCCC"); Link Here
320
319
321
$template->param(
320
$template->param(
322
    captcha        => $captcha,
321
    captcha        => $captcha,
323
    captcha_digest => md5_base64($captcha)
322
    captcha_digest => md5_base64($captcha),
323
    patron         => Koha::Patrons->find( $borrowernumber ),
324
);
324
);
325
325
326
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
326
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-user.pl (-8 / +9 lines)
Lines 40-45 use Koha::Holds; Link Here
40
use Koha::Database;
40
use Koha::Database;
41
use Koha::ItemTypes;
41
use Koha::ItemTypes;
42
use Koha::Patron::Attribute::Types;
42
use Koha::Patron::Attribute::Types;
43
use Koha::Patrons;
43
use Koha::Patron::Messages;
44
use Koha::Patron::Messages;
44
use Koha::Patron::Discharge;
45
use Koha::Patron::Discharge;
45
use Koha::Patrons;
46
use Koha::Patrons;
Lines 76-81 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
76
    }
77
    }
77
);
78
);
78
79
80
my $patron = Koha::Patrons->find( $borrowernumber );
81
79
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
82
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
80
83
81
my $show_priority;
84
my $show_priority;
Lines 348-361 my $patron_messages = Koha::Patron::Messages->search( Link Here
348
if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
351
if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
349
    || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
352
    || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
350
{
353
{
351
    my @relatives =
354
    my @relatives;
352
      Koha::Database->new()->schema()->resultset("Borrower")->search(
355
    # Filter out guarantees that don't want guarantor to see checkouts
353
        {
356
    foreach my $gr ( $patron->guarantee_relationships() ) {
354
            privacy_guarantor_checkouts => 1,
357
        my $g = $gr->guarantee;
355
            'me.guarantorid'           => $borrowernumber
358
        push( @relatives, $g ) if $g->privacy_guarantor_checkouts;
356
        },
359
    }
357
        { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] }
358
      );
359
    $template->param( relatives => \@relatives );
360
    $template->param( relatives => \@relatives );
360
}
361
}
361
362
(-)a/t/Patron.t (-22 / +2 lines)
Lines 95-106 my $patron = Koha::Patron->new( Link Here
95
        lost                => '0',
95
        lost                => '0',
96
        debarred            => '2015-04-19',
96
        debarred            => '2015-04-19',
97
        debarredcomment     => 'You are debarred',
97
        debarredcomment     => 'You are debarred',
98
        contactname         => 'myContactname',
99
        contactfirstname    => 'myContactfirstname',
100
        contacttitle        => 'myContacttitle',
101
        guarantorid         => '123454321',
102
        borrowernotes       => 'borrowernotes',
98
        borrowernotes       => 'borrowernotes',
103
        relationship        => 'myRelationship',
104
        sex                 => 'M',
99
        sex                 => 'M',
105
        password            => 'hfkurhfe976634èj!',
100
        password            => 'hfkurhfe976634èj!',
106
        flags               => '55555',
101
        flags               => '55555',
Lines 125-131 my $patron = Koha::Patron->new( Link Here
125
120
126
# patron Accessor tests
121
# patron Accessor tests
127
subtest 'Accessor tests' => sub {
122
subtest 'Accessor tests' => sub {
128
    plan tests => 65;
123
    plan tests => 60;
129
    is( $patron->borrowernumber, '12345',                           'borrowernumber accessor returns correct value' );
124
    is( $patron->borrowernumber, '12345',                           'borrowernumber accessor returns correct value' );
130
    is( $patron->cardnumber,     '1234567890',                      'cardnumber accessor returns correct value' );
125
    is( $patron->cardnumber,     '1234567890',                      'cardnumber accessor returns correct value' );
131
    is( $patron->surname,        'mySurname',                       'surname accessor returns correct value' );
126
    is( $patron->surname,        'mySurname',                       'surname accessor returns correct value' );
Lines 166-177 subtest 'Accessor tests' => sub { Link Here
166
    is( $patron->lost,           '0',                               'lost accessor returns correct value' );
161
    is( $patron->lost,           '0',                               'lost accessor returns correct value' );
167
    is( $patron->debarred,       '2015-04-19',                      'debarred accessor returns correct value' );
162
    is( $patron->debarred,       '2015-04-19',                      'debarred accessor returns correct value' );
168
    is( $patron->debarredcomment,     'You are debarred',      'debarredcomment accessor returns correct value' );
163
    is( $patron->debarredcomment,     'You are debarred',      'debarredcomment accessor returns correct value' );
169
    is( $patron->contactname,         'myContactname',         'contactname accessor returns correct value' );
170
    is( $patron->contactfirstname,    'myContactfirstname',    'contactfirstname accessor returns correct value' );
171
    is( $patron->contacttitle,        'myContacttitle',        'contacttitle accessor returns correct value' );
172
    is( $patron->guarantorid,         '123454321',             'guarantorid accessor returns correct value' );
173
    is( $patron->borrowernotes,       'borrowernotes',         'borrowernotes accessor returns correct value' );
164
    is( $patron->borrowernotes,       'borrowernotes',         'borrowernotes accessor returns correct value' );
174
    is( $patron->relationship,        'myRelationship',        'relationship accessor returns correct value' );
175
    is( $patron->sex,                 'M',                     'sex accessor returns correct value' );
165
    is( $patron->sex,                 'M',                     'sex accessor returns correct value' );
176
    is( $patron->password,            'hfkurhfe976634èj!',    'password accessor returns correct value' );
166
    is( $patron->password,            'hfkurhfe976634èj!',    'password accessor returns correct value' );
177
    is( $patron->flags,               '55555',                 'flags accessor returns correct value' );
167
    is( $patron->flags,               '55555',                 'flags accessor returns correct value' );
Lines 195-201 subtest 'Accessor tests' => sub { Link Here
195
185
196
# patron Set tests
186
# patron Set tests
197
subtest 'Set tests' => sub {
187
subtest 'Set tests' => sub {
198
    plan tests => 65;
188
    plan tests => 60;
199
189
200
    $patron->set(
190
    $patron->set(
201
        {
191
        {
Lines 239-250 subtest 'Set tests' => sub { Link Here
239
            lost                => '1',
229
            lost                => '1',
240
            debarred            => '2016-04-19',
230
            debarred            => '2016-04-19',
241
            debarredcomment     => 'You are still debarred',
231
            debarredcomment     => 'You are still debarred',
242
            contactname         => 'SmyContactname',
243
            contactfirstname    => 'SmyContactfirstname',
244
            contacttitle        => 'SmyContacttitle',
245
            guarantorid         => '223454321',
246
            borrowernotes       => 'Sborrowernotes',
232
            borrowernotes       => 'Sborrowernotes',
247
            relationship        => 'SmyRelationship',
248
            sex                 => 'F',
233
            sex                 => 'F',
249
            password            => 'zerzerzer#',
234
            password            => 'zerzerzer#',
250
            flags               => '666666',
235
            flags               => '666666',
Lines 307-318 subtest 'Set tests' => sub { Link Here
307
    is( $patron->lost,                '1',                                'lost field set ok' );
292
    is( $patron->lost,                '1',                                'lost field set ok' );
308
    is( $patron->debarred,            '2016-04-19',                       'debarred field set ok' );
293
    is( $patron->debarred,            '2016-04-19',                       'debarred field set ok' );
309
    is( $patron->debarredcomment,     'You are still debarred',           'debarredcomment field set ok' );
294
    is( $patron->debarredcomment,     'You are still debarred',           'debarredcomment field set ok' );
310
    is( $patron->contactname,         'SmyContactname',                   'contactname field set ok' );
311
    is( $patron->contactfirstname,    'SmyContactfirstname',              'contactfirstname field set ok' );
312
    is( $patron->contacttitle,        'SmyContacttitle',                  'contacttitle field set ok' );
313
    is( $patron->guarantorid,         '223454321',                        'guarantorid field set ok' );
314
    is( $patron->borrowernotes,       'Sborrowernotes',                   'borrowernotes field set ok' );
295
    is( $patron->borrowernotes,       'Sborrowernotes',                   'borrowernotes field set ok' );
315
    is( $patron->relationship,        'SmyRelationship',                  'relationship field set ok' );
316
    is( $patron->sex,                 'F',                                'sex field set ok' );
296
    is( $patron->sex,                 'F',                                'sex field set ok' );
317
    is( $patron->password,            'zerzerzer#',                       'password field set ok' );
297
    is( $patron->password,            'zerzerzer#',                       'password field set ok' );
318
    is( $patron->flags,               '666666',                           'flags field set ok' );
298
    is( $patron->flags,               '666666',                           'flags field set ok' );
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-6 / +19 lines)
Lines 26-31 use C4::Accounts qw( manualinvoice ); Link Here
26
use C4::Circulation qw( CanBookBeIssued );
26
use C4::Circulation qw( CanBookBeIssued );
27
use Koha::Account::Lines;
27
use Koha::Account::Lines;
28
use Koha::Account::Offsets;
28
use Koha::Account::Offsets;
29
use Koha::Patron::Relationship;
29
30
30
my $schema = Koha::Database->new->schema;
31
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
$schema->storage->txn_begin;
Lines 52-63 my $patron = $builder->build_object( Link Here
52
        }
53
        }
53
    }
54
    }
54
);
55
);
55
my $guarantee = $builder->build(
56
57
my $guarantee = $builder->build_object(
56
    {
58
    {
57
        source => 'Borrower',
59
        class => 'Koha::Patrons',
58
        value  => {
60
        value => {
61
            patron_category => $patron_category->{categorycode},
59
            guarantorid => $patron->borrowernumber,
62
            guarantorid => $patron->borrowernumber,
60
            categorycode => $patron_category->{categorycode},
63
        }
64
    }
65
);
66
67
my $r = $builder->build_object(
68
    {
69
        class => 'Koha::Patron::Relationships',
70
        value => {
71
            guarantor_id => $patron->id,
72
            guarantee_id => $guarantee->id,
73
            relationship => 'parent',
61
        }
74
        }
62
    }
75
    }
63
);
76
);
Lines 68-78 t::lib::Mocks::mock_preference( 'AllowFineOverride', '' ); Link Here
68
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
81
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
69
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
82
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
70
83
71
manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
84
manualinvoice( $guarantee->id, undef, undef, 'L', 10.00 );
72
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
85
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
73
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
86
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
74
87
75
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
88
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
76
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
89
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
77
is( $accountline->accounttype, "L", "Account type is L" );
90
is( $accountline->accounttype, "L", "Account type is L" );
78
91
(-)a/t/db_dependent/Items.t (-1 / +5 lines)
Lines 508-514 subtest 'SearchItems test' => sub { Link Here
508
508
509
subtest 'Koha::Item(s) tests' => sub {
509
subtest 'Koha::Item(s) tests' => sub {
510
510
511
    plan tests => 5;
511
    plan tests => 7;
512
512
513
    $schema->storage->txn_begin();
513
    $schema->storage->txn_begin();
514
514
Lines 547-552 subtest 'Koha::Item(s) tests' => sub { Link Here
547
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
547
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
548
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
548
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
549
549
550
    my $biblio = $item->biblio();
551
    is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
552
    is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );
553
550
    $schema->storage->txn_rollback;
554
    $schema->storage->txn_rollback;
551
};
555
};
552
556
(-)a/t/db_dependent/Koha/Patrons.t (-15 / +21 lines)
Lines 34-39 use Koha::Holds; Link Here
34
use Koha::Patron;
34
use Koha::Patron;
35
use Koha::Patrons;
35
use Koha::Patrons;
36
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
37
use Koha::Patron::Relationship;
37
use Koha::Database;
38
use Koha::Database;
38
use Koha::DateUtils;
39
use Koha::DateUtils;
39
use Koha::Virtualshelves;
40
use Koha::Virtualshelves;
Lines 84-106 subtest 'library' => sub { Link Here
84
85
85
subtest 'guarantees' => sub {
86
subtest 'guarantees' => sub {
86
    plan tests => 8;
87
    plan tests => 8;
87
    my $guarantees = $new_patron_1->guarantees;
88
    my $guarantees = $new_patron_1->guarantee_relationships;
88
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
89
    is( ref($guarantees), 'Koha::Patron::Relationships', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
89
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee' );
90
    is( $guarantees->count, 0, 'new_patron_1 should have 0 guarantee relationships' );
90
    my @guarantees = $new_patron_1->guarantees;
91
    my @guarantees = $new_patron_1->guarantee_relationships;
91
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
92
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantee_relationships should return an array in a list context' );
92
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
93
    is( scalar(@guarantees), 0, 'new_patron_1 should have 0 guarantee' );
93
94
94
    my $guarantee_1 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
95
    my $guarantee_1 = $builder->build({ source => 'Borrower' });
95
    my $guarantee_2 = $builder->build({ source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber }});
96
    my $relationship_1 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->id, guarantee_id => $guarantee_1->{borrowernumber} } )->store();
97
    my $guarantee_2 = $builder->build({ source => 'Borrower' });
98
    my $relationship_2 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->id, guarantee_id => $guarantee_2->{borrowernumber} } )->store();
96
99
97
    $guarantees = $new_patron_1->guarantees;
100
    $guarantees = $new_patron_1->guarantee_relationships;
98
    is( ref($guarantees), 'Koha::Patrons', 'Koha::Patron->guarantees should return a Koha::Patrons result set in a scalar context' );
101
    is( ref($guarantees), 'Koha::Patron::Relationships', 'Koha::Patron->guarantee_relationships should return a Koha::Patrons result set in a scalar context' );
99
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
102
    is( $guarantees->count, 2, 'new_patron_1 should have 2 guarantees' );
100
    @guarantees = $new_patron_1->guarantees;
103
    @guarantees = $new_patron_1->guarantee_relationships;
101
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantees should return an array in a list context' );
104
    is( ref(\@guarantees), 'ARRAY', 'Koha::Patron->guarantee_relationships should return an array in a list context' );
102
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
105
    is( scalar(@guarantees), 2, 'new_patron_1 should have 2 guarantees' );
103
    $_->delete for @guarantees;
106
    map { $_->guarantee->delete } @guarantees;
104
};
107
};
105
108
106
subtest 'category' => sub {
109
subtest 'category' => sub {
Lines 114-128 subtest 'siblings' => sub { Link Here
114
    plan tests => 7;
117
    plan tests => 7;
115
    my $siblings = $new_patron_1->siblings;
118
    my $siblings = $new_patron_1->siblings;
116
    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
119
    is( $siblings, undef, 'Koha::Patron->siblings should not crashed if the patron has no guarantor' );
117
    my $guarantee_1 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
120
    my $guarantee_1 = $builder->build( { source => 'Borrower' } );
121
    my $relationship_1 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_1->{borrowernumber} } )->store();
118
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
122
    my $retrieved_guarantee_1 = Koha::Patrons->find($guarantee_1);
119
    $siblings = $retrieved_guarantee_1->siblings;
123
    $siblings = $retrieved_guarantee_1->siblings;
120
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
124
    is( ref($siblings), 'Koha::Patrons', 'Koha::Patron->siblings should return a Koha::Patrons result set in a scalar context' );
121
    my @siblings = $retrieved_guarantee_1->siblings;
125
    my @siblings = $retrieved_guarantee_1->siblings;
122
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
126
    is( ref( \@siblings ), 'ARRAY', 'Koha::Patron->siblings should return an array in a list context' );
123
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
127
    is( $siblings->count,  0,       'guarantee_1 should not have siblings yet' );
124
    my $guarantee_2 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
128
    my $guarantee_2 = $builder->build( { source => 'Borrower' } );
125
    my $guarantee_3 = $builder->build( { source => 'Borrower', value => { guarantorid => $new_patron_1->borrowernumber } } );
129
    my $relationship_2 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_2->{borrowernumber} } )->store();
130
    my $guarantee_3 = $builder->build( { source => 'Borrower' } );
131
    my $relationship_3 = Koha::Patron::Relationship->new( { guarantor_id => $new_patron_1->borrowernumber, guarantee_id => $guarantee_3->{borrowernumber} } )->store();
126
    $siblings = $retrieved_guarantee_1->siblings;
132
    $siblings = $retrieved_guarantee_1->siblings;
127
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
133
    is( $siblings->count,               2,                               'guarantee_1 should have 2 siblings' );
128
    is( $guarantee_2->{borrowernumber}, $siblings->next->borrowernumber, 'guarantee_2 should exist in the guarantees' );
134
    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 / +1 lines)
Lines 62-67 my $extended = C4::Context->preference('ExtendedPatronAttributes'); Link Here
62
62
63
my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } Koha::Patrons->columns();
63
my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } Koha::Patrons->columns();
64
push( @columnkeys, 'patron_attributes' ) if $extended;
64
push( @columnkeys, 'patron_attributes' ) if $extended;
65
push( @columnkeys, qw( relationship guarantor_id  guarantor_firstname guarantor_surname ) );
65
66
66
my $input = CGI->new();
67
my $input = CGI->new();
67
68
68
- 

Return to bug 14570