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 = time2str($cust_pkg_date_format, $value)
98 if $item->table eq 'h_cust_pkg'
99 && $cust_pkg_date_fields{$_}
102 $value = substr($value, 0, 77).'...' if length($value) > 80;
103 $value = encode_entities($value);
104 "<I>$_</I>:<B>$value</B>";
106 grep { $history_other
107 ? ( $item->get($_) ne $history_other->get($_) )
108 : ( $item->get($_) =~ /\S/ )
110 grep { ! /^(history|custnum$)/i }
124 tie my %years, 'Tie::IxHash',
132 # labeling history rows
135 'insert' => 'Insert', #'Create',
136 'replace_old' => 'Change from',
137 'replace_new' => 'Change to',
138 'delete' => 'Remove',
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
166 # which tables to search and what to call them
168 tie my %tables, 'Tie::IxHash',
169 'cust_main' => 'Customer',
170 'cust_main_invoice' => 'Invoice destination',
171 'cust_pkg' => 'Package',
172 #? or just svc_* ? 'cust_svc' =>
173 'svc_acct' => 'Account',
174 'radius_usergroup' => 'RADIUS group',
175 'svc_domain' => 'Domain',
176 'svc_www' => 'Hosting',
177 'svc_forward' => 'Mail forward',
178 'svc_broadband' => 'Broadband',
179 'svc_external' => 'External service',
180 'svc_phone' => 'Phone',
181 'phone_device' => 'Phone device',
182 #? it gets provisioned anyway 'phone_avail' => 'Phone',
185 my $svc_join = 'JOIN cust_svc USING ( svcnum ) JOIN cust_pkg USING ( pkgnum )';
188 'svc_acct' => $svc_join,
189 'radius_usergroup' => $svc_join,
190 'svc_domain' => $svc_join,
191 'svc_www' => $svc_join,
192 'svc_forward' => $svc_join,
193 'svc_broadband' => $svc_join,
194 'svc_external' => $svc_join,
195 'svc_phone' => $svc_join,
196 'phone_device' => $svc_join,
199 my %h_tables = map { ( "h_$_" => $tables{$_} ) } keys %tables;
202 my $pkg_labelsub = sub {
203 my($item, $label) = @_;
204 $pkgpart{$item->pkgpart} ||= $item->part_pkg->pkg;
205 $label. ': <b>'. encode_entities($pkgpart{$item->pkgpart}). '</b>';
208 my $svc_labelsub = sub {
209 my($item, $label) = @_;
210 $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
213 my %h_table_labelsub = (
214 'h_cust_pkg' => $pkg_labelsub,
215 'h_svc_acct' => $svc_labelsub,
216 #'h_radius_usergroup' =>
217 'h_svc_domain' => $svc_labelsub,
218 'h_svc_www' => $svc_labelsub,
219 'h_svc_forward' => $svc_labelsub,
220 'h_svc_broadband' => $svc_labelsub,
221 'h_svc_external' => $svc_labelsub,
222 'h_svc_phone' => $svc_labelsub,
232 # cust_pkg_reason? no
239 # acct_snarf? is this even used? it is now, for communigate RPOP
246 # (virtual fields? eh... maybe when they're real)
254 # inventory_item (from services)
255 # pkg_referral? (changed?)
260 # cust_main-exemption?? (295.ca named tax exemptions)
265 my( $cust_main ) = @_;
267 my $conf = new FS::Conf;
269 my $curuser = $FS::CurrentUser::CurrentUser;
272 unless $curuser->access_right('View customer history');
274 my $cust_pkg_date_format = '%b %o, %Y';
275 $cust_pkg_date_format .= ' %l:%M:%S%P'
276 if $conf->exists('cust_pkg-display_times')
277 || $curuser->option('cust_pkg-display_times');
279 my %cust_pkg_date_fields = map { $_=>1 } qw(
280 start_date setup bill last_bill susp adjourn cancel expire contract_end
284 # find out the beginning of this customer history, if possible
285 my $h_insert = qsearchs({
286 'table' => 'h_cust_main',
287 'hashref' => { 'custnum' => $cust_main->custnum,
288 'history_action' => 'insert',
290 'extra_sql' => 'ORDER BY historynum LIMIT 1',
292 my $start = $h_insert ? $h_insert->history_date : 0;
294 # retreive the history
298 my $years = $conf->config('change_history-years') || .5;
299 if ( $cgi->param('change_history-years') =~ /^([\d\.]+)$/ ) {
302 my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24
304 local($FS::Record::nowarn_classload) = 1;
306 foreach my $table ( keys %tables ) {
307 my @items = qsearch({
308 'table' => "h_$table",
309 'addl_from' => $table_join{$table},
310 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than }, },
311 'extra_sql' => ' AND custnum = '. $cust_main->custnum,
313 push @history, @items;