RT# 73421 Add allow messages flag message_dest to contact_email
[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 =item invoice_dest
59
60 'Y' if the customer should get invoices sent to this address, null if not
61
62 =item message_dest
63
64 'Y' if contact should get non-invoice email messages sent to this address,
65 NULL if not
66
67 =back
68
69 =head1 METHODS
70
71 =over 4
72
73 =item new HASHREF
74
75 Creates a new record.  To add the record to the database, see L<"insert">.
76
77 Note that this stores the hash reference, not a distinct copy of the hash it
78 points to.  You can ask the object for a copy with the I<hash> method.
79
80 =cut
81
82 # the new method can be inherited from FS::Record, if a table method is defined
83
84 sub table { 'cust_contact'; }
85
86 =item insert
87
88 Adds this record to the database.  If there is an error, returns the error,
89 otherwise returns false.
90
91 =item delete
92
93 Delete this record from the database.
94
95 =item replace OLD_RECORD
96
97 Replaces the OLD_RECORD with this one in the database.  If there is an error,
98 returns the error, otherwise returns false.
99
100 =item check
101
102 Checks all fields to make sure this is a valid record.  If there is
103 an error, returns the error, otherwise returns false.  Called by the insert
104 and replace methods.
105
106 =cut
107
108 # the check method should currently be supplied - FS::Record contains some
109 # data checking routines
110
111 sub check {
112   my $self = shift;
113
114   if ( $self->selfservice_access eq 'R' || $self->selfservice_access eq 'E' || $self->selfservice_access eq 'P') {
115     $self->selfservice_access('Y');
116     $self->_resend('Y');
117   }
118
119   my $error = 
120     $self->ut_numbern('custcontactnum')
121     || $self->ut_number('custnum')
122     || $self->ut_number('contactnum')
123     || $self->ut_numbern('classnum')
124     || $self->ut_textn('comment')
125     || $self->ut_enum('selfservice_access', [ '', 'Y' ])
126     || $self->ut_flag('invoice_dest')
127     || $self->ut_flag('message_dest')
128   ;
129   return $error if $error;
130
131   $self->SUPER::check;
132 }
133
134 =item contact_classname
135
136 Returns the name of this contact's class (see L<FS::contact_class>).
137
138 =cut
139
140 sub contact_classname {
141   my $self = shift;
142   my $contact_class = $self->contact_class or return '';
143   $contact_class->classname;
144 }
145
146 =back
147
148 =head1 BUGS
149
150 =head1 SEE ALSO
151
152 L<FS::contact>, L<FS::cust_main>, L<FS::Record>
153
154 =cut
155
156 1;