future package unsuspend date, #14144
[freeside.git] / httemplate / elements / change_history_common.html
1 <% include("/elements/table-grid.html") %>
2 % my $bgcolor1 = '#eeeeee';
3 %   my $bgcolor2 = '#ffffff';
4 %   my $bgcolor = '';
5
6 <TR>
7   <TH CLASS="grid" BGCOLOR="#cccccc">User</TH>
8   <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
9   <TH CLASS="grid" BGCOLOR="#cccccc">Time</TH>
10   <% $single_cust ? '' : 
11            '<TH CLASS="grid" BGCOLOR="#cccccc">Customer</TH>'
12   %>
13   <TH CLASS="grid" BGCOLOR="#cccccc">Item</TH>
14   <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
15   <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
16 </TR>
17
18 % foreach my $item ( sort { $a->history_date <=> $b->history_date
19 %                           #|| table order
20 %                           || $a->historynum <=> $b->historynum
21 %                         }
22 %                         @history
23 %                  )
24 % {
25 %   my $history_other = '';
26 %   my $act  = $item->history_action;
27 %   if ( $act =~ /^replace/ ) {
28 %     my $pkey = $item->primary_key;
29 %     my $date = $item->history_date;
30 %     $history_other = qsearchs({
31 %       'table'     => $item->table,
32 %       'hashref'   => { $pkey            => $item->$pkey(),
33 %                        'history_action' => $replace_other{$act},
34 %                        'historynum'     => { 'op'    => $replace_dir{$act},
35 %                                              'value' => $item->historynum
36 %                                            },
37 %                      },
38 %       'extra_sql' => "
39 %         AND history_date $replace_direq{$act} $date
40 %         AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date
41 %         ORDER BY historynum $replace_ord{$act} LIMIT 1
42 %       ",
43 %     });
44 %   }
45 %
46 %   if ( $bgcolor eq $bgcolor1 ) {
47 %     $bgcolor = $bgcolor2;
48 %   } else {
49 %     $bgcolor = $bgcolor1;
50 %   }
51
52   <TR>
53     <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
54 %     my $otaker = $item->history_user;
55 %     $otaker = '<i>auto billing</i>'          if $otaker eq 'fs_daily';
56 %     $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
57 %     $otaker = '<i>job queue</i>'             if $otaker eq 'fs_queue';
58       <% $otaker %>
59     </TD>
60     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
61 %     my $d = time2str('%b %o, %Y', $item->history_date );
62 %     $d =~ s/ /&nbsp;/g;
63       <% $d %>
64     </TD>
65     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
66 %     my $t = time2str('%r', $item->history_date );
67 %     $t =~ s/ /&nbsp;/g;
68       <% $t %>
69     </TD>
70
71 % unless ( $single_cust ) {
72     <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
73 %    my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
74       <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
75                             .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
76     </TD>
77 % }
78
79     <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
80 %       my $label = '';
81 %       $label = $item->table;
82 %       $label =~ s/^h_//;
83 %       $label = $tables{$label};
84 % if ( $single_cust ) {
85 %     $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
86 %       if $h_table_labelsub{$item->table};
87 % }
88       <% $label %>
89     </TD>
90     <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
91       <% $action{$item->history_action} %>
92     </TD>
93     <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
94       <% join(', ',
95            map  { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ ) 
96                                 ? 'N/A'
97                                 : $item->get($_);
98                   $value = time2str($cust_pkg_date_format, $value)
99                    if $item->table eq 'h_cust_pkg'
100                    && $cust_pkg_date_fields{$_}
101                    && $value;
102
103                   $value = substr($value, 0, 77).'...' if length($value) > 80;
104                   $value = encode_entities($value);
105                   "<I>$_</I>:<B>$value</B>";
106                 }
107            grep { $history_other
108                     ? ( $item->get($_) ne $history_other->get($_) )
109                     : ( $item->get($_) =~ /\S/ )
110                 }
111            grep { ! /^(history|custnum$)/i }
112                 $item->fields
113          )
114       %>
115     </TD>
116   </TR>
117
118 % }
119 </TABLE>
120 <%init>
121
122 my %opt = @_;
123 my @history = @{$opt{'history'}};
124 my %tables = %{$opt{'tables'}};
125 my $single_cust = $opt{'single_cust'};
126 my $conf = new FS::Conf;
127 my $curuser = $FS::CurrentUser::CurrentUser;
128
129 die "access deined"
130   unless $curuser->access_right('View customer history');
131
132 my %action = (
133   'insert'      => 'Insert', #'Create',
134   'replace_old' => 'Change&nbsp;from',
135   'replace_new' => 'Change&nbsp;to',
136   'delete'      => 'Remove',
137 );
138
139 my %cust_pkg_date_fields = map { $_=>1 } qw(
140   start_date setup bill last_bill susp adjourn cancel expire contract_end
141   resume change_date
142 );
143
144 # finding the other replace row
145
146 my %replace_other = (
147   'replace_new' => 'replace_old',
148   'replace_old' => 'replace_new',
149 );
150 my %replace_dir = (
151   'replace_new' => '<',
152   'replace_old' => '>',
153 );
154 my %replace_direq = (
155   'replace_new' => '<=',
156   'replace_old' => '>=',
157 );
158 my %replace_op = (
159   'replace_new' => '-',
160   'replace_old' => '+',
161 );
162 my %replace_ord = (
163   'replace_new' => 'DESC',
164   'replace_old' => 'ASC',
165 );
166
167 my $fuzz = 5; #seems like a lot
168
169 my %pkgpart = ();
170 my $pkg_labelsub = sub {
171   my($item, $label) = @_;
172   $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
173   $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
174 };
175
176 my $svc_labelsub = sub {
177   my($item, $label) = @_;
178   $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
179 };
180
181 my %h_table_labelsub = (
182   'h_cust_pkg'      => $pkg_labelsub,
183   'h_svc_acct'      => $svc_labelsub,
184   #'h_radius_usergroup' =>
185   'h_svc_domain'    => $svc_labelsub,
186   'h_svc_www'       => $svc_labelsub,
187   'h_svc_forward'   => $svc_labelsub,
188   'h_svc_broadband' => $svc_labelsub,
189   'h_svc_external'  => $svc_labelsub,
190   'h_svc_phone'     => $svc_labelsub,
191   #'h_phone_device'
192 );
193
194 my $cust_pkg_date_format = '%b %o, %Y';
195 $cust_pkg_date_format .= ' %l:%M:%S%P'
196   if $conf->exists('cust_pkg-display_times')
197   || $curuser->option('cust_pkg-display_times');
198
199 </%init>