default to a session cookie instead of setting an explicit timeout, weird timezone...
[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     <& /elements/tr-select-reason.html,
69              'field'          => 'reasonnum',
70              'reason_class'   => 'S',
71              'label'          => 'Suspended Reason',
72              'label_id'       => 'reasonnum_label',
73              'hide_addnew'    => '1',
74              'hide_onload'    => '1',
75              'cgi'            => $cgi,
76              'control_button' => 'confirm_suspend_cust_button',
77              'pre_options'    => [ 0 => 'all' ],
78     &>
79
80     <SCRIPT TYPE="text/javascript">
81   
82       function status_changed(what) {
83
84         if (what.options[what.selectedIndex].value == 'suspended') {
85           document.getElementById('reasonnum_row').style.visibility = 'visible';
86         }
87         else {
88           document.getElementById('reasonnum_row').style.visibility = 'collapse';
89         }
90
91 %       foreach my $status ( '', FS::cust_pkg->statuses() ) {
92
93           if ( what.options[what.selectedIndex].value == '<% $status %>' ) {
94
95 %           foreach my $field (@date_fields) {
96 %             if ( $disable{$status}->{$field} ) {
97
98                 what.form.<% $field %>_beginning_text.disabled = true;
99                 what.form.<% $field %>_ending_text.disabled = true;
100                 what.form.<% $field %>_null.disabled = true;
101                 what.form.<% $field %>_beginning_text.style.backgroundColor = '#dddddd';
102                 what.form.<% $field %>_ending_text.style.backgroundColor = '#dddddd';
103
104                 what.form.<% $field %>_beginning_button.style.display = 'none';
105                 what.form.<% $field %>_ending_button.style.display = 'none';
106                 what.form.<% $field %>_beginning_disabled.style.display = '';
107                 what.form.<% $field %>_ending_disabled.style.display = '';
108
109 %             } else {
110
111                 what.form.<% $field %>_null.disabled = false;
112
113                 if ( ! what.form.<% $field %>_null.checked ) {
114
115                   what.form.<% $field %>_beginning_text.disabled = false;
116                   what.form.<% $field %>_ending_text.disabled = false;
117                   what.form.<% $field %>_beginning_text.style.backgroundColor = '#ffffff';
118                   what.form.<% $field %>_ending_text.style.backgroundColor = '#ffffff';
119
120                   what.form.<% $field %>_beginning_button.style.display = '';
121                   what.form.<% $field %>_ending_button.style.display = '';
122                   what.form.<% $field %>_beginning_disabled.style.display = 'none';
123                   what.form.<% $field %>_ending_disabled.style.display = 'none';
124
125                 }
126
127 %             }
128 %           }
129
130           }
131
132 %       }
133
134       }
135
136 %     foreach my $field (@date_fields) {
137
138         function <% $field %>_null_changed(what) {
139
140           if ( what.checked ) {
141             what.form.<% $field %>_beginning_text.disabled = true;
142             what.form.<% $field %>_ending_text.disabled = true;
143             what.form.<% $field %>_beginning_text.style.backgroundColor = '#dddddd';
144             what.form.<% $field %>_ending_text.style.backgroundColor = '#dddddd';
145             what.form.<% $field %>_beginning_button.style.display = 'none';
146             what.form.<% $field %>_ending_button.style.display = 'none';
147             what.form.<% $field %>_beginning_disabled.style.display = '';
148             what.form.<% $field %>_ending_disabled.style.display = '';
149
150           } else {
151             what.form.<% $field %>_beginning_text.disabled = false;
152             what.form.<% $field %>_ending_text.disabled = false;
153             what.form.<% $field %>_beginning_text.style.backgroundColor = '#ffffff';
154             what.form.<% $field %>_ending_text.style.backgroundColor = '#ffffff';
155
156             what.form.<% $field %>_beginning_button.style.display = '';
157             what.form.<% $field %>_ending_button.style.display = '';
158             what.form.<% $field %>_beginning_disabled.style.display = 'none';
159             what.form.<% $field %>_ending_disabled.style.display = 'none';
160
161           }
162
163         }
164
165 %     }
166
167     </SCRIPT>
168
169     <& /elements/tr-select-pkg_class.html,
170                    'pre_options' => [ '0' => 'all' ],
171                    'empty_label' => '(empty class)',
172     &>
173
174 %   if ( scalar( qsearch( 'part_pkg_report_option', { 'disabled' => '' } ) ) ) {
175
176     <& /elements/tr-select-table.html,
177                    'label'        => 'Report classes',
178                    'table'        => 'part_pkg_report_option',
179                    'name_col'     => 'name',
180                    'hashref'      => { 'disabled' => '' },
181                    'element_name' => 'report_option',
182                    'multiple'     => 'multiple',
183     &>
184
185 %   }
186     <TR>
187
188
189
190             <TD></TD>
191             <TH ALIGN="left"><% '&nbsp;'x 10 %>From date <i>(m/d/y)</i></TH>
192             <TH ALIGN="center">To date <i>(m/d/y)</i></TH>
193             <TH>Empty date</TH>
194           </TR>
195 %   my $noinit = 0;
196 %   foreach my $field (@date_fields) {
197
198           <TR>
199             <TH ALIGN="right" VALIGN="center"><% $label{$field} %></TH>
200 %     foreach (qw(beginning ending)) {
201             <TD>
202               <& /elements/input-date-field.html, {
203                 'name'    => $field.'_'.$_,
204                 'value'   => '',
205                 'noinit'  => $noinit,
206                 'format'  => '%m/%d/%Y',
207               } &>
208             </TD>
209 %     $noinit = 1;
210 %     }
211             <TD ALIGN="center">
212               <& /elements/checkbox.html,
213                    'field'    => $field.'_null',
214                    'value'    => 'Y',
215                    'onchange' => $field.'_null_changed',
216               &>
217             </TD>
218           </TR>
219 %   } #foreach $field
220
221
222
223     
224     <SCRIPT TYPE="text/javascript">
225   
226       function custom_changed(what) {
227
228         if ( what.checked  ) {
229
230           what.form.pkgpart.disabled = true;
231           what.form.pkgpart.style.backgroundColor = '#dddddd';
232
233         } else {
234
235           what.form.pkgpart.disabled = false;
236           what.form.pkgpart.style.backgroundColor = '#ffffff';
237
238         }
239
240       }
241
242     </SCRIPT>
243
244     <& /elements/tr-checkbox.html,
245                 'label' => 'Custom packages',
246                 'field' => 'custom',
247                 'value' => 1,
248                 'onchange' => 'custom_changed(this);',
249     &> 
250
251     <& /elements/tr-selectmultiple-part_pkg.html, colspan=>3 &> 
252
253 </TABLE>
254 <BR>
255
256 <FONT CLASS="fsinnerbox-title"><% emt('Location search options') %></FONT>
257 <TABLE CLASS="fsinnerbox">
258
259 %   my @location_options = qw(cust nocust census nocensus);
260 %   if ( $conf->config('tax_data_vendor') eq 'cch' ) {
261 %     push @location_options, 'geocode', 'nogeocode';
262 %   }
263     <& /elements/tr-checkbox-multiple.html,
264                 'label'   => 'Where package location:',
265                 'field'   => 'loc',
266                 'options' => \@location_options,
267                 'labels'  => { 'cust'     => "is the customer's default location",
268                                'nocust'   => "is not the customer's default location",
269                                'census'   => "has an up-to-date census tract",
270                                'nocensus' => "does not have an up-to-date census tract",
271                                'nogeocode'=> 'has an implicit tax location',
272                                'geocode'  => 'has a hardcoded tax location',
273                              },
274                 'value'   => { map { $_ => 0 } @location_options },
275     &>
276
277 </TABLE>
278 <BR>
279
280 <FONT CLASS="fsinnerbox-title"><% emt('Display options') %></FONT>
281 <TABLE CLASS="fsinnerbox">
282
283     <& /elements/tr-select-cust-fields.html &>
284     
285   </TABLE>
286
287 <BR>
288 <INPUT TYPE="submit" VALUE="Get Report">
289
290 </FORM>
291
292 <% include('/elements/footer.html') %>
293 <%init>
294
295 die "access denied"
296   unless $FS::CurrentUser::CurrentUser->access_right('List packages');
297
298 my $title = 'Package Report';
299 #false laziness w/report_cust_bill.html
300 my @title_arg = ();
301
302 my $custnum = '';
303 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
304   $custnum = $1;
305   my $cust_main = qsearchs({
306     'table'     => 'cust_main', 
307     'hashref'   => { 'custnum' => $custnum },
308     'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
309   }) or die "unknown custnum $custnum";
310   $title .= ': [_1]';
311   push @title_arg, $cust_main->name;
312 }
313
314 </%init>
315 <%once>
316
317 tie my %label, 'Tie::IxHash',
318   'setup'        => 'Setup',
319   'last_bill'    => 'Last bill',
320   'bill'         => 'Next bill',
321   'adjourn'      => 'Adjourns',
322   'susp'         => 'Suspended',
323   'dundate'      => 'Suspension delayed until',
324   'expire'       => 'Expires',
325   'contract_end' => 'Contract ends',
326   'change_date'  => 'Changed from other package',
327   'cancel'       => 'Cancelled',
328 ;
329 my @date_fields = keys %label;
330
331 #false laziness w/cust_pkg.cgi
332 my %disable = (
333   'all'             => {},
334   'on hold'         => { 'setup'=>1, 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'expire'=>1, 'cancel'=>1, 'dundate'=> 1, },
335   'not yet billed'  => { 'setup'=>1, 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'dundate'=>1, },
336   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'contract_end'=>1, 'dundate'=>1, },
337   'active'          => { 'susp'=>1, 'cancel'=>1 },
338   'suspended'       => { 'cancel'=>1, 'dundate'=>1, },
339   'cancelled'       => {},
340   ''                => {},
341 );
342
343 #hmm?
344 my %checkbox = (
345   'setup'     => 0,
346   'last_bill' => 0,
347   'bill'      => 0,
348   'susp'      => 1,
349   'dundate'   => 1,
350   'expire'    => 1,
351   'cancel'    => 1,
352 );
353
354 my $conf = FS::Conf->new;
355 </%once>