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