communigate provisioning phase 2: add svc_domain.trailer -> communigate TrailerText...
[freeside.git] / FS / FS / cust_main_note.pm
1 package FS::cust_main_note;
2
3 use strict;
4 use base qw( FS::otaker_Mixin FS::Record );
5 use Carp;
6 use FS::Record qw( qsearch qsearchs );
7
8 =head1 NAME
9
10 FS::cust_main_note - Object methods for cust_main_note records
11
12 =head1 SYNOPSIS
13
14   use FS::cust_main_note;
15
16   $record = new FS::cust_main_note \%hash;
17   $record = new FS::cust_main_note { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::cust_main_note object represents a note attachted to a customer.
30 FS::cust_main_note inherits from FS::Record.  The following fields are
31 currently supported:
32
33 =over 4
34
35 =item notenum
36
37 primary key
38
39 =item custnum
40
41 =item _date
42
43 =item usernum
44
45 =item comments
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new customer note.  To add the note to the database, see L<"insert">.
56
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to.  You can ask the object for a copy with the I<hash> method.
59
60 =cut
61
62 # the new method can be inherited from FS::Record, if a table method is defined
63
64 sub table { 'cust_main_note'; }
65
66 =item insert
67
68 Adds this record to the database.  If there is an error, returns the error,
69 otherwise returns false.
70
71 =cut
72
73 # the insert method can be inherited from FS::Record
74
75 =item delete
76
77 Delete this record from the database.
78
79 =cut
80
81 # the delete method can be inherited from FS::Record
82
83 =item replace OLD_RECORD
84
85 Replaces the OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =cut
89
90 # the replace method can be inherited from FS::Record
91
92 =item check
93
94 Checks all fields to make sure this is a valid example.  If there is
95 an error, returns the error, otherwise returns false.  Called by the insert
96 and replace methods.
97
98 =cut
99
100 # the check method should currently be supplied - FS::Record contains some
101 # data checking routines
102
103 sub check {
104   my $self = shift;
105
106   my $error = 
107     $self->ut_numbern('notenum')
108     || $self->ut_number('custnum')
109     || $self->ut_numbern('_date')
110     || $self->ut_textn('otaker')
111     || $self->ut_anything('comments')
112   ;
113   return $error if $error;
114
115   $self->SUPER::check;
116 }
117
118 #false laziness w/otaker_Mixin & cust_attachment
119 sub otaker {
120   my $self = shift;
121   if ( scalar(@_) ) { #set
122     my $otaker = shift;
123     my($l,$f) = (split(', ', $otaker));
124     my $access_user =  qsearchs('access_user', { 'username'=>$otaker }     )
125                     || qsearchs('access_user', { 'first'=>$f, 'last'=>$l } )
126       or croak "can't set otaker: $otaker not found!"; #confess?
127     $self->usernum( $access_user->usernum );
128     $otaker; #not sure return is used anywhere, but just in case
129   } else { #get
130     if ( $self->usernum ) {
131       $self->access_user->username;
132     } elsif ( length($self->get('otaker')) ) {
133       $self->get('otaker');
134     } else {
135       '';
136     }
137   }
138 }
139
140 # Used by FS::Upgrade to migrate to a new database.
141 sub _upgrade_data {  # class method
142   my ($class, %opts) = @_;
143   $class->_upgrade_otaker(%opts);
144 }
145
146 =back
147
148 =head1 BUGS
149
150 Lurking in the cracks.
151
152 =head1 SEE ALSO
153
154 L<FS::Record>, schema.html from the base documentation.
155
156 =cut
157
158 1;
159