summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Conf.pm4
-rw-r--r--FS/FS/part_export/cust_location_http.pm111
2 files changed, 113 insertions, 2 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 2a5bffd..3796624 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -5333,7 +5333,7 @@ and customer address. Include units.',
my @part_export =
map { qsearch( 'part_export', {exporttype => $_ } ) }
keys %{FS::part_export::export_info('cust_location')};
- map { $_->exportnum => $_->exporttype.' to '.$_->machine } @part_export;
+ map { $_->exportnum => $_->exportname } @part_export;
},
'option_sub' => sub {
require FS::Record;
@@ -5342,7 +5342,7 @@ and customer address. Include units.',
'part_export', { 'exportnum' => shift }
);
$part_export
- ? $part_export->exporttype.' to '.$part_export->machine
+ ? $part_export->exportname
: '';
},
},
diff --git a/FS/FS/part_export/cust_location_http.pm b/FS/FS/part_export/cust_location_http.pm
new file mode 100644
index 0000000..460080c
--- /dev/null
+++ b/FS/FS/part_export/cust_location_http.pm
@@ -0,0 +1,111 @@
+package FS::part_export::cust_location_http;
+
+use strict;
+use base qw( FS::part_export::http );
+use vars qw( %options %info );
+
+my @location_fields = qw(
+ custnum
+ address1
+ address2
+ city
+ state
+ zip
+ country
+ locationname
+ county
+ latitude
+ longitude
+ prospectnum
+ location_type
+ location_number
+ location_kind
+ geocode
+ district
+ censusyear
+ incorporated
+);
+
+tie %options, 'Tie::IxHash',
+ 'method' => { label =>'Method',
+ type =>'select',
+ #options =>[qw(POST GET)],
+ options =>[qw(POST)],
+ default =>'POST' },
+ 'url' => { label => 'URL', default => 'http://', },
+ 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
+ type => 'checkbox',
+ },
+ 'include_fields' => { 'label' => 'Include fields',
+ 'type' => 'select',
+ 'multiple' => 1,
+ 'options' => [ @location_fields ] },
+ 'success_regexp' => {
+ label => 'Success Regexp',
+ default => '',
+ },
+;
+
+%info = (
+ 'svc' => [qw( cust_location )],
+ 'desc' => 'Send an HTTP or HTTPS GET or POST request, for customer locations',
+ 'options' => \%options,
+ 'no_machine' => 1,
+ 'notes' => <<'END',
+Send an HTTP or HTTPS GET or POST to the specified URL on customer location insert
+or replace. Always sends cgi fields action ('insert' or 'replace') and locationnum,
+as well as any fields specified below. Only sends on replace if one of the
+specified fields changed.
+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
+);
+
+sub http_queue_standard {
+ my $self = shift;
+ $self->http_queue( '',
+ ( $self->option('ssl_no_verify') ? 'ssl_no_verify' : '' ),
+ $self->option('method'),
+ $self->option('url'),
+ $self->option('success_regexp'),
+ @_
+ );
+}
+
+sub _include_fields {
+ my $self = shift;
+ split( /\s+/, $self->option('include_fields') );
+}
+
+sub _export_command {
+ my( $self, $action, $cust_location ) = ( shift, shift, shift );
+
+ return '' unless $action eq 'insert';
+
+ $self->http_queue_standard(
+ 'action' => $action,
+ map { $_ => $cust_location->get($_) } ('locationnum', $self->_include_fields)
+ );
+
+}
+
+# currently, only custnum can change (when converting prospect to customer)
+# but using more generic logic for ease of adding other changeable fields
+sub _export_replace {
+ my( $self, $new, $old ) = ( shift, shift, shift );
+
+ my $changed = 0;
+ foreach my $field ($self->_include_fields) {
+ next if $new->get($field) eq $old->get($field);
+ next if ($field =~ /latitude|longitude/) and $new->get($field) == $old->get($field);
+ $changed = 1;
+ }
+ return '' unless $changed;
+
+ $self->http_queue_standard(
+ 'action' => 'replace',
+ map { $_ => $new->get($_) } ('locationnum', $self->_include_fields)
+ );
+}
+
+1;