From a172aa2d549f2c62978fa1f6b6851a68ae0f2a4e Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 7 Apr 2014 14:42:10 -0700 Subject: [PATCH] cust_pkg import format with location, #28082 --- FS/FS/Schema.pm | 2 +- FS/FS/cust_pkg.pm | 2 +- FS/FS/cust_pkg/Import.pm | 23 +++++++++++++++++++++- httemplate/misc/cust_pkg-import.html | 38 ++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index bdae73649..ae25da154 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2573,7 +2573,7 @@ sub tables_hashref { 'manual_flag', 'char', 'NULL', 1, '', '', 'no_auto', 'char', 'NULL', 1, '', '', 'quantity', 'int', 'NULL', '', '', '', - 'agent_pkgid', 'int', 'NULL', '', '', '', + 'agent_pkgid', 'varchar', 'NULL', $char_d, '', '', 'waive_setup', 'char', 'NULL', 1, '', '', 'recur_show_zero', 'char', 'NULL', 1, '', '', 'setup_show_zero', 'char', 'NULL', 1, '', '', diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index daec07eaa..a893e5cbe 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -649,7 +649,7 @@ sub check { || $self->ut_numbern('dundate') || $self->ut_enum('no_auto', [ '', 'Y' ]) || $self->ut_enum('waive_setup', [ '', 'Y' ]) - || $self->ut_numbern('agent_pkgid') + || $self->ut_textn('agent_pkgid') || $self->ut_enum('recur_show_zero', [ '', 'Y', 'N', ]) || $self->ut_enum('setup_show_zero', [ '', 'Y', 'N', ]) || $self->ut_foreign_keyn('main_pkgnum', 'cust_pkg', 'pkgnum') diff --git a/FS/FS/cust_pkg/Import.pm b/FS/FS/cust_pkg/Import.pm index fe69f82fd..694d8147f 100644 --- a/FS/FS/cust_pkg/Import.pm +++ b/FS/FS/cust_pkg/Import.pm @@ -106,6 +106,7 @@ my %formatfields = ( 'svc_acct' => [qw( username _password domsvc )], 'svc_phone' => [qw( countrycode phonenum sip_password pin )], 'svc_external' => [qw( id title )], + 'location' => [qw( address1 address2 city state zip country )], ); sub _formatfields { @@ -115,11 +116,31 @@ sub _formatfields { my %import_options = ( 'table' => 'cust_pkg', + 'preinsert_callback' => sub { + my($record, $param) = @_; + my @location_params = grep /^location\./, keys %$param; + if (@location_params) { + my $cust_location = FS::cust_location->new({ + 'custnum' => $record->custnum, + }); + foreach my $p (@location_params) { + $p =~ /^location.(\w+)$/; + $cust_location->set($1, $param->{$p}); + } + +warn Dumper $cust_location; # XXX + my $error = $cust_location->find_or_insert; # this avoids duplicates + return "error creating location: $error" if $error; + $record->set('locationnum', $cust_location->locationnum); + } + ''; + }, + 'postinsert_callback' => sub { my( $record, $param ) = @_; my $formatfields = _formatfields; - foreach my $svc_x ( grep { $_ ne 'default' } keys %$formatfields ) { + foreach my $svc_x ( grep /^svc/, keys %$formatfields ) { my $ff = $formatfields->{$svc_x}; diff --git a/httemplate/misc/cust_pkg-import.html b/httemplate/misc/cust_pkg-import.html index f86d317b9..94e7dd926 100644 --- a/httemplate/misc/cust_pkg-import.html +++ b/httemplate/misc/cust_pkg-import.html @@ -36,6 +36,9 @@ Import a file containing package records.