-<%
-#
-# $Id: cust_pay.cgi,v 1.1 2001-07-30 07:36:04 ivan Exp $
-#
-# Usage: cust_pay.cgi invnum
-# http://server.name/path/cust_pay.cgi?invnum
-#
-# some hooks for modifications as well as additions, but needs work.
-#
-# ivan@voicenet.com 96-dec-11
-#
-# rewrite ivan@sisd.com 98-mar-16
-#
-# $Log: cust_pay.cgi,v $
-# Revision 1.1 2001-07-30 07:36:04 ivan
-# templates!!!
-#
-# Revision 1.6 1999/02/28 00:03:35 ivan
-# removed misleading comments
-#
-# Revision 1.5 1999/01/25 12:09:56 ivan
-# yet more mod_perl stuff
-#
-# Revision 1.4 1999/01/19 05:13:37 ivan
-# for mod_perl: no more top-level my() variables; use vars instead
-# also the last s/create/new/;
-#
-# Revision 1.3 1999/01/18 09:41:27 ivan
-# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
-# (good idea anyway)
-#
-# Revision 1.2 1998/12/17 06:17:03 ivan
-# fix double // in relative URLs, s/CGI::Base/CGI/;
-#
-
-use strict;
-use vars qw( $cgi $invnum $p1 $_date $payby $payinfo $paid );
-use Date::Format;
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::UID qw(cgisuidsetup);
-use FS::CGI qw(header popurl);
-
-$cgi = new CGI;
-cgisuidsetup($cgi);
+% if ( $link eq 'popup' ) {
+ <& /elements/header-popup.html, $title &>
+% } else {
+ <& /elements/header.html, $title, '' &>
+% }
-if ( $cgi->param('error') ) {
- $invnum = $cgi->param('invnum');
- $paid = $cgi->param('paid');
- $payby = $cgi->param('payby');
- $payinfo = $cgi->param('payinfo');
-} else {
- my ($query) = $cgi->keywords;
- $query =~ /^(\d+)$/;
- $invnum = $1;
- $paid = '';
- $payby = "BILL";
- $payinfo = "";
-}
-$_date = time;
+<& /elements/init_calendar.html &>
-$p1 = popurl(1);
-print $cgi->header( '-expires' => 'now' ), header("Enter payment", '');
+<& /elements/error.html &>
-print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
- "</FONT>"
- if $cgi->param('error');
+% unless ( $link eq 'popup' ) {
+ <% small_custview($custnum, $conf->config('countrydefault')) %>
+% }
-print <<END;
- <FORM ACTION="${p1}process/cust_pay.cgi" METHOD=POST>
- <HR><PRE>
-END
+<FORM NAME="PaymentForm" ACTION="<% popurl(1) %>process/cust_pay.cgi" METHOD=POST onSubmit="document.PaymentForm.submit.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 %>">
-print qq!Invoice #<B>$invnum</B><INPUT TYPE="hidden" NAME="invnum" VALUE="$invnum">!;
+<BR>
-print qq!<BR>Date: <B>!, time2str("%D",$_date), qq!</B><INPUT TYPE="hidden" NAME="_date" VALUE="$_date">!;
+<% mt('Payment') |h %>
+<% ntable("#cccccc", 2) %>
+
+% 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>
+ <TD ALIGN="right"><% mt('Amount') |h %></TD>
+ <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>
+</TR>
+
+% if ( $conf->exists('part_pkg-term_discounts') ) {
+ <& /elements/tr-select-discount_term.html,
+ 'custnum' => $custnum,
+ 'amount_id' => 'paid',
+ &>
+% }
+
+% if ( $payby eq 'BILL' ) {
+ <TR>
+ <TD ALIGN="right"><% mt('Check #') |h %></TD>
+ <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>
+ <TD ALIGN="right"><% mt('Bank') |h %></TD>
+ <TD COLSPAN=3><INPUT TYPE="text" NAME="bank" VALUE="<% $cgi->param('bank') %>"></TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right"><% mt('Check #') |h %></TD>
+ <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right"><% mt('Teller #') |h %></TD>
+ <TD COLSPAN=2><INPUT TYPE="text" NAME="teller" VALUE="<% $cgi->param('teller') %>" SIZE=10></TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right"><% mt('Depositor') |h %></TD>
+ <TD COLSPAN=3><INPUT TYPE="text" NAME="depositor" VALUE="<% $cgi->param('depositor') %>"></TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right"><% mt('Account #') |h %></TD>
+ <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><% mt('no') |h %></SELECT>
+ </TD>
+
+% } elsif ( $link eq 'invnum' ) {
+
+ <TD ALIGN="right"><% mt('Apply to') |h %></TD>
+ <TD COLSPAN=2 BGCOLOR="#ffffff">Invoice #<B><% $linknum %></B> only</TD>
+ <INPUT TYPE="hidden" NAME="apply" VALUE="no">
+
+% }
+</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>
-print qq!<BR>Amount \$<INPUT TYPE="text" NAME="paid" VALUE="$paid" SIZE=8 MAXLENGTH=8>!;
+<BR>
+<INPUT TYPE="submit" VALUE="<% mt('Post payment') |h %>">
-print qq!<BR>Payby: <B>$payby</B><INPUT TYPE="hidden" NAME="payby" VALUE="$payby">!;
+</FORM>
-#payinfo (check # now as payby="BILL" hardcoded.. what to do later?)
-print qq!<BR>Check #<INPUT TYPE="text" NAME="payinfo" VALUE="$payinfo">!;
+% if ( $link eq 'popup' ) {
+ </BODY>
+ </HTML>
+% } else {
+ <& /elements/footer.html &>
+% }
-#paybatch
-print qq!<INPUT TYPE="hidden" NAME="paybatch" VALUE="">!;
+<%init>
-print <<END;
-</PRE>
-<BR>
-<INPUT TYPE="submit" VALUE="Post payment">
-END
+my $conf = new FS::Conf;
-print <<END;
+my $money_char = $conf->config('money_char') || '$';
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
- </FORM>
- </BODY>
-</HTML>
-END
+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>