discounts, RT#6679
authorivan <ivan>
Sat, 30 Jan 2010 20:05:16 +0000 (20:05 +0000)
committerivan <ivan>
Sat, 30 Jan 2010 20:05:16 +0000 (20:05 +0000)
httemplate/elements/select-part_pkg.html
httemplate/elements/select-table.html
httemplate/elements/tr-select-cust-part_pkg.html
httemplate/misc/cust-part_pkg.cgi
httemplate/misc/order_pkg.html
httemplate/view/cust_main/order_pkg_link.html [new file with mode: 0644]
httemplate/view/cust_main/packages.html

index 6b697ab..e11f020 100644 (file)
@@ -23,6 +23,7 @@ Example:
               'empty_label'    => 'Select package', #should this be the default?
               'label_callback' => sub { shift->pkg_comment },
               'hashref'        => \%hash,
+              'extra_option_attributes' => [ 'can_discount' ],
               %opt,
           )
 %>
index 45585a8..4d8d9a9 100644 (file)
@@ -45,6 +45,10 @@ Example:
                             #<SELECT> element
     'onchange'       => '', #javascript code
 
+    #params (well, a param) controlling the <OPTION>s
+    'extra_option_attributes' => [ 'field' ], #field or method in $table objects
+                                              #(are prefixed w/data- per HTML5)
+
     #special return options
     'js_only'      => 0, #set true to return only the JS portions (i.e. nothing)
     'html_only'    => 0, #set true to return only the HTML portions (no-op, i.e. return everything)
@@ -89,6 +93,9 @@ Example:
             <% $opt{'all_selected'} || ref($value) && $value->{$recvalue} || $value == $recvalue
                ? ' SELECTED' : ''
             %>
+%           foreach my $att ( @{ $opt{'extra_option_attributes'} } ) {
+              data-<% $att %>="<% $record->$att() |h %>"
+%           }
     ><% $opt{'label_showkey'} ? "$recvalue: " : '' %>
      <% $opt{'label_callback'}
           ? &{ $opt{'label_callback'} }( $record )
@@ -106,6 +113,8 @@ my( %opt ) = @_;
 warn "elements/select-table.html: \n". Dumper(%opt)
   if exists $opt{debug} && $opt{debug};
 
+$opt{'extra_option_attributes'} ||= [];
+
 my $onchange = '';
 if ( $opt{'onchange'} ) {
   $onchange = $opt{'onchange'};
index 75f1f6f..69400f1 100644 (file)
@@ -8,8 +8,9 @@
 
   <SCRIPT TYPE="text/javascript">
 
-    function opt(what,value,text) {
+    function part_pkg_opt(what,value,text,can_discount) {
       var optionName = new Option(text, value, false, false);
+      optionName.setAttribute('data-can_discount', can_discount);
       var length = what.length;
       what.options[length] = optionName;
     }
 
       what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
       what.form.submit.disabled = true; //disable the submit button
+      var discountnum = what.form.discountnum;
+      if ( discountnum ) {
+        discountnum.disabled = true; //disable discount dropdown
+      }
 
       classnum = what.options[what.selectedIndex].value;
 
         // add the new packages
         opt(what.form.pkgpart, '', 'Select package');
         var packagesArray = eval('(' + part_pkg + ')' );
-        for ( var s = 0; s < packagesArray.length; s=s+2 ) {
+        for ( var s = 0; s < packagesArray.length; s=s+3 ) {
           var packagesLabel = packagesArray[s+1];
-          opt(what.form.pkgpart, packagesArray[s], packagesLabel);
+          var can_discount  = packagesArray[s+2];
+          part_pkg_opt(
+            what.form.pkgpart, packagesArray[s], packagesLabel, can_discount
+          );
         }
 
         what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
index 974ac0e..524799c 100644 (file)
@@ -23,7 +23,7 @@ my @part_pkg = qsearch({
   'order_by'  => 'ORDER BY pkg',
 });
 
-my @return = map  { $_->pkgpart => $_->pkg_comment }
+my @return = map  { ( $_->pkgpart, $_->pkg_comment, $_->can_discount ); }
              #sort { $a->pkg_comment cmp $b->pkg_comment }
              @part_pkg;
 
index 684f94e..e05205b 100644 (file)
   function enable_order_pkg () {
     if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
       document.OrderPkgForm.submit.disabled = false;
+      if ( document.OrderPkgForm.pkgpart.options[document.OrderPkgForm.pkgpart.selectedIndex].getAttribute('data-can_discount') == 1 ) {
+        document.OrderPkgForm.discountnum.disabled = false;
+      } else {
+        document.OrderPkgForm.discountnum.disabled = true;
+      }
     } else {
       document.OrderPkgForm.submit.disabled = true;
+      document.OrderPkgForm.discountnum.disabled = true;
     }
   }
 
 </SCRIPT>
 
 % if ( $curuser->access_right('Discount customer package') ) {
-  <% include('/elements/tr-select-discount.html') %>
+  <% include('/elements/tr-select-discount.html',
+               'element_etc' => 'DISABLED',
+            )
+  %>
 % }
 
 % if ( $conf->exists('pkg_referral') ) {
diff --git a/httemplate/view/cust_main/order_pkg_link.html b/httemplate/view/cust_main/order_pkg_link.html
new file mode 100644 (file)
index 0000000..9a12019
--- /dev/null
@@ -0,0 +1,16 @@
+<% include( '/elements/popup_link-cust_main.html',
+              'action'      => $p. 'misc/order_pkg.html',
+              'label'       => 'Order&nbsp;new&nbsp;package',
+              'actionlabel' => 'Order new package',
+              'color'       => '#333399',
+              'cust_main'   => $cust_main,
+              'closetext'   => 'Close',
+              'width'       => 763,
+              'height'      => 408,
+          )
+%>
+<%init>
+
+my($cust_main) = @_;
+
+</%init>
index 31aa262..3ac4861 100755 (executable)
@@ -1,17 +1,7 @@
 % my $s = 0;
 % if ( $curuser->access_right('Order customer package') ) { 
   <% $s++ ? ' | ' : '' %>
-  <% include( '/elements/popup_link-cust_main.html',
-                'action'      => $p. 'misc/order_pkg.html',
-                'label'       => 'Order&nbsp;new&nbsp;package',
-                'actionlabel' => 'Order new package',
-                'color'       => '#333399',
-                'cust_main'   => $cust_main,
-                'closetext'   => 'Close',
-                'width'       => 763,
-                'height'      => 350,
-            )
-  %>
+  <% include('order_pkg_link.html', $cust_main) %>
 % } 
 
 % if ( $curuser->access_right('One-time charge')