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.
65 sub new { FS::Record::new(@_); }
67 sub table { 'cust_statement'; }
71 Adds this record to the database. If there is an error, returns the error,
72 otherwise returns false.
79 local $SIG{HUP} = 'IGNORE';
80 local $SIG{INT} = 'IGNORE';
81 local $SIG{QUIT} = 'IGNORE';
82 local $SIG{TERM} = 'IGNORE';
83 local $SIG{TSTP} = 'IGNORE';
84 local $SIG{PIPE} = 'IGNORE';
86 my $oldAutoCommit = $FS::UID::AutoCommit;
87 local $FS::UID::AutoCommit = 0;
90 FS::Record::insert($self);
92 foreach my $cust_bill (
94 'table' => 'cust_bill',
95 'hashref' => { 'custnum' => $self->custnum,
98 'extra_sql' => 'FOR UPDATE' ,
102 $cust_bill->statementnum( $self->statementnum );
103 my $error = $cust_bill->replace;
105 $dbh->rollback if $oldAutoCommit;
106 return "Error associating invoice: $error";
110 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
117 Delete this record from the database.
121 sub delete { FS::Record::delete(@_); }
123 =item replace OLD_RECORD
125 Replaces the OLD_RECORD with this one in the database. If there is an error,
126 returns the error, otherwise returns false.
130 sub replace { FS::Record::replace(@_); }
132 sub replace_check { ''; }
136 Checks all fields to make sure this is a valid record. If there is
137 an error, returns the error, otherwise returns false. Called by the insert
146 $self->ut_numbern('statementnum')
147 || $self->ut_foreign_key('custnum', 'cust_main', 'custnum' )
148 || $self->ut_numbern('_date')
150 return $error if $error;
152 $self->_date(time) unless $self->_date;
154 #don't want to call cust_bill, and Record just checks virtual fields
155 #$self->SUPER::check;
162 Returns the associated invoices (cust_bill records) for this statement.
168 qsearch('cust_bill', { 'statementnum' => $self->statementnum } );
172 my( $self, $method ) = ( shift, shift );
176 foreach my $cust_bill ( $self->cust_bill ) {
177 push @agg, $cust_bill->$method( @_ );
185 Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices.
187 =item cust_bill_pkg_pkgnum PKGNUM
189 Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices
190 and specified pkgnum.
194 Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
199 Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
202 =item cust_bill_pay_pkgnum PKGNUM
204 Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
205 invoices with matching pkgnum.
207 =item cust_credited_pkgnum PKGNUM
209 Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
210 invoices with matching pkgnum.
214 sub cust_bill_pay { shift->_aggregate('cust_bill_pay', @_); }
215 sub cust_credited { shift->_aggregate('cust_credited', @_); }
216 sub cust_bill_pay_pkgnum { shift->_aggregate('cust_bill_pay_pkgnum', @_); }
217 sub cust_credited_pkgnum { shift->_aggregate('cust_credited_pkgnum', @_); }
219 sub cust_bill_pkg { shift->_aggregate('cust_bill_pkg', @_); }
220 sub cust_bill_pkg_pkgnum { shift->_aggregate('cust_bill_pkg_pkgnum', @_); }
224 Returns the tax amount (see L<FS::cust_bill_pkg>) for this invoice.
233 foreach my $cust_bill ( $self->cust_bill ) {
234 $total += $cust_bill->tax;
246 L<FS::cust_bill>, L<FS::Record>, schema.html from the base documentation.