contacts can be shared among customers / "duplicate contact emails", RT#27943
[freeside.git] / FS / FS / cust_contact.pm
1 package FS::cust_contact;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::cust_contact - Object methods for cust_contact records
10
11 =head1 SYNOPSIS
12
13   use FS::cust_contact;
14
15   $record = new FS::cust_contact \%hash;
16   $record = new FS::cust_contact { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::cust_contact object represents a contact's attachment to a specific
29 customer.  FS::cust_contact inherits from FS::Record.  The following fields are
30 currently supported:
31
32 =over 4
33
34 =item custcontactnum
35
36 primary key
37
38 =item custnum
39
40 custnum
41
42 =item contactnum
43
44 contactnum
45
46 =item classnum
47
48 classnum
49
50 =item comment
51
52 comment
53
54 =item selfservice_access
55
56 empty or Y
57
58 =back
59
60 =head1 METHODS
61
62 =over 4
63
64 =item new HASHREF
65
66 Creates a new record.  To add the record to the database, see L<"insert">.
67
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to.  You can ask the object for a copy with the I<hash> method.
70
71 =cut
72
73 # the new method can be inherited from FS::Record, if a table method is defined
74
75 sub table { 'cust_contact'; }
76
77 =item insert
78
79 Adds this record to the database.  If there is an error, returns the error,
80 otherwise returns false.
81
82 =item delete
83
84 Delete this record from the database.
85
86 =item replace OLD_RECORD
87
88 Replaces the OLD_RECORD with this one in the database.  If there is an error,
89 returns the error, otherwise returns false.
90
91 =item check
92
93 Checks all fields to make sure this is a valid record.  If there is
94 an error, returns the error, otherwise returns false.  Called by the insert
95 and replace methods.
96
97 =cut
98
99 # the check method should currently be supplied - FS::Record contains some
100 # data checking routines
101
102 sub check {
103   my $self = shift;
104
105   if ( $self->selfservice_access eq 'R' ) {
106     $self->selfservice_access('Y');
107     $self->_resend('Y');
108   }
109
110   my $error = 
111     $self->ut_numbern('custcontactnum')
112     || $self->ut_number('custnum')
113     || $self->ut_number('contactnum')
114     || $self->ut_numbern('classnum')
115     || $self->ut_textn('comment')
116     || $self->ut_enum('selfservice_access', [ '', 'Y' ])
117   ;
118   return $error if $error;
119
120   $self->SUPER::check;
121 }
122
123 =item contact_classname
124
125 Returns the name of this contact's class (see L<FS::contact_class>).
126
127 =cut
128
129 sub contact_classname {
130   my $self = shift;
131   my $contact_class = $self->contact_class or return '';
132   $contact_class->classname;
133 }
134
135 =back
136
137 =head1 BUGS
138
139 =head1 SEE ALSO
140
141 L<FS::contact>, L<FS::cust_main>, L<FS::Record>
142
143 =cut
144
145 1;
146