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
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')
|| $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;
}
+=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 .= ', applies to setup' if $self->setup;
+ $desc;
+}
+
=back
=head1 BUGS