X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fview%2Fcust_main.cgi;h=22c4191021cf4fc67a89775942146ced12ec57fa;hb=165868b01df15958f51498f4a67117d92176680b;hp=cf899d0410684c5e58b109900867d5b6e918dd59;hpb=d01dbb663c0d58ed4294c9284106a0e46f274301;p=freeside.git
diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi
index cf899d041..22c419102 100755
--- a/httemplate/view/cust_main.cgi
+++ b/httemplate/view/cust_main.cgi
@@ -36,15 +36,15 @@ print qq!Edit this customer!;
%>
<%
-print qq! | !.
+print qq! | !.
'Cancel this customer'
if $cust_main->ncancelled_pkgs;
@@ -300,13 +300,25 @@ if ( defined $cust_main->dbdef_table->column('comments')
'';
}
-print '';
+%>
+
+
-print '
'.
- '
';
+<%
if ( $conf->config('payby-default') ne 'HIDE' ) {
@@ -349,21 +363,6 @@ if ( $conf->config('payby-default') ne 'HIDE' ) {
}
-%>
-
-
-
-<%
-
print qq!Packages !,
qq!( Order and cancel packages (preserves services) )!,
;
@@ -544,29 +543,6 @@ print '';
#end display packages
%>
-
-
<% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
Payment History
@@ -604,33 +580,52 @@ function cust_credit_areyousure(href) {
? $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;
my $target = "$payby$payinfo";
$payby =~ s/^BILL$/Check #/ if $payinfo;
+ $payby =~ s/^CHEK$/Electronic check /;
$payby =~ s/^BILL$//;
$payby =~ s/^(CARD|COMP)$/$1 /;
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 +637,78 @@ 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 =~ /^(CARD|CHEK)$/
+ && 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 !~ /^(CARD|CHEK)$/
+ ) {
+ $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/^CHEK$/Electronic check /;
+ $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 +726,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
@@ -722,18 +764,20 @@ function cust_credit_areyousure(href) {
#
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, {
@@ -755,6 +799,7 @@ function cust_credit_areyousure(href) {
: $cust_refund->payinfo;
$payby =~ s/^BILL$/Check #/ if $payinfo;
+ $payby =~ s/^CHEK$/Electronic check /;
$payby =~ s/^(CARD|COMP)$/$1 /;
push @history, {
@@ -791,6 +836,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'})
: '';
@@ -867,28 +914,14 @@ sub get_packages {
$pkg{expire} = $cust_pkg->getfield('expire');
$pkg{cancel} = $cust_pkg->getfield('cancel');
- my %svcparts = ();
-
- foreach my $pkg_svc (
- qsearch('pkg_svc', { 'pkgpart' => $part_pkg->pkgpart })
- ) {
-
- next if ($pkg_svc->quantity == 0);
-
- my $part_svc = qsearchs('part_svc', { 'svcpart' => $pkg_svc->svcpart });
-
- my $svcpart = {};
- $svcpart->{svcpart} = $part_svc->svcpart;
- $svcpart->{svc} = $part_svc->svc;
- $svcpart->{svcdb} = $part_svc->svcdb;
- $svcpart->{quantity} = $pkg_svc->quantity;
- $svcpart->{count} = 0;
-
- $svcpart->{services} = [];
-
- $svcparts{$svcpart->{svcpart}} = $svcpart;
-
- }
+ my %svcparts = map {
+ $_->svcpart => {
+ $_->part_svc->hash,
+ 'quantity' => $_->quantity,
+ 'count' => $cust_pkg->num_cust_svc($_->svcpart),
+ #'services' => [],
+ };
+ } $part_pkg->pkg_svc;
foreach my $cust_svc ( $cust_pkg->cust_svc ) {
#warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
@@ -900,18 +933,14 @@ sub get_packages {
#false laziness with above, to catch extraneous services. whole
#damn thing should be OO...
my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
- 'svcpart' => $cust_svc->svcpart,
- 'svc' => $cust_svc->part_svc->svc,
- 'svcdb' => $cust_svc->part_svc->svcdb,
+ $cust_svc->part_svc->hash,
'quantity' => 0,
- 'count' => 0,
- 'services' => [],
+ 'count' => $cust_pkg->num_cust_svc($cust_svc->svcpart),
+ #'services' => [],
} );
push @{$svcpart->{services}}, $svc;
- $svcpart->{count}++;
-
}
$pkg{svcparts} = [ values %svcparts ];
@@ -958,7 +987,8 @@ sub svc_provision_link {
sub svc_unprovision_link {
my $svc = shift or return '';
- return qq!Unprovision!;
+ qq!Unprovision!;
}
# This should be generalized to use config options to determine order.
@@ -986,7 +1016,8 @@ sub pkg_datestr {
sub pkg_change_link {
my $pkg = shift or return '';
- return qq!Change package!;
+ return qq!!.
+ qq!Change package!;
}
sub pkg_suspend_link {
@@ -1001,19 +1032,22 @@ sub pkg_unsuspend_link {
sub pkg_cancel_link {
my $pkg = shift or return '';
- qq!Cancel now | !.
+ qq!!.
+ qq!Cancel now | !.
qq!Cancel later!;
}
sub pkg_dates_link {
my $pkg = shift or return '';
- return qq!Edit dates!;
+ qq!Edit dates!;
}
sub pkg_customize_link {
my $pkg = shift or return '';
my $custnum = shift;
- return qq!Customize!;
+ qq!Customize!;
}
%>