1 <% include("/elements/table-grid.html") %>
2 % my $bgcolor1 = '#eeeeee';
3 % my $bgcolor2 = '#ffffff';
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>'
13 <TH CLASS="grid" BGCOLOR="#cccccc">Item</TH>
14 <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
15 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
18 % foreach my $item ( @history ) {
19 % my $history_other = '';
20 % my $act = $item->history_action;
21 % if ( $act =~ /^replace/ && $item->table ne 'legacy_cust_history' ) {
22 % my $pkey = $item->primary_key;
23 % my $date = $item->history_date;
24 % $history_other = qsearchs({
25 % 'table' => $item->table,
26 % 'hashref' => { $pkey => $item->$pkey(),
27 % 'history_action' => $replace_other{$act},
28 % 'historynum' => { 'op' => $replace_dir{$act},
29 % 'value' => $item->historynum
33 % AND history_date $replace_direq{$act} $date
34 % AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date
35 % ORDER BY historynum $replace_ord{$act} LIMIT 1
40 % if ( $bgcolor eq $bgcolor1 ) {
41 % $bgcolor = $bgcolor2;
43 % $bgcolor = $bgcolor1;
48 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
50 % if ( $item->history_usernum ) {
51 % $access_user{ $item->history_usernum } ||=
52 % FS::access_user->by_key( $item->history_usernum );
53 % $otaker = $access_user{ $item->history_usernum }->username
54 % if $access_user{ $item->history_usernum };
56 % $otaker ||= $item->history_user;
57 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
58 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
59 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
60 % $otaker = '<i>system bootstrap user</i>' if $otaker eq 'fs_bootstrap';
64 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
65 % my $d = time2str('%b %o, %Y', $item->history_date );
70 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
71 % my $t = time2str('%r', $item->history_date );
76 % unless ( $single_cust ) {
77 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
78 % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
79 <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
80 .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
84 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
86 % if ( $item->table eq 'legacy_cust_history' ) {
87 % $label = $item->item;
89 % $label = $item->table;
91 % $label = $tables{$label};
92 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
93 % if $single_cust && $h_table_labelsub{$item->table};
98 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
99 <% $action{$item->history_action} || ucfirst($item->history_action) |h %>
102 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
103 % my $description = '';
104 % if ( $item->table eq 'legacy_cust_history' ) {
105 <% $item->description |h %>
106 % } elsif ( $item->table eq 'h_cust_tag' ) {
107 % $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} )
108 % if $single_cust && $h_table_descripsub{$item->table};
112 map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
115 $value = time2str($cust_pkg_date_format, $value)
116 if $item->table eq 'h_cust_pkg'
117 && $cust_pkg_date_fields{$_}
120 $value = substr($value, 0, 77).'...' if length($value) > 80;
121 $value = encode_entities($value);
122 "<I>$_</I>:<B>$value</B>";
124 grep { $history_other
125 ? ( $item->get($_) ne $history_other->get($_) )
126 : ( $item->get($_) =~ /\S/ )
128 grep { ! /^(history|custnum$)/i }
132 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
133 <% &{ $h_table_descripsub{$item->table} }( $item ) %>
145 my @history = @{$opt{'history'}};
146 my %tables = %{$opt{'tables'}};
147 my $single_cust = $opt{'single_cust'};
148 my $conf = new FS::Conf;
149 my $curuser = $FS::CurrentUser::CurrentUser;
152 unless $curuser->access_right('View customer history');
155 'insert' => 'Insert', #'Create',
156 'replace_old' => "Change\xA0from",
157 'replace_new' => "Change\xA0to",
158 'delete' => 'Remove',
161 my %cust_pkg_date_fields = map { $_=>1 } qw(
162 start_date setup bill last_bill susp adjourn cancel expire contract_end
166 # finding the other replace row
168 my %replace_other = (
169 'replace_new' => 'replace_old',
170 'replace_old' => 'replace_new',
173 'replace_new' => '<',
174 'replace_old' => '>',
176 my %replace_direq = (
177 'replace_new' => '<=',
178 'replace_old' => '>=',
181 'replace_new' => '-',
182 'replace_old' => '+',
185 'replace_new' => 'DESC',
186 'replace_old' => 'ASC',
189 my $fuzz = 5; #seems like a lot
192 my $pkg_labelsub = sub {
193 my($item, $label) = @_;
194 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
195 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
198 my $svc_labelsub = sub {
199 my($item, $label) = @_;
200 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
203 my $tag_labelsub = sub {
204 my($item, $label) = @_;
205 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
206 $label. ': <SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
209 my %h_table_labelsub = (
210 'h_cust_pkg' => $pkg_labelsub,
211 'h_svc_acct' => $svc_labelsub,
212 #'h_radius_usergroup' =>
213 'h_svc_domain' => $svc_labelsub,
214 'h_svc_www' => $svc_labelsub,
215 'h_svc_forward' => $svc_labelsub,
216 'h_svc_broadband' => $svc_labelsub,
217 'h_svc_external' => $svc_labelsub,
218 'h_svc_phone' => $svc_labelsub,
220 #'h_cust_tag' => $tag_labelsub,
223 my $tag_descripsub = sub {
224 my($item, $label) = @_;
225 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
226 '<SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
230 my $discount_descripsub = sub {
232 $pkgpart{$item->pkgpart} ||= qsearchs({
233 'table' => 'part_pkg',
234 'hashref' => {'pkgpart' => $item->pkgpart}
236 my $dnum = $item->discountnum;
237 $discounts->{$dnum} ||= qsearchs({
239 'hashref'=>{'discountnum'=>$dnum}
241 my $d = $discounts->{$dnum};
242 '(<b>' . encode_entities($d->description_short) . '</b>'
243 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
246 my %h_table_descripsub = (
247 'h_cust_pkg_discount' => $discount_descripsub,
248 'h_cust_tag' => $tag_descripsub,
251 my $cust_pkg_date_format = '%b %o, %Y';
252 $cust_pkg_date_format .= ' %l:%M:%S%P'
253 if $conf->exists('cust_pkg-display_times')
254 || $curuser->option('cust_pkg-display_times');
256 @history = sort { $a->history_date <=> $b->history_date
257 || $a->historynum <=> $b->historynum } @history;
259 if ( $curuser->option('history_order') eq 'newest' ) {
260 @history = reverse @history;
263 my %access_user = (); #cache