1 package FS::cust_statement;
4 use base qw( FS::cust_bill );
5 use FS::Record qw( dbh qsearch ); #qsearchs );
11 FS::cust_statement - Object methods for cust_statement records
15 use FS::cust_statement;
17 $record = new FS::cust_statement \%hash;
18 $record = new FS::cust_statement { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::cust_statement object represents an informational statement which
31 aggregates one or more invoices. FS::cust_statement inherits from
34 The following fields are currently supported:
58 Creates a new record. To add the record to the database, see L<"insert">.
60 Note that this stores the hash reference, not a distinct copy of the hash it
61 points to. You can ask the object for a copy with the I<hash> method.
63 Pass "statementnum => 'ALL'" to create a temporary statement that includes
64 all of the customer's invoices. This statement can't be inserted and won't
65 set the statementnum field on any invoices.
69 sub new { FS::Record::new(@_); }
71 sub table { 'cust_statement'; }
75 Adds this record to the database. If there is an error, returns the error,
76 otherwise returns false.
83 local $SIG{HUP} = 'IGNORE';
84 local $SIG{INT} = 'IGNORE';
85 local $SIG{QUIT} = 'IGNORE';
86 local $SIG{TERM} = 'IGNORE';
87 local $SIG{TSTP} = 'IGNORE';
88 local $SIG{PIPE} = 'IGNORE';
90 my $oldAutoCommit = $FS::UID::AutoCommit;
91 local $FS::UID::AutoCommit = 0;
94 FS::Record::insert($self);
96 foreach my $cust_bill (
98 'table' => 'cust_bill',
99 'hashref' => { 'custnum' => $self->custnum,
100 'statementnum' => '',
102 'extra_sql' => 'FOR UPDATE' ,
106 $cust_bill->statementnum( $self->statementnum );
107 my $error = $cust_bill->replace;
109 $dbh->rollback if $oldAutoCommit;
110 return "Error associating invoice: $error";
114 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
121 Delete this record from the database.
125 sub delete { FS::Record::delete(@_); }
127 =item replace OLD_RECORD
129 Replaces the OLD_RECORD with this one in the database. If there is an error,
130 returns the error, otherwise returns false.
134 sub replace { FS::Record::replace(@_); }
136 sub replace_check { ''; }
140 Checks all fields to make sure this is a valid record. If there is
141 an error, returns the error, otherwise returns false. Called by the insert
150 $self->ut_numbern('statementnum')
151 || $self->ut_foreign_key('custnum', 'cust_main', 'custnum' )
152 || $self->ut_numbern('_date')
154 return $error if $error;
156 $self->_date(time) unless $self->_date;
158 #don't want to call cust_bill, and Record just checks virtual fields
159 #$self->SUPER::check;
166 Returns the associated invoices (cust_bill records) for this statement.
172 # we use it about a thousand times, let's cache it
173 $self->{Hash}->{cust_bill} ||= [
174 qsearch('cust_bill', {
175 $self->statementnum eq 'ALL' ?
176 ('custnum' => $self->custnum) :
177 ('statementnum' => $self->statementnum)
181 @{ $self->{Hash}->{cust_bill} }
185 my( $self, $method ) = ( shift, shift );
189 foreach my $cust_bill ( $self->cust_bill ) {
190 push @agg, $cust_bill->$method( @_ );
197 my( $self, $method ) = ( shift, shift );
201 foreach my $cust_bill ( $self->cust_bill ) {
202 $total += $cust_bill->$method( @_ );
210 Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices.
212 =item cust_bill_pkg_pkgnum PKGNUM
214 Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices
215 and specified pkgnum.
219 Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
224 Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
227 =item cust_bill_pay_pkgnum PKGNUM
229 Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
230 invoices with matching pkgnum.
232 =item cust_credited_pkgnum PKGNUM
234 Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
235 invoices with matching pkgnum.
239 sub cust_bill_pay { shift->_aggregate('cust_bill_pay', @_); }
240 sub cust_credited { shift->_aggregate('cust_credited', @_); }
241 sub cust_bill_pay_pkgnum { shift->_aggregate('cust_bill_pay_pkgnum', @_); }
242 sub cust_credited_pkgnum { shift->_aggregate('cust_credited_pkgnum', @_); }
244 sub cust_bill_pkg { shift->_aggregate('cust_bill_pkg', @_); }
245 sub cust_bill_pkg_pkgnum { shift->_aggregate('cust_bill_pkg_pkgnum', @_); }
249 Returns the total tax amount for all assoicated invoices.0
255 Returns the total amount charged for all associated invoices.
261 Returns the total amount owed for all associated invoices.
265 sub tax { shift->_total('tax', @_); }
266 sub charged { shift->_total('charged', @_); }
267 sub owed { shift->_total('owed', @_); }
269 #don't show previous info
271 ( 0 ); # 0, empty list
280 L<FS::cust_bill>, L<FS::Record>, schema.html from the base documentation.