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