summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2013-10-24 00:40:05 -0700
committerIvan Kohler <ivan@freeside.biz>2013-10-24 00:40:05 -0700
commitec4ae54938488e037977066b28c6a325272b16fc (patch)
tree104983666ce725572b51795ee1954baa3d626fca /FS/FS
parentac67ba5d343e1e704b9e706e2aa19ecd979a5863 (diff)
discount classes, RT#24911
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/Mason.pm1
-rw-r--r--FS/FS/Schema.pm13
-rw-r--r--FS/FS/discount.pm39
3 files changed, 42 insertions, 11 deletions
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 398d785..fc25a86 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -357,6 +357,7 @@ if ( -e $addl_handler_use_file ) {
use FS::invoice_conf;
use FS::cable_provider;
use FS::cust_credit_void;
+ use FS::discount_class;
# Sammath Naur
if ( $FS::Mason::addl_handler_use ) {
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index cbb50e0..fcc2092 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2008,6 +2008,7 @@ sub tables_hashref {
'columns' => [
'discountnum', 'serial', '', '', '', '',
#'agentnum', 'int', 'NULL', '', '', '',
+ 'classnum', 'int', 'NULL', '', '', '',
'name', 'varchar', 'NULL', $char_d, '', '',
'amount', @money_type, '', '',
'percent', 'decimal', '', '7,4', '', '',
@@ -2021,6 +2022,18 @@ sub tables_hashref {
'index' => [], # [ 'agentnum' ], ],
},
+ 'discount_class' => {
+ 'columns' => [
+ 'classnum', 'serial', '', '', '', '',
+ 'classname', 'varchar', '', $char_d, '', '',
+ #'categorynum', 'int', 'NULL', '', '', '',
+ 'disabled', 'char', 'NULL', 1, '', '',
+ ],
+ 'primary_key' => 'classnum',
+ 'unique' => [],
+ 'index' => [ ['disabled'] ],
+ },
+
'cust_refund' => {
'columns' => [
'refundnum', 'serial', '', '', '', '',
diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm
index f6f9945..e66d78c 100644
--- a/FS/FS/discount.pm
+++ b/FS/FS/discount.pm
@@ -1,8 +1,9 @@
package FS::discount;
+use base qw( FS::Record );
use strict;
-use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs );
+use FS::discount_class;
=head1 NAME
@@ -130,6 +131,7 @@ sub check {
my $error =
$self->ut_numbern('discountnum')
+ || $self->ut_foreign_keyn('classnum', 'discount_class', 'classnum')
|| $self->ut_textn('name')
|| $self->ut_money('amount')
|| $self->ut_float('percent') #actually decimal, but this will do
@@ -140,16 +142,19 @@ 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) );
- }
+#causes "months must be integers greater than 1" errors when you go back and
+# try to edit an existing discount (because the months format as NN.000)
+#not worth whatever reason it came in with "prepayment discounts rt#5318" for
+# #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;
}
@@ -195,6 +200,18 @@ sub description {
$desc;
}
+sub classname {
+ my $self = shift;
+ my $discount_class = $self->discount_class;
+ $discount_class ? $discount_class->classname : '(none)';
+}
+
+sub discount_class {
+ my $self = shift;
+ qsearchs('discount_class', { 'classnum' => $self->classnum });
+}
+
+
=back
=head1 BUGS