1 package FS::part_fee_usage;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
10 FS::part_fee_usage - Object methods for part_fee_usage records
14 use FS::part_fee_usage;
16 $record = new FS::part_fee_usage \%hash;
17 $record = new FS::part_fee_usage { '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_fee_usage object is the part of a processing fee definition
30 (L<FS::part_fee>) that applies to a specific telephone usage class
31 (L<FS::usage_class>). FS::part_fee_usage inherits from
32 FS::Record. The following fields are currently supported:
36 =item feepartusagenum - primary key
38 =item feepart - foreign key to L<FS::part_pkg>
40 =item classnum - foreign key to L<FS::usage_class>
42 =item amount - fixed amount to charge per usage record
44 =item percent - percentage of rated price to charge per usage record
54 sub table { 'part_fee_usage'; }
59 $self->set('amount', 0) unless ($self->amount || 0) > 0;
60 $self->set('percent', 0) unless ($self->percent || 0) > 0;
63 $self->ut_numbern('feepartusagenum')
64 || $self->ut_foreign_key('feepart', 'part_fee', 'feepart')
65 || $self->ut_foreign_key('classnum', 'usage_class', 'classnum')
66 || $self->ut_money('amount')
67 || $self->ut_float('percent')
69 return $error if $error;
74 # silently discard records with percent = 0 and amount = 0
78 if ( $self->amount > 0 or $self->percent > 0 ) {
79 return $self->SUPER::insert;
86 $old ||= $new->replace_old;
87 if ( $new->amount > 0 or $new->percent > 0 ) {
88 return $new->SUPER::replace($old);
89 } elsif ( $old->feepartusagenum ) {
97 Returns a string describing how this fee is calculated.
104 my $money = (FS::Conf->new->config('money_char') || '$') . '%.2f';
105 my $percent = '%.1f%%';
106 if ( $self->amount > 0 ) {
107 $string = sprintf($money, $self->amount);
109 if ( $self->percent > 0 ) {
113 $string .= sprintf($percent, $self->percent);
114 $string .= ' of the rated charge';
116 $string .= ' per '. $self->usage_class->classname . ' call';
125 L<FS::Record>, schema.html from the base documentation.