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