add customer status to advanced package report, RT#24631
[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     <TR>
12       <TH CLASS="background" COLSPAN=2 ALIGN="left">
13         <FONT SIZE="+1">Customer search options</FONT>
14       </TH>
15     </TR>
16
17     <& /elements/tr-select-agent.html,
18                    'curr_value'    => scalar( $cgi->param('agentnum') ),
19                    'disable_empty' => 0,
20                    'onchange'      => 'agent_changed(this)',
21     &>
22
23     <& /elements/tr-select-cust_main-status.html,
24          'label' => 'Customer status',
25          'field' => 'cust_status',
26     &>
27
28     <SCRIPT TYPE="text/javascript">
29
30       function agent_changed(what) {
31 %       # update sales dropdowns
32         salesnum_agentnum_changed(what);
33         cust_main_salesnum_agentnum_changed(what);
34       }
35
36       <&| /elements/onload.js &>
37       agent_changed(document.getElementById('agentnum'))
38       </&>
39  
40     </SCRIPT>
41
42     <& /elements/tr-select-sales.html,
43                   'label'         => 'Customer sales person',
44                   'element_name'  => 'cust_main_salesnum',
45                   'id'            => 'cust_main_salesnum',
46                   'curr_value'    => scalar($cgi->param('cust_main_salesnum')),
47                   'pre_options'   => [ '' => 'all',
48                                        0  => '(none)', ],
49                   'disable_empty' => 1,
50     &>
51
52   </TABLE>
53   <BR>
54
55 % }
56
57   <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
58
59     <TR>
60       <TH CLASS="background" COLSPAN=2 ALIGN="left">
61         <FONT SIZE="+1">Package search options</FONT>
62       </TH>
63     </TR>
64
65     <& /elements/tr-select-sales.html,
66                   'label'         => 'Package sales person',
67                   'curr_value'    => scalar($cgi->param('salesnum')),
68                   'pre_options'   => [ '' => 'all',
69                                         0  => '(none)', ],
70                   'disable_empty' => 1,
71     &>
72
73     <% include( '/elements/tr-select-cust_pkg-status.html',
74                   'label'    => 'Package status',
75                   'onchange' => 'status_changed(this);',
76               )
77     %>
78
79     <SCRIPT TYPE="text/javascript">
80   
81       function status_changed(what) {
82
83 %       foreach my $status ( '', FS::cust_pkg->statuses() ) {
84
85           if ( what.options[what.selectedIndex].value == '<% $status %>' ) {
86
87 %           foreach my $field (@date_fields) {
88 %             if ( $disable{$status}->{$field} ) {
89
90                 what.form.<% $field %>_beginning_text.disabled = true;
91                 what.form.<% $field %>_ending_text.disabled = true;
92                 what.form.<% $field %>_beginning_text.style.backgroundColor = '#dddddd';
93                 what.form.<% $field %>_ending_text.style.backgroundColor = '#dddddd';
94
95                 what.form.<% $field %>_beginning_button.style.display = 'none';
96                 what.form.<% $field %>_ending_button.style.display = 'none';
97                 what.form.<% $field %>_beginning_disabled.style.display = '';
98                 what.form.<% $field %>_ending_disabled.style.display = '';
99
100 %             } else {
101
102                 what.form.<% $field %>_beginning_text.disabled = false;
103                 what.form.<% $field %>_ending_text.disabled = false;
104                 what.form.<% $field %>_beginning_text.style.backgroundColor = '#ffffff';
105                 what.form.<% $field %>_ending_text.style.backgroundColor = '#ffffff';
106
107                 what.form.<% $field %>_beginning_button.style.display = '';
108                 what.form.<% $field %>_ending_button.style.display = '';
109                 what.form.<% $field %>_beginning_disabled.style.display = 'none';
110                 what.form.<% $field %>_ending_disabled.style.display = 'none';
111
112 %             }
113 %           }
114
115           }
116
117 %       }
118
119       }
120
121     </SCRIPT>
122
123     <% include( '/elements/tr-select-pkg_class.html',
124                    'pre_options' => [ '0' => 'all' ],
125                    'empty_label' => '(empty class)',
126                )
127     %>
128
129 %   if ( scalar( qsearch( 'part_pkg_report_option', { 'disabled' => '' } ) ) ) {
130
131     <% include( '/elements/tr-select-table.html',
132                    'label'        => 'Report classes',
133                    'table'        => 'part_pkg_report_option',
134                    'name_col'     => 'name',
135                    'hashref'      => { 'disabled' => '' },
136                    'element_name' => 'report_option',
137                    'multiple'     => 'multiple',
138                )
139     %>
140
141 %   }
142     <TR>
143       <TD COLSPAN=2>
144         <TABLE>
145           <TR>
146             <TD></TD>
147             <TD>From date <i>(m/d/y)</i></TD>
148             <TD>To date <i>(m/d/y)</i></TD>
149           </TR>
150 %   my $noinit = 0;
151 %   foreach my $field (@date_fields) {
152
153           <TR>
154             <TD ALIGN="right" VALIGN="center"><% $label{$field} %></TD>
155 %     foreach (qw(beginning ending)) {
156             <TD>
157               <& /elements/input-date-field.html, {
158                 'name'    => $field.'_'.$_,
159                 'value'   => '',
160                 'noinit'  => $noinit,
161                 'format'  => '%m/%d/%Y',
162               } &>
163             </TD>
164 %     $noinit = 1;
165 %     }
166           </TR>
167 %   } #foreach $field
168         </TABLE>
169       </TD>
170     </TR>
171     
172     <SCRIPT TYPE="text/javascript">
173   
174       function custom_changed(what) {
175
176         if ( what.checked  ) {
177
178           what.form.pkgpart.disabled = true;
179           what.form.pkgpart.style.backgroundColor = '#dddddd';
180
181         } else {
182
183           what.form.pkgpart.disabled = false;
184           what.form.pkgpart.style.backgroundColor = '#ffffff';
185
186         }
187
188       }
189
190     </SCRIPT>
191
192     <% include( '/elements/tr-checkbox.html',
193                 'label' => 'Custom packages',
194                 'field' => 'custom',
195                 'value' => 1,
196                 'onchange' => 'custom_changed(this);',
197               )
198     %> 
199
200     <% include( '/elements/tr-selectmultiple-part_pkg.html' ) %> 
201
202     <TR>
203       <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
204     </TR>
205
206     <TR>
207       <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
208     </TR>
209     <% include( '/elements/tr-select-cust-fields.html' ) %>
210     
211   </TABLE>
212
213 <BR>
214 <INPUT TYPE="submit" VALUE="Get Report">
215
216 </FORM>
217
218 <% include('/elements/footer.html') %>
219 <%init>
220
221 die "access denied"
222   unless $FS::CurrentUser::CurrentUser->access_right('List packages');
223
224 my $title = 'Package Report';
225 #false laziness w/report_cust_bill.html
226 my @title_arg = ();
227
228 my $custnum = '';
229 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
230   $custnum = $1;
231   my $cust_main = qsearchs({
232     'table'     => 'cust_main', 
233     'hashref'   => { 'custnum' => $custnum },
234     'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
235   }) or die "unknown custnum $custnum";
236   $title .= ': [_1]';
237   push @title_arg, $cust_main->name;
238 }
239
240 </%init>
241 <%once>
242
243 tie my %label, 'Tie::IxHash',
244   'setup'        => 'Setup',
245   'last_bill'    => 'Last bill',
246   'bill'         => 'Next bill',
247   'adjourn'      => 'Adjourns',
248   'susp'         => 'Suspended',
249   'dundate'      => 'Suspension delayed until',
250   'expire'       => 'Expires',
251   'contract_end' => 'Contract ends',
252   'change_date'  => 'Changed from other package',
253   'cancel'       => 'Cancelled',
254 ;
255 my @date_fields = keys %label;
256
257 #false laziness w/cust_pkg.cgi
258 my %disable = (
259   'all'             => {},
260   'not yet billed'  => { 'setup'=>1, 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
261   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'contract_end'=>1, 'dundate'=>1, },
262   'active'          => { 'susp'=>1, 'cancel'=>1 },
263   'suspended'       => { 'cancel'=>1, 'dundate'=>1, },
264   'cancelled'       => {},
265   ''                => {},
266 );
267
268 #hmm?
269 my %checkbox = (
270   'setup'     => 0,
271   'last_bill' => 0,
272   'bill'      => 0,
273   'susp'      => 1,
274   'dundate'   => 1,
275   'expire'    => 1,
276   'cancel'    => 1,
277 );
278
279 </%once>