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