RT# 80138 - Added config option to display/edit customer option to send or not send...
[freeside.git] / httemplate / edit / cust_main / billing.html
1 %  my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
2
3   <SCRIPT>
4
5     function tax_changed(what) {
6       var num = document.getElementById(what.id + '_num'); 
7       if ( what.checked ) {
8         num.disabled = false;
9       } else {
10         num.disabled = true;
11       }
12     }
13     
14   </SCRIPT>
15
16   <BR><FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
17
18   <TABLE CLASS="fsinnerbox">
19
20 %   my $curuser = $FS::CurrentUser::CurrentUser;
21
22 %   ###
23 %   # complimentry flag
24 %   ###
25
26 %   if ( $curuser->access_right('Complimentary customer') ) {
27
28     <& /elements/tr-checkbox.html,
29       field       => 'complimentary',
30       label       => emt('Complimentary customer'),
31       value       => 'Y',
32       curr_value  => $cust_main->complimentary,
33       box_first   => 1,
34     &>
35
36 %   } else {
37
38       <INPUT TYPE="hidden" NAME="complimentary" VALUE="<% $cust_main->complimentary eq 'Y' ? 'Y' : '' %>">
39
40 %   }
41
42 %   ###
43 %   # tax exemptions
44 %   ###
45
46 %   my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
47 %   if (    $conf->exists('cust_class-tax_exempt')
48 %        || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
49 %        || $conf->config('tax-cust_exempt-groups-num_req') =~ /\w/
50 %        || ! $curuser->access_right('Edit customer tax exemptions')
51 %      )
52 %   {
53
54       <INPUT TYPE="hidden" NAME="tax" VALUE="<% $cust_main->tax eq 'Y' ? 'Y' : '' %>">
55
56 %   } else {
57
58     <& /elements/tr-checkbox.html,
59       field       => 'tax',
60       label       => emt('Tax Exempt' . (scalar(@exempt_groups) ? '(all taxes)' : '') ),
61       value       => 'Y',
62       curr_value  => $cust_main->tax,
63       box_first   => 1,
64     &>
65
66 %   }
67
68 %   if ( $curuser->access_right('Edit customer tax exemptions') ) {
69 %     foreach my $exempt_group ( @exempt_groups ) {
70 %       my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
71 %       #escape $exempt_group for NAME etc.
72 %       my $checked = ($cust_main_exemption || $cgi->param("tax_$exempt_group"));
73         <TR>
74           <TD STYLE="white-space:nowrap">&nbsp;&nbsp;<INPUT TYPE="checkbox" NAME="tax_<% $exempt_group %>" ID="tax_<% $exempt_group %>" VALUE="Y" <% $checked ? 'CHECKED' : '' %> onChange="tax_changed(this)"> Tax Exempt (<% $exempt_group %> taxes)</TD>
75           <TD> - Exemption number <INPUT TYPE="text" NAME="tax_<% $exempt_group %>_num" ID="tax_<% $exempt_group %>_num" VALUE="<% $cgi->param("tax_$exempt_group".'_num') || ( $cust_main_exemption ? $cust_main_exemption->exempt_number : '' ) |h %>" <% $checked ? '' : 'DISABLED' %>></TD>
76         </TR>
77 %     } #"
78 %   }
79
80 %   ###
81 %   # postal invoices
82 %   ###
83
84 % unless ( $conf->exists('emailinvoiceonly') ) {
85
86     <& /elements/tr-checkbox.html,
87       field       => 'postal_invoice',
88       label       => emt('Postal mail invoices'),
89       value       => 'Y',
90       curr_value  => $cust_main->postal_invoice,
91       box_first   => 1,
92     &>
93
94 % }
95
96 %   ###
97 %   # email invoices
98 %   ###
99
100     <& /elements/tr-checkbox.html,
101       field       => 'invoice_noemail',
102       label       => emt('Do not send email invoices'),
103       value       => 'Y',
104       curr_value  => $cust_main->invoice_noemail,
105       box_first   => 1,
106     &>
107
108 % if ( $conf->config_bool('allow_payment_receipt_noemail', $cust_main->agentnum) ) {
109     <& /elements/tr-checkbox.html,
110       field       => 'paymentreceipt_noemail',
111       label       => emt('Do not send email payment receipts'),
112       value       => 'Y',
113       curr_value  => $cust_main->paymentreceipt_noemail,
114       box_first   => 1,
115     &>
116 % }
117
118     <& /elements/tr-checkbox.html,
119       field       => 'message_noemail',
120       label       => emt('Do not send other email notices'),
121       value       => 'Y',
122       curr_value  => $cust_main->message_noemail,
123       box_first   => 1,
124     &>
125
126 %   ###
127 %   # prorate_day
128 %   ###
129
130 % if ( $conf->exists('cust_main-select-prorate_day') ) {
131     <TR>
132       <TH ALIGN="right" WIDTH="200"><% mt('Prorate day') |h %> </TD>
133       <TD>
134         <SELECT NAME="prorate_day">
135           <% prorate_day_options($cust_main->prorate_day) %>
136         </SELECT>
137         <& /elements/checkbox.html,
138           field       => 'force_prorate_day',
139           value       => 'Y',
140           curr_value  => $cust_main->force_prorate_day
141         &>
142         <label><% emt('Force all packages to this day') %></label>
143       </TD>
144     </TR>
145
146 %   sub prorate_day_options {
147 %     my $curr_value = shift;
148 %     my $ret = '';
149 %     for my $prorate_day ( 1 .. 28 ) {
150 %       my $sel = '';
151 %       $sel = "SELECTED='SELECTED'" if $curr_value == $prorate_day;
152 %       $ret .= "<OPTION VALUE='$prorate_day' $sel>$prorate_day</OPTION>";
153 %     }
154 %     $ret;
155 %    }
156
157 % } else {
158     <INPUT TYPE="hidden" NAME="prorate_day" VALUE="<% $cust_main->prorate_day %>">
159 % }
160
161 %   ###
162 %   # billday
163 %   ###
164
165     <TR>
166       <TH ALIGN="right" WIDTH="200"><% mt('Charge card/e-check on this day of the month') |h %> </TD>
167       <TD>
168         <SELECT NAME="billday">
169           <% billday_options($cust_main->billday) %>
170         </SELECT>
171       </TD>
172     </TR>
173
174 %  sub billday_options {
175 %   my $curr_value = shift;
176 %   my $ret = '';
177 %   for my $billday ( 1 .. 28 ) {
178 %       my $sel = '';
179 %       $sel = "SELECTED='SELECTED'" if $curr_value == $billday;
180 %       $ret .= "<OPTION VALUE='$billday' $sel>$billday</OPTION>";
181 %   }
182 %   $ret;
183 %  }
184
185 %   ###
186 %   # invoice_terms
187 %   ###
188
189     <TR>
190       <TH ALIGN="right" WIDTH="200"><% mt('Invoice terms') |h %> </TD>
191       <TD WIDTH="408">
192 %       if ( $curuser->access_right('Edit customer invoice terms') ) {
193           <& /elements/select-terms.html,
194                'curr_value' => $cust_main->invoice_terms,
195                'agentnum'   => $cust_main->agentnum,
196           &>
197 %       } else {
198 %
199 %         my $terms =
200 %           $cust_main->invoice_terms
201 %             || emt('Default').' ('.
202 %                ( $conf->config('invoice_default_terms', $cust_main->agentnum)
203 %                    || emt('Payable upon receipt')
204 %                ).
205 %                ')';
206           <% $terms |h %>
207
208           <& /elements/hidden.html, 
209                'field'      => 'invoice_terms',
210                'curr_value' => $cust_main->invoice_terms,
211           &>
212 %       }
213       </TD>
214     </TR>
215
216 %   ###
217 %   # credit_limit
218 %   ###
219
220     <TR>
221       <TH ALIGN="right" WIDTH="200"><% mt('Credit limit') |h %> </TD>
222       <TD WIDTH="408">
223         <SCRIPT TYPE="text/javascript">
224 function toggle(obj) {
225   obj.form.credit_limit.disabled = obj.checked;
226 }
227         </SCRIPT>
228         <INPUT TYPE  = "text"
229                NAME  = "credit_limit"
230                VALUE = "<% sprintf('%.2f', $cust_main->credit_limit) %>"
231                <% length($cust_main->credit_limit) ? '' : ' DISABLED' %>
232         >
233 %       my $default_credit_limit = $conf->config('default_credit_limit');
234         <INPUT TYPE  = "checkbox"
235                NAME  = "no_credit_limit"
236                VALUE = 1
237                onClick="toggle(this)"
238                <% length($cust_main->credit_limit) ? '' : ' CHECKED'%>
239         > <FONT SIZE="-1" COLOR="#333333">
240           <% $default_credit_limit
241                ? "Default ($money_char". sprintf("%.2f", $default_credit_limit).
242                  ")"
243                : mt('Unlimited')
244             |h
245           %>
246           </FONT> 
247       </TD>
248     </TR>
249
250 %   ###
251 %   # CDR flags / options
252 %   ###
253
254 % if ( $conf->exists('voip-cust_cdr_spools') ) { 
255       <TR>
256        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="spool_cdr" VALUE="Y" <% $cust_main->spool_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt('Spool CDRs') |h %></TD>
257       </TR>
258 % } else { 
259       <INPUT TYPE="hidden" NAME="spool_cdr" VALUE="<% $cust_main->spool_cdr %>">
260 % }
261
262 % if ( $conf->exists('voip-cust_cdr_squelch') ) { 
263       <TR>
264        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="squelch_cdr" VALUE="Y" <% $cust_main->squelch_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt($conf->exists('voip-cdr_email') ? 'Omit CDRs from printed invoices' : 'Omit CDRs from invoices') |h %></TD>
265       </TR>
266 % } else { 
267       <INPUT TYPE="hidden" NAME="squelch_cdr" VALUE="<% $cust_main->squelch_cdr %>">
268 % }
269
270 % if ( my $attach = $conf->config('voip-cdr_email_attach') ) {
271       <TR>
272        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="email_csv_cdr" VALUE="Y" <% $cust_main->email_csv_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt('Attach CDRs as '. uc($attach). ' to emailed invoices') |h %></TD>
273       </TR>
274 % } else { 
275       <INPUT TYPE="hidden" NAME="email_csv_cdr" VALUE="<% $cust_main->email_csv_cdr %>">
276 % }
277
278 % if ( $conf->exists('voip-cust_accountcode_cdr') ) { 
279        <TR>
280         <TD COLSPAN="2">
281             <INPUT TYPE="checkbox" 
282                    NAME="accountcode_cdr" 
283                    VALUE="Y" 
284                    <% $cust_main->accountcode_cdr eq "Y" ? 'CHECKED' : '' %>
285             > <% mt('Breakdown CDRs by accountcode') |h %></TD>
286        </TR>
287 % } else { 
288        <INPUT TYPE="hidden" NAME="accountcode_cdr" VALUE="<% $cust_main->accountcode_cdr %>">
289 % }
290
291 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
292       <TR>
293        <TH ALIGN="right"><% mt('CDR termination settlement') |h %></TD>
294        <TD><INPUT TYPE  = "text"
295                   NAME  = "cdr_termination_percentage"
296                   SIZE  = 6
297                   VALUE = "<% $cust_main->cdr_termination_percentage %>"
298                   STYLE = "text-align:right;"
299         ><B>%</B></TD>
300       </TR>
301 % } else {
302       <INPUT TYPE="hidden" NAME="cdr_termination_percentage" VALUE="<% $cust_main->cdr_termination_percentage %>">
303 % }
304
305 %   ###
306 %   # Invoicing currency
307 %   ###
308
309 %my @currencies = $conf->config('currencies');
310 %if ( scalar(@currencies) ) {
311 %  unshift @currencies, ''; #default
312 %  my %currency_labels = map { $_ => "$_: ". code2currency($_) } @currencies;
313 %  $currency_labels{''} =
314 %    'Default: '. code2currency( $conf->config('currency') || 'USD' );
315
316     <& /elements/tr-select.html, 
317          'label'         => emt('Invoicing currency'),
318          'field'         => 'currency',
319          'options'       => \@currencies,
320          'labels'        => \%currency_labels,
321          'curr_value'    => $cust_main->currency,
322     &>
323 % }
324
325 %   ###
326 %   # Invoicing locale
327 %   ###
328
329 %my @available_locales = $conf->config('available-locales');
330 %if ( scalar(@available_locales) ) {
331 %  push @available_locales, ''
332 %    unless $cust_main->locale && $conf->exists('cust_main-require_locale');
333 %  my %locale_labels = map { 
334 %    my %ll;
335 %    my %info = FS::Locales->locale_info($_);
336 %    $ll{$_} = $info{name} . " (" . $info{country} . ")";
337 %    %ll;
338 %  } FS::Locales->locales;
339 %    
340 %  my $label = ( $conf->exists('cust_main-require_locale') ? $r : '' ).
341 %              emt('Invoicing locale');
342
343     <& /elements/tr-select.html, 
344          'label'         => $label,
345          'field'         => 'locale',
346          'options'       => \@available_locales,
347          'labels'        => \%locale_labels,
348          'curr_value'    => $cust_main->locale,
349     &>
350 % }
351
352   </TABLE>
353   <BR>
354
355   <FONT CLASS="fsinnerbox-title"><% mt('Payment information') |h %></FONT>
356   <& cust_payby.html, 'cust_main'=>$cust_main, &>  
357
358 <%init>
359
360 my( $cust_main, %options ) = @_;
361 my @invoicing_list = @{ $options{'invoicing_list'} };
362 my $conf = new FS::Conf;
363
364 my $money_char = $conf->config('money_char') || '$';
365
366 my $show_term = '';
367 if ( $cust_main->custnum ) {
368   #false laziness w/view/cust_main/billing.html
369   my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
370   my $term_sth = dbh->prepare($term_sql)  or die dbh->errstr;
371   $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
372   $show_term = $term_sth->fetchrow_arrayref->[0];
373 }
374
375 my $agentnum = $cust_main->agentnum if $cust_main->custnum;
376
377 </%init>