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