5 use FS::Record qw( qsearchs );
9 @ISA = qw( FS::Record );
13 FS::pkg_svc - Object methods for pkg_svc records
19 $record = new FS::pkg_svc \%hash;
20 $record = new FS::pkg_svc { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
30 $part_pkg = $record->part_pkg;
32 $part_svc = $record->part_svc;
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:
42 =item pkgpart - Billing item definition (see L<FS::part_pkg>)
44 =item svcpart - Service definition (see L<FS::part_svc>)
46 =item quantity - Quantity of this service definition that this billing item
57 Create a new record. To add the record to the database, see L<"insert">.
61 sub table { 'pkg_svc'; }
65 Adds this record to the database. If there is an error, returns the error,
66 otherwise returns false.
70 Deletes this record from the database. If this svcpart is also the default svcpart,
71 we set part_pkg.def_svcpart to NULL. If there is an error, returns the error,
72 otherwise returns false.
76 my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $self->pkgpart } );
78 # Should this be wrapped in a transaction?
79 if ( $part_pkg->def_svcpart == $self->svcpart ) {
80 my $new = new FS::part_pkg $part_pkg->hash;
81 $new->def_svcpart = 0;
82 my $error = $new->replace($part_pkg);
83 return $error if $error;
89 =item replace OLD_RECORD
91 Replaces OLD_RECORD with this one in the database. If there is an error,
92 returns the error, otherwise returns false.
97 my ( $new, $old ) = ( shift, shift );
99 return "Can't change pkgpart!" if $old->pkgpart != $new->pkgpart;
100 return "Can't change svcpart!" if $old->svcpart != $new->svcpart;
102 my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $new->pkgpart } );
104 # Should this be wrapped in a transaction?
105 if ( ($part_pkg->def_svcpart == $new->svcpart) && ($new->quantity == 0) ) {
106 my $new_part_pkg = new FS::part_pkg $part_pkg->hash;
107 $new_part_pkg->def_svcpart = 0;
108 my $error = $new_part_pkg->replace($part_pkg);
109 return $error if $error;
112 $new->SUPER::replace($old);
117 Checks all fields to make sure this is a valid record. If there is an error,
118 returns the error, otherwise returns false. Called by the insert and replace
128 $self->ut_number('pkgpart')
129 || $self->ut_number('svcpart')
130 || $self->ut_number('quantity')
132 return $error if $error;
134 return "Unknown pkgpart!" unless $self->part_pkg;
135 return "Unknown svcpart!" unless $self->part_svc;
142 Returns the FS::part_pkg object (see L<FS::part_pkg>).
148 qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
153 Returns the FS::part_svc object (see L<FS::part_svc>).
159 qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
166 $Id: pkg_svc.pm,v 1.2 2002-06-08 07:48:37 khoff Exp $
172 L<FS::Record>, L<FS::part_pkg>, L<FS::part_svc>, schema.html from the base