[freeside-commits] freeside/FS/FS cust_statement.pm, NONE, 1.1 Schema.pm, 1.163, 1.164 part_event.pm, 1.3, 1.4 cust_main.pm, 1.451, 1.452
Ivan,,,
ivan at wavetail.420.am
Wed Aug 19 21:03:36 PDT 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv8501/FS/FS
Modified Files:
Schema.pm part_event.pm cust_main.pm
Added Files:
cust_statement.pm
Log Message:
Emailing statements of accounts, RT#4860
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -d -r1.163 -r1.164
--- Schema.pm 17 Aug 2009 20:48:26 -0000 1.163
+++ Schema.pm 20 Aug 2009 04:03:34 -0000 1.164
@@ -390,16 +390,28 @@
'cust_bill' => {
'columns' => [
- 'invnum', 'serial', '', '', '', '',
- 'custnum', 'int', '', '', '', '',
- '_date', @date_type, '', '',
- 'charged', @money_type, '', '',
- 'printed', 'int', '', '', '', '',
- 'closed', 'char', 'NULL', 1, '', '',
+ 'invnum', 'serial', '', '', '', '',
+ 'custnum', 'int', '', '', '', '',
+ '_date', @date_type, '', '',
+ 'charged', @money_type, '', '',
+ 'printed', 'int', '', '', '', '',
+ 'closed', 'char', 'NULL', 1, '', '',
+ 'statementnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'invnum',
'unique' => [],
- 'index' => [ ['custnum'], ['_date'] ],
+ 'index' => [ ['custnum'], ['_date'], ['statementnum'], ],
+ },
+
+ 'cust_statement' => {
+ 'columns' => [
+ 'statementnum', 'serial', '', '', '', '',
+ 'custnum', 'int', '', '', '', '',
+ '_date', @date_type, '', '',
+ ],
+ 'primary_key' => 'statementnum',
+ 'unique' => [],
+ 'index' => [ ['custnum'], ['_date'], ],
},
'cust_bill_event' => {
--- NEW FILE: cust_statement.pm ---
package FS::cust_statement;
use strict;
use base qw( FS::cust_bill );
use FS::Record qw( dbh qsearch ); #qsearchs );
use FS::cust_main;
use FS::cust_bill;
=head1 NAME
FS::cust_statement - Object methods for cust_statement records
=head1 SYNOPSIS
use FS::cust_statement;
$record = new FS::cust_statement \%hash;
$record = new FS::cust_statement { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::cust_statement object represents an informational statement which
aggregates one or more invoices. FS::cust_statement inherits from
FS::cust_bill.
The following fields are currently supported:
=over 4
=item statementnum
primary key
=item custnum
customer
=item _date
date
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new record. To add the record to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
sub new { FS::Record::new(@_); }
sub table { 'cust_statement'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
sub insert {
my $self = shift;
local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
local $SIG{QUIT} = 'IGNORE';
local $SIG{TERM} = 'IGNORE';
local $SIG{TSTP} = 'IGNORE';
local $SIG{PIPE} = 'IGNORE';
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
FS::Record::insert($self);
foreach my $cust_bill (
qsearch({
'table' => 'cust_bill',
'hashref' => { 'custnum' => $self->custnum,
'statementnum' => '',
},
'extra_sql' => 'FOR UPDATE' ,
})
)
{
$cust_bill->statementnum( $self->statementnum );
my $error = $cust_bill->replace;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "Error associating invoice: $error";
}
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
''; #no error
}
=item delete
Delete this record from the database.
=cut
sub delete { FS::Record::delete(@_); }
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
sub replace { FS::Record::replace(@_); }
sub replace_check { ''; }
=item check
Checks all fields to make sure this is a valid record. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
sub check {
my $self = shift;
my $error =
$self->ut_numbern('statementnum')
|| $self->ut_foreign_key('custnum', 'cust_main', 'custnum' )
|| $self->ut_numbern('_date')
;
return $error if $error;
$self->_date(time) unless $self->_date;
#don't want to call cust_bill, and Record just checks virtual fields
#$self->SUPER::check;
'';
}
=item cust_bill
Returns the associated invoices (cust_bill records) for this statement.
=cut
sub cust_bill {
my $self = shift;
qsearch('cust_bill', { 'statementnum' => $self->statementnum } );
}
sub _aggregate {
my( $self, $method ) = ( shift, shift );
my @agg = ();
foreach my $cust_bill ( $self->cust_bill ) {
push @agg, $cust_bill->$method( @_ );
}
@agg;
}
=item cust_bill_pkg
Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices.
=item cust_bill_pkg_pkgnum PKGNUM
Returns the line items (see L<FS::cust_bill_pkg>) for all associated invoices
and specified pkgnum.
=item cust_bill_pay
Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
invoices.
=item cust_credited
Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
invoices.
=item cust_bill_pay_pkgnum PKGNUM
Returns all payment applications (see L<FS::cust_bill_pay>) for all associated
invoices with matching pkgnum.
=item cust_credited_pkgnum PKGNUM
Returns all applied credits (see L<FS::cust_credit_bill>) for all associated
invoices with matching pkgnum.
=cut
sub cust_bill_pay { shift->_aggregate('cust_bill_pay', @_); }
sub cust_credited { shift->_aggregate('cust_credited', @_); }
sub cust_bill_pay_pkgnum { shift->_aggregate('cust_bill_pay_pkgnum', @_); }
sub cust_credited_pkgnum { shift->_aggregate('cust_credited_pkgnum', @_); }
sub cust_bill_pkg { shift->_aggregate('cust_bill_pkg', @_); }
sub cust_bill_pkg_pkgnum { shift->_aggregate('cust_bill_pkg_pkgnum', @_); }
=item tax
Returns the tax amount (see L<FS::cust_bill_pkg>) for this invoice.
=cut
sub tax {
my $self = shift;
my $total = 0;
foreach my $cust_bill ( $self->cust_bill ) {
$total += $cust_bill->tax;
}
$total;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::cust_bill>, L<FS::Record>, schema.html from the base documentation.
=cut
1;
Index: part_event.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- part_event.pm 22 Nov 2008 22:17:26 -0000 1.3
+++ part_event.pm 20 Aug 2009 04:03:34 -0000 1.4
@@ -52,7 +52,7 @@
=item event - event name
-=item eventtable - table name against which this event is triggered; currently "cust_bill" (the traditional invoice events), "cust_main" (customer events) or "cust_pkg (package events)
+=item eventtable - table name against which this event is triggered; currently "cust_bill" (the traditional invoice events), "cust_main" (customer events) or "cust_pkg (package events) (or "cust_statement")
=item check_freq - how often events of this type are checked; currently "1d" (daily) and "1m" (monthly) are recognized. Note that the apprioriate freeside-daily and/or freeside-monthly cron job needs to be in place.
@@ -133,7 +133,7 @@
my $error =
$self->ut_numbern('eventpart')
|| $self->ut_text('event')
- || $self->ut_enum('eventtable', [ 'cust_bill', 'cust_main', 'cust_pkg' ] )
+ || $self->ut_enum('eventtable', [ $self->eventtables ] )
|| $self->ut_enum('check_freq', [ '1d', '1m' ])
|| $self->ut_number('weight')
|| $self->ut_alpha('action')
@@ -273,6 +273,7 @@
'cust_bill' => 'Invoice',
'cust_main' => 'Customer',
'cust_pay_batch' => 'Batch payment',
+ 'cust_statement' => 'Statement', #too general a name here? "Invoice group"?
;
\%hash
@@ -310,6 +311,7 @@
'cust_bill' => 'invnum',
'cust_pkg' => 'pkgnum',
'cust_pay_batch' => 'paybatchnum',
+ 'cust_statement' => 'statementnum',
};
}
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.451
retrieving revision 1.452
diff -u -d -r1.451 -r1.452
--- cust_main.pm 12 Aug 2009 05:22:07 -0000 1.451
+++ cust_main.pm 20 Aug 2009 04:03:34 -0000 1.452
@@ -7251,6 +7251,18 @@
}
+=item cust_statements
+
+Returns all the statements (see L<FS::cust_statement>) for this customer.
+
+=cut
+
+sub cust_statement {
+ my $self = shift;
+ sort { $a->_date <=> $b->_date }
+ qsearch('cust_statement', { 'custnum' => $self->custnum, } )
+}
+
=item cust_credit
Returns all the credits (see L<FS::cust_credit>) for this customer.
More information about the freeside-commits
mailing list