hide start date on package order for specific package definitions, RT#13783
authorivan <ivan>
Thu, 11 Aug 2011 00:38:14 +0000 (00:38 +0000)
committerivan <ivan>
Thu, 11 Aug 2011 00:38:14 +0000 (00:38 +0000)
FS/FS/cust_pkg.pm
FS/FS/part_pkg.pm
FS/FS/part_pkg/delayed_Mixin.pm
FS/FS/part_pkg/flat.pm
httemplate/elements/order_pkg.js
httemplate/elements/select-part_pkg.html
httemplate/elements/tr-select-cust-part_pkg.html
httemplate/misc/cust-part_pkg.cgi
httemplate/misc/order_pkg.html

index 21c05f3..54e302e 100644 (file)
@@ -284,7 +284,7 @@ sub insert {
   }
 
   my $free_days = $part_pkg->option('free_days');
-  if ( $free_days && $part_pkg->option('delay_setup') ) { #&& !$self->start_date
+  if ( $free_days && $part_pkg->option('delay_setup',1) ) { #&& !$self->start_date
     my ($mday,$mon,$year) = (localtime(time) )[3,4,5];
     #my $start_date = ($self->start_date || timelocal(0,0,0,$mday,$mon,$year)) + 86400 * $free_days;
     my $start_date = timelocal(0,0,0,$mday,$mon,$year) + 86400 * $free_days;
index c485947..bad3853 100644 (file)
@@ -867,6 +867,8 @@ sub is_free {
 
 sub can_discount { 0; }
 
+sub can_start_date { 1; }
+
 sub freqs_href {
   # moved to FS::Misc to make this accessible to other packages
   # at initialization
index 027cfff..4228a4a 100644 (file)
@@ -25,7 +25,7 @@ use vars qw(%info);
 sub calc_setup {
   my($self, $cust_pkg, $time ) = @_;
 
-  unless ( $self->option('delay_setup') ) {
+  unless ( $self->option('delay_setup', 1) ) {
     my $d = $cust_pkg->bill || $time;
     $d += 86400 * $self->option('free_days');
     $cust_pkg->bill($d);
@@ -37,7 +37,7 @@ sub calc_setup {
 sub calc_remain {
   my ($self, $cust_pkg, %options) = @_;
 
-  unless ( $self->option('delay_setup') ) {
+  unless ( $self->option('delay_setup', 1) ) {
     my $last_bill = $cust_pkg->last_bill || 0;
     my $next_bill = $cust_pkg->getfield('bill') || 0;
     my $free_days = $self->option('free_days');
@@ -49,4 +49,6 @@ sub calc_remain {
   return $self->SUPER::calc_remain($cust_pkg, %options);
 }
 
+sub can_start_date { ! shift->option('delay_setup', 1) }
+
 1;
index c1690f8..0049bd7 100644 (file)
@@ -219,6 +219,8 @@ sub is_free_options {
 
 sub is_prepaid { 0; } #no, we're postpaid
 
+sub can_start_date { ! shift->option('start_1st', 1) }
+
 #XXX discounts only on recurring fees for now (no setup/one-time or usage)
 sub can_discount {
   my $self = shift;
index 2c13ed2..2f53e36 100644 (file)
@@ -1,8 +1,9 @@
-function enable_order_pkg () {
+function pkg_changed () {
   var form = document.OrderPkgForm;
   var discountnum = form.discountnum;
 
   if ( form.pkgpart.selectedIndex > 0 ) {
+
     form.submitButton.disabled = false;
     if ( discountnum ) {
       if ( form.pkgpart.options[form.pkgpart.selectedIndex].getAttribute('data-can_discount') == 1 ) {
@@ -11,6 +12,20 @@ function enable_order_pkg () {
         form.discountnum.disabled = true;
       }
     }
+
+    if ( form.pkgpart.options[form.pkgpart.selectedIndex].getAttribute('data-can_start_date') == 1 ) {
+      form.start_date_text.disabled = false;
+      form.start_date.style.backgroundColor = '#ffffff';
+      form.start_date_button.style.display = '';
+      form.start_date_button_disabled.style.display = 'none';
+      form.invoice_terms.disabled = true;
+    } else {
+      form.start_date_text.disabled = true;
+      form.start_date.style.backgroundColor = '#dddddd';
+      form.start_date_button.style.display = 'none';
+      form.start_date_button_disabled.style.display = '';
+    }
+
   } else {
     form.submitButton.disabled = true;
     if ( discountnum ) { form.discountnum.disabled = true; }
index 885bb80..439c4b5 100644 (file)
@@ -23,7 +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' ],
+              'extra_option_attributes' => [ 'can_discount', 'can_start_date' ],
               %opt,
           )
 %>
index e55cbee..767d232 100644 (file)
@@ -7,9 +7,10 @@
 
   <SCRIPT TYPE="text/javascript">
 
-    function part_pkg_opt(what,value,text,can_discount) {
+    function part_pkg_opt(what, value, text, can_discount, can_start_date) {
       var optionName = new Option(text, value, false, false);
-      optionName.setAttribute('data-can_discount', can_discount);
+      optionName.setAttribute('data-can_discount',   can_discount);
+      optionName.setAttribute('data-can_start_date', can_start_date);
       var length = what.length;
       what.options[length] = optionName;
     }
         // add the new packages
         opt(what.form.pkgpart, '', 'Select package');
         var packagesArray = eval('(' + part_pkg + ')' );
-        for ( var s = 0; s < packagesArray.length; s=s+3 ) {
-          var packagesLabel = packagesArray[s+1];
-          var can_discount  = packagesArray[s+2];
+        for ( var s = 0; s < packagesArray.length; s=s+4 ) {
+          var packagesLabel  = packagesArray[s+1];
+          var can_discount   = packagesArray[s+2];
+          var can_start_date = packagesArray[s+3];
           part_pkg_opt(
-            what.form.pkgpart, packagesArray[s], packagesLabel, can_discount
+            what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date
           );
         }
 
@@ -75,7 +77,7 @@
                  'curr_value' => $opt{'curr_value'}, #$pkgpart
                  'classnum'   => $opt{'classnum'},
                  'cust_main'  => $opt{'cust_main'},  #$cust_main
-                 'onchange'   => 'enable_order_pkg',
+                 'onchange'   => 'pkg_changed',
     &>
   </TD>
 </TR>
index 524799c..dcd033f 100644 (file)
@@ -23,8 +23,14 @@ my @part_pkg = qsearch({
   'order_by'  => 'ORDER BY pkg',
 });
 
-my @return = map  { ( $_->pkgpart, $_->pkg_comment, $_->can_discount ); }
-             #sort { $a->pkg_comment cmp $b->pkg_comment }
-             @part_pkg;
+my @return = map  { warn $_->can_start_date;
+                    ( $_->pkgpart,
+                      $_->pkg_comment,
+                      $_->can_discount,
+                      $_->can_start_date,
+                    );
+                  }
+                  #sort { $a->pkg_comment cmp $b->pkg_comment }
+                  @part_pkg;
 
 </%init>
index 4c7a02b..2332f20 100644 (file)
@@ -29,7 +29,6 @@
                  'curr_value' => $pkgpart,
                  'classnum'   => -1,
                  'cust_main'  => $cust_main,
-                 'onchange'   => 'enable_order_pkg',
     &>
 % }