a6b73b13adfbd61f01ee51c105940b6aac810c4a
[freeside.git] / httemplate / edit / cust_pay.cgi
1 % if ( $link eq 'popup' ) { 
2   <% include('/elements/header-popup.html', $title ) %>
3 % } else { 
4   <%  include("/elements/header.html", $title, '') %>
5 % } 
6
7 <% include('/elements/init_calendar.html') %>
8
9 <% include('/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 Payment
24 <% ntable("#cccccc", 2) %>
25
26 <TR>
27   <TD ALIGN="right">Date</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="Select date">
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">Amount</TD>
45   <TD BGCOLOR="#ffffff" ALIGN="right"><% $money_char %></TD>
46   <TD><INPUT TYPE="text" NAME="paid" VALUE="<% $paid %>" SIZE=8 MAXLENGTH=8> by <B><% FS::payby->payname($payby) %></B></TD>
47 </TR>
48
49 % if ( $payby eq 'BILL' ) { 
50   <TR>
51     <TD ALIGN="right">Check #</TD>
52     <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
53   </TR>
54 % } 
55
56 <TR>
57 % if ( $link eq 'custnum' || $link eq 'popup' ) { 
58
59   <TD ALIGN="right">Auto-apply<BR>to invoices</TD>
60   <TD COLSPAN=2>
61     <SELECT NAME="apply">
62       <OPTION VALUE="yes" SELECTED>yes
63       <OPTION>no</SELECT>
64     </TD>
65
66 % } elsif ( $link eq 'invnum' ) { 
67
68   <TD ALIGN="right">Apply to</TD>
69   <TD COLSPAN=2 BGCOLOR="#ffffff">Invoice #<B><% $linknum %></B> only</TD>
70   <INPUT TYPE="hidden" NAME="apply" VALUE="no">
71
72 % } 
73 </TR>
74
75 % if ( $conf->exists('pkg-balances') ) {
76   <% include('/elements/tr-select-cust_pkg-balances.html',
77                'custnum' => $custnum,
78                'cgi'     => $cgi
79             )
80   %>
81 % } else {
82   <INPUT TYPE="hidden" NAME="pkgnum" VALUE="">
83 % }
84
85 </TABLE>
86
87 <BR>
88 <INPUT TYPE="submit" VALUE="Post payment">
89
90 </FORM>
91
92 % if ( $link eq 'popup' ) { 
93     </BODY>
94     </HTML>
95 % } else { 
96     <% include('/elements/footer.html') %>
97 % } 
98
99 <%init>
100
101 my $conf = new FS::Conf;
102
103 my $money_char  = $conf->config('money_char')  || '$';
104 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
105
106 die "access denied"
107   unless $FS::CurrentUser::CurrentUser->access_right('Post payment');
108
109 my($link, $linknum, $paid, $payby, $payinfo, $_date);
110 if ( $cgi->param('error') ) {
111   $link     = $cgi->param('link');
112   $linknum  = $cgi->param('linknum');
113   $paid     = $cgi->param('paid');
114   $payby    = $cgi->param('payby');
115   $payinfo  = $cgi->param('payinfo');
116   $_date    = $cgi->param('_date') ? str2time($cgi->param('_date')) : time;
117 } elsif ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
118   $link     = $cgi->param('popup') ? 'popup' : 'custnum';
119   $linknum  = $1;
120   $paid     = '';
121   $payby    = $cgi->param('payby') || 'BILL';
122   $payinfo  = '';
123   $_date    = time;
124 } elsif ( $cgi->param('invnum') =~ /^(\d+)$/ ) {
125   $link     = 'invnum';
126   $linknum  = $1;
127   $paid     = '';
128   $payby    = $cgi->param('payby') || 'BILL';
129   $payinfo  = "";
130   $_date    = time;
131 } else {
132   die "illegal query ". $cgi->keywords;
133 }
134
135 my $paybatch = "webui-$_date-$$-". rand() * 2**32;
136
137 my $title = 'Post '. FS::payby->payname($payby). ' payment';
138 $title .= " against Invoice #$linknum" if $link eq 'invnum';
139
140 my $custnum;
141 if ( $link eq 'invnum' ) {
142   my $cust_bill = qsearchs('cust_bill', { 'invnum' => $linknum } )
143     or die "unknown invnum $linknum";
144   $custnum = $cust_bill->custnum;
145 } elsif ( $link eq 'custnum' || $link eq 'popup' ) {
146   $custnum = $linknum;
147 }
148
149 </%init>