fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / export_nas.pm
1 package FS::export_nas;
2
3 use strict;
4 use vars qw($noexport_hack);
5 use base qw( FS::Record );
6 use FS::Record qw( qsearch qsearchs );
7
8 $noexport_hack = '';
9
10 =head1 NAME
11
12 FS::export_nas - Object methods for export_nas records
13
14 =head1 SYNOPSIS
15
16   use FS::export_nas;
17
18   $record = new FS::export_nas \%hash;
19   $record = new FS::export_nas { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::export_nas object links RADIUS exports (in the part_export table)
32 to RADIUS clients (in the nas table).  FS::export_nas inherits from
33 FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item exportnasnum
38
39 primary key
40
41 =item exportnum
42
43 exportnum
44
45 =item nasnum
46
47 nasnum
48
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 { 'export_nas'; }
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 sub insert {
77   my $self = shift;
78   $self->SUPER::insert || 
79   ($noexport_hack ? '' : $self->part_export->export_nas_insert($self->nas));
80 }
81
82 =item delete
83
84 Delete this record from the database.
85
86 =cut
87
88 sub delete {
89   my $self = shift;
90   ($noexport_hack ? '' : $self->part_export->export_nas_delete($self->nas))
91   || $self->SUPER::delete;
92 }
93
94 =item replace OLD_RECORD
95
96 Unavailable.  Delete the record and create a new one.
97
98 =cut
99
100 sub replace {
101   die "replace not implemented for export_nas records";
102 }
103
104 =item check
105
106 Checks all fields to make sure this is a valid record.  If there is
107 an error, returns the error, otherwise returns false.  Called by the insert
108 and replace methods.
109
110 =cut
111
112 # the check method should currently be supplied - FS::Record contains some
113 # data checking routines
114
115 sub check {
116   my $self = shift;
117
118   my $error = 
119     $self->ut_numbern('exportnasnum')
120     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
121     || $self->ut_foreign_key('nasnum', 'nas', 'nasnum')
122   ;
123   return $error if $error;
124
125   $self->SUPER::check;
126 }
127
128 sub part_export {
129   my $self = shift;
130   qsearchs('part_export', { 'exportnum' => $self->exportnum });
131 }
132
133 sub nas {
134   my $self = shift;
135   qsearchs('nas', { 'nasnum' => $self->nasnum });
136 }
137
138 =back
139
140 =head1 BUGS
141
142 =head1 SEE ALSO
143
144 L<FS::Record>, schema.html from the base documentation.
145
146 =cut
147
148 1;
149