Rollback part_pkg.def_svcpart changes.
[freeside.git] / FS / FS / pkg_svc.pm
1 package FS::pkg_svc;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::part_pkg;
7 use FS::part_svc;
8
9 @ISA = qw( FS::Record );
10
11 =head1 NAME
12
13 FS::pkg_svc - Object methods for pkg_svc records
14
15 =head1 SYNOPSIS
16
17   use FS::pkg_svc;
18
19   $record = new FS::pkg_svc \%hash;
20   $record = new FS::pkg_svc { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30   $part_pkg = $record->part_pkg;
31
32   $part_svc = $record->part_svc;
33
34 =head1 DESCRIPTION
35
36 An FS::pkg_svc record links a billing item definition (see L<FS::part_pkg>) to
37 a service definition (see L<FS::part_svc>).  FS::pkg_svc inherits from
38 FS::Record.  The following fields are currently supported:
39
40 =over 4
41
42 =item pkgpart - Billing item definition (see L<FS::part_pkg>)
43
44 =item svcpart - Service definition (see L<FS::part_svc>)
45
46 =item quantity - Quantity of this service definition that this billing item
47 definition includes
48
49 =back
50
51 =head1 METHODS
52
53 =over 4
54
55 =item new HASHREF
56
57 Create a new record.  To add the record to the database, see L<"insert">.
58
59 =cut
60
61 sub table { 'pkg_svc'; }
62
63 =item insert
64
65 Adds this record to the database.  If there is an error, returns the error,
66 otherwise returns false.
67
68 =item delete
69
70 Deletes this record from the database.  If there is an error, returns the
71 error, otherwise returns false.
72
73 =item replace OLD_RECORD
74
75 Replaces OLD_RECORD with this one in the database.  If there is an error,
76 returns the error, otherwise returns false.
77
78 =cut
79
80 sub replace {
81   my ( $new, $old ) = ( shift, shift );
82
83   return "Can't change pkgpart!" if $old->pkgpart != $new->pkgpart;
84   return "Can't change svcpart!" if $old->svcpart != $new->svcpart;
85
86   $new->SUPER::replace($old);
87 }
88
89 =item check
90
91 Checks all fields to make sure this is a valid record.  If there is an error,
92 returns the error, otherwise returns false.  Called by the insert and replace
93 methods.
94
95 =cut
96
97 sub check {
98   my $self = shift;
99
100   my $error;
101   $error =
102     $self->ut_number('pkgpart')
103     || $self->ut_number('svcpart')
104     || $self->ut_number('quantity')
105   ;
106   return $error if $error;
107
108   return "Unknown pkgpart!" unless $self->part_pkg;
109   return "Unknown svcpart!" unless $self->part_svc;
110
111   ''; #no error
112 }
113
114 =item part_pkg
115
116 Returns the FS::part_pkg object (see L<FS::part_pkg>).
117
118 =cut
119
120 sub part_pkg {
121   my $self = shift;
122   qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
123 }
124
125 =item part_svc
126
127 Returns the FS::part_svc object (see L<FS::part_svc>).
128
129 =cut
130
131 sub part_svc {
132   my $self = shift;
133   qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
134 }
135
136 =back
137
138 =head1 VERSION
139
140 $Id: pkg_svc.pm,v 1.3 2002-06-10 01:39:50 khoff Exp $
141
142 =head1 BUGS
143
144 =head1 SEE ALSO
145
146 L<FS::Record>, L<FS::part_pkg>, L<FS::part_svc>, schema.html from the base
147 documentation.
148
149 =cut
150
151 1;
152