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( @_ );
184 my( $self, $method ) = ( shift, shift );
188 foreach my $cust_bill ( $self->cust_bill ) {
189 $total += $cust_bill->$method( @_ );
197 Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices.
199 =item cust_bill_pkg_pkgnum PKGNUM
201 Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices
202 and specified pkgnum.
206 Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
211 Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
214 =item cust_bill_pay_pkgnum PKGNUM
216 Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
217 invoices with matching pkgnum.
219 =item cust_credited_pkgnum PKGNUM
221 Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
222 invoices with matching pkgnum.
226 sub cust_bill_pay { shift->_aggregate('cust_bill_pay', @_); }
227 sub cust_credited { shift->_aggregate('cust_credited', @_); }
228 sub cust_bill_pay_pkgnum { shift->_aggregate('cust_bill_pay_pkgnum', @_); }
229 sub cust_credited_pkgnum { shift->_aggregate('cust_credited_pkgnum', @_); }
231 sub cust_bill_pkg { shift->_aggregate('cust_bill_pkg', @_); }
232 sub cust_bill_pkg_pkgnum { shift->_aggregate('cust_bill_pkg_pkgnum', @_); }
236 Returns the total tax amount for all assoicated invoices.0
242 Returns the total amount charged for all associated invoices.
248 Returns the total amount owed for all associated invoices.
252 sub tax { shift->_total('tax', @_); }
253 sub charged { shift->_total('charged', @_); }
254 sub owed { shift->_total('owed', @_); }
256 #don't show previous info
258 ( 0 ); # 0, empty list
267 L<FS::cust_bill>, L<FS::Record>, schema.html from the base documentation.