summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorlevinse <levinse>2011-07-01 22:02:47 +0000
committerlevinse <levinse>2011-07-01 22:02:47 +0000
commitd6ff3967df6ee08263023a4d35865b66bdb8a672 (patch)
treeae4d8ed7ba36c2eb6cd853b08226d86c4a93e98b /httemplate
parent4665d5af02f915679207a369222472a25e137c9d (diff)
add employee audit report, RT13350
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/elements/change_history_common.html199
-rw-r--r--httemplate/elements/menu.html1
-rw-r--r--httemplate/search/employee_audit.html45
-rw-r--r--httemplate/search/report_employee_audit.html39
-rw-r--r--httemplate/view/cust_main/change_history.html186
5 files changed, 290 insertions, 180 deletions
diff --git a/httemplate/elements/change_history_common.html b/httemplate/elements/change_history_common.html
new file mode 100644
index 0000000..9e19539
--- /dev/null
+++ b/httemplate/elements/change_history_common.html
@@ -0,0 +1,199 @@
+<% include("/elements/table-grid.html") %>
+% my $bgcolor1 = '#eeeeee';
+% my $bgcolor2 = '#ffffff';
+% my $bgcolor = '';
+
+<TR>
+ <TH CLASS="grid" BGCOLOR="#cccccc">User</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Time</TH>
+ <% $single_cust ? '' :
+ '<TH CLASS="grid" BGCOLOR="#cccccc">Customer</TH>'
+ %>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Item</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
+</TR>
+
+% foreach my $item ( sort { $a->history_date <=> $b->history_date
+% #|| table order
+% || $a->historynum <=> $b->historynum
+% }
+% @history
+% )
+% {
+% my $history_other = '';
+% my $act = $item->history_action;
+% if ( $act =~ /^replace/ ) {
+% my $pkey = $item->primary_key;
+% my $date = $item->history_date;
+% $history_other = qsearchs({
+% 'table' => $item->table,
+% 'hashref' => { $pkey => $item->$pkey(),
+% 'history_action' => $replace_other{$act},
+% 'historynum' => { 'op' => $replace_dir{$act},
+% 'value' => $item->historynum
+% },
+% },
+% 'extra_sql' => "
+% AND history_date $replace_direq{$act} $date
+% AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date
+% ORDER BY historynum $replace_ord{$act} LIMIT 1
+% ",
+% });
+% }
+%
+% if ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+
+ <TR>
+ <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+% my $otaker = $item->history_user;
+% $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
+% $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
+% $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
+ <% $otaker %>
+ </TD>
+ <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+% my $d = time2str('%b %o, %Y', $item->history_date );
+% $d =~ s/ /&nbsp;/g;
+ <% $d %>
+ </TD>
+ <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+% my $t = time2str('%r', $item->history_date );
+% $t =~ s/ /&nbsp;/g;
+ <% $t %>
+ </TD>
+
+% unless ( $single_cust ) {
+ <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+% my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
+ <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
+ .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
+ </TD>
+% }
+
+ <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+% my $label = '';
+% $label = $item->table;
+% $label =~ s/^h_//;
+% $label = $tables{$label};
+% if ( $single_cust ) {
+% $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
+% if $h_table_labelsub{$item->table};
+% }
+ <% $label %>
+ </TD>
+ <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+ <% $action{$item->history_action} %>
+ </TD>
+ <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+ <% join(', ',
+ map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
+ ? 'N/A'
+ : $item->get($_);
+ $value = time2str($cust_pkg_date_format, $value)
+ if $item->table eq 'h_cust_pkg'
+ && $cust_pkg_date_fields{$_}
+ && $value;
+
+ $value = substr($value, 0, 77).'...' if length($value) > 80;
+ $value = encode_entities($value);
+ "<I>$_</I>:<B>$value</B>";
+ }
+ grep { $history_other
+ ? ( $item->get($_) ne $history_other->get($_) )
+ : ( $item->get($_) =~ /\S/ )
+ }
+ grep { ! /^(history|custnum$)/i }
+ $item->fields
+ )
+ %>
+ </TD>
+ </TR>
+
+% }
+</TABLE>
+<%init>
+
+my %opt = @_;
+my @history = @{$opt{'history'}};
+my %tables = %{$opt{'tables'}};
+my $single_cust = $opt{'single_cust'};
+my $conf = new FS::Conf;
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access deined"
+ unless $curuser->access_right('View customer history');
+
+my %action = (
+ 'insert' => 'Insert', #'Create',
+ 'replace_old' => 'Change&nbsp;from',
+ 'replace_new' => 'Change&nbsp;to',
+ 'delete' => 'Remove',
+);
+
+my %cust_pkg_date_fields = map { $_=>1 } qw(
+ start_date setup bill last_bill susp adjourn cancel expire contract_end
+ change_date
+);
+
+# finding the other replace row
+
+my %replace_other = (
+ 'replace_new' => 'replace_old',
+ 'replace_old' => 'replace_new',
+);
+my %replace_dir = (
+ 'replace_new' => '<',
+ 'replace_old' => '>',
+);
+my %replace_direq = (
+ 'replace_new' => '<=',
+ 'replace_old' => '>=',
+);
+my %replace_op = (
+ 'replace_new' => '-',
+ 'replace_old' => '+',
+);
+my %replace_ord = (
+ 'replace_new' => 'DESC',
+ 'replace_old' => 'ASC',
+);
+
+my $fuzz = 5; #seems like a lot
+
+my %pkgpart = ();
+my $pkg_labelsub = sub {
+ my($item, $label) = @_;
+ $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
+ $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
+};
+
+my $svc_labelsub = sub {
+ my($item, $label) = @_;
+ $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
+};
+
+my %h_table_labelsub = (
+ 'h_cust_pkg' => $pkg_labelsub,
+ 'h_svc_acct' => $svc_labelsub,
+ #'h_radius_usergroup' =>
+ 'h_svc_domain' => $svc_labelsub,
+ 'h_svc_www' => $svc_labelsub,
+ 'h_svc_forward' => $svc_labelsub,
+ 'h_svc_broadband' => $svc_labelsub,
+ 'h_svc_external' => $svc_labelsub,
+ 'h_svc_phone' => $svc_labelsub,
+ #'h_phone_device'
+);
+
+my $cust_pkg_date_format = '%b %o, %Y';
+$cust_pkg_date_format .= ' %l:%M:%S%P'
+ if $conf->exists('cust_pkg-display_times')
+ || $curuser->option('cust_pkg-display_times');
+
+</%init>
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index 236fe6a..1064836 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -310,6 +310,7 @@ if($curuser->access_right('Financial reports')) {
'Refund Report' => [ $fsurl.'search/report_cust_refund.html', 'Refund report (by type and/or date range)' ],
'Unapplied Refunds' => [ $fsurl.'search/report_cust_refund.html?unapplied=1', 'Unapplied refund report (by type and/or date range)' ],
'Package Costs Report' => [ $fsurl.'graph/report_cust_pkg_cost.html', 'Package setup and recurring costs graph' ],
+ 'Employee Audit Report' => [ $fsurl.'search/report_employee_audit.html', 'Employee audit report' ],
);
$report_financial{'A/R Aging'} = [ $fsurl.'search/report_receivables.html', 'Accounts Receivable Aging report' ];
$report_financial{'Prepaid Income'} = [ $fsurl.'search/report_prepaid_income.html', 'Prepaid income (unearned revenue) report' ];
diff --git a/httemplate/search/employee_audit.html b/httemplate/search/employee_audit.html
new file mode 100644
index 0000000..753c7bf
--- /dev/null
+++ b/httemplate/search/employee_audit.html
@@ -0,0 +1,45 @@
+<% include("/elements/header.html", "Employee Audit Report") %>
+<% include("/elements/change_history_common.html",
+ 'history' => \@history,
+ 'tables' => \%tables,
+ ) %>
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my %tables = (
+ cust_pay => 'Payments',
+ cust_refund => 'Refunds',
+ cust_credit => 'Credits',
+ cust_bill => 'Invoices',
+ cust_main => 'Customers',
+ cust_pkg => 'Packages',
+ cust_main_invoice => 'Customer invoice destinations',
+ cust_pkg_discount => 'Discount applications',
+);
+
+my $history_user = ($cgi->param('usernum') && $cgi->param('usernum') =~ /^(\d+)$/)
+ ? qsearchs('access_user', { 'usernum' => $1 } )
+ : '';
+$history_user = $history_user->username if $history_user;
+
+my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
+
+my @checked_tables = grep { defined($cgi->param($_)) } keys(%tables);
+
+my @history;
+foreach my $table ( @checked_tables ) {
+ my @extra_sql;
+ push @extra_sql, "history_user = '$history_user'" if $history_user;
+ push @extra_sql, "history_date >= $beginning" if $beginning;
+ push @extra_sql, "history_date <= $ending" if $ending;
+ my @items = qsearch({
+ 'table' => "h_$table",
+ 'extra_sql' => scalar(@extra_sql) ? "WHERE ".join(' AND ',@extra_sql) : '',
+ });
+ push @history, @items;
+}
+
+</%init>
diff --git a/httemplate/search/report_employee_audit.html b/httemplate/search/report_employee_audit.html
new file mode 100644
index 0000000..757b823
--- /dev/null
+++ b/httemplate/search/report_employee_audit.html
@@ -0,0 +1,39 @@
+<% include('/elements/header.html', 'Employee audit report' ) %>
+
+<FORM ACTION="employee_audit.html" METHOD="GET">
+ <TABLE>
+ <% include( '/elements/tr-select-user.html' ) %>
+ <% include( '/elements/tr-input-beginning_ending.html', ) %>
+
+ <% include( '/elements/tr-td-label.html', label => 'Include:' ) %>
+ <TD>
+ <% map { include('/elements/checkbox.html',
+ field => $_, id => $_, postfix => $tables{$_} )
+ . "<BR>"
+ } keys(%tables)
+ %>
+ </TD>
+ </TR>
+
+ </TABLE>
+<INPUT TYPE="submit" VALUE="Get Report">
+</FORM>
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my %tables = (
+ cust_pay => 'Payments',
+ cust_refund => 'Refunds',
+ cust_credit => 'Credits',
+ cust_bill => 'Invoices',
+ cust_main => 'Customers',
+ cust_pkg => 'Packages',
+ cust_main_invoice => 'Customer invoice destinations',
+ cust_pkg_discount => 'Discount applications',
+);
+
+</%init>
diff --git a/httemplate/view/cust_main/change_history.html b/httemplate/view/cust_main/change_history.html
index 8fc90f6..ea84b8f 100644
--- a/httemplate/view/cust_main/change_history.html
+++ b/httemplate/view/cust_main/change_history.html
@@ -13,113 +13,13 @@
% $cgi->param('change_history-years', $chy);
% }
-<% include("/elements/table-grid.html") %>
-% my $bgcolor1 = '#eeeeee';
-% my $bgcolor2 = '#ffffff';
-% my $bgcolor = '';
+<% include("/elements/change_history_common.html",
+ 'history' => \@history,
+ 'tables' => \%tables,
+ 'single_cust' => 1,
+ ) %>
-<TR>
- <TH CLASS="grid" BGCOLOR="#cccccc">User</TH>
- <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
- <TH CLASS="grid" BGCOLOR="#cccccc">Time</TH>
- <TH CLASS="grid" BGCOLOR="#cccccc">Item</TH>
- <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
- <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
-</TR>
-
-% foreach my $item ( sort { $a->history_date <=> $b->history_date
-% #|| table order
-% || $a->historynum <=> $b->historynum
-% }
-% @history
-% )
-% {
-%
-% my $history_other = '';
-% my $act = $item->history_action;
-% if ( $act =~ /^replace/ ) {
-% my $pkey = $item->primary_key;
-% my $date = $item->history_date;
-% $history_other = qsearchs({
-% 'table' => $item->table,
-% 'hashref' => { $pkey => $item->$pkey(),
-% 'history_action' => $replace_other{$act},
-% 'historynum' => { 'op' => $replace_dir{$act},
-% 'value' => $item->historynum
-% },
-% },
-% 'extra_sql' => "
-% AND history_date $replace_direq{$act} $date
-% AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date
-% ORDER BY historynum $replace_ord{$act} LIMIT 1
-% ",
-% });
-% }
-%
-% if ( $bgcolor eq $bgcolor1 ) {
-% $bgcolor = $bgcolor2;
-% } else {
-% $bgcolor = $bgcolor1;
-% }
-
- <TR>
- <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-% my $otaker = $item->history_user;
-% $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
-% $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
-% $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
- <% $otaker %>
- </TD>
- <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-% my $d = time2str('%b %o, %Y', $item->history_date );
-% $d =~ s/ /&nbsp;/g;
- <% $d %>
- </TD>
- <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-% my $t = time2str('%r', $item->history_date );
-% $t =~ s/ /&nbsp;/g;
- <% $t %>
- </TD>
- <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-% my $label = $h_tables{$item->table};
-% $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
-% if $h_table_labelsub{$item->table};
- <% $label %>
- </TD>
- <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
- <% $action{$item->history_action} %>
- </TD>
- <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
- <% join(', ',
- map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
- ? 'N/A'
- : $item->get($_);
- $value = time2str($cust_pkg_date_format, $value)
- if $item->table eq 'h_cust_pkg'
- && $cust_pkg_date_fields{$_}
- && $value;
-
- $value = substr($value, 0, 77).'...' if length($value) > 80;
- $value = encode_entities($value);
- "<I>$_</I>:<B>$value</B>";
- }
- grep { $history_other
- ? ( $item->get($_) ne $history_other->get($_) )
- : ( $item->get($_) =~ /\S/ )
- }
- grep { ! /^(history|custnum$)/i }
- $item->fields
- )
- %>
- </TD>
- </TR>
-
-% }
-
-</TABLE>
-<%once>
-
-# length-switching
+<%init>
tie my %years, 'Tie::IxHash',
.5 => '6 months',
@@ -129,42 +29,6 @@ tie my %years, 'Tie::IxHash',
39 => 'all history',
;
-# labeling history rows
-
-my %action = (
- 'insert' => 'Insert', #'Create',
- 'replace_old' => 'Change&nbsp;from',
- 'replace_new' => 'Change&nbsp;to',
- 'delete' => 'Remove',
-);
-
-# finding the other replace row
-
-my %replace_other = (
- 'replace_new' => 'replace_old',
- 'replace_old' => 'replace_new',
-);
-my %replace_dir = (
- 'replace_new' => '<',
- 'replace_old' => '>',
-);
-my %replace_direq = (
- 'replace_new' => '<=',
- 'replace_old' => '>=',
-);
-my %replace_op = (
- 'replace_new' => '-',
- 'replace_old' => '+',
-);
-my %replace_ord = (
- 'replace_new' => 'DESC',
- 'replace_old' => 'ASC',
-);
-
-my $fuzz = 5; #seems like a lot
-
-# which tables to search and what to call them
-
tie my %tables, 'Tie::IxHash',
'cust_main' => 'Customer',
'cust_main_invoice' => 'Invoice destination',
@@ -196,32 +60,6 @@ my %table_join = (
'phone_device' => $svc_join,
);
-my %h_tables = map { ( "h_$_" => $tables{$_} ) } keys %tables;
-
-my %pkgpart = ();
-my $pkg_labelsub = sub {
- my($item, $label) = @_;
- $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
- $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
-};
-
-my $svc_labelsub = sub {
- my($item, $label) = @_;
- $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
-};
-
-my %h_table_labelsub = (
- 'h_cust_pkg' => $pkg_labelsub,
- 'h_svc_acct' => $svc_labelsub,
- #'h_radius_usergroup' =>
- 'h_svc_domain' => $svc_labelsub,
- 'h_svc_www' => $svc_labelsub,
- 'h_svc_forward' => $svc_labelsub,
- 'h_svc_broadband' => $svc_labelsub,
- 'h_svc_external' => $svc_labelsub,
- 'h_svc_phone' => $svc_labelsub,
- #'h_phone_device'
-);
# cust_main
# cust_main_invoice
@@ -259,8 +97,6 @@ my %h_table_labelsub = (
# cust_location?
# cust_main-exemption?? (295.ca named tax exemptions)
-</%once>
-<%init>
my( $cust_main ) = @_;
@@ -271,16 +107,6 @@ my $curuser = $FS::CurrentUser::CurrentUser;
die "access deined"
unless $curuser->access_right('View customer history');
-my $cust_pkg_date_format = '%b %o, %Y';
-$cust_pkg_date_format .= ' %l:%M:%S%P'
- if $conf->exists('cust_pkg-display_times')
- || $curuser->option('cust_pkg-display_times');
-
-my %cust_pkg_date_fields = map { $_=>1 } qw(
- start_date setup bill last_bill susp adjourn cancel expire contract_end
- change_date
-);
-
# find out the beginning of this customer history, if possible
my $h_insert = qsearchs({
'table' => 'h_cust_main',