add ut_snumber, fix replacement of records with empty values in non-primary-keyed...
[freeside.git] / FS / FS / svc_external.pm
1 package FS::svc_external;
2
3 use strict;
4 use vars qw(@ISA); # $conf
5 use FS::UID;
6 #use FS::Record qw( qsearch qsearchs dbh);
7 use FS::svc_Common;
8
9 @ISA = qw( FS::svc_Common );
10
11 #FS::UID::install_callback( sub {
12 #  $conf = new FS::Conf;
13 #};
14
15 =head1 NAME
16
17 FS::svc_external - Object methods for svc_external records
18
19 =head1 SYNOPSIS
20
21   use FS::svc_external;
22
23   $record = new FS::svc_external \%hash;
24   $record = new FS::svc_external { 'column' => 'value' };
25
26   $error = $record->insert;
27
28   $error = $new_record->replace($old_record);
29
30   $error = $record->delete;
31
32   $error = $record->check;
33
34   $error = $record->suspend;
35
36   $error = $record->unsuspend;
37
38   $error = $record->cancel;
39
40 =head1 DESCRIPTION
41
42 An FS::svc_external object represents a externally tracked service.
43 FS::svc_external inherits from FS::svc_Common.  The following fields are
44 currently supported:
45
46 =over 4
47
48 =item svcnum - primary key
49
50 =item id - unique number of external record
51
52 =item title - for invoice line items
53
54 =back
55
56 =head1 METHODS
57
58 =over 4
59
60 =item new HASHREF
61
62 Creates a new external service.  To add the external service to the database,
63 see L<"insert">.  
64
65 Note that this stores the hash reference, not a distinct copy of the hash it
66 points to.  You can ask the object for a copy with the I<hash> method.
67
68 =cut
69
70 sub table { 'svc_external'; }
71
72 =item insert
73
74 Adds this external service to the database.  If there is an error, returns the
75 error, otherwise returns false.
76
77 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
78 defined.  An FS::cust_svc record will be created and inserted.
79
80 =cut
81
82 sub insert {
83   my $self = shift;
84   my $error;
85
86   $error = $self->SUPER::insert;
87   return $error if $error;
88
89   '';
90 }
91
92 =item delete
93
94 Delete this record from the database.
95
96 =cut
97
98 sub delete {
99   my $self = shift;
100   my $error;
101
102   $error = $self->SUPER::delete;
103   return $error if $error;
104
105   '';
106 }
107
108
109 =item replace OLD_RECORD
110
111 Replaces the OLD_RECORD with this one in the database.  If there is an error,
112 returns the error, otherwise returns false.
113
114 =cut
115
116 sub replace {
117   my ( $new, $old ) = ( shift, shift );
118   my $error;
119
120   $error = $new->SUPER::replace($old);
121   return $error if $error;
122
123   '';
124 }
125
126 =item suspend
127
128 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
129
130 =item unsuspend
131
132 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
133
134 =item cancel
135
136 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
137
138 =item check
139
140 Checks all fields to make sure this is a valid external service.  If there is
141 an error, returns the error, otherwise returns false.  Called by the insert
142 and repalce methods.
143
144 =cut
145
146 sub check {
147   my $self = shift;
148
149   my $x = $self->setfixed;
150   return $x unless ref($x);
151   my $part_svc = $x;
152
153   my $error = 
154     $self->ut_numbern('svcnum')
155     || $self->ut_number('id')
156     || $self->ut_textn('title')
157   ;
158
159   $self->SUPER::check;
160 }
161
162 =back
163
164 =head1 BUGS
165
166 =head1 SEE ALSO
167
168 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
169 L<FS::cust_pkg>, schema.html from the base documentation.
170
171 =cut
172
173 1;
174