0fa6bca978cdbb49390e212502c71d47008d48df
[freeside.git] / FS / FS / part_pkg_usageprice.pm
1 package FS::part_pkg_usageprice;
2 use base qw( FS::Record );
3
4 use strict;
5 #use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::part_pkg_usageprice - Object methods for part_pkg_usageprice records
10
11 =head1 SYNOPSIS
12
13   use FS::part_pkg_usageprice;
14
15   $record = new FS::part_pkg_usageprice \%hash;
16   $record = new FS::part_pkg_usageprice { '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::part_pkg_usageprice object represents a usage pricing add-on.
29 FS::part_pkg_usageprice inherits from FS::Record.  The following fields are
30 currently supported:
31
32 =over 4
33
34 =item usagepricepart
35
36 primary key
37
38 =item pkgpart
39
40 pkgpart
41
42 =item price
43
44 price
45
46 =item currency
47
48 currency
49
50 =item action
51
52 action
53
54 =item target
55
56 target
57
58 =item amount
59
60 amount
61
62
63 =back
64
65 =head1 METHODS
66
67 =over 4
68
69 =item new HASHREF
70
71 Creates a new record.  To add the record to the database, see L<"insert">.
72
73 Note that this stores the hash reference, not a distinct copy of the hash it
74 points to.  You can ask the object for a copy with the I<hash> method.
75
76 =cut
77
78 sub table { 'part_pkg_usageprice'; }
79
80 =item insert
81
82 Adds this record to the database.  If there is an error, returns the error,
83 otherwise returns false.
84
85 =item delete
86
87 Delete this record from the database.
88
89 =item replace OLD_RECORD
90
91 Replaces the OLD_RECORD with this one in the database.  If there is an error,
92 returns the error, otherwise returns false.
93
94 =item check
95
96 Checks all fields to make sure this is a valid record.  If there is
97 an error, returns the error, otherwise returns false.  Called by the insert
98 and replace methods.
99
100 =cut
101
102 sub check {
103   my $self = shift;
104
105   my $error = 
106     $self->ut_numbern('usagepricepart')
107     || $self->ut_number('pkgpart')
108     || $self->ut_money('price')
109     || $self->ut_currencyn('currency')
110     || $self->ut_enum('action', [ 'increment', 'set' ])
111     || $self->ut_enum('target', [ 'svc_acct.totalbytes', 'svc_acct.seconds',
112                                   'svc_conferencing.participants',
113                                   'svc_conferencing.confqualitynum'
114                                 ]
115                      )
116     || $self->ut_text('amount')
117   ;
118   return $error if $error;
119
120   $self->SUPER::check;
121 }
122
123 =back
124
125 =head1 BUGS
126
127 =head1 SEE ALSO
128
129 L<FS::part_pkg>, L<FS::Record>
130
131 =cut
132
133 1;
134