summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-10-23 20:24:40 -0500
committerJonathan Prykop <jonathan@freeside.biz>2015-10-28 22:20:01 -0500
commitb1e8f7b5c082434415e36d3f247fbebca2a79f46 (patch)
tree49d378f3dadf5d6526e800025c130ff906e84a8d
parent30deb7ff0f7edada3fa816402ed082999d6c4688 (diff)
RT#38432: OFM - Send refund receipt [v4 merge]
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/cust_refund.pm53
-rw-r--r--FS/FS/msg_template.pm12
-rw-r--r--httemplate/edit/msg_template/email.html10
-rw-r--r--httemplate/view/cust_pay.html15
-rw-r--r--httemplate/view/cust_refund.html36
6 files changed, 122 insertions, 11 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 13f3ec443..95f8aca3a 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1692,6 +1692,13 @@ and customer address. Include units.',
},
{
+ 'key' => 'refund_receipt_msgnum',
+ 'section' => 'notification',
+ 'description' => 'Template to use for manual refund receipts.',
+ %msg_template_options,
+ },
+
+ {
'key' => 'trigger_export_insert_on_payment',
'section' => 'billing',
'description' => 'Enable exports on payment application.',
diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm
index e3fc910ec..efbdceeb0 100644
--- a/FS/FS/cust_refund.pm
+++ b/FS/FS/cust_refund.pm
@@ -370,6 +370,59 @@ sub unapplied {
sprintf("%.2f", $amount );
}
+=item send_receipt HASHREF | OPTION => VALUE ...
+
+Sends a payment receipt for this payment.
+
+refund_receipt_msgnum must be configured.
+
+Available options:
+
+=over 4
+
+=item cust_main
+
+Customer (FS::cust_main) object (for efficiency).
+
+=cut
+
+=back
+
+=cut
+
+sub send_receipt {
+ my $self = shift;
+ my $opt = ref($_[0]) ? shift : { @_ };
+
+ my $cust_main = $opt->{'cust_main'} || $self->cust_main;
+
+ my $conf = new FS::Conf;
+
+ my $msgnum = $conf->config('refund_receipt_msgnum', $cust_main->agentnum);
+ return "No refund_receipt_msgnum configured" unless $msgnum;
+
+ my $msg_template = qsearchs('msg_template',{ msgnum => $msgnum});
+ return "Could not load template"
+ unless $msg_template;
+
+ my $cust_msg = $msg_template->prepare(
+ 'cust_main' => $cust_main,
+ 'object' => $self,
+ 'msgtype' => 'receipt',
+ );
+ return 'Error preparing message' unless $cust_msg;
+ my $error = $cust_msg->insert;
+ return $error if $error;
+
+ my $queue = new FS::queue {
+ 'job' => 'FS::cust_msg::process_send',
+ 'custnum' => $cust_main->custnum,
+ };
+ $error = $queue->insert( $cust_msg->custmsgnum );
+
+ return $error;
+}
+
=back
=head1 CLASS METHODS
diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
index cf81f7ec9..c5d17cd8c 100644
--- a/FS/FS/msg_template.pm
+++ b/FS/FS/msg_template.pm
@@ -613,6 +613,18 @@ sub substitutions {
$cust_pay->paymask : $cust_pay->decrypt($cust_pay->payinfo)
} ],
],
+ # for refund receipts
+ 'cust_refund' => [
+ 'refundnum',
+ [ refund => sub { sprintf("%.2f", shift->refund) } ],
+ [ payby => sub { FS::payby->shortname(shift->payby) } ],
+ [ date => sub { time2str("%a %B %o, %Y", shift->_date) } ],
+ [ payinfo => sub {
+ my $cust_refund = shift;
+ ($cust_refund->payby eq 'CARD' || $cust_refund->payby eq 'CHEK') ?
+ $cust_refund->paymask : $cust_refund->decrypt($cust_refund->payinfo)
+ } ],
+ ],
# for payment decline messages
# try to support all cust_pay fields
# 'error' is a special case, it contains the raw error from the gateway
diff --git a/httemplate/edit/msg_template/email.html b/httemplate/edit/msg_template/email.html
index dc70ef6ec..f0098762d 100644
--- a/httemplate/edit/msg_template/email.html
+++ b/httemplate/edit/msg_template/email.html
@@ -4,7 +4,7 @@
'body_etc' => $body_etc,
'name_singular' => 'template',
'table' => 'msg_template',
- 'viewall_dir' => 'browse',
+ 'viewall_url' => $fsurl.'browse/msg_template/email.html',
'agent_virt' => 1,
'agent_null' => 1,
'agent_null_right' => [ 'View global templates', 'Edit global templates' ],
@@ -302,6 +302,13 @@ my %substitutions = (
'$payinfo' => 'Card/account# (masked)',
'$error' => 'Decline reason',
],
+ 'cust_refund' => [
+ '$refundnum' => 'Refund#',
+ '$refund' => 'Refund Amount',
+ '$payby' => 'Refund method',
+ '$date' => 'Refund date',
+ '$payinfo' => 'Card/account# (masked)',
+ ],
);
tie my %sections, 'Tie::IxHash', (
@@ -309,6 +316,7 @@ tie my %sections, 'Tie::IxHash', (
'service' => 'Service address',
'cust_main' => 'Customer status and payment info',
'cust_pkg' => 'Package fields',
+'cust_refund' => 'Refund fields',
'cust_bill' => 'Invoice fields',
'cust_pay' => 'Payment fields',
'svc_acct' => 'Login service fields',
diff --git a/httemplate/view/cust_pay.html b/httemplate/view/cust_pay.html
index 76a24884a..b34a90818 100644
--- a/httemplate/view/cust_pay.html
+++ b/httemplate/view/cust_pay.html
@@ -3,8 +3,10 @@
<& /elements/header-popup.html, mt("$thing Receipt") &>
<div align="center">
- <A HREF="javascript:self.parent.location = '<% $pr_link %>'"><% mt('Print') |h %></A> |
- <A HREF="javascript:self.location = '<% $email_link %>'"><% mt('Re-email') |h %></A>
+ <A HREF="javascript:self.parent.location = '<% $pr_link %>'"><% mt('Print') |h %></A>
+% if ( $cust_main->invoicing_list_emailonly ) {
+ | <A HREF="javascript:self.location = '<% $email_link %>'"><% mt('Re-email') |h %></A>
+% }
</div><BR>
% } elsif ( $link eq 'print' ) {
@@ -180,11 +182,13 @@ my $cust_pay = qsearchs({
});
die "$thing #$paynum not found!" unless $cust_pay;
+my $cust_main = $cust_pay->cust_main;
+
my $pr_link = "${p}view/cust_pay.html?link=print;paynum=$paynum;void=$void";
my $email_link = "${p}view/cust_pay.html?link=email;paynum=$paynum;void=$void";
my $custnum = $cust_pay->custnum;
-my $display_custnum = $cust_pay->cust_main->display_custnum;
+my $display_custnum = $cust_main->display_custnum;
my $conf = new FS::Conf;
@@ -195,8 +199,9 @@ tie my %payby, 'Tie::IxHash', FS::payby->payby2longname;
my $email_error;
if ( $link eq 'email' ) {
- my $email_error = $cust_pay->send_receipt(
- 'manual' => 1,
+ $email_error = $cust_pay->send_receipt(
+ 'manual' => 1,
+ 'cust_main' => $cust_main,
);
warn "can't send payment receipt/statement: $email_error" if $email_error;
diff --git a/httemplate/view/cust_refund.html b/httemplate/view/cust_refund.html
index 319761506..d5f5eb232 100644
--- a/httemplate/view/cust_refund.html
+++ b/httemplate/view/cust_refund.html
@@ -2,7 +2,12 @@
<& /elements/header-popup.html, mt('Refund Receipt') &>
- <CENTER><A HREF="javascript:self.parent.location = '<% $pr_link %>'"><% mt('Print') |h %></A></CENTER><BR>
+ <DIV ALIGN="center">
+ <A HREF="javascript:self.parent.location = '<% $pr_link %>'"><% mt('Print') |h %></A>
+% if ( $cust_main->invoicing_list_emailonly ) {
+ | <A HREF="javascript:self.location = '<% $email_link %>'"><% mt('Email') |h %></A>
+% }
+ </DIV>
% } elsif ( $link eq 'print' ) {
@@ -16,6 +21,12 @@
%>
<BR><BR>
+% } elsif ( $link eq 'email' ) {
+% if ( $email_error ) {
+ <& /elements/header-popup.html, mt("Error re-emailing receipt: [_1]", $email_error) &>
+% } else {
+ <& /elements/header-popup.html, mt("Re-emailed receipt") &>
+% }
% } else {
<& /elements/header.html, mt('Refund Receipt'), menubar(
@@ -26,7 +37,7 @@
% }
-% unless ($link eq 'popup' ) {
+% unless ($link =~ /^(popup|email)$/ ) {
<& /elements/small_custview.html,
$custnum,
scalar($conf->config('countrydefault')),
@@ -91,9 +102,14 @@
window.print();
</SCRIPT>
-% }
+% } elsif ( $link eq 'email' ) {
-% if ( $link =~ /^(popup|print)$/ ) {
+ <SCRIPT TYPE="text/javascript">
+ window.top.location.reload();
+ </SCRIPT>
+
+% }
+% if ( $link =~ /^(popup|print|email)$/ ) {
</BODY>
</HTML>
% } else {
@@ -125,10 +141,13 @@ my $cust_refund = qsearchs({
});
die "Refund #$refundnum not found!" unless $cust_refund;
+my $cust_main = $cust_refund->cust_main;
+
my $pr_link = "${p}view/cust_refund.html?link=print;refundnum=$refundnum";
+my $email_link = "${p}view/cust_refund.html?link=email;refundnum=$refundnum";
my $custnum = $cust_refund->custnum;
-my $display_custnum = $cust_refund->cust_main->display_custnum;
+my $display_custnum = $cust_main->display_custnum;
my $conf = new FS::Conf;
@@ -136,4 +155,11 @@ my $money_char = $conf->config('money_char') || '$';
tie my %payby, 'Tie::IxHash', FS::payby->payby2longname;
+my $email_error;
+
+if ( $link eq 'email' ) {
+ $email_error = $cust_refund->send_receipt( 'cust_main' => $cust_main );
+ warn "can't send refund receipt: $email_error" if $email_error;
+}
+
</%init>