X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=acc73dfda74606a804f8764a867e6956895d1836;hp=5cdca09ac8587cbbc1751f3be90f899bcf613cf1;hb=8a0204b4a129a3c26dcca18ba401b2de26d22d2b;hpb=4cacb3fa439b56fc7c9a742b69ec3f6ffd660433 diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 5cdca09ac..acc73dfda 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