9c81406ae32276b10c3f9dcc29b7ebe63bb21c2f
[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 country
45
46 =item tax - percentage
47
48 =back
49
50 =head1 METHODS
51
52 =over 4
53
54 =item create HASHREF
55
56 Creates a new tax rate.  To add the tax rate to the database, see L<"insert">.
57
58 =cut
59
60 sub create {
61   my($proto,$hashref)=@_;
62
63   #now in FS::Record::new
64   #my($field);
65   #foreach $field (fields('cust_main_county')) {
66   #  $hashref->{$field}='' unless defined $hashref->{$field};
67   #}
68
69   $proto->new('cust_main_county',$hashref);
70 }
71
72 =item insert
73
74 Adds this tax rate to the database.  If there is an error, returns the error,
75 otherwise returns false.
76
77 =cut
78
79 sub insert {
80   my($self)=@_;
81
82   $self->check or
83   $self->add;
84 }
85
86 =item delete
87
88 Deletes this tax rate from the database.  If there is an error, returns the
89 error, otherwise returns false.
90
91 =cut
92
93 sub delete {
94   my($self)=@_;
95
96   $self->del;
97 }
98
99 =item replace OLD_RECORD
100
101 Replaces the OLD_RECORD with this one in the database.  If there is an error,
102 returns the error, otherwise returns false.
103
104 =cut
105
106 sub replace {
107   my($new,$old)=@_;
108   return "(Old) Not a cust_main_county record!"
109     unless $old->table eq "cust_main_county";
110   return "Can't change taxnum!"
111     unless $old->getfield('taxnum') eq $new->getfield('taxnum');
112   $new->check or
113   $new->rep($old);
114 }
115
116 =item check
117
118 Checks all fields to make sure this is a valid tax rate.  If there is an error,
119 returns the error, otherwise returns false.  Called by the insert and replace
120 methods.
121
122 =cut
123
124 sub check {
125   my($self)=@_;
126   return "Not a cust_main_county record!"
127     unless $self->table eq "cust_main_county";
128   my($recref) = $self->hashref;
129
130   $self->ut_numbern('taxnum')
131     or $self->ut_textn('state')
132     or $self->ut_textn('county')
133     or $self->ut_float('tax')
134   ;
135
136 }
137
138 =back
139
140 =head1 VERSION
141
142 $Id: cust_main_county.pm,v 1.2 1998-11-18 09:01:43 ivan Exp $
143
144 =head1 BUGS
145
146 It doesn't properly override FS::Record yet.
147
148 =head1 SEE ALSO
149
150 L<FS::Record>, L<FS::cust_main>, L<FS::cust_bill>, schema.html from the base
151 documentation.
152
153 =head1 HISTORY
154
155 ivan@voicenet.com 97-dec-16
156
157 Changed check for 'tax' to use the new ut_float subroutine
158         bmccane@maxbaud.net     98-apr-3
159
160 pod ivan@sisd.com 98-sep-21
161
162 $Log: cust_main_county.pm,v $
163 Revision 1.2  1998-11-18 09:01:43  ivan
164 i18n! i18n!
165
166
167 =cut
168
169 1;
170