1 package FS::cust_pkg_usage;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearch ); #qsearchs );
9 FS::cust_pkg_usage - Object methods for cust_pkg_usage records
13 use FS::cust_pkg_usage;
15 $record = new FS::cust_pkg_usage \%hash;
16 $record = new FS::cust_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::cust_pkg_usage object represents a counter of remaining included
29 minutes on a voice-call package. FS::cust_pkg_usage inherits from
30 FS::Record. The following fields are currently supported:
34 =item pkgusagenum - primary key
36 =item pkgnum - the package (L<FS::cust_pkg>) containing the usage
38 =item pkgusagepart - the usage stock definition (L<FS::part_pkg_usage>).
39 This record in turn links to the call usage classes that are eligible to
42 =item minutes - the remaining minutes
52 # the new method can be inherited from FS::Record, if a table method is defined
56 sub table { 'cust_pkg_usage'; }
60 Adds this record to the database. If there is an error, returns the error,
61 otherwise returns false.
65 # the insert method can be inherited from FS::Record
69 Delete this record from the database.
75 my $error = $self->reset || $self->SUPER::delete;
80 Remove all allocations of this usage to CDRs.
87 foreach (qsearch('cdr_cust_pkg_usage', { pkgusagenum => $self->pkgusagenum }))
89 $error ||= $_->delete;
94 =item replace OLD_RECORD
96 Replaces the OLD_RECORD with this one in the database. If there is an error,
97 returns the error, otherwise returns false.
101 # the replace method can be inherited from FS::Record
105 Checks all fields to make sure this is a valid example. If there is
106 an error, returns the error, otherwise returns false. Called by the insert
111 # the check method should currently be supplied - FS::Record contains some
112 # data checking routines
118 $self->ut_numbern('pkgusagenum')
119 || $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum')
120 || $self->ut_floatn('minutes')
121 || $self->ut_foreign_key('pkgusagepart', 'part_pkg_usage', 'pkgusagepart')
123 return $error if $error;
125 if ( $self->minutes eq '' ) {
126 $self->set(minutes => $self->part_pkg_usage->minutes);
134 Return the L<FS::cust_pkg> linked to this record.
138 Return the L<FS::part_pkg_usage> linked to this record.
144 L<FS::Record>, schema.html from the base documentation.