+
+ if ( $self->option('query_style') eq 'detailed' ) {
+
+ while (my $row = $sth->fetchrow_hashref) {
+ if (exists $row->{amount}) {
+ if ( $row->{amount} eq '' ) {
+ # treat as zero
+ } elsif ( $row->{amount} =~ /^\d+(?:\.\d+)?$/ ) {
+ $price += $row->{amount};
+ } else {
+ die "sql_external query returned non-numeric amount: $row->{amount}";
+ }
+ }
+ if (defined $row->{quantity}) {
+ if ( $row->{quantity} eq '' ) {
+ # treat as zero
+ } elsif ( $row->{quantity} =~ /^\d+$/ ) {
+ $quantity += $row->{quantity};
+ } else {
+ die "sql_external query returned non-integer quantity: $row->{quantity}";
+ }
+ }
+
+ my $detail = FS::cust_bill_pkg_detail->new;
+ foreach my $field (@detail_cols) {
+ if (exists $row->{$field}) {
+ $detail->set($field, $row->{$field});
+ }
+ }
+ if (!$detail->get('detail')) {
+ die "sql_external query did not return detail description";
+ # or make something up?
+ # or just don't insert the detail?
+ }
+
+ push @$details, $detail;
+ } # while $row
+
+ } else {
+
+ # simple style: returns only a single value, which is the price
+ $price += $sth->fetchrow_arrayref->[0];
+
+ }
+ }
+ $price = sprintf('%.2f', $price);
+
+ # XXX probably shouldn't allow package quantity > 1 on these packages.
+ if ($cust_pkg->quantity > 1) {
+ warn "sql_external package #".$cust_pkg->pkgnum." has quantity > 1\n";
+ }
+
+ $param->{'override_quantity'} = $quantity;
+ $param->{'override_charges'} = $price;
+ ($cust_pkg->quantity || 1) * $self->calc_recur_Common($cust_pkg,$sdate,$details,$param);
+}
+
+sub cutoff_day {
+ my $self = shift;
+ my $cust_pkg = shift;
+ my $cust_main = $cust_pkg->cust_main;
+ # force it to act like a prorate package, is what this means
+ # because we made a distinction once between prorate and flat packages
+ if ( $cust_main->force_prorate_day and $cust_main->prorate_day ) {
+ return ( $cust_main->prorate_day );