default for customers with no invoices
[freeside.git] / FS / FS / cust_bill.pm
index 258b32e..296c8b6 100644 (file)
@@ -352,7 +352,11 @@ sub send {
   my @print_text = $self->print_text('', $template);
   my @invoicing_list = $self->cust_main->invoicing_list;
 
-  if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice
+  if ( grep { $_ ne 'POST' } @invoicing_list or !@invoicing_list  ) { #email
+
+    #better to notify this person than silence
+    @invoicing_list = ($invoice_from) unless @invoicing_list;
+
     #false laziness w/FS::cust_pay::delete & fs_signup_server && ::realtime_card
     #$ENV{SMTPHOSTS} = $smtpmachine;
     $ENV{MAILADDRESS} = $invoice_from;
@@ -377,7 +381,7 @@ sub send {
 
   }
 
-  if ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { #postal
+  if ( grep { $_ eq 'POST' } @invoicing_list ) { #postal
     open(LPR, "|$lpr")
       or return "Can't open pipe to $lpr: $!";
     print LPR @print_text;
@@ -510,10 +514,13 @@ sub send_csv {
         time2str("%x", $cust_bill_pkg->edate),
       );
 
-    } else { #pkgnum Tax
+    } else { #pkgnum tax
       next unless $cust_bill_pkg->setup != 0;
+      my $itemdesc = defined $cust_bill_pkg->dbdef_table->column('itemdesc')
+                       ? ( $cust_bill_pkg->itemdesc || 'Tax' )
+                       : 'Tax';
       ($pkg, $setup, $recur, $sdate, $edate) =
-        ( 'Tax', sprintf("%10.2f",$cust_bill_pkg->setup), '', '', '' );
+        ( $itemdesc, sprintf("%10.2f",$cust_bill_pkg->setup), '', '', '' );
     }
 
     $csv->combine(
@@ -858,7 +865,9 @@ sub print_text {
   }
 
   #new charges
-  foreach ( $self->cust_bill_pkg ) {
+  foreach ( ( grep {   $_->pkgnum } $self->cust_bill_pkg ),  #packages first
+            ( grep { ! $_->pkgnum } $self->cust_bill_pkg ),  #then taxes
+  ) {
 
     if ( $_->pkgnum ) {
 
@@ -882,8 +891,11 @@ sub print_text {
           map { [ "  ". $_->[0]. ": ". $_->[1], '' ] } $cust_pkg->labels;
       }
 
-    } else { #pkgnum Tax
-      push @buf,["Tax", $money_char. sprintf("%10.2f",$_->setup) ] 
+    } else { #pkgnum tax
+      my $itemdesc = defined $_->dbdef_table->column('itemdesc')
+                     ? ( $_->itemdesc || 'Tax' )
+                     : 'Tax';
+      push @buf,[$itemdesc, $money_char. sprintf("%10.2f",$_->setup) ] 
         if $_->setup != 0;
     }
   }
@@ -1031,7 +1043,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.45 2002-09-17 10:21:47 ivan Exp $
+$Id: cust_bill.pm,v 1.47 2002-10-04 12:09:21 ivan Exp $
 
 =head1 BUGS