acc67c4b54aa97018f39750e22bc4516d92d57f8
[freeside.git] / httemplate / edit / cust_pay.cgi
1 % if ( $link eq 'popup' ) { 
2   <& /elements/header-popup.html, $title  &>
3 % } else { 
4   <& /elements/header-cust_main.html, view=>'payment_history', custnum=>$custnum &>
5   <h2><% $title |h %></h2>
6 % } 
7
8 <& /elements/init_calendar.html &>
9
10 <& /elements/error.html &>
11
12 <FORM NAME="PaymentForm" ACTION="<% popurl(1) %>process/cust_pay.cgi" METHOD=POST onSubmit="document.PaymentForm.submitButton.disabled=true">
13 <INPUT TYPE="hidden" NAME="link" VALUE="<% $link %>">
14 <INPUT TYPE="hidden" NAME="linknum" VALUE="<% $linknum %>">
15 <INPUT TYPE="hidden" NAME="payby" VALUE="<% $payby %>">
16 <INPUT TYPE="hidden" NAME="paybatch" VALUE="<% $paybatch %>">
17
18 <% ntable("#cccccc", 2) %>
19
20 % my %date_args = (
21 %   'name'    =>  '_date',
22 %   'label'   => emt('Date'),
23 %   'value'   => $_date,
24 %   'format'  => $date_format. ' %r',
25 %   'colspan' => 2,
26 % );
27 % if ( $FS::CurrentUser::CurrentUser->access_right('Backdate payment') ) {
28
29   <& /elements/tr-input-date-field.html, \%date_args &>
30
31 % } else {
32
33   <& /elements/tr-fixed-date.html, \%date_args &>
34
35 % }
36
37 <TR>
38   <TD ALIGN="right"><% mt('Amount') |h %></TD>
39   <TD BGCOLOR="#ffffff"><% $money_char |h %><INPUT TYPE="text" NAME="paid" ID="paid" VALUE="<% $paid %>" SIZE=8 MAXLENGTH=9> <% mt('by') |h %> <B><% mt(FS::payby->payname($payby)) |h %></B></TD>
40 </TR>
41
42 % if ( $conf->exists('part_pkg-term_discounts') ) {
43     <& /elements/tr-select-discount_term.html,
44          'custnum'   => $custnum,
45          'amount_id' => 'paid',
46     &>
47 % }
48
49 % if ( $payby eq 'BILL' ) { 
50   <TR>
51     <TD ALIGN="right"><% mt('Check #') |h %></TD>
52     <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
53   </TR>
54 % }
55 % elsif ( $payby eq 'CASH' and $conf->exists('require_cash_deposit_info') ) {
56   <TR>
57     <TD ALIGN="right"><% mt('Bank') |h %></TD>
58     <TD COLSPAN=3><INPUT TYPE="text" NAME="bank" VALUE="<% $cgi->param('bank') %>"></TD>
59   </TR>
60   <TR>
61     <TD ALIGN="right"><% mt('Check #') |h %></TD>
62     <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
63   </TR>
64   <TR>
65     <TD ALIGN="right"><% mt('Teller #') |h %></TD>
66     <TD COLSPAN=2><INPUT TYPE="text" NAME="teller" VALUE="<% $cgi->param('teller') %>" SIZE=10></TD>
67   </TR>
68   <TR>
69     <TD ALIGN="right"><% mt('Depositor') |h %></TD>
70     <TD COLSPAN=3><INPUT TYPE="text" NAME="depositor" VALUE="<% $cgi->param('depositor') %>"></TD>
71   </TR>
72   <TR>
73     <TD ALIGN="right"><% mt('Account #') |h %></TD>
74     <TD COLSPAN=2><INPUT TYPE="text" NAME="account" VALUE="<% $cgi->param('account') %>" SIZE=18></TD>
75   </TR>
76 % }
77
78 <TR>
79 % if ( $link eq 'custnum' || $link eq 'popup' ) { 
80
81   <TD ALIGN="right"><% mt('Auto-apply to invoices') |h %></TD>
82   <TD COLSPAN=2>
83     <SELECT NAME="apply">
84       <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
85       <OPTION VALUE=""><% mt('not now') |h %></OPTION>
86       <OPTION VALUE="never"><% mt('never') |h %></OPTION>
87     </SELECT>
88   </TD>
89
90 % } elsif ( $link eq 'invnum' ) { 
91
92   <TD ALIGN="right"><% mt('Apply to') |h %></TD>
93   <TD COLSPAN=2 BGCOLOR="#ffffff">Invoice #<B><% $linknum %></B> only</TD>
94   <INPUT TYPE="hidden" NAME="apply" VALUE="">
95
96 % } 
97 </TR>
98
99 % if ( $conf->exists('pkg-balances') ) {
100   <& /elements/tr-select-cust_pkg-balances.html,
101                'custnum' => $custnum,
102                'cgi'     => $cgi
103   &>
104 % } else {
105   <INPUT TYPE="hidden" NAME="pkgnum" VALUE="">
106 % }
107
108 </TABLE>
109
110 <BR>
111 <INPUT NAME="submitButton" TYPE="submit" VALUE="<% mt('Post payment') |h %>">
112
113 </FORM>
114
115 % if ( $link eq 'popup' ) { 
116     </BODY>
117     </HTML>
118 % } else { 
119     <& /elements/footer-cust_main.html &>
120 % } 
121
122 <%init>
123
124 my $conf = new FS::Conf;
125
126 my $money_char  = $conf->config('money_char')  || '$';
127 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
128
129 my($link, $linknum, $paid, $payby, $payinfo, $_date);
130 if ( $cgi->param('error') ) {
131   $link     = $cgi->param('link');
132   $linknum  = $cgi->param('linknum');
133   $paid     = $cgi->param('paid');
134   $payby    = $cgi->param('payby');
135   $payinfo  = $cgi->param('payinfo');
136   $_date    = $cgi->param('_date') ? parse_datetime($cgi->param('_date')) : time;
137 } elsif ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
138   $link     = $cgi->param('popup') ? 'popup' : 'custnum';
139   $linknum  = $1;
140   $paid     = '';
141   $payby    = $cgi->param('payby') || 'BILL';
142   $payinfo  = '';
143   $_date    = time;
144 } elsif ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
145   $link     = 'invnum';
146   $linknum  = $1;
147   $paid     = '';
148   $payby    = $cgi->param('payby') || 'BILL';
149   $payinfo  = "";
150   $_date    = time;
151 } else {
152   die "illegal query ". $cgi->keywords;
153 }
154
155 my @rights = ('Post payment');
156 push @rights, 'Post check payment' if $payby eq 'BILL';
157 push @rights, 'Post cash payment'  if $payby eq 'CASH';
158
159 die "access denied"
160   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
161
162 my $paybatch = "webui-$_date-$$-". rand() * 2**32;
163
164 my $title = mt('Post '. FS::payby->payname($payby). ' payment');
165 $title .= mt(" against Invoice #[_1]",$linknum) if $link eq 'invnum';
166
167 my $custnum;
168 if ( $link eq 'invnum' ) {
169   my $cust_bill = qsearchs('cust_bill', { 'invnum' => $linknum } )
170     or die "unknown invnum $linknum";
171   $custnum = $cust_bill->custnum;
172 } elsif ( $link eq 'custnum' || $link eq 'popup' ) {
173   $custnum = $linknum;
174 }
175
176 </%init>