summaryrefslogtreecommitdiff
path: root/httemplate/browse/invoice_conf.html
blob: 050c78923f6363a34ff3e03294cb2ba88a985fa5 (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
<& elements/browse.html,
  'title'         => 'Invoice modes',
  'name_singular' => 'configuration',
  'menubar'       => \@menubar,
  'query'         => {
                      'select'    => $select,
                      'table'     => 'invoice_conf',
                      'addl_from' => ' JOIN invoice_mode USING (modenum)',
                      'extra_sql' => ' WHERE '.$curuser->agentnums_sql(
                        'table'       => 'invoice_mode',
                        'null_right'  => ['Edit global templates'],
                      ),
                      'order_by'  => q( ORDER BY modename asc, COALESCE(locale,'') asc),
                     },
  'count_query'   => 'SELECT COUNT(*) FROM invoice_conf JOIN invoice_mode USING (modenum)',
  'header'        => [ 'Name', 'Agent', 'Locale', 'Overrides', ],
  'fields'        => [  $modename,
                        $agent,
                        $locale_label,
                        $overrides,
                     ],
  'align'         => 'llcll',
  'links'         => [ '', '', $link ],
  'disable_maxselect' => 1,
&>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;

die "access denied"
  unless $curuser->access_right([ 'View templates', 'View global templates',
                                  'Edit templates', 'Edit global templates', ]);

my @overrides = grep {$_ ne 'modenum' and $_ ne 'confnum'} FS::invoice_conf->fields;                                 
my $select = join(',', 'modename', 'agentnum', 'confnum', 'invoice_conf.*');

my @menubar = ();
if ( $curuser->access_right(['Edit templates', 'Edit global templates']) ) {
  push @menubar, 'Add a new invoice mode' => $p.'edit/invoice_conf.html';
}

my $locale_style = 'font-size:0.8em; padding:3px; background-color:';

my $last_modenum = 0;
my $modename = sub {
  return '' if $_[0]->modenum == $last_modenum;
  $_[0]->modename;
};

my $agent = sub {
  return '' if $_[0]->modenum == $last_modenum;
  $last_modenum = $_[0]->modenum;
  $_[0]->agentnum ? FS::agent->by_key($_[0]->agentnum)->agent : '(global)';
};

my $locale_label = sub {
  my $l = $_[0]->locale;
  ($l ? +{ FS::Locales->locale_info($l) }->{'label'} : 'default') . 
    '<br><font size="-1">('.mt('edit').')</font>'
};

my $overrides = sub {
  my $invoice_conf = shift;
  [ map { [ { data => $_ } ] }
    grep { length $invoice_conf->get($_) }
    @overrides
  ],
};

my $link = [ $p.'edit/invoice_conf.html?', 'confnum' ];
</%init>