don't re-my var, quiet warning
[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 =item primary_svc - primary flag, empty or 'Y'
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Create a new record.  To add the record to the database, see L<"insert">.
60
61 =cut
62
63 sub table { 'pkg_svc'; }
64
65 =item insert
66
67 Adds this record to the database.  If there is an error, returns the error,
68 otherwise returns false.
69
70 =item delete
71
72 Deletes this record from the database.  If there is an error, returns the
73 error, otherwise returns false.
74
75 =item replace OLD_RECORD
76
77 Replaces OLD_RECORD with this one in the database.  If there is an error,
78 returns the error, otherwise returns false.
79
80 =cut
81
82 sub replace {
83   my ( $new, $old ) = ( shift, shift );
84
85   return "Can't change pkgpart!" if $old->pkgpart != $new->pkgpart;
86   return "Can't change svcpart!" if $old->svcpart != $new->svcpart;
87
88   $new->SUPER::replace($old);
89 }
90
91 =item check
92
93 Checks all fields to make sure this is a valid record.  If there is an error,
94 returns the error, otherwise returns false.  Called by the insert and replace
95 methods.
96
97 =cut
98
99 sub check {
100   my $self = shift;
101
102   my $error;
103   $error =
104     $self->ut_number('pkgpart')
105     || $self->ut_number('svcpart')
106     || $self->ut_number('quantity')
107   ;
108   return $error if $error;
109
110   return "Unknown pkgpart!" unless $self->part_pkg;
111   return "Unknown svcpart!" unless $self->part_svc;
112
113   if ( $self->dbdef_table->column('primary_svc') ) {
114     $error = $self->ut_enum('primary_svc', [ '', 'Y' ] );
115     return $error if $error;
116   }
117
118   $self->SUPER::check;
119 }
120
121 =item part_pkg
122
123 Returns the FS::part_pkg object (see L<FS::part_pkg>).
124
125 =cut
126
127 sub part_pkg {
128   my $self = shift;
129   qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
130 }
131
132 =item part_svc
133
134 Returns the FS::part_svc object (see L<FS::part_svc>).
135
136 =cut
137
138 sub part_svc {
139   my $self = shift;
140   qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
141 }
142
143 =back
144
145 =head1 BUGS
146
147 =head1 SEE ALSO
148
149 L<FS::Record>, L<FS::part_pkg>, L<FS::part_svc>, schema.html from the base
150 documentation.
151
152 =cut
153
154 1;
155