From 58f8f045141e56c38dd47bf7b9f33094236c0d0a Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 20 May 2014 22:52:20 -0700 Subject: [PATCH] search voided invoices, missing files, #28684 --- httemplate/search/cust_bill_void.html | 169 +++++++++++++++++++++++++++ httemplate/search/report_cust_bill_void.html | 102 ++++++++++++++++ 2 files changed, 271 insertions(+) create mode 100644 httemplate/search/cust_bill_void.html create mode 100644 httemplate/search/report_cust_bill_void.html diff --git a/httemplate/search/cust_bill_void.html b/httemplate/search/cust_bill_void.html new file mode 100644 index 000000000..d99f759bd --- /dev/null +++ b/httemplate/search/cust_bill_void.html @@ -0,0 +1,169 @@ +<& elements/search.html, + 'title' => emt('Voided Invoice Search Results'), + 'name' => 'voided invoices', + 'query' => $sql_query, + 'count_query' => $count_query, + 'count_addl' => $count_addl, + 'redirect' => $link, + 'header' => [ emt('Invoice #'), + emt('Amount'), + emt('Date'), + FS::UI::Web::cust_header(), + emt('Voided by'), + emt('Date'), + emt('Reason'), + ], + 'fields' => [ + 'display_invnum', + sub { sprintf($money_char.'%.2f', shift->charged ) }, + sub { time2str('%b %d %Y', shift->_date ) }, + \&FS::UI::Web::cust_fields, + 'username', + sub { time2str('%b %d %Y', shift->void_date) }, + 'reason', + ], + 'sort_fields' => [ + 'COALESCE( agent_invid, invnum )', + 'charged', + '_date', + FS::UI::Web::cust_sort_fields(), + 'username', + 'void_date', + 'reason', + ], + 'align' => 'rrl'.FS::UI::Web::cust_aligns().'lll', + 'links' => [ + $link, + $link, + $link, + ( map { $_ ne 'Cust. Status' ? $clink : '' } + FS::UI::Web::cust_header() + ), + $link, + $link, + ], + 'color' => [ + '', + '', + '', + FS::UI::Web::cust_colors(), + ], + 'style' => [ + '', + '', + '', + FS::UI::Web::cust_styles(), + ], +&> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('List invoices'); + # or something else? + +my $conf = new FS::Conf; +my $money_char = $conf->config('money_char') || '$'; + +my $addl_from = + ' LEFT JOIN access_user ON (cust_bill_void.void_usernum = access_user.usernum) '. + FS::UI::Web::join_cust_main('cust_bill_void'); +#here is the agent virtualization +my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql; + +my( $count_query, $sql_query ); +my $count_addl = ''; +my %search; + +if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) { + + my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )"; + my $where = "WHERE $invnum_or_invid AND $agentnums_sql"; + + $count_query = "SELECT COUNT(*) FROM cust_bill_void $addl_from $where"; + + $sql_query = { + 'table' => 'cust_bill_void', + 'addl_from' => $addl_from, + 'hashref' => {}, + 'extra_sql' => $where, + }; + +} else { + + #some false laziness w/cust_bill::re_X + my $orderby = 'ORDER BY cust_bill_void._date'; + + if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { + $search{'agentnum'} = $1; + } + + if ( $cgi->param('refnum') =~ /^(\d+)$/ ) { + $search{'refnum'} = $1; + } + +if ( grep { $_ eq 'cust_classnum' } $cgi->param ) { + $search{'cust_classnum'} = [ $cgi->param('cust_classnum') ]; + } + + if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + $search{'custnum'} = $1; + } + + # begin/end/beginning/ending + my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, ''); + $search{'_date'} = [ $beginning, $ending ] + unless $beginning == 0 && $ending == 4294967295; + + ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, 'void_'); + $search{'void_date'} = [ $beginning, $ending ] + unless $beginning == 0 && $ending == 4294967295; + + if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) { + $search{'invnum_min'} = $1; + } + if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) { + $search{'invnum_max'} = $1; + } + #payby + if ( $cgi->param('payby') ) { + $search{'payby'} = [ $cgi->param('payby') ]; + } + + #amounts + $search{'charged'} = [ FS::UI::Web::parse_lt_gt($cgi, 'charged') ]; + + my $extra_sql = FS::cust_bill_void->search_sql_where( \%search ); + $extra_sql = "WHERE $extra_sql" if $extra_sql; + + unless ( $count_query ) { + $count_query = 'SELECT COUNT(*), SUM(charged)'; + $count_addl = [ $money_char . '%.2f voided' ]; + } + $count_query .= " FROM cust_bill_void $addl_from $extra_sql"; + + $sql_query = { + 'table' => 'cust_bill_void', + 'addl_from' => $addl_from, + 'hashref' => {}, + 'select' => join(', ', + 'cust_bill_void.*', + #( map "cust_main.$_", qw(custnum last first company) ), + 'cust_main.custnum as cust_main_custnum', + FS::UI::Web::cust_sql_fields(), + 'access_user.username', + ), + 'extra_sql' => $extra_sql, + 'order_by' => $orderby, + }; + +} +my $link = [ "${p}view/cust_bill_void.html?", 'invnum', ]; +my $clink = sub { + my $cust_bill = shift; + $cust_bill->cust_main_custnum + ? [ "${p}view/cust_main.cgi?", 'custnum' ] + : ''; +}; + +# really don't want the ability to print/spool/email voided invoices + diff --git a/httemplate/search/report_cust_bill_void.html b/httemplate/search/report_cust_bill_void.html new file mode 100644 index 000000000..cb13b785a --- /dev/null +++ b/httemplate/search/report_cust_bill_void.html @@ -0,0 +1,102 @@ +<& /elements/header.html, mt($title, @title_arg) &> + +
+ + + +% unless ( $custnum ) { + + + + + + + + <& /elements/tr-select-agent.html, + 'curr_value' => scalar( $cgi->param('agentnum') ), + 'label' => emt('Agent'), + 'disable_empty' => 0, + &> + + <& /elements/tr-select-cust_class.html, + label => mt('Customer Class'), + field => 'cust_classnum', + multiple => 1, + 'pre_options' => [ '' => emt('(none)') ], + 'all_selected' => 1, + &> + +% if ( $cust_main ) { + +% } else { + <& /elements/tr-select-payby.html, + label => emt('Payment method:'), + payby_type => 'cust', + multiple => 1, + all_selected => 1, + &> +% } + +
+ Customer search options +
+
+ +% } + + + + + + + + <& /elements/tr-input-beginning_ending.html &> + + <& /elements/tr-input-lessthan_greaterthan.html, + label => emt('Charged'), + field => 'charged', + &> + + <& /elements/tablebreak-tr-title.html, + value => 'Void circumstances' + &> + <& /elements/tr-select-user.html, + field => 'void_usernum', + label => 'Voided by: ', + &> + <& /elements/tr-input-beginning_ending.html, prefix => 'void_' &> + +
+ Invoice search options +
+
+ + +
+ +<& /elements/footer.html &> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('List invoices'); + +my $conf = new FS::Conf; + +my $title = 'Voided Invoice Report'; +#false laziness w/report_cust_pkg.html +my @title_arg = (); + +my $custnum = ''; +my $cust_main = ''; +if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + $custnum = $1; + $cust_main = qsearchs({ + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $custnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, + }) or die "unknown custnum $custnum"; + $title .= ': [_1]'; + push @title_arg, $cust_main->name; +} + + -- 2.11.0