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