cust_main exports! cust_main-exports config option and part_export/cust_http.pm...
authorivan <ivan>
Wed, 30 Jun 2010 20:42:54 +0000 (20:42 +0000)
committerivan <ivan>
Wed, 30 Jun 2010 20:42:54 +0000 (20:42 +0000)
FS/FS/Conf.pm
FS/FS/cust_main.pm
FS/FS/part_export/cust_http.pm [new file with mode: 0644]
FS/FS/part_export/http.pm
httemplate/config/config-process.cgi
httemplate/config/config.cgi

index 853a951..43d604c 100644 (file)
@@ -3782,6 +3782,32 @@ and customer address. Include units.',
     'type'        => 'checkbox',
   },
 
+  {
+    'key'         => 'cust_main-exports',
+    'section'     => '',
+    'description' => 'Export(s) to call on cust_main insert, modification and deletion.',
+    'type'        => 'select-sub',
+    'multiple'    => 1,
+    'options_sub' => sub {
+      require FS::Record;
+      require FS::part_export;
+      my @part_export =
+        map { qsearch( 'part_export', {exporttype => $_ } ) }
+          keys %{FS::part_export::export_info('cust_main')};
+      map { $_->exportnum => $_->exporttype.' to '.$_->machine } @part_export;
+    },
+    'option_sub'  => sub {
+      require FS::Record;
+      require FS::part_export;
+      my $part_export = FS::Record::qsearchs(
+        'part_export', { 'exportnum' => shift }
+      );
+      $part_export
+        ? $part_export->exporttype.' to '.$part_export->machine
+        : '';
+    },
+  },
+
   { key => "apacheroot", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachine", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachines", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
index 6d879bc..9c16294 100644 (file)
@@ -62,6 +62,7 @@ use FS::queue;
 use FS::part_pkg;
 use FS::part_event;
 use FS::part_event_condition;
+use FS::part_export;
 #use FS::cust_event;
 use FS::type_pkgs;
 use FS::payment_gateway;
@@ -546,6 +547,45 @@ sub insert {
     }
   }
 
+  # cust_main exports!
+  warn "  exporting\n" if $DEBUG > 1;
+
+  my $export_args = $options{'export_args'} || [];
+
+  my @part_export =
+    map qsearch( 'part_export', {exportnum=>$_} ),
+      $conf->config('cust_main-exports'); #, $agentnum
+
+  foreach my $part_export ( @part_export ) {
+    my $error = $part_export->export_insert($self, @$export_args);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "exporting to ". $part_export->exporttype.
+             " (transaction rolled back): $error";
+    }
+  }
+
+  #foreach my $depend_jobnum ( @$depend_jobnums ) {
+  #    warn "[$me] inserting dependancies on supplied job $depend_jobnum\n"
+  #      if $DEBUG;
+  #    foreach my $jobnum ( @jobnums ) {
+  #      my $queue = qsearchs('queue', { 'jobnum' => $jobnum } );
+  #      warn "[$me] inserting dependancy for job $jobnum on $depend_jobnum\n"
+  #        if $DEBUG;
+  #      my $error = $queue->depend_insert($depend_jobnum);
+  #      if ( $error ) {
+  #        $dbh->rollback if $oldAutoCommit;
+  #        return "error queuing job dependancy: $error";
+  #      }
+  #    }
+  #  }
+  #
+  #}
+  #
+  #if ( exists $options{'jobnums'} ) {
+  #  push @{ $options{'jobnums'} }, @jobnums;
+  #}
+
   warn "  insert complete; committing transaction\n"
     if $DEBUG > 1;
 
@@ -1340,6 +1380,23 @@ sub delete {
     return $error;
   }
 
+  # cust_main exports!
+
+  #my $export_args = $options{'export_args'} || [];
+
+  my @part_export =
+    map qsearch( 'part_export', {exportnum=>$_} ),
+      $conf->config('cust_main-exports'); #, $agentnum
+
+  foreach my $part_export ( @part_export ) {
+    my $error = $part_export->export_delete( $self ); #, @$export_args);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "exporting to ". $part_export->exporttype.
+             " (transaction rolled back): $error";
+    }
+  }
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
 
@@ -1478,6 +1535,23 @@ sub replace {
     }
   }
 
+  # cust_main exports!
+
+  my $export_args = $options{'export_args'} || [];
+
+  my @part_export =
+    map qsearch( 'part_export', {exportnum=>$_} ),
+      $conf->config('cust_main-exports'); #, $agentnum
+
+  foreach my $part_export ( @part_export ) {
+    my $error = $part_export->export_replace( $self, $old, @$export_args);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "exporting to ". $part_export->exporttype.
+             " (transaction rolled back): $error";
+    }
+  }
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
 
diff --git a/FS/FS/part_export/cust_http.pm b/FS/FS/part_export/cust_http.pm
new file mode 100644 (file)
index 0000000..d2781f6
--- /dev/null
@@ -0,0 +1,43 @@
+package FS::part_export::cust_http;
+
+use vars qw( @ISA %info );
+use FS::part_export::http;
+use Tie::IxHash;
+
+@ISA = qw( FS::part_export::http );
+
+$options{'insert_data'}->{'default'} = join("\n",
+  "action  'insert'",
+  "custnum \$cust_main->custnum",
+  "first   \$cust_main->first",
+  "last    \$cust_main->get('last')",
+  ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax  last ) ),
+  "email   \$cust_main->invoicing_list_emailonly_scalar",
+);
+$options{'delete_data'}->{'default'} = join("\n",
+  "action  'delete'",
+  "custnum \$cust_main->custnum",
+);
+$options{'replace_data'}->{'default'} = join("\n",
+  "action  'replace'",
+  "custnum \$new_cust_main->custnum",
+  "first   \$new_cust_main->first",
+  "last    \$new_cust_main->get('last')",
+  ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax  last ) ),
+  "email   \$new_cust_main->invoicing_list_emailonly_scalar",
+);
+
+%info = (
+  'svc'     => 'cust_main',
+  'desc'    => 'Send an HTTP or HTTPS GET or POST request, for customers.',
+  'options' => \%options,
+  'notes'   => <<'END'
+Send an HTTP or HTTPS GET or POST to the specified URL on customer addition,
+modification and deletion.  For HTTPS support,
+<a href="http://search.cpan.org/dist/Crypt-SSLeay">Crypt::SSLeay</a>
+or <a href="http://search.cpan.org/dist/IO-Socket-SSL">IO::Socket::SSL</a>
+is required.
+END
+);
+
+1;
index 55d8329..9a216c1 100644 (file)
@@ -1,12 +1,10 @@
 package FS::part_export::http;
 
-use vars qw(@ISA %info);
+use base qw( FS::part_export );
+use vars qw( %options %info );
 use Tie::IxHash;
-use FS::part_export;
 
-@ISA = qw(FS::part_export);
-
-tie my %options, 'Tie::IxHash',
+tie %options, 'Tie::IxHash',
   'method' => { label   =>'Method',
                 type    =>'select',
                 #options =>[qw(POST GET)],
@@ -66,6 +64,10 @@ sub _export_command {
 
   return unless $self->option("${action}_data");
 
+  my $cust_main = $svc_x->table eq 'cust_main'
+                    ? $svc_x
+                    : $svc_x->cust_svc->cust_pkg->cust_main;
+
   $self->http_queue( $svc_x->svcnum,
     $self->option('method'),
     $self->option('url'),
@@ -85,6 +87,10 @@ sub _export_replace {
 
   return unless $self->option('replace_data');
 
+  my $new_cust_main = $new->table eq 'cust_main'
+                        ? $new
+                        : $new->cust_svc->cust_pkg->cust_main;
+
   $self->http_queue( $svc_x->svcnum,
     $self->option('method'),
     $self->option('url'),
@@ -100,10 +106,8 @@ sub _export_replace {
 
 sub http_queue {
   my($self, $svcnum) = (shift, shift);
-  my $queue = new FS::queue {
-    'svcnum' => $svcnum,
-    'job'    => "FS::part_export::http::http",
-  };
+  my $queue = new FS::queue { 'job' => "FS::part_export::http::http" };
+  $queue->svcnum($svcnum) if $svcnum;
   $queue->insert( @_ );
 }
 
index c2b11b8..4e1c85a 100644 (file)
@@ -73,7 +73,7 @@
 %       my $record = qsearchs($table, { $pkey => $key });
 %       my $value = $record ? "$key: ".$record->$namecol() : $key;
         configCell.innerHTML = <% $value |js_string %>;
-%     } elsif ( $type eq 'select-sub' ) {
+%     } elsif ( $type eq 'select-sub' && ! $i->multiple ) {
         configCell.innerHTML =
           <% $conf->config($i->key, $agentnum) |js_string %> + ': ' +
           <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>;
index ce96bc1..cde4838 100644 (file)
@@ -131,7 +131,11 @@ Setting <b><% $key %></b>
 
 %   } elsif ( $type eq 'select-sub' ) { 
 
-  <select name="<% "$key$n" %>"><option value="">
+  <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
+
+%     unless ( $config_item->multiple ) {
+        <option value="">
+%     }
 
 %     my %options = &{$config_item->options_sub};
 %     my @options = sort { $a <=> $b } keys %options;
@@ -139,7 +143,17 @@ Setting <b><% $key %></b>
 %     foreach my $value ( @options ) {
 %       local($^W)=0; next if $saw{$value}++;
 
-    <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
+        <option value="<% $value %>"
+
+%         if ( $value eq $conf->config($key, $agentnum)
+%              || ( $config_item->multiple
+%                   && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
+
+            SELECTED
+
+%         }
+
+        ><% $value %>: <% $options{$value} %>
 
 %     } 
 %     my $curvalue = $conf->config($key, $agentnum);