summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/edit/process/change-cust_pkg.html11
-rw-r--r--httemplate/elements/select-discount.html36
-rwxr-xr-xhttemplate/misc/change_pkg.cgi32
3 files changed, 77 insertions, 2 deletions
diff --git a/httemplate/edit/process/change-cust_pkg.html b/httemplate/edit/process/change-cust_pkg.html
index e1b220e51..0b36e9053 100644
--- a/httemplate/edit/process/change-cust_pkg.html
+++ b/httemplate/edit/process/change-cust_pkg.html
@@ -40,6 +40,12 @@ if ( $cgi->param('locationnum') == -1 ) {
$change{'cust_location'} = $cust_location;
}
+my %discount = (discountnum => $cgi->param('discountnum'));
+if (%discount) {
+ $discount{$_} = $cgi->param("discountnum_$_")
+ for qw(_type amount months percent setup);
+}
+
my $error;
my $now = time;
if (defined($cgi->param('contract_end'))) {
@@ -56,6 +62,7 @@ unless ($error) {
} else {
# schedule the change
$change{'start_date'} = $date;
+ $change{discount} = \%discount if %discount;
$error = $cust_pkg->change_later(\%change);
}
} else {
@@ -74,9 +81,11 @@ unless ($error) {
%change = ( 'cust_pkg' => $change_to );
}
}
-
+
# do a package change right now
my $pkg_or_error = $cust_pkg->change( \%change );
+ $pkg_or_error->change_discount(\%discount)
+ if ref $pkg_or_error && $discount{discountnum} =~ /$-?\d+$/;
$error = ref($pkg_or_error) ? '' : $pkg_or_error;
}
}
diff --git a/httemplate/elements/select-discount.html b/httemplate/elements/select-discount.html
index 3a267ed08..4bbdc661a 100644
--- a/httemplate/elements/select-discount.html
+++ b/httemplate/elements/select-discount.html
@@ -6,6 +6,7 @@
'empty_label' => '(none)',
'hashref' => $hashref,
'post_options' => $post_options,
+ 'label_callback' => $label_callback,
%opt,
)
%>
@@ -22,9 +23,42 @@ my $curuser = $FS::CurrentUser::CurrentUser;
my $hashref = $opt{hashref} || { 'disabled' => '' };
my $post_options = [];
+
+# If a 'custom' discount is applied to existing cust_pkg,
+# also add that option to the selectbox
+my $pkgnum = $cgi ? $cgi->param('pkgnum') : undef;
+if ($pkgnum) {
+
+ # Does pkgnum have a custom discount?
+ my $cust_pkg_discount = qsearchs(cust_pkg_discount => {
+ disabled => '',
+ pkgnum => $pkgnum,
+ });
+
+ if ($cust_pkg_discount) {
+ my $discount = qsearchs(discount => {
+ discountnum => $cust_pkg_discount->discountnum,
+ disabled => 'Y',
+ });
+ if ($discount) {
+ my $descr = $opt{carry_value} eq $discount->discountnum
+ ? $discount->description.' [Continue existing discount]'
+ : $discount->description;
+ push @$post_options, $discount->discountnum, $descr;
+ }
+ }
+}
+
push @$post_options, -1 => 'Custom discount'
if $curuser->access_right('Custom discount customer package')
&& ! $opt{disable_custom_discount};
-</%init>
+my $label_callback = sub {
+ my $rec = shift;
+ if ( $opt{carry_value} eq $rec->discountnum ) {
+ return $rec->description.' [Continue existing discount]';
+ }
+ return $rec->description;
+};
+</%init>
diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi
index 94f32e699..f5b807566 100755
--- a/httemplate/misc/change_pkg.cgi
+++ b/httemplate/misc/change_pkg.cgi
@@ -1,5 +1,17 @@
<& /elements/header-popup.html, mt($title) &>
+<SCRIPT TYPE="text/javascript">
+
+ function enable_discount_pkg () {
+ if ( document.DiscountPkgForm.discountnum.selectedIndex > 0 ) {
+ document.DiscountPkgForm.submit.disabled = false;
+ } else {
+ document.DiscountPkgForm.submit.disabled = false;
+ }
+ }
+
+</SCRIPT>
+
<SCRIPT TYPE="text/javascript" SRC="../elements/order_pkg.js"></SCRIPT>
<& /elements/error.html &>
@@ -86,6 +98,16 @@
</TR>
% }
+% if ( $discount_cust_pkg ) {
+<% include('/elements/tr-select-discount.html',
+ 'empty_label' => 'Select discount',
+ #'onchange' => 'enable_discount_pkg()',
+ 'cgi' => $cgi,
+ 'carry_value' => $carry_value,
+ 'td_width' => '125',
+ #'setup_only' => $setup_only,
+ ) %>
+% }
</TABLE><BR>
% }
@@ -151,6 +173,16 @@ my $title = "Change Package";
my $use_contract_end = $cust_pkg->get('contract_end') ? 1 : 0;
+# Pass previous discountnum to change screen
+my $cust_pkg_discount = qsearchs(cust_pkg_discount => {
+ disabled => '',
+ pkgnum => $cust_pkg->pkgnum,
+});
+my $carry_value =
+ $cust_pkg_discount
+ ? $cust_pkg_discount->discountnum
+ : undef;
+
# if there's already a package change ordered, preload it
if ( $cust_pkg->change_to_pkgnum ) {
my $change_to = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);