1 package FS::part_pkg_usage;
2 use base qw( FS::m2m_Common FS::Record );
5 use Scalar::Util qw(blessed);
9 FS::part_pkg_usage - Object methods for part_pkg_usage records
13 use FS::part_pkg_usage;
15 $record = new FS::part_pkg_usage \%hash;
16 $record = new FS::part_pkg_usage { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::part_pkg_usage object represents a stock of usage minutes (generally
29 for voice services) included in a package definition. FS::part_pkg_usage
30 inherits from FS::Record. The following fields are currently supported:
34 =item pkgusagepart - primary key
36 =item pkgpart - the package definition (L<FS::part_pkg>)
38 =item minutes - the number of minutes included per billing cycle
40 =item priority - the relative order in which to use this stock of minutes.
42 =item shared - 'Y' to allow these minutes to be shared with other packages
43 belonging to the same customer. Otherwise, only usage allocated to this
44 package will use this stock of minutes.
46 =item rollover - 'Y' to allow unused minutes to carry over between billing
47 cycles. Otherwise, the available minutes will reset to the value of the
48 "minutes" field upon billing.
50 =item description - a text description of this stock of minutes
64 CLASSES can be an array or hash of usage classnums (see L<FS::usage_class>)
65 to link to this record.
71 sub table { 'part_pkg_usage'; }
75 my $opt = ref($_[0]) eq 'HASH' ? shift : { @_ };
78 || $self->process_m2m( 'link_table' => 'part_pkg_usage_class',
79 'target_table' => 'usage_class',
86 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
89 my $opt = ref($_[0]) eq 'HASH' ? $_[0] : { @_ };
90 $self->SUPER::replace($old)
91 || $self->process_m2m( 'link_table' => 'part_pkg_usage_class',
92 'target_table' => 'usage_class',
99 $self->process_m2m( 'link_table' => 'part_pkg_usage_class',
100 'target_table' => 'usage_class',
102 ) || $self->SUPER::delete;
107 Checks all fields to make sure this is a valid example. If there is
108 an error, returns the error, otherwise returns false. Called by the insert
117 $self->ut_numbern('pkgusagepart')
118 || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
119 || $self->ut_float('minutes')
120 || $self->ut_numbern('priority')
121 || $self->ut_flag('shared')
122 || $self->ut_flag('rollover')
123 || $self->ut_textn('description')
125 return $error if $error;
132 Returns the usage class numbers that are allowed to use minutes from this
139 if (!$self->get('classnums')) {
140 my $classnums = [ map { $_->classnum } $self->part_pkg_usage_class ];
141 $self->set('classnums', $classnums);
143 @{ $self->get('classnums') };
150 L<FS::Record>, schema.html from the base documentation.