agent-virtualize credit card surcharge percentage, RT#72961
[freeside.git] / FS / FS / commission_rate.pm
1 package FS::commission_rate;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::commission_rate - Object methods for commission_rate records
10
11 =head1 SYNOPSIS
12
13   use FS::commission_rate;
14
15   $record = new FS::commission_rate \%hash;
16   $record = new FS::commission_rate { '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::commission_rate object represents a commission rate (a percentage or a
29 flat amount) that will be paid on a customer's N-th invoice. The sequence of
30 commissions that will be paid on consecutive invoices is the parent object,
31 L<FS::commission_schedule>.
32
33 FS::commission_rate inherits from FS::Record.  The following fields are
34 currently supported:
35
36 =over 4
37
38 =item commissionratenum - primary key
39
40 =item schedulenum - L<FS::commission_schedule> foreign key
41
42 =item cycle - the ordinal of the billing cycle this commission will apply
43 to. cycle = 1 applies to the customer's first invoice, cycle = 2 to the
44 second, etc.
45
46 =item amount - the flat amount to pay per invoice in commission
47
48 =item percent - the percentage of the invoice amount to pay in 
49 commission
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new commission rate.  To add it to the database, see L<"insert">.
60
61 =cut
62
63 sub table { 'commission_rate'; }
64
65 =item insert
66
67 Adds this record to the database.  If there is an error, returns the error,
68 otherwise returns false.
69
70 =item delete
71
72 Delete this record from the database.
73
74 =item replace OLD_RECORD
75
76 Replaces the OLD_RECORD with this one in the database.  If there is an error,
77 returns the error, otherwise returns false.
78
79 =item check
80
81 Checks all fields to make sure this is a valid commission rate.  If there is
82 an error, returns the error, otherwise returns false.  Called by the insert
83 and replace methods.
84
85 =cut
86
87 sub check {
88   my $self = shift;
89
90   $self->set('amount', '0.00')
91     if $self->get('amount') eq '';
92   $self->set('percent', '0')
93     if $self->get('percent') eq '';
94
95   my $error = 
96     $self->ut_numbern('commissionratenum')
97     || $self->ut_number('schedulenum')
98     || $self->ut_number('cycle')
99     || $self->ut_money('amount')
100     || $self->ut_decimal('percent')
101   ;
102   return $error if $error;
103
104   $self->SUPER::check;
105 }
106
107 =back
108
109 =head1 SEE ALSO
110
111 L<FS::Record>
112
113 =cut
114
115 1;
116