% if ( int( time - (keys %years)[0] * 31556736 ) > $start ) { Show: % my $chy = $cgi->param('change_history-years'); % foreach my $y (keys %years) { % if ( $y == $years ) { <% $years{$y} %> % } else { % $cgi->param('change_history-years', $y); <% $years{$y} %> % } % last if int( time - $y * 31556736 ) < $start; % } % $cgi->param('change_history-years', $chy); % } <% include("/elements/table-grid.html") %> % my $bgcolor1 = '#eeeeee'; % my $bgcolor2 = '#ffffff'; % my $bgcolor = ''; User Date Time Item Action Description % foreach my $item ( sort { $a->history_date <=> $b->history_date % #|| table order % || $a->historynum <=> $b->historynum % } % @history % ) % { % % my $history_other = ''; % my $act = $item->history_action; % if ( $act =~ /^replace/ ) { % 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; % } % my $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 %> % my $d = time2str('%b %o, %Y', $item->history_date ); % $d =~ s/ / /g; <% $d %> % my $t = time2str('%r', $item->history_date ); % $t =~ s/ / /g; <% $t %> % my $label = $h_tables{$item->table}; % $label = &{ $h_table_labelsub{$item->table} }( $item, $label ) % if $h_table_labelsub{$item->table}; <% $label %> <% $action{$item->history_action} %> <% join(', ', map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ ) ? 'N/A' : $item->get($_); $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 } $item->fields ) %> % } <%once> # length-switching tie my %years, 'Tie::IxHash', .5 => '6 months', 1 => '1 year', 2 => '2 years', 5 => '5 years', 39 => 'all history', ; # labeling history rows my %action = ( 'insert' => 'Insert', #'Create', 'replace_old' => 'Change from', 'replace_new' => 'Change to', 'delete' => 'Remove', ); # 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 # which tables to search and what to call them tie my %tables, 'Tie::IxHash', 'cust_main' => 'Customer', 'cust_main_invoice' => 'Invoice destination', 'cust_pkg' => 'Package', #? or just svc_* ? 'cust_svc' => 'svc_acct' => 'Account', 'radius_usergroup' => 'RADIUS group', 'svc_domain' => 'Domain', 'svc_www' => 'Hosting', 'svc_forward' => 'Mail forward', 'svc_broadband' => 'Broadband', 'svc_external' => 'External service', 'svc_phone' => 'Phone', 'phone_device' => 'Phone device', #? it gets provisioned anyway 'phone_avail' => 'Phone', ; my $svc_join = 'JOIN cust_svc USING ( svcnum ) JOIN cust_pkg USING ( pkgnum )'; my %table_join = ( 'svc_acct' => $svc_join, 'radius_usergroup' => $svc_join, 'svc_domain' => $svc_join, 'svc_www' => $svc_join, 'svc_forward' => $svc_join, 'svc_broadband' => $svc_join, 'svc_external' => $svc_join, 'svc_phone' => $svc_join, 'phone_device' => $svc_join, ); my %h_tables = map { ( "h_$_" => $tables{$_} ) } keys %tables; 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 %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' ); # cust_main # cust_main_invoice # cust_pkg # cust_pkg_option? # cust_pkg_detail # cust_pkg_reason? no #cust_svc #cust_svc_option? #svc_* # svc_acct # radius_usergroup # acct_snarf? is this even used? # svc_domain # domain_record # registrar # svc_forward # svc_www # svc_broadband # (virtual fields? eh... maybe when they're real) # svc_external # svc_phone # phone_device # phone_avail # future: # inventory_item (from services) # pkg_referral? (changed?) #random others: # cust_location? # cust_main-exemption?? (295.ca named tax exemptions) <%init> my( $cust_main ) = @_; my $conf = new FS::Conf; my $curuser = $FS::CurrentUser::CurrentUser; die "access deined" unless $curuser->access_right('View customer history'); # find out the beginning of this customer history, if possible my $h_insert = qsearchs({ 'table' => 'h_cust_main', 'hashref' => { 'custnum' => $cust_main->custnum, 'history_action' => 'insert', }, 'extra_sql' => 'ORDER BY historynum LIMIT 1', }); my $start = $h_insert ? $h_insert->history_date : 0; # retreive the history my @history = (); my $years = $conf->config('change_history-years') || .5; if ( $cgi->param('change_history-years') =~ /^([\d\.]+)$/ ) { $years = $1; } my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24 local($FS::Record::nowarn_classload) = 1; foreach my $table ( keys %tables ) { my @items = qsearch({ 'table' => "h_$table", 'addl_from' => $table_join{$table}, 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than }, }, 'extra_sql' => ' AND custnum = '. $cust_main->custnum, }); push @history, @items; }