fix unapplied payment report, RT#73048, fallout from #25944
[freeside.git] / httemplate / search / employee_audit.html
1 <% include("/elements/header.html", "Employee Audit Report") %>
2 <% include("/elements/change_history_common.html", 
3     'history'   => \@history,
4     'tables'    => \%tables,
5     ) %>
6 <% include('/elements/footer.html') %>
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Employees: Audit Report');
11
12 my %tables = (
13     cust_pay        => 'Payments',
14     cust_refund     => 'Refunds',
15     cust_credit     => 'Credits',
16     cust_bill       => 'Invoices',
17     cust_main       => 'Customers',
18     cust_pkg        => 'Packages',
19     cust_main_invoice => 'Customer invoice destinations',
20     cust_pkg_discount => 'Discount applications',
21 );
22
23 my $history_user = ($cgi->param('usernum') && $cgi->param('usernum') =~ /^(\d+)$/) 
24                     ? qsearchs('access_user', { 'usernum' => $1 } )
25                     : '';
26 $history_user = $history_user->username if $history_user;
27
28 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
29
30 my @checked_tables = grep { defined($cgi->param($_)) } keys(%tables);
31
32 my @history;
33 foreach my $table ( @checked_tables ) {
34   my @extra_sql;
35   push @extra_sql, "history_user = '$history_user'" if $history_user;
36   push @extra_sql, "history_date >= $beginning" if $beginning;
37   push @extra_sql, "history_date <= $ending" if $ending;
38   my @items = qsearch({
39     'table'     => "h_$table",
40     'extra_sql' => scalar(@extra_sql) ? "WHERE ".join(' AND ',@extra_sql) : '',
41   });
42   push @history, @items;
43 }
44
45 </%init>