things are starting to work again, sorta.
[freeside.git] / FS / FS / cust_bill_pay.pm
index e7040d9..921c025 100644 (file)
@@ -1,9 +1,10 @@
-package cust_bill_pay;
+package FS::cust_bill_pay;
 
 use strict;
 use vars qw( @ISA );
 use FS::Record qw( qsearch qsearchs dbh );
-#use FS::cust_bill
+use FS::cust_bill;
+use FS::cust_pay;
 
 @ISA = qw( FS::Record );
 
@@ -106,9 +107,9 @@ sub insert {
   };
 
   my $bill_total = 0;
-  $bill_total += foreach map { $_->amount }
+  $bill_total += $_ foreach map { $_->amount }
     qsearch('cust_bill_pay', { 'invnum' => $self->invnum } );
-  $bill_total += foreach map { $_->amount } 
+  $bill_total += $_ foreach map { $_->amount } 
     qsearch('cust_credit_bill', { 'invnum' => $self->invnum } );
   if ( $bill_total > $cust_bill->charged ) {
     $dbh->rollback if $oldAutoCommit;
@@ -155,29 +156,53 @@ sub check {
   my $error = 
     $self->ut_numbern('billpaynum')
     || $self->ut_number('invnum')
-    || $self->ut_numner('paynum')
+    || $self->ut_number('paynum')
     || $self->ut_money('amount')
     || $self->ut_numbern('_date')
   ;
   return $error if $error;
 
-  $self->_date(time) unless $self->_date;
+  return "amount must be > 0" if $self->amount == 0;
 
+  $self->_date(time) unless $self->_date;
 
   ''; #no error
 }
 
+=item cust_pay 
+
+Returns the payment (see L<FS::cust_pay>)
+
+=cut
+
+sub cust_pay {
+  my $self = shift;
+  qsearchs( 'cust_pay', { 'paynum' => $self->paynum } );
+}
+
+=item cust_bill 
+
+Returns the invoice (see L<FS::cust_bill>)
+
+=cut
+
+sub cust_bill {
+  my $self = shift;
+  qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
+}
+
 =back
 
 =head1 VERSION
 
-$Id: cust_bill_pay.pm,v 1.2 2001-09-01 21:55:06 jeff Exp $
+$Id: cust_bill_pay.pm,v 1.7 2001-09-02 07:49:52 ivan Exp $
 
 =head1 BUGS
 
 Delete and replace methods.
 
-cust_credit_bill isn't checked yet (uncomment around line 111)
+the checks for over-applied payments could be better done like the ones in
+cust_bill_credit
 
 =head1 SEE ALSO