+ my($self,$qual) = (shift,shift);
+
+ return 'Invalid operation - Import Mode is enabled' if $self->import_mode;
+
+ my %location_hash = $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 $zip = $location_hash{zip};
+ $zip =~ s/(\d{5})-\d{4}/$1/;
+
+ my $result = $self->ikano_command('PREQUAL',
+ { AddressLine1 => $location_hash{address1},
+ AddressUnitType => $location_hash{location_type},
+ AddressUnitValue => $location_hash{location_number},
+ AddressCity => $location_hash{city},
+ AddressState => $location_hash{state},
+ ZipCode => $zip,
+ Country => $location_hash{country},
+ LocationType => $location_hash{location_kind},
+ PhoneNumber => length($svctn) > 1 ? $svctn : "STANDALONE",
+ RequestClientIP => '127.0.0.1',
+ CheckNetworks => $self->option('check_networks'),
+ } );
+ return $result unless ref($result); # error case
+ return 'Invalid prequal response' unless defined $result->{'PrequalId'};
+
+ my $qoptions = {};
+ # lame data structure traversal...
+ # don't spend much time here, just get TermsId and ProductCustomId
+ my $networks = $result->{'Network'};
+ my @networks = defined $networks ? @$networks : ();
+ my $netcount = 0;
+ foreach my $network ( @networks ) {
+ my $productgroups = $network->{'ProductGroup'};
+ my @productgroups = defined $productgroups ? @$productgroups : ();
+ my $pgcount = 0;
+ foreach my $productgroup ( @productgroups ) {
+ my $prefix = "ikano_Network_$netcount"."_ProductGroup_$pgcount"."_";
+ $qoptions->{$prefix."TermsId"} = $productgroup->{'TermsId'};
+ my $products = $productgroup->{'Product'};
+ my @products = defined $products ? @$products : ();
+ my $prodcount = 0;
+ foreach my $product ( @products ) {
+ $qoptions->{$prefix."Product_$prodcount"."_ProductCustomId"} = $product->{'ProductCustomId'};
+ $prodcount++;
+ }
+ $pgcount++;
+ }
+ $netcount++;
+ }
+
+ { 'vendor_qual_id' => $result->{'PrequalId'},
+ 'status' => scalar(@networks) ? 'Q' : 'D',
+ 'options' => $qoptions,
+ };
+}
+
+sub qual_result {
+ my($self,$qual) = (shift,shift);
+
+ my %qual_options = $qual->options;
+ my @externalids = ();
+ my( $optionname, $optionvalue );
+ while (($optionname, $optionvalue) = each %qual_options) {
+ push @externalids, $optionvalue
+ if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
+ && $optionvalue ne '' );
+ }
+
+ my %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_comment;
+ $found{$externalid}++;
+ }
+ }
+
+ my %not_avail = ();
+ foreach my $externalid ( grep !$found{$_}, @externalids ) {
+ $not_avail{$externalid} = $externalid; #a better label?
+ }
+
+ {
+ 'pkglist' => \%pkglist,
+ 'not_avail' => \%not_avail,
+ };