-<!-- mason kludge -->
-<%
+<& /elements/header-popup.html, mt('Enter Credit') &>
+
+<& /elements/error.html &>
+
+<FORM NAME="credit_popup" ACTION="<% $p1 %>process/cust_credit.cgi" METHOD=POST>
+<INPUT TYPE="hidden" NAME="crednum" VALUE="">
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum |h %>">
+<INPUT TYPE="hidden" NAME="paybatch" VALUE="">
+<INPUT TYPE="hidden" NAME="credited" VALUE="">
+<INPUT TYPE="hidden" NAME="otaker" VALUE="<% $otaker %>">
+
+<% ntable("#cccccc", 2) %>
+
+% my %date_args = (
+% 'name' => '_date',
+% 'label' => emt('Date'),
+% 'value' => $_date,
+% 'format' => $date_format. ' %r',
+% );
+% if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) {
+
+ <& /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="amount" VALUE="<% $amount |h %>" SIZE=8 MAXLENGTH=9></TD>
+ </TR>
+
+<& /elements/tr-select-reason.html,
+ 'field' => 'reasonnum',
+ 'reason_class' => 'R',
+ 'control_button' => 'confirm_credit_button',
+ 'cgi' => $cgi,
+&>
+
+ <TR>
+ <TD ALIGN="right"><% mt('Additional info') |h %></TD>
+ <TD>
+ <INPUT TYPE="text" NAME="addlinfo" VALUE="<% $cgi->param('addlinfo') |h %>">
+ </TD>
+ </TR>
+
+% if ( $conf->exists('credits-auto-apply-disable') ) {
+ <INPUT TYPE="HIDDEN" NAME="apply" VALUE="no">
+% } else {
+ <TR>
+ <TD ALIGN="right"><% mt('Auto-apply to invoices') |h %></TD>
+ <TD><SELECT NAME="apply"><OPTION VALUE="yes" SELECTED><% mt('yes') |h %><OPTION><% mt('no') |h %></SELECT></TD>
+ </TR>
+% }
+
+% if ( $conf->exists('pkg-balances') ) {
+ <& /elements/tr-select-cust_pkg-balances.html,
+ 'custnum' => $custnum,
+ 'cgi' => $cgi
+ &>
+% } else {
+ <INPUT TYPE="hidden" NAME="pkgnum" VALUE="">
+% }
-my $conf = new FS::Conf;
-my($custnum, $amount, $reason);
-if ( $cgi->param('error') ) {
- #$cust_credit = new FS::cust_credit ( {
- # map { $_, scalar($cgi->param($_)) } fields('cust_credit')
- #} );
- $custnum = $cgi->param('custnum');
- $amount = $cgi->param('amount');
- #$refund = $cgi->param('refund');
- $reason = $cgi->param('reason');
-} else {
- my($query) = $cgi->keywords;
- $query =~ /^(\d+)$/;
- $custnum = $1;
- $amount = '';
- #$refund = 'yes';
- $reason = '';
-}
-my $_date = time;
-
-my $otaker = getotaker;
-
-my $p1 = popurl(1);
-
-print header("Post Credit", '');
-print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
- "</FONT>"
- if $cgi->param('error');
-print <<END, small_custview($custnum, $conf->config('countrydefault'));
- <FORM ACTION="${p1}process/cust_credit.cgi" METHOD=POST>
- <INPUT TYPE="hidden" NAME="crednum" VALUE="">
- <INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">
- <INPUT TYPE="hidden" NAME="paybatch" VALUE="">
- <INPUT TYPE="hidden" NAME="_date" VALUE="$_date">
- <INPUT TYPE="hidden" NAME="credited" VALUE="">
- <INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">
-END
-
-print '<BR><BR>Credit'. ntable("#cccccc", 2).
- '<TR><TD ALIGN="right">Date</TD><TD BGCOLOR="#ffffff">'.
- time2str("%D",$_date). '</TD></TR>';
-
-print qq!<TR><TD ALIGN="right">Amount</TD><TD BGCOLOR="#ffffff">\$<INPUT TYPE="text" NAME="amount" VALUE="$amount" SIZE=8 MAXLENGTH=8></TD></TR>!;
-
-#print qq! <INPUT TYPE="checkbox" NAME="refund" VALUE="$refund">Also post refund!;
-
-print qq!<TR><TD ALIGN="right">Reason</TD><TD BGCOLOR="#ffffff"><INPUT TYPE="text" NAME="reason" VALUE="$reason"></TD></TR>!;
-
-print qq!<TR><TD ALIGN="right">Auto-apply<BR>to invoices</TD><TD><SELECT NAME="apply"><OPTION VALUE="yes" SELECTED>yes<OPTION>no</SELECT></TD>!;
-
-print <<END;
</TABLE>
+
<BR>
-<INPUT TYPE="submit" VALUE="Post credit">
- </FORM>
- </BODY>
+
+<CENTER><INPUT TYPE="submit" ID="confirm_credit_button" VALUE="<% mt('Enter credit') |h %>" DISABLED></CENTER>
+
+</FORM>
+</BODY>
</HTML>
-END
+<%init>
+
+my $conf = new FS::Conf;
+
+my $money_char = $conf->config('money_char') || '$';
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Post credit');
+
+my $custnum = $cgi->param('custnum');
+my $amount = $cgi->param('amount');
+my $_date = time;
+my $otaker = getotaker;
+my $p1 = popurl(1);
-%>
+</%init>