1 <% include("/elements/table-grid.html") %>
2 % my $bgcolor1 = '#eeeeee';
3 % my $bgcolor2 = '#ffffff';
8 <TH CLASS="grid" BGCOLOR="#cccccc">User</TH>
9 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
10 <TH CLASS="grid" BGCOLOR="#cccccc">Time</TH>
11 <% $single_cust ? '' :
12 '<TH CLASS="grid" BGCOLOR="#cccccc">Customer</TH>'
14 <TH CLASS="grid" BGCOLOR="#cccccc">Item</TH>
15 <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
16 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
20 % foreach my $item ( @history ) {
21 % my $history_other = '';
22 % my $act = $item->history_action;
23 % if ( $act =~ /^replace/ && $item->table ne 'legacy_cust_history' ) {
24 % my $pkey = $item->primary_key;
25 % my $date = $item->history_date;
26 % $history_other = qsearchs({
27 % 'table' => $item->table,
28 % 'hashref' => { $pkey => $item->$pkey(),
29 % 'history_action' => $replace_other{$act},
30 % 'historynum' => { 'op' => $replace_dir{$act},
31 % 'value' => $item->historynum
35 % AND history_date $replace_direq{$act} $date
36 % AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date
37 % ORDER BY historynum $replace_ord{$act} LIMIT 1
42 % if ( $bgcolor eq $bgcolor1 ) {
43 % $bgcolor = $bgcolor2;
45 % $bgcolor = $bgcolor1;
48 % ## Create Description and check to see it is not empty, no need to display a record with no description, so skip it.
49 % my $description = '';
50 % if ( $item->table eq 'legacy_cust_history' ) {
51 % $description = $item->description;
52 % } elsif ( $item->table eq 'h_cust_tag' ) {
53 % $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} )
54 % if $single_cust && $h_table_descripsub{$item->table};
56 % $description = join(', ',
57 % map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
60 % $value = time2str($cust_pkg_date_format, $value)
61 % if $item->table eq 'h_cust_pkg'
62 % && $cust_pkg_date_fields{$_}
65 % $value = substr($value, 0, 77).'...' if length($value) > 80;
66 % $value = encode_entities($value);
67 % "<I>$_</I>:<B>$value</B>";
69 % grep { $history_other
70 % ? ( $item->get($_) ne $history_other->get($_) )
71 % : ( $item->get($_) =~ /\S/ )
73 % grep { ! /^(history|custnum$)/i }
76 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
77 % $description = &{ $h_table_descripsub{$item->table} }( $item );
80 % if (!$description) { next; }
84 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
86 % if ( $item->history_usernum ) {
87 % $access_user{ $item->history_usernum } ||=
88 % FS::access_user->by_key( $item->history_usernum );
89 % $otaker = $access_user{ $item->history_usernum }->username
90 % if $access_user{ $item->history_usernum };
92 % $otaker ||= $item->history_user;
93 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
94 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
95 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
96 % $otaker = '<i>system bootstrap user</i>' if $otaker eq 'fs_bootstrap';
100 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
101 % my $d = time2str('%b %o, %Y', $item->history_date );
102 % $d =~ s/ / /g;
106 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
107 % my $t = time2str('%r', $item->history_date );
108 % $t =~ s/ / /g;
112 % unless ( $single_cust ) {
113 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
114 % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
115 <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
116 .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
120 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
122 % if ( $item->table eq 'legacy_cust_history' ) {
123 % $label = $item->item;
125 % $label = $item->table;
127 % $label = $tables{$label};
128 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
129 % if $single_cust && $h_table_labelsub{$item->table};
134 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
135 <% $action{$item->history_action} || ucfirst($item->history_action) |h %>
138 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
149 my @history = @{$opt{'history'}};
150 my %tables = %{$opt{'tables'}};
151 my $single_cust = $opt{'single_cust'};
152 my $conf = new FS::Conf;
153 my $curuser = $FS::CurrentUser::CurrentUser;
156 unless $curuser->access_right('View customer history');
159 'insert' => 'Insert', #'Create',
160 'replace_old' => "Change\xA0from",
161 'replace_new' => "Change\xA0to",
162 'delete' => 'Remove',
165 my %cust_pkg_date_fields = map { $_=>1 } qw(
166 start_date setup bill last_bill susp adjourn cancel expire contract_end
170 # finding the other replace row
172 my %replace_other = (
173 'replace_new' => 'replace_old',
174 'replace_old' => 'replace_new',
177 'replace_new' => '<',
178 'replace_old' => '>',
180 my %replace_direq = (
181 'replace_new' => '<=',
182 'replace_old' => '>=',
185 'replace_new' => '-',
186 'replace_old' => '+',
189 'replace_new' => 'DESC',
190 'replace_old' => 'ASC',
193 my $fuzz = 5; #seems like a lot
196 my $pkg_labelsub = sub {
197 my($item, $label) = @_;
198 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
199 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
202 my $svc_labelsub = sub {
203 my($item, $label) = @_;
204 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
207 my $tag_labelsub = sub {
208 my($item, $label) = @_;
209 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
210 $label. ': <SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
213 my %h_table_labelsub = (
214 'h_cust_pkg' => $pkg_labelsub,
215 'h_svc_acct' => $svc_labelsub,
216 #'h_radius_usergroup' =>
217 'h_svc_domain' => $svc_labelsub,
218 'h_svc_www' => $svc_labelsub,
219 'h_svc_forward' => $svc_labelsub,
220 'h_svc_broadband' => $svc_labelsub,
221 'h_svc_external' => $svc_labelsub,
222 'h_svc_phone' => $svc_labelsub,
224 #'h_cust_tag' => $tag_labelsub,
227 my $tag_descripsub = sub {
228 my($item, $label) = @_;
229 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
230 '<SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
234 my $discount_descripsub = sub {
236 $pkgpart{$item->pkgpart} ||= qsearchs({
237 'table' => 'part_pkg',
238 'hashref' => {'pkgpart' => $item->pkgpart}
240 my $dnum = $item->discountnum;
241 $discounts->{$dnum} ||= qsearchs({
243 'hashref'=>{'discountnum'=>$dnum}
245 my $d = $discounts->{$dnum};
246 '(<b>' . encode_entities($d->description_short) . '</b>'
247 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
250 my %h_table_descripsub = (
251 'h_cust_pkg_discount' => $discount_descripsub,
252 'h_cust_tag' => $tag_descripsub,
255 my $cust_pkg_date_format = '%b %o, %Y';
256 $cust_pkg_date_format .= ' %l:%M:%S%P'
257 if $conf->exists('cust_pkg-display_times')
258 || $curuser->option('cust_pkg-display_times');
260 @history = sort { $a->history_date <=> $b->history_date
261 || $a->historynum <=> $b->historynum } @history;
263 if ( $curuser->option('history_order') eq 'newest' ) {
264 @history = reverse @history;
267 my %access_user = (); #cache