From 5749847c1d8a05f605127e7e0601ca17ea0bf996 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 27 Nov 2018 15:19:59 -0800 Subject: [PATCH] select agent and customer fields on attachment report, RT#81809 --- FS/FS/cust_attachment.pm | 2 +- httemplate/elements/menu.html | 2 +- httemplate/{browse => search}/cust_attachment.html | 70 ++++++++++++++++------ httemplate/search/report_cust_attachment.html | 42 +++++++++++++ 4 files changed, 95 insertions(+), 21 deletions(-) rename httemplate/{browse => search}/cust_attachment.html (71%) create mode 100644 httemplate/search/report_cust_attachment.html diff --git a/FS/FS/cust_attachment.pm b/FS/FS/cust_attachment.pm index 5e5e07673..8f6278960 100644 --- a/FS/FS/cust_attachment.pm +++ b/FS/FS/cust_attachment.pm @@ -1,7 +1,7 @@ package FS::cust_attachment; use strict; -use base qw( FS::otaker_Mixin FS::Record ); +use base qw( FS::cust_main_Mixin FS::otaker_Mixin FS::Record ); use Carp; use FS::Record qw( qsearch qsearchs ); use FS::Conf; diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index e013632be..7d69596c3 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -554,7 +554,7 @@ $tools_menu{'Business card scan'} = [ $fsurl.'edit/prospect_main-upload.html' ] if $curuser->access_right('New prospect'); $tools_menu{'Time Queue'} = [ $fsurl.'search/report_timeworked.html', 'View pending support time' ] if $curuser->access_right('Time queue'); -$tools_menu{'Attachments'} = [ $fsurl.'browse/cust_attachment.html', 'View customer attachments' ] +$tools_menu{'Attachments'} = [ $fsurl.'search/cust_attachment.html', 'View customer attachments' ] if !$conf->config('disable_cust_attachment') and $curuser->access_right('View attachments') and $curuser->access_right('Browse attachments'); $tools_menu{'Importing'} = [ \%tools_importing, 'Import tools' ] if $curuser->access_right('Import'); diff --git a/httemplate/browse/cust_attachment.html b/httemplate/search/cust_attachment.html similarity index 71% rename from httemplate/browse/cust_attachment.html rename to httemplate/search/cust_attachment.html index f81ec1b6b..7c34733a0 100755 --- a/httemplate/browse/cust_attachment.html +++ b/httemplate/search/cust_attachment.html @@ -1,4 +1,4 @@ -<% include( 'elements/browse.html', +<% include( 'elements/search.html', 'title' => 'Attachments', 'menubar' => '', 'name' => ($disabled ? 'deleted' : '') .' attachments', @@ -11,13 +11,13 @@ ! , - 'query' => { 'table' => 'cust_attachment', - 'hashref' => $hashref, - 'order_by' => 'ORDER BY '.$orderby, - }, + 'query' => $query, 'count_query' => $count_query, 'header' => [ selflink('#',orderby => 'attachnum'), - selflink('Customer',orderby => 'custnum'), + #selflink('Customer',orderby => 'custnum'), + FS::UI::Web::cust_header( + $cgi->param('cust_fields') + ), selflink('Date',orderby => '_date'), selflink('Filename',orderby => 'filename'), selflink('Size',orderby => 'length(body)'), @@ -27,7 +27,8 @@ ], 'fields' => [ 'attachnum', - $sub_cust, + #$sub_cust, + \&FS::UI::Web::cust_fields, $sub_date, 'filename', $sub_size, @@ -36,14 +37,30 @@ $sub_checkbox, ], 'links' => [ '', - [ $p.'view/cust_main.cgi?', 'custnum' ], + ( map { $_ ne 'Cust. Status' ? $clink : '' } + FS::UI::Web::cust_header( + $cgi->param('cust_fields') + ) + ), ], 'link_onclicks' => [ '', - '', + ( map '', FS::UI::Web::cust_header( + $cgi->param('cust_fields') + ) + ), '', $sub_edit_link, ], + 'color' => [ + '', + FS::UI::Web::cust_colors(), + ], + 'style' => [ + '', + FS::UI::Web::cust_styles(), + ], + 'align' => 'r'. FS::UI::Web::cust_aligns(), #'links' => [ # '', @@ -90,20 +107,35 @@ else { } } -my $hashref = $disabled ? - { disabled => { op => '>', value => 0 } } : - { disabled => '' }; - -my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ? - 'disabled > 0' : 'disabled IS NULL'); - my $orderby = $cgi->param('orderby') || 'custnum'; -my $sub_cust = sub { - my $c = qsearchs('cust_main', { custnum => shift->custnum } ); - return $c ? encode_entities($c->name) : '(not found)'; +my $extra_sql = ''; +if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) { + $extra_sql = " AND agentnum = $1 "; +} + +my $query = { + table => 'cust_attachment', + hashref => { disabled => $disabled ? { op => '>', value => 0 } : '', }, + order_by => "ORDER BY $orderby", + addl_from => 'JOIN cust_main USING (custnum)', + extra_sql => "$extra_sql AND ". $curuser->agentnums_sql, }; +my $count_query = 'SELECT COUNT(*) FROM cust_attachment' + . ' JOIN cust_main USING (custnum)' + . ' WHERE ' . $curuser->agentnums_sql + . ' AND disabled ' . ( $disabled ? '> 0' : 'IS NULL' ); + + +#still need to report on attachments with deleted customer? did we ever? +#my $sub_cust = sub { +# my $c = qsearchs('cust_main', { custnum => shift->custnum } ); +# return $c ? encode_entities($c->name) : '(not found)'; +#}; + +my $clink = [ $p.'view/cust_main.cgi?', 'custnum' ]; + my $sub_date = sub { time2str("%b %o, %Y", shift->_date); }; diff --git a/httemplate/search/report_cust_attachment.html b/httemplate/search/report_cust_attachment.html new file mode 100644 index 000000000..d9d9cb430 --- /dev/null +++ b/httemplate/search/report_cust_attachment.html @@ -0,0 +1,42 @@ +<& /elements/header.html, mt('Customer attachment report') &> + +
+ +<% emt('Attachment search options') %> + + + <& /elements/tr-select-agent.html &> + +% if ( $curuser->access_right('View deleted attachments') ) { + + <& /elements/tr-checkbox.html, + 'label' => 'Show deleted attachments', + 'field' => 'show_deleted', + 'value' => 1, + &> + +% } + +
+

+ +<% emt('Display options') %> + + + <& /elements/tr-select-cust-fields.html &> + +
+ +
+ + +
+ +<& /elements/footer.html &> +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +die "access denied" if !$curuser->access_right('View attachments') + || !$curuser->access_right('Browse attachments'); + + -- 2.11.0