X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fdiscount.pm;h=88cbdd41cba75d4c1d2e499c749d262ec13d8fc5;hp=8afeb2e0c06b4935a896feb12698553804ce4e7d;hb=395cc72629d31c8dcd138acf423e66d2d73d89d2;hpb=624b2d44625f69d71175c3348cae635d580c890b diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm index 8afeb2e0c..88cbdd41c 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 @@ -130,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,7 +172,10 @@ sub description_short { my $desc = $self->name ? $self->name.': ' : ''; $desc .= $money_char. sprintf('%.2f/month ', $self->amount) if $self->amount > 0; - $desc .= $self->percent. '% ' + + ( my $percent = $self->percent ) =~ s/\.0+$//; + $percent =~ s/(\.\d*[1-9])0+$/$1/; + $desc .= $percent. '% ' if $self->percent > 0; $desc; @@ -164,7 +184,13 @@ sub description_short { sub description { my $self = shift; my $desc = $self->description_short; - $desc .= ' for '. $self->months. ' months' if $self->months; + + ( my $months = $self->months ) =~ s/\.0+$//; + $months =~ s/(\.\d*[1-9])0+$/$1/; + $desc .= " for $months months" if $months; + + $desc .= ', applies to setup' if $self->setup; + $desc; }