From 9f5cf2be392f07e6d7dd49462b14f7ee351c251e Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 14 Dec 2015 16:26:05 -0800 Subject: [PATCH] show refund reason on report and make it searchable, #39398 --- httemplate/elements/menu.html | 2 +- httemplate/search/cust_pay_pending.html | 1 + httemplate/search/cust_pay_void.html | 1 + httemplate/search/elements/cust_pay_or_refund.html | 21 +++++++++++++++++++++ .../search/elements/report_cust_pay_or_refund.html | 18 +++++++++++++++++- httemplate/search/report_cust_refund.html | 1 + 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 0988b98db..fd77d9d28 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -684,12 +684,12 @@ if ( $curuser->access_right('Configuration') ) { if $conf->exists('enable_taxproducts'); $config_billing{'Tax classes'} = [ $fsurl. 'browse/part_pkg_taxclass.html', 'Tax classes' ]; + $config_billing{'separator5'} = ''; #its a separator! $config_billing{'Credit reasons'} = [ $fsurl.'browse/reason.html?class=R', 'Credit reasons explain why a credit was issued.' ]; $config_billing{'Credit reason types'} = [ $fsurl.'browse/reason_type.html?class=R', 'Credit reason types define groups of reasons.' ]; $config_billing{'Credit void reasons'} = [ $fsurl.'browse/reason.html?class=X', 'Credit void reasons explain why a credit was voided.' ]; $config_billing{'Credit void reason types'} = [ $fsurl.'browse/reason_type.html?class=X', 'Credit void reason types define groups of reasons.' ]; - $config_billing{'separator5'} = ''; #its a separator! $config_billing{'Refund reasons'} = [ $fsurl.'browse/reason.html?class=F', 'Refund reasons explain why a refund was issued.' ]; $config_billing{'Refund reason types'} = [ $fsurl.'browse/reason_type.html?class=F', 'Refund reason types define groups of reasons.' ]; } diff --git a/httemplate/search/cust_pay_pending.html b/httemplate/search/cust_pay_pending.html index 54c9935ef..942085c6c 100755 --- a/httemplate/search/cust_pay_pending.html +++ b/httemplate/search/cust_pay_pending.html @@ -9,6 +9,7 @@ 'addl_fields' => [ sub { time2str('%r', shift->_date ) }, $status_sub, ], + 'addl_sort_fields' => [ 'status' ], 'redirect_empty' => $redirect_empty, &> <%init> diff --git a/httemplate/search/cust_pay_void.html b/httemplate/search/cust_pay_void.html index 5b247367b..c639706df 100755 --- a/httemplate/search/cust_pay_void.html +++ b/httemplate/search/cust_pay_void.html @@ -8,4 +8,5 @@ 'addl_fields' => [ sub { time2str('%b %d %Y', shift->void_date ) }, ], + 'addl_sort_fields' => [ 'void_date' ], &> diff --git a/httemplate/search/elements/cust_pay_or_refund.html b/httemplate/search/elements/cust_pay_or_refund.html index 1fea67c19..ffc6afed3 100755 --- a/httemplate/search/elements/cust_pay_or_refund.html +++ b/httemplate/search/elements/cust_pay_or_refund.html @@ -26,6 +26,7 @@ Examples: 'html_init' => '', 'addl_header' => [], 'addl_fields' => [], + 'addl_sort_fields' => [], 'redirect_empty' => $redirect_empty, ) @@ -80,6 +81,8 @@ die "access denied" my $table = $opt{'table'} || 'cust_'.$opt{'thing'}; +my $has_reason = dbdef->table($table)->column('reasonnum') ? 1 : 0; + my $amount_field = $opt{'amount_field'}; my $name_singular = $opt{'name_singular'}; @@ -217,6 +220,7 @@ unless ( $opt{'disable_by'} ) { $o = 'customer self-service' if $o eq 'fs_selfservice'; $o; }; + push @sort_fields, ''; } if ( $tax_names ) { @@ -233,6 +237,7 @@ if ( $tax_names ) { split('\|', shift->tax_names) ); }; + push @sort_fields, '', ''; } push @header, FS::UI::Web::cust_header(); @@ -242,11 +247,14 @@ push @links, map { $_ ne 'Cust. Status' ? $cust_link : '' } my @color = ( ( map '', @fields ), FS::UI::Web::cust_colors() ); my @style = ( ( map '', @fields ), FS::UI::Web::cust_styles() ); push @fields, \&FS::UI::Web::cust_fields; +push @sort_fields, FS::UI::Web::cust_sort_fields; push @header, @{ $opt{'addl_header'} } if $opt{'addl_header'}; push @fields, @{ $opt{'addl_fields'} } if $opt{'addl_fields'}; +push @sort_fields, @{ $opt{'addl_sort_fields'} } + if $opt{'addl_sort_fields'}; my( $count_query, $sql_query, @count_addl ); if ( $cgi->param('magic') ) { @@ -432,6 +440,7 @@ if ( $cgi->param('magic') ) { push @search, "($table.auth LIKE '$1%') OR ($table.order_number LIKE '$1%')"; push @fields, 'auth', 'order_number'; push @header, 'Auth #', 'Transaction #'; + push @sort_fields, '', ''; $align .= 'rr'; } @@ -513,6 +522,18 @@ if ( $cgi->param('magic') ) { my $addl_from = FS::UI::Web::join_cust_main($table); my $group_by = ''; + # reasons, for refunds and voided payments + if ( $has_reason ) { + push @select, "reason.reason"; + $addl_from .= " LEFT JOIN reason USING (reasonnum)\n"; + push @fields, 'reason'; + push @sort_fields, 'reason.reason'; + push @header, emt('Reason'); + if ( $cgi->param('reasonnum') =~ /^(\d+)$/ ) { + push @search, "COALESCE(reasonnum, 0) = $1"; + } + } + if ( $cgi->param('tax_names') ) { if ( dbh->{Driver}->{Name} =~ /^Pg/i ) { diff --git a/httemplate/search/elements/report_cust_pay_or_refund.html b/httemplate/search/elements/report_cust_pay_or_refund.html index 70727c007..a25e69643 100644 --- a/httemplate/search/elements/report_cust_pay_or_refund.html +++ b/httemplate/search/elements/report_cust_pay_or_refund.html @@ -23,7 +23,7 @@ Examples: - <% mt('Payment search options') |h %> + <% mt('[_1] search options', ucfirst($name_singular)) |h %> @@ -51,6 +51,20 @@ Examples: <& /elements/tr-select-user.html &> +% if ( $has_reason ) { +% # limit to reasons that are in use for the table being reported on +% # (maybe order by count(*) desc?) + <& /elements/tr-select-table.html, + label => emt('Reason'), + field => 'reasonnum', + id => 'reasonnum', + table => 'reason', + name_col => 'reason', + extra_sql => " WHERE EXISTS(SELECT 1 FROM $table WHERE $table.reasonnum = reason.reasonnum) ", + empty_label => emt('any'), + &> +% } + <% mt(ucfirst($name_singular). ' date') |h %> @@ -166,6 +180,8 @@ my $title = $void ? "Voided $name_singular report" : "\u$name_singular report" ; $table .= '_void' if $void; +my $has_reason = dbdef->table($table)->column('reasonnum'); + tie (my %payby, 'Tie::IxHash', 'CARD-VisaMC' => 'credit card (Visa/MasterCard)', 'CARD-Amex' => 'credit card (American Express)', diff --git a/httemplate/search/report_cust_refund.html b/httemplate/search/report_cust_refund.html index fe84cf6e2..98b31a10f 100644 --- a/httemplate/search/report_cust_refund.html +++ b/httemplate/search/report_cust_refund.html @@ -1,4 +1,5 @@ <& elements/report_cust_pay_or_refund.html, 'thing' => 'refund', 'name_singular' => emt('refund'), + 'reason_class' => 'F', &> -- 2.11.0