>
- <%=$pkg->{pkgnum}%>:
+ <%=$pkg->{pkgnum}%>:
<%=$pkg->{pkg}%> - <%=$pkg->{comment}%>
<% unless ($pkg->{cancel}) { %>
( <%=pkg_change_link($pkg)%> )
@@ -547,34 +529,14 @@ print '';
#end display packages
%>
-
-
<% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
-
Payment History
- (Post payment
- | Post credit)
+
Payment History
+ Post cash/check payment
+ | Process credit card payment
+ | Process electronic check (ACH) payment
+ Post credit
+
<%
#get payment history
@@ -600,11 +562,12 @@ function cust_credit_areyousure(href) {
foreach my $cust_pay ($cust_main->cust_pay) {
my $payby = $cust_pay->payby;
- my $payinfo = $cust_pay->payinfo;
+ my $payinfo = $payby eq 'CARD'
+ ? $cust_pay->payinfo_masked
+ : $cust_pay->payinfo;
my @cust_bill_pay = $cust_pay->cust_bill_pay;
+ my @cust_pay_refund = $cust_pay->cust_pay_refund;
- $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/^BILL$//;
@@ -612,25 +575,42 @@ function cust_credit_areyousure(href) {
my $info = $payby ? " ($payby$payinfo)" : '';
my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
- if ( scalar(@cust_bill_pay) == 0 ) {
+ if ( scalar(@cust_bill_pay) == 0
+ && scalar(@cust_pay_refund) == 0 ) {
#completely unapplied
$pre = 'Unapplied ';
$post = '';
$apply = qq! (apply)';
- } elsif ( scalar(@cust_bill_pay) == 1 && $cust_pay->unapplied == 0 ) {
- #applied to one invoice
+ } elsif ( scalar(@cust_bill_pay) == 1
+ && scalar(@cust_pay_refund) == 0
+ && $cust_pay->unapplied == 0 ) {
+ #applied to one invoice, the usual situation
$desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
+ } elsif ( scalar(@cust_bill_pay) == 0
+ && scalar(@cust_pay_refund) == 1
+ && $cust_pay->unapplied == 0 ) {
+ #applied to one refund
+ $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
} else {
#complicated
$desc = ' ';
- foreach my $cust_bill_pay (@cust_bill_pay) {
- $desc .= ' '.
- '$'. $cust_bill_pay->amount.
- ' applied to Invoice #'. $cust_bill_pay->invnum.
- ' ';
- #' on '. time2str("%D", $cust_bill_pay->_date).
-
+ foreach my $app ( sort { $a->_date <=> $b->_date }
+ ( @cust_bill_pay, @cust_pay_refund ) ) {
+ if ( $app->isa('FS::cust_bill_pay') ) {
+ $desc .= ' '.
+ '$'. $app->amount.
+ ' applied to Invoice #'. $app->invnum.
+ ' ';
+ #' on '. time2str("%D", $cust_bill_pay->_date).
+ } elsif ( $app->isa('FS::cust_pay_refund') ) {
+ $desc .= ' '.
+ '$'. $app->amount.
+ ' refunded on'. time2str("%D", $app->_date).
+ ' ';
+ } else {
+ die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
+ }
}
if ( $cust_pay->unapplied > 0 ) {
$desc .= ' '.
@@ -642,31 +622,77 @@ function cust_credit_areyousure(href) {
}
}
+ my $refund = '';
+ my $refund_days = $conf->config('card_refund-days') || 120;
+ if ( $cust_pay->closed !~ /^Y/i
+ && $cust_pay->payby eq 'CARD'
+ && time-$cust_pay->_date < $refund_days*86400
+ && $cust_pay->unrefunded > 0
+ ) {
+ $refund = qq! (refund)!;
+ }
+
+ my $void = '';
+ if ( $cust_pay->closed !~ /^Y/i
+ && $cust_pay->payby ne 'CARD'
+ ) {
+ $void = qq! (!.
+ qq!void)!;
+ }
+
my $delete = '';
if ( $cust_pay->closed !~ /^Y/i && $conf->exists('deletepayments') ) {
- $delete = qq! (paynum.
- qq!')">delete)!;
+ qq!', 'Are you sure you want to delete this payment?')">!.
+ qq!delete)!;
}
my $unapply = '';
if ( $cust_pay->closed !~ /^Y/i
&& $conf->exists('unapplypayments')
&& scalar(@cust_bill_pay) ) {
- $unapply = qq! (paynum.
- qq!')">unapply)!;
+ qq!', 'Are you sure you want to unapply this payment?')">!.
+ qq!unapply)!;
}
push @history, {
'date' => $cust_pay->_date,
'desc' => $pre. "Payment$post$info$desc".
- "$apply$delete$unapply",
+ "$apply$refund$void$delete$unapply",
'payment' => $cust_pay->paid,
'target' => $target,
};
}
+ #voided payments
+ foreach my $cust_pay_void ($cust_main->cust_pay_void) {
+
+ my $payby = $cust_pay_void->payby;
+ my $payinfo = $payby eq 'CARD'
+ ? $cust_pay_void->payinfo_masked
+ : $cust_pay_void->payinfo;
+
+ $payby =~ s/^BILL$/Check #/ if $payinfo;
+ $payby =~ s/^BILL$//;
+ $payby =~ s/^(CARD|COMP)$/$1 /;
+ my $info = $payby ? " ($payby$payinfo)" : '';
+
+ push @history, {
+ 'date' => $cust_pay_void->_date,
+ 'desc' => "Payment $info voided ".
+ time2str("%D", $cust_pay_void->void_date).
+ " by ". $cust_pay_void->otaker. '',
+ 'void_payment' => $cust_pay_void->paid,
+ };
+
+ }
+
#credits (some false laziness w/payments)
foreach my $cust_credit ($cust_main->cust_credit) {
@@ -684,7 +710,7 @@ function cust_credit_areyousure(href) {
} elsif ( scalar(@cust_credit_bill) == 1
&& scalar(@cust_credit_refund) == 0
&& $cust_credit->credited == 0 ) {
- #applied to one invoice
+ #applied to one invoice, the usual situation
$desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
} elsif ( scalar(@cust_credit_bill) == 0
&& scalar(@cust_credit_refund) == 1
@@ -712,28 +738,30 @@ function cust_credit_areyousure(href) {
}
}
if ( $cust_credit->credited > 0 ) {
- $desc .= ' - $'.
- $cust_credit->unapplied. ' unapplied'.
+ $desc .= ' $'.
+ $cust_credit->credited. ' unapplied'.
qq! (apply'.
+ $cust_credit->crednum. '">apply)'.
' ';
}
}
#
my $delete = '';
if ( $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits') ) {
- $delete = qq! (crednum.
- qq!')">delete)!;
+ qq!', 'Are you sure you want to delete this credit?')">!.
+ qq!delete)!;
}
my $unapply = '';
if ( $cust_credit->closed !~ /^Y/i
&& $conf->exists('unapplycredits')
&& scalar(@cust_credit_bill) ) {
- $unapply = qq! (crednum.
- qq!')">unapply)!;
+ qq!', 'Are you sure you want to unapply this credit?')">!.
+ qq!unapply)!;
}
push @history, {
@@ -750,10 +778,10 @@ function cust_credit_areyousure(href) {
foreach my $cust_refund ($cust_main->cust_refund) {
my $payby = $cust_refund->payby;
- my $payinfo = $cust_refund->payinfo;
+ my $payinfo = $payby eq 'CARD'
+ ? $cust_refund->payinfo_masked
+ : $cust_refund->payinfo;
- $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
- if $payby eq 'CARD';
$payby =~ s/^BILL$/Check #/ if $payinfo;
$payby =~ s/^(CARD|COMP)$/$1 /;
@@ -791,6 +819,8 @@ function cust_credit_areyousure(href) {
my $payment = exists($item->{'payment'})
? sprintf('- $%.2f', $item->{'payment'})
: '';
+ $payment ||= sprintf('- $%.2f', $item->{'void_payment'})
+ if exists($item->{'void_payment'});
my $credit = exists($item->{'credit'})
? sprintf('- $%.2f', $item->{'credit'})
: '';
@@ -806,6 +836,7 @@ function cust_credit_areyousure(href) {
$balance += $item->{'refund'} if exists $item->{'refund'};
$balance = sprintf("%.2f", $balance);
$balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
+ ( my $showbalance = '$'. $balance ) =~ s/^\$\-/- \$/;
%>
@@ -821,11 +852,11 @@ function cust_credit_areyousure(href) {
|
<%= $item->{'desc'} %> |
- <%= $charge %> |
- <%= $payment %> |
- <%= $credit %> |
- <%= $refund %> |
- $<%= $balance %> |
+ <%= $charge %> |
+ <%= $payment %> |
+ <%= $credit %> |
+ <%= $refund %> |
+ <%= $showbalance %> |
<% } %>
@@ -889,15 +920,8 @@ sub get_packages {
}
- foreach my $cust_svc (
- qsearch( 'cust_svc', {
- 'pkgnum' => $cust_pkg->pkgnum,
- #'svcpart' => $part_svc->svcpart,
- }
- )
- ) {
-
- warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
+ foreach my $cust_svc ( $cust_pkg->cust_svc ) {
+ #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
my $svc = {
'svcnum' => $cust_svc->svcnum,
'label' => ($cust_svc->label)[1],
@@ -964,7 +988,8 @@ sub svc_provision_link {
sub svc_unprovision_link {
my $svc = shift or return '';
- return qq!