common element for cust_pkg search form fields
[freeside.git] / httemplate / misc / payment.cgi
1 <& /elements/header-cust_main.html, view=>'payment_history', cust_main=>$cust_main &>
2
3 <h2><% emt("Process [_1] payment",$type{$payby}) %></h2>
4
5 <FORM NAME="OneTrueForm" ACTION="process/payment.cgi" METHOD="POST" onSubmit="document.OneTrueForm.process.disabled=true">
6 <INPUT TYPE="hidden" NAME="custnum"   VALUE="<% $custnum %>">
7 <INPUT TYPE="hidden" NAME="payby"     VALUE="<% $payby %>">
8 <INPUT TYPE="hidden" NAME="payunique" VALUE="<% $payunique %>">
9 <INPUT TYPE="hidden" NAME="balance"   VALUE="<% $balance %>">
10
11 <& /elements/init_overlib.html &>
12
13 <TABLE class="fsinnerbox">
14
15   <& /elements/tr-select-payment_options.html,
16        'cust_main'          => $cust_main,
17        'process-pkgpart'    => 
18           scalar($conf->config('manual_process-pkgpart', $cust_main->agentnum)),
19        'process-display'    => scalar($conf->config('manual_process-display')),
20        'process-skip_first' => $conf->exists('manual_process-skip_first'),
21        'num_payments'       => scalar($cust_main->cust_pay), 
22        'surcharge_percentage' =>
23          ( $payby eq 'CARD'
24              ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
25              : 0
26          ),
27        'surcharge_flatfee' =>
28          ( $payby eq 'CARD'
29              ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
30              : 0
31          ),
32          'processing_fee' => scalar($conf->config('processing-fee', $cust_main->agentnum)),
33   &>
34
35 % if ( $conf->exists('part_pkg-term_discounts') ) {
36     <& /elements/tr-select-discount_term.html,
37          'custnum'   => $custnum,
38          'amount_id' => 'amount',
39     &>
40 % }
41
42 % my $disallow_no_auto_apply = 0;
43 % if ( $conf->exists("batch-enable")
44 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
45 %    ) {
46 %
47 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
48 %       $disallow_no_auto_apply = 1;
49
50           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
51
52 %     } else {
53
54           <TR>
55             <TH ALIGN="right">&nbsp;&nbsp;&nbsp;<% mt('Add to current batch') |h %></TH>
56             <TD>
57               <INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch_checkbox" ONCHANGE="change_batch_checkbox()">
58             </TD>
59           </TR>
60
61 %     }
62 % }
63
64 % unless ($disallow_no_auto_apply) {
65 %   # false laziness with edit/cust_pay.cgi
66
67 <TR ID="apply_box_row">
68   <TH ALIGN="right"><% mt('Auto-apply to invoices') |h %></TH>
69   <TD>
70     <SELECT NAME="apply" ID="apply_box">
71       <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
72       <OPTION VALUE=""><% mt('not now') |h %></OPTION>
73       <OPTION VALUE="never"><% mt('never') |h %></OPTION>
74     </SELECT>
75   </TD>
76 </TR>
77
78 % # this can go away if no_auto_apply handling gets added to batch payment processing
79 <SCRIPT>
80 function change_batch_checkbox () {
81   if (document.getElementById('batch_checkbox').checked) {
82     document.getElementById('apply_box').disabled = true;
83     document.getElementById('apply_box_row').style.display = 'none';
84   } else {
85     document.getElementById('apply_box').disabled = false;
86     document.getElementById('apply_box_row').style.display = '';
87   }
88 }
89 </SCRIPT>
90
91 % }
92
93 <SCRIPT TYPE="text/javascript">
94   function cust_payby_changed (what) {
95     var custpaybynum = what.options[what.selectedIndex].value
96     if ( custpaybynum == '' || custpaybynum == '0' ) {
97        //what.form.payinfo.disabled = false;
98        $('#cust_payby').slideDown();
99     } else {
100        //what.form.payinfo.value = '';
101        //what.form.payinfo.disabled = true;
102        $('#cust_payby').slideUp();
103     }
104   }
105
106   function enableAmountField() {
107     document.getElementById('amount').disabled = false;
108   }
109
110 </SCRIPT>
111
112 % #can't quite handle CARD/CHEK on the same page yet, but very close
113 % #does it make sense from a UI/usability perspective?
114 %
115 % my @cust_payby = ();
116 % if ( $payby eq 'CARD' ) {
117 %   @cust_payby = $cust_main->cust_payby('CARD','DCRD');
118 % } elsif ( $payby eq 'CHEK' ) {
119 %   @cust_payby = $cust_main->cust_payby('CHEK','DCHK');
120 % } else {
121 %   die "unknown payby $payby";
122 % }
123 %
124 % my $custpaybynum = length(scalar($cgi->param('custpaybynum')))
125 %                      ? scalar($cgi->param('custpaybynum'))
126 %                      : scalar(@cust_payby) && $cust_payby[0]->custpaybynum;
127
128 <& /elements/tr-select-cust_payby.html,
129      'cust_payby' => \@cust_payby,
130      'curr_value' => $custpaybynum,
131      'onchange'   => 'cust_payby_changed(this)',
132 &>
133
134 </TABLE>
135 <BR>
136 <DIV ID="cust_payby"
137   <% $custpaybynum ? 'STYLE="display:none"'
138                    : ''
139   %>
140 >
141 <TABLE class="fsinnerbox">
142
143 <& /elements/cust_payby_new.html,
144      'cust_payby' => \@cust_payby,
145      'curr_value' => $custpaybynum,
146 &>
147
148 </TABLE>
149 </DIV>
150
151 <BR>
152 <INPUT TYPE="submit" NAME="process" ID="process" VALUE="<% mt('Process payment') |h %>" disabled="disabled" onclick="enableAmountField()">
153 </FORM>
154
155 <SCRIPT TYPE="text/javascript">
156
157 $(document).ready(function (){
158     validate();
159     $('<% $validate_select_fields %>').change(validate);
160     $('<% $validate_input_fields %>').keyup(validate);
161 });
162
163 function validate(){
164     if (
165       $('#amount').val() > 0 && (
166         ( $('#custpaybynum').val() > 0 ) ||
167 % if ($payby eq "CHEK") {
168         ( $('input[name=payinfo1]').val().length > 0 &&
169           $('input[name=payinfo2]').val().length > 0 &&
170           $('input[name=payname]').val().length > 0  &&
171           $('select[name=paytype]').val().length > 0
172         )
173 % }
174 % elsif ($payby eq "CARD") {
175         ( $('input[name=payinfo]').val().length > 0 &&
176           $('input[name=paycvv]').val().length > 0 &&
177           $('input[name=payname]').val().length > 0 &&
178           $('#city').val().length > 0 &&
179           $('#city').val().length > 0 &&
180           $('#state').val().length > 0 &&
181           $('#country').val().length > 0
182         )
183 % }
184       )
185      ) {
186         $("#process").prop("disabled", false);
187     }
188     else {
189         $("#process").prop("disabled", true);
190     }
191 }
192
193 </SCRIPT>
194
195 <& /elements/footer-cust_main.html &>
196 <%once>
197
198 my %weight = (
199   1 => 'Primary',
200   2 => 'Secondary',
201   3 => 'Tertiary',
202   4 => 'Fourth',
203   5 => 'Fifth',
204   6 => 'Sixth',
205   7 => 'Seventh',
206 );
207
208 </%once>
209 <%init>
210
211 die "access denied"
212   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
213
214 my %type = ( 'CARD' => 'credit card',
215              'CHEK' => 'electronic check (ACH)',
216            );
217
218 $cgi->param('payby') =~ /^(CARD|CHEK)$/
219   or die "unknown payby ". $cgi->param('payby');
220 my $payby = $1;
221
222 my $validate_select_fields = "#payment_option, #invoice, #custpaybynum, ";
223 my $validate_input_fields  = "#amount, input[name=payname], ";
224 if ($payby eq "CHEK") {
225   $validate_input_fields  .= "input[name=payinfo1], input[name=payinfo2]";
226   $validate_select_fields .= "select[name=paytype] ";
227 }
228 elsif ($payby eq "CARD") {
229   $validate_input_fields  .= "input[name=payinfo], input[name=paycvv], input[name=address1], #city, #zip";
230   $validate_select_fields .= "#state, #country ";
231 }
232
233 $cgi->param('custnum') =~ /^(\d+)$/
234   or die "illegal custnum ". $cgi->param('custnum');
235 my $custnum = $1;
236
237 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
238 die "unknown custnum $custnum" unless $cust_main;
239
240 my $balance = $cust_main->balance;
241
242 my $payinfo = '';
243
244 my $conf = new FS::Conf;
245
246 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
247
248 </%init>