fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / legacy_cust_bill.pm
1 package FS::legacy_cust_bill;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::cust_main;
7
8 =head1 NAME
9
10 FS::legacy_cust_bill - Object methods for legacy_cust_bill records
11
12 =head1 SYNOPSIS
13
14   use FS::legacy_cust_bill;
15
16   $record = new FS::legacy_cust_bill \%hash;
17   $record = new FS::legacy_cust_bill { '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::legacy_cust_bill object represents an invoice from a previous billing
30 system, about which full details are not availble.  Instead, the rendered
31 content is stored in HTML or PDF format.  FS::legacy_cust_bill invoices are
32 stored for informational and display purposes only; they have no effect upon
33 customer balances.
34
35 FS::legacy_cust_bill inherits from FS::Record.  The following fields are
36 currently supported:
37
38 =over 4
39
40 =item legacyinvnum
41
42 primary key
43
44 =item legacyid
45
46 Invoice number or identifier from previous system
47
48 =item custnum
49
50 Customer (see L<FS::cust_main)
51
52 =item _date
53
54 Date, as a UNIX timestamp
55
56 =item charged
57
58 Amount charged
59
60 =item content_pdf
61
62 PDF content
63
64 =item content_html
65
66 HTML content
67
68
69 =back
70
71 =head1 METHODS
72
73 =over 4
74
75 =item new HASHREF
76
77 Creates a new legacy invoice.  To add the example to the database, see
78 L<"insert">.
79
80 Note that this stores the hash reference, not a distinct copy of the hash it
81 points to.  You can ask the object for a copy with the I<hash> method.
82
83 =cut
84
85 # the new method can be inherited from FS::Record, if a table method is defined
86
87 sub table { 'legacy_cust_bill'; }
88
89 =item insert
90
91 Adds this record to the database.  If there is an error, returns the error,
92 otherwise returns false.
93
94 =cut
95
96 # the insert method can be inherited from FS::Record
97
98 =item delete
99
100 Delete this record from the database.
101
102 =cut
103
104 # the delete method can be inherited from FS::Record
105
106 =item replace OLD_RECORD
107
108 Replaces the OLD_RECORD with this one in the database.  If there is an error,
109 returns the error, otherwise returns false.
110
111 =cut
112
113 # the replace method can be inherited from FS::Record
114
115 =item check
116
117 Checks all fields to make sure this is a valid legacy invoice.  If there is
118 an error, returns the error, otherwise returns false.  Called by the insert
119 and replace methods.
120
121 =cut
122
123 # the check method should currently be supplied - FS::Record contains some
124 # data checking routines
125
126 sub check {
127   my $self = shift;
128
129   my $error = 
130     $self->ut_numbern('legacyinvnum')
131     || $self->ut_textn('legacyid')
132     || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
133     || $self->ut_number('_date')
134     || $self->ut_money('charged')
135     || $self->ut_anything('content_pdf')
136     || $self->ut_anything('content_html')
137   ;
138   return $error if $error;
139
140   $self->SUPER::check;
141 }
142
143 =item cust_main
144
145 Returns the customer (see L<FS::cust_main>) for this invoice.
146
147 =cut
148
149 sub cust_main {
150   my $self = shift;
151   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
152 }
153
154 =back
155
156 =head1 BUGS
157
158 =head1 SEE ALSO
159
160 L<FS::Record>, schema.html from the base documentation.
161
162 =cut
163
164 1;
165