summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_pay.cgi
blob: f9f99de7e0d47f7f209fd3fcdf5d5c7bcb8146aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
% if ( $link eq 'popup' ) { 
  <& /elements/header-popup.html, $title  &>
% } else { 
  <& /elements/header-cust_main.html, view=>'payment_history', custnum=>$custnum &>
  <h2><% $title |h %></h2>
% } 

<& /elements/init_calendar.html &>

<& /elements/error.html &>

<FORM NAME="PaymentForm" ACTION="<% popurl(1) %>process/cust_pay.cgi" METHOD=POST onSubmit="document.PaymentForm.submitButton.disabled=true">
<INPUT TYPE="hidden" NAME="link" VALUE="<% $link %>">
<INPUT TYPE="hidden" NAME="linknum" VALUE="<% $linknum %>">
<INPUT TYPE="hidden" NAME="payby" VALUE="<% $payby %>">
<INPUT TYPE="hidden" NAME="paybatch" VALUE="<% $paybatch %>">

<TABLE CLASS="fsinnerbox">

% my %date_args = (
%   'name'    =>  '_date',
%   'label'   => emt('Date'),
%   'value'   => $_date,
%   'format'  => $date_format. ' %r',
%   'colspan' => 2,
% );
% if ( $FS::CurrentUser::CurrentUser->access_right('Backdate payment') ) {

  <& /elements/tr-input-date-field.html, \%date_args &>

% } else {

  <& /elements/tr-fixed-date.html, \%date_args &>

% }

<TR>
  <TH ALIGN="right"><% mt('Amount') |h %></TH>
  <TD><% $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>
</TR>

% if ( $conf->exists('part_pkg-term_discounts') ) {
    <& /elements/tr-select-discount_term.html,
         'custnum'   => $custnum,
         'amount_id' => 'paid',
    &>
% }

% if ( $payby eq 'BILL' ) { 
  <TR>
    <TH ALIGN="right"><% mt('Check #') |h %></TH>
    <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
  </TR>
% }
% elsif ( $payby eq 'CASH' and $conf->exists('require_cash_deposit_info') ) {
  <TR>
    <TH ALIGN="right"><% mt('Bank') |h %></TH>
    <TD COLSPAN=3><INPUT TYPE="text" NAME="bank" VALUE="<% $cgi->param('bank') %>"></TD>
  </TR>
  <TR>
    <TH ALIGN="right"><% mt('Check #') |h %></TH>
    <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
  </TR>
  <TR>
    <TH ALIGN="right"><% mt('Teller #') |h %></TH>
    <TD COLSPAN=2><INPUT TYPE="text" NAME="teller" VALUE="<% $cgi->param('teller') %>" SIZE=10></TD>
  </TR>
  <TR>
    <TH ALIGN="right"><% mt('Depositor') |h %></TH>
    <TD COLSPAN=3><INPUT TYPE="text" NAME="depositor" VALUE="<% $cgi->param('depositor') %>"></TD>
  </TR>
  <TR>
    <TH ALIGN="right"><% mt('Account #') |h %></TH>
    <TD COLSPAN=2><INPUT TYPE="text" NAME="account" VALUE="<% $cgi->param('account') %>" SIZE=18></TD>
  </TR>
% }

<TR>
% if ( $link eq 'custnum' || $link eq 'popup' ) { 

  <TD ALIGN="right"><% mt('Auto-apply to invoices') |h %></TD>
  <TD COLSPAN=2>
    <SELECT NAME="apply">
      <OPTION VALUE="yes" SELECTED><% mt('yes') |h %></OPTION> 
      <OPTION VALUE=""><% mt('not now') |h %></OPTION>
      <OPTION VALUE="never"><% mt('never') |h %></OPTION>
    </SELECT>
  </TD>

% } elsif ( $link eq 'invnum' ) { 

  <TH ALIGN="right"><% mt('Apply to') |h %></TH>
  <TD COLSPAN=2>Invoice #<B><% $linknum %></B> only</TD>
  <INPUT TYPE="hidden" NAME="apply" VALUE="">

% } 
</TR>

% if ( $conf->exists('pkg-balances') ) {
  <& /elements/tr-select-cust_pkg-balances.html,
               'custnum' => $custnum,
               'cgi'     => $cgi
  &>
% } else {
  <INPUT TYPE="hidden" NAME="pkgnum" VALUE="">
% }

</TABLE>

<BR>
<INPUT NAME="submitButton" TYPE="submit" VALUE="<% mt('Post payment') |h %>">

</FORM>

% if ( $link eq 'popup' ) { 
    </BODY>
    </HTML>
% } else { 
    <& /elements/footer-cust_main.html &>
% } 

<%init>

my $conf = new FS::Conf;

my $money_char  = $conf->config('money_char')  || '$';
my $date_format = $conf->config('date_format') || '%m/%d/%Y';

my($link, $linknum, $paid, $payby, $payinfo, $_date);
if ( $cgi->param('error') ) {
  $link     = $cgi->param('link');
  $linknum  = $cgi->param('linknum');
  $paid     = $cgi->param('paid');
  $payby    = $cgi->param('payby');
  $payinfo  = $cgi->param('payinfo');
  $_date    = $cgi->param('_date') ? parse_datetime($cgi->param('_date')) : time;
} elsif ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
  $link     = $cgi->param('popup') ? 'popup' : 'custnum';
  $linknum  = $1;
  $paid     = '';
  $payby    = $cgi->param('payby') || 'BILL';
  $payinfo  = '';
  $_date    = time;
} elsif ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
  $link     = 'invnum';
  $linknum  = $1;
  $paid     = '';
  $payby    = $cgi->param('payby') || 'BILL';
  $payinfo  = "";
  $_date    = time;
} else {
  die "illegal query ". $cgi->keywords;
}

my @rights = ('Post payment');
push @rights, 'Post check payment' if $payby eq 'BILL';
push @rights, 'Post cash payment'  if $payby eq 'CASH';

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right(\@rights);

my $paybatch = "webui-$_date-$$-". rand() * 2**32;

my $title = mt('Post '. FS::payby->payname($payby). ' payment');
$title .= mt(" against Invoice #[_1]",$linknum) if $link eq 'invnum';

my $custnum;
if ( $link eq 'invnum' ) {
  my $cust_bill = qsearchs('cust_bill', { 'invnum' => $linknum } )
    or die "unknown invnum $linknum";
  $custnum = $cust_bill->custnum;
} elsif ( $link eq 'custnum' || $link eq 'popup' ) {
  $custnum = $linknum;
}

</%init>