2 'body_etc' => $body_etc,
3 'name_singular' => 'invoice configuration',
4 'table' => 'invoice_conf',
5 'viewall_dir' => 'browse',
8 'new_callback' => \&new_callback,
9 'edit_callback' => \&edit_callback,
10 'error_callback' => \&error_callback,
11 'html_init' => \&html_init,
12 'html_table_bottom' => \&html_table_bottom,
13 'html_bottom' => '</DIV>', # close tablebreak-tabs
17 my $curuser = $FS::CurrentUser::CurrentUser;
21 unless $curuser->access_right([ 'Edit templates', 'Edit global templates' ]);
24 $body_etc = q!onload="document.getElementById('locale').onchange()"!
25 if $cgi->param('locale') eq 'new';
27 my $modenum = $cgi->param('modenum');
28 my $mode = $modenum ? qsearchs('invoice_mode', { modenum => $modenum }) : '';
30 my %textarea = (type => 'textarea', rows => 10, cols => 40);
32 { field => 'modenum', type => 'hidden' },
33 { field => 'agentnum',
34 type => 'select-agent',
36 { field => 'modename', size=>60, },
37 { type => 'tablebreak-tabs',
38 include_opt_callback => \&menubar_opt_callback,
40 { field => 'locale', type => 'hidden' },
41 { field => 'notice_name', size=>60, },
42 { field => 'subject', size=>60, },
43 { field => 'lpr', size=>60, },
45 { type => 'columnstart', aligned => 1 },
46 { type => 'title', value => '<BR>' },
47 map ( { +{ type => 'justtitle', value => $_ } }
62 { type => 'columnnext' },
63 { type => 'title', value => 'LaTeX' },
64 { field => 'latexnotes', %textarea },
65 { field => 'latexfooter', %textarea },
66 { field => 'latexsummary', %textarea },
67 { field => 'latexreturnaddress', %textarea },
68 { field => 'latexcoupon', %textarea },
69 { field => 'latexsmallfooter', %textarea },
70 { field => 'latextopmargin', size => 16 },
71 { field => 'latexheadsep', size => 16 },
72 { field => 'latexaddresssep', size => 16 },
73 { field => 'latextextheight', size => 16 },
74 { field => 'latexextracouponspace', size => 16 },
75 { field => 'latexcouponfootsep', size => 16 },
76 # are these still used?
77 #{ field => 'latexcouponamountenclosedsep', size => 16 },
78 #{ field => 'latexverticalreturnaddress', type => 'checkbox' },
79 #{ field => 'latexcouponaddcompanytoaddress',type => 'checkbox' },
80 # logo -- implement if someone really needs it...
82 { type => 'columnnext' },
83 { type => 'title', value => 'HTML' },
84 { field => 'htmlnotes', %textarea }, #htmlarea?
85 { field => 'htmlfooter', %textarea },
86 { field => 'htmlsummary', %textarea },
87 { field => 'htmlreturnaddress', %textarea },
90 { type => 'columnend' },
94 'confnum' => 'Configuration',
96 'agentnum' => 'Agent',
97 'modename' => 'Mode name',
98 'notice_name' => 'Notice name',
99 'subject' => 'Email Subject: header',
100 'lpr' => 'Alternate lpr command',
102 map { $_ => '' } (qw(
113 latexextracouponspace
125 sub get_invoice_mode { # because we can't quite use agent_virt here
128 'table' => 'invoice_mode',
129 'hashref' => { 'modenum' => $modenum },
130 'extra_sql' => ' AND '.
131 $FS::CurrentUser::CurrentUser->agentnums_sql(
132 'null_right' => 'Edit global templates',
133 'viewall_right' => 'Edit global templates' ),
138 my ($cgi, $object) = @_;
139 foreach (qw(modename agentnum)) {
140 $object->set($_, $cgi->param($_));
142 if ($object->confnum) {
143 return edit_callback(@_);
145 return new_callback(@_);
150 my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
152 if ( $cgi->param('locale') =~ /^(\w+)$/ ) {
153 $object->set('locale' => $1);
156 if ( $cgi->param('modenum') =~ /^(\d+)$/ ) {
157 $modenum = $1; # we're adding a locale to an existing mode
158 $object->set('modenum' => $modenum);
159 my $invoice_mode = get_invoice_mode($modenum)
160 or die "invoice mode $modenum not found";
162 $object->set('modename', $invoice_mode->modename);
163 $object->set('agentnum', $invoice_mode->agentnum);
165 # also, need to select a locale
166 # make a list of available locales
167 my %existing_locales = map { $_->locale }
168 qsearch('invoice_conf', { modenum => $modenum });
170 my @locales = grep { !exists($existing_locales{$_}) }
171 FS::Conf->new->config('available-locales');
174 my %info = FS::Locales->locale_info($_);
175 $labels{$_} = $info{'label'};
177 unshift @locales, 'new';
178 $labels{'new'} = 'Select language';
182 $i++ until ( $fields_arrayref->[$i]->{'field'} eq 'locale' );
183 my $locale_field = $fields_arrayref->[$i];
185 my $onchange_locale = "document.getElementById('submit').disabled =
186 (this.options[this.selectedIndex].value == 'new');";
191 options => \@locales,
194 onchange => $onchange_locale,
197 } # otherwise it's a completely new mode, so the locale is default
202 # massive false laziness with msg_template UI
203 my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
205 # a little different here in that we treat the content object
206 # as "primary" (this is edit/invoice_conf.html, etc.)
207 # so all we need from the invoice_mode is its name
208 # (and agent identity)
209 my $modenum = $object->modenum;
210 my $invoice_mode = get_invoice_mode($modenum)
211 or die "invoice mode $modenum not found";
212 $object->set('modename', $invoice_mode->modename);
213 $object->set('agentnum', $invoice_mode->agentnum);
217 sub menubar_opt_callback {
219 my $modenum = $object->modenum or return;
220 my (@tabs, @options, %labels);
223 foreach my $l ('', FS::Conf->new->config('available-locales')) {
225 qsearchs('invoice_conf', { modenum => $modenum, locale => $l });
226 if ( $invoice_conf ) {
227 my %info = FS::Locales->locale_info($l) if $l;
228 my $label = $info{'label'} || mt('Default');
229 push @tabs, $label, $invoice_conf->confnum;
230 $selected = $label if $object->locale eq $l;
233 $display_new = 1; # there is at least one unused locale left
236 push @tabs, mt('New'), "modenum=$modenum;locale=new" if $display_new;
237 $selected = mt('New') if $object->locale eq 'new';
238 $selected ||= mt('Default');
240 'url_base' => $cgi->url() . '?',
241 'selected' => $selected,
249 .fstabcontainer th { vertical-align: middle; text-align: center }
254 sub html_table_bottom {
259 if ($object->locale =~ /^(\w+)$/) {
262 if ($object->modenum =~ /^(\d+)$/) {
267 # don't allow the default locale to be removed unless it's the last one
269 $show_delete = 0 if (
273 FS::invoice_conf->count("modenum = $modenum and locale is not null") > 0
277 if ( $show_delete ) {
278 # set up a delete link
279 my $confnum = $object->confnum;
280 my $url = $p."misc/delete-invoice_conf.html?$confnum";
281 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this configuration?')">! .
282 'Delete this configuration' .
284 $html = qq!<TR><TD></TD>
285 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>
286 <SCRIPT TYPE="text/javascript">
287 function areyousure(url, message) {
288 if (confirm(message)) window.location.href = url;