X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fikano.pm;h=4323d94f3dd2ef66bdd5efdd0190389b4a95c5f5;hb=e9bfb3af6db5f76f378f46e6367a8a932a4824bf;hp=604f47e99f39360f8a50c41f50c7a25e34e3bdbf;hpb=1888d732dcc9f50b7f88ebc684d1c05b534cbd92;p=freeside.git diff --git a/FS/FS/part_export/ikano.pm b/FS/FS/part_export/ikano.pm index 604f47e99..4323d94f3 100644 --- a/FS/FS/part_export/ikano.pm +++ b/FS/FS/part_export/ikano.pm @@ -42,6 +42,33 @@ sub rebless { shift; } sub external_pkg_map { 1; } +sub location_types { + ( + '' => '(None)', + 'APT' => 'Apartment', + 'BLDG' => 'Building', + 'FLR' => 'Floor', + 'LOT' => 'Lot', + 'RM' => 'Room', + 'SLIP' => 'Slip', + 'SUIT' => 'Suite', + 'TRLR' => 'Trailer', + 'UNIT' => 'Unit', + 'WING' => 'Wing', + ); +} + +sub location_types_parse { + my $class = shift; + my %t = $class->location_types; + delete $t{''}; + ( + (map { $_ => $_ } keys %t), + (reverse %t), + 'STE' => 'SUIT', #USPS + ); +} + sub dsl_pull { # we distinguish between invalid new data (return error) versus data that # has legitimately changed (may eventually execute hooks; now just update) @@ -207,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 ) { @@ -216,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"; @@ -225,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"; @@ -263,9 +289,10 @@ sub qual { my($self,$qual) = (shift,shift); my %location_hash = $qual->location_hash; - warn Dumper $qual->location_hash; return 'No address provided' unless keys %location_hash; + return 'Location kind is required' unless $location_hash{location_kind}; + my $svctn = $qual->phonenum; my $result = $self->ikano_command('PREQUAL', @@ -328,21 +355,27 @@ sub qual_result { } my %pkglist = (); - my $result = { 'header' => 'Qualifying Packages', - 'pkglist' => \%pkglist, - }; - + my %found = (); my @part_pkgs = qsearch( 'part_pkg', { 'disabled' => '' } ); foreach my $part_pkg ( @part_pkgs ) { my %vendor_pkg_ids = $part_pkg->vendor_pkg_ids; my $externalid = $vendor_pkg_ids{$self->exportnum} if defined $vendor_pkg_ids{$self->exportnum}; - if ( $externalid && grep( $_ eq $externalid, @externalids )) { - $pkglist{$part_pkg->pkgpart} = $part_pkg->pkg." - ".$part_pkg->comment; + if ( $externalid && grep { $_ eq $externalid } @externalids ) { + $pkglist{$part_pkg->pkgpart} = $part_pkg->pkg_comment; + $found{$externalid}++; } } - $result; + my %not_avail = (); + foreach my $externalid ( grep !$found{$_}, @externalids ) { + $not_avail{$externalid} = $externalid; #a better label? + } + + { + 'pkglist' => \%pkglist, + 'not_avail' => \%not_avail, + }; } sub quals_by_cust_and_pkg { @@ -427,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}; @@ -447,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 @@ -458,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 @@ -500,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;