5 use FS::Record qw( qsearch );
8 @ISA = qw( FS::Record );
12 FS::part_pkg - Object methods for part_pkg objects
18 $record = new FS::part_pkg \%hash
19 $record = new FS::part_pkg { 'column' => 'value' };
21 $custom_record = $template_record->clone;
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
31 @pkg_svc = $record->pkg_svc;
33 $svcnum = $record->svcpart;
34 $svcnum = $record->svcpart( 'svc_acct' );
38 An FS::part_pkg object represents a billing item definition. FS::part_pkg
39 inherits from FS::Record. The following fields are currently supported:
43 =item pkgpart - primary key (assigned automatically for new billing item definitions)
45 =item pkg - Text name of this billing item definition (customer-viewable)
47 =item comment - Text name of this billing item definition (non-customer-viewable)
49 =item setup - Setup fee expression
51 =item freq - Frequency of recurring fee
53 =item recur - Recurring fee expression
55 =item plan - Price plan
57 =item plandata - Price plan data
61 setup and recur are evaluated as Safe perl expressions. You can use numbers
62 just as you would normally. More advanced semantics are not yet defined.
70 Creates a new billing item definition. To add the billing item definition to
71 the database, see L<"insert">.
75 sub table { 'part_pkg'; }
79 An alternate constructor. Creates a new billing item definition by duplicating
80 an existing definition. A new pkgpart is assigned and `(CUSTOM) ' is prepended
81 to the comment field. To add the billing item definition to the database, see
88 my $class = ref($self);
89 my %hash = $self->hash;
90 $hash{'pkgpart'} = '';
91 $hash{'comment'} = "(CUSTOM) ". $hash{'comment'}
92 unless $hash{'comment'} =~ /^\(CUSTOM\) /;
93 #new FS::part_pkg ( \%hash ); # ?
94 new $class ( \%hash ); # ?
99 Adds this billing item definition to the database. If there is an error,
100 returns the error, otherwise returns false.
104 Currently unimplemented.
109 return "Can't (yet?) delete package definitions.";
110 # check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
113 =item replace OLD_RECORD
115 Replaces OLD_RECORD with this one in the database. If there is an error,
116 returns the error, otherwise returns false.
120 Checks all fields to make sure this is a valid billing item definition. If
121 there is an error, returns the error, otherwise returns false. Called by the
122 insert and replace methods.
129 $self->ut_numbern('pkgpart')
130 || $self->ut_text('pkg')
131 || $self->ut_text('comment')
132 || $self->ut_anything('setup')
133 || $self->ut_number('freq')
134 || $self->ut_anything('recur')
135 || $self->ut_alphan('plan')
136 || $self->ut_anything('plandata')
142 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
143 definition (with non-zero quantity).
149 grep { $_->quantity } qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
152 =item svcpart [ SVCDB ]
154 Returns the svcpart of a single service definition (see L<FS::part_svc>)
155 associated with this billing item definition (see L<FS::pkg_svc>). Returns
156 false if there not exactly one service definition with quantity 1, or if
157 SVCDB is specified and does not match the svcdb of the service definition,
164 my @pkg_svc = $self->pkg_svc;
165 return '' if scalar(@pkg_svc) != 1
166 || $pkg_svc[0]->quantity != 1
167 || ( $svcdb && $pkg_svc[0]->part_svc->svcdb ne $svcdb );
168 $pkg_svc[0]->svcpart;
175 $Id: part_pkg.pm,v 1.3 2001-10-15 10:42:28 ivan Exp $
179 The delete method is unimplemented.
181 setup and recur semantics are not yet defined (and are implemented in
182 FS::cust_bill. hmm.).
186 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
187 schema.html from the base documentation.