'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, '', '',
|| $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')
'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 {
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};
<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>
<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>
<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 -> Packages -> Package definitions
<li><i>discountnum</i>: Optional discount. Configuration -> Packages -> Discounts
<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>