X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fdiscount.pm;h=8afeb2e0c06b4935a896feb12698553804ce4e7d;hp=558d0f8814fb19dfe99b7475eaa635b740801d49;hb=ad7f49821d40ffd099a45acc32ba91e0e211aede;hpb=0fcdc36642e1430f02ebf5326740e231883bd41f diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm index 558d0f881..8afeb2e0c 100644 --- a/FS/FS/discount.pm +++ b/FS/FS/discount.pm @@ -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') @@ -126,28 +136,38 @@ sub check { $self->SUPER::check; } +=item description_short + =item description Returns a text description incorporating the amount, percent and months fields. +description_short omits term information + =cut -sub description { +sub description_short { my $self = shift; my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; - my $desc = ''; + my $desc = $self->name ? $self->name.': ' : ''; $desc .= $money_char. sprintf('%.2f/month ', $self->amount) if $self->amount > 0; $desc .= $self->percent. '% ' if $self->percent > 0; - $desc .= 'for '. $self->months. ' months' if $self->months; $desc; } +sub description { + my $self = shift; + my $desc = $self->description_short; + $desc .= ' for '. $self->months. ' months' if $self->months; + $desc; +} + =back =head1 BUGS