%>
<SCRIPT>
-function cancel_areyousure(href) {
- if (confirm("Perminantly delete all services and cancel this customer?") == true)
+function areyousure(href, message) {
+ if (confirm(message) == true)
window.location.href = href;
}
</SCRIPT>
<%
-print qq! | <A HREF="javascript:cancel_areyousure('${p}misc/cust_main-cancel.cgi?$custnum')">!.
+print qq! | <A HREF="javascript:areyousure('${p}misc/cust_main-cancel.cgi?$custnum', 'Perminantly delete all services and cancel this customer?')">!.
'Cancel this customer</A>'
if $cust_main->ncancelled_pkgs;
;
if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
- my $payinfo = $cust_main->payinfo;
- $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
+ my $payinfo = $cust_main->payinfo_masked;
print 'Credit card ',
( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
'</TD></TR>',
'</PRE></TD></TR></TABLE></TABLE>';
}
-print '</TD></TR></TABLE>';
+%>
-print '<BR>'.
- '<FORM ACTION="'.popurl(2).'edit/process/quick-cust_pkg.cgi" METHOD="POST">'.
- qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
- '<SELECT NAME="pkgpart"><OPTION> ';
+</TD></TR></TABLE>
+<BR>
+<SCRIPT TYPE="text/javascript">
+function enable_order_pkg () {
+ if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
+ document.OrderPkgForm.submit.disabled = false;
+ } else {
+ document.OrderPkgForm.submit.disabled = true;
+ }
+}
+</SCRIPT>
+<FORM NAME="OrderPkgForm" ACTION="<%= $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
+<SELECT NAME="pkgpart" onChange="enable_order_pkg()"><OPTION>Order additional package
+
+<%
foreach my $part_pkg (
qsearch( 'part_pkg', { 'disabled' => '' }, '',
' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
)
) {
- print '<OPTION VALUE="'. $part_pkg->pkgpart. '">'. $part_pkg->pkg. ' - '.
- $part_pkg->comment;
-}
+%>
+<OPTION VALUE="<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg %> - <%= $part_pkg->comment %>
+<% } %>
-print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"></FORM><BR>';
+</SELECT><INPUT NAME="submit" TYPE="submit" VALUE="Order Package" disabled></FORM><BR>
+
+<%
if ( $conf->config('payby-default') ne 'HIDE' ) {
}
-%>
-
-<SCRIPT>
-function cust_pkg_areyousure(href) {
- if (confirm("Permanently delete included services and cancel this package?") == true)
- window.location.href = href;
-}
-function svc_areyousure(href) {
- if (confirm("Permanently unprovision and delete this service?") == true)
- window.location.href = href;
-}
-</SCRIPT>
-
-<%
-
print qq!<A NAME="cust_pkg">Packages</A> !,
qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
;
#end display packages
%>
-<SCRIPT>
-function cust_pay_areyousure(href) {
- if (confirm("Are you sure you want to delete this payment?")
- == true)
- window.location.href = href;
-}
-function cust_pay_unapply_areyousure(href) {
- if (confirm("Are you sure you want to unapply this payment?")
- == true)
- window.location.href = href;
-}
-function cust_credit_unapply_areyousure(href) {
- if (confirm("Are you sure you want to unapply this credit?")
- == true)
- window.location.href = href;
-}
-function cust_credit_areyousure(href) {
- if (confirm("Are you sure you want to delete this credit?")
- == true)
- window.location.href = href;
-}
-</SCRIPT>
-
<% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
<BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
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/^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 = '<B><FONT COLOR="#FF0000">Unapplied ';
$post = '</FONT></B>';
$apply = qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
$cust_pay->paynum. '">apply</A>)';
- } 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 = '<BR>';
- foreach my $cust_bill_pay (@cust_bill_pay) {
- $desc .= ' '.
- '$'. $cust_bill_pay->amount.
- ' applied to Invoice #'. $cust_bill_pay->invnum.
- '<BR>';
- #' 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.
+ '<BR>';
+ #' on '. time2str("%D", $cust_bill_pay->_date).
+ } elsif ( $app->isa('FS::cust_pay_refund') ) {
+ $desc .= ' '.
+ '$'. $app->amount.
+ ' refunded on'. time2str("%D", $app->_date).
+ '<BR>';
+ } else {
+ die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
+ }
}
if ( $cust_pay->unapplied > 0 ) {
$desc .= ' '.
}
}
+ 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! (<A HREF="!. qq!${p}edit/cust_refund.cgi?payby=$1;!.
+ qq!paynum=!. $cust_pay->paynum. qq!">refund</A>)!;
+ }
+
+ my $void = '';
+ if ( $cust_pay->closed !~ /^Y/i
+ && $cust_pay->payby !~ /^(CARD|CHEK)$/
+ ) {
+ $void = qq! (<A HREF="javascript:areyousure('!.
+ qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
+ qq!', 'Are you sure you want to void this payment?')">!.
+ qq!void</A>)!;
+ }
+
my $delete = '';
if ( $cust_pay->closed !~ /^Y/i && $conf->exists('deletepayments') ) {
- $delete = qq! (<A HREF="javascript:cust_pay_areyousure('!.
+ $delete = qq! (<A HREF="javascript:areyousure('!.
qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
- qq!')">delete</A>)!;
+ qq!', 'Are you sure you want to delete this payment?')">!.
+ qq!delete</A>)!;
}
my $unapply = '';
if ( $cust_pay->closed !~ /^Y/i
&& $conf->exists('unapplypayments')
&& scalar(@cust_bill_pay) ) {
- $unapply = qq! (<A HREF="javascript:cust_pay_unapply_areyousure('!.
+ $unapply = qq! (<A HREF="javascript:areyousure('!.
qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
- qq!')">unapply</A>)!;
+ qq!', 'Are you sure you want to unapply this payment?')">!.
+ qq!unapply</A>)!;
}
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' => "<DEL>Payment $info</DEL> <I>voided ".
+ time2str("%D", $cust_pay_void->void_date).
+ " by ". $cust_pay_void->otaker. '</i>',
+ 'void_payment' => $cust_pay_void->paid,
+ };
+
+ }
+
#credits (some false laziness w/payments)
foreach my $cust_credit ($cust_main->cust_credit) {
} 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
}
}
if ( $cust_credit->credited > 0 ) {
- $desc .= ' - <B><FONT COLOR="#FF0000">$'.
+ $desc .= ' <B><FONT COLOR="#FF0000">$'.
$cust_credit->credited. ' unapplied</FONT></B>'.
qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
$cust_credit->crednum. '">apply</A>)'.
#
my $delete = '';
if ( $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits') ) {
- $delete = qq! (<A HREF="javascript:cust_credit_areyousure('!.
+ $delete = qq! (<A HREF="javascript:areyousure('!.
qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
- qq!')">delete</A>)!;
+ qq!', 'Are you sure you want to delete this credit?')">!.
+ qq!delete</A>)!;
}
my $unapply = '';
if ( $cust_credit->closed !~ /^Y/i
&& $conf->exists('unapplycredits')
&& scalar(@cust_credit_bill) ) {
- $unapply = qq! (<A HREF="javascript:cust_credit_unapply_areyousure('!.
+ $unapply = qq! (<A HREF="javascript:areyousure('!.
qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
- qq!')">unapply</A>)!;
+ qq!', 'Are you sure you want to unapply this credit?')">!.
+ qq!unapply</A>)!;
}
push @history, {
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/^CHEK$/Electronic check /;
$payby =~ s/^(CARD|COMP)$/$1 /;
push @history, {
my $payment = exists($item->{'payment'})
? sprintf('- $%.2f', $item->{'payment'})
: '';
+ $payment ||= sprintf('<DEL>- $%.2f</DEL>', $item->{'void_payment'})
+ if exists($item->{'void_payment'});
my $credit = exists($item->{'credit'})
? sprintf('- $%.2f', $item->{'credit'})
: '';
$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;
-
- }
-
- 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";
+ 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";
my $svc = {
'svcnum' => $cust_svc->svcnum,
'label' => ($cust_svc->label)[1],
#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 ];
sub svc_provision_link {
my ($pkg, $svcpart, $conf) = @_;
( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
- my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
my $num_left = $svcpart->{quantity} - $svcpart->{count};
+ my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
- my $link = qq!<A CLASS="provision" HREF="${p}edit/$svcpart->{svcdb}.cgi?!.
- qq!$pkgnum_svcpart">!.
+ my $url;
+ if ( $svcpart->{svcdb} eq 'svc_external'
+ && $conf->exists('svc_external-skip_manual')
+ ) {
+ $url = "${p}edit/process/$svcpart->{svcdb}.cgi?".
+ "pkgnum=$pkg->{pkgnum}&".
+ "svcpart=$svcpart->{svcpart}";
+ } else {
+ $url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
+ }
+
+ my $link = qq!<A CLASS="provision" HREF="$url">!.
"Provision $svc_nbsp ($num_left)</A>";
if ( $conf->exists('legacy_link') ) {
$link .= '<BR>'.
sub svc_unprovision_link {
my $svc = shift or return '';
- return qq!<A HREF="javascript:svc_areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}')">Unprovision</A>!;
+ qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}',!.
+ qq!'Permanently unprovision and delete this service?')">Unprovision</A>!;
}
# This should be generalized to use config options to determine order.
sub pkg_change_link {
my $pkg = shift or return '';
- return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">Change package</a>!;
+ return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">!.
+ qq!Change package</a>!;
}
sub pkg_suspend_link {
sub pkg_cancel_link {
my $pkg = shift or return '';
- qq!<A HREF="javascript:cust_pkg_areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}')">Cancel now</A> | !.
+ qq!<A HREF="javascript:areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}', !.
+ qq!'Permanently delete included services and cancel this package?')">!.
+ qq!Cancel now</A> | !.
qq!<A HREF="${p}misc/expire_pkg.cgi?$pkg->{pkgnum}">Cancel later</A>!;
}
sub pkg_dates_link {
my $pkg = shift or return '';
- return qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
+ qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
}
sub pkg_customize_link {
my $pkg = shift or return '';
my $custnum = shift;
- return qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};pkgnum=$pkg->{pkgnum}">Customize</A>!;
+ qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};!.
+ qq!pkgnum=$pkg->{pkgnum}">Customize</A>!;
}
%>