eWay self-signup fixes
[freeside.git] / FS / FS / discount.pm
index 6771510..4f42c5b 100644 (file)
@@ -113,6 +113,16 @@ and replace methods.
 sub check {
   my $self = shift;
 
+  if ( $self->_type eq 'Select discount type' ) {
+    return 'Please select a discount type';
+  } elsif ( $self->_type eq 'Amount' ) {
+    $self->percent('0');
+    return 'Amount must be greater than 0' unless $self->amount > 0;
+  } elsif ( $self->_type eq 'Percentage' ) {
+    $self->amount('0.00');
+    return 'Percentage must be greater than 0' unless $self->percent > 0;
+  }
+
   my $error = 
     $self->ut_numbern('discountnum')
     || $self->ut_textn('name')
@@ -123,6 +133,17 @@ sub check {
   ;
   return $error if $error;
 
+  #discourage non-integer months for package discounts
+  if ($self->discountnum) {
+    my $sql =
+      "SELECT count(*) FROM part_pkg_discount WHERE part_pkg_discount.discountnum = ".
+      $self->discountnum;
+
+    my $count = $self->scalar_sql($sql); 
+    return "months must be integers greater than 1"
+      if ( $count && ($self->ut_number('months') || $self->months < 2) );
+  }
+    
   $self->SUPER::check;
 }