Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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   'svc_cable'         => 'Cable',
46   'phone_device'      => 'Phone device',
47   'cust_pkg_discount' => 'Discount',
48   #? it gets provisioned anyway 'phone_avail'         => 'Phone',
49
50   'legacy_history'    => 'Label not used',
51
52 ;
53
54 my $pkg_join = "JOIN cust_pkg USING ( pkgnum )";
55 my $svc_join = "JOIN cust_svc USING ( svcnum ) $pkg_join";
56
57 my %table_join = (
58   'svc_acct'         => $svc_join,
59   'radius_usergroup' => $svc_join,
60   'svc_domain'       => $svc_join,
61   'svc_www'          => $svc_join,
62   'svc_forward'      => $svc_join,
63   'svc_broadband'    => $svc_join,
64   'svc_external'     => $svc_join,
65   'svc_phone'        => $svc_join,
66   'svc_cable'        => $svc_join,
67   'phone_device'     => $svc_join,
68   'cust_pkg_discount'=> $pkg_join,
69 );
70
71
72 # cust_main
73 # cust_main_invoice
74
75 # cust_pkg
76 # cust_pkg_option?
77 # cust_pkg_detail
78 # cust_pkg_reason?  no
79
80 #cust_svc
81 #cust_svc_option?
82 #svc_*
83 # svc_acct
84 #  radius_usergroup
85 #  acct_snarf?  is this even used? it is now, for communigate RPOP
86 # svc_domain
87 #  domain_record
88 #  registrar
89 # svc_forward
90 # svc_www
91 # svc_broadband
92 #  (virtual fields?  eh... maybe when they're real)
93 # svc_external
94 # svc_phone
95 #  phone_device
96 #  phone_avail
97
98 # future:
99
100 # inventory_item (from services)
101 # pkg_referral? (changed?)
102
103 #random others:
104
105 # cust_location?
106 # cust_main-exemption?? (295.ca named tax exemptions)
107
108
109 my( $cust_main ) = @_;
110
111 my $conf = new FS::Conf;
112
113 my $curuser = $FS::CurrentUser::CurrentUser;
114
115 die "access denied"
116   unless $curuser->access_right('View customer history');
117
118 # find out the beginning of this customer history, if possible
119 my $h_insert = qsearchs({
120   'table'     => 'h_cust_main',
121   'hashref'   => { 'custnum'        => $cust_main->custnum,
122                    'history_action' => 'insert',
123                  },
124   'extra_sql' => 'ORDER BY historynum LIMIT 1',
125 });
126 my $start = $h_insert ? $h_insert->history_date : 0;
127
128 # retreive the history
129
130 my @history = ();
131
132 my $years = $conf->config('change_history-years') || .5;
133 if ( $cgi->param('change_history-years') =~ /^([\d\.]+)$/ ) {
134   $years = $1;
135 }
136 my $newer_than = int( time - $years * 31556736 ); #60*60*24*365.24
137
138 local($FS::Record::nowarn_classload) = 1;
139
140 foreach my $table ( keys %tables ) {
141   my @items = qsearch({
142     'table'     => "h_$table",
143     'addl_from' => $table_join{$table},
144     'hashref'   => { 'history_date' =>  { op=>'>=', value=>$newer_than }, },
145     'extra_sql' => ' AND custnum = '. $cust_main->custnum,
146   });
147   push @history, @items;
148
149 }
150
151 </%init>