+=cut
+
+=item insert_discount
+
+Associates this package with a discount (see L<FS::cust_pkg_discount>,
+possibly inserting a new discount on the fly (see L<FS::discount>). Properties
+of the discount will be taken from this object.
+
+=cut
+
+sub insert_discount {
+ #my ($self, %options) = @_;
+ my $self = shift;
+
+ my $quotation_pkg_discount = FS::quotation_pkg_discount->new( {
+ 'quotationpkgnum' => $self->quotationpkgnum,
+ 'discountnum' => $self->discountnum,
+ #for the create a new discount case
+ '_type' => $self->discountnum__type,
+ 'amount' => $self->discountnum_amount,
+ 'percent' => $self->discountnum_percent,
+ 'months' => $self->discountnum_months,
+ 'setup' => $self->discountnum_setup,
+ } );
+
+ $quotation_pkg_discount->insert;
+}
+
+sub _item_discount {
+ my $self = shift;
+ my %options = @_;
+ my $setuprecur = $options{'setuprecur'};
+
+ # kind of silly treating this as multiple records, but it works, and will
+ # work if we allow multiple discounts at some point
+ my @pkg_discounts = $self->pkg_discount;
+ return if @pkg_discounts == 0;
+
+ my @ext;
+ my $d = {
+ _is_discount => 1,
+ description => $self->mt('Discount'),
+ amount => 0,
+ ext_description => \@ext,
+ # maybe should show quantity/unit discount?
+ };
+ foreach my $pkg_discount (@pkg_discounts) {
+ push @ext, $pkg_discount->description;
+ my $amount = $pkg_discount->get($setuprecur.'_amount');
+ $d->{amount} -= $amount;
+ }
+ $d->{amount} = sprintf('%.2f', $d->{amount} * $self->quantity);
+
+ return $d;
+}
+