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;
46 % ## Create Description and check to see it is not empty, no need to display a record with no description, so skip it.
47 % my $description = '';
48 % if ( $item->table eq 'legacy_cust_history' ) {
49 % $description = $item->description;
50 % } elsif ( $item->table eq 'h_cust_tag' ) {
51 % $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} )
52 % if $single_cust && $h_table_descripsub{$item->table};
54 % $description = join(', ',
55 % map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
58 % $value = time2str($cust_pkg_date_format, $value)
59 % if $item->table eq 'h_cust_pkg'
60 % && $cust_pkg_date_fields{$_}
63 % $value = substr($value, 0, 77).'...' if length($value) > 80;
64 % $value = encode_entities($value);
65 % "<I>$_</I>:<B>$value</B>";
67 % grep { $history_other
68 % ? ( $item->get($_) ne $history_other->get($_) )
69 % : ( $item->get($_) =~ /\S/ )
71 % grep { ! /^(history|custnum$)/i }
74 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
75 % $description = &{ $h_table_descripsub{$item->table} }( $item );
78 % if (!$description) { next; }
82 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
84 % if ( $item->history_usernum ) {
85 % $access_user{ $item->history_usernum } ||=
86 % FS::access_user->by_key( $item->history_usernum );
87 % $otaker = $access_user{ $item->history_usernum }->username
88 % if $access_user{ $item->history_usernum };
90 % $otaker ||= $item->history_user;
91 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
92 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
93 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
94 % $otaker = '<i>system bootstrap user</i>' if $otaker eq 'fs_bootstrap';
98 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
99 % my $d = time2str('%b %o, %Y', $item->history_date );
100 % $d =~ s/ / /g;
104 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
105 % my $t = time2str('%r', $item->history_date );
106 % $t =~ s/ / /g;
110 % unless ( $single_cust ) {
111 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
112 % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
113 <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
114 .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
118 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
120 % if ( $item->table eq 'legacy_cust_history' ) {
121 % $label = $item->item;
123 % $label = $item->table;
125 % $label = $tables{$label};
126 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
127 % if $single_cust && $h_table_labelsub{$item->table};
132 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
133 <% $action{$item->history_action} || ucfirst($item->history_action) |h %>
136 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
147 my @history = @{$opt{'history'}};
148 my %tables = %{$opt{'tables'}};
149 my $single_cust = $opt{'single_cust'};
150 my $conf = new FS::Conf;
151 my $curuser = $FS::CurrentUser::CurrentUser;
154 unless $curuser->access_right('View customer history');
157 'insert' => 'Insert', #'Create',
158 'replace_old' => "Change\xA0from",
159 'replace_new' => "Change\xA0to",
160 'delete' => 'Remove',
163 my %cust_pkg_date_fields = map { $_=>1 } qw(
164 start_date setup bill last_bill susp adjourn cancel expire contract_end
168 # finding the other replace row
170 my %replace_other = (
171 'replace_new' => 'replace_old',
172 'replace_old' => 'replace_new',
175 'replace_new' => '<',
176 'replace_old' => '>',
178 my %replace_direq = (
179 'replace_new' => '<=',
180 'replace_old' => '>=',
183 'replace_new' => '-',
184 'replace_old' => '+',
187 'replace_new' => 'DESC',
188 'replace_old' => 'ASC',
191 my $fuzz = 5; #seems like a lot
194 my $pkg_labelsub = sub {
195 my($item, $label) = @_;
196 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
197 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
200 my $svc_labelsub = sub {
201 my($item, $label) = @_;
202 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
205 my $tag_labelsub = sub {
206 my($item, $label) = @_;
207 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
208 $label. ': <SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
211 my %h_table_labelsub = (
212 'h_cust_pkg' => $pkg_labelsub,
213 'h_svc_acct' => $svc_labelsub,
214 #'h_radius_usergroup' =>
215 'h_svc_domain' => $svc_labelsub,
216 'h_svc_www' => $svc_labelsub,
217 'h_svc_forward' => $svc_labelsub,
218 'h_svc_broadband' => $svc_labelsub,
219 'h_svc_external' => $svc_labelsub,
220 'h_svc_phone' => $svc_labelsub,
222 #'h_cust_tag' => $tag_labelsub,
225 my $tag_descripsub = sub {
226 my($item, $label) = @_;
227 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
228 '<SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
232 my $discount_descripsub = sub {
234 $pkgpart{$item->pkgpart} ||= qsearchs({
235 'table' => 'part_pkg',
236 'hashref' => {'pkgpart' => $item->pkgpart}
238 my $dnum = $item->discountnum;
239 $discounts->{$dnum} ||= qsearchs({
241 'hashref'=>{'discountnum'=>$dnum}
243 my $d = $discounts->{$dnum};
244 '(<b>' . encode_entities($d->description_short) . '</b>'
245 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
248 my %h_table_descripsub = (
249 'h_cust_pkg_discount' => $discount_descripsub,
250 'h_cust_tag' => $tag_descripsub,
253 my $cust_pkg_date_format = '%b %o, %Y';
254 $cust_pkg_date_format .= ' %l:%M:%S%P'
255 if $conf->exists('cust_pkg-display_times')
256 || $curuser->option('cust_pkg-display_times');
258 @history = sort { $a->history_date <=> $b->history_date
259 || $a->historynum <=> $b->historynum } @history;
261 if ( $curuser->option('history_order') eq 'newest' ) {
262 @history = reverse @history;
265 my %access_user = (); #cache