invoice sections by location, #23820
[freeside.git] / FS / FS / cust_bill.pm
index 128aaf7..fc6a7dd 100644 (file)
@@ -110,9 +110,11 @@ Customer info at invoice generation time
 
 =over 4
 
 
 =over 4
 
-=item previous_balance
+=item billing_balance - the customer's balance at the time the invoice was 
+generated (not including charges on this invoice)
 
 
-=item billing_balance
+=item previous_balance - the billing_balance of this customer's previous 
+invoice plus the charges on that invoice
 
 =back
 
 
 =back
 
@@ -1330,6 +1332,8 @@ invoice and all older invoices is greater than the specified amount.
 
 I<notice_name>, if specified, overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required)
 
 
 I<notice_name>, if specified, overrides "Invoice" as the name of the sent document (templates from 10/2009 or newer required)
 
+I<lpr>, if specified, is passed to 
+
 =cut
 
 sub queueable_send {
 =cut
 
 sub queueable_send {
@@ -1354,6 +1358,7 @@ sub send {
   my( $template, $invoice_from, $notice_name );
   my $agentnums = '';
   my $balance_over = 0;
   my( $template, $invoice_from, $notice_name );
   my $agentnums = '';
   my $balance_over = 0;
+  my $lpr = '';
 
   if ( ref($_[0]) ) {
     my $opt = shift;
 
   if ( ref($_[0]) ) {
     my $opt = shift;
@@ -1364,6 +1369,7 @@ sub send {
     $invoice_from = $opt->{'invoice_from'};
     $balance_over = $opt->{'balance_over'} if $opt->{'balance_over'};
     $notice_name = $opt->{'notice_name'};
     $invoice_from = $opt->{'invoice_from'};
     $balance_over = $opt->{'balance_over'} if $opt->{'balance_over'};
     $notice_name = $opt->{'notice_name'};
+    $lpr = $opt->{'lpr'}
   } else {
     $template = scalar(@_) ? shift : '';
     if ( scalar(@_) && $_[0]  ) {
   } else {
     $template = scalar(@_) ? shift : '';
     if ( scalar(@_) && $_[0]  ) {
@@ -1397,10 +1403,12 @@ sub send {
     if ( grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list )
     && ! $self->invoice_noemail;
 
     if ( grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list )
     && ! $self->invoice_noemail;
 
+  $opt{'lpr'} = $lpr;
   #$self->print_invoice(\%opt)
   $self->print(\%opt)
     if grep { $_ eq 'POST' } @invoicing_list; #postal
 
   #$self->print_invoice(\%opt)
   $self->print(\%opt)
     if grep { $_ eq 'POST' } @invoicing_list; #postal
 
+  #this has never been used post-$ORIGINAL_ISP afaik
   $self->fax_invoice(\%opt)
     if grep { $_ eq 'FAX' } @invoicing_list; #fax
 
   $self->fax_invoice(\%opt)
     if grep { $_ eq 'FAX' } @invoicing_list; #fax
 
@@ -1564,14 +1572,16 @@ sub print {
   return if $self->hide;
   my $conf = $self->conf;
 
   return if $self->hide;
   my $conf = $self->conf;
 
-  my( $template, $notice_name );
+  my( $template, $notice_name, $lpr );
   if ( ref($_[0]) ) {
     my $opt = shift;
     $template = $opt->{'template'} || '';
     $notice_name = $opt->{'notice_name'} || 'Invoice';
   if ( ref($_[0]) ) {
     my $opt = shift;
     $template = $opt->{'template'} || '';
     $notice_name = $opt->{'notice_name'} || 'Invoice';
+    $lpr = $opt->{'lpr'}
   } else {
     $template = scalar(@_) ? shift : '';
     $notice_name = 'Invoice';
   } else {
     $template = scalar(@_) ? shift : '';
     $notice_name = 'Invoice';
+    $lpr = '';
   }
 
   my %opt = (
   }
 
   my %opt = (
@@ -1584,7 +1594,11 @@ sub print {
     $self->batch_invoice(\%opt);
   }
   else {
     $self->batch_invoice(\%opt);
   }
   else {
-    do_print $self->lpr_data(\%opt);
+    do_print(
+      $self->lpr_data(\%opt),
+      'agentnum' => $self->cust_main->agentnum,
+      'lpr'      => $lpr,
+    );
   }
 }
 
   }
 }
 
@@ -2029,7 +2043,7 @@ header line only, with the fields:
 
 Agent number, agent name, customer number, first name, last name, address
 line 1, address line 2, city, state, zip, invoice date, invoice number,
 
 Agent number, agent name, customer number, first name, last name, address
 line 1, address line 2, city, state, zip, invoice date, invoice number,
-amount charged, amount due,
+amount charged, amount due, previous balance, due date.
 
 and then, for each line item, three columns containing the package number,
 description, and amount.
 
 and then, for each line item, three columns containing the package number,
 description, and amount.
@@ -2115,12 +2129,16 @@ sub print_csv {
   } elsif ( $format eq 'oneline' ) { #name
   
     my ($previous_balance) = $self->previous; 
   } elsif ( $format eq 'oneline' ) { #name
   
     my ($previous_balance) = $self->previous; 
+    $previous_balance = sprintf('%.2f', $previous_balance);
     my $totaldue = sprintf('%.2f', $self->owed + $previous_balance);
     my @items = map {
     my $totaldue = sprintf('%.2f', $self->owed + $previous_balance);
     my @items = map {
-      ($_->{pkgnum} || ''),
-      $_->{description},
-      $_->{amount}
-    } $self->_items_pkg;
+                      $_->{pkgnum},
+                      $_->{description},
+                      $_->{amount}
+                    }
+                  $self->_items_pkg, #_items_nontax?  no sections or anything
+                                     # with this format
+                  $self->_items_tax;
 
     $csv->combine(
       $cust_main->agentnum,
 
     $csv->combine(
       $cust_main->agentnum,
@@ -2128,6 +2146,7 @@ sub print_csv {
       $self->custnum,
       $cust_main->first,
       $cust_main->last,
       $self->custnum,
       $cust_main->first,
       $cust_main->last,
+      $cust_main->company,
       $cust_main->address1,
       $cust_main->address2,
       $cust_main->city,
       $cust_main->address1,
       $cust_main->address2,
       $cust_main->city,
@@ -2139,6 +2158,8 @@ sub print_csv {
       $self->invnum,
       $self->charged,
       $totaldue,
       $self->invnum,
       $self->charged,
       $totaldue,
+      $previous_balance,
+      $self->due_date2str("%x"),
 
       @items,
     );
 
       @items,
     );
@@ -2249,12 +2270,11 @@ sub print_csv {
                                    '';
           }
 
                                    '';
           }
 
-          my $svc_x = $cust_svc->svc_x or 
-            warn "missing svc_x record for svc#".$cust_svc->svcnum."\n";
+          my @h_label = $cust_svc->label(@dates, 'I');
           push @details, sprintf('01%-9s%-20s%-47s',
             $cust_svc->svcnum,
             $svc_class{$svcpart},
           push @details, sprintf('01%-9s%-20s%-47s',
             $cust_svc->svcnum,
             $svc_class{$svcpart},
-            ($svc_x ? $svc_x->label : ''),
+            $h_label[1],
           );
         } #foreach $cust_svc
       } #if $cust_pkg
           );
         } #foreach $cust_svc
       } #if $cust_pkg
@@ -3120,11 +3140,16 @@ sub _items_payments {
 
     #something more elaborate if $_->amount ne ->cust_pay->paid ?
 
 
     #something more elaborate if $_->amount ne ->cust_pay->paid ?
 
+    my $desc = $self->mt('Payment received').' '.
+               time2str($date_format,$_->cust_pay->_date );
+    $desc   .= $self->mt(' via ' . $_->cust_pay->payby_payinfo_pretty)
+      if ( $self->conf->exists('invoice_payment_details') );
     push @b, {
     push @b, {
-      'description' => $self->mt('Payment received').' '.
-                       time2str($date_format,$_->cust_pay->_date ),
+      'description' => $desc,
       'amount'      => sprintf("%.2f", $_->amount )
     };
       'amount'      => sprintf("%.2f", $_->amount )
     };
+
   }
 
   @b;
   }
 
   @b;
@@ -3427,6 +3452,15 @@ sub search_sql_where {
     push @search, "cust_bill.custnum = $1";
   }
 
     push @search, "cust_bill.custnum = $1";
   }
 
+  #customer classnum
+  if ( $param->{'cust_classnum'} ) {
+    my $classnums = $param->{'cust_classnum'};
+    $classnums = [ $classnums ] if !ref($classnums);
+    $classnums = [ grep /^\d+$/, @$classnums ];
+    push @search, 'cust_main.classnum in ('.join(',',@$classnums).')'
+      if @$classnums;
+  }
+
   #_date
   if ( $param->{_date} ) {
     my($beginning, $ending) = @{$param->{_date}};
   #_date
   if ( $param->{_date} ) {
     my($beginning, $ending) = @{$param->{_date}};