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/change_history_common.html",
17 'history' => \@history,
24 tie my %years, 'Tie::IxHash',
32 tie my %tables, 'Tie::IxHash',
33 'cust_main' => 'Customer',
34 'cust_main_invoice' => 'Invoice destination',
35 'cust_main_note' => 'Note',
36 'cust_pkg' => 'Package',
37 #? or just svc_* ? 'cust_svc' =>
38 'svc_acct' => 'Account',
39 'radius_usergroup' => 'RADIUS group',
40 'svc_domain' => 'Domain',
41 'svc_www' => 'Hosting',
42 'svc_forward' => 'Mail forward',
43 'svc_broadband' => 'Broadband',
44 'svc_external' => 'External service',
45 'svc_phone' => 'Phone',
46 'svc_cable' => 'Cable',
47 'phone_device' => 'Phone device',
48 'cust_pkg_discount' => 'Discount',
49 #? it gets provisioned anyway 'phone_avail' => 'Phone',
53 my $pkg_join = "JOIN cust_pkg USING ( pkgnum )";
54 my $svc_join = "JOIN cust_svc USING ( svcnum ) $pkg_join";
68 'radius_usergroup' => $svc_join,
69 'phone_device' => $svc_join,
70 'cust_pkg_discount'=> $pkg_join,
73 %table_join = (%table_join, map { $_ => $svc_join } @svc_tables);
89 # acct_snarf? is this even used? it is now, for communigate RPOP
96 # (virtual fields? eh... maybe when they're real)
104 # inventory_item (from services)
105 # pkg_referral? (changed?)
110 # cust_main-exemption?? (295.ca named tax exemptions)
113 my( $cust_main ) = @_;
115 my $conf = new FS::Conf;
117 my $curuser = $FS::CurrentUser::CurrentUser;
120 unless $curuser->access_right('View customer history');
122 # find out the beginning of this customer history, if possible
123 my $h_insert = qsearchs({
124 'table' => 'h_cust_main',
125 'hashref' => { 'custnum' => $cust_main->custnum,
126 'history_action' => 'insert',
128 'extra_sql' => 'ORDER BY historynum LIMIT 1',
130 my $start = $h_insert ? $h_insert->history_date : 0;
132 # retreive the history
136 my $years = $conf->config('change_history-years') || .5;
137 if ( $cgi->param('change_history-years') =~ /^([\d\.]+)$/ ) {
140 my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24
142 local($FS::Record::nowarn_classload) = 1;
145 foreach my $table ( keys %tables ) {
146 my @items = qsearch({
147 'table' => "h_$table",
148 'addl_from' => $table_join{$table},
149 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than }, },
150 'extra_sql' => ' AND custnum = '. $cust_main->custnum,
152 %foundsvcs = (%foundsvcs, map { $_->svcnum => 1 } @items)
154 push @history, @items;
157 ### Load svcs that are no longer linked (cust_svc has been deleted)
159 # get list of all svcs for this customer from h_cust_svc
160 # could also load svcdb here by joining to part_svc on svcpart,
161 # but it would spoil database optimizations on this lookup
162 my @svcnumobj = qsearch({
163 'select' => 'DISTINCT svcnum',
164 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than } },
165 'table' => 'h_cust_svc',
166 'addl_from' => 'JOIN cust_pkg USING (pkgnum)',
167 'extra_sql' => ' AND custnum = '. $cust_main->custnum,
170 # now grab those svcs explicitly
171 foreach my $svcnum ( map { $_->get('svcnum') } @svcnumobj ) {
172 # can skip the services we already found
173 next if $foundsvcs{$svcnum};
174 # grab any given h_cust_svc record for this svcnum to get svcdb
175 my $svcdbobj = qsearchs({
177 'hashref' => { svcnum => $svcnum },
178 'table' => 'h_cust_svc',
179 'addl_from' => 'JOIN part_svc USING (svcpart)',
180 'extra_sql' => 'LIMIT 1',
182 unless ($svcdbobj && $svcdbobj->get('svcdb')) {
183 # don't think this ever happens, but just in case, don't break history page over it
184 warn "Could not load svcdb for svcnum $svcnum";
187 my @items = qsearch({
188 'table' => "h_".$svcdbobj->get('svcdb'),
189 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than },
190 'svcnum' => $svcnum },
192 push @history, @items;
197 my @legacy_items = qsearch({
198 'table' => 'legacy_cust_history',
199 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than }, },
200 'extra_sql' => ' AND custnum = '. $cust_main->custnum,
202 push @history, @legacy_items;