diff options
author | ivan <ivan> | 2011-03-22 06:00:54 +0000 |
---|---|---|
committer | ivan <ivan> | 2011-03-22 06:00:54 +0000 |
commit | 3dfc446d8a4d241787c47ff7e2db72483d62ab7a (patch) | |
tree | f0129a16674ccd7c2feec43d7aea7dd5be2f7d41 /FS/FS | |
parent | b1011034b084a90c07c7199f5e64cdee7cdd199f (diff) |
new customer from prospect qualification, RT#7111
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/cust_location.pm | 81 | ||||
-rw-r--r-- | FS/FS/geocode_Mixin.pm | 50 | ||||
-rw-r--r-- | FS/FS/part_export/ikano.pm | 31 | ||||
-rw-r--r-- | FS/FS/qual.pm | 49 |
4 files changed, 126 insertions, 85 deletions
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 7d0ce1c7b..7ffa5ed41 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -203,7 +203,8 @@ sub has_ship_address { =item location_hash Returns a list of key/value pairs, with the following keys: address1, address2, -city, county, state, zip, country, geocode. +city, county, state, zip, country, geocode, location_type, location_number, +location_kind. =cut @@ -271,6 +272,84 @@ sub move_to { return; } +=item alternize + +Attempts to parse data for location_type and location_number from address1 +and address2. + +=cut + +sub alternize { + my $self = shift; + + return '' if $self->get('location_type') + || $self->get('location_number'); + + my %parse; + if ( 1 ) { #ikano, switch on via config + { no warnings 'void'; + eval { 'use FS::part_export::ikano;' }; + die $@ if $@; + } + %parse = FS::part_export::ikano->location_types_parse; + } else { + %parse = (); #? + } + + foreach my $from ('address1', 'address2') { + foreach my $parse ( keys %parse ) { + my $value = $self->get($from); + if ( $value =~ s/(^|\W+)$parse\W+(\w+)\W*$//i ) { + $self->set('location_type', $parse{$parse}); + $self->set('location_number', $2); + $self->set($from, $value); + return ''; + } + } + } + + #nothing matched, no changes + $self->get('address2') + ? "Can't parse unit type and number from address2" + : ''; +} + +=item dealternize + +Moves data from location_type and location_number to the end of address1. + +=cut + +sub dealternize { + my $self = shift; + + #false laziness w/geocode_Mixin.pm::line + my $lt = $self->get('location_type'); + if ( $lt ) { + + my %location_type; + if ( 1 ) { #ikano, switch on via config + { no warnings 'void'; + eval { 'use FS::part_export::ikano;' }; + die $@ if $@; + } + %location_type = FS::part_export::ikano->location_types; + } else { + %location_type = (); #? + } + + $self->address1( $self->address1. ' '. $location_type{$lt} || $lt ); + $self->location_type(''); + } + + if ( length($self->location_number) ) { + $self->address1( $self->address1. ' '. $self->location_number ); + $self->location_number(''); + } + + ''; +} + =back =head1 BUGS diff --git a/FS/FS/geocode_Mixin.pm b/FS/FS/geocode_Mixin.pm index a17a0abed..4f8d1e85c 100644 --- a/FS/FS/geocode_Mixin.pm +++ b/FS/FS/geocode_Mixin.pm @@ -96,7 +96,8 @@ sub location_label { $notfirst++; } - if ( $self->get($prefix.'location_type') ) { + my $lt = $self->get($prefix.'location_type'); + if ( $lt ) { my %location_type; if ( 1 ) { #ikano, switch on via config { no warnings 'void'; @@ -108,9 +109,7 @@ sub location_label { %location_type = (); #? } - $line .= ' '.&$escape( $location_type{ $self->get($prefix.'location_type') } - || $self->get($prefix.'location_type') - ); + $line .= ' '.&$escape( $location_type{$lt} || $lt ); } $line .= ' '. &$escape($self->get($prefix.'location_number')) @@ -172,49 +171,6 @@ sub geocode { $geocode; } -=item alternize - -Attempts to parse data for location_type and location_number from address1 -and address2. - -=cut - -sub alternize { - my $self = shift; - my $prefix = $self->has_ship_address ? 'ship_' : ''; - - return '' if $self->get($prefix.'location_type') - || $self->get($prefix.'location_number'); - - my %parse; - if ( 1 ) { #ikano, switch on via config - { no warnings 'void'; - eval { 'use FS::part_export::ikano;' }; - die $@ if $@; - } - %parse = FS::part_export::ikano->location_types_parse; - } else { - %parse = (); #? - } - - foreach my $from ('address1', 'address2') { - foreach my $parse ( keys %parse ) { - my $value = $self->get($prefix.$from); - if ( $value =~ s/(^|\W+)$parse\W+(\w+)\W*$//i ) { - $self->set($prefix.'location_type', $parse{$parse}); - $self->set($prefix.'location_number', $2); - $self->set($prefix.$from, $value); - return ''; - } - } - } - - #nothing matched, no changes - $self->get($prefix.'address2') - ? "Can't parse unit type and number from ${prefix}address2" - : ''; -} - =back =head1 BUGS diff --git a/FS/FS/part_export/ikano.pm b/FS/FS/part_export/ikano.pm index 2d7688ddc..4323d94f3 100644 --- a/FS/FS/part_export/ikano.pm +++ b/FS/FS/part_export/ikano.pm @@ -234,7 +234,6 @@ sub dsl_pull { my @onotes = $svc_dsl->notes; # assume notes we already have don't change & no notes added from our side # so using the horrible code below just find what we're missing and add it - my $error; foreach my $inote ( @inotes ) { my $found = 0; foreach my $onote ( @onotes ) { @@ -243,7 +242,7 @@ sub dsl_pull { last; } } - $error = $inote->insert unless ( $found ); + my $error = $inote->insert unless ( $found ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Cannot add note: $error"; @@ -252,7 +251,7 @@ sub dsl_pull { $svc_dsl->last_pull((time)); local $FS::svc_Common::noexport_hack = 1; - $error = $svc_dsl->replace; + my $error = $svc_dsl->replace; if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Cannot update DSL data: $error"; @@ -373,7 +372,7 @@ sub qual_result { $not_avail{$externalid} = $externalid; #a better label? } - { 'header' => 'Qualifying Packages', + { 'pkglist' => \%pkglist, 'not_avail' => \%not_avail, }; @@ -461,15 +460,14 @@ sub valid_order { if $self->option('debug'); # common to all order types/status/loop_type - my $error = !($svc_dsl->desired_due_date - && grep($_ eq $svc_dsl->vendor_order_type, Net::Ikano->orderTypes) - && $svc_dsl->first - && $svc_dsl->last - && defined $svc_dsl->loop_type - && $svc_dsl->vendor_qual_id - ); - return 'Missing or invalid order data' if $error; - + return 'No desired_due_date' unless $svc_dsl->desired_due_date; + return 'Unknown vendor_order_type' + unless grep $_ eq $svc_dsl->vendor_order_type, Net::Ikano->orderTypes; + return 'No first name' unless $svc_dsl->first; + return 'No last name' unless $svc_dsl->get('last'); + return 'No loop type' unless defined $svc_dsl->loop_type; + return 'No vendor_qual_id' unless $svc_dsl->vendor_qual_id; + my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids; return 'Package does not have an external id configured' unless defined $vendor_pkg_ids{$self->exportnum}; @@ -481,7 +479,7 @@ sub valid_order { # weird ifs & long lines for readability and ease of understanding - don't change if($svc_dsl->vendor_order_type eq 'NEW') { if($svc_dsl->pushed) { - $error = !( ($action eq 'pull' || $action eq 'statuschg' + my $error = !( ($action eq 'pull' || $action eq 'statuschg' || $action eq 'delete' || $action eq 'expire') && length($svc_dsl->vendor_order_id) > 0 && length($svc_dsl->vendor_order_status) > 0 @@ -492,7 +490,7 @@ sub valid_order { if ($action eq 'statuschg' && length($svc_dsl->phonenum) < 1); } else { # unpushed New order - cannot do anything other than push it - $error = !($action eq 'insert' + my $error = !($action eq 'insert' && length($svc_dsl->vendor_order_id) < 1 && length($svc_dsl->vendor_order_status) < 1 && ( ($svc_dsl->phonenum eq '' && $svc_dsl->loop_type eq '0') # dry @@ -534,7 +532,8 @@ sub _export_insert { return $result unless $result eq ''; my $isp_chg = $svc_dsl->isp_chg eq 'Y' ? 'YES' : 'NO'; - my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime; + my $cust_main = $svc_dsl->cust_svc->cust_pkg->cust_main; + my $contactTN = $cust_main->daytime || $cust_main->night || '5555555555'; $contactTN =~ s/[^0-9]//g; my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids; diff --git a/FS/FS/qual.pm b/FS/FS/qual.pm index d0b3fbdfe..07878e9c2 100644 --- a/FS/FS/qual.pm +++ b/FS/FS/qual.pm @@ -185,28 +185,34 @@ sub part_export { ''; } +sub cust_location { + my $self = shift; + return '' unless $self->locationnum; + qsearchs('cust_location', { 'locationnum' => $self->locationnum } ); +} + +sub cust_main { + my $self = shift; + return '' unless $self->custnum; + qsearchs('cust_main', { 'custnum' => $self->custnum } ); +} + sub location_hash { - my $self = shift; - if ( $self->locationnum ) { - my $l = qsearchs( 'cust_location', - { 'locationnum' => $self->locationnum }); - if ( $l ) { - my %loc_hash = $l->location_hash; - $loc_hash{locationnum} = $self->locationnum; - return %loc_hash; - } - } - if ( $self->custnum ) { - my $c = qsearchs( 'cust_main', { 'custnum' => $self->custnum }); - - if($c) { - # always override location_kind as it would never be known in the - # case of cust_main "default service address" - my %loc_hash = $c->location_hash; - $loc_hash{location_kind} = $c->company ? 'B' : 'R'; - return %loc_hash; - } - } + my $self = shift; + + if ( my $l = $self->cust_location ) { + my %loc_hash = $l->location_hash; + $loc_hash{locationnum} = $self->locationnum; + return %loc_hash; + } + + if ( my $c = $self->cust_main ) { + # always override location_kind as it would never be known in the + # case of cust_main "default service address" + my %loc_hash = $c->location_hash; + $loc_hash{location_kind} = $c->company ? 'B' : 'R'; + return %loc_hash; + } warn "prospectnum does not imply any particular address! must specify locationnum"; return (); @@ -226,6 +232,7 @@ sub cust_or_prospect { if $self->custnum; return qsearchs('prospect_main', { 'prospectnum' => $self->prospectnum }) if $self->prospectnum; + ''; } sub status_long { |