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