new package def editor
[freeside.git] / FS / FS / part_pkg_link.pm
1 package FS::part_pkg_link;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::part_pkg;
7
8 @ISA = qw(FS::Record);
9
10 =head1 NAME
11
12 FS::part_pkg_link - Object methods for part_pkg_link records
13
14 =head1 SYNOPSIS
15
16   use FS::part_pkg_link;
17
18   $record = new FS::part_pkg_link \%hash;
19   $record = new FS::part_pkg_link { '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::part_pkg_link object represents an link from one package definition to
32 another.  FS::part_pkg_link inherits from FS::Record.  The following fields are
33 currently supported:
34
35 =over 4
36
37 =item pkglinknum
38
39 primary key
40
41 =item src_pkgpart
42
43 Source package (see L<FS::part_pkg>)
44
45 =item dst_pkgpart
46
47 Destination package (see L<FS::part_pkg>)
48
49 =item link_type
50
51 Link type - currently, "bill" (source package bills a line item from target
52 package), or "svc" (source package includes services from target package).
53
54 =back
55
56 =head1 METHODS
57
58 =over 4
59
60 =item new HASHREF
61
62 Creates a new link.  To add the link to the database, see L<"insert">.
63
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to.  You can ask the object for a copy with the I<hash> method.
66
67 =cut
68
69 # the new method can be inherited from FS::Record, if a table method is defined
70
71 sub table { 'part_pkg_link'; }
72
73 =item insert
74
75 Adds this record to the database.  If there is an error, returns the error,
76 otherwise returns false.
77
78 =cut
79
80 # the insert method can be inherited from FS::Record
81
82 =item delete
83
84 Delete this record from the database.
85
86 =cut
87
88 # the delete method can be inherited from FS::Record
89
90 =item replace OLD_RECORD
91
92 Replaces the OLD_RECORD with this one in the database.  If there is an error,
93 returns the error, otherwise returns false.
94
95 =cut
96
97 # the replace method can be inherited from FS::Record
98
99 =item check
100
101 Checks all fields to make sure this is a valid link.  If there is
102 an error, returns the error, otherwise returns false.  Called by the insert
103 and replace methods.
104
105 =cut
106
107 # the check method should currently be supplied - FS::Record contains some
108 # data checking routines
109
110 sub check {
111   my $self = shift;
112
113   my $error = 
114     $self->ut_numbern('pkglinknum')
115     || $self->ut_foreign_key('src_pkgpart', 'part_pkg', 'pkgpart')
116     || $self->ut_foreign_key('dst_pkgpart', 'part_pkg', 'pkgpart')
117     || $self->ut_text('link_type', [ 'bill', 'svc' ] )
118   ;
119   return $error if $error;
120
121   $self->SUPER::check;
122 }
123
124 =item src_pkg
125
126 Returns the source part_pkg object (see L<FS::part_pkg>).
127
128 =cut
129
130 sub src_pkg {
131   my $self = shift;
132   qsearchs('part_pkg', { 'pkgpart' => $self->src_pkgpart } );
133 }
134
135 =item dst_pkg
136
137 Returns the source part_pkg object (see L<FS::part_pkg>).
138
139 =cut
140
141 sub dst_pkg {
142   my $self = shift;
143   qsearchs('part_pkg', { 'pkgpart' => $self->dst_pkgpart } );
144 }
145
146 =back
147
148 =head1 BUGS
149
150 =head1 SEE ALSO
151
152 L<FS::Record>, schema.html from the base documentation.
153
154 =cut
155
156 1;
157