skycatcher modifications for pre-printing invoices, but with today's date
[freeside.git] / FS / FS / cust_main.pm
index 708f014..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:
+
+=over 4
 
-resetup - if set true, re-charges setup fees.
+=item resetup - if set true, re-charges setup fees.
 
-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 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,
   } );
@@ -3025,8 +3026,19 @@ sub realtime_refund_bop {
     if length($auth); #echeck/ACH transactions have an order # but no auth
                       #(at least with authorize.net)
 
+  my $disable_void_after;
+  if ($conf->exists('disable_void_after')
+      && $conf->config('disable_void_after') =~ /^(\d+)$/) {
+    $disable_void_after = $1;
+  }
+
   #first try void if applicable
-  if ( $cust_pay && $cust_pay->paid == $amount ) { #and check dates?
+  if ( $cust_pay && $cust_pay->paid == $amount
+    && (
+      ( not defined($disable_void_after) )
+      || ( time < ($cust_pay->_date + $disable_void_after ) )
+    )
+  ) {
     warn "  attempting void\n" if $DEBUG > 1;
     my $void = new Business::OnlinePayment( $processor, @bop_options );
     $void->content( 'action' => 'void', %content );