svc_broadband torrus, RT#14133
[freeside.git] / FS / FS / svc_port.pm
1 package FS::svc_port;
2 use base qw( FS::svc_Torrus_Mixin FS::svc_Common );
3
4 use strict;
5 #use vars qw( $DEBUG $me );
6
7 #$DEBUG = 0;
8 #$me = '[FS::svc_port]';
9
10 =head1 NAME
11
12 FS::svc_port - Object methods for svc_port records
13
14 =head1 SYNOPSIS
15
16   use FS::svc_port;
17
18   $record = new FS::svc_port \%hash;
19   $record = new FS::svc_port { '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   $error = $record->suspend;
30
31   $error = $record->unsuspend;
32
33   $error = $record->cancel;
34
35 =head1 DESCRIPTION
36
37 An FS::svc_port object represents a router port.  FS::table_name inherits from
38 FS::svc_Common.  The following fields are currently supported:
39
40 =over 4
41
42 =item svcnum - 
43
44 =item serviceid - Torrus serviceid (in srvexport and reportfields tables)
45
46 =back
47
48 =head1 METHODS
49
50 =over 4
51
52 =item new HASHREF
53
54 Creates a new port.  To add the port to the database, see L<"insert">.
55
56 Note that this stores the hash reference, not a distinct copy of the hash it
57 points to.  You can ask the object for a copy with the I<hash> method.
58
59 =cut
60
61 sub table { 'svc_port'; }
62
63 sub table_info {
64   {
65     'name' => 'Port',
66     #'name_plural' => 'Ports', #optional,
67     #'longname_plural' => 'Ports', #optional
68     #'sorts' => [ 'svcnum', 'serviceid' ], # optional sort field (or arrayref of sort fields, main first)
69     'sorts' => [ 'serviceid' ], # optional sort field (or arrayref of sort fields, main first)
70     'display_weight' => 75,
71     'cancel_weight'  => 10,
72     'fields' => {
73       'svcnum'    => 'Service',
74       'serviceid' => 'Torrus serviceid',
75     },
76   };
77 }
78
79 =item search_sql STRING
80
81 Class method which returns an SQL fragment to search for the given string.
82
83 =cut
84
85 #or something more complicated if necessary
86 sub search_sql {
87   my($class, $string) = @_;
88   $class->search_sql_field('serviceid', $string);
89 }
90
91 =item label
92
93 Returns a meaningful identifier for this port
94
95 =cut
96
97 sub label {
98   my $self = shift;
99   $self->serviceid; #or something more complicated if necessary
100 }
101
102 =item insert
103
104 Adds this record to the database.  If there is an error, returns the error,
105 otherwise returns false.
106
107 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
108 defined.  An FS::cust_svc record will be created and inserted.
109
110 =cut
111
112 sub insert {
113   my $self = shift;
114   my $error;
115
116   $error = $self->SUPER::insert;
117   return $error if $error;
118
119   '';
120 }
121
122 =item delete
123
124 Delete this record from the database.
125
126 =cut
127
128 sub delete {
129   my $self = shift;
130   my $error;
131
132   $error = $self->SUPER::delete;
133   return $error if $error;
134
135   '';
136 }
137
138
139 =item replace OLD_RECORD
140
141 Replaces the OLD_RECORD with this one in the database.  If there is an error,
142 returns the error, otherwise returns false.
143
144 =cut
145
146 sub replace {
147   my ( $new, $old ) = ( shift, shift );
148   my $error;
149
150   $error = $new->SUPER::replace($old);
151   return $error if $error;
152
153   '';
154 }
155
156 =item suspend
157
158 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
159
160 =item unsuspend
161
162 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
163
164 =item cancel
165
166 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
167
168 =item check
169
170 Checks all fields to make sure this is a valid port.  If there is
171 an error, returns the error, otherwise returns false.  Called by the insert
172 and repalce methods.
173
174 =cut
175
176 sub check {
177   my $self = shift;
178
179   my $x = $self->setfixed;
180   return $x unless ref($x);
181   my $part_svc = $x;
182
183   my $error = $self->ut_textn('serviceid'); #too lenient?
184   return $error if $error;
185
186   $self->SUPER::check;
187 }
188
189 =back
190
191 =head1 BUGS
192
193 =head1 SEE ALSO
194
195 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
196 L<FS::cust_pkg>, schema.html from the base documentation.
197
198 =cut
199
200 1;
201