fix attribute importing bugs that borked the passwords
[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::cust_bill;
7 use FS::part_bill_event;
8
9 @ISA = qw(FS::Record);
10
11 =head1 NAME
12
13 FS::cust_bill_event - Object methods for cust_bill_event records
14
15 =head1 SYNOPSIS
16
17   use FS::cust_bill_event;
18
19   $record = new FS::cust_bill_event \%hash;
20   $record = new FS::cust_bill_event { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::cust_bill_event object represents an complete invoice event.
33 FS::cust_bill_event inherits from FS::Record.  The following fields are
34 currently supported:
35
36 =over 4
37
38 =item eventnum - primary key
39
40 =item invnum - invoice (see L<FS::cust_bill>)
41
42 =item eventpart - event definition (see L<FS::part_bill_event>)
43
44 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
45 L<Time::Local> and L<Date::Parse> for conversion functions.
46
47 =item status - event status: B<done> or B<failed>
48
49 =item statustext - additional status detail (i.e. error message)
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new completed invoice event.  To add the compelted invoice event to
60 the database, see L<"insert">.
61
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to.  You can ask the object for a copy with the I<hash> method.
64
65 =cut
66
67 # the new method can be inherited from FS::Record, if a table method is defined
68
69 sub table { 'cust_bill_event'; }
70
71 =item insert
72
73 Adds this record to the database.  If there is an error, returns the error,
74 otherwise returns false.
75
76 =cut
77
78 # the insert method can be inherited from FS::Record
79
80 =item delete
81
82 Delete this record from the database.
83
84 =cut
85
86 # the delete method can be inherited from FS::Record
87
88 =item replace OLD_RECORD
89
90 Replaces the OLD_RECORD with this one in the database.  If there is an error,
91 returns the error, otherwise returns false.
92
93 =cut
94
95 # the replace method can be inherited from FS::Record
96
97 =item check
98
99 Checks all fields to make sure this is a valid completed invoice event.  If
100 there is an error, returns the error, otherwise returns false.  Called by the
101 insert and replace methods.
102
103 =cut
104
105 # the check method should currently be supplied - FS::Record contains some
106 # data checking routines
107
108 sub check {
109   my $self = shift;
110
111   my $error = $self->ut_numbern('eventnum')
112     || $self->ut_number('invnum')
113     || $self->ut_number('eventpart')
114     || $self->ut_number('_date')
115     || $self->ut_enum('status', [qw( done failed )])
116     || $self->ut_textn('statustext')
117   ;
118
119   return "Unknown invnum ". $self->invnum
120     unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
121
122   return "Unknown eventpart ". $self->eventpart
123     unless qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
124
125   $self->SUPER::check;
126 }
127
128 =item part_bill_event
129
130 Returns the invoice event definition (see L<FS::part_bill_event>) for this
131 completed invoice event.
132
133 =cut
134
135 sub part_bill_event {
136   my $self = shift;
137   qsearchs( 'part_bill_event', { 'eventpart' => $self->eventpart } );
138 }
139
140 =item cust_bill
141
142 Returns the invoice (see L<FS::cust_bill>) for this completed invoice event.
143
144 =cut
145
146 sub cust_bill {
147   my $self = shift;
148   qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
149 }
150
151 =item retry
152
153 Changes the status of this event from B<done> to B<failed>, allowing it to be
154 retried.
155
156 =cut
157
158 sub retry {
159   my $self = shift;
160   return '' unless $self->status eq 'done';
161   my $old = ref($self)->new( { $self->hash } );
162   $self->status('failed');
163   $self->replace($old);
164 }
165
166 =back
167
168 =head1 BUGS
169
170 Far too early in the morning.
171
172 =head1 SEE ALSO
173
174 L<FS::part_bill_event>, L<FS::cust_bill>, L<FS::Record>, schema.html from the
175 base documentation.
176
177 =cut
178
179 1;
180