Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / cust_bill.pm
index e4b2df4..fc6a7dd 100644 (file)
@@ -110,9 +110,11 @@ Customer info at invoice generation time
 
 =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
 
@@ -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<lpr>, if specified, is passed to 
+
 =cut
 
 sub queueable_send {
@@ -1354,6 +1358,7 @@ sub send {
   my( $template, $invoice_from, $notice_name );
   my $agentnums = '';
   my $balance_over = 0;
+  my $lpr = '';
 
   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'};
+    $lpr = $opt->{'lpr'}
   } 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;
 
+  $opt{'lpr'} = $lpr;
   #$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
 
@@ -1564,14 +1572,16 @@ sub print {
   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';
+    $lpr = $opt->{'lpr'}
   } else {
     $template = scalar(@_) ? shift : '';
     $notice_name = 'Invoice';
+    $lpr = '';
   }
 
   my %opt = (
@@ -1584,7 +1594,11 @@ sub print {
     $self->batch_invoice(\%opt);
   }
   else {
-    do_print $self->lpr_data(\%opt);
+    do_print(
+      $self->lpr_data(\%opt),
+      'agentnum' => $self->cust_main->agentnum,
+      'lpr'      => $lpr,
+    );
   }
 }
 
@@ -2118,10 +2132,13 @@ sub print_csv {
     $previous_balance = sprintf('%.2f', $previous_balance);
     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,
@@ -2129,6 +2146,7 @@ sub print_csv {
       $self->custnum,
       $cust_main->first,
       $cust_main->last,
+      $cust_main->company,
       $cust_main->address1,
       $cust_main->address2,
       $cust_main->city,
@@ -3122,11 +3140,16 @@ sub _items_payments {
 
     #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, {
-      'description' => $self->mt('Payment received').' '.
-                       time2str($date_format,$_->cust_pay->_date ),
+      'description' => $desc,
       'amount'      => sprintf("%.2f", $_->amount )
     };
+
   }
 
   @b;
@@ -3429,6 +3452,15 @@ sub search_sql_where {
     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}};