X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fdiscount.pm;h=6fc3391caec21acffc19e5af8a1bd4d0fd2bdd06;hb=3c54c844c665ed108c7892a154fd3972fab1f3e5;hp=6771510d0c249c415e2adfe62b943e0afb012cd6;hpb=4cacb3fa439b56fc7c9a742b69ec3f6ffd660433;p=freeside.git diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm index 6771510d0..6fc3391ca 100644 --- a/FS/FS/discount.pm +++ b/FS/FS/discount.pm @@ -54,6 +54,11 @@ months disabled +=item setup - apply discount to setup fee (not just to recurring fee) + +If the discount is based on a percentage, then the % will be applied to the +setup and recurring portions. + =back =head1 METHODS @@ -113,6 +118,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') @@ -120,9 +135,21 @@ sub check { || $self->ut_float('percent') #actually decimal, but this will do || $self->ut_floatn('months') #actually decimal, but this will do || $self->ut_enum('disabled', [ '', 'Y' ]) + || $self->ut_enum('setup', [ '', 'Y' ]) ; 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; } @@ -155,6 +182,7 @@ sub description { my $self = shift; my $desc = $self->description_short; $desc .= ' for '. $self->months. ' months' if $self->months; + $desc .= ', applies to setup' if $self->setup; $desc; }