4 use base qw( FS::cust_main_Mixin FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use vars qw( @statuses );
10 FS::cust_msg - Object methods for cust_msg records
16 $record = new FS::cust_msg \%hash;
17 $record = new FS::cust_msg { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $record->check;
25 An FS::cust_msg object represents a template-generated message sent to
26 a customer (see L<FS::msg_template>). FS::cust_msg inherits from
27 FS::Record. The following fields are currently supported:
31 =item custmsgnum - primary key
33 =item custnum - customer number
35 =item msgnum - template number
37 =item _date - the time the message was sent
39 =item env_from - envelope From address
41 =item env_to - envelope To addresses, including Bcc, separated by newlines
43 =item header - message header
45 =item body - message body
47 =item error - Email::Sender error message (or null for success)
61 # the new method can be inherited from FS::Record, if a table method is defined
63 sub table { 'cust_msg'; }
65 sub nohistory_fields { ('header', 'body'); }
66 # history is kind of pointless on this table
68 @statuses = qw( prepared sent failed );
72 Adds this record to the database. If there is an error, returns the error
73 and emits a warning; otherwise returns false.
78 # warn of all errors here; failing to insert/update one of these should
79 # cause a warning at worst
81 my $error = $self->SUPER::insert;
82 warn "[cust_msg] error logging message status: $error\n" if $error;
88 Delete this record from the database. There's no reason to do this.
94 warn "[cust_msg] log entry deleted\n";
95 return $self->SUPER::delete;
98 =item replace OLD_RECORD
100 Replaces the OLD_RECORD with this one in the database. If there is an error,
101 returns the error and emits a warning, otherwise returns false.
107 my $error = $self->SUPER::replace(@_);
108 warn "[cust_msg] error logging message status: $error\n" if $error;
114 Checks all fields to make sure this is a valid example. If there is
115 an error, returns the error, otherwise returns false. Called by the insert
120 # the check method should currently be supplied - FS::Record contains some
121 # data checking routines
127 $self->ut_numbern('custmsgnum')
128 || $self->ut_number('custnum')
129 || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
130 || $self->ut_numbern('msgnum')
131 || $self->ut_foreign_keyn('msgnum', 'msg_template', 'msgnum')
132 || $self->ut_numbern('_date')
133 || $self->ut_textn('env_from')
134 || $self->ut_textn('env_to')
135 || $self->ut_anything('header')
136 || $self->ut_anything('body')
137 || $self->ut_enum('status', \@statuses)
138 || $self->ut_textn('error')
140 return $error if $error;
149 L<FS::msg_template>, L<FS::cust_main>, L<FS::Record>.