+
+ } #if $conf->exists('enable_taxproducts')
+
+ # XXX all this goes away with cust_bill_pay refactor
+
+ $cust_bill_pkg{setup} = $cust_bill_pkg if $cust_bill_pkg->setup;
+ $cust_bill_pkg{recur} = $cust_bill_pkg if $cust_bill_pkg->recur;
+
+ #split setup and recur
+ if ($cust_bill_pkg->setup && $cust_bill_pkg->recur) {
+ my $cust_bill_pkg_recur = new FS::cust_bill_pkg { $cust_bill_pkg->hash };
+ $cust_bill_pkg->set('details', []);
+ $cust_bill_pkg->recur(0);
+ $cust_bill_pkg->type('');
+ $cust_bill_pkg{recur} = $cust_bill_pkg_recur;
+ }
+
+ #split usage from recur
+ my $usage = $cust_bill_pkg->usage;
+ if ($usage) {
+ my $cust_bill_pkg_usage =
+ new FS::cust_bill_pkg { $cust_bill_pkg{recur}->hash };
+ $cust_bill_pkg_usage->recur($usage);
+ $cust_bill_pkg{recur}->recur( $cust_bill_pkg{recur}->recur - $usage );
+ $cust_bill_pkg{recur}->type( '' );
+ $cust_bill_pkg{''} = $cust_bill_pkg_usage;
+ }
+
+ #subdivide usage by usage_class
+ if (exists($cust_bill_pkg{''})) {
+ foreach my $class (grep {$_} @classes) {
+ my $usage = $cust_bill_pkg{''}->usage($class);
+ my $cust_bill_pkg_usage =
+ new FS::cust_bill_pkg { $cust_bill_pkg{''}->hash };
+ $cust_bill_pkg_usage->recur($usage);
+ $cust_bill_pkg{''}->recur( $cust_bill_pkg{''}->recur - $usage );
+ $cust_bill_pkg{$class} = $cust_bill_pkg_usage;
+ }
+ $cust_bill_pkg{''}->set('details', []);
+ delete $cust_bill_pkg{''} unless $cust_bill_pkg{''}->recur;