1 package FS::pkg_discount_Mixin;
5 use FS::Record qw(dbh);
9 FS::pkg_discount_Mixin - mixin class for package-discount link objects.
13 Implements some behavior that's common to cust_pkg_discount and
14 quotation_pkg_discount objects. The only required field is "discountnum",
15 a foreign key to L<FS::discount>.
23 Inserts the record. If the 'discountnum' field is -1, this will first create
24 a discount using the contents of the '_type', 'amount', 'percent', 'months',
25 and 'setup' field. The new discount will be disabled, since it's a one-off
32 my $oldAutoCommit = $FS::UID::AutoCommit;
33 local $FS::UID::AutoCommit = 0;
36 if ( $self->discountnum == -1 ) {
37 my $discount = new FS::discount {
38 '_type' => $self->_type,
39 'amount' => $self->amount,
40 'percent' => $self->percent,
41 'months' => $self->months,
42 'setup' => $self->setup,
43 #'linked' => $self->linked,
46 my $error = $discount->insert;
48 $dbh->rollback if $oldAutoCommit;
51 $self->set('discountnum', $discount->discountnum);
54 my $error = $self->NEXT::insert;
56 $dbh->rollback if $oldAutoCommit;
60 $dbh->commit or die $dbh->errstr if $oldAutoCommit;