<% include("/elements/table-grid.html") %> % my $bgcolor1 = '#eeeeee'; % my $bgcolor2 = '#ffffff'; % my $bgcolor = ''; User Date Time <% $single_cust ? '' : 'Customer' %> Item Action Description % foreach my $item ( @history ) { % my $history_other = ''; % my $act = $item->history_action; % if ( $act =~ /^replace/ && $item->table ne 'legacy_cust_history' ) { % my $pkey = $item->primary_key; % my $date = $item->history_date; % $history_other = qsearchs({ % 'table' => $item->table, % 'hashref' => { $pkey => $item->$pkey(), % 'history_action' => $replace_other{$act}, % 'historynum' => { 'op' => $replace_dir{$act}, % 'value' => $item->historynum % }, % }, % 'extra_sql' => " % AND history_date $replace_direq{$act} $date % AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date % ORDER BY historynum $replace_ord{$act} LIMIT 1 % ", % }); % } % % if ( $bgcolor eq $bgcolor1 ) { % $bgcolor = $bgcolor2; % } else { % $bgcolor = $bgcolor1; % } % % ## Create Description and check to see it is not empty, no need to display a record with no description, so skip it. % my $description = ''; % if ( $item->table eq 'legacy_cust_history' ) { % $description = $item->description; % } elsif ( $item->table eq 'h_cust_tag' ) { % $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} ) % if $single_cust && $h_table_descripsub{$item->table}; % } else { % my @fields = $item->fields; % push @fields, 'message_dest' if $item->table eq 'h_contact'; % $description = join(', ', % map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ ) % ? 'N/A' % : $item->get($_); % $value = time2str($cust_pkg_date_format, $value) % if $item->table eq 'h_cust_pkg' % && $cust_pkg_date_fields{$_} % && $value; % % $value = substr($value, 0, 77).'...' if length($value) > 80; % $value = encode_entities($value); % "$_:$value"; % } % grep { $history_other % ? ( $item->get($_) ne $history_other->get($_) ) % : ( $item->get($_) =~ /\S/ ) % } % grep { ! /^(history|custnum$)/i } % @fields % ); % if ( $single_cust && $h_table_descripsub{$item->table} ) { % $description = &{ $h_table_descripsub{$item->table} }( $item ); % } % } #else % if (!$description) { next; } % my $otaker = ''; % if ( $item->history_usernum ) { % $access_user{ $item->history_usernum } ||= % FS::access_user->by_key( $item->history_usernum ); % $otaker = $access_user{ $item->history_usernum }->username % if $access_user{ $item->history_usernum }; % } % $otaker ||= $item->history_user; % $otaker = 'auto billing' if $otaker eq 'fs_daily'; % $otaker = 'customer self-service' if $otaker eq 'fs_selfservice'; % $otaker = 'job queue' if $otaker eq 'fs_queue'; % $otaker = 'system bootstrap user' if $otaker eq 'fs_bootstrap'; <% $otaker %> % my $d = time2str('%b %o, %Y', $item->history_date ); % $d =~ s/ / /g; <% $d %> % my $t = time2str('%r', $item->history_date ); % $t =~ s/ / /g; <% $t %> % unless ( $single_cust ) { % my $cust_main = qsearchs('cust_main', { custnum => $item->custnum }); <% $cust_main ? "".$cust_main->name.'' : '' %> % } % my $label = ''; % if ( $item->table eq 'legacy_cust_history' ) { % $label = $item->item; % } else { % $label = $item->table; % $label =~ s/^h_//; % $label = $tables{$label}; % $label = &{ $h_table_labelsub{$item->table} }( $item, $label ) % if $single_cust && $h_table_labelsub{$item->table}; % } <% $label %> <% $action{$item->history_action} || ucfirst($item->history_action) |h %> <% $description %> % } <%init> my %opt = @_; my @history = @{$opt{'history'}}; my %tables = %{$opt{'tables'}}; my $single_cust = $opt{'single_cust'}; my $conf = new FS::Conf; my $curuser = $FS::CurrentUser::CurrentUser; die "access deined" unless $curuser->access_right('View customer history'); my %action = ( 'insert' => 'Insert', #'Create', 'replace_old' => "Change\xA0from", 'replace_new' => "Change\xA0to", 'delete' => 'Remove', ); my %cust_pkg_date_fields = map { $_=>1 } qw( start_date setup bill last_bill susp adjourn cancel expire contract_end resume change_date ); # finding the other replace row my %replace_other = ( 'replace_new' => 'replace_old', 'replace_old' => 'replace_new', ); my %replace_dir = ( 'replace_new' => '<', 'replace_old' => '>', ); my %replace_direq = ( 'replace_new' => '<=', 'replace_old' => '>=', ); my %replace_op = ( 'replace_new' => '-', 'replace_old' => '+', ); my %replace_ord = ( 'replace_new' => 'DESC', 'replace_old' => 'ASC', ); my $fuzz = 5; #seems like a lot my %pkgpart = (); my $pkg_labelsub = sub { my($item, $label) = @_; $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg; $label. ': '. encode_entities($pkgpart{$item->pkgpart}). ''; }; my $svc_labelsub = sub { my($item, $label) = @_; $label. ': '. encode_entities($item->label($item->history_date)). ''; }; my $tag_labelsub = sub { my($item, $label) = @_; my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum }); $label. ': '. encode_entities($part_tag->tagname). ''; }; my $contact_labelsub = sub { my($item, $label) = @_; my $contact = qsearchs('h_contact',{ contactnum => $item->contactnum }); $label. ': '. encode_entities($contact->first). ' ' . encode_entities($contact->last) . ''; }; my %h_table_labelsub = ( 'h_cust_pkg' => $pkg_labelsub, 'h_svc_acct' => $svc_labelsub, #'h_radius_usergroup' => 'h_svc_domain' => $svc_labelsub, 'h_svc_www' => $svc_labelsub, 'h_svc_forward' => $svc_labelsub, 'h_svc_broadband' => $svc_labelsub, 'h_svc_external' => $svc_labelsub, 'h_svc_phone' => $svc_labelsub, #'h_phone_device' #'h_cust_tag' => $tag_labelsub, 'h_contact' => $contact_labelsub, 'h_cust_contact' => $contact_labelsub, ); my $tag_descripsub = sub { my($item, $label) = @_; my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum }); ''. encode_entities($part_tag->tagname). ''; }; my $discounts = {}; my $discount_descripsub = sub { my($item) = @_; $pkgpart{$item->pkgpart} ||= qsearchs({ 'table' => 'part_pkg', 'hashref' => {'pkgpart' => $item->pkgpart} })->pkg; my $dnum = $item->discountnum; $discounts->{$dnum} ||= qsearchs({ 'table'=>'discount', 'hashref'=>{'discountnum'=>$dnum} }); my $d = $discounts->{$dnum}; '(' . encode_entities($d->description_short) . '' . ' on ' . encode_entities($pkgpart{$item->pkgpart}) . ')'; }; my %h_table_descripsub = ( 'h_cust_pkg_discount' => $discount_descripsub, 'h_cust_tag' => $tag_descripsub, ); my $cust_pkg_date_format = '%b %o, %Y'; $cust_pkg_date_format .= ' %l:%M:%S%P' if $conf->exists('cust_pkg-display_times') || $curuser->option('cust_pkg-display_times'); @history = sort { $a->history_date <=> $b->history_date || $a->historynum <=> $b->historynum } @history; if ( $curuser->option('history_order') eq 'newest' ) { @history = reverse @history; } my %access_user = (); #cache