+ my $fee_links = $self->get('cust_bill_pkg_fee');
+ if ( $fee_links ) {
+ foreach my $link ( @$fee_links ) {
+ # very similar to cust_bill_pkg_tax_location, for obvious reasons
+ next if $link->billpkgfeenum; # don't try to double-insert
+
+ my $target = $link->get('cust_bill_pkg'); # the line item of the fee
+ my $base = $link->get('base_cust_bill_pkg'); # line item it was based on
+
+ if ( $target and $target->billpkgnum ) {
+ $link->set('billpkgnum', $target->billpkgnum);
+ # base_invnum => null indicates that the fee is based on its own
+ # invoice
+ $link->set('base_invnum', $target->invnum) unless $link->base_invnum;
+ $link->set('cust_bill_pkg', '');
+ }
+
+ if ( $base and $base->billpkgnum ) {
+ $link->set('base_billpkgnum', $base->billpkgnum);
+ $link->set('base_cust_bill_pkg', '');
+ } elsif ( $base ) {
+ # it's based on a line item that's not yet inserted
+ my $link_array = $base->get('cust_bill_pkg_fee') || [];
+ push @$link_array, $link;
+ $base->set('cust_bill_pkg_fee' => $link_array);
+ next; # don't insert the link yet
+ }
+
+ $error = $link->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "error inserting cust_bill_pkg_fee: $error";
+ }
+ } # foreach my $link
+ }
+
+ my $cust_event_fee = $self->get('cust_event_fee');
+ if ( $cust_event_fee ) {
+ $cust_event_fee->set('billpkgnum' => $self->billpkgnum);
+ $error = $cust_event_fee->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "error updating cust_event_fee: $error";
+ }
+ }
+