stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / elements / tr-select-reason.html
index 1258746..9a43022 100755 (executable)
@@ -6,8 +6,7 @@ Example:
 
     #required 
     'field'         => 'reasonnum',
-    'reason_class'  => 'C', # currently 'C', 'R', 'F', 'S' or 'X'
-                           # for cancel, credit, refund, suspend or void credit
+    'reason_class'  => 'C', # one of those in %FS::reason_type::class_name
 
     #recommended
     'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors
@@ -121,6 +120,13 @@ Example:
       &>
 %   } # scalar(@types)
 
+%   if ( $class eq 'C' ) {
+      <& tr-checkbox.html,
+        label => 'Credit the unused portion of service when canceling',
+        field => $id.'_new_unused_credit',
+        value => 'Y'
+      &>
+%   }
 %   if ( $class eq 'S' ) {
       <& tr-checkbox.html,
         label => 'Credit the unused portion of service when suspending',
@@ -182,27 +188,14 @@ my $class = $opt{'reason_class'};
 my $init_reason;
 if ( $opt{'cgi'} ) {
   $init_reason = $opt{'cgi'}->param($name);
-} else {
-  $init_reason = $opt{'curr_value'};
 }
+$init_reason ||= $opt{'curr_value'};
 
 my $id = $opt{'id'} || $name;
 $id =~ s/\./_/g; # for edit/part_event
 
-my $add_access_right;
-if ($class eq 'C') {
-  $add_access_right = 'Add on-the-fly cancel reason';
-} elsif ($class eq 'S') {
-  $add_access_right = 'Add on-the-fly suspend reason';
-} elsif ($class eq 'R') {
-  $add_access_right = 'Add on-the-fly credit reason';
-} elsif ($class eq 'F') {
-  $add_access_right = 'Add on-the-fly refund reason';
-} elsif ($class eq 'X') {
-  $add_access_right = 'Add on-the-fly void credit reason';
-} else {
-  die "illegal class: $class";
-}
+my $add_access_right = $FS::reason_type::class_add_access_right{$class}
+  or die "unknown class: $class";
 
 my @reasons = qsearch({
   'table'           => 'reason',