payment posting styled inside customer
[freeside.git] / httemplate / edit / cust_pay.cgi
index 7f70802..acc67c4 100755 (executable)
-<%
-#<!-- $Id: cust_pay.cgi,v 1.8 2001-12-26 04:25:04 ivan Exp $ -->
-
-use strict;
-use vars qw( $cgi $link $linknum $p1 $_date $payby $payinfo $paid );
-use Date::Format;
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::Conf;
-use FS::UID qw(cgisuidsetup);
-use FS::CGI qw(header popurl ntable small_custview);
+% if ( $link eq 'popup' ) { 
+  <& /elements/header-popup.html, $title  &>
+% } else { 
+  <& /elements/header-cust_main.html, view=>'payment_history', custnum=>$custnum &>
+  <h2><% $title |h %></h2>
+% } 
+
+<& /elements/init_calendar.html &>
+
+<& /elements/error.html &>
+
+<FORM NAME="PaymentForm" ACTION="<% popurl(1) %>process/cust_pay.cgi" METHOD=POST onSubmit="document.PaymentForm.submitButton.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 %>">
+
+<% 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> 
+      <OPTION VALUE=""><% mt('not now') |h %></OPTION>
+      <OPTION VALUE="never"><% mt('never') |h %></OPTION>
+    </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="">
+
+% } 
+</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>
+
+<BR>
+<INPUT NAME="submitButton" TYPE="submit" VALUE="<% mt('Post payment') |h %>">
+
+</FORM>
+
+% if ( $link eq 'popup' ) { 
+    </BODY>
+    </HTML>
+% } else { 
+    <& /elements/footer-cust_main.html &>
+% } 
+
+<%init>
 
 my $conf = new FS::Conf;
 
-$cgi = new CGI;
-cgisuidsetup($cgi);
+my $money_char  = $conf->config('money_char')  || '$';
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
 
+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');
-} elsif ($cgi->keywords) {
-  my($query) = $cgi->keywords;
-  $query =~ /^(\d+)$/;
-  $link = 'invnum';
-  $linknum = $1;
-  $paid = '';
-  $payby = 'BILL';
-  $payinfo = "";
-} elsif ( $cgi->param('custnum')  =~ /^(\d+)$/ ) {
-  $link = 'custnum';
-  $linknum = $1;
-  $paid = '';
-  $payby = 'BILL';
-  $payinfo = '';
+  $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;
 }
-$_date = time;
 
-$p1 = popurl(1);
-print header("Post payment", '');
+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);
 
-print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
-      "</FONT><BR><BR>"
-  if $cgi->param('error');
+my $paybatch = "webui-$_date-$$-". rand() * 2**32;
 
-print <<END, ntable("#cccccc",2);
-    <FORM ACTION="${p1}process/cust_pay.cgi" METHOD=POST>
-    <INPUT TYPE="hidden" NAME="link" VALUE="$link">
-    <INPUT TYPE="hidden" NAME="linknum" VALUE="$linknum">
-END
+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";
-  print "Invoice #<B>$linknum</B>". ntable("#cccccc",2).
-        '<TR><TD ALIGN="right">Date</TD><TD BGCOLOR="#ffffff">'.
-        time2str("%D", $cust_bill->_date). '</TD></TR>'.
-        '<TR><TD ALIGN="right" VALIGN="top">Items</TD><TD BGCOLOR="#ffffff">';
-  foreach ( $cust_bill->cust_bill_pkg ) { #false laziness with FS::cust_bill
-    if ( $_->pkgnum ) {
-
-      my($cust_pkg)=qsearchs('cust_pkg', { 'pkgnum', $_->pkgnum } );
-      my($part_pkg)=qsearchs('part_pkg',{'pkgpart'=>$cust_pkg->pkgpart});
-      my($pkg)=$part_pkg->pkg;
-
-      if ( $_->setup != 0 ) {
-        print "$pkg Setup<BR>"; # $money_char. sprintf("%10.2f",$_->setup);
-        print join('<BR>',
-          map { "  ". $_->[0]. ": ". $_->[1] } $cust_pkg->labels
-        ). '<BR>';
-      }
-
-      if ( $_->recur != 0 ) {
-        print
-          "$pkg (" . time2str("%x",$_->sdate) . " - " .
-                                time2str("%x",$_->edate) . ")<BR>";
-          #$money_char. sprintf("%10.2f",$_->recur)
-        print join('<BR>',
-          map { '--->'. $_->[0]. ": ". $_->[1] } $cust_pkg->labels
-        ). '<BR>';
-      }
-
-    } else { #pkgnum Tax
-      print "Tax<BR>" # $money_char. sprintf("%10.2f",$_->setup)
-        if $_->setup != 0;
-    }
-
-  }
-  print '</TD></TR></TABLE>';
-
   $custnum = $cust_bill->custnum;
-
-} elsif ( $link eq 'custnum' ) {
+} elsif ( $link eq 'custnum' || $link eq 'popup' ) {
   $custnum = $linknum;
 }
 
-print small_custview($custnum, $conf->config('countrydefault'));
-
-print qq!<INPUT TYPE="hidden" NAME="_date" VALUE="$_date">!;
-print qq!<INPUT TYPE="hidden" NAME="payby" VALUE="$payby">!;
-
-print '<BR><BR>Payment'. 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="paid" VALUE="$paid" SIZE=8 MAXLENGTH=8></TD></TR>!;
-
-print qq!<TR><TD ALIGN="right">Payby</TD><TD BGCOLOR="#ffffff">$payby</TD></TR>!;
-
-#payinfo (check # now as payby="BILL" hardcoded.. what to do later?)
-print qq!<TR><TD ALIGN="right">Check #</TD><TD BGCOLOR="#ffffff"><INPUT TYPE="text" NAME="payinfo" VALUE="$payinfo"></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>!;
-
-#paybatch
-print qq!<INPUT TYPE="hidden" NAME="paybatch" VALUE="">!;
-
-print <<END;
-</TABLE>
-<BR>
-<INPUT TYPE="submit" VALUE="Post payment">
-    </FORM>
-  </BODY>
-</HTML>
-END
-
-%>
+</%init>