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