default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / misc / order_pkg.html
1 <& /elements/header-popup.html, {
2      'title' =>  $quotationnum ? mt('Add package to quotation')
3                                : mt('Order new package'),
4      'nobr'  => 1,
5    }
6 &>
7
8 <& /elements/init_calendar.html &>
9
10 <SCRIPT TYPE="text/javascript" SRC="../elements/order_pkg.js"></SCRIPT>
11
12 <& /elements/error.html &>
13
14 <FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
15
16 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
17 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
18 <INPUT TYPE="hidden" NAME="qualnum" VALUE="<% scalar($cgi->param('qualnum')) |h %>">
19 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
20 % if ( $svcpart ) {
21     <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
22 % }
23
24 % my $num_sales = $agent->num_sales;
25 % my $conf_pkg_referral = $conf->exists('pkg_referral');
26 % my $show_sales = $num_sales && $conf_pkg_referral;
27 % my $show_sales_table = $num_sales || $conf_pkg_referral;
28
29 % if ( $show_sales ) {
30   <FONT CLASS="fsinnerbox-title"><% mt('Sales') |h %></FONT>
31 % }
32 % if ( $show_sales_table ) {
33   <TABLE CLASS="fsinnerbox">
34 % }
35
36 <& /elements/tr-select-sales.html,
37      'curr_value' => scalar($cgi->param('salesnum')),
38      'agentnum'   => $agent->agentnum,
39      'th'         => 1,
40 &>
41
42 % if ( $conf->exists('pkg_referral') ) {
43   <& /elements/tr-select-part_referral.html,
44                'curr_value'    => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,
45                'disable_empty' => 1,
46                'multiple'      => $conf->exists('pkg_referral-multiple'),
47                'colspan'       => 7,
48   &>
49 % }
50
51 % if ( $show_sales_table ) {
52   </TABLE><BR>
53 % }
54
55 <FONT CLASS="fsinnerbox-title"><% mt('Package') |h %></FONT>
56 <TABLE CLASS="fsinnerbox">
57
58 % if ( $part_pkg ) {
59     <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
60     <TR>
61       <TH ALIGN="right"><% mt('Package') |h %></TH>
62       <TD COLSPAN=6><% $part_pkg->pkg_comment |h %></TD>
63     </TR>
64 % } else {
65     <& /elements/tr-select-cust-part_pkg.html,
66                  'curr_value'    => $pkgpart,
67                  'classnum'      => -1,
68                  'cust_main'     => $cust_main,
69                  'prospect_main' => $prospect_main,
70     &>
71 % }
72
73 <& /elements/tr-input-pkg-quantity.html, curr_value => $quantity &>
74
75 % unless ( $quotationnum ) {
76
77 %   if ( $cust_main && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
78 %     my $what = lc(FS::payby->shortname($cust_main->payby));
79       <TR>
80         <TH ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TH>
81         <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
82       </TR>
83 %   }
84
85     <TR>
86       <TH ALIGN="right"><% mt('Start') |h %> </TD>
87       <TD COLSPAN=6>
88         <INPUT TYPE  = "radio"
89                NAME  = "start"
90                ID    = "start_now"
91                VALUE = ""
92                <% $cgi->param('start') eq '' ? 'CHECKED' : ''%>
93                <% $pkgpart ? '' : 'DISABLED' %>
94         >Now
95         &emsp;
96         <INPUT TYPE  = "radio"
97                NAME  = "start"
98                ID    = "start_on_hold"
99                VALUE = "on_hold"
100                <% $cgi->param('start') eq 'on_hold' ? 'CHECKED' : ''%>
101                <% $pkgpart ? '' : 'DISABLED' %>
102         >On hold
103         &emsp;
104         <INPUT TYPE  = "radio" 
105                NAME  = "start" 
106                ID    = "start_on_date" 
107                VALUE = "on_date" 
108                <% $cgi->param('start') eq 'date' ? 'CHECKED' : ''%>
109                <% $pkgpart ? '' : 'DISABLED' %>
110         >On date
111
112         <& /elements/input-date-field.html,
113              { 'name'      => 'start_date',
114                'format'    => $date_format,
115                'value'     => '',
116                'noinit'    => 1,
117              }
118         &>
119
120       </TD>
121     </TR>
122
123     <TR>
124       <TH ALIGN="right"><% mt('Contract end date') |h %> </TD>
125       <TD COLSPAN=6>
126         <& /elements/input-date-field.html,{
127                     'name'      => 'contract_end',
128                     'format'    => $date_format,
129                     'value'     => '',
130                     'noinit'    => 1,
131                     } &>
132       </TD>
133     </TR>
134
135 % }
136
137 </TABLE><BR>
138
139 <& /elements/table-cust_pkg_usageprice.html,
140      'pkgpart' => $pkgpart
141 &>
142
143 % my $discount_cust_pkg = $curuser->access_right('Discount customer package');
144 % my $waive_setup_fee   = $curuser->access_right('Waive setup fee');
145 %
146 % if ( $discount_cust_pkg || $waive_setup_fee ) {
147   <FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
148   <TABLE CLASS="fsinnerbox">
149     <& /elements/tr-select-pkg-discount.html &>
150   </TABLE><BR>
151
152 % }
153
154
155 % my $lock_locationnum = scalar($cgi->param('lock_locationnum'));
156 % my $contact_title = $lock_locationnum ? 'Contact'
157 %                                       : 'Contact and Location';
158 <FONT CLASS="fsinnerbox-title"><% mt($contact_title) |h %></FONT>
159 <TABLE CLASS="fsinnerbox">
160
161 <& /elements/tr-select-contact.html,
162              'cgi'           => $cgi,
163              'cust_main'     => $cust_main,
164              'prospect_main' => $prospect_main,
165 &>
166
167 % if ( $cgi->param('lock_locationnum') ) {
168
169     <INPUT TYPE  = "hidden"
170            NAME  = "locationnum"
171            ID    = "locationnum"
172            VALUE = "<% scalar($cgi->param('lock_locationnum')) |h %>"
173     >
174
175 % } else {
176
177     <& /elements/tr-select-cust_location.html,
178                  'cgi'           => $cgi,
179                  'cust_main'     => $cust_main,
180                  'prospect_main' => $prospect_main,
181     &>
182
183 % }
184
185 </TABLE>
186
187 % unless ( $cgi->param('lock_locationnum') ) {
188
189   <& /elements/standardize_locations.html,
190                 'form'        => "OrderPkgForm",
191                 'callback'    => $conf->exists('tax_district_method')
192                                  ? 'wa_state_tax_district()'
193                                  : 'submit_continue()',
194                 'with_census' => 1,
195                 'with_census_functions' => 1,
196   &>
197
198   <script>
199     <& /elements/wa_state_tax_district.js &>
200
201     // wa_sate_tax_district() will call submit_continue() upon success,
202     //   or submit_abort() upon error
203     function submit_continue() {
204       document.OrderPkgForm.submit();
205     }
206   </script>
207
208 % }
209
210 % if ($quotationnum) {
211 <BR>
212 <FONT CLASS="fsinnerbox-title"><% mt('Quotation details') |h %></FONT>
213 <TABLE ID="QuotationDetailTable" CLASS="fsinnerbox">
214   <TR>
215     <TD></TD>
216     <TD>
217       <SELECT NAME="copy_on_order">
218         <OPTION VALUE=""<% $copy_on_order ? '' : ' SELECTED' %>>
219           <% emt('Details will only appear on quotation') %>
220         </OPTION>
221         <OPTION VALUE="Y"<% $copy_on_order ? ' SELECTED' : '' %>>
222           <% emt('Copy details to invoice when placing order') %>
223         </OPTION>
224       </SELECT>
225     </TD>
226   </TR>
227 <& /edit/elements/detail-table.html, 
228      id      => 'QuotationDetailTable',
229      details => $details->{'quotation_detail'},
230      field   => 'quotation_detail',
231  &>
232 </TABLE>
233 % } else {
234 <BR>
235 <FONT CLASS="fsinnerbox-title"><% mt('Invoice details') |h %></FONT>
236 <TABLE ID="InvoiceDetailTable" CLASS="fsinnerbox">
237 <& /edit/elements/detail-table.html, 
238      id      => 'InvoiceDetailTable',
239      details => $details->{'invoice_detail'},
240      field   => 'invoice_detail',
241  &>
242 </TABLE>
243
244 <BR>
245 <FONT CLASS="fsinnerbox-title"><% mt('Package comments') |h %></FONT>
246 <TABLE ID="PackageCommentTable" CLASS="fsinnerbox">
247 <& /edit/elements/detail-table.html, 
248      id      => 'PackageCommentTable',
249      details => $details->{'package_comment'},
250      field   => 'package_comment',
251  &>
252 </TABLE>
253 % }
254
255
256 <BR>
257 % my $onclick = $cgi->param('lock_locationnum')
258 %                 ? 'document.OrderPkgForm.submit()'
259 %                 : 'standardize_new_location()';
260 <INPUT NAME    = "submitButton"
261        TYPE    = "button"
262        VALUE   = "<% mt("Order Package") |h %>"
263        onClick = "this.disabled=true; <% $onclick %>;"
264        <% $pkgpart ? '' : 'DISABLED' %>
265 >
266
267 </FORM>
268 </BODY>
269 </HTML>
270 <%init>
271
272 my $curuser = $FS::CurrentUser::CurrentUser;
273
274 die "access denied"
275   unless $curuser->access_right('Order customer package');
276
277 my $conf = new FS::Conf;
278 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
279
280 my $cust_main = '';
281 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
282   my $custnum = $1;
283   $cust_main = qsearchs({
284     'table'     => 'cust_main',
285     'hashref'   => { 'custnum' => $custnum },
286     'extra_sql' => ' AND '. $curuser->agentnums_sql,
287   });
288 }
289
290 my $prospect_main = '';
291 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
292   my $prospectnum = $1;
293   $prospect_main = qsearchs({
294     'table'     => 'prospect_main',
295     'hashref'   => { 'prospectnum' => $prospectnum },
296     'extra_sql' => ' AND '. $curuser->agentnums_sql,
297   });
298 }
299
300 my $quotationnum = '';
301 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
302   $quotationnum = $1;
303 }
304
305 my $details = {
306   'invoice_detail' => [],
307   'package_comment' => [],
308   'quotation_detail' => [],
309 };
310 foreach my $field ( $cgi->param ) {
311   foreach my $detailtype ( keys %$details ) {
312     if ($field =~ /^$detailtype(\d+)$/) {
313       $details->{$detailtype}->[$1] = $cgi->param($field);
314     }
315   }
316 }
317 foreach my $detailtype ( keys %$details ) {
318   @{ $details->{$detailtype} } = grep { length($_) } @{ $details->{$detailtype} };
319 }
320 my $copy_on_order = $cgi->param('copy_on_order');
321
322 die 'no custnum or prospectnum' unless $cust_main || $prospect_main;
323
324 my $agent =  $cust_main ? $cust_main->agent
325                         : $prospect_main->agent;
326
327 my $part_pkg = '';
328 if ( $cgi->param('lock_pkgpart') ) {
329   $part_pkg = qsearchs({
330     'table'     => 'part_pkg',
331     'hashref'   => { 'pkgpart' => scalar($cgi->param('lock_pkgpart')) },
332     'extra_sql' => ' AND '. FS::part_pkg->agent_pkgs_sql($agent),
333   })
334     or die "unknown pkgpart ". $cgi->param('lock_pkgpart');
335 }
336
337 my $pkgpart = $part_pkg ? $part_pkg->pkgpart : scalar($cgi->param('pkgpart'));
338
339 my $quantity = 1;
340 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
341   $quantity = $1;
342 }
343
344 my $format = $date_format. ' %T %z (%Z)'; #false laziness w/REAL_cust_pkg.cgi?
345
346 my $svcpart = scalar($cgi->param('svcpart'));
347
348 </%init>