checkpoint of new tax rating system
[freeside.git] / httemplate / misc / process / tax-import.cgi
1 % if ( $error ) {
2 %   warn $error;
3 %   errorpage($error);
4 %  } else {
5     <% include('/elements/header.html','Import successful') %> 
6     <% include('/elements/footer.html') %> 
7 %  }
8 <%init>
9
10 die "access denied"
11   unless $FS::CurrentUser::CurrentUser->access_right('Import');
12
13 my $cfh = $cgi->upload('codefile');
14 my $zfh = $cgi->upload('plus4file');
15 my $tfh = $cgi->upload('txmatrix');
16 my $dfh = $cgi->upload('detail');
17 #warn $cgi;
18 #warn $fh;
19
20 my $oldAutoCommit = $FS::UID::AutoCommit;
21 local $FS::UID::AutoCommit = 0;
22 my $dbh = dbh;
23
24 my $error = defined($cfh)
25   ? FS::tax_class::batch_import( {
26       filehandle => $cfh,
27       'format'   => scalar($cgi->param('format')),
28     } )
29   : 'No code file';
30
31 $error ||= defined($zfh)
32   ? FS::cust_tax_location::batch_import( {
33       filehandle => $zfh,
34       'format'   => scalar($cgi->param('format')),
35     } )
36   : 'No plus4 file';
37
38 $error ||= defined($tfh)
39   ? FS::part_pkg_taxrate::batch_import( {
40       filehandle => $tfh,
41       'format'   => scalar($cgi->param('format')),
42     } )
43   : 'No tax matrix file';
44
45 $error ||= defined($dfh)
46   ? FS::tax_rate::batch_import( {
47       filehandle => $dfh,
48       'format'   => scalar($cgi->param('format')),
49     } )
50   : 'No tax detail file';
51
52 if ($error) {
53   $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
54 }else{
55   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
56 }
57
58 </%init>