X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fvitelity.pm;h=7803b3fabe0973274205b554ce26d8037c8360ed;hp=bec3837d9ebeea856e09cdb52d4f5945dbfb0dcf;hb=74e058c8a010ef6feb539248a550d0bb169c1e94;hpb=0d957a0f6008f301af282e134681088ba952c6f5 diff --git a/FS/FS/part_export/vitelity.pm b/FS/FS/part_export/vitelity.pm index bec3837d9..7803b3fab 100644 --- a/FS/FS/part_export/vitelity.pm +++ b/FS/FS/part_export/vitelity.pm @@ -12,6 +12,8 @@ tie my %options, 'Tie::IxHash', 'login' => { label=>'Vitelity API login' }, 'pass' => { label=>'Vitelity API password' }, 'dry_run' => { label=>"Test mode - don't actually provision" }, + 'routesip' => { label=>'routesip (optional sub-account)' }, + 'type' => { label=>'type (optional DID type to order)' }, ; %info = ( @@ -22,6 +24,9 @@ tie my %options, 'Tie::IxHash', Requires installation of Net::Vitelity from CPAN. +

+routesip - optional Vitelity sub-account to which newly ordered DIDs will be routed +
type - optional DID type (perminute, unlimited, or your-pri) END ); @@ -31,40 +36,43 @@ sub get_dids { my $self = shift; my %opt = ref($_[0]) ? %{$_[0]} : @_; +# currently one of three cases: areacode+exchange, areacode, state +# name == ratecenter + my %search = (); - # 'orderby' => 'npa', #but it doesn't seem to work :/ my $method = ''; - if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers + if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers in format NPA-NXX-XXXX return [ - map { join('-', $_->npx, $_->nxx, $_->station ) } + map { join('-', $_->npa, $_->nxx, $_->station ) } qsearch({ 'table' => 'phone_avail', 'hashref' => { 'exportnum' => $self->exportnum, - 'countrycode' => '1', - 'state' => $opt{'state'}, + 'countrycode' => '1', # vitelity is US/CA only now 'npa' => $opt{'areacode'}, 'nxx' => $opt{'exchange'}, }, - 'order_by' => 'ORDER BY name', #? + 'order_by' => 'ORDER BY station', }) ]; - } elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX) + } elsif ( $opt{'areacode'} ) { #return exchanges in format NPA-NXX- literal 'XXXX' + # you can't call $->name .... that returns "(unlinked)" + # and in any case this is still major abuse of encapsulation, it just happens to work for the other fields return [ - map { $_->name. ' ('. $_->npa. '-'. $_->nxx. '-XXXX)' } + map { $_->{'Hash'}->{name}.' ('. $_->npa. '-'. $_->nxx. '-XXXX)' } qsearch({ - 'select' => 'DISTINCT ON ( name, npa, nxx ) *', + # i know this doesn't do the same thing as before, but now the sort works + 'select' => 'DISTINCT npa,nxx,name', 'table' => 'phone_avail', 'hashref' => { 'exportnum' => $self->exportnum, - 'countrycode' => '1', - 'state' => $opt{'state'}, + 'countrycode' => '1', # vitelity is US/CA only now 'npa' => $opt{'areacode'}, }, - 'order_by' => 'ORDER BY name', #? + 'order_by' => 'ORDER BY nxx', }) ]; @@ -76,7 +84,7 @@ sub get_dids { 'select' => 'DISTINCT npa', 'table' => 'phone_avail', 'hashref' => { 'exportnum' => $self->exportnum, - 'countrycode' => '1', #don't hardcode me when gp goes intl + 'countrycode' => '1', # vitelity is US/CA only now 'state' => $opt{'state'}, }, 'order_by' => 'ORDER BY npa', @@ -89,6 +97,7 @@ sub get_dids { my @ratecenters = $self->vitelity_command( 'listavailratecenters', 'state' => $opt{'state'}, ); + # XXX: Options: type=unlimited OR type=pri if ( $ratecenters[0] eq 'unavailable' ) { return []; @@ -116,6 +125,7 @@ sub get_dids { 'state' => $opt{'state'}, 'ratecenter' => $ratecenter, ); + # XXX: Options: type=unlimited OR type=pri if ( $dids[0] eq 'unavailable' ) { next; @@ -124,13 +134,13 @@ sub get_dids { } foreach my $did ( @dids ) { - $did =~ /^(\d{3})(\d{3})(\d{4})$/ or die "unparsable did $did\n"; + $did =~ /^(\d{3})(\d{3})(\d{4}),/ or die "unparsable did $did\n"; my($npa, $nxx, $station) = ($1, $2, $3); $npa{$npa}++; my $phone_avail = new FS::phone_avail { 'exportnum' => $self->exportnum, - 'countrycode' => '1', #don't hardcode me when vitelity goes int'l + 'countrycode' => '1', # vitelity is US/CA only now 'state' => $opt{'state'}, 'npa' => $npa, 'nxx' => $nxx, @@ -183,12 +193,13 @@ sub _export_insert { #we want to provision and catch errors now, not queue - my $result = $self->vitelity_command('getlocaldid', - 'did' => $svc_phone->phonenum, -#XXX -#Options: type=perminute OR type=unlimited OR type=your-pri OR -# routesip=route_to_this_subaccount - ); + %vparams = ( 'did' => $svc_phone->phonenum ); + $vparams{'routesip'} = $self->option('routesip') + if defined $self->option('routesip'); + $vparams{'type'} = $self->option('type') + if defined $self->option('type'); + + my $result = $self->vitelity_command('getlocaldid',%vparams); if ( $result ne 'success' ) { return "Error running Vitelity getlocaldid: $result";