stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / browse / invoice_conf.html
1 <& elements/browse.html,
2   'title'         => 'Invoice modes',
3   'name_singular' => 'configuration',
4   'menubar'       => \@menubar,
5   'query'         => {
6                       'select'    => $select,
7                       'table'     => 'invoice_conf',
8                       'addl_from' => ' JOIN invoice_mode USING (modenum)',
9                       'extra_sql' => ' WHERE '.$curuser->agentnums_sql(
10                         'table'       => 'invoice_mode',
11                         'null_right'  => ['Edit global templates'],
12                       ),
13                       'order_by'  => q( ORDER BY modename asc, COALESCE(locale,'') asc),
14                      },
15   'count_query'   => 'SELECT COUNT(*) FROM invoice_conf JOIN invoice_mode USING (modenum)',
16   'header'        => [ 'Name', 'Agent', 'Locale', 'Overrides', ],
17   'fields'        => [  $modename,
18                         $agent,
19                         $locale_label,
20                         $overrides,
21                      ],
22   'align'         => 'llcll',
23   'links'         => [ '', '', $link ],
24   'disable_maxselect' => 1,
25 &>
26 <%init>
27
28 my $curuser = $FS::CurrentUser::CurrentUser;
29
30 die "access denied"
31   unless $curuser->access_right([ 'View templates', 'View global templates',
32                                   'Edit templates', 'Edit global templates', ]);
33
34 my @overrides = grep {$_ ne 'modenum' and $_ ne 'confnum'} FS::invoice_conf->fields;                                 
35 my $select = join(',', 'modename', 'agentnum', 'confnum', 'invoice_conf.*');
36
37 my @menubar = ();
38 if ( $curuser->access_right(['Edit templates', 'Edit global templates']) ) {
39   push @menubar, 'Add a new invoice mode' => $p.'edit/invoice_conf.html';
40 }
41
42 my $locale_style = 'font-size:0.8em; padding:3px; background-color:';
43
44 my $last_modenum = 0;
45 my $modename = sub {
46   return '' if $_[0]->modenum == $last_modenum;
47   $_[0]->modename;
48 };
49
50 my $agent = sub {
51   return '' if $_[0]->modenum == $last_modenum;
52   $last_modenum = $_[0]->modenum;
53   $_[0]->agentnum ? FS::agent->by_key($_[0]->agentnum)->agent : '(global)';
54 };
55
56 my $locale_label = sub {
57   my $l = $_[0]->locale;
58   ($l ? +{ FS::Locales->locale_info($l) }->{'label'} : 'default') . 
59     '<br><font size="-1">('.mt('edit').')</font>'
60 };
61
62 my $overrides = sub {
63   my $invoice_conf = shift;
64   [ map { [ { data => $_ } ] }
65     grep { length $invoice_conf->get($_) }
66     @overrides
67   ],
68 };
69
70 my $link = [ $p.'edit/invoice_conf.html?', 'confnum' ];
71 </%init>