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