delete fees, RT#81713
[freeside.git] / FS / FS / pkg_discount_Mixin.pm
1 package FS::pkg_discount_Mixin;
2
3 use strict;
4 use NEXT;
5 use FS::Record qw(dbh);
6
7 =head1 NAME
8
9 FS::pkg_discount_Mixin - mixin class for package-discount link objects.
10
11 =head1 DESCRIPTION
12
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>.
16
17 =head1 METHODS
18
19 =over 4
20
21 =item insert
22
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
26 discount.
27
28 =cut
29
30 sub insert {
31   my $self = shift;
32   my $oldAutoCommit = $FS::UID::AutoCommit;
33   local $FS::UID::AutoCommit = 0;
34   my $dbh = dbh;
35   
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,
44       'disabled' => 'Y',
45     };
46     my $error = $discount->insert;
47     if ( $error ) {
48       $dbh->rollback if $oldAutoCommit;
49       return $error; 
50     } 
51     $self->set('discountnum', $discount->discountnum);
52   }
53
54   my $error = $self->NEXT::insert;
55   if ( $error ) {
56     $dbh->rollback if $oldAutoCommit;
57     return $error;
58   }
59
60   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
61   '';
62   
63
64
65 =back
66
67 =cut
68
69 1;