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