make package churn report actually show package churn, #7990
[freeside.git] / httemplate / graph / report_cust_bill_pkg.html
1 <& /elements/header.html,
2      { title => 'Sales Report',
3        head  => '
4   <SCRIPT TYPE="text/javascript"  SRC="'. $p. 'elements/jquery.js"></SCRIPT>
5   <SCRIPT TYPE="text/javascript"  SRC="'. $p. 'elements/spectrum.js"></SCRIPT>
6   <LINK   REL="stylesheet"       HREF="'. $p. 'elements/spectrum.css" />',
7      }
8 &>
9
10 <FORM ACTION="cust_bill_pkg.cgi" METHOD="POST">
11
12 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
13
14 <TR>
15   <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1"><% mt('Search options') |h %></FONT></TH>
16 </TR>
17
18 <% include('/elements/tr-select-from_to.html' ) %>
19
20 <TR>
21   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="projection" VALUE="1"></TD>
22   <TD>Show projected data for future months</TD>
23 </TR>
24
25 <SCRIPT TYPE="text/javascript">
26
27 function agent_changed(obj) {
28
29   if ( obj.value == '' ) { //breakdown, one color list per agent needed
30     document.getElementById('agent0-label').style.display = '';
31 %   for ( 1 .. $#agents ) {
32       document.getElementById('agent<% $_ %>-colors').style.display = '';
33 %   }
34   } else { //aggregate, only one color list needed
35     document.getElementById('agent0-label').style.display = 'none';
36 %   for ( 1 .. $#agents ) {
37       document.getElementById('agent<% $_ %>-colors').style.display = 'none';
38 %   }
39   } 
40
41   enable_agent_totals(obj);
42 }
43
44 function enable_agent_totals(obj) {
45 %# enable it iff we are breaking down by agent AND something else
46   obj.form.agent_totals.disabled = !(
47     obj.form.agentnum.value == '' && (
48       obj.form.refnum.value == ''   ||
49       document.getElementById('class_agg_break_breakdown').checked ||
50       obj.form.use_setup.value == 1 ||
51       obj.form.use_usage.value == 1
52     )
53   );
54 }
55
56 function class_mode_changed() {
57   var options = document.getElementsByName('class_mode');
58   var mode;
59   for(var i=0; i < options.length; i++) {
60     if (options[i].checked) {
61       mode = options[i].value;
62     }
63   }
64     
65   var div_pkg = document.getElementById('pkg_class');
66   var div_report = document.getElementById('report_class');
67   var span_exact = document.getElementById('exact_match');
68   if (mode == 'pkg') {
69     div_pkg.style.display = '';
70     div_report.style.display = 'none';
71     span_exact.style.display = 'none';
72   } else if (mode == 'report') {
73     div_pkg.style.display = 'none';
74     div_report.style.display = '';
75     span_exact.style.display = '';
76   }
77 }
78 window.onload = class_mode_changed;
79 </SCRIPT>
80
81 <& /elements/tr-select-agent.html,
82   'field'         => 'agentnum',
83   'label'         => 'Agent ',
84   'disable_empty' => 0,
85   'pre_options'   => [ 'all' => 'all (aggregate)' ],
86   'empty_label'   => 'all (breakdown)',
87   'onchange'      => 'agent_changed',
88 &>
89
90 <& /elements/tr-select-cust_class.html,
91   'field'         => 'cust_classnum',
92   'label'         => 'Customer class',
93   'multiple'      => 1,
94 &>
95
96 <& /elements/tr-select-part_referral.html,
97   'field'         => 'refnum',
98   'label'         => 'Advertising source ',
99   'disable_empty' => 0,
100   'pre_options'   => [ 'all' => 'all (aggregate)' ],
101   'empty_label'   => 'all (breakdown)',
102   'onchange'      => 'enable_agent_totals'
103 &>
104
105 <TR>
106
107   <TD>
108     <INPUT TYPE="radio" NAME="class_mode" VALUE="pkg" onchange="class_mode_changed('pkg')" CHECKED>
109     <% emt('Package class') %>
110     <BR>
111     <INPUT TYPE="radio" NAME="class_mode" VALUE="report" onchange="class_mode_changed('report')">
112     <% emt('Report class') %>
113   </TD>
114
115   <TD>
116     <TABLE>
117       <TR>
118
119         <TD>
120           <DIV ID="pkg_class">
121           <& /elements/select-pkg_class.html,
122             'field'         => 'classnum',
123             'multiple'      => 1,
124             'all_selected'  => 1,
125             'pre_options'   => [ #'all'  => 'all (aggregate)',
126                                 #   ''  => 'all (breakdown)',
127                                   '0'  => '(empty class)' ],
128             'disable_empty' => 1,
129             'onchange'      => 'enable_agent_totals',
130           &>
131           </DIV>
132           <DIV ID="report_class" STYLE="display: none">
133           <& /elements/select-table.html,
134             'field'         => 'report_optionnum',
135             'table'         => 'part_pkg_report_option',
136             'name_col'      => 'name',
137             'value_col'     => 'num',
138             'multiple'      => 1,
139             'all_selected'  => 1,
140             'pre_options'   => [ #'all' => 'all (aggregate)',
141                                #   '' => 'all (breakdown)', 
142                                  '0'  => '(empty class)' ],
143             'disable_empty' => 1,
144             'onchange'      => 'enable_agent_totals',
145           &>
146           </DIV>
147         </TD>
148
149         <TD>
150           <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_aggregate" VALUE="aggregate" onchange="enable_agent_totals(this)" CHECKED>
151           <% emt('Aggregate') %>
152           <BR>
153           <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_breakdown" VALUE="breakdown" onchange="enable_agent_totals(this)">
154           <% emt('Breakdown') %>
155           <BR>
156           <SPAN ID="exact_match" style="display:none">
157           <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_exact" VALUE="exact" onchange="enable_agent_totals(this)">
158           <% emt('Exact match') %>
159           </SPAN>
160         </TD>
161
162       </TR>
163     </TABLE>
164   </TD>
165
166 </TR>
167
168
169 <TR>
170   <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
171 </TR>
172
173 <TR>
174   <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1"><% mt('Display options') |h %></FONT></TH>
175 </TR>
176
177 <!--
178 <TR>
179   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="separate_0freq" VALUE="1"></TD>
180   <TD>Separate one-time vs. recurring sales</TD>
181 </TR>
182 -->
183
184 % foreach ( qw(Setup Usage) ) {
185 <& /elements/tr-select.html,
186     'label'   => "$_ fees",
187     'field'   => 'use_'.lc($_),
188     'options' => [ 0, 1, 2 ],
189     'labels'  => { 0 => 'Combine', 1 => 'Separate', 2 => 'Do not show' },
190     'onchange'=> 'enable_agent_totals',
191 &>
192 % }
193
194 <TR>
195   <TD ALIGN="right">Colors</TD>
196   <TD>
197 %   my @names = ();
198 %
199 %   #no particular long-term attachment to this, just trying to replicate
200 %   # historical behavior so people's graphs don't change color suddenly in 3.x
201 %   my $hue = 0;
202 %   my $hue_increment = 125;
203
204       <TABLE>
205 %       my $anum = 0;
206 %       foreach my $agent ( @agents ) {
207           <TR <% $anum ? 'STYLE="display:none"' : '' %>
208               ID="agent<%$anum%>-colors"
209           >
210             <TD <% $anum ? '' :'STYLE="display:none"' %>
211                 ID="agent<%$anum%>-label"
212             >
213               <% $agent->agent |h %>
214             </TD>
215             <TD>
216 %            my $col_scheme = Color::Scheme->new
217 %                               ->from_hue($hue) #->from_hex($agent->color)
218 %                               ->scheme('analogic')
219 %                             ;
220 %
221 %            my $cnum = 0;
222 %            my @colors = ($col_scheme->colors)[ 0,4,8,1,5,9 ];#again some some random historical shite
223 %            for (@colors) {
224 %              my $name = "agent$anum-color$cnum";
225 %              push @names, $name;
226 %              $cnum++;
227                <INPUT TYPE  = "color"
228                       NAME  = "<% $name %>"
229                       ID    = "<% $name %>"
230                       VALUE = "#<%$_%>"
231                >
232 %            }
233             </TD>
234           </TR>
235 %         $anum++;
236 %         $hue += $hue_increment;
237 %       }
238      </TABLE>
239   </TD>
240 </TR>
241
242 <SCRIPT TYPE="text/javascript">
243   $(document).ready(function() {
244 %   foreach my $name (@names) {
245       $("#<% $name %>").spectrum({
246         clickoutFiresChange: true
247       });
248 %   }
249   });
250 </SCRIPT>
251
252 <TR>
253   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="agent_totals" VALUE="1" DISABLED="1"></TD>
254   <TD>Show per-agent subtotals</TD>
255 </TR>
256
257 <TR>
258   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="use_override" VALUE="1"></TD>
259   <TD>Separate sub-packages from parents</TD>
260 </TR>
261
262 <TR>
263   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="average_per_cust_pkg" VALUE="1"></TD>
264   <TD>Average per customer package</TD>
265 </TR>
266
267 <TR>
268   <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="distribute" VALUE="1"></TD>
269   <TD>Distribute recurring fees over billing period</TD>
270 </TR>
271
272 </TABLE>
273
274 <BR><INPUT TYPE="submit" VALUE="Display">
275 </FORM>
276
277 <% include('/elements/footer.html') %>
278 <%init>
279
280 die "access denied"
281   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
282
283 my @agents = $FS::CurrentUser::CurrentUser->agents;
284
285 </%init>