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