allow invoice_lines(0) meaning no limit, no padding (see Bug#388)
[freeside.git] / FS / FS / cust_bill.pm
index 0a8d4a4..f157f86 100644 (file)
@@ -373,7 +373,7 @@ sub send {
   #my @print_text = $cust_bill->print_text; #( date )
   my @invoicing_list = $self->cust_main->invoicing_list;
   if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice
-    #false laziness w/FS::cust_pay::delete
+    #false laziness w/FS::cust_pay::delete & fs_signup_server
     #$ENV{SMTPHOSTS} = $smtpmachine;
     $ENV{MAILADDRESS} = $invoice_from;
     my $header = new Mail::Header ( [
@@ -478,6 +478,19 @@ sub realtime_card {
   my $email = $invoicing_list[0];
 
   my( $action1, $action2 ) = split(/\s*\,\s*/, $bop_action );
+
+  my $description = 'Internet Services';
+  if ( $conf->exists('business-onlinepayment-description') ) {
+    my $dtempl = $conf->config('business-onlinepayment-description');
+
+    my $agent = $self->cust_main->agent->agent;
+    my $pkgs = join(', ',
+      map { $_->cust_pkg->part_pkg->pkg }
+        grep { $_->pkgnum } $self->cust_bill_pkg
+    );
+    $description = eval qq("$dtempl");
+
+  }
   
   my $transaction =
     new Business::OnlinePayment( $bop_processor, @bop_options );
@@ -486,7 +499,7 @@ sub realtime_card {
     'login'          => $bop_login,
     'password'       => $bop_password,
     'action'         => $action1,
-    'description'    => 'Internet Services',
+    'description'    => $description,
     'amount'         => $amount,
     'invoice_number' => $self->invnum,
     'customer_id'    => $self->custnum,
@@ -520,7 +533,7 @@ sub realtime_card {
       order_number   => $ordernum,
       amount         => $amount,
       authorization  => $auth,
-      description    => 'Internet Services',
+      description    => $description,
     );
 
     $capture->submit();
@@ -802,11 +815,13 @@ sub print_text {
   my @invoice_template = $conf->config($templatefile)
   or die "cannot load config file $templatefile";
   $invoice_lines = 0;
+  my $wasfunc = 0;
   foreach ( grep /invoice_lines\(\d+\)/, @invoice_template ) { #kludgy
     /invoice_lines\((\d+)\)/;
     $invoice_lines += $1;
+    $wasfunc=1;
   }
-  die "no invoice_lines() functions in template?" unless $invoice_lines;
+  die "no invoice_lines() functions in template?" unless $wasfunc;
   my $invoice_template = new Text::Template (
     TYPE   => 'ARRAY',
     SOURCE => [ map "$_\n", @invoice_template ],
@@ -822,11 +837,14 @@ sub print_text {
   $date = $self->_date;
   $page = 1;
 
-  $total_pages =
-    int( scalar(@FS::cust_bill::buf) / $FS::cust_bill::invoice_lines );
-  $total_pages++
-    if scalar(@FS::cust_bill::buf) % $FS::cust_bill::invoice_lines;
-
+  if ( $FS::cust_bill::invoice_lines ) {
+    $total_pages =
+      int( scalar(@FS::cust_bill::buf) / $FS::cust_bill::invoice_lines );
+    $total_pages++
+      if scalar(@FS::cust_bill::buf) % $FS::cust_bill::invoice_lines;
+  } else {
+    $total_pages = 1;
+  }
 
   #format address (variable for the template)
   my $l = 0;
@@ -860,7 +878,7 @@ sub print_text {
   #and subroutine for the template
 
   sub FS::cust_bill::_template::invoice_lines {
-    my $lines = shift;
+    my $lines = shift or return @buf;
     map { 
       scalar(@buf) ? shift @buf : [ '', '' ];
     }
@@ -887,7 +905,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.24 2002-03-18 21:40:17 ivan Exp $
+$Id: cust_bill.pm,v 1.27 2002-04-13 09:14:07 ivan Exp $
 
 =head1 BUGS