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;
48 % ## Create Description and check to see it is not empty, no need to display a record with no description, so skip it.
49 % my $description = '';
50 % if ( $item->table eq 'legacy_cust_history' ) {
51 % $description = $item->description;
52 % } elsif ( $item->table eq 'h_cust_tag' ) {
53 % $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} )
54 % if $single_cust && $h_table_descripsub{$item->table};
56 % my @fields = $item->fields;
57 % push @fields, 'message_dest' if $item->table eq 'h_contact';
58 % $description = join(', ',
59 % map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
62 % $value = time2str($cust_pkg_date_format, $value)
63 % if $item->table eq 'h_cust_pkg'
64 % && $cust_pkg_date_fields{$_}
67 % $value = substr($value, 0, 77).'...' if length($value) > 80;
68 % $value = encode_entities($value);
69 % "<I>$_</I>:<B>$value</B>";
71 % grep { $history_other
72 % ? ( $item->get($_) ne $history_other->get($_) )
73 % : ( $item->get($_) =~ /\S/ )
75 % grep { ! /^(history|custnum$)/i }
78 % if ( $single_cust && $h_table_descripsub{$item->table} ) {
79 % $description = &{ $h_table_descripsub{$item->table} }( $item );
82 % if (!$description) { next; }
86 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
88 % if ( $item->history_usernum ) {
89 % $access_user{ $item->history_usernum } ||=
90 % FS::access_user->by_key( $item->history_usernum );
91 % $otaker = $access_user{ $item->history_usernum }->username
92 % if $access_user{ $item->history_usernum };
94 % $otaker ||= $item->history_user;
95 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
96 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
97 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
98 % $otaker = '<i>system bootstrap user</i>' if $otaker eq 'fs_bootstrap';
102 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
103 % my $d = time2str('%b %o, %Y', $item->history_date );
104 % $d =~ s/ / /g;
108 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
109 % my $t = time2str('%r', $item->history_date );
110 % $t =~ s/ / /g;
114 % unless ( $single_cust ) {
115 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
116 % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum });
117 <% $cust_main ? "<A HREF='${p}view/cust_main.cgi?"
118 .$cust_main->custnum."'>".$cust_main->name.'</A>' : '' %>
122 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
124 % if ( $item->table eq 'legacy_cust_history' ) {
125 % $label = $item->item;
127 % $label = $item->table;
129 % $label = $tables{$label};
130 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
131 % if $single_cust && $h_table_labelsub{$item->table};
136 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
137 <% $action{$item->history_action} || ucfirst($item->history_action) |h %>
140 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
151 my @history = @{$opt{'history'}};
152 my %tables = %{$opt{'tables'}};
153 my $single_cust = $opt{'single_cust'};
154 my $conf = new FS::Conf;
155 my $curuser = $FS::CurrentUser::CurrentUser;
158 unless $curuser->access_right('View customer history');
161 'insert' => 'Insert', #'Create',
162 'replace_old' => "Change\xA0from",
163 'replace_new' => "Change\xA0to",
164 'delete' => 'Remove',
167 my %cust_pkg_date_fields = map { $_=>1 } qw(
168 start_date setup bill last_bill susp adjourn cancel expire contract_end
172 # finding the other replace row
174 my %replace_other = (
175 'replace_new' => 'replace_old',
176 'replace_old' => 'replace_new',
179 'replace_new' => '<',
180 'replace_old' => '>',
182 my %replace_direq = (
183 'replace_new' => '<=',
184 'replace_old' => '>=',
187 'replace_new' => '-',
188 'replace_old' => '+',
191 'replace_new' => 'DESC',
192 'replace_old' => 'ASC',
195 my $fuzz = 5; #seems like a lot
198 my $pkg_labelsub = sub {
199 my($item, $label) = @_;
200 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
201 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
204 my $svc_labelsub = sub {
205 my($item, $label) = @_;
206 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
209 my $tag_labelsub = sub {
210 my($item, $label) = @_;
211 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
212 $label. ': <SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
215 my $contact_labelsub = sub {
216 my($item, $label) = @_;
217 my $contact = qsearchs('h_contact',{ contactnum => $item->contactnum });
218 $label. ': <B>'. encode_entities($contact->first). ' ' . encode_entities($contact->last) . '</B>';
221 my %h_table_labelsub = (
222 'h_cust_pkg' => $pkg_labelsub,
223 'h_svc_acct' => $svc_labelsub,
224 #'h_radius_usergroup' =>
225 'h_svc_domain' => $svc_labelsub,
226 'h_svc_www' => $svc_labelsub,
227 'h_svc_forward' => $svc_labelsub,
228 'h_svc_broadband' => $svc_labelsub,
229 'h_svc_external' => $svc_labelsub,
230 'h_svc_phone' => $svc_labelsub,
232 #'h_cust_tag' => $tag_labelsub,
233 'h_contact' => $contact_labelsub,
234 'h_cust_contact' => $contact_labelsub,
235 'h_contact_phone' => $contact_labelsub,
236 'h_contact_email' => $contact_labelsub,
239 my $tag_descripsub = sub {
240 my($item, $label) = @_;
241 my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
242 '<SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
245 my $contact_descripsub = sub {
246 my($item, $label) = @_;
247 my $phone_type = qsearchs('phone_type',{ phonetypenum => $item->phonetypenum });
248 my @fields = $item->fields;
251 my $value = ( $_ eq "phonetypenum" )
252 ? $item->get($_).' ('.$phone_type->typename.')'
254 $value = substr($value, 0, 77).'...' if length($value) > 80;
255 $value = encode_entities($value);
256 "<I>$_</I>:<B>$value</B>";
258 grep { ! /^(history|custnum$)/i }
264 my $discount_descripsub = sub {
266 $pkgpart{$item->pkgpart} ||= qsearchs({
267 'table' => 'part_pkg',
268 'hashref' => {'pkgpart' => $item->pkgpart}
270 my $dnum = $item->discountnum;
271 $discounts->{$dnum} ||= qsearchs({
273 'hashref'=>{'discountnum'=>$dnum}
275 my $d = $discounts->{$dnum};
276 '(<b>' . encode_entities($d->description_short) . '</b>'
277 . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
280 my %h_table_descripsub = (
281 'h_cust_pkg_discount' => $discount_descripsub,
282 'h_cust_tag' => $tag_descripsub,
283 'h_contact_phone' => $contact_descripsub,
286 my $cust_pkg_date_format = '%b %o, %Y';
287 $cust_pkg_date_format .= ' %l:%M:%S%P'
288 if $conf->exists('cust_pkg-display_times')
289 || $curuser->option('cust_pkg-display_times');
291 @history = sort { $a->history_date <=> $b->history_date
292 || $a->historynum <=> $b->historynum } @history;
294 if ( $curuser->option('history_order') eq 'newest' ) {
295 @history = reverse @history;
298 my %access_user = (); #cache