-<% include('/elements/header-popup.html', 'Order new package' ) %>
-
-<% include('/elements/xmlhttp.html',
- 'url' => $p.'misc/location.cgi',
- 'subs' => [ 'get_location' ],
- )
-%>
-
-<SCRIPT TYPE="text/javascript">
-
- function locationnum_changed(what) {
- var locationnum = what.options[what.selectedIndex].value;
- if ( locationnum == -1 ) {
-
-% for (@location_fields) {
- what.form.<%$_%>.disabled = false;
- what.form.<%$_%>.style.backgroundColor = '#ffffff';
-% }
-
- what.form.address1.value = '';
- what.form.address2.value = '';
- what.form.city.value = '';
- what.form.zip.value = '';
- changeSelect(what.form.country, <% $countrydefault |js_string %>);
-%#shouldn't we sleep/wait here until the state dropdown is updated?
-%#(is it even triggered???)
- changeSelect(what.form.state, <% $statedefault |js_string %>);
- what.form.county.selectedIndex = 0;
-
- } else {
-
- if ( locationnum == 0 ) {
- what.form.address1.value = <% $cust_main->address1 |js_string %>;
- what.form.address2.value = <% $cust_main->address2 |js_string %>;
- what.form.city.value = <% $cust_main->city |js_string %>;
- what.form.zip.value = <% $cust_main->zip |js_string %>;
- changeSelect(what.form.country, <% $cust_main->country | js_string %> );
-%#shouldn't we sleep/wait here until the state dropdown is updated?
-%#(is it even triggered???)
- changeSelect(what.form.state, <% $cust_main->state | js_string %> );
-%#shouldn't we sleep/wait here until the county dropdown is updated?
-%#(is it even triggered???)
- changeSelect(what.form.county, <% $cust_main->county | js_string %> );
- } else {
- get_location( locationnum, update_location );
- }
-
-%#sleep/wait until dropdowns are updated?
-% for (@location_fields) {
- what.form.<%$_%>.disabled = true;
- what.form.<%$_%>.style.backgroundColor = '#dddddd';
-% }
-
- }
- }
-
- function changeSelect(what, value) {
- for ( var i=0; i<what.length; i++) {
- if ( what.options[i].value == value ) {
- what.selectedIndex = i;
- }
- }
- }
-
- function update_location( hash ) {
- alert(hash);
- }
-
- function enable_order_pkg () {
- if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
- document.OrderPkgForm.submit.disabled = false;
- } else {
- document.OrderPkgForm.submit.disabled = true;
- }
- }
-
-</SCRIPT>
-
-<% include('/elements/error.html') %>
+<& /elements/header-popup.html, {
+ 'title' => $quotationnum ? mt('Add package to quotation')
+ : mt('Order new package'),
+ 'nobr' => 1,
+ }
+&>
+
+<& /elements/xmlhttp.html,
+ 'url' => $p.'misc/xmlhttp-part_pkg_usageprice.html',
+ 'subs' => [ 'get_part_pkg_usageprice' ],
+&>
+
+<& /elements/init_calendar.html &>
+
+<SCRIPT TYPE="text/javascript" SRC="../elements/order_pkg.js"></SCRIPT>
+
+<& /elements/error.html &>
<FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
-<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
-
-<% ntable("#cccccc", 2) %>
-<TR>
- <TH ALIGN="right">Package</TH>
- <TD COLSPAN=7>
- <% include('/elements/select-cust-part_pkg.html',
- 'curr_value' => $pkgpart,
- 'cust_main' => $cust_main,
- 'onchange' => 'enable_order_pkg',
- )
- %>
- </TD>
-</TR>
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
+<INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
+<INPUT TYPE="hidden" NAME="qualnum" VALUE="<% scalar($cgi->param('qualnum')) |h %>">
+<INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
+% if ( $svcpart ) {
+ <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
+% }
+
+% my $num_sales = $agent->num_sales;
+% my $conf_pkg_referral = $conf->exists('pkg_referral');
+% my $show_sales = $num_sales && $conf_pkg_referral;
+% my $show_sales_table = $num_sales || $conf_pkg_referral;
+
+% if ( $show_sales ) {
+ <FONT CLASS="fsinnerbox-title"><% mt('Sales') |h %></FONT>
+% }
+% if ( $show_sales_table ) {
+ <% ntable("#cccccc") %>
+% }
+
+<& /elements/tr-select-sales.html,
+ 'curr_value' => scalar($cgi->param('salesnum')),
+ 'agentnum' => $agent->agentnum,
+ 'th' => 1,
+&>
% if ( $conf->exists('pkg_referral') ) {
- <% include('/elements/tr-select-part_referral.html',
+ <& /elements/tr-select-part_referral.html,
'curr_value' => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,
'disable_empty' => 1,
'multiple' => $conf->exists('pkg_referral-multiple'),
'colspan' => 7,
- )
- %>
+ &>
+% }
+
+% if ( $show_sales_table ) {
+ </TABLE><BR>
+% }
+
+<FONT CLASS="fsinnerbox-title"><% mt('Package') |h %></FONT>
+<% ntable("#cccccc") %>
+
+% if ( $part_pkg ) {
+ <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
+ <TR>
+ <TH ALIGN="right"><% mt('Package') |h %></TH>
+ <TD COLSPAN=6><% $part_pkg->pkg_comment |h %></TD>
+ </TR>
+% } else {
+ <& /elements/tr-select-cust-part_pkg.html,
+ 'curr_value' => $pkgpart,
+ 'classnum' => -1,
+ 'cust_main' => $cust_main,
+ 'prospect_main' => $prospect_main,
+ &>
+% }
+
+<& /elements/tr-input-pkg-quantity.html, curr_value => $quantity &>
+
+% unless ( $quotationnum ) {
+
+% if ( $cust_main && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
+% my $what = lc(FS::payby->shortname($cust_main->payby));
+ <TR>
+ <TH ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TH>
+ <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
+ </TR>
+% }
+
+ <TR>
+ <TH ALIGN="right"><% mt('Start') |h %> </TD>
+ <TD COLSPAN=6>
+ <INPUT TYPE="radio" NAME="start" ID="start_now" VALUE="" <% $cgi->param('start') eq '' ? 'CHECKED' : ''%>>Now
+  
+ <INPUT TYPE="radio" NAME="start" ID="start_on_hold" VALUE="on_hold" <% $cgi->param('start') eq 'on_hold' ? 'CHECKED' : ''%>>On hold
+  
+ <INPUT TYPE="radio" NAME="start" ID="start_on_date" VALUE="on_date" <% $cgi->param('start') eq 'date' ? 'CHECKED' : ''%>>On date
+
+ <& /elements/input-date-field.html,{
+ 'name' => 'start_date',
+ 'format' => $date_format,
+ 'value' => '',
+ 'noinit' => 1,
+ } &>
+ </TD>
+ </TR>
+
+ <TR>
+ <TH ALIGN="right"><% mt('Contract end date') |h %> </TD>
+ <TD COLSPAN=6>
+ <& /elements/input-date-field.html,{
+ 'name' => 'contract_end',
+ 'format' => $date_format,
+ 'value' => '',
+ 'noinit' => 1,
+ } &>
+ </TD>
+ </TR>
+
+% }
+
+</TABLE><BR>
+
+%#so:
+%# - hide until you selecdt a pacakge with add-ons
+%# -lookup and display the available add-ons when
+%# -add them to the (recur if there is one, otherwise setup) price and display magically like processing fees do on edit/cust_pay.cgi
+
+%# better label?
+<FONT CLASS = "fsinnerbox-title"
+ ID = "cust_pkg_usageprice_title"
+ STYLE = "display:none"
+><% mt('Usage add-ons') |h %></FONT>
+<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 ID="cust_pkg_usageprice_table">
+
+</TABLE>
+<BR>
+
+% my $discount_cust_pkg = $curuser->access_right('Discount customer package');
+% my $waive_setup_fee = $curuser->access_right('Waive setup fee');
+%
+% if ( $discount_cust_pkg || $waive_setup_fee ) {
+ <FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
+ <% ntable("#cccccc") %>
+
+% if ( $waive_setup_fee ) {
+ <TR>
+ <TH ALIGN="right"><% mt('Waive setup fee') |h %> </TH>
+ <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="waive_setup" VALUE="Y"></TD>
+ </TR>
+% }
+
+% if ( $discount_cust_pkg ) {
+ <& /elements/tr-select-discount.html,
+ 'element_etc' => 'DISABLED',
+ 'colspan' => 7,
+ 'cgi' => $cgi,
+ &>
+% }
+
+ </TABLE><BR>
+
% }
-<TR>
- <TH ALIGN="right">Service location</TH>
- <TD COLSPAN=7>
- <SELECT NAME="locationnum" onChange="locationnum_changed(this);">
- <OPTION VALUE="">(default service address)
-% foreach my $loc ( $cust_main->cust_location ) {
- <OPTION VALUE="<% $loc->locationnum %>"
- <% $locationnum == $loc->locationnum ? 'SELECTED' : '' %>
- ><% $loc->line |h %>
-% }
- <OPTION VALUE="-1"
- <% $locationnum == -1 ? 'SELECTED' : '' %>
- >Add new location
- </SELECT>
- </TD>
-</TR>
-
-<% include('/elements/location.html',
- 'object' => $cust_location,
- #'onchange' ? probably not
- 'disabled' => ( $locationnum == -1 ? '' : 'DISABLED' ),
- 'no_asterisks' => 1,
- )
-%>
+
+% my $lock_locationnum = scalar($cgi->param('lock_locationnum'));
+% my $contact_title = $lock_locationnum ? 'Contact'
+% : 'Contact and Location';
+<FONT CLASS="fsinnerbox-title"><% mt($contact_title) |h %></FONT>
+<% ntable("#cccccc") %>
+
+<& /elements/tr-select-contact.html,
+ 'cgi' => $cgi,
+ 'cust_main' => $cust_main,
+ 'prospect_main' => $prospect_main,
+&>
+
+% if ( $cgi->param('lock_locationnum') ) {
+
+ <INPUT TYPE = "hidden"
+ NAME = "locationnum"
+ ID = "locationnum"
+ VALUE = "<% scalar($cgi->param('lock_locationnum')) |h %>"
+ >
+
+% } else {
+
+ <& /elements/tr-select-cust_location.html,
+ 'cgi' => $cgi,
+ 'cust_main' => $cust_main,
+ 'prospect_main' => $prospect_main,
+ &>
+
+% }
</TABLE>
+% unless ( $cgi->param('lock_locationnum') ) {
+
+ <& /elements/standardize_locations.html,
+ 'form' => "OrderPkgForm",
+ 'callback' => 'document.OrderPkgForm.submit()',
+ 'with_census' => 1,
+ 'with_census_functions' => 1,
+ &>
+
+% }
+
<BR>
-<INPUT NAME="submit" TYPE="submit" VALUE="Order Package" <% $pkgpart ? '' : 'DISABLED' %>>
+% my $onclick = $cgi->param('lock_locationnum')
+% ? 'document.OrderPkgForm.submit()'
+% : 'standardize_new_location()';
+<INPUT NAME = "submitButton"
+ TYPE = "button"
+ VALUE = "<% mt("Order Package") |h %>"
+ onClick = "this.disabled=true; <% $onclick %>;"
+ <% $pkgpart ? '' : 'DISABLED' %>
+>
</FORM>
</BODY>
</HTML>
-<%once>
-
-my @location_fields = qw( address1 address2 city county state zip country );
-
-</%once>
<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Order customer package');
+ unless $curuser->access_right('Order customer package');
my $conf = new FS::Conf;
-my $countrydefault = $conf->config('countrydefault') || 'US';
-my $statedefault = $conf->config('statedefault')
- || ($countrydefault eq 'US' ? 'CA' : '');
-
-$cgi->param('custnum') =~ /^(\d+)$/ or die "no custnum";
-my $custnum = $1;
-my $cust_main = qsearchs({
- 'table' => 'cust_main',
- 'hashref' => { 'custnum' => $custnum },
- 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
-});
-
-my $pkgpart = scalar($cgi->param('pkgpart'));
-
-$cgi->param('locationnum') =~ /^(\d*)$/ or die "illegal locationnum";
-my $locationnum = $1;
-my $cust_location;
-if ( $locationnum ) {
- $cust_location = qsearchs('cust_location', { 'locationnum' => $locationnum } )
- or die "unknown locationnum";
-} else {
- $cust_location = new FS::cust_location;
- if ( $cgi->param('error') && $locationnum == -1 ) {
- $cust_location->$_( $cgi->param($_) ) foreach @location_fields;
- } else {
- $cust_location->$_( $cust_main->$_() ) foreach @location_fields;
- }
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
+
+my $cust_main = '';
+if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
+ my $custnum = $1;
+ $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'custnum' => $custnum },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+ });
+}
+
+my $prospect_main = '';
+if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
+ my $prospectnum = $1;
+ $prospect_main = qsearchs({
+ 'table' => 'prospect_main',
+ 'hashref' => { 'prospectnum' => $prospectnum },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+ });
+}
+
+my $quotationnum = '';
+if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
+ $quotationnum = $1;
+}
+
+die 'no custnum or prospectnum' unless $cust_main || $prospect_main;
+
+my $agent = $cust_main ? $cust_main->agent
+ : $prospect_main->agent;
+
+my $part_pkg = '';
+if ( $cgi->param('lock_pkgpart') ) {
+ $part_pkg = qsearchs({
+ 'table' => 'part_pkg',
+ 'hashref' => { 'pkgpart' => scalar($cgi->param('lock_pkgpart')) },
+ 'extra_sql' => ' AND '. FS::part_pkg->agent_pkgs_sql($agent),
+ })
+ or die "unknown pkgpart ". $cgi->param('lock_pkgpart');
+}
+
+my $pkgpart = $part_pkg ? $part_pkg->pkgpart : scalar($cgi->param('pkgpart'));
+
+my $quantity = 1;
+if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
+ $quantity = $1;
}
+my $format = $date_format. ' %T %z (%Z)'; #false laziness w/REAL_cust_pkg.cgi?
+
+my $svcpart = scalar($cgi->param('svcpart'));
+
</%init>