Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / cdr_cust_pkg_usage.pm
1 package FS::cdr_cust_pkg_usage;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::cdr_cust_pkg_usage - Object methods for cdr_cust_pkg_usage records
10
11 =head1 SYNOPSIS
12
13   use FS::cdr_cust_pkg_usage;
14
15   $record = new FS::cdr_cust_pkg_usage \%hash;
16   $record = new FS::cdr_cust_pkg_usage { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::cdr_cust_pkg_usage object represents an allocation of included 
29 usage minutes to a call.  FS::cdr_cust_pkg_usage inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item cdrusagenum - primary key
35
36 =item acctid - foreign key to cdr.acctid
37
38 =item pkgusagenum - foreign key to cust_pkg_usage.pkgusagenum
39
40 =item minutes - the number of minutes allocated
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Creates a new example.  To add the example to the database, see L<"insert">.
51
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to.  You can ask the object for a copy with the I<hash> method.
54
55 =cut
56
57 # the new method can be inherited from FS::Record, if a table method is defined
58
59 sub table { 'cdr_cust_pkg_usage'; }
60
61 =item insert
62
63 Adds this record to the database.  If there is an error, returns the error,
64 otherwise returns false.
65
66 =item delete
67
68 Delete this record from the database.
69
70 =item replace OLD_RECORD
71
72 Replaces the OLD_RECORD with this one in the database.  If there is an error,
73 returns the error, otherwise returns false.
74
75 =item check
76
77 Checks all fields to make sure this is a valid example.  If there is
78 an error, returns the error, otherwise returns false.  Called by the insert
79 and replace methods.
80
81 =cut
82
83 sub check {
84   my $self = shift;
85
86   my $error = 
87     $self->ut_numbern('cdrusagenum')
88     || $self->ut_foreign_key('acctid', 'cdr', 'acctid')
89     || $self->ut_foreign_key('pkgusagenum', 'cust_pkg_usage', 'pkgusagenum')
90     || $self->ut_number('minutes')
91   ;
92   return $error if $error;
93
94   $self->SUPER::check;
95 }
96
97 =item cust_pkg_usage
98
99 Returns the L<FS::cust_pkg_usage> object that this usage allocation came from.
100
101 =item cdr
102
103 Returns the L<FS::cdr> object that the usage was applied to.
104
105 =cut
106
107 sub cust_pkg_usage {
108   FS::cust_pkg_usage->by_key($_[0]->pkgusagenum);
109 }
110
111 sub cdr {
112   FS::cdr->by_key($_[0]->acctid);
113 }
114
115 =back
116
117 =head1 SEE ALSO
118
119 L<FS::Record>, schema.html from the base documentation.
120
121 =cut
122
123 1;
124