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