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 % if ( $item->table eq 'legacy_cust_history' ) {
104 <% $item->description |h %>
107 map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
110 $value = time2str($cust_pkg_date_format, $value)
111 if $item->table eq 'h_cust_pkg'
112 && $cust_pkg_date_fields{$_}
115 $value = substr($value, 0, 77).'...' if length($value) > 80;
116 $value = encode_entities($value);
117 "<I>$_</I>:<B>$value</B>";
119 grep { $history_other
120 ? ( $item->get($_) ne $history_other->get($_) )
121 : ( $item->get($_) =~ /\S/ )
123 grep { ! /^(history|custnum$)/i }
127 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
128 <% &{ $h_table_descripsub{$item->table} }( $item ) %>
140 my @history = @{$opt{'history'}};
141 my %tables = %{$opt{'tables'}};
142 my $single_cust = $opt{'single_cust'};
143 my $conf = new FS::Conf;
144 my $curuser = $FS::CurrentUser::CurrentUser;
147 unless $curuser->access_right('View customer history');
150 'insert' => 'Insert', #'Create',
151 'replace_old' => "Change\xA0from",
152 'replace_new' => "Change\xA0to",
153 'delete' => 'Remove',
156 my %cust_pkg_date_fields = map { $_=>1 } qw(
157 start_date setup bill last_bill susp adjourn cancel expire contract_end
161 # finding the other replace row
163 my %replace_other = (
164 'replace_new' => 'replace_old',
165 'replace_old' => 'replace_new',
168 'replace_new' => '<',
169 'replace_old' => '>',
171 my %replace_direq = (
172 'replace_new' => '<=',
173 'replace_old' => '>=',
176 'replace_new' => '-',
177 'replace_old' => '+',
180 'replace_new' => 'DESC',
181 'replace_old' => 'ASC',
184 my $fuzz = 5; #seems like a lot
187 my $pkg_labelsub = sub {
188 my($item, $label) = @_;
189 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
190 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
193 my $svc_labelsub = sub {
194 my($item, $label) = @_;
195 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
198 my %h_table_labelsub = (
199 'h_cust_pkg' => $pkg_labelsub,
200 'h_svc_acct' => $svc_labelsub,
201 #'h_radius_usergroup' =>
202 'h_svc_domain' => $svc_labelsub,
203 'h_svc_www' => $svc_labelsub,
204 'h_svc_forward' => $svc_labelsub,
205 'h_svc_broadband' => $svc_labelsub,
206 'h_svc_external' => $svc_labelsub,
207 'h_svc_phone' => $svc_labelsub,
212 my $discount_descripsub = sub {
214 $pkgpart{$item->pkgpart} ||= qsearchs({
215 'table' => 'part_pkg',
216 'hashref' => {'pkgpart' => $item->pkgpart}
218 my $dnum = $item->discountnum;
219 $discounts->{$dnum} ||= qsearchs({
221 'hashref'=>{'discountnum'=>$dnum}
223 my $d = $discounts->{$dnum};
224 '(<b>' . encode_entities($d->description_short) . '</b>'
225 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
228 my %h_table_descripsub = (
229 'h_cust_pkg_discount' => $discount_descripsub,
232 my $cust_pkg_date_format = '%b %o, %Y';
233 $cust_pkg_date_format .= ' %l:%M:%S%P'
234 if $conf->exists('cust_pkg-display_times')
235 || $curuser->option('cust_pkg-display_times');
237 @history = sort { $a->history_date <=> $b->history_date
238 || $a->historynum <=> $b->historynum } @history;
240 if ( $curuser->option('history_order') eq 'newest' ) {
241 @history = reverse @history;
244 my %access_user = (); #cache