cust_pkg import format with location, #28082
authorMark Wells <mark@freeside.biz>
Mon, 7 Apr 2014 21:42:10 +0000 (14:42 -0700)
committerMark Wells <mark@freeside.biz>
Mon, 7 Apr 2014 21:42:10 +0000 (14:42 -0700)
FS/FS/Schema.pm
FS/FS/cust_pkg.pm
FS/FS/cust_pkg/Import.pm
httemplate/misc/cust_pkg-import.html

index bdae736..ae25da1 100644 (file)
@@ -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, '', '',
index daec07e..a893e5c 100644 (file)
@@ -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')
index fe69f82..694d814 100644 (file)
@@ -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};
 
index f86d317..94e7dd9 100644 (file)
@@ -36,6 +36,9 @@ Import a file containing package records.
         <OPTION VALUE="svc_phone-agent_custid">Phone service with agent_custid
         <OPTION VALUE="svc_external">External service
         <OPTION VALUE="svc_external-agent_custid">External service with agent_custid
+        <OPTION VALUE="location">Location
+        <OPTION VALUE="location-agent_custid">Location with agent_custid
+        <OPTION VALUE="location-agent_custid-agent_pkgid">Location with agent_custid and agent_pkgid
       </SELECT>
     </TD>
   </TR>
@@ -88,6 +91,27 @@ Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets.
 <b>External service with agent_custid</b> format has the following field order: <i>agent_custid<%$req%>, pkgpart<%$req%>, discountnum, start_date, setup, bill, last_bill, susp, adjourn, cancel, expire, id, title</i>
 <BR><BR>
 
+<b>Location</b> format has the following field order: <i>custnum<%$req%>,
+pkgpart<%$req%>, discountnum,
+start_date, setup, bill, last_bill, susp, adjourn, cancel, expire,
+address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country<%$req%>
+</i>
+<BR><BR>
+
+<b>Location with agent_custid</b> format has the following field order: <i>agent_custid<%$req%>,
+pkgpart<%$req%>, discountnum,
+start_date, setup, bill, last_bill, susp, adjourn, cancel, expire,
+address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country<%$req%>
+</i>
+<BR><BR>
+
+<b>Location with agent_custid and agent_pkgid</b> format has the following field order: <i>agent_custid<%$req%>, agent_pkgid,
+pkgpart<%$req%>, discountnum,
+start_date, setup, bill, last_bill, susp, adjourn, cancel, expire,
+address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country<%$req%>
+</i>
+<BR><BR>
+
 <%$req%> Required fields
 <BR><BR>
 
@@ -99,6 +123,8 @@ Field information:
 
   <li><i>agent_custid</i>: This specifies an existing customer record by agent_custid.
 
+  <li><i>agent_pkgid</i>: This specifies an existing customer record by agent_custid.
+
   <li><i>pkgpart</i>: Package definition.  Configuration -&gt; Packages -&gt; Package definitions
 
   <li><i>discountnum</i>: Optional discount.  Configuration -&gt; Packages -&gt; Discounts
@@ -129,6 +155,18 @@ Field information:
 
   <li><i>title</i>: External service identifier, text
 
+  <li><i>address1</i>: Service address, number and street, text
+
+  <li><i>address2</i>: Service address, suite/unit/building identifier, text
+
+  <li><i>city</i>: Service address, name of city, text
+
+  <li><i>state</i>: Service address, state/province, abbreviated
+
+  <li><i>zip</i>: Service address, postal code
+
+  <li><i>country</i>: Service address, country, 2-letter code
+
 </ul>
 
 <BR>