4.x style reports
[freeside.git] / httemplate / search / report_cust_pkg.html
1 <& /elements/header.html, mt($title, @title_arg) &>
2
3 <FORM ACTION="cust_pkg.cgi" METHOD="GET">
4 <INPUT TYPE="hidden" NAME="magic" VALUE="bill">
5 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
6
7 % unless ( $custnum ) {
8
9   <FONT CLASS="fsinnerbox-title"><% emt('Customer search options') %></FONT>
10   <TABLE CLASS="fsinnerbox">
11
12     <& /elements/tr-select-agent.html,
13                    'curr_value'    => scalar( $cgi->param('agentnum') ),
14                    'disable_empty' => 0,
15                    'onchange'      => 'agent_changed(this)',
16     &>
17
18     <& /elements/tr-select-cust_main-status.html,
19          'label' => 'Customer status',
20          'field' => 'cust_status',
21     &>
22
23     <SCRIPT TYPE="text/javascript">
24
25       function agent_changed(what) {
26 %       # update sales dropdowns
27         salesnum_agentnum_changed(what);
28         cust_main_salesnum_agentnum_changed(what);
29       }
30
31       <&| /elements/onload.js &>
32       agent_changed(document.getElementById('agentnum'))
33       </&>
34  
35     </SCRIPT>
36
37     <& /elements/tr-select-sales.html,
38                   'label'         => 'Customer sales person',
39                   'element_name'  => 'cust_main_salesnum',
40                   'id'            => 'cust_main_salesnum',
41                   'curr_value'    => scalar($cgi->param('cust_main_salesnum')),
42                   'pre_options'   => [ '' => 'all',
43                                        0  => '(none)', ],
44                   'disable_empty' => 1,
45     &>
46
47   </TABLE>
48   <BR>
49
50 % }
51
52 <FONT CLASS="fsinnerbox-title"><% emt('Package search options') %></FONT>
53 <TABLE CLASS="fsinnerbox">
54
55     <& /elements/tr-select-sales.html,
56                   'label'         => 'Package sales person',
57                   'curr_value'    => scalar($cgi->param('salesnum')),
58                   'pre_options'   => [ '' => 'all',
59                                         0  => '(none)', ],
60                   'disable_empty' => 1,
61     &>
62
63     <& /elements/tr-select-cust_pkg-status.html,
64                   'label'    => 'Package status',
65                   'onchange' => 'status_changed(this);',
66     &>
67
68     <SCRIPT TYPE="text/javascript">
69   
70       function status_changed(what) {
71
72 %       foreach my $status ( '', FS::cust_pkg->statuses() ) {
73
74           if ( what.options[what.selectedIndex].value == '<% $status %>' ) {
75
76 %           foreach my $field (@date_fields) {
77 %             if ( $disable{$status}->{$field} ) {
78
79                 what.form.<% $field %>_beginning_text.disabled = true;
80                 what.form.<% $field %>_ending_text.disabled = true;
81                 what.form.<% $field %>_null.disabled = true;
82                 what.form.<% $field %>_beginning_text.style.backgroundColor = '#dddddd';
83                 what.form.<% $field %>_ending_text.style.backgroundColor = '#dddddd';
84
85                 what.form.<% $field %>_beginning_button.style.display = 'none';
86                 what.form.<% $field %>_ending_button.style.display = 'none';
87                 what.form.<% $field %>_beginning_disabled.style.display = '';
88                 what.form.<% $field %>_ending_disabled.style.display = '';
89
90 %             } else {
91
92                 what.form.<% $field %>_null.disabled = false;
93
94                 if ( ! what.form.<% $field %>_null.checked ) {
95
96                   what.form.<% $field %>_beginning_text.disabled = false;
97                   what.form.<% $field %>_ending_text.disabled = false;
98                   what.form.<% $field %>_beginning_text.style.backgroundColor = '#ffffff';
99                   what.form.<% $field %>_ending_text.style.backgroundColor = '#ffffff';
100
101                   what.form.<% $field %>_beginning_button.style.display = '';
102                   what.form.<% $field %>_ending_button.style.display = '';
103                   what.form.<% $field %>_beginning_disabled.style.display = 'none';
104                   what.form.<% $field %>_ending_disabled.style.display = 'none';
105
106                 }
107
108 %             }
109 %           }
110
111           }
112
113 %       }
114
115       }
116
117 %     foreach my $field (@date_fields) {
118
119         function <% $field %>_null_changed(what) {
120
121           if ( what.checked ) {
122             what.form.<% $field %>_beginning_text.disabled = true;
123             what.form.<% $field %>_ending_text.disabled = true;
124             what.form.<% $field %>_beginning_text.style.backgroundColor = '#dddddd';
125             what.form.<% $field %>_ending_text.style.backgroundColor = '#dddddd';
126             what.form.<% $field %>_beginning_button.style.display = 'none';
127             what.form.<% $field %>_ending_button.style.display = 'none';
128             what.form.<% $field %>_beginning_disabled.style.display = '';
129             what.form.<% $field %>_ending_disabled.style.display = '';
130
131           } else {
132             what.form.<% $field %>_beginning_text.disabled = false;
133             what.form.<% $field %>_ending_text.disabled = false;
134             what.form.<% $field %>_beginning_text.style.backgroundColor = '#ffffff';
135             what.form.<% $field %>_ending_text.style.backgroundColor = '#ffffff';
136
137             what.form.<% $field %>_beginning_button.style.display = '';
138             what.form.<% $field %>_ending_button.style.display = '';
139             what.form.<% $field %>_beginning_disabled.style.display = 'none';
140             what.form.<% $field %>_ending_disabled.style.display = 'none';
141
142           }
143
144         }
145
146 %     }
147
148     </SCRIPT>
149
150     <& /elements/tr-select-pkg_class.html,
151                    'pre_options' => [ '0' => 'all' ],
152                    'empty_label' => '(empty class)',
153     &>
154
155 %   if ( scalar( qsearch( 'part_pkg_report_option', { 'disabled' => '' } ) ) ) {
156
157     <& /elements/tr-select-table.html,
158                    'label'        => 'Report classes',
159                    'table'        => 'part_pkg_report_option',
160                    'name_col'     => 'name',
161                    'hashref'      => { 'disabled' => '' },
162                    'element_name' => 'report_option',
163                    'multiple'     => 'multiple',
164     &>
165
166 %   }
167     <TR>
168       <TD COLSPAN=2>
169         <TABLE>
170           <TR>
171             <TD></TD>
172             <TD>From date <i>(m/d/y)</i></TD>
173             <TD>To date <i>(m/d/y)</i></TD>
174             <TD>Empty date</TD>
175           </TR>
176 %   my $noinit = 0;
177 %   foreach my $field (@date_fields) {
178
179           <TR>
180             <TD ALIGN="right" VALIGN="center"><% $label{$field} %></TD>
181 %     foreach (qw(beginning ending)) {
182             <TD>
183               <& /elements/input-date-field.html, {
184                 'name'    => $field.'_'.$_,
185                 'value'   => '',
186                 'noinit'  => $noinit,
187                 'format'  => '%m/%d/%Y',
188               } &>
189             </TD>
190 %     $noinit = 1;
191 %     }
192             <TD ALIGN="center">
193               <& /elements/checkbox.html,
194                    'field'    => $field.'_null',
195                    'value'    => 'Y',
196                    'onchange' => $field.'_null_changed',
197               &>
198             </TD>
199           </TR>
200 %   } #foreach $field
201         </TABLE>
202       </TD>
203     </TR>
204     
205     <SCRIPT TYPE="text/javascript">
206   
207       function custom_changed(what) {
208
209         if ( what.checked  ) {
210
211           what.form.pkgpart.disabled = true;
212           what.form.pkgpart.style.backgroundColor = '#dddddd';
213
214         } else {
215
216           what.form.pkgpart.disabled = false;
217           what.form.pkgpart.style.backgroundColor = '#ffffff';
218
219         }
220
221       }
222
223     </SCRIPT>
224
225     <& /elements/tr-checkbox.html,
226                 'label' => 'Custom packages',
227                 'field' => 'custom',
228                 'value' => 1,
229                 'onchange' => 'custom_changed(this);',
230     &> 
231
232     <& /elements/tr-selectmultiple-part_pkg.html &> 
233
234 </TABLE>
235 <BR>
236
237 <FONT CLASS="fsinnerbox-title"><% emt('Location search options') %></FONT>
238 <TABLE CLASS="fsinnerbox">
239
240 %   my @location_options = qw(cust nocust census nocensus);
241 %   if ( $conf->config('tax_data_vendor') eq 'cch' ) {
242 %     push @location_options, 'geocode', 'nogeocode';
243 %   }
244     <& /elements/tr-checkbox-multiple.html,
245                 'label'   => 'Where package location:',
246                 'field'   => 'loc',
247                 'options' => \@location_options,
248                 'labels'  => { 'cust'     => "is the customer's default location",
249                                'nocust'   => "is not the customer's default location",
250                                'census'   => "has a census tract",
251                                'nocensus' => "does not have a census tract",
252                                'nogeocode'=> 'has an implicit tax location',
253                                'geocode'  => 'has a hardcoded tax location',
254                              },
255                 'value'   => { map { $_ => 0 } @location_options },
256     &>
257
258 </TABLE>
259 <BR>
260
261 <FONT CLASS="fsinnerbox-title"><% emt('Display options') %></FONT>
262 <TABLE CLASS="fsinnerbox">
263
264     <& /elements/tr-select-cust-fields.html &>
265     
266   </TABLE>
267
268 <BR>
269 <INPUT TYPE="submit" VALUE="Get Report">
270
271 </FORM>
272
273 <% include('/elements/footer.html') %>
274 <%init>
275
276 die "access denied"
277   unless $FS::CurrentUser::CurrentUser->access_right('List packages');
278
279 my $title = 'Package Report';
280 #false laziness w/report_cust_bill.html
281 my @title_arg = ();
282
283 my $custnum = '';
284 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
285   $custnum = $1;
286   my $cust_main = qsearchs({
287     'table'     => 'cust_main', 
288     'hashref'   => { 'custnum' => $custnum },
289     'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
290   }) or die "unknown custnum $custnum";
291   $title .= ': [_1]';
292   push @title_arg, $cust_main->name;
293 }
294
295 </%init>
296 <%once>
297
298 tie my %label, 'Tie::IxHash',
299   'setup'        => 'Setup',
300   'last_bill'    => 'Last bill',
301   'bill'         => 'Next bill',
302   'adjourn'      => 'Adjourns',
303   'susp'         => 'Suspended',
304   'dundate'      => 'Suspension delayed until',
305   'expire'       => 'Expires',
306   'contract_end' => 'Contract ends',
307   'change_date'  => 'Changed from other package',
308   'cancel'       => 'Cancelled',
309 ;
310 my @date_fields = keys %label;
311
312 #false laziness w/cust_pkg.cgi
313 my %disable = (
314   'all'             => {},
315   'on hold'         => { 'setup'=>1, 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'expire'=>1, 'cancel'=>1, 'dundate'=> 1, },
316   'not yet billed'  => { 'setup'=>1, 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'dundate'=>1, },
317   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'contract_end'=>1, 'dundate'=>1, },
318   'active'          => { 'susp'=>1, 'cancel'=>1 },
319   'suspended'       => { 'cancel'=>1, 'dundate'=>1, },
320   'cancelled'       => {},
321   ''                => {},
322 );
323
324 #hmm?
325 my %checkbox = (
326   'setup'     => 0,
327   'last_bill' => 0,
328   'bill'      => 0,
329   'susp'      => 1,
330   'dundate'   => 1,
331   'expire'    => 1,
332   'cancel'    => 1,
333 );
334
335 my $conf = FS::Conf->new;
336 </%once>