Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / cust_main_exemption.pm
1 package FS::cust_main_exemption;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::Conf;
7 use FS::cust_main;
8
9 =head1 NAME
10
11 FS::cust_main_exemption - Object methods for cust_main_exemption records
12
13 =head1 SYNOPSIS
14
15   use FS::cust_main_exemption;
16
17   $record = new FS::cust_main_exemption \%hash;
18   $record = new FS::cust_main_exemption { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::cust_main_exemption object represents a customer tax exemption from a
31 specific tax name (prefix).  FS::cust_main_exemption inherits from
32 FS::Record.  The following fields are currently supported:
33
34 =over 4
35
36 =item exemptionnum
37
38 Primary key
39
40 =item custnum
41
42 Customer (see L<FS::cust_main>)
43
44 =item taxname
45
46 taxname
47
48 =item exempt_number
49
50 Exemption number
51
52 =back
53
54 =head1 METHODS
55
56 =over 4
57
58 =item new HASHREF
59
60 Creates a new record.  To add the record to the database, see L<"insert">.
61
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to.  You can ask the object for a copy with the I<hash> method.
64
65 =cut
66
67 # the new method can be inherited from FS::Record, if a table method is defined
68
69 sub table { 'cust_main_exemption'; }
70
71 =item insert
72
73 Adds this record to the database.  If there is an error, returns the error,
74 otherwise returns false.
75
76 =cut
77
78 # the insert method can be inherited from FS::Record
79
80 =item delete
81
82 Delete this record from the database.
83
84 =cut
85
86 # the delete method can be inherited from FS::Record
87
88 =item replace OLD_RECORD
89
90 Replaces the OLD_RECORD with this one in the database.  If there is an error,
91 returns the error, otherwise returns false.
92
93 =cut
94
95 # the replace method can be inherited from FS::Record
96
97 =item check
98
99 Checks all fields to make sure this is a valid record.  If there is
100 an error, returns the error, otherwise returns false.  Called by the insert
101 and replace methods.
102
103 =cut
104
105 # the check method should currently be supplied - FS::Record contains some
106 # data checking routines
107
108 sub check {
109   my $self = shift;
110
111   my $error = 
112     $self->ut_numbern('exemptionnum')
113     || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
114     || $self->ut_text('taxname')
115     || $self->ut_textn('exempt_number')
116   ;
117   return $error if $error;
118
119   my $conf = new FS::Conf;
120   if ( ! $self->exempt_number && $conf->exists('tax-cust_exempt-groups-require_individual_nums') ) {
121     return 'Tax exemption number required for '. $self->taxname. ' exemption';
122   }
123
124   $self->SUPER::check;
125 }
126
127 =back
128
129 =head1 BUGS
130
131 =head1 SEE ALSO
132
133 L<FS::cust_main>, L<FS::Record>, schema.html from the base documentation.
134
135 =cut
136
137 1;
138