move javascript for great justice
[freeside.git] / httemplate / misc / order_pkg.html
1 <% include('/elements/header-popup.html', 'Order new package' ) %>
2
3 <LINK REL="stylesheet" TYPE="text/css" HREF="../elements/calendar-win2k-2.css" TITLE="win2k-2">
4 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar_stripped.js"></SCRIPT>
5 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT>
6 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT>
7
8 <SCRIPT TYPE="text/javascript">
9
10   function enable_order_pkg () {
11     if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
12       document.OrderPkgForm.submitButton.disabled = false;
13       if ( document.OrderPkgForm.pkgpart.options[document.OrderPkgForm.pkgpart.selectedIndex].getAttribute('data-can_discount') == 1 ) {
14         document.OrderPkgForm.discountnum.disabled = false;
15       } else {
16         document.OrderPkgForm.discountnum.disabled = true;
17       }
18     } else {
19       document.OrderPkgForm.submitButton.disabled = true;
20       document.OrderPkgForm.discountnum.disabled = true;
21     }
22   }
23
24   function standardize_new_location() {
25     var form = document.OrderPkgForm;
26     var loc = form.locationnum;
27     if (loc.type = 'select-one' && loc.options[loc.selectedIndex].value == -1) {
28       standardize_locations();
29     } else {
30       form.submit();
31     }
32   }
33
34 </SCRIPT>
35
36 <% include('/elements/error.html') %>
37
38 <FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
39
40 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
41 <INPUT TYPE="hidden" NAME="qualnum" VALUE="<% scalar($cgi->param('qualnum')) |h %>">
42 % if ( $svcpart ) {
43     <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
44 % }
45
46 <% ntable("#cccccc", 2) %>
47 % if ( $part_pkg ) {
48     <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
49     <TR>
50       <TH ALIGN="right">Package</TH>
51       <TD COLSPAN=6><% $part_pkg->pkg_comment |h %></TD>
52     </TR>
53 % } else {
54     <% include('/elements/tr-select-cust-part_pkg.html',
55                  'curr_value' => $pkgpart,
56                  'classnum'   => -1,
57                  'cust_main'  => $cust_main,
58                  'onchange'   => 'enable_order_pkg',
59               )
60     %>
61 % }
62
63 <TR>
64   <TH ALIGN="right">Start date </TD>
65   <TD COLSPAN=6>
66     <% include('/elements/input-date-field.html',{
67                 'name'      => 'start_date',
68                 'format'    => $date_format,
69                 'value'     => $start_date,
70                 'noinit'    => 1,
71               }) %>
72     <FONT SIZE=-1>(leave blank to start immediately)</FONT>
73   </TD>
74 </TR>
75
76 % if ( $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
77 %   my $what = lc(FS::payby->shortname($cust_main->payby));
78     <TR>
79       <TH ALIGN="right">Disable automatic <% $what %> charge </TH>
80       <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
81     </TR>
82 % }
83
84 % if ( $curuser->access_right('Discount customer package') ) {
85   <% include('/elements/tr-select-discount.html',
86                'element_etc' => 'DISABLED',
87                'colspan'     => 7,
88                'cgi'         => $cgi,
89             )
90   %>
91 % }
92
93 % if ( $conf->exists('pkg_referral') ) {
94   <% include('/elements/tr-select-part_referral.html',
95                'curr_value'    => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,
96                'disable_empty' => 1,
97                'multiple'      => $conf->exists('pkg_referral-multiple'),
98                'colspan'       => 7,
99             )
100   %>
101 % }
102
103 % if ( $cgi->param('lock_locationnum') ) {
104
105     <INPUT TYPE  = "hidden"
106            NAME  = "locationnum"
107            ID    = "locationnum"
108            VALUE = "<% scalar($cgi->param('lock_locationnum')) |h %>"
109     >
110
111 % } else {
112
113     <% include('/elements/tr-select-cust_location.html',
114                  'cgi'       => $cgi,
115                  'cust_main' => $cust_main,
116               )
117     %>
118
119 % }
120
121 <TR>
122   <TH ALIGN="right">Contract end date </TD>
123   <TD COLSPAN=6>
124     <% include('/elements/input-date-field.html',{
125                 'name'      => 'contract_end',
126                 'format'    => $date_format,
127                 'value'     => '',
128                 'noinit'    => 1,
129                 }) %>
130   </TD>
131 </TR>
132
133 </TABLE>
134
135 % unless ( $cgi->param('lock_locationnum') ) {
136
137   <% include( '/elements/standardize_locations.html',
138                 'form'       => "OrderPkgForm",
139                 'onlyship'   => 1,
140                 'no_company' => 1,
141                 'callback'   => 'document.OrderPkgForm.submit();',
142             )
143   %>
144
145 % }
146
147 <BR>
148 % my $onclick = $cgi->param('lock_locationnum')
149 %                 ? 'document.OrderPkgForm.submit()'
150 %                 : 'standardize_new_location()';
151 <INPUT NAME="submitButton"
152        TYPE="button"
153        VALUE="Order Package"
154        onClick = "this.disabled=true; <% $onclick %>;"
155        <% $pkgpart ? '' : 'DISABLED' %>
156 >
157
158 </FORM>
159 </BODY>
160 </HTML>
161 <%init>
162
163 my $curuser = $FS::CurrentUser::CurrentUser;
164
165 die "access denied"
166   unless $curuser->access_right('Order customer package');
167
168 my $conf = new FS::Conf;
169 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
170
171 $cgi->param('custnum') =~ /^(\d+)$/ or die "no custnum";
172 my $custnum = $1;
173 my $cust_main = qsearchs({
174   'table'     => 'cust_main',
175   'hashref'   => { 'custnum' => $custnum },
176   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
177 });
178
179 my $part_pkg = '';
180 if ( $cgi->param('lock_pkgpart') ) {
181   $part_pkg = qsearchs({
182     'table'     => 'part_pkg',
183     'hashref'   => { 'pkgpart' => scalar($cgi->param('lock_pkgpart')) },
184     'extra_sql' => ' AND '. FS::part_pkg->agent_pkgs_sql( $cust_main->agent ),
185   })
186     or die "unknown pkgpart ". $cgi->param('lock_pkgpart');
187 }
188
189 my $pkgpart = $part_pkg ? $part_pkg->pkgpart : scalar($cgi->param('pkgpart'));
190
191 my $format = $date_format. ' %T %z (%Z)'; #false laziness w/REAL_cust_pkg.cgi?
192 my $start_date = '';
193 if( ! $conf->exists('order_pkg-no_start_date') ) {
194   $start_date = $cust_main->next_bill_date;
195   $start_date = $start_date ? time2str($format, $start_date) : '';
196 }
197
198 my $svcpart = scalar($cgi->param('svcpart'));
199
200 </%init>