skycatcher modifications for pre-printing invoices, but with today's date
authorivan <ivan>
Sat, 9 Jun 2007 00:43:14 +0000 (00:43 +0000)
committerivan <ivan>
Sat, 9 Jun 2007 00:43:14 +0000 (00:43 +0000)
FS/FS/Cron/bill.pm
FS/FS/cust_main.pm
FS/bin/freeside-daily

index 4d77fd0..9926fea 100644 (file)
@@ -24,6 +24,8 @@ sub bill {
   my($time)= $opt{'d'} ? str2time($opt{'d'}) : $^T;
   $time += $opt{'y'} * 86400 if $opt{'y'};
 
+  my $invoice_time = $opt{'n'} ? $^T : $time;
+
   # select * from cust_main where
   my $where_pkg = <<"END";
     0 < ( select count(*) from cust_pkg
@@ -102,8 +104,9 @@ END
         if $error;
     }
   
-    my $error = $cust_main->bill( 'time'    => $time,
-                                  'resetup' => $opt{'s'},
+    my $error = $cust_main->bill( 'time'         => $time,
+                                  'invoice_time' => $invoice_time,
+                                  'resetup'      => $opt{'s'},
                                 );
     warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error;
   
index 252a5ca..3dbd9c4 100644 (file)
@@ -1815,22 +1815,23 @@ sub agent {
 Generates invoices (see L<FS::cust_bill>) for this customer.  Usually used in
 conjunction with the collect method.
 
-Options are passed as name-value pairs.
+If there is an error, returns the error, otherwise returns false.
 
-Currently available options are:
+Options are passed as name-value pairs.  Currently available options are:
 
-resetup - if set true, re-charges setup fees.
+=over 4
 
-time - bills the customer as if it were that time.  Specified as a UNIX
-timestamp; see L<perlfunc/"time">).  Also see L<Time::Local> and
-L<Date::Parse> for conversion functions.  For example:
+=item resetup - if set true, re-charges setup fees.
+
+=item time - bills the customer as if it were that time.  Specified as a UNIX timestamp; see L<perlfunc/"time">).  Also see L<Time::Local> and L<Date::Parse> for conversion functions.  For example:
 
  use Date::Parse;
  ...
  $cust_main->bill( 'time' => str2time('April 20th, 2001') );
 
+=item invoice_time - used in conjunction with the I<time> option, this option specifies the date of for the generated invoices.  Other calculations, such as whether or not to generate the invoice in the first place, are not affected.
 
-If there is an error, returns the error, otherwise returns false.
+=back
 
 =cut
 
@@ -1863,7 +1864,7 @@ sub bill {
   # no line items] and we're inside a transaciton so nothing else will see it)
   my $cust_bill = new FS::cust_bill ( {
     'custnum' => $self->custnum,
-    '_date'   => $time,
+    '_date'   => ( $options{'invoice_time'} || $time ),
     #'charged' => $charged,
     'charged' => 0,
   } );
index a06a2b1..d5748d6 100755 (executable)
@@ -5,9 +5,8 @@ use Getopt::Std;
 use FS::UID qw(adminsuidsetup);
 
 &untaint_argv; #what it sounds like  (eww)
-#use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y);
 use vars qw(%opt);
-getopts("p:a:d:vsy:", \%opt);
+getopts("p:a:d:vsy:n", \%opt);
 
 my $user = shift or die &usage;
 adminsuidsetup $user;
@@ -69,6 +68,10 @@ the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
       "pretend date" 15 days from whatever was specified by the -d switch
       (or now, if no -d switch was given).
 
+  -n: When used with "-d" and/or "-y", specifies that invoices should be dated
+      with today's date, irregardless of the pretend date used to pre-generate
+      the invoices.
+
   -p: Only process customers with the specified payby (I<CARD>, I<DCRD>, I<CHEK>, I<DCHK>, I<BILL>, I<COMP>, I<LECB>)
 
   -a: Only process customers with the specified agentnum