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 htmlwatermark - watermark to show in background (HTML)
54 =item latexnotes - "notes" section (LaTeX)
56 =item latexfooter - footer (LaTeX)
58 =item latexsummary - summary header, for invoices in summary format (LaTeX)
60 =item latexreturnaddress - return address (LaTeX)
62 =item latexsmallfooter - footer for pages after the first (LaTeX)
64 =item latexwatermark - watermark to show in background (LaTeX)
66 =item with_latexcoupon - 'Y' to print the payment coupon (LaTeX)
68 =item lpr - command to print the invoice (passed on stdin as a PDF)
78 Creates a new invoice configuration. To add it to the database, see
83 # the new method can be inherited from FS::Record, if a table method is defined
85 sub table { 'invoice_conf'; }
87 # fields (prefixed with 'with_') that turn on certain conf variables
88 # (set them to their conf values, rather than to null)
95 Adds this record to the database. If there is an error, returns the error,
96 otherwise returns false.
100 # slightly special: you can insert/replace the invoice mode this way
104 if (!$self->modenum) {
105 my $invoice_mode = FS::invoice_mode->new({
106 'modename' => $self->modename,
107 'agentnum' => $self->agentnum,
109 my $error = $invoice_mode->insert;
110 return $error if $error;
111 $self->set('modenum' => $invoice_mode->modenum);
113 my $invoice_mode = FS::invoice_mode->by_key($self->modenum);
115 foreach (qw(agentnum modename)) {
116 $changed ||= ($invoice_mode->get($_) eq $self->get($_));
117 $invoice_mode->set($_, $self->get($_));
119 my $error = $invoice_mode->replace if $changed;
120 return $error if $error;
122 $self->SUPER::insert(@_);
127 Delete this record from the database.
133 my $error = $self->FS::Record::delete; # not Conf::delete
134 return $error if $error;
135 my $invoice_mode = FS::invoice_mode->by_key($self->modenum);
136 if ( $invoice_mode and
137 FS::invoice_conf->count('modenum = '.$invoice_mode->modenum) == 0 ) {
138 $error = $invoice_mode->delete;
139 return $error if $error;
144 =item replace OLD_RECORD
146 Replaces the OLD_RECORD with this one in the database. If there is an error,
147 returns the error, otherwise returns false.
153 my $error = $self->SUPER::replace(@_);
154 return $error if $error;
156 my $invoice_mode = FS::invoice_mode->by_key($self->modenum);
158 foreach (qw(agentnum modename)) {
159 $changed ||= ($invoice_mode->get($_) eq $self->get($_));
160 $invoice_mode->set($_, $self->get($_));
162 $error = $invoice_mode->replace if $changed;
163 return $error if $error;
168 Checks all fields to make sure this is a valid example. If there is
169 an error, returns the error, otherwise returns false. Called by the insert
174 # the check method should currently be supplied - FS::Record contains some
175 # data checking routines
181 $self->ut_numbern('confnum')
183 || $self->ut_number('modenum')
184 || $self->ut_textn('locale')
185 # direct overrides of conf variables
186 || $self->ut_anything('notice_name')
187 || $self->ut_anything('subject')
188 || $self->ut_anything('htmlnotes')
189 || $self->ut_anything('htmlfooter')
190 || $self->ut_anything('htmlsummary')
191 || $self->ut_anything('htmlreturnaddress')
192 || $self->ut_anything('htmlwatermark')
193 || $self->ut_anything('latexnotes')
194 || $self->ut_anything('latexfooter')
195 || $self->ut_anything('latexsummary')
196 || $self->ut_anything('latexsmallfooter')
197 || $self->ut_anything('latexreturnaddress')
198 || $self->ut_anything('latexwatermark')
200 || $self->ut_flag('with_latexcoupon')
202 return $error if $error;
207 # hook _config to substitute our own values; let FS::Conf do the rest of
212 # if we fall back, we still want FS::Conf to respect our locale
213 $self->{locale} = $self->get('locale');
214 my ($key, $agentnum, $nodefault) = @_;
215 # some fields, but not all, start with invoice_
217 if ( $key =~ /^invoice_(.*)$/ ) {
220 if ( $flags{$colname} and !$self->get("with_$colname") ) {
221 # then a flag field is defined, and the flag is off, so act as though
222 # the config entry doesn't exist
223 # (currently only used for "latexcoupon", to allow invoice modes
224 # where the coupon is not printed)
227 if ( length($self->get($colname)) ) {
228 return FS::conf->new({ 'name' => $key,
229 'value' => $self->get($colname) });
231 return $self->FS::Conf::_config(@_);
238 $self->FS::Record::set(@_);
243 $self->FS::Conf::exists(@_);
250 L<FS::Template_Mixin>, L<FS::Record>, schema.html from the base documentation.