summaryrefslogtreecommitdiff
path: root/httemplate/misc/process/tax-import.cgi
blob: 77fba61f585c7b23377aeb604790be73e6819019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% if ( $error ) {
%   warn $error;
%   errorpage($error);
%  } else {
    <% include('/elements/header.html','Import successful') %> 
    <% include('/elements/footer.html') %> 
%  }
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Import');

my $cfh = $cgi->upload('codefile');
my $zfh = $cgi->upload('plus4file');
my $tfh = $cgi->upload('txmatrix');
my $dfh = $cgi->upload('detail');
#warn $cgi;
#warn $fh;

my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;

my $error = defined($cfh)
  ? FS::tax_class::batch_import( {
      filehandle => $cfh,
      'format'   => scalar($cgi->param('format')),
    } )
  : 'No code file';

$error ||= defined($zfh)
  ? FS::cust_tax_location::batch_import( {
      filehandle => $zfh,
      'format'   => scalar($cgi->param('format')),
    } )
  : 'No plus4 file';

$error ||= defined($tfh)
  ? FS::part_pkg_taxrate::batch_import( {
      filehandle => $tfh,
      'format'   => scalar($cgi->param('format')),
    } )
  : 'No tax matrix file';

$error ||= defined($dfh)
  ? FS::tax_rate::batch_import( {
      filehandle => $dfh,
      'format'   => scalar($cgi->param('format')),
    } )
  : 'No tax detail file';

if ($error) {
  $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
}else{
  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
}

</%init>