diff options
author | jeff <jeff> | 2001-09-01 21:52:20 +0000 |
---|---|---|
committer | jeff <jeff> | 2001-09-01 21:52:20 +0000 |
commit | 6412f71a3557249225abf5eb2096ebad1729c585 (patch) | |
tree | e8365251d39c29387ba68dce8a3fb56564d407b7 /FS | |
parent | cdd5aa1d86cd5b266e02bed58570c97c2d7698ba (diff) |
add cust_credit_bill relating multiple invoices to credits
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_bill.pm | 32 | ||||
-rw-r--r-- | FS/FS/cust_credit.pm | 23 | ||||
-rw-r--r-- | FS/FS/cust_credit_bill.pm | 146 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 3 | ||||
-rw-r--r-- | FS/MANIFEST | 1 |
5 files changed, 196 insertions, 9 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 4ffb8e210..4c1617f0e 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -11,6 +11,7 @@ use FS::cust_bill_pkg; use FS::cust_credit; use FS::cust_pay; use FS::cust_pkg; +use FS::cust_credit_bill; @ISA = qw( FS::Record ); @@ -204,8 +205,8 @@ sub cust_bill_pkg { =item cust_credit Returns a list consisting of the total previous credited (see -L<FS::cust_credit>) for this customer, followed by the previous outstanding -credits (FS::cust_credit objects). +L<FS::cust_credit>) and unapplied for this customer, followed by the previous +outstanding credits (FS::cust_credit objects). =cut @@ -233,6 +234,19 @@ sub cust_pay { ; } +=item cust_credited + +Returns all applied credits (see L<FS::cust_credit_bill>) for this invoice. + +=cut + +sub cust_credited { + my $self = shift; + sort { $a->_date <=> $b->_date } + qsearch( 'cust_credit_bill', { 'invnum' => $self->invnum } ) + ; +} + =item tax Returns the tax amount (see L<FS::cust_bill_pkg>) for this invoice. @@ -251,7 +265,8 @@ sub tax { =item owed Returns the amount owed (still outstanding) on this invoice, which is charged -minus all payments (see L<FS::cust_pay>). +minus all payments (see L<FS::cust_pay>) and applied credits +(see L<FS::cust_credit_bill>). =cut @@ -259,7 +274,8 @@ sub owed { my $self = shift; my $balance = $self->charged; $balance -= $_->paid foreach ( $self->cust_pay ); - $balance; + $balance -= $_->amount foreach ( $self->cust_credited ); + $balance = sprintf( "%.2f", $balance); } =item print_text [TIME]; @@ -349,6 +365,12 @@ sub print_text { push @buf,['','']; #credits + foreach ( $self->cust_credited ) { + push @buf,[ + "Credit #". $_->crednum. " (" . time2str("%x",$_->_date) .")", + $money_char. sprintf("%10.2f",$_->amount) + ]; + } foreach ( @cr_cust_credit ) { push @buf,[ "Credit #". $_->crednum. " (" . time2str("%x",$_->_date) .")", @@ -441,7 +463,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.8 2001-08-03 20:34:28 jeff Exp $ +$Id: cust_bill.pm,v 1.9 2001-09-01 21:52:19 jeff Exp $ =head1 BUGS diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index d6de27c64..ec3a7ce26 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -6,6 +6,7 @@ use FS::UID qw( getotaker ); use FS::Record qw( qsearch qsearchs ); use FS::cust_main; use FS::cust_refund; +use FS::cust_credit_bill; @ISA = qw( FS::Record ); @@ -132,10 +133,25 @@ sub cust_refund { ; } +=item cust_credit_bill + +Returns all application to invoices (see L<FS::cust_credit_bill>) for this +credit. + +=cut + +sub cust_credit_bill { + my $self = shift; + sort { $a->_date <=> $b->_date } + qsearch( 'cust_credit_bill', { 'crednum' => $self->crednum } ) + ; +} + =item credited Returns the amount of this credit that is still outstanding; which is -amount minus all refunds (see L<FS::cust_refund>). +amount minus all refunds (see L<FS::cust_refund>) and applications to +invoices (see L<FS::cust_credit_bill>). =cut @@ -143,14 +159,15 @@ sub credited { my $self = shift; my $amount = $self->amount; $amount -= $_->refund foreach ( $self->cust_refund ); - $amount; + $amount -= $_->amount foreach ( $self->cust_credit_bill ); + sprintf( "%.2f", $amount ); } =back =head1 VERSION -$Id: cust_credit.pm,v 1.8 2001-08-26 05:06:19 ivan Exp $ +$Id: cust_credit.pm,v 1.9 2001-09-01 21:52:19 jeff Exp $ =head1 BUGS diff --git a/FS/FS/cust_credit_bill.pm b/FS/FS/cust_credit_bill.pm new file mode 100644 index 000000000..be3d54897 --- /dev/null +++ b/FS/FS/cust_credit_bill.pm @@ -0,0 +1,146 @@ +package FS::cust_credit_bill; + +use strict; +use vars qw( @ISA ); +use FS::UID qw( getotaker ); +use FS::Record qw( qsearch qsearchs ); +use FS::cust_main; +use FS::cust_refund; +use FS::cust_credit; +use FS::cust_bill; + +@ISA = qw( FS::Record ); + +=head1 NAME + +FS::cust_credit_bill - Object methods for cust_credit_bill records + +=head1 SYNOPSIS + + use FS::cust_credit_bill; + + $record = new FS::cust_credit_bill \%hash; + $record = new FS::cust_credit_bill { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::cust_credit_bill object represents application of a credit (see +L<FS::cust_credit>) to a customer bill (see L<FS::cust_bill>). FS::cust_credit +inherits from FS::Record. The following fields are currently supported: + +=over 4 + +=item crednum - primary key; credit being applied + +=item invnum - invoice to which credit is applied (see L<FS::cust_bill>) + +=item amount - amount of the credit applied + +=item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see +L<Time::Local> and L<Date::Parse> for conversion functions. + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new cust_credit_bill. To add the cust_credit_bill to the database, +see L<"insert">. + +=cut + +sub table { 'cust_credit_bill'; } + +=item insert + +Adds this cust_credit_bill to the database ("Posts" all or part of a credit). +If there is an error, returns the error, otherwise returns false. + +=item delete + +Currently unimplemented. + +=cut + +sub delete { + return "Can't unapply credit!" +} + +=item replace OLD_RECORD + +Application of credits may not be modified. + +=cut + +sub replace { + return "Can't modify application of credit!" +} + +=item check + +Checks all fields to make sure this is a valid credit application. 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_number('crednum') + || $self->ut_number('invnum') + || $self->ut_numbern('_date') + || $self->ut_money('amount') + ; + return $error if $error; + + return "Unknown credit" + unless my $cust_credit = + qsearchs( 'cust_credit', { 'crednum' => $self->crednum } ); + + return "Unknown invoice" + unless my $cust_bill = + qsearchs( 'cust_bill', { 'invnum' => $self->invnum } ); + + $self->_date(time) unless $self->_date; + + return "Cannot apply more than remaining value of credit memo" + unless $self->amount <= $cust_credit->credited; + + return "Cannot apply more than remaining value of invoice" + unless $self->amount <= $cust_bill->owed; + + ''; #no error +} + +=back + +=head1 VERSION + +$Id: cust_credit_bill.pm,v 1.1 2001-09-01 21:52:19 jeff Exp $ + +=head1 BUGS + +The delete method. + +=head1 SEE ALSO + +L<FS::Record>, L<FS::cust_refund>, L<FS::cust_bill>, schema.html from the base +documentation. + +=cut + +1; + diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 31f6d5e3e..382cc492d 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -28,6 +28,7 @@ use FS::part_referral; use FS::cust_main_county; use FS::agent; use FS::cust_main_invoice; +use FS::cust_credit_bill; use FS::prepay_credit; @ISA = qw( FS::Record ); @@ -1398,7 +1399,7 @@ sub rebuild_fuzzyfiles { =head1 VERSION -$Id: cust_main.pm,v 1.23 2001-09-01 20:11:07 ivan Exp $ +$Id: cust_main.pm,v 1.24 2001-09-01 21:52:20 jeff Exp $ =head1 BUGS diff --git a/FS/MANIFEST b/FS/MANIFEST index fa51b21b6..a8c080b60 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -13,6 +13,7 @@ FS/agent_type.pm FS/cust_bill.pm FS/cust_bill_pkg.pm FS/cust_credit.pm +FS/cust_credit_bill.pm FS/cust_main.pm FS/cust_main_county.pm FS/cust_main_invoice.pm |