show un-configured ikano products, RT#7111
[freeside.git] / FS / FS / part_export / ikano.pm
index 604f47e..2d7688d 100644 (file)
@@ -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)
@@ -263,9 +290,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 +356,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?
+    }
+
+    { 'header'    => 'Qualifying Packages',
+      'pkglist'   => \%pkglist,
+      'not_avail' => \%not_avail,
+    };
 }
 
 sub quals_by_cust_and_pkg {