+ $pf_cust_pkg->setup(time);
+ my $pf_error = $pf_cust_pkg->replace;
+ if($pf_error) {
+ warn 'Unable to set setup time on cust_pkg for processing fee';
+ # but keep going...
+ }
+
+ if ($conf->exists('processing-fee_on_separate_invoice')) {
+ my $cust_bill_pkg = qsearchs( 'cust_bill_pkg', { 'pkgnum' => $pf_cust_pkg->pkgnum } );
+
+ my $pf_cust_bill = qsearchs('cust_bill', { 'invnum' => $cust_bill_pkg->invnum });
+ unless ( $pf_cust_bill ) {
+ warn "no processing fee inv found!";
+ return '';
+ }
+
+ my $pf_apply_error = $pf_cust_bill->apply_payments_and_credits;
+
+ my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum });
+ unless ( $cust_bill ) {
+ warn "race condition + invoice deletion just happened";
+ return '';
+ }
+
+ my $grand_pf_error = $cust_bill->apply_payments_and_credits;
+
+ warn "cannot apply Processing fee to invoice #$invnum: $grand_pf_error - $pf_apply_error"
+ if $grand_pf_error || $pf_apply_error;
+ } ## processing-fee_on_separate_invoice
+ else {
+ my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum });
+ unless ( $cust_bill ) {
+ warn "race condition + invoice deletion just happened";
+ return '';
+ }
+
+ my $grand_pf_error =
+ $cust_bill->add_cc_surcharge($pf_cust_pkg->pkgnum,$options{'processing-fee'});
+
+ warn "cannot add Processing fee to invoice #$invnum: $grand_pf_error"
+ if $grand_pf_error;
+ } ## no processing-fee_on_separate_invoice
+ } #end if $options{'processing-fee'}
+
+ } #end if ( $options{'cc_surcharge'} > 0 || $options{'processing-fee'} > 0)
+