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;
50 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
52 % if ( $item->history_usernum ) {
53 % $access_user{ $item->history_usernum } ||=
54 % FS::access_user->by_key( $item->history_usernum );
55 % $otaker = $access_user{ $item->history_usernum }->username
56 % if $access_user{ $item->history_usernum };
58 % $otaker ||= $item->history_user;
59 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
60 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
61 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
62 % $otaker = '<i>system bootstrap user</i>' if $otaker eq 'fs_bootstrap';
66 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
67 % my $d = time2str('%b %o, %Y', $item->history_date );
72 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
73 % my $t = time2str('%r', $item->history_date );
78 % unless ( $single_cust ) {
79 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
80 % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
81 <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
82 .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
86 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
88 % if ( $item->table eq 'legacy_cust_history' ) {
89 % $label = $item->item;
91 % $label = $item->table;
93 % $label = $tables{$label};
94 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
95 % if $single_cust && $h_table_labelsub{$item->table};
100 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
101 <% $action{$item->history_action} || ucfirst($item->history_action) |h %>
104 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
105 % if ( $item->table eq 'legacy_cust_history' ) {
106 <% $item->description |h %>
109 map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
112 $value = time2str($cust_pkg_date_format, $value)
113 if $item->table eq 'h_cust_pkg'
114 && $cust_pkg_date_fields{$_}
117 $value = substr($value, 0, 77).'...' if length($value) > 80;
118 $value = encode_entities($value);
119 "<I>$_</I>:<B>$value</B>";
121 grep { $history_other
122 ? ( $item->get($_) ne $history_other->get($_) )
123 : ( $item->get($_) =~ /\S/ )
125 grep { ! /^(history|custnum$)/i }
129 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
130 <% &{ $h_table_descripsub{$item->table} }( $item ) %>
142 my @history = @{$opt{'history'}};
143 my %tables = %{$opt{'tables'}};
144 my $single_cust = $opt{'single_cust'};
145 my $conf = new FS::Conf;
146 my $curuser = $FS::CurrentUser::CurrentUser;
149 unless $curuser->access_right('View customer history');
152 'insert' => 'Insert', #'Create',
153 'replace_old' => "Change\xA0from",
154 'replace_new' => "Change\xA0to",
155 'delete' => 'Remove',
158 my %cust_pkg_date_fields = map { $_=>1 } qw(
159 start_date setup bill last_bill susp adjourn cancel expire contract_end
163 # finding the other replace row
165 my %replace_other = (
166 'replace_new' => 'replace_old',
167 'replace_old' => 'replace_new',
170 'replace_new' => '<',
171 'replace_old' => '>',
173 my %replace_direq = (
174 'replace_new' => '<=',
175 'replace_old' => '>=',
178 'replace_new' => '-',
179 'replace_old' => '+',
182 'replace_new' => 'DESC',
183 'replace_old' => 'ASC',
186 my $fuzz = 5; #seems like a lot
189 my $pkg_labelsub = sub {
190 my($item, $label) = @_;
191 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
192 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
195 my $svc_labelsub = sub {
196 my($item, $label) = @_;
197 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
200 my %h_table_labelsub = (
201 'h_cust_pkg' => $pkg_labelsub,
202 'h_svc_acct' => $svc_labelsub,
203 #'h_radius_usergroup' =>
204 'h_svc_domain' => $svc_labelsub,
205 'h_svc_www' => $svc_labelsub,
206 'h_svc_forward' => $svc_labelsub,
207 'h_svc_broadband' => $svc_labelsub,
208 'h_svc_external' => $svc_labelsub,
209 'h_svc_phone' => $svc_labelsub,
214 my $discount_descripsub = sub {
216 $pkgpart{$item->pkgpart} ||= qsearchs({
217 'table' => 'part_pkg',
218 'hashref' => {'pkgpart' => $item->pkgpart}
220 my $dnum = $item->discountnum;
221 $discounts->{$dnum} ||= qsearchs({
223 'hashref'=>{'discountnum'=>$dnum}
225 my $d = $discounts->{$dnum};
226 '(<b>' . encode_entities($d->description_short) . '</b>'
227 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
230 my %h_table_descripsub = (
231 'h_cust_pkg_discount' => $discount_descripsub,
234 my $cust_pkg_date_format = '%b %o, %Y';
235 $cust_pkg_date_format .= ' %l:%M:%S%P'
236 if $conf->exists('cust_pkg-display_times')
237 || $curuser->option('cust_pkg-display_times');
239 @history = sort { $a->history_date <=> $b->history_date
240 || $a->historynum <=> $b->historynum } @history;
242 if ( $curuser->option('history_order') eq 'newest' ) {
243 @history = reverse @history;
246 my %access_user = (); #cache