799165fe06da953f09352659ac4aa79e920f8d1c
[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/xmlhttp.html,
9               'url'  => $p.'misc/xmlhttp-part_pkg_usageprice.html',
10               'subs' => [ 'get_part_pkg_usageprice' ],
11 &>
12
13 <& /elements/init_calendar.html &>
14
15 <SCRIPT TYPE="text/javascript" SRC="../elements/order_pkg.js"></SCRIPT>
16
17 <& /elements/error.html &>
18
19 <FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
20
21 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
22 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
23 <INPUT TYPE="hidden" NAME="qualnum" VALUE="<% scalar($cgi->param('qualnum')) |h %>">
24 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
25 % if ( $svcpart ) {
26     <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
27 % }
28
29 % my $num_sales = $agent->num_sales;
30 % my $conf_pkg_referral = $conf->exists('pkg_referral');
31 % my $show_sales = $num_sales && $conf_pkg_referral;
32 % my $show_sales_table = $num_sales || $conf_pkg_referral;
33
34 % if ( $show_sales ) {
35   <FONT CLASS="fsinnerbox-title"><% mt('Sales') |h %></FONT>
36 % }
37 % if ( $show_sales_table ) {
38   <% ntable("#cccccc") %>
39 % }
40
41 <& /elements/tr-select-sales.html,
42      'curr_value' => scalar($cgi->param('salesnum')),
43      'agentnum'   => $agent->agentnum,
44      'th'         => 1,
45 &>
46
47 % if ( $conf->exists('pkg_referral') ) {
48   <& /elements/tr-select-part_referral.html,
49                'curr_value'    => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,
50                'disable_empty' => 1,
51                'multiple'      => $conf->exists('pkg_referral-multiple'),
52                'colspan'       => 7,
53   &>
54 % }
55
56 % if ( $show_sales_table ) {
57   </TABLE><BR>
58 % }
59
60 <FONT CLASS="fsinnerbox-title"><% mt('Package') |h %></FONT>
61 <% ntable("#cccccc") %>
62
63 % if ( $part_pkg ) {
64     <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
65     <TR>
66       <TH ALIGN="right"><% mt('Package') |h %></TH>
67       <TD COLSPAN=6><% $part_pkg->pkg_comment |h %></TD>
68     </TR>
69 % } else {
70     <& /elements/tr-select-cust-part_pkg.html,
71                  'curr_value'    => $pkgpart,
72                  'classnum'      => -1,
73                  'cust_main'     => $cust_main,
74                  'prospect_main' => $prospect_main,
75     &>
76 % }
77
78 <& /elements/tr-input-pkg-quantity.html, curr_value => $quantity &>
79
80 % unless ( $quotationnum ) {
81
82 %   if ( $cust_main && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
83 %     my $what = lc(FS::payby->shortname($cust_main->payby));
84       <TR>
85         <TH ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TH>
86         <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
87       </TR>
88 %   }
89
90     <TR>
91       <TH ALIGN="right"><% mt('Start') |h %> </TD>
92       <TD COLSPAN=6>
93         <INPUT TYPE="radio" NAME="start" ID="start_now" VALUE="" <% $cgi->param('start') eq '' ? 'CHECKED' : ''%>>Now
94         &emsp;
95         <INPUT TYPE="radio" NAME="start" ID="start_on_hold" VALUE="on_hold" <% $cgi->param('start') eq 'on_hold' ? 'CHECKED' : ''%>>On hold
96         &emsp;
97         <INPUT TYPE="radio" NAME="start" ID="start_on_date" VALUE="on_date" <% $cgi->param('start') eq 'date' ? 'CHECKED' : ''%>>On date
98
99         <& /elements/input-date-field.html,{
100                     'name'      => 'start_date',
101                     'format'    => $date_format,
102                     'value'     => '',
103                     'noinit'    => 1,
104                   } &>
105       </TD>
106     </TR>
107
108     <TR>
109       <TH ALIGN="right"><% mt('Contract end date') |h %> </TD>
110       <TD COLSPAN=6>
111         <& /elements/input-date-field.html,{
112                     'name'      => 'contract_end',
113                     'format'    => $date_format,
114                     'value'     => '',
115                     'noinit'    => 1,
116                     } &>
117       </TD>
118     </TR>
119
120 % }
121
122 </TABLE><BR>
123
124 %#so:
125 %# - hide until you selecdt a pacakge with add-ons
126 %# -lookup and display the available add-ons when 
127 %# -add them to the (recur if there is one, otherwise setup) price and display magically like processing fees do on edit/cust_pay.cgi
128
129 %# better label?
130 <FONT CLASS = "fsinnerbox-title" 
131       ID    = "cust_pkg_usageprice_title"
132       STYLE = "display:none"
133 ><% mt('Usage add-ons') |h %></FONT>
134 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 ID="cust_pkg_usageprice_table">
135
136 </TABLE>
137 <BR>
138
139 % my $discount_cust_pkg = $curuser->access_right('Discount customer package');
140 % my $waive_setup_fee   = $curuser->access_right('Waive setup fee');
141 %
142 % if ( $discount_cust_pkg || $waive_setup_fee ) {
143   <FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
144   <% ntable("#cccccc") %>
145
146 %   if ( $waive_setup_fee ) {
147       <TR>
148         <TH ALIGN="right"><% mt('Waive setup fee') |h %> </TH>
149         <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="waive_setup" VALUE="Y"></TD>
150       </TR>
151 %   }
152
153 %   if ( $discount_cust_pkg ) {
154       <& /elements/tr-select-discount.html,
155                'element_etc' => 'DISABLED',
156                'colspan'     => 7,
157                'cgi'         => $cgi,
158       &>
159 %   }
160
161   </TABLE><BR>
162
163 % }
164
165
166 % my $lock_locationnum = scalar($cgi->param('lock_locationnum'));
167 % my $contact_title = $lock_locationnum ? 'Contact'
168 %                                       : 'Contact and Location';
169 <FONT CLASS="fsinnerbox-title"><% mt($contact_title) |h %></FONT>
170 <% ntable("#cccccc") %>
171
172 <& /elements/tr-select-contact.html,
173              'cgi'           => $cgi,
174              'cust_main'     => $cust_main,
175              'prospect_main' => $prospect_main,
176 &>
177
178 % if ( $cgi->param('lock_locationnum') ) {
179
180     <INPUT TYPE  = "hidden"
181            NAME  = "locationnum"
182            ID    = "locationnum"
183            VALUE = "<% scalar($cgi->param('lock_locationnum')) |h %>"
184     >
185
186 % } else {
187
188     <& /elements/tr-select-cust_location.html,
189                  'cgi'           => $cgi,
190                  'cust_main'     => $cust_main,
191                  'prospect_main' => $prospect_main,
192     &>
193
194 % }
195
196 </TABLE>
197
198 % unless ( $cgi->param('lock_locationnum') ) {
199
200   <& /elements/standardize_locations.html,
201                 'form'        => "OrderPkgForm",
202                 'callback'    => 'document.OrderPkgForm.submit()',
203                 'with_census' => 1,
204                 'with_census_functions' => 1,
205   &>
206
207 % }
208
209 <BR>
210 % my $onclick = $cgi->param('lock_locationnum')
211 %                 ? 'document.OrderPkgForm.submit()'
212 %                 : 'standardize_new_location()';
213 <INPUT NAME    = "submitButton"
214        TYPE    = "button"
215        VALUE   = "<% mt("Order Package") |h %>"
216        onClick = "this.disabled=true; <% $onclick %>;"
217        <% $pkgpart ? '' : 'DISABLED' %>
218 >
219
220 </FORM>
221 </BODY>
222 </HTML>
223 <%init>
224
225 my $curuser = $FS::CurrentUser::CurrentUser;
226
227 die "access denied"
228   unless $curuser->access_right('Order customer package');
229
230 my $conf = new FS::Conf;
231 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
232
233 my $cust_main = '';
234 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
235   my $custnum = $1;
236   $cust_main = qsearchs({
237     'table'     => 'cust_main',
238     'hashref'   => { 'custnum' => $custnum },
239     'extra_sql' => ' AND '. $curuser->agentnums_sql,
240   });
241 }
242
243 my $prospect_main = '';
244 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
245   my $prospectnum = $1;
246   $prospect_main = qsearchs({
247     'table'     => 'prospect_main',
248     'hashref'   => { 'prospectnum' => $prospectnum },
249     'extra_sql' => ' AND '. $curuser->agentnums_sql,
250   });
251 }
252
253 my $quotationnum = '';
254 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
255   $quotationnum = $1;
256 }
257
258 die 'no custnum or prospectnum' unless $cust_main || $prospect_main;
259
260 my $agent =  $cust_main ? $cust_main->agent
261                         : $prospect_main->agent;
262
263 my $part_pkg = '';
264 if ( $cgi->param('lock_pkgpart') ) {
265   $part_pkg = qsearchs({
266     'table'     => 'part_pkg',
267     'hashref'   => { 'pkgpart' => scalar($cgi->param('lock_pkgpart')) },
268     'extra_sql' => ' AND '. FS::part_pkg->agent_pkgs_sql($agent),
269   })
270     or die "unknown pkgpart ". $cgi->param('lock_pkgpart');
271 }
272
273 my $pkgpart = $part_pkg ? $part_pkg->pkgpart : scalar($cgi->param('pkgpart'));
274
275 my $quantity = 1;
276 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
277   $quantity = $1;
278 }
279
280 my $format = $date_format. ' %T %z (%Z)'; #false laziness w/REAL_cust_pkg.cgi?
281
282 my $svcpart = scalar($cgi->param('svcpart'));
283
284 </%init>