+=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;
+
+ foreach my $x (qw(setup recur)) {
+ if ( my $discountnum = $self->get("${x}_discountnum") ) {
+ my $cust_pkg_discount = FS::quotation_pkg_discount->new( {
+ 'quotationpkgnum' => $self->quotationpkgnum,
+ 'discountnum' => $discountnum,
+ 'setuprecur' => $x,
+ #for the create a new discount case
+ 'amount' => $self->get("${x}_discountnum_amount"),
+ 'percent' => $self->get("${x}_discountnum_percent"),
+ 'months' => $self->get("${x}_discountnum_months"),
+ } );
+ if ( $x eq 'setup' ) {
+ $cust_pkg_discount->setup('Y');
+ $cust_pkg_discount->months('');
+ }
+ my $error = $cust_pkg_discount->insert;
+ return $error if $error;
+ }
+ }
+}
+
+sub _item_discount {
+ my $self = shift;
+ my %options = @_;
+ my $setuprecur = $options{'setuprecur'};
+ # a little different from cust_bill_pkg::_item_discount, in that this one
+ # is asked specifically whether to show setup or recur discounts (because
+ # on the quotation they're separate sections entirely)
+
+ my @pkg_discounts = grep { $_->setuprecur eq $setuprecur }
+ $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('amount');
+ $d->{amount} -= $amount;
+ }
+ $d->{amount} = sprintf('%.2f', $d->{amount} * $self->quantity);
+
+ return $d;
+}
+