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/ ) {
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;
47 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
48 % my $otaker = $item->history_user;
49 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
50 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
51 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
54 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
55 % my $d = time2str('%b %o, %Y', $item->history_date );
59 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
60 % my $t = time2str('%r', $item->history_date );
65 % unless ( $single_cust ) {
66 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
67 % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
68 <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
69 .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
73 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
75 % $label = $item->table;
77 % $label = $tables{$label};
78 % if ( $single_cust ) {
79 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
80 % if $h_table_labelsub{$item->table};
84 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
85 <% $action{$item->history_action} %>
87 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
89 map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
92 $value = time2str($cust_pkg_date_format, $value)
93 if $item->table eq 'h_cust_pkg'
94 && $cust_pkg_date_fields{$_}
97 $value = substr($value, 0, 77).'...' if length($value) > 80;
98 $value = encode_entities($value);
99 "<I>$_</I>:<B>$value</B>";
101 grep { $history_other
102 ? ( $item->get($_) ne $history_other->get($_) )
103 : ( $item->get($_) =~ /\S/ )
105 grep { ! /^(history|custnum$)/i }
109 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
110 <% &{ $h_table_descripsub{$item->table} }( $item ) %>
120 my @history = @{$opt{'history'}};
121 my %tables = %{$opt{'tables'}};
122 my $single_cust = $opt{'single_cust'};
123 my $conf = new FS::Conf;
124 my $curuser = $FS::CurrentUser::CurrentUser;
127 unless $curuser->access_right('View customer history');
130 'insert' => 'Insert', #'Create',
131 'replace_old' => 'Change from',
132 'replace_new' => 'Change to',
133 'delete' => 'Remove',
136 my %cust_pkg_date_fields = map { $_=>1 } qw(
137 start_date setup bill last_bill susp adjourn cancel expire contract_end
141 # finding the other replace row
143 my %replace_other = (
144 'replace_new' => 'replace_old',
145 'replace_old' => 'replace_new',
148 'replace_new' => '<',
149 'replace_old' => '>',
151 my %replace_direq = (
152 'replace_new' => '<=',
153 'replace_old' => '>=',
156 'replace_new' => '-',
157 'replace_old' => '+',
160 'replace_new' => 'DESC',
161 'replace_old' => 'ASC',
164 my $fuzz = 5; #seems like a lot
167 my $pkg_labelsub = sub {
168 my($item, $label) = @_;
169 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
170 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
173 my $svc_labelsub = sub {
174 my($item, $label) = @_;
175 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
178 my %h_table_labelsub = (
179 'h_cust_pkg' => $pkg_labelsub,
180 'h_svc_acct' => $svc_labelsub,
181 #'h_radius_usergroup' =>
182 'h_svc_domain' => $svc_labelsub,
183 'h_svc_www' => $svc_labelsub,
184 'h_svc_forward' => $svc_labelsub,
185 'h_svc_broadband' => $svc_labelsub,
186 'h_svc_external' => $svc_labelsub,
187 'h_svc_phone' => $svc_labelsub,
192 my $discount_descripsub = sub {
194 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
195 my $dnum = $item->discountnum;
196 $discounts->{$dnum} ||= qsearchs({
198 'hashref'=>{'discountnum'=>$dnum}
200 my $d = $discounts->{$dnum};
201 '(<b>' . encode_entities($d->description_short) . '</b>'
202 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
205 my %h_table_descripsub = (
206 'h_cust_pkg_discount' => $discount_descripsub,
209 my $cust_pkg_date_format = '%b %o, %Y';
210 $cust_pkg_date_format .= ' %l:%M:%S%P'
211 if $conf->exists('cust_pkg-display_times')
212 || $curuser->option('cust_pkg-display_times');
214 @history = sort { $a->history_date <=> $b->history_date
215 || $a->historynum <=> $b->historynum } @history;
217 if ( $curuser->option('history_order') eq 'newest' ) {
218 @history = reverse @history;