2 % $cgi->param('error', $error);
3 % $dbh->rollback if $oldAutoCommit;
4 <% $cgi->redirect(popurl(3). 'misc/qual.html?'. $cgi->query_string ) %>
6 % $dbh->commit or die $dbh->errstr if $oldAutoCommit;
7 <% header('Qualification entered') %>
8 <SCRIPT TYPE="text/javascript">
9 window.top.location = '<% popurl(3). "view/qual.cgi?qualnum=$qualnum" %>';
16 my $curuser = $FS::CurrentUser::CurrentUser;
19 unless $curuser->access_right('Qualify service');
21 # copied from misc/qual.html :(
22 $cgi->param('custnum') =~ /^(\d+)$/;
24 $cgi->param('prospectnum') =~ /^(\d+)$/;
26 my $cust_or_prospect = $custnum ? "cust" : "prospect";
27 my $table = $cust_or_prospect . "_main";
28 my $custnum_or_prospectnum = $custnum ? $custnum : $prospectnum;
29 my $cust_main_or_prospect_main = qsearchs({
31 'hashref' => { $cust_or_prospect."num" => $custnum_or_prospectnum },
32 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
34 die "neither prospect nor customer specified or found"
35 unless $cust_main_or_prospect_main;
37 $cgi->param('exportnum') =~ /^(\d+)$/ or die 'illegal exportnum';
40 $cgi->param('phonenum') =~ /^(\d*)$/ or die 'illegal phonenum';
43 $cgi->param('locationnum') =~ /^(\-?\d*)$/
44 or die 'illegal locationnum '. $cgi->param('locationnum');
47 my $oldAutoCommit = $FS::UID::AutoCommit;
48 local $FS::UID::AutoCommit = 0;
52 if ( $locationnum == -1 ) { # adding a new one
53 my %location_hash = map { $_ => scalar($cgi->param($_)) }
54 qw( address1 address2 city county state zip country geocode );
55 $location_hash{$cust_or_prospect."num"} = $custnum_or_prospectnum;
56 $location_hash{location_type} = $cgi->param('location_type')
57 if $cgi->param('location_type');
58 $location_hash{location_number} = $cgi->param('location_number')
59 if $cgi->param('location_number');
60 $location_hash{location_kind} = $cgi->param('location_kind')
61 if $cgi->param('location_kind');
62 $cust_location = new FS::cust_location ( { %location_hash } );
63 $error = $cust_location->insert;
64 die "Unable to insert cust_location: $error" if $error;
66 elsif ( $locationnum eq '' ) { # default service location
68 $cust_location = new FS::cust_location ( {
69 $cust_main_or_prospect_main->location_hash,
72 } elsif ( $prospectnum ) {
73 die "a location must be specified explicitly for prospects";
76 elsif ( $locationnum != -2 ) { # -2 = address not required for qual
77 $cust_location = qsearchs('cust_location', { 'locationnum' => $locationnum })
78 or die 'Invalid locationnum';
82 if ( $exportnum > 0 ) {
83 $export = qsearchs( 'part_export', { 'exportnum' => $exportnum } )
84 or die 'Invalid exportnum';
87 die "Nothing to qualify - neither TN nor address specified"
88 unless ( defined $cust_location || $phonenum ne '' );
91 if ( $locationnum != -2 && $cust_location->locationnum > 0 ) {
92 $qual = new FS::qual( { locationnum => $cust_location->locationnum } );
94 else { # a cust_main default service address *OR* address not required
95 $qual = new FS::qual( { $cust_or_prospect."num" => $custnum_or_prospectnum } );
97 $qual->phonenum($phonenum) if $phonenum ne '';
101 $qual->exportnum($export->exportnum);
102 my $qres = $export->qual($qual);
103 $error = "Qualification error: $qres" unless ref($qres);
105 $qual->status($qres->{'status'}) if $qres->{'status'};
106 $qual->vendor_qual_id($qres->{'vendor_qual_id'})
107 if $qres->{'vendor_qual_id'};
108 $error = $qual->insert($qres->{'options'}) if ref($qres->{'options'});
112 unless ( $error || $qual->qualnum ) {
113 $error = $qual->insert;
119 $qualnum = $qual->qualnum;
122 $error = "Unable to save qualification";