X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=c3734b54e3c58a54b344b317f7f55e9be08c56bf;hb=788c20506afc3475c02b05620b8bbb64150d22b7;hp=5cdca09ac8587cbbc1751f3be90f899bcf613cf1;hpb=2d5f9e43a60773a9b079e96c330cb9e0e089800a;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 5cdca09ac..c3734b54e 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -277,15 +277,7 @@ sub insert { ); if ( $self->discountnum ) { - #XXX new/custom discount case - my $cust_pkg_discount = new FS::cust_pkg_discount { - 'pkgnum' => $self->pkgnum, - 'discountnum' => $self->discountnum, - 'months_used' => 0, - 'end_date' => '', #XXX - 'otaker' => $self->otaker, - }; - my $error = $cust_pkg_discount->insert; + my $error = $self->insert_discount(); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -2303,6 +2295,44 @@ sub insert_reason { $cust_pkg_reason->insert; } +=item insert_discount + +Associates this package with a discount (see L, possibly +inserting a new discount on the fly (see L). + +Available options are: + +=over 4 + +=item discountnum + +=back + +If there is an error, returns the error, otherwise returns false. + +=cut + +sub insert_discount { + #my ($self, %options) = @_; + my $self = shift; + + my $cust_pkg_discount = new FS::cust_pkg_discount { + 'pkgnum' => $self->pkgnum, + 'discountnum' => $self->discountnum, + 'months_used' => 0, + 'end_date' => '', #XXX + 'otaker' => $self->otaker, + #for the create a new discount case + '_type' => $self->discountnum__type, + 'amount' => $self->discountnum_amount, + 'percent' => $self->discountnum_percent, + 'months' => $self->discountnum_months, + #'disabled' => $self->discountnum_disabled, + }; + + $cust_pkg_discount->insert; +} + =item set_usage USAGE_VALUE_HASHREF USAGE_VALUE_HASHREF is a hashref of svc_acct usage columns and the amounts @@ -2358,10 +2388,7 @@ sub cust_pkg_discount { sub cust_pkg_discount_active { my $self = shift; - grep { my $d = $_->discount; - ! $d->months || $_->months_used < $d->months; # XXX also end date - } - $self->cust_pkg_discount; + grep { $_->status eq 'active' } $self->cust_pkg_discount; } =back