select agent and customer fields on attachment report, RT#81809
authorIvan Kohler <ivan@freeside.biz>
Tue, 27 Nov 2018 23:19:59 +0000 (15:19 -0800)
committerIvan Kohler <ivan@freeside.biz>
Tue, 27 Nov 2018 23:19:59 +0000 (15:19 -0800)
FS/FS/cust_attachment.pm
httemplate/browse/cust_attachment.html [deleted file]
httemplate/elements/menu.html
httemplate/search/cust_attachment.html [new file with mode: 0755]
httemplate/search/report_cust_attachment.html [new file with mode: 0644]

index 5e5e076..8f62789 100644 (file)
@@ -1,7 +1,7 @@
 package FS::cust_attachment;
 
 use strict;
 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;
 use Carp;
 use FS::Record qw( qsearch qsearchs );
 use FS::Conf;
diff --git a/httemplate/browse/cust_attachment.html b/httemplate/browse/cust_attachment.html
deleted file mode 100755 (executable)
index 7330c05..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-<% include( 'elements/browse.html',
-                 'title'       => 'Attachments',
-                 'menubar'     => '',
-                 'name'        => ($disabled ? 'deleted' : '') .' attachments',
-                 'html_init'   => include('/elements/init_overlib.html') .
-                    ($curuser->access_right('View deleted attachments') ? (
-                    selflink('Show '.($disabled ? 'active' : 'deleted'),
-                             show_deleted => (1-$disabled))) : ''),
-                'html_form'   => 
-                    qq!<FORM NAME="attachForm" ACTION="$p/misc/cust_attachment.cgi" METHOD="POST">
-                    <INPUT TYPE="hidden" NAME="orderby" VALUE="$orderby">
-                    <INPUT TYPE="hidden" NAME="show_deleted" VALUE="$disabled">!
-                    , 
-                 'query'       => $query,
-                 'count_query' => $count_query,
-                 'header' => [ selflink('#',orderby => 'attachnum'),
-                               selflink('Customer',orderby => 'custnum'),
-                               selflink('Date',orderby => '_date'),
-                               selflink('Filename',orderby => 'filename'),
-                               selflink('Size',orderby => 'length(body)'),
-                               selflink('Uploaded by',orderby => 'otaker'),
-                               selflink('Description',orderby => 'title'),
-                               '', # checkbox column
-                             ],
-                 'fields' => [
-                               'attachnum',
-                               $sub_cust,
-                               $sub_date,
-                               'filename',
-                               $sub_size,
-                               'otaker',
-                               'title',
-                               $sub_checkbox,
-                             ],
-                 'links' => [ '',
-                              [ $p.'view/cust_main.cgi?', 'custnum' ],
-                            ],
-                 'link_onclicks' => [
-                              '',
-                              '',
-                              '',
-                              $sub_edit_link,
-                              ],
-
-                 #'links' =>  [
-                 #              '',
-                 #              '',
-                 #              '',
-                 #              '',
-                 #              '',
-                 #              '', #$acct_link,
-                 #              '',
-                'html_foot' => $sub_foot,
-             )
-
-%>
-
-
-<%init>
-
-my $curuser = $FS::CurrentUser::CurrentUser;
-die "access denied" if !$curuser->access_right('View attachments')
-                    or !$curuser->access_right('Browse attachments');
-
-my $conf = new FS::Conf;
-
-my $noactions = 1;
-my $areboxes = 0;
-
-my $disabled = 0;
-
-if($cgi->param('show_deleted')) {
-  if ($curuser->access_right('View deleted attachments')) {
-    $disabled = 1;
-    if ($curuser->access_right('Purge attachment') or
-        $curuser->access_right('Undelete attachment')) {
-      $noactions = 0;
-    }
-  }
-  else {
-    die "access denied";
-  }
-}
-else {
-  if ($curuser->access_right('Delete attachment')) {
-    $noactions = 0;
-  }
-}
-
-my $orderby = $cgi->param('orderby') || 'custnum';
-
-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 => ' 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' );
-
-my $sub_cust = sub {
-  my $c = qsearchs('cust_main', { custnum => shift->custnum } );
-  return $c ? encode_entities($c->name) : '<FONT COLOR="red"><B>(not found)</B></FONT>';
-};
-
-my $sub_date = sub {
-  time2str("%b %o, %Y", shift->_date);
-};
-
-my $sub_size = sub {
-  my $size = shift->size;
-  return $size if $size < 1024;
-  return int($size/1024).'K' if $size < 1048576;
-  return int($size/1048576).'M';
-};
-
-my $sub_checkbox = sub {
-  return '' if $noactions;
-  my $attach = shift;
-  my $attachnum = $attach->attachnum;
-  $areboxes = 1;
-  return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
-};
-
-my $sub_edit_link = sub {
-  my $attach = shift;
-  my $attachnum = $attach->attachnum;
-  my $custnum = $attach->custnum;
-  return include('/elements/popup_link_onclick.html',
-           action => popurl(2).'edit/cust_main_attach.cgi?'.
-                     "custnum=$custnum;attachnum=$attachnum",
-           actionlabel => 'Edit attachment properties',
-           width  => 510,
-           height => 315,
-           frame  => 'top',
-           );
-};
-
-sub selflink {
-  my $label = shift;
-  my %new_param = @_;
-  my $param = $cgi->Vars;
-  my %old_param = %$param;
-  @{$param}{keys(%new_param)} = values(%new_param);
-  my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
-  %$param = %old_param;
-  return $link;
-}
-
-sub confirm {
-  my $action = shift;
-  my $onclick = "return(confirm('$action all selected files?'))";
-  return qq!onclick="$onclick"!;
-}
-
-my $sub_foot = sub {
-  return '' if ($noactions or !$areboxes);
-  my $foot = 
-'<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
-<INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
-  if ($disabled) {
-    if ($curuser->access_right('Undelete attachment')) {
-      $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
-    }
-    if ($curuser->access_right('Purge attachment')) {
-      $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
-    }
-  }
-  else {
-    $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
-  }
-  $foot .= 
-'<SCRIPT TYPE="text/javascript">
-  function setAll(setTo) { 
-    theForm = document.attachForm;
-    for (i=0,n=theForm.elements.length;i<n;i++)
-      if (theForm.elements[i].name.indexOf("attachnum") != -1)
-        theForm.elements[i].checked = setTo;
-  }
-</SCRIPT>';
-  return $foot;
-};
-
-</%init>
index 9220073..ed9d59d 100644 (file)
@@ -501,7 +501,7 @@ $report_menu{'SQL Query'}      = [ $fsurl.'search/report_sql.html', 'SQL Query']
 tie my %tools_customers, 'Tie::IxHash', ();
 $tools_customers{'Appointments'} = [ $fsurl.'rt/Search/Schedule.html?LengthMin=0', 'View appointment schedule' ]
   if $curuser->access_right('View appointments');
 tie my %tools_customers, 'Tie::IxHash', ();
 $tools_customers{'Appointments'} = [ $fsurl.'rt/Search/Schedule.html?LengthMin=0', 'View appointment schedule' ]
   if $curuser->access_right('View appointments');
-$tools_customers{'Attachments'} = [ $fsurl.'browse/cust_attachment.html', 'View customer attachments' ]
+$tools_customers{'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_customers{'Customer email settings'} = [ $fsurl.'misc/manage_cust_email.html' ]
   if $curuser->access_right('Edit customer');
   if !$conf->config('disable_cust_attachment') and $curuser->access_right('View attachments') and $curuser->access_right('Browse attachments');
 $tools_customers{'Customer email settings'} = [ $fsurl.'misc/manage_cust_email.html' ]
   if $curuser->access_right('Edit customer');
diff --git a/httemplate/search/cust_attachment.html b/httemplate/search/cust_attachment.html
new file mode 100755 (executable)
index 0000000..556bb52
--- /dev/null
@@ -0,0 +1,216 @@
+<% include( 'elements/search.html',
+                 'title'       => 'Attachments',
+                 'menubar'     => '',
+                 'name'        => ($disabled ? 'deleted' : '') .' attachments',
+                 'html_init'   => include('/elements/init_overlib.html') .
+                    ($curuser->access_right('View deleted attachments') ? (
+                    selflink('Show '.($disabled ? 'active' : 'deleted'),
+                             show_deleted => (1-$disabled))) : ''),
+                'html_form'   => 
+                    qq!<FORM NAME="attachForm" ACTION="$p/misc/cust_attachment.cgi" METHOD="POST">
+                    <INPUT TYPE="hidden" NAME="orderby" VALUE="$orderby">
+                    <INPUT TYPE="hidden" NAME="show_deleted" VALUE="$disabled">!
+                    , 
+                 'query'       => $query,
+                 'count_query' => $count_query,
+                 'header' => [ selflink('#',orderby => 'attachnum'),
+                               #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)'),
+                               selflink('Uploaded by',orderby => 'otaker'),
+                               selflink('Description',orderby => 'title'),
+                               '', # checkbox column
+                             ],
+                 'fields' => [
+                               'attachnum',
+                               #$sub_cust,
+                               \&FS::UI::Web::cust_fields,
+                               $sub_date,
+                               'filename',
+                               $sub_size,
+                               'otaker',
+                               'title',
+                               $sub_checkbox,
+                             ],
+                 'links' => [ '',
+                              ( 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' =>  [
+                 #              '',
+                 #              '',
+                 #              '',
+                 #              '',
+                 #              '',
+                 #              '', #$acct_link,
+                 #              '',
+                'html_foot' => $sub_foot,
+             )
+
+%>
+
+
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied" if !$curuser->access_right('View attachments')
+                    or !$curuser->access_right('Browse attachments');
+
+my $conf = new FS::Conf;
+
+my $noactions = 1;
+my $areboxes = 0;
+
+my $disabled = 0;
+
+if($cgi->param('show_deleted')) {
+  if ($curuser->access_right('View deleted attachments')) {
+    $disabled = 1;
+    if ($curuser->access_right('Purge attachment') or
+        $curuser->access_right('Undelete attachment')) {
+      $noactions = 0;
+    }
+  }
+  else {
+    die "access denied";
+  }
+}
+else {
+  if ($curuser->access_right('Delete attachment')) {
+    $noactions = 0;
+  }
+}
+
+my $orderby = $cgi->param('orderby') || 'custnum';
+
+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) : '<FONT COLOR="red"><B>(not found)</B></FONT>';
+#};
+
+my $clink = [ $p.'view/cust_main.cgi?', 'custnum' ];
+
+my $sub_date = sub {
+  time2str("%b %o, %Y", shift->_date);
+};
+
+my $sub_size = sub {
+  my $size = shift->size;
+  return $size if $size < 1024;
+  return int($size/1024).'K' if $size < 1048576;
+  return int($size/1048576).'M';
+};
+
+my $sub_checkbox = sub {
+  return '' if $noactions;
+  my $attach = shift;
+  my $attachnum = $attach->attachnum;
+  $areboxes = 1;
+  return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
+};
+
+my $sub_edit_link = sub {
+  my $attach = shift;
+  my $attachnum = $attach->attachnum;
+  my $custnum = $attach->custnum;
+  return include('/elements/popup_link_onclick.html',
+           action => popurl(2).'edit/cust_main_attach.cgi?'.
+                     "custnum=$custnum;attachnum=$attachnum",
+           actionlabel => 'Edit attachment properties',
+           width  => 510,
+           height => 315,
+           frame  => 'top',
+           );
+};
+
+sub selflink {
+  my $label = shift;
+  my %new_param = @_;
+  my $param = $cgi->Vars;
+  my %old_param = %$param;
+  @{$param}{keys(%new_param)} = values(%new_param);
+  my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
+  %$param = %old_param;
+  return $link;
+}
+
+sub confirm {
+  my $action = shift;
+  my $onclick = "return(confirm('$action all selected files?'))";
+  return qq!onclick="$onclick"!;
+}
+
+my $sub_foot = sub {
+  return '' if ($noactions or !$areboxes);
+  my $foot = 
+'<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
+<INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
+  if ($disabled) {
+    if ($curuser->access_right('Undelete attachment')) {
+      $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
+    }
+    if ($curuser->access_right('Purge attachment')) {
+      $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
+    }
+  }
+  else {
+    $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
+  }
+  $foot .= 
+'<SCRIPT TYPE="text/javascript">
+  function setAll(setTo) { 
+    theForm = document.attachForm;
+    for (i=0,n=theForm.elements.length;i<n;i++)
+      if (theForm.elements[i].name.indexOf("attachnum") != -1)
+        theForm.elements[i].checked = setTo;
+  }
+</SCRIPT>';
+  return $foot;
+};
+
+</%init>
diff --git a/httemplate/search/report_cust_attachment.html b/httemplate/search/report_cust_attachment.html
new file mode 100644 (file)
index 0000000..d9d9cb4
--- /dev/null
@@ -0,0 +1,42 @@
+<& /elements/header.html, mt('Customer attachment report') &>
+
+<FORM ACTION="cust_attachment.html" METHOD="GET">
+
+<FONT CLASS="fsinnerbox-title"><% emt('Attachment search options') %></FONT>
+<TABLE CLASS="fsinnerbox">
+
+  <& /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,
+    &>
+
+% }
+
+</TABLE>
+<BR><BR>
+
+<FONT CLASS="fsinnerbox-title"><% emt('Display options') %></FONT>
+<TABLE CLASS="fsinnerbox">
+
+    <& /elements/tr-select-cust-fields.html &>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="<% emt('Get Report') %>">
+
+</FORM>
+
+<& /elements/footer.html &>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied" if !$curuser->access_right('View attachments')
+                    || !$curuser->access_right('Browse attachments');
+
+</%init>