This commit was generated by cvs2svn to compensate for changes in r12472,
[freeside.git] / httemplate / view / cust_main / change_history.html
1 % if ( int( time - (keys %years)[0] * 31556736 ) > $start ) {
2     Show:
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>
7 %     } else {
8 %       $cgi->param('change_history-years', $y);
9         <A HREF="<% $cgi->self_url %>"><% $years{$y} %></A>
10 %     }
11 %     last if int( time - $y * 31556736 ) < $start;
12 %   }
13 %   $cgi->param('change_history-years', $chy);
14 % }
15
16 <% include("/elements/change_history_common.html",
17         'history'   => \@history,
18         'tables'    => \%tables,
19         'single_cust'   => 1,
20     ) %>
21
22 <%init>
23
24 tie my %years, 'Tie::IxHash',
25     .5 => '6 months',
26    1  => '1 year',
27    2  => '2 years',
28    5  => '5 years',
29   39  => 'all history',
30 ;
31
32 tie my %tables, 'Tie::IxHash',
33   'cust_main'         => 'Customer',
34   'cust_main_invoice' => 'Invoice destination',
35   'cust_pkg'          => 'Package',
36   #? or just svc_* ? 'cust_svc' => 
37   'svc_acct'          => 'Account',
38   'radius_usergroup'  => 'RADIUS group',
39   'svc_domain'        => 'Domain',
40   'svc_www'           => 'Hosting',
41   'svc_forward'       => 'Mail forward',
42   'svc_broadband'     => 'Broadband',
43   'svc_external'      => 'External service',
44   'svc_phone'         => 'Phone',
45   'phone_device'      => 'Phone device',
46   #? it gets provisioned anyway 'phone_avail'         => 'Phone',
47 ;
48
49 my $svc_join = 'JOIN cust_svc USING ( svcnum ) JOIN cust_pkg USING ( pkgnum )';
50
51 my %table_join = (
52   'svc_acct'         => $svc_join,
53   'radius_usergroup' => $svc_join,
54   'svc_domain'       => $svc_join,
55   'svc_www'          => $svc_join,
56   'svc_forward'      => $svc_join,
57   'svc_broadband'    => $svc_join,
58   'svc_external'     => $svc_join,
59   'svc_phone'        => $svc_join,
60   'phone_device'     => $svc_join,
61 );
62
63
64 # cust_main
65 # cust_main_invoice
66
67 # cust_pkg
68 # cust_pkg_option?
69 # cust_pkg_detail
70 # cust_pkg_reason?  no
71
72 #cust_svc
73 #cust_svc_option?
74 #svc_*
75 # svc_acct
76 #  radius_usergroup
77 #  acct_snarf?  is this even used? it is now, for communigate RPOP
78 # svc_domain
79 #  domain_record
80 #  registrar
81 # svc_forward
82 # svc_www
83 # svc_broadband
84 #  (virtual fields?  eh... maybe when they're real)
85 # svc_external
86 # svc_phone
87 #  phone_device
88 #  phone_avail
89
90 # future:
91
92 # inventory_item (from services)
93 # pkg_referral? (changed?)
94
95 #random others:
96
97 # cust_location?
98 # cust_main-exemption?? (295.ca named tax exemptions)
99
100
101 my( $cust_main ) = @_;
102
103 my $conf = new FS::Conf;
104
105 my $curuser = $FS::CurrentUser::CurrentUser;
106
107 die "access deined"
108   unless $curuser->access_right('View customer history');
109
110 # find out the beginning of this customer history, if possible
111 my $h_insert = qsearchs({
112   'table'     => 'h_cust_main',
113   'hashref'   => { 'custnum'        => $cust_main->custnum,
114                    'history_action' => 'insert',
115                  },
116   'extra_sql' => 'ORDER BY historynum LIMIT 1',
117 });
118 my $start = $h_insert ? $h_insert->history_date : 0;
119
120 # retreive the history
121
122 my @history = ();
123
124 my $years = $conf->config('change_history-years') || .5;
125 if ( $cgi->param('change_history-years') =~ /^([\d\.]+)$/ ) {
126   $years = $1;
127 }
128 my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24
129
130 local($FS::Record::nowarn_classload) = 1;
131
132 foreach my $table ( keys %tables ) {
133   my @items = qsearch({
134     'table'     => "h_$table",
135     'addl_from' => $table_join{$table},
136     'hashref'   => { 'history_date' =>  { op=>'>=', value=>$newer_than }, },
137     'extra_sql' => ' AND custnum = '. $cust_main->custnum,
138   });
139   push @history, @items;
140
141 }
142
143 </%init>