-#formatting
-print qq!<BR><BR><A NAME="history">Payment History!.
- qq!</A> ( !.
- qq!<A HREF="!. popurl(2). qq!edit/cust_pay.cgi?custnum=$custnum">!.
- qq!Post payment</A> | !.
- qq!<A HREF="!. popurl(2). qq!edit/cust_credit.cgi?$custnum">!.
- qq!Post credit</A> )!;
-
-#get payment history
-#
-# major problem: this whole thing is way too sloppy.
-# minor problem: the description lines need better formatting.
-
-my @history = (); #needed for mod_perl :)
-
-my %target = ();
-
-my @bills = qsearch('cust_bill',{'custnum'=>$custnum});
-foreach my $bill (@bills) {
- my($bref)=$bill->hashref;
- my $bpre = ( $bill->owed > 0 )
- ? '<b><font size="+1" color="#ff0000"> Open '
- : '';
- my $bpost = ( $bill->owed > 0 ) ? '</font></b>' : '';
- push @history,
- $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
- $bref->{invnum} . qq!">${bpre}Invoice #! . $bref->{invnum} .
- qq! (Balance \$! . $bill->owed . qq!)$bpost</A>\t! .
- $bref->{charged} . qq!\t\t\t!;
-
- my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } );
-# my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
-# my($payment);
-# foreach $payment (@payments) {
- foreach my $cust_bill_pay (@cust_bill_pay) {
- my $payment = $cust_bill_pay->cust_pay;
- my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date,
- $cust_bill_pay->invnum,
- $payment->payby,
- $payment->payinfo,
- $cust_bill_pay->amount,
- );
- $payinfo = substr($payinfo,0,4). 'x'x(length($payinfo)-4)
+if ( $conf->config('payby-default') ne 'HIDE' ) {
+
+ #formatting
+ print qq!<BR><BR><A NAME="history">Payment History!.
+ qq!</A> ( !.
+ qq!<A HREF="!. popurl(2). qq!edit/cust_pay.cgi?custnum=$custnum">!.
+ qq!Post payment</A> | !.
+ qq!<A HREF="!. popurl(2). qq!edit/cust_credit.cgi?$custnum">!.
+ qq!Post credit</A> )!;
+
+ #get payment history
+ #
+ # major problem: this whole thing is way too sloppy.
+ # minor problem: the description lines need better formatting.
+
+ my @history = (); #needed for mod_perl :)
+
+ my %target = ();
+
+ my @bills = qsearch('cust_bill',{'custnum'=>$custnum});
+ foreach my $bill (@bills) {
+ my($bref)=$bill->hashref;
+ my $bpre = ( $bill->owed > 0 )
+ ? '<b><font size="+1" color="#ff0000"> Open '
+ : '';
+ my $bpost = ( $bill->owed > 0 ) ? '</font></b>' : '';
+ push @history,
+ $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
+ $bref->{invnum} . qq!">${bpre}Invoice #! . $bref->{invnum} .
+ qq! (Balance \$! . $bill->owed . qq!)$bpost</A>\t! .
+ $bref->{charged} . qq!\t\t\t!;
+
+ my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } );
+ # my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
+ # my($payment);
+ foreach my $cust_bill_pay (@cust_bill_pay) {
+ my $payment = $cust_bill_pay->cust_pay;
+ my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date,
+ $cust_bill_pay->invnum,
+ $payment->payby,
+ $payment->payinfo,
+ $cust_bill_pay->amount,
+ );
+ $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
+ if $payby eq 'CARD';
+ my $target = "$payby$payinfo";
+ $payby =~ s/^BILL$/Check #/ if $payinfo;
+ $payby =~ s/^(CARD|COMP)$/$1 /;
+ my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
+ ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
+ : '';
+ push @history,
+ "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete\t\t$paid\t\t\t$target";
+ }
+
+ my(@cust_credit_bill)=
+ qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } );
+ foreach my $cust_credit_bill (@cust_credit_bill) {
+ my $cust_credit = $cust_credit_bill->cust_credit;
+ my($date, $invnum, $crednum, $amount, $reason, $app_date ) = (
+ $cust_credit->_date,
+ $cust_credit_bill->invnum,
+ $cust_credit_bill->crednum,
+ $cust_credit_bill->amount,
+ $cust_credit->reason,
+ time2str("%D", $cust_credit_bill->_date),
+ );
+ push @history,
+ "$date\tCredit #$crednum: $reason<BR>".
+ "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t";
+ }
+ }
+
+ my @credits = grep { scalar(my @array = $_->cust_credit_refund) }
+ qsearch('cust_credit',{'custnum'=>$custnum});
+ foreach my $credit (@credits) {
+ my($cref)=$credit->hashref;
+ my(@cust_credit_refund)=
+ qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } );
+ foreach my $cust_credit_refund (@cust_credit_refund) {
+ my $cust_refund = $cust_credit_refund->cust_credit;
+ my($date, $crednum, $amount, $reason, $app_date ) = (
+ $credit->_date,
+ $credit->crednum,
+ $cust_credit_refund->amount,
+ $credit->reason,
+ time2str("%D", $cust_credit_refund->_date),
+ );
+ push @history,
+ "$date\tCredit #$crednum: $reason<BR>".
+ "(applied to refund on $app_date)\t\t\t$amount\t";
+ }
+ }
+
+ @credits = grep { $_->credited > 0 }
+ qsearch('cust_credit',{'custnum'=>$custnum});
+ foreach my $credit (@credits) {
+ my($cref)=$credit->hashref;
+ push @history,
+ $cref->{_date} . "\t" .
+ qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!.
+ '<b><font size="+1" color="#ff0000">Unapplied credit #' .
+ $cref->{crednum} . "</font></b></A>: ".
+ $cref->{reason} . "\t\t\t" . $credit->credited . "\t";
+ }
+
+ my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } );
+ foreach my $refund (@refunds) {
+ my($rref)=$refund->hashref;
+ my($refundnum) = (
+ $refund->refundnum,
+ );
+
+ push @history,
+ $rref->{_date} . "\tRefund #$refundnum, (" .
+ $rref->{payby} . " " . $rref->{payinfo} . ") by " .
+ $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
+ $rref->{refund};
+ }
+
+ my @unapplied_payments =
+ grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } );
+ foreach my $payment (@unapplied_payments) {
+ my $payby = $payment->payby;
+ my $payinfo = $payment->payinfo;
+ #false laziness w/above
+ $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))