fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / cust_tax_exempt.pm
1 package FS::cust_tax_exempt;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::cust_main_Mixin;
7 use FS::cust_main;
8 use FS::cust_main_county;
9
10 @ISA = qw( FS::cust_main_Mixin FS::Record );
11
12 =head1 NAME
13
14 FS::cust_tax_exempt - Object methods for cust_tax_exempt records
15
16 =head1 SYNOPSIS
17
18   use FS::cust_tax_exempt;
19
20   $record = new FS::cust_tax_exempt \%hash;
21   $record = new FS::cust_tax_exempt { 'column' => 'value' };
22
23   $error = $record->insert;
24
25   $error = $new_record->replace($old_record);
26
27   $error = $record->delete;
28
29   $error = $record->check;
30
31 =head1 DESCRIPTION
32
33 An FS::cust_tax_exempt object represents a record of an old-style customer tax
34 exemption.  Currently this is only used for "texas tax".  FS::cust_tax_exempt
35 inherits from FS::Record.  The following fields are currently supported:
36
37 =over 4
38
39 =item exemptnum - primary key
40
41 =item custnum - customer (see L<FS::cust_main>)
42
43 =item taxnum - tax rate (see L<FS::cust_main_county>)
44
45 =item year
46
47 =item month
48
49 =item amount
50
51 =back
52
53 =head1 NOTE
54
55 Old-style customer tax exemptions are only useful for legacy migrations - if
56 you are looking for current customer tax exemption data see
57 L<FS::cust_tax_exempt_pkg>.
58
59 =head1 METHODS
60
61 =over 4
62
63 =item new HASHREF
64
65 Creates a new exemption record.  To add the example to the database, see
66 L<"insert">.
67
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to.  You can ask the object for a copy with the I<hash> method.
70
71 =cut
72
73 # the new method can be inherited from FS::Record, if a table method is defined
74
75 sub table { 'cust_tax_exempt'; }
76
77 =item insert
78
79 Adds this record to the database.  If there is an error, returns the error,
80 otherwise returns false.
81
82 =cut
83
84 # the insert method can be inherited from FS::Record
85
86 =item delete
87
88 Delete this record from the database.
89
90 =cut
91
92 # the delete method can be inherited from FS::Record
93
94 =item replace OLD_RECORD
95
96 Replaces the OLD_RECORD with this one in the database.  If there is an error,
97 returns the error, otherwise returns false.
98
99 =cut
100
101 # the replace method can be inherited from FS::Record
102
103 =item check
104
105 Checks all fields to make sure this is a valid example.  If there is
106 an error, returns the error, otherwise returns false.  Called by the insert
107 and replace methods.
108
109 =cut
110
111 # the check method should currently be supplied - FS::Record contains some
112 # data checking routines
113
114 sub check {
115   my $self = shift;
116
117   $self->ut_numbern('exemptnum')
118     || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
119     || $self->ut_foreign_key('taxnum', 'cust_main_county', 'taxnum')
120     || $self->ut_number('year') #check better
121     || $self->ut_number('month') #check better
122     || $self->ut_money('amount')
123     || $self->SUPER::check
124   ;
125 }
126
127 =item cust_main_county
128
129 Returns the FS::cust_main_county object associated with this tax exemption.
130
131 =cut
132
133 sub cust_main_county {
134   my $self = shift;
135   qsearchs( 'cust_main_county', { 'taxnum' => $self->taxnum } );
136 }
137
138 =back
139
140 =head1 BUGS
141
142 Texas tax is a royal pain in the ass.
143
144 =head1 SEE ALSO
145
146 L<FS::cust_main_county>, L<FS::cust_main>, L<FS::Record>, schema.html from the
147 base documentation.
148
149 =cut
150
151 1;
152