pro-rating w/ web interface, tested (closes: Bug#313).
[freeside.git] / FS / FS / cust_bill_event.pm
1 package FS::cust_bill_event;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::part_bill_event;
7
8 @ISA = qw(FS::Record);
9
10 =head1 NAME
11
12 FS::cust_bill_event - Object methods for cust_bill_event records
13
14 =head1 SYNOPSIS
15
16   use FS::cust_bill_event;
17
18   $record = new FS::cust_bill_event \%hash;
19   $record = new FS::cust_bill_event { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::cust_bill_event object represents an complete invoice event.
32 FS::cust_bill_event inherits from FS::Record.  The following fields are
33 currently supported:
34
35 =over 4
36
37 =item eventnum - primary key
38
39 =item invnum - invoice (see L<FS::cust_bill>)
40
41 =item eventpart - event definition (see L<FS::part_bill_event>)
42
43 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
44 L<Time::Local> and L<Date::Parse> for conversion functions.
45
46 =back
47
48 =head1 METHODS
49
50 =over 4
51
52 =item new HASHREF
53
54 Creates a new completed invoice event.  To add the compelted invoice event to
55 the database, see L<"insert">.
56
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to.  You can ask the object for a copy with the I<hash> method.
59
60 =cut
61
62 # the new method can be inherited from FS::Record, if a table method is defined
63
64 sub table { 'cust_bill_event'; }
65
66 =item insert
67
68 Adds this record to the database.  If there is an error, returns the error,
69 otherwise returns false.
70
71 =cut
72
73 # the insert method can be inherited from FS::Record
74
75 =item delete
76
77 Delete this record from the database.
78
79 =cut
80
81 # the delete method can be inherited from FS::Record
82
83 =item replace OLD_RECORD
84
85 Replaces the OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =cut
89
90 # the replace method can be inherited from FS::Record
91
92 =item check
93
94 Checks all fields to make sure this is a valid completed invoice event.  If
95 there is an error, returns the error, otherwise returns false.  Called by the
96 insert and replace methods.
97
98 =cut
99
100 # the check method should currently be supplied - FS::Record contains some
101 # data checking routines
102
103 sub check {
104   my $self = shift;
105
106   my $error = $self->ut_numbern('eventnum')
107     || $self->ut_number('invnum')
108     || $self->ut_number('eventpart')
109     || $self->ut_number('_date')
110   ;
111
112   return "Unknown invnum"
113     unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
114
115   return "Unknown eventpart"
116     unless qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
117
118   ''; #no error
119 }
120
121 =item part_bill_event
122
123 Returns the invoice event definition (see L<FS::part_bill_event>) for this
124 completed invoice event.
125
126 =cut
127
128 sub part_bill_event {
129   my $self = shift;
130   qsearchs( 'part_bill_event', { 'eventpart' => $self->eventpart } );
131 }
132
133 =back
134
135 =head1 BUGS
136
137 Far too early in the morning.
138
139 =head1 SEE ALSO
140
141 L<FS::part_bill_event>, L<FS::cust_bill>, L<FS::Record>, schema.html from the
142 base documentation.
143
144 =cut
145
146 1;
147