f4b4595aefe61ee4b12680d4660919fcf5b17ced
[freeside.git] / site_perl / cust_main_county.pm
1 package FS::cust_main_county;
2
3 use strict;
4 use vars qw(@ISA @EXPORT_OK);
5 use Exporter;
6 use FS::Record qw(fields hfields qsearch qsearchs);
7
8 @ISA = qw(FS::Record Exporter);
9 @EXPORT_OK = qw(hfields);
10
11 =head1 NAME
12
13 FS::cust_main_county - Object methods for cust_main_county objects
14
15 =head1 SYNOPSIS
16
17   use FS::cust_main_county;
18
19   $record = create FS::cust_main_county \%hash;
20   $record = create FS::cust_main_county { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::cust_main_county object represents a tax rate, defined by locale.
33 FS::cust_main_county inherits from FS::Record.  The following fields are
34 currently supported:
35
36 =over 4
37
38 =item taxnum - primary key (assigned automatically for new tax rates)
39
40 =item state
41
42 =item county
43
44 =item tax - percentage
45
46 =back
47
48 =head1 METHODS
49
50 =over 4
51
52 =item create HASHREF
53
54 Creates a new tax rate.  To add the tax rate to the database, see L<"insert">.
55
56 =cut
57
58 sub create {
59   my($proto,$hashref)=@_;
60
61   #now in FS::Record::new
62   #my($field);
63   #foreach $field (fields('cust_main_county')) {
64   #  $hashref->{$field}='' unless defined $hashref->{$field};
65   #}
66
67   $proto->new('cust_main_county',$hashref);
68 }
69
70 =item insert
71
72 Adds this tax rate to the database.  If there is an error, returns the error,
73 otherwise returns false.
74
75 =cut
76
77 sub insert {
78   my($self)=@_;
79
80   $self->check or
81   $self->add;
82 }
83
84 =item delete
85
86 Deletes this tax rate from the database.  If there is an error, returns the
87 error, otherwise returns false.
88
89 =cut
90
91 sub delete {
92   my($self)=@_;
93
94   $self->del;
95 }
96
97 =item replace OLD_RECORD
98
99 Replaces the OLD_RECORD with this one in the database.  If there is an error,
100 returns the error, otherwise returns false.
101
102 =cut
103
104 sub replace {
105   my($new,$old)=@_;
106   return "(Old) Not a cust_main_county record!"
107     unless $old->table eq "cust_main_county";
108   return "Can't change taxnum!"
109     unless $old->getfield('taxnum') eq $new->getfield('taxnum');
110   $new->check or
111   $new->rep($old);
112 }
113
114 =item check
115
116 Checks all fields to make sure this is a valid tax rate.  If there is an error,
117 returns the error, otherwise returns false.  Called by the insert and replace
118 methods.
119
120 =cut
121
122 sub check {
123   my($self)=@_;
124   return "Not a cust_main_county record!"
125     unless $self->table eq "cust_main_county";
126   my($recref) = $self->hashref;
127
128   $self->ut_numbern('taxnum')
129     or $self->ut_text('state')
130     or $self->ut_textn('county')
131     or $self->ut_float('tax')
132   ;
133
134 }
135
136 =back
137
138 =head1 BUGS
139
140 It doesn't properly override FS::Record yet.
141
142 A country field (and possibly a currency field) should be added.
143
144 =head1 SEE ALSO
145
146 L<FS::Record>, L<FS::cust_main>, L<FS::cust_bill>, schema.html from the base
147 documentation.
148
149 =head1 HISTORY
150
151 ivan@voicenet.com 97-dec-16
152
153 Changed check for 'tax' to use the new ut_float subroutine
154         bmccane@maxbaud.net     98-apr-3
155
156 pod ivan@sisd.com 98-sep-21
157
158 =cut
159
160 1;
161