1 package FS::invoice_conf;
4 use base qw( FS::Record FS::Conf );
5 use FS::Record qw( qsearch qsearchs );
9 FS::invoice_conf - Object methods for invoice_conf records
15 $record = new FS::invoice_conf \%hash;
16 $record = new FS::invoice_conf { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::invoice_conf object represents a set of localized invoice
29 configuration values. FS::invoice_conf inherits from FS::Record and FS::Conf,
30 and supports the FS::Conf interface. The following fields are supported:
34 =item confnum - primary key
36 =item modenum - L<FS::invoice_mode> foreign key
38 =item locale - locale string (see L<FS::Locales>)
40 =item notice_name - the title to display on the invoice
42 =item subject - subject line of the email
44 =item htmlnotes - "notes" section (HTML)
46 =item htmlfooter - footer (HTML)
48 =item htmlsummary - summary header, for invoices in summary format (HTML)
50 =item htmlreturnaddress - return address (HTML)
52 =item latexnotes - "notes" section (LaTeX)
54 =item latexfooter - footer (LaTeX)
56 =item latexsummary - summary header, for invoices in summary format (LaTeX)
58 =item latexreturnaddress - return address (LaTeX)
60 =item latexsmallfooter - footer for pages after the first (LaTeX)
62 =item with_latexcoupon - 'Y' to print the payment coupon (LaTeX)
64 =item lpr - command to print the invoice (passed on stdin as a PDF)
74 Creates a new invoice configuration. To add it to the database, see
79 # the new method can be inherited from FS::Record, if a table method is defined
81 sub table { 'invoice_conf'; }
83 # fields (prefixed with 'with_') that turn on certain conf variables
84 # (set them to their conf values, rather than to null)
91 Adds this record to the database. If there is an error, returns the error,
92 otherwise returns false.
96 # slightly special: you can insert/replace the invoice mode this way
100 if (!$self->modenum) {
101 my $invoice_mode = FS::invoice_mode->new({
102 'modename' => $self->modename,
103 'agentnum' => $self->agentnum,
105 my $error = $invoice_mode->insert;
106 return $error if $error;
107 $self->set('modenum' => $invoice_mode->modenum);
109 my $invoice_mode = FS::invoice_mode->by_key($self->modenum);
111 foreach (qw(agentnum modename)) {
112 $changed ||= ($invoice_mode->get($_) eq $self->get($_));
113 $invoice_mode->set($_, $self->get($_));
115 my $error = $invoice_mode->replace if $changed;
116 return $error if $error;
118 $self->SUPER::insert(@_);
123 Delete this record from the database.
129 my $error = $self->FS::Record::delete; # not Conf::delete
130 return $error if $error;
131 my $invoice_mode = FS::invoice_mode->by_key($self->modenum);
132 if ( $invoice_mode and
133 FS::invoice_conf->count('modenum = '.$invoice_mode->modenum) == 0 ) {
134 $error = $invoice_mode->delete;
135 return $error if $error;
140 =item replace OLD_RECORD
142 Replaces the OLD_RECORD with this one in the database. If there is an error,
143 returns the error, otherwise returns false.
149 my $error = $self->SUPER::replace(@_);
150 return $error if $error;
152 my $invoice_mode = FS::invoice_mode->by_key($self->modenum);
154 foreach (qw(agentnum modename)) {
155 $changed ||= ($invoice_mode->get($_) eq $self->get($_));
156 $invoice_mode->set($_, $self->get($_));
158 $error = $invoice_mode->replace if $changed;
159 return $error if $error;
164 Checks all fields to make sure this is a valid example. If there is
165 an error, returns the error, otherwise returns false. Called by the insert
170 # the check method should currently be supplied - FS::Record contains some
171 # data checking routines
177 $self->ut_numbern('confnum')
179 || $self->ut_number('modenum')
180 || $self->ut_textn('locale')
181 # direct overrides of conf variables
182 || $self->ut_anything('notice_name')
183 || $self->ut_anything('subject')
184 || $self->ut_anything('htmlnotes')
185 || $self->ut_anything('htmlfooter')
186 || $self->ut_anything('htmlsummary')
187 || $self->ut_anything('htmlreturnaddress')
188 || $self->ut_anything('latexnotes')
189 || $self->ut_anything('latexfooter')
190 || $self->ut_anything('latexsummary')
191 || $self->ut_anything('latexsmallfooter')
192 || $self->ut_anything('latexreturnaddress')
194 || $self->ut_flag('with_latexcoupon')
196 return $error if $error;
201 # hook _config to substitute our own values; let FS::Conf do the rest of
206 # if we fall back, we still want FS::Conf to respect our locale
207 $self->{locale} = $self->get('locale');
208 my ($key, $agentnum, $nodefault) = @_;
209 # some fields, but not all, start with invoice_
211 if ( $key =~ /^invoice_(.*)$/ ) {
214 if ( $flags{$colname} and !$self->get("with_$colname") ) {
215 # then a flag field is defined, and the flag is off, so act as though
216 # the config entry doesn't exist
217 # (currently only used for "latexcoupon", to allow invoice modes
218 # where the coupon is not printed)
221 if ( length($self->get($colname)) ) {
222 return FS::conf->new({ 'name' => $key,
223 'value' => $self->get($colname) });
225 return $self->FS::Conf::_config(@_);
232 $self->FS::Record::set(@_);
237 $self->FS::Conf::exists(@_);
244 L<FS::Template_Mixin>, L<FS::Record>, schema.html from the base documentation.