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