and show the flag in view UI, #38191
[freeside.git] / FS / FS / cust_main_note.pm
1 package FS::cust_main_note;
2 use base qw( FS::otaker_Mixin FS::Record );
3
4 use strict;
5 use Carp;
6 use FS::Record qw( qsearchs ); #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 classnum
42
43 =item _date
44
45 =item usernum
46
47 =item comments
48
49 =back
50
51 =head1 METHODS
52
53 =over 4
54
55 =item new HASHREF
56
57 Creates a new customer note.  To add the note to the database, see L<"insert">.
58
59 Note that this stores the hash reference, not a distinct copy of the hash it
60 points to.  You can ask the object for a copy with the I<hash> method.
61
62 =cut
63
64 # the new method can be inherited from FS::Record, if a table method is defined
65
66 sub table { 'cust_main_note'; }
67
68 =item insert
69
70 Adds this record to the database.  If there is an error, returns the error,
71 otherwise returns false.
72
73 =cut
74
75 # the insert method can be inherited from FS::Record
76
77 =item delete
78
79 Delete this record from the database.
80
81 =cut
82
83 # the delete method can be inherited from FS::Record
84
85 =item replace OLD_RECORD
86
87 Replaces the OLD_RECORD with this one in the database.  If there is an error,
88 returns the error, otherwise returns false.
89
90 =cut
91
92 # the replace method can be inherited from FS::Record
93
94 =item check
95
96 Checks all fields to make sure this is a valid example.  If there is
97 an error, returns the error, otherwise returns false.  Called by the insert
98 and replace methods.
99
100 =cut
101
102 # the check method should currently be supplied - FS::Record contains some
103 # data checking routines
104
105 sub check {
106   my $self = shift;
107
108   my $error = 
109     $self->ut_numbern('notenum')
110     || $self->ut_number('custnum')
111     || $self->ut_foreign_keyn('classnum', 'cust_note_class', 'classnum')
112     || $self->ut_numbern('_date')
113     || $self->ut_textn('otaker')
114     || $self->ut_anything('comments')
115     || $self->ut_numbern('sticky')
116   ;
117   return $error if $error;
118
119   $self->SUPER::check;
120 }
121
122 =item cust_note_class
123
124 Returns the customer note class, as an FS::cust_note_class object, or the empty
125 string if there is no note class.
126
127 =item classname 
128
129 Returns the customer note class name, or the empty string if there is no 
130 customer note class.
131
132 =cut
133
134 sub classname {
135   my $self = shift;
136   my $cust_note_class = $self->cust_note_class;
137   $cust_note_class ? $cust_note_class->classname : '';
138 }
139
140
141 #false laziness w/otaker_Mixin & cust_attachment
142 sub otaker {
143   my $self = shift;
144   if ( scalar(@_) ) { #set
145     my $otaker = shift;
146     my($l,$f) = (split(', ', $otaker));
147     my $access_user =  qsearchs('access_user', { 'username'=>$otaker }     )
148                     || qsearchs('access_user', { 'first'=>$f, 'last'=>$l } )
149       or croak "can't set otaker: $otaker not found!"; #confess?
150     $self->usernum( $access_user->usernum );
151     $otaker; #not sure return is used anywhere, but just in case
152   } else { #get
153     if ( $self->usernum ) {
154       $self->access_user->username;
155     } elsif ( length($self->get('otaker')) ) {
156       $self->get('otaker');
157     } else {
158       '';
159     }
160   }
161 }
162
163 # Used by FS::Upgrade to migrate to a new database.
164 sub _upgrade_data {  # class method
165   my ($class, %opts) = @_;
166   $class->_upgrade_otaker(%opts);
167 }
168
169 =back
170
171 =head1 BUGS
172
173 Lurking in the cracks.
174
175 =head1 SEE ALSO
176
177 L<FS::Record>, schema.html from the base documentation.
178
179 =cut
180
181 1;
182