time/data/etc. unit pricing add-ons, RT#24392
[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 Tie::IxHash;
6 #use FS::Record qw( qsearch qsearchs );
7
8 =head1 NAME
9
10 FS::part_pkg_usageprice - Object methods for part_pkg_usageprice records
11
12 =head1 SYNOPSIS
13
14   use FS::part_pkg_usageprice;
15
16   $record = new FS::part_pkg_usageprice \%hash;
17   $record = new FS::part_pkg_usageprice { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::part_pkg_usageprice object represents a usage pricing add-on.
30 FS::part_pkg_usageprice inherits from FS::Record.  The following fields are
31 currently supported:
32
33 =over 4
34
35 =item usagepricepart
36
37 primary key
38
39 =item pkgpart
40
41 pkgpart
42
43 =item price
44
45 price
46
47 =item currency
48
49 currency
50
51 =item action
52
53 action
54
55 =item target
56
57 target
58
59 =item amount
60
61 amount
62
63
64 =back
65
66 =head1 METHODS
67
68 =over 4
69
70 =item new HASHREF
71
72 Creates a new record.  To add the record to the database, see L<"insert">.
73
74 Note that this stores the hash reference, not a distinct copy of the hash it
75 points to.  You can ask the object for a copy with the I<hash> method.
76
77 =cut
78
79 sub table { 'part_pkg_usageprice'; }
80
81 =item insert
82
83 Adds this record to the database.  If there is an error, returns the error,
84 otherwise returns false.
85
86 =item delete
87
88 Delete this record from the database.
89
90 =item replace OLD_RECORD
91
92 Replaces the OLD_RECORD with this one in the database.  If there is an error,
93 returns the error, otherwise returns false.
94
95 =item check
96
97 Checks all fields to make sure this is a valid record.  If there is
98 an error, returns the error, otherwise returns false.  Called by the insert
99 and replace methods.
100
101 =cut
102
103 sub check {
104   my $self = shift;
105
106   my $error = 
107     $self->ut_numbern('usagepricepart')
108     || $self->ut_number('pkgpart')
109     || $self->ut_money('price')
110     || $self->ut_currencyn('currency')
111     || $self->ut_enum('action', [ 'increment', 'set' ])
112     || $self->ut_enum('target', [ 'svc_acct.totalbytes', 'svc_acct.seconds',
113                                   'svc_conferencing.participants',
114                                   'svc_conferencing.confqualitynum'
115                                 ]
116                      )
117     || $self->ut_text('amount')
118   ;
119   return $error if $error;
120
121   $self->SUPER::check;
122 }
123
124 =item target_info
125
126 Returns a hash reference of information about the target of this object.
127 Keys are "label" and "multiplier".
128
129 =cut
130
131 sub target_info {
132   my $self = shift;
133   $self->targets->{$self->target};
134 }
135
136 =item targets
137
138 (Class method)
139 Returns a hash reference.  Keys are possible values for the "target" field.
140 Values are hash references with "label" and "multiplier" keys.
141
142 =cut
143
144 sub targets {
145
146   tie my %targets, 'Tie::IxHash', # once?
147     #'svc_acct.totalbytes' => { label      => 'Megabytes',
148     #                           multiplier => 1048576,
149     #                         },
150     'svc_acct.totalbytes' => { label      => 'Gigabytes',
151                                multiplier => 1073741824,
152                              },
153     'svc_acct.seconds' => { label      => 'Hours',
154                             multiplier => 3600,
155                           },
156     'svc_conferencing.participants' => { label     => 'Conference Participants',
157                                          multiplier=> 1,
158                                        },
159   #this will take more work: set action, not increment..
160   #  and then value comes from a select, not a text field
161   #  'svc_conferencing.confqualitynum' => { label => 'Conference Quality',
162   #                                        },
163   ;
164
165   \%targets;
166
167 }
168
169 =back
170
171 =head1 BUGS
172
173 =head1 SEE ALSO
174
175 L<FS::part_pkg>, L<FS::Record>
176
177 =cut
178
179 1;
180