RT# 77498 - Customer Import now uses contact/Import.pm rather than contact_import.pm
[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-amount_fee.html,
16        'amount'             => $amount,
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   &>
33
34 % if ( $conf->exists('part_pkg-term_discounts') ) {
35     <& /elements/tr-select-discount_term.html,
36          'custnum'   => $custnum,
37          'amount_id' => 'amount',
38     &>
39 % }
40
41 % my $disallow_no_auto_apply = 0;
42 % if ( $conf->exists("batch-enable")
43 %      || grep $payby eq $_, $conf->config('batch-enable_payby')
44 %    ) {
45 %
46 %     if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) {
47 %       $disallow_no_auto_apply = 1;
48
49           <INPUT TYPE="hidden" NAME="batch" VALUE="1">
50
51 %     } else {
52
53           <TR>
54             <TH ALIGN="right">&nbsp;&nbsp;&nbsp;<% mt('Add to current batch') |h %></TH>
55             <TD>
56               <INPUT TYPE="checkbox" NAME="batch" VALUE="1" ID="batch_checkbox" ONCHANGE="change_batch_checkbox()">
57             </TD>
58           </TR>
59
60 %     }
61 % }
62
63 % unless ($disallow_no_auto_apply) {
64 %   # false laziness with edit/cust_pay.cgi
65
66 <TR ID="apply_box_row">
67   <TH ALIGN="right"><% mt('Auto-apply to invoices') |h %></TH>
68   <TD>
69     <SELECT NAME="apply" ID="apply_box">
70       <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
71       <OPTION VALUE=""><% mt('not now') |h %></OPTION>
72       <OPTION VALUE="never"><% mt('never') |h %></OPTION>
73     </SELECT>
74   </TD>
75 </TR>
76
77 % # this can go away if no_auto_apply handling gets added to batch payment processing
78 <SCRIPT>
79 function change_batch_checkbox () {
80   if (document.getElementById('batch_checkbox').checked) {
81     document.getElementById('apply_box').disabled = true;
82     document.getElementById('apply_box_row').style.display = 'none';
83   } else {
84     document.getElementById('apply_box').disabled = false;
85     document.getElementById('apply_box_row').style.display = '';
86   }
87 }
88 </SCRIPT>
89
90 % }
91
92 <SCRIPT TYPE="text/javascript">
93   function cust_payby_changed (what) {
94     var custpaybynum = what.options[what.selectedIndex].value
95     if ( custpaybynum == '' || custpaybynum == '0' ) {
96        //what.form.payinfo.disabled = false;
97        $('#cust_payby').slideDown();
98     } else {
99        //what.form.payinfo.value = '';
100        //what.form.payinfo.disabled = true;
101        $('#cust_payby').slideUp();
102     }
103   }
104 </SCRIPT>
105
106 % #can't quite handle CARD/CHEK on the same page yet, but very close
107 % #does it make sense from a UI/usability perspective?
108 %
109 % my @cust_payby = ();
110 % if ( $payby eq 'CARD' ) {
111 %   @cust_payby = $cust_main->cust_payby('CARD','DCRD');
112 % } elsif ( $payby eq 'CHEK' ) {
113 %   @cust_payby = $cust_main->cust_payby('CHEK','DCHK');
114 % } else {
115 %   die "unknown payby $payby";
116 % }
117 %
118 % my $custpaybynum = length(scalar($cgi->param('custpaybynum')))
119 %                      ? scalar($cgi->param('custpaybynum'))
120 %                      : scalar(@cust_payby) && $cust_payby[0]->custpaybynum;
121
122 <& /elements/tr-select-cust_payby.html,
123      'cust_payby' => \@cust_payby,
124      'curr_value' => $custpaybynum,
125      'onchange'   => 'cust_payby_changed(this)',
126 &>
127
128 </TABLE>
129 <BR>
130 <DIV ID="cust_payby"
131   <% $custpaybynum ? 'STYLE="display:none"'
132                    : ''
133   %>
134 >
135 <TABLE class="fsinnerbox">
136
137 <& /elements/cust_payby_new.html,
138      'cust_payby' => \@cust_payby,
139      'curr_value' => $custpaybynum,
140 &>
141
142 </TABLE>
143 </DIV>
144
145 <BR>
146 <INPUT TYPE="submit" NAME="process" VALUE="<% mt('Process payment') |h %>">
147 </FORM>
148
149 <& /elements/footer-cust_main.html &>
150 <%once>
151
152 my %weight = (
153   1 => 'Primary',
154   2 => 'Secondary',
155   3 => 'Tertiary',
156   4 => 'Fourth',
157   5 => 'Fifth',
158   6 => 'Sixth',
159   7 => 'Seventh',
160 );
161
162 </%once>
163 <%init>
164
165 die "access denied"
166   unless $FS::CurrentUser::CurrentUser->access_right('Process payment');
167
168 my %type = ( 'CARD' => 'credit card',
169              'CHEK' => 'electronic check (ACH)',
170            );
171
172 $cgi->param('payby') =~ /^(CARD|CHEK)$/
173   or die "unknown payby ". $cgi->param('payby');
174 my $payby = $1;
175
176 $cgi->param('custnum') =~ /^(\d+)$/
177   or die "illegal custnum ". $cgi->param('custnum');
178 my $custnum = $1;
179
180 my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } );
181 die "unknown custnum $custnum" unless $cust_main;
182
183 my $balance = $cust_main->balance;
184
185 my $payinfo = '';
186
187 my $conf = new FS::Conf;
188
189 my $amount = '';
190 if ( $balance > 0 ) {
191   # when configured to do so, amount will only auto-fill with balance
192   # if balance represents a single invoice
193   $amount = $balance
194     unless $conf->exists('manual_process-single_invoice_amount')
195       && ($cust_main->open_cust_bill != 1);
196 }
197
198 my $payunique = "webui-payment-". time. "-$$-". rand() * 2**32;
199
200 </%init>