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