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