use FS::cust_credit;
use FS::cust_pay;
use FS::cust_pkg;
+use FS::cust_credit_bill;
@ISA = qw( FS::Record );
=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).
+Depreciated. See the cust_credited method.
+
+ #Returns a list consisting of the total previous credited (see
+ #L<FS::cust_credit>) and unapplied for this customer, followed by the previous
+ #outstanding credits (FS::cust_credit objects).
=cut
sub cust_credit {
- my $self = shift;
- my $total = 0;
- my @cust_credit = sort { $a->_date <=> $b->_date }
- grep { $_->credited != 0 && $_->_date < $self->_date }
- qsearch('cust_credit', { 'custnum' => $self->custnum } )
- ;
- foreach (@cust_credit) { $total += $_->credited; }
- $total, @cust_credit;
+ use Carp;
+ croak "FS::cust_bill->cust_credit depreciated; see ".
+ "FS::cust_bill->cust_credit_bill";
+ #my $self = shift;
+ #my $total = 0;
+ #my @cust_credit = sort { $a->_date <=> $b->_date }
+ # grep { $_->credited != 0 && $_->_date < $self->_date }
+ # qsearch('cust_credit', { 'custnum' => $self->custnum } )
+ #;
+ #foreach (@cust_credit) { $total += $_->credited; }
+ #$total, @cust_credit;
}
=item cust_pay
-Returns all payments (see L<FS::cust_pay>) for this invoice.
+Depreciated. See the cust_bill_pay method.
+
+#Returns all payments (see L<FS::cust_pay>) for this invoice.
=cut
sub cust_pay {
+ use Carp;
+ croak "FS::cust_bill->cust_pay depreciated; see FS::cust_bill->cust_bill_pay";
+ #my $self = shift;
+ #sort { $a->_date <=> $b->_date }
+ # qsearch( 'cust_pay', { 'invnum' => $self->invnum } )
+ #;
+}
+
+=item cust_bill_pay
+
+Returns all payment applications (see L<FS::cust_bill_pay>) for this invoice.
+
+=cut
+
+sub cust_bill_pay {
+ my $self = shift;
+ sort { $a->_date <=> $b->date }
+ qsearch( 'cust_bill_pay', { 'invnum' => $self->invnum } );
+}
+
+=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_pay', { 'invnum' => $self->invnum } )
+ qsearch( 'cust_credit_bill', { 'invnum' => $self->invnum } )
;
}
=item owed
Returns the amount owed (still outstanding) on this invoice, which is charged
-minus all payments (see L<FS::cust_pay>).
+minus all payment applications (see L<FS::cust_bill_pay>) and credit
+applications (see L<FS::cust_credit_bill>).
=cut
sub owed {
my $self = shift;
my $balance = $self->charged;
- $balance -= $_->paid foreach ( $self->cust_pay );
- $balance;
+ $balance -= $_->amount foreach ( $self->cust_bill_pay );
+ $balance -= $_->amount foreach ( $self->cust_credited );
+ $balance = sprintf( "%.2f", $balance);
}
=item print_text [TIME];
unless $cust_main->payname;
my( $pr_total, @pr_cust_bill ) = $self->previous; #previous balance
- my( $cr_total, @cr_cust_credit ) = $self->cust_credit; #credits
- my $balance_due = $self->owed + $pr_total - $cr_total;
-
- #
+# my( $cr_total, @cr_cust_credit ) = $self->cust_credit; #credits
+ #my $balance_due = $self->owed + $pr_total - $cr_total;
+ my $balance_due = $self->owed + $pr_total;
#my @collect = ();
#my($description,$amount);
push @buf,['',''];
#credits
- foreach ( @cr_cust_credit ) {
+ foreach ( $self->cust_credited ) {
+
+ #something more elaborate if $_->amount ne $_->cust_credit->credited ?
+
+ my $reason = substr($_->cust_credit->reason,0,32);
+ $reason .= '...' if length($reason) < length($_->cust_credit->reason);
+ $reason = " ($reason) " if $reason;
push @buf,[
- "Credit #". $_->crednum. " (" . time2str("%x",$_->_date) .")",
- $money_char. sprintf("%10.2f",$_->credited)
+ "Credit #". $_->crednum. " (". time2str("%x",$_->cust_credit->_date) .")".
+ $reason,
+ $money_char. sprintf("%10.2f",$_->amount)
];
}
+ #foreach ( @cr_cust_credit ) {
+ # push @buf,[
+ # "Credit #". $_->crednum. " (" . time2str("%x",$_->_date) .")",
+ # $money_char. sprintf("%10.2f",$_->credited)
+ # ];
+ #}
#get & print payments
- foreach ( $self->cust_pay ) {
+ foreach ( $self->cust_bill_pay ) {
+
+ #something more elaborate if $_->amount ne ->cust_pay->paid ?
+
push @buf,[
- "Payment received ". time2str("%x",$_->_date ),
- $money_char. sprintf("%10.2f",$_->paid )
+ "Payment received ". time2str("%x",$_->cust_pay->_date ),
+ $money_char. sprintf("%10.2f",$_->amount )
];
}
#balance due
push @buf,['','-----------'];
push @buf,['Balance Due', $money_char.
- sprintf("%10.2f",$self->owed + $pr_total - $cr_total ) ];
+ sprintf("%10.2f", $balance_due ) ];
#setup template variables
=head1 VERSION
-$Id: cust_bill.pm,v 1.8 2001-08-03 20:34:28 jeff Exp $
+$Id: cust_bill.pm,v 1.12 2001-10-15 12:16:41 ivan Exp $
=head1 BUGS
=head1 SEE ALSO
-L<FS::Record>, L<FS::cust_main>, L<FS::cust_pay>, L<FS::cust_bill_pkg>,
-L<FS::cust_credit>, schema.html from the base documentation.
+L<FS::Record>, L<FS::cust_main>, L<FS::cust_bill_pay>, L<FS:;cust_pay>,
+L<FS::cust_bill_pkg>, L<FS::cust_bill_credit>, schema.html from the base
+documentation.
=cut