book closing schema changes
[freeside.git] / FS / FS / cust_bill.pm
index 2ca4b52..8b326a5 100644 (file)
@@ -91,6 +91,8 @@ L<Time::Local> and L<Date::Parse> for conversion functions.
 =item printed - how many times this invoice has been printed automatically
 (see L<FS::cust_main/"collect">).
 
+=item closed - books closed flag, empty or `Y'
+
 =back
 
 =head1 METHODS
@@ -120,7 +122,9 @@ no record you ever posted this invoice (which is bad, no?)
 =cut
 
 sub delete {
-  return "Can't remove invoice!"
+  my $self = shift;
+  return "Can't delete closed invoice" if $self->closed =~ /^Y/i;
+  $self->SUPER::delete(@_);
 }
 
 =item replace OLD_RECORD
@@ -160,6 +164,7 @@ sub check {
     || $self->ut_numbern('_date')
     || $self->ut_money('charged')
     || $self->ut_numbern('printed')
+    || $self->ut_enum('closed', [ '', 'Y' ])
   ;
   return $error if $error;
 
@@ -251,7 +256,7 @@ Returns all payment applications (see L<FS::cust_bill_pay>) for this invoice.
 
 sub cust_bill_pay {
   my $self = shift;
-  sort { $a->_date <=> $b->date }
+  sort { $a->_date <=> $b->_date }
     qsearch( 'cust_bill_pay', { 'invnum' => $self->invnum } );
 }
 
@@ -297,6 +302,8 @@ sub owed {
   $balance -= $_->amount foreach ( $self->cust_bill_pay );
   $balance -= $_->amount foreach ( $self->cust_credited );
   $balance = sprintf( "%.2f", $balance);
+  $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
+  $balance;
 }
 
 =item print_text [TIME];
@@ -389,8 +396,12 @@ sub print_text {
 
     #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",$_->cust_credit->_date) .")",
+      "Credit #". $_->crednum. " (". time2str("%x",$_->cust_credit->_date) .")".
+        $reason,
       $money_char. sprintf("%10.2f",$_->amount)
     ];
   }
@@ -408,7 +419,7 @@ sub print_text {
 
     push @buf,[
       "Payment received ". time2str("%x",$_->cust_pay->_date ),
-      $money_char. sprintf("%10.2f",$_->paid )
+      $money_char. sprintf("%10.2f",$_->amount )
     ];
   }
 
@@ -489,7 +500,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.10 2001-09-02 01:27:10 ivan Exp $
+$Id: cust_bill.pm,v 1.15 2002-01-28 06:57:23 ivan Exp $
 
 =head1 BUGS