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