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 $cgi->param('custnum') =~ /^(\d+)$/
22 or die 'illegal custnum '. $cgi->param('custnum');
24 my $cust_main = qsearchs({
25 'table' => 'cust_main',
26 'hashref' => { 'custnum' => $custnum },
27 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
29 die 'unknown custnum' unless $cust_main;
31 $cgi->param('exportnum') =~ /^(\d+)$/ or die 'illegal exportnum';
34 $cgi->param('phonenum') =~ /^(\d*)$/ or die 'illegal phonenum';
37 $cgi->param('locationnum') =~ /^(\-?\d*)$/
38 or die 'illegal locationnum '. $cgi->param('locationnum');
41 my $oldAutoCommit = $FS::UID::AutoCommit;
42 local $FS::UID::AutoCommit = 0;
46 if ( $locationnum == -1 ) { # adding a new one
47 my %location_hash = map { $_ => scalar($cgi->param($_)) }
48 qw( custnum address1 address2 city county state zip country geocode );
49 $location_hash{location_type} = $cgi->param('location_type')
50 if $cgi->param('location_type');
51 $location_hash{location_number} = $cgi->param('location_number')
52 if $cgi->param('location_number');
53 $location_hash{location_kind} = $cgi->param('location_kind')
54 if $cgi->param('location_kind');
55 $cust_location = new FS::cust_location ( { %location_hash } );
56 $error = $cust_location->insert;
57 die "Unable to insert cust_location: $error" if $error;
59 elsif ( $locationnum eq '' ) { # default service location
60 $cust_location = new FS::cust_location ( {
61 $cust_main->location_hash,
65 elsif ( $locationnum != -2 ) { # -2 = address not required for qual
66 $cust_location = qsearchs('cust_location', { 'locationnum' => $locationnum })
67 or die 'Invalid locationnum';
71 if ( $exportnum > 0 ) {
72 $export = qsearchs( 'part_export', { 'exportnum' => $exportnum } )
73 or die 'Invalid exportnum';
76 die "Nothing to qualify - neither TN nor address specified"
77 unless ( defined $cust_location || $phonenum ne '' );
80 if ( $locationnum != -2 && $cust_location->locationnum > 0 ) {
81 $qual = new FS::qual( { locationnum => $cust_location->locationnum } );
83 else { # a cust_main default service address *OR* address not required
84 $qual = new FS::qual( { custnum => $custnum } );
86 $qual->phonenum($phonenum) if $phonenum ne '';
90 $qual->exportnum($export->exportnum);
91 my $qres = $export->qual($qual);
92 $error = "Qualification error: $qres" unless ref($qres);
94 $qual->status($qres->{'status'}) if $qres->{'status'};
95 $qual->vendor_qual_id($qres->{'vendor_qual_id'})
96 if $qres->{'vendor_qual_id'};
97 $error = $qual->insert($qres->{'options'}) if ref($qres->{'options'});
101 unless ( $error || $qual->qualnum ) {
102 $error = $qual->insert;
108 $qualnum = $qual->qualnum;
111 $error = "Unable to save qualification";