Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / elements / tr-select-pkg-discount.html
index dc38cff..810e462 100644 (file)
@@ -3,10 +3,13 @@
 In order_pkg.html or similar:
 
 <& /elements/tr-select-pkg-discount.html,
-  curr_value_setup => ($cgi->param('setup_discountnum') || ''),
-  curr_value_recur => ($cgi->param('recur_discountnum') || ''),
-  disable_setup    => 0,
-  disable_recur    => 0,
+  curr_value_setup    => ($cgi->param('setup_discountnum') || ''),
+  curr_value_recur    => ($cgi->param('recur_discountnum') || ''),
+  disable_setup       => 0,
+  disable_recur       => 0,
+  disable_waive_setup => 0,
+  carry_value_setup   => $carry_setup_discountnum,
+  carry_value_recur   => $carry_recur_discountnum,
 &>
 
 This provides the following:
@@ -19,6 +22,8 @@ This provides the following:
   checkbox to waive setup fee.
 - Same for recurring fee, but without the "waive setup fee" stuff, obviously.
 - Custom recurring discounts also have an option for a duration in months.
+- When changing a package, the original package's discount option is
+  labeled in the select options
 
 "disable_setup" locks the setup discount, but will still show a static
 description if curr_value_setup is set. Likewise "disable_recur".
@@ -31,10 +36,10 @@ description if curr_value_setup is set. Likewise "disable_recur".
 %      and !$opt{disable_setup} )
 % {
 %   my $pre_options = [ '' => '(none)' ];
-%   if ( $curuser->access_right('Waive setup fee') ) {
-%     push @$pre_options, -2 => 'Waive setup fee';
-%   }
-<& tr-td-label.html, label => emt('Setup fee') &>
+%   push @$pre_options, -2 => 'Waive setup fee'
+%     if $curuser->access_right('Waive setup fee')
+%     && ! $opt{'disable_waive_setup'};
+<& tr-td-label.html, label => $opt{setup_label} || emt('Setup fee') &>
   <td>
     <& select-discount.html,
       field       => 'setup_discountnum',
@@ -46,6 +51,8 @@ description if curr_value_setup is set. Likewise "disable_recur".
       curr_value  => $opt{'curr_value_setup'},
       disable_empty => 1,
       pre_options => $pre_options,
+      also_show_option => $opt{carry_value_setup},
+      label_callback   => $opt{carry_value_setup} ? $carry_setup_sub : undef,
     &>
   </td>
 </tr>
@@ -68,7 +75,9 @@ description if curr_value_setup is set. Likewise "disable_recur".
 </tr>
 
 % } elsif ( $curuser->access_right('Waive setup fee')
-%           and !$opt{disable_setup} )
+%             && !$opt{disable_waive_setup}
+%             && !$opt{disable_setup}
+%         )
 % {
 
 <& tr-td-label.html, label => emt('Waive setup fee') &>
@@ -97,13 +106,15 @@ description if curr_value_setup is set. Likewise "disable_recur".
 % if ( $curuser->access_right('Discount customer package')
 %      and !$opt{disable_recur} ) {
 
-<& tr-td-label.html, label => emt('Recurring fee') &>
+<& tr-td-label.html, label => $opt{recur_label} || emt('Recurring fee') &>
   <td>
     <& select-discount.html,
       field       => 'recur_discountnum',
       id          => 'recur_discountnum',
       hashref     =>  { disabled => '' },
       curr_value  => $opt{'curr_value_recur'},
+      also_show_option => $opt{carry_value_recur},
+      label_callback   => $opt{carry_value_recur} ? $carry_recur_sub : undef,
     &>
 
   </td>
@@ -193,4 +204,18 @@ my %opt = (
 my $curuser = $FS::CurrentUser::CurrentUser;
 my $money_char = FS::Conf->new->config('money_char') || '$';
 
+# Change the label for the select-option when it matches the carryover
+# discountnum
+my $carry_recur_sub =  sub {
+  my ($rec) = @_;
+  $rec->discountnum eq $opt{carry_value_recur}
+    ? $rec->description() . ' [Continues existing discount]'
+    : $rec->description();
+};
+my $carry_setup_sub =  sub {
+  my ($rec) = @_;
+  $rec->discountnum eq $opt{carry_value_setup}
+    ? $rec->description() . ' [Continues existing discount]'
+    : $rec->description();
+};
 </%init>