summaryrefslogtreecommitdiff
path: root/httemplate/browse/tax_class.html
blob: 76d266bf9072debde5c0149f14b26cf4fe4b4e32 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<% include( 'elements/browse.html',
     'title'             => "Tax classes $title",
     'name_singular'     => 'tax class',
     'menubar'           => \@menubar,
     'html_init'         => $html_init,
     'query'             => {
                              'table'     => 'tax_class',
                              'hashref'   => $hashref,
                              'extra_sql' => $where,
                              'order_by'  => 'ORDER BY taxclass',
                            },
     'count_query'       => $count_query,
     'header'            => \@header,
     'fields'            => \@fields,
     'align'             => $align,
     'links'             => \@links,
     'link_onclicks'     => \@link_onclicks,
     'disable_maxselect' => 1,
     'disable_total'     => 1,
  )
%>
<%once>

my $conf = new FS::Conf;

</%once>
<%init>

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

my $title = '';
my @menubar = ();
my $html_init = '';
my $hashref = {};
my @where = ();
my $onclick = 'return true;';

my $omit = '';
if ( $cgi->param('magic') eq 'omit' ) {
  $cgi->param('omit') =~ /^([,\d]+)$/;
  $omit = $1;
  $title .= " unselected";
  push @where, map { "taxclassnum != $_" } grep {$_} split( /,/, $omit );
  $onclick = sub{ 'parent.doSelect('. shift->taxclassnum. '); return false;' } 
}
$cgi->delete('omit');

my $data_vendor = '';
if ( $cgi->param('datavendor') =~ /^([\w]+)$/ ) {
  $data_vendor = $1;
  $title .= " for data vendor $1";
  push @where, 'data_vendor = '. dbh->quote($data_vendor);
}
$cgi->delete('data_vendor');

my $selected = '';
if (    $cgi->param('magic') eq 'select')
{
  $cgi->param('selected') =~ /^([,\d]*)$/;
  $selected = $1;
  $title = " selected";
  my @clauses =  map { "taxclassnum = $_" } grep {$_} split( /,/, $selected );
  @where =  scalar(@clauses) ? '( '. join(' OR ', @clauses) .')' : '1=0';
  $onclick = sub{ 'parent.doUnselect('. shift->taxclassnum. '); return false;' } ;
}
$cgi->delete('selected');


if ( $data_vendor ) {
  push @menubar, 'View all tax classes' => $p.'browse/tax_class.html';
}

$cgi->param('dummy', 1);

#restore this so pagination works
$cgi->param('omit', $omit ) if $omit;
$cgi->param('selected', $selected ) if $selected;
$cgi->param('data_vendor', $data_vendor ) if $data_vendor;

my $where = scalar(@where) ? 'WHERE '. join( ' AND ', @where ) : '';
my $count_query = 'SELECT COUNT(*) FROM tax_class '. $where;

my $link = [ 'javascript:void(0);', sub{ ''; } ];

my @header        = ( '', '', '' );
my @links         = ( $link, $link, $link );
my @link_onclicks = ( $onclick, $onclick, $onclick );
my $align = 'lll';
my @fields = ( 'data_vendor', 'taxclass', 'description' );

</%init>