fix more bugs
[freeside.git] / FS / bin / freeside-bill
index 3462fa1..1dce9a1 100755 (executable)
@@ -55,15 +55,19 @@ foreach $cust_main (
   warn "Error billing,  customer #" . $cust_main->getfield('custnum') . 
     ":" . $error if $error;
 
+  if ($main::opt_p) {
+    $cust_main->apply_payments;
+    $error=$cust_main->apply_credits;
+  }
+
   if ($main::opt_c) {
     $error=$cust_main->collect('invoice_time'=>$time,
                                'batch_card' => $main::opt_i ? 'no' : 'yes',
                               );
-    warn "Error collecting customer #" . $cust_main->getfield('custnum') .
-      ":" . $error if $error;
-
-  #sleep 1;
+    warn "Error collecting from customer #" . $cust_main->gcustnum.  ":$error"
+      if $error;
 
+    #sleep 1;
   }
 
 }
@@ -89,7 +93,7 @@ freeside-bill - Command line (crontab, script) interface to customer billing.
 
 =head1 SYNOPSIS
 
-  freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ]
+  freeside-bill [ -c [ -p ] [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ]
 
 =head1 DESCRIPTION
 
@@ -98,6 +102,9 @@ the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
 
   -c: Turn on collecting (you probably want this).
 
+  -p: Apply unapplied payments and credits before collecting (you probably want
+      this too)
+
   -a: Call collect even if there isn't a new invoice (probably a bad idea for
       daily use)
 
@@ -114,7 +121,7 @@ customers.  Otherwise, bills all customers.
 
 =head1 VERSION
 
-$Id: freeside-bill,v 1.7 2001-08-21 09:34:13 ivan Exp $
+$Id: freeside-bill,v 1.8 2001-09-03 22:07:39 ivan Exp $
 
 =head1 BUGS