communigate provisioning phase 2: add svc_domain.trailer -> communigate TrailerText...
[freeside.git] / FS / FS / contact.pm
1 package FS::contact;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::prospect_main;
7 use FS::cust_main;
8 use FS::cust_location;
9
10 =head1 NAME
11
12 FS::contact - Object methods for contact records
13
14 =head1 SYNOPSIS
15
16   use FS::contact;
17
18   $record = new FS::contact \%hash;
19   $record = new FS::contact { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::contact object represents an example.  FS::contact inherits from
32 FS::Record.  The following fields are currently supported:
33
34 =over 4
35
36 =item contactnum
37
38 primary key
39
40 =item prospectnum
41
42 prospectnum
43
44 =item custnum
45
46 custnum
47
48 =item locationnum
49
50 locationnum
51
52 =item last
53
54 last
55
56 =item first
57
58 first
59
60 =item title
61
62 title
63
64 =item comment
65
66 comment
67
68 =item disabled
69
70 disabled
71
72
73 =back
74
75 =head1 METHODS
76
77 =over 4
78
79 =item new HASHREF
80
81 Creates a new example.  To add the example to the database, see L<"insert">.
82
83 Note that this stores the hash reference, not a distinct copy of the hash it
84 points to.  You can ask the object for a copy with the I<hash> method.
85
86 =cut
87
88 # the new method can be inherited from FS::Record, if a table method is defined
89
90 sub table { 'contact'; }
91
92 =item insert
93
94 Adds this record to the database.  If there is an error, returns the error,
95 otherwise returns false.
96
97 =cut
98
99 # the insert method can be inherited from FS::Record
100
101 =item delete
102
103 Delete this record from the database.
104
105 =cut
106
107 # the delete method can be inherited from FS::Record
108
109 =item replace OLD_RECORD
110
111 Replaces the OLD_RECORD with this one in the database.  If there is an error,
112 returns the error, otherwise returns false.
113
114 =cut
115
116 # the replace method can be inherited from FS::Record
117
118 =item check
119
120 Checks all fields to make sure this is a valid example.  If there is
121 an error, returns the error, otherwise returns false.  Called by the insert
122 and replace methods.
123
124 =cut
125
126 # the check method should currently be supplied - FS::Record contains some
127 # data checking routines
128
129 sub check {
130   my $self = shift;
131
132   my $error = 
133     $self->ut_numbern('contactnum')
134     || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
135     || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
136     || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
137     || $self->ut_textn('last')
138     || $self->ut_textn('first')
139     || $self->ut_textn('title')
140     || $self->ut_textn('comment')
141     || $self->ut_enum('disabled', [ '', 'Y' ])
142   ;
143   return $error if $error;
144
145   return "No prospect or customer!" unless $self->prospectnum || $self->custnum;
146   return "Prospect and customer!"       if $self->prospectnum && $self->custnum;
147
148   return "One of first name, last name, or title must have a value"
149     if ! grep $self->$_(), qw( first last title);
150
151   $self->SUPER::check;
152 }
153
154 sub line {
155   my $self = shift;
156   my $data = $self->first. ' '. $self->last;
157   $data .= ', '. $self->title
158     if $self->title;
159   $data .= ' ('. $self->comment. ')'
160     if $self->comment;
161   $data;
162 }
163
164 =back
165
166 =head1 BUGS
167
168 The author forgot to customize this manpage.
169
170 =head1 SEE ALSO
171
172 L<FS::Record>, schema.html from the base documentation.
173
174 =cut
175
176 1;
177