1 package FS::part_fee_usage;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
12 FS::part_fee_usage - Object methods for part_fee_usage records
16 use FS::part_fee_usage;
18 $record = new FS::part_fee_usage \%hash;
19 $record = new FS::part_fee_usage { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::part_fee_usage object is the part of a processing fee definition
32 (L<FS::part_fee>) that applies to a specific telephone usage class
33 (L<FS::usage_class>). FS::part_fee_usage inherits from
34 FS::Record. The following fields are currently supported:
38 =item feepartusagenum - primary key
40 =item feepart - foreign key to L<FS::part_pkg>
42 =item classnum - foreign key to L<FS::usage_class>
44 =item amount - fixed amount to charge per usage record
46 =item percent - percentage of rated price to charge per usage record
56 sub table { 'part_fee_usage'; }
61 $self->set('amount', 0) unless ($self->amount || 0) > 0;
62 $self->set('percent', 0) unless ($self->percent || 0) > 0;
65 $self->ut_numbern('feepartusagenum')
66 || $self->ut_foreign_key('feepart', 'part_fee', 'feepart')
67 || $self->ut_foreign_key('classnum', 'usage_class', 'classnum')
68 || $self->ut_money('amount')
69 || $self->ut_float('percent')
71 return $error if $error;
76 # silently discard records with percent = 0 and amount = 0
80 if ( $self->amount > 0 or $self->percent > 0 ) {
81 return $self->SUPER::insert;
88 $old ||= $new->replace_old;
89 if ( $new->amount > 0 or $new->percent > 0 ) {
90 return $new->SUPER::replace($old);
91 } elsif ( $old->feepartusagenum ) {
99 Returns a string describing how this fee is calculated.
106 my $money = (FS::Conf->new->config('money_char') || '$') . '%.2f';
107 my $percent = '%.1f%%';
108 if ( $self->amount > 0 ) {
109 $string = sprintf($money, $self->amount);
111 if ( $self->percent > 0 ) {
115 $string .= sprintf($percent, $self->percent);
116 $string .= ' of the rated charge';
118 $string .= ' per '. $self->usage_class->classname . ' call';
123 # stubs, remove under 4.x
127 FS::part_fee->by_key($self->feepart);
132 FS::usage_class->by_key($self->classnum);
139 L<FS::Record>, schema.html from the base documentation.