1 package FS::part_pkg_usage;
4 use base qw( FS::m2m_Common FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use Scalar::Util qw(blessed);
10 FS::part_pkg_usage - Object methods for part_pkg_usage records
14 use FS::part_pkg_usage;
16 $record = new FS::part_pkg_usage \%hash;
17 $record = new FS::part_pkg_usage { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::part_pkg_usage object represents a stock of usage minutes (generally
30 for voice services) included in a package definition. FS::part_pkg_usage
31 inherits from FS::Record. The following fields are currently supported:
35 =item pkgusagepart - primary key
37 =item pkgpart - the package definition (L<FS::part_pkg>)
39 =item minutes - the number of minutes included per billing cycle
41 =item priority - the relative order in which to use this stock of minutes.
43 =item shared - 'Y' to allow these minutes to be shared with other packages
44 belonging to the same customer. Otherwise, only usage allocated to this
45 package will use this stock of minutes.
47 =item rollover - 'Y' to allow unused minutes to carry over between billing
48 cycles. Otherwise, the available minutes will reset to the value of the
49 "minutes" field upon billing.
51 =item description - a text description of this stock of minutes
65 CLASSES can be an array or hash of usage classnums (see L<FS::usage_class>)
66 to link to this record.
72 sub table { 'part_pkg_usage'; }
76 my $opt = ref($_[0]) eq 'HASH' ? shift : { @_ };
79 || $self->process_m2m( 'link_table' => 'part_pkg_usage_class',
80 'target_table' => 'usage_class',
87 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
90 my $opt = ref($_[0]) eq 'HASH' ? $_[0] : { @_ };
91 $self->SUPER::replace($old)
92 || $self->process_m2m( 'link_table' => 'part_pkg_usage_class',
93 'target_table' => 'usage_class',
100 $self->process_m2m( 'link_table' => 'part_pkg_usage_class',
101 'target_table' => 'usage_class',
103 ) || $self->SUPER::delete;
108 Checks all fields to make sure this is a valid example. If there is
109 an error, returns the error, otherwise returns false. Called by the insert
118 $self->ut_numbern('pkgusagepart')
119 || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
120 || $self->ut_float('minutes')
121 || $self->ut_numbern('priority')
122 || $self->ut_flag('shared')
123 || $self->ut_flag('rollover')
124 || $self->ut_textn('description')
126 return $error if $error;
133 Returns the usage class numbers that are allowed to use minutes from this
140 if (!$self->get('classnums')) {
143 qsearch('part_pkg_usage_class', { 'pkgusagepart' => $self->pkgusagepart })
145 $self->set('classnums', $classnums);
147 @{ $self->get('classnums') };
154 L<FS::Record>, schema.html from the base documentation.