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