1 % if ( int( time - (keys %years)[0] * 31556736 ) > $start ) {
3 % my $chy = $cgi->param('change_history-years');
4 % foreach my $y (keys %years) {
5 % if ( $y == $years ) {
6 <FONT SIZE="+1"><% $years{$y} %></FONT>
8 % $cgi->param('change_history-years', $y);
9 <A HREF="<% $cgi->self_url %>"><% $years{$y} %></A>
11 % last if int( time - $y * 31556736 ) < $start;
13 % $cgi->param('change_history-years', $chy);
16 <% include("/elements/table-grid.html") %>
17 % my $bgcolor1 = '#eeeeee';
18 % my $bgcolor2 = '#ffffff';
22 <TH CLASS="grid" BGCOLOR="#cccccc">User</TH>
23 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
24 <TH CLASS="grid" BGCOLOR="#cccccc">Time</TH>
25 <TH CLASS="grid" BGCOLOR="#cccccc">Item</TH>
26 <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
27 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
30 % foreach my $item ( sort { $a->history_date <=> $b->history_date
32 % || $a->historynum <=> $b->historynum
38 % my $history_other = '';
39 % my $act = $item->history_action;
40 % if ( $act =~ /^replace/ ) {
41 % my $pkey = $item->primary_key;
42 % my $date = $item->history_date;
43 % $history_other = qsearchs({
44 % 'table' => $item->table,
45 % 'hashref' => { $pkey => $item->$pkey(),
46 % 'history_action' => $replace_other{$act},
47 % 'historynum' => { 'op' => $replace_dir{$act},
48 % 'value' => $item->historynum
52 % AND history_date $replace_direq{$act} $date
53 % AND ($date $replace_op{$act} $fuzz) $replace_direq{$act} history_date
54 % ORDER BY historynum $replace_ord{$act} LIMIT 1
59 % if ( $bgcolor eq $bgcolor1 ) {
60 % $bgcolor = $bgcolor2;
62 % $bgcolor = $bgcolor1;
66 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
67 % my $otaker = $item->history_user;
68 % $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
69 % $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
70 % $otaker = '<i>job queue</i>' if $otaker eq 'fs_queue';
73 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
74 % my $d = time2str('%b %o, %Y', $item->history_date );
78 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
79 % my $t = time2str('%r', $item->history_date );
83 <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
84 % my $label = $h_tables{$item->table};
85 % $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
86 % if $h_table_labelsub{$item->table};
89 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
90 <% $action{$item->history_action} %>
92 <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
94 map { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ )
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 }
119 tie my %years, 'Tie::IxHash',
127 # labeling history rows
130 'insert' => 'Insert', #'Create',
131 'replace_old' => 'Change from',
132 'replace_new' => 'Change to',
133 'delete' => 'Remove',
136 # finding the other replace row
138 my %replace_other = (
139 'replace_new' => 'replace_old',
140 'replace_old' => 'replace_new',
143 'replace_new' => '<',
144 'replace_old' => '>',
146 my %replace_direq = (
147 'replace_new' => '<=',
148 'replace_old' => '>=',
151 'replace_new' => '-',
152 'replace_old' => '+',
155 'replace_new' => 'DESC',
156 'replace_old' => 'ASC',
159 my $fuzz = 5; #seems like a lot
161 # which tables to search and what to call them
163 tie my %tables, 'Tie::IxHash',
164 'cust_main' => 'Customer',
165 'cust_main_invoice' => 'Invoice destination',
166 'cust_pkg' => 'Package',
167 #? or just svc_* ? 'cust_svc' =>
168 'svc_acct' => 'Account',
169 'radius_usergroup' => 'RADIUS group',
170 'svc_domain' => 'Domain',
171 'svc_www' => 'Hosting',
172 'svc_forward' => 'Mail forward',
173 'svc_broadband' => 'Broadband',
174 'svc_external' => 'External service',
175 'svc_phone' => 'Phone',
176 'phone_device' => 'Phone device',
177 #? it gets provisioned anyway 'phone_avail' => 'Phone',
180 my $svc_join = 'JOIN cust_svc USING ( svcnum ) JOIN cust_pkg USING ( pkgnum )';
183 'svc_acct' => $svc_join,
184 'radius_usergroup' => $svc_join,
185 'svc_domain' => $svc_join,
186 'svc_www' => $svc_join,
187 'svc_forward' => $svc_join,
188 'svc_broadband' => $svc_join,
189 'svc_external' => $svc_join,
190 'svc_phone' => $svc_join,
191 'phone_device' => $svc_join,
194 my %h_tables = map { ( "h_$_" => $tables{$_} ) } keys %tables;
197 my $pkg_labelsub = sub {
198 my($item, $label) = @_;
199 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
200 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
203 my $svc_labelsub = sub {
204 my($item, $label) = @_;
205 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
208 my %h_table_labelsub = (
209 'h_cust_pkg' => $pkg_labelsub,
210 'h_svc_acct' => $svc_labelsub,
211 #'h_radius_usergroup' =>
212 'h_svc_domain' => $svc_labelsub,
213 'h_svc_www' => $svc_labelsub,
214 'h_svc_forward' => $svc_labelsub,
215 'h_svc_broadband' => $svc_labelsub,
216 'h_svc_external' => $svc_labelsub,
217 'h_svc_phone' => $svc_labelsub,
227 # cust_pkg_reason? no
234 # acct_snarf? is this even used?
241 # (virtual fields? eh... maybe when they're real)
249 # inventory_item (from services)
250 # pkg_referral? (changed?)
255 # cust_main-exemption?? (295.ca named tax exemptions)
260 my( $cust_main ) = @_;
262 my $conf = new FS::Conf;
264 my $curuser = $FS::CurrentUser::CurrentUser;
267 unless $curuser->access_right('View customer history');
269 # find out the beginning of this customer history, if possible
270 my $h_insert = qsearchs({
271 'table' => 'h_cust_main',
272 'hashref' => { 'custnum' => $cust_main->custnum,
273 'history_action' => 'insert',
275 'extra_sql' => 'ORDER BY historynum LIMIT 1',
277 my $start = $h_insert ? $h_insert->history_date : 0;
279 # retreive the history
283 my $years = $conf->config('change_history-years') || .5;
284 if ( $cgi->param('change_history-years') =~ /^([\d\.]+)$/ ) {
287 my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24
289 local($FS::Record::nowarn_classload) = 1;
291 foreach my $table ( keys %tables ) {
292 my @items = qsearch({
293 'table' => "h_$table",
294 'addl_from' => $table_join{$table},
295 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than }, },
296 'extra_sql' => ' AND custnum = '. $cust_main->custnum,
298 push @history, @items;