0bb86e352e4bab0622273a68536f83ba70897fd4
[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><BR>
22
23 <% mt('Payment') |h %> 
24 <% ntable("#cccccc", 2) %>
25
26 <TR>
27   <TD ALIGN="right"><% mt('Date') |h %></TD>
28   <TD COLSPAN=2>
29     <INPUT TYPE="text" NAME="_date" ID="_date_text" VALUE="<% time2str($date_format.' %r',$_date) %>">
30     <IMG SRC="../images/calendar.png" ID="_date_button" STYLE="cursor: pointer" TITLE="<% mt('Select date') |h %>">
31   </TD>
32 </TR>
33
34 <SCRIPT TYPE="text/javascript">
35   Calendar.setup({
36     inputField: "_date_text",
37     ifFormat:   "<% $date_format %>",
38     button:     "_date_button",
39     align:      "BR"
40   });
41 </SCRIPT>
42
43 <TR>
44   <TD ALIGN="right"><% mt('Amount') |h %></TD>
45   <TD BGCOLOR="#ffffff" ALIGN="right"><% $money_char %></TD>
46   <TD><INPUT TYPE="text" NAME="paid" VALUE="<% $paid %>" SIZE=8 MAXLENGTH=9> <% mt('by') |h %> <B><% mt(FS::payby->payname($payby)) |h %></B></TD>
47 </TR>
48
49   <& /elements/tr-select-discount_term.html,
50                'custnum' => $custnum,
51                'cgi'     => $cgi
52   &>
53
54 % if ( $payby eq 'BILL' ) { 
55   <TR>
56     <TD ALIGN="right"><% mt('Check #') |h %></TD>
57     <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
58   </TR>
59 % } 
60
61 <TR>
62 % if ( $link eq 'custnum' || $link eq 'popup' ) { 
63
64   <TD ALIGN="right"><% mt('Auto-apply to invoices') |h %></TD>
65   <TD COLSPAN=2>
66     <SELECT NAME="apply">
67       <OPTION VALUE="yes" SELECTED><% mt('yes') |h %> 
68       <OPTION><% mt('no') |h %></SELECT>
69     </TD>
70
71 % } elsif ( $link eq 'invnum' ) { 
72
73   <TD ALIGN="right"><% mt('Apply to') |h %></TD>
74   <TD COLSPAN=2 BGCOLOR="#ffffff">Invoice #<B><% $linknum %></B> only</TD>
75   <INPUT TYPE="hidden" NAME="apply" VALUE="no">
76
77 % } 
78 </TR>
79
80 % if ( $conf->exists('pkg-balances') ) {
81   <& /elements/tr-select-cust_pkg-balances.html,
82                'custnum' => $custnum,
83                'cgi'     => $cgi
84   &>
85 % } else {
86   <INPUT TYPE="hidden" NAME="pkgnum" VALUE="">
87 % }
88
89 </TABLE>
90
91 <BR>
92 <INPUT TYPE="submit" VALUE="<% mt('Post payment') |h %>">
93
94 </FORM>
95
96 % if ( $link eq 'popup' ) { 
97     </BODY>
98     </HTML>
99 % } else { 
100     <& /elements/footer.html &>
101 % } 
102
103 <%init>
104
105 my $conf = new FS::Conf;
106
107 my $money_char  = $conf->config('money_char')  || '$';
108 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
109
110 my($link, $linknum, $paid, $payby, $payinfo, $_date);
111 if ( $cgi->param('error') ) {
112   $link     = $cgi->param('link');
113   $linknum  = $cgi->param('linknum');
114   $paid     = $cgi->param('paid');
115   $payby    = $cgi->param('payby');
116   $payinfo  = $cgi->param('payinfo');
117   $_date    = $cgi->param('_date') ? parse_datetime($cgi->param('_date')) : time;
118 } elsif ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
119   $link     = $cgi->param('popup') ? 'popup' : 'custnum';
120   $linknum  = $1;
121   $paid     = '';
122   $payby    = $cgi->param('payby') || 'BILL';
123   $payinfo  = '';
124   $_date    = time;
125 } elsif ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
126   $link     = 'invnum';
127   $linknum  = $1;
128   $paid     = '';
129   $payby    = $cgi->param('payby') || 'BILL';
130   $payinfo  = "";
131   $_date    = time;
132 } else {
133   die "illegal query ". $cgi->keywords;
134 }
135
136 my @rights = ('Post payment');
137 push @rights, 'Post check payment' if $payby eq 'BILL';
138 push @rights, 'Post cash payment'  if $payby eq 'CASH';
139
140 die "access denied"
141   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
142
143 my $paybatch = "webui-$_date-$$-". rand() * 2**32;
144
145 my $title = mt('Post '. FS::payby->payname($payby). ' payment');
146 $title .= mt(" against Invoice #[_1]",$linknum) if $link eq 'invnum';
147
148 my $custnum;
149 if ( $link eq 'invnum' ) {
150   my $cust_bill = qsearchs('cust_bill', { 'invnum' => $linknum } )
151     or die "unknown invnum $linknum";
152   $custnum = $cust_bill->custnum;
153 } elsif ( $link eq 'custnum' || $link eq 'popup' ) {
154   $custnum = $linknum;
155 }
156
157 </%init>