Multi-System Billing:
authorjayce <jayce>
Thu, 27 Sep 2007 18:24:33 +0000 (18:24 +0000)
committerjayce <jayce>
Thu, 27 Sep 2007 18:24:33 +0000 (18:24 +0000)
with a -m flag, daily will queue billing jobs instead of running each.  freeside-queued will then pick it up, allowing multiple simultaneous jobs to run, as well as multiple machines.
Also adds a 'Secure' column to the queue system, allowing for billing jobs to define themselves as 'secure only' in cases where a box might be using the encryption.  This allows you to
 run secure only jobs (such as a collect) on boxes that can.

FS/FS/Cron/bill.pm
FS/FS/Schema.pm
FS/FS/cust_main.pm
FS/bin/freeside-daily

index 1a6c4a7..38fbae5 100644 (file)
@@ -44,7 +44,7 @@ sub bill {
                   )
         )
 END
-
+  
   my $where_event = join(' OR ', map {
     my $eventtable = $_;
 
@@ -76,7 +76,7 @@ END
 
   my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ).
                   "( $where_pkg OR $where_event )";
-
+  
   my @cust_main;
   if ( @ARGV ) {
     @cust_main = map { qsearchs('cust_main', { custnum => $_, %search } ) } @ARGV
@@ -95,12 +95,23 @@ END
 
   }
   
-  foreach my $cust_main ( @cust_main ) {
+  my($cust_main,%saw);
+  foreach $cust_main ( @cust_main ) {
 
     if ( $opt{'m'} ) {
 
-      die "XXX multi-process mode not yet completed";
       #add job to queue that calls bill_and_collect with options
+        my $queue = new FS::queue {
+          'job'    => 'FS::cust_main::queued_bill',
+          'secure' => 'Y',
+        };
+        my $error = $queue->insert(
+        'custnum'      =>  $cust_main->custnum,
+        'time'         => $time,
+        'invoice_time' => $invoice_time,
+        'check_freq'   => $check_freq,
+        'resetup'      => $opt{'s'} ? $opt{'s'} : 0,
+      );
 
     } else {
 
@@ -112,7 +123,7 @@ END
       );
 
     }
-
+  
   }
 
 }
index 3084e36..e147e68 100644 (file)
@@ -1156,6 +1156,7 @@ sub tables_hashref {
         'status', 'varchar', '', $char_d, '', '', 
         'statustext', 'text', 'NULL', '', '', '', 
         'svcnum', 'int', 'NULL', '', '', '', 
+        'secure',  'char', 'NULL', 1, '', '', # Y = recur tax exempt
       ],
       'primary_key' => 'jobnum',
       'unique'      => [],
index 6512888..9627f9f 100644 (file)
@@ -5822,6 +5822,16 @@ sub _agent_plandata {
 
 }
 
+sub queued_bill {
+  ## actual sub, not a method, designed to be called from the queue.
+  ## sets up the customer, and calls the bill_and_collect
+  my (%args) = @_; #, ($time, $invoice_time, $check_freq, $resetup) = @_;
+  my $cust_main = qsearchs( 'cust_main', { custnum => $args{'custnum'} } );
+      $cust_main->bill_and_collect(
+        %args,
+      );
+}
+
 =back
 
 =head1 BUGS
index f0ec9f0..fb855b7 100755 (executable)
@@ -6,7 +6,7 @@ use FS::UID qw(adminsuidsetup);
 
 &untaint_argv; #what it sounds like  (eww)
 use vars qw(%opt);
-getopts("p:a:d:vl:sy:n", \%opt);
+getopts("p:a:d:vl:sy:nm", \%opt);
 
 my $user = shift or die &usage;
 adminsuidsetup $user;
@@ -55,7 +55,7 @@ freeside-daily - Run daily billing and invoice collection events.
 
 =head1 SYNOPSIS
 
-  freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] [ -l level ] user [ custnum custnum ... ]
+  freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] [ -l level ] [ -m ]user [ custnum custnum ... ]
 
 =head1 DESCRIPTION