eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / invoice_mode.pm
1 package FS::invoice_mode;
2 use base qw(FS::Record);
3
4 use strict;
5 use FS::Record qw( qsearchs ); #qsearch qsearchs );
6 use FS::invoice_conf;
7
8 =head1 NAME
9
10 FS::invoice_mode - Object methods for invoice_mode records
11
12 =head1 SYNOPSIS
13
14   use FS::invoice_mode;
15
16   $record = new FS::invoice_mode \%hash;
17   $record = new FS::invoice_mode { '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::invoice_mode object represents an invoice rendering style.  
30 FS::invoice_mode inherits from FS::Record.  The following fields are 
31 currently supported:
32
33 =over 4
34
35 =item modenum - primary key
36
37 =item agentnum - the agent who owns this invoice mode (can be null)
38
39 =item modename - descriptive name for internal use
40
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Creates a new invoice mode.  To add the object to the database, 
51 see L<"insert">.
52
53 Note that this stores the hash reference, not a distinct copy of the hash it
54 points to.  You can ask the object for a copy with the I<hash> method.
55
56 =cut
57
58 # the new method can be inherited from FS::Record, if a table method is defined
59
60 sub table { 'invoice_mode'; }
61
62 =item insert
63
64 Adds this record to the database.  If there is an error, returns the error,
65 otherwise returns false.
66
67 =cut
68
69 # the insert method can be inherited from FS::Record
70
71 =item delete
72
73 Delete this record from the database.
74
75 =cut
76
77 # the delete method can be inherited from FS::Record
78
79 =item replace OLD_RECORD
80
81 Replaces the OLD_RECORD with this one in the database.  If there is an error,
82 returns the error, otherwise returns false.
83
84 =cut
85
86 # the replace method can be inherited from FS::Record
87
88 =item check
89
90 Checks all fields to make sure this is a valid example.  If there is
91 an error, returns the error, otherwise returns false.  Called by the insert
92 and replace methods.
93
94 =cut
95
96 # the check method should currently be supplied - FS::Record contains some
97 # data checking routines
98
99 sub check {
100   my $self = shift;
101
102   my $error = 
103     $self->ut_numbern('modenum')
104     || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
105     || $self->ut_text('modename')
106   ;
107   return $error if $error;
108
109   $self->SUPER::check;
110 }
111
112 =item invoice_conf [ LOCALE ]
113
114 Returns the L<FS::invoice_conf> for this invoice mode, with the specified
115 locale.  If there isn't one with that locale, returns the one with null 
116 locale.  If that doesn't exist, returns nothing.
117
118 =cut
119
120 sub invoice_conf {
121   my $self = shift;
122   my $locale = shift;
123   my $invoice_conf;
124   if ( $locale ) {
125     $invoice_conf = qsearchs('invoice_conf', {
126         modenum => $self->modenum,
127         locale  => $locale,
128     });
129   }
130   $invoice_conf ||= qsearchs('invoice_conf', {
131       modenum => $self->modenum,
132       locale  => '',
133   });
134   $invoice_conf;
135 }
136
137 =item agent
138
139 Returns the agent associated with this invoice mode, if any.
140
141 =back
142
143 =head1 SEE ALSO
144
145 L<FS::Record>, schema.html from the base documentation.
146
147 =cut
148
149 1;
150