1 package FS::cust_pkg_usage;
4 use base qw( FS::Record );
6 use FS::part_pkg_usage;
7 use FS::Record qw( qsearch qsearchs );
11 FS::cust_pkg_usage - Object methods for cust_pkg_usage records
15 use FS::cust_pkg_usage;
17 $record = new FS::cust_pkg_usage \%hash;
18 $record = new FS::cust_pkg_usage { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::cust_pkg_usage object represents a counter of remaining included
31 minutes on a voice-call package. FS::cust_pkg_usage inherits from
32 FS::Record. The following fields are currently supported:
36 =item pkgusagenum - primary key
38 =item pkgnum - the package (L<FS::cust_pkg>) containing the usage
40 =item pkgusagepart - the usage stock definition (L<FS::part_pkg_usage>).
41 This record in turn links to the call usage classes that are eligible to
44 =item minutes - the remaining minutes
54 # the new method can be inherited from FS::Record, if a table method is defined
58 sub table { 'cust_pkg_usage'; }
62 Adds this record to the database. If there is an error, returns the error,
63 otherwise returns false.
67 # the insert method can be inherited from FS::Record
71 Delete this record from the database.
77 my $error = $self->reset || $self->SUPER::delete;
82 Remove all allocations of this usage to CDRs.
89 foreach (qsearch('cdr_cust_pkg_usage', { pkgusagenum => $self->pkgusagenum }))
91 $error ||= $_->delete;
96 =item replace OLD_RECORD
98 Replaces the OLD_RECORD with this one in the database. If there is an error,
99 returns the error, otherwise returns false.
103 # the replace method can be inherited from FS::Record
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
113 # the check method should currently be supplied - FS::Record contains some
114 # data checking routines
120 $self->ut_numbern('pkgusagenum')
121 || $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum')
122 || $self->ut_numbern('minutes')
123 || $self->ut_foreign_key('pkgusagepart', 'part_pkg_usage', 'pkgusagepart')
125 return $error if $error;
127 if ( $self->minutes eq '' ) {
128 $self->set(minutes => $self->part_pkg_usage->minutes);
136 Return the L<FS::cust_pkg> linked to this record.
140 Return the L<FS::part_pkg_usage> linked to this record.
146 FS::cust_pkg->by_key($self->pkgnum);
151 FS::part_pkg_usage->by_key($self->pkgusagepart);
158 L<FS::Record>, schema.html from the base documentation.