1 package FS::part_pkg_usageprice;
2 use base qw( FS::Record );
6 #use FS::Record qw( qsearch qsearchs );
10 FS::part_pkg_usageprice - Object methods for part_pkg_usageprice records
14 use FS::part_pkg_usageprice;
16 $record = new FS::part_pkg_usageprice \%hash;
17 $record = new FS::part_pkg_usageprice { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
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
72 Creates a new record. To add the record to the database, see L<"insert">.
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.
79 sub table { 'part_pkg_usageprice'; }
83 Adds this record to the database. If there is an error, returns the error,
84 otherwise returns false.
88 Delete this record from the database.
90 =item replace OLD_RECORD
92 Replaces the OLD_RECORD with this one in the database. If there is an error,
93 returns the error, otherwise returns false.
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
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 'sqlradacct_hour.recur_included_total'
118 || $self->ut_text('amount')
120 return $error if $error;
122 #Check target against package
123 #UI doesn't currently prevent these from happing,
124 #so keep error messages informative
125 my $part_pkg = $self->part_pkg;
126 my $target = $self->target;
127 my $label = $self->target_info->{'label'};
128 my ($needs_svcdb, $needs_plan);
129 if ( $target =~ /^svc_acct.(\w+)$/ ) {
130 $needs_svcdb = 'svc_acct';
131 } elsif ( $target eq 'svc_conferencing.participants' ) {
132 $needs_svcdb = 'svc_conferencing';
133 } elsif ( $target =~ /^sqlradacct_hour.(\w+)$/ ) {
134 $needs_plan = 'sqlradacct_hour';
138 foreach my $pkg_svc ($part_pkg->pkg_svc) {
139 next unless $pkg_svc->quantity;
140 my $svcdb = $pkg_svc->part_svc->svcdb;
142 if $svcdb eq $needs_svcdb;
145 return "Usage pricing add-on \'$label\' can only be used on packages with at least one $needs_svcdb service.\n"
149 return "Usage pricing add-on \'$label\' can only be used on packages with pricing plan \'" .
150 FS::part_pkg->plan_info->{$needs_plan}->{'shortname'} . "\'\n"
151 unless ref($part_pkg) eq 'FS::part_pkg::' . $needs_plan;
159 Returns a hash reference of information about the target of this object.
160 Keys are "label" and "multiplier".
166 $self->targets->{$self->target};
172 Returns a hash reference. Keys are possible values for the "target" field.
173 Values are hash references with "label" and "multiplier" keys.
179 tie my %targets, 'Tie::IxHash', # once?
180 #'svc_acct.totalbytes' => { label => 'Megabytes',
181 # multiplier => 1048576,
183 'svc_acct.totalbytes' => { label => 'Total Gigabytes',
184 multiplier => 1073741824,
186 'svc_acct.seconds' => { label => 'Total Hours',
189 'svc_conferencing.participants' => { label => 'Conference Participants',
192 #this will take more work: set action, not increment..
193 # and then value comes from a select, not a text field
194 # 'svc_conferencing.confqualitynum' => { label => 'Conference Quality',
197 # this bypasses usual apply methods, handled entirely in sqlradacct_hour
198 'sqlradacct_hour.recur_included_total' => { label => 'Included Gigabytes',
199 multiplier => 1 }, #recur_included_total is stored in GB
213 L<FS::part_pkg>, L<FS::Record>