+ my($self,$qual) = (shift,shift);
+# address always required for Ikano qual, TN optional (assume dry if not given)
+
+ my %location_hash = $qual->location;
+ return 'No address provided' unless %location_hash;
+ my $svctn = $qual->phonenum;
+
+ 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 => $location_hash{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_html {
+ 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 '' );
+ }
+
+ # XXX: eventually perhaps this should return both the packages a link to
+ # order each package and go to the svc prov with the prequal id filled in
+ # but only if cust, not prospect!
+ my $list = "<B>Qualifying Packages:</B><UL>";
+ 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 ) {
+ $list .= "<LI>".$part_pkg->pkgpart.": ".$part_pkg->pkg." - "
+ .$part_pkg->comment."</LI>"
+ if grep( $_ eq $externalid, @externalids );
+ }
+ }
+ $list .= "</UL>";
+ $list;