X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg.pm;h=402d88cb99d66a67a4bffba0c4efdfd7e28690ec;hb=b03bd63dcee4fce35d86e906b0379acdb6c76c27;hp=f90e3eec51a0d4ada4e89d9290eaea5aae51c706;hpb=022bfd91eca7ae26f8f6ee125179f5c0ff4cbb72;p=freeside.git diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index f90e3eec5..402d88cb9 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -120,6 +120,10 @@ part_pkg, will be equal to pkgpart. =item delay_start - Number of days to delay package start, by default +=item start_on_hold - 'Y' to suspend this package immediately when it is +ordered. The package will not start billing or have a setup fee charged +until it is manually unsuspended. + =back =head1 METHODS @@ -164,7 +168,8 @@ I and I. If I is set to a hashref with svcparts as keys and quantities as values, appropriate FS::pkg_svc records will be inserted. I can be set to a hashref of svcparts and flag values ('Y' or '') to set the -'hidden' field in these records. +'hidden' field in these records, and I can be set similarly +for the 'provision_hold' field in these records. If I is set to the svcpart of the primary service, the appropriate FS::pkg_svc record will be updated. @@ -244,6 +249,7 @@ sub insert { warn " inserting pkg_svc records" if $DEBUG; my $pkg_svc = $options{'pkg_svc'} || {}; my $hidden_svc = $options{'hidden_svc'} || {}; + my $provision_hold = $options{'provision_hold'} || {}; foreach my $part_svc ( qsearch('part_svc', {} ) ) { my $quantity = $pkg_svc->{$part_svc->svcpart} || 0; my $primary_svc = @@ -257,6 +263,7 @@ sub insert { 'quantity' => $quantity, 'primary_svc' => $primary_svc, 'hidden' => $hidden_svc->{$part_svc->svcpart}, + 'provision_hold' => $provision_hold->{$part_svc->svcpart}, } ); my $error = $pkg_svc->insert; if ( $error ) { @@ -331,13 +338,15 @@ sub delete { Replaces OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. -Currently available options are: I, I, I -and I +Currently available options are: I, I, I, +I, I and I If I is set to a hashref with svcparts as keys and quantities as values, the appropriate FS::pkg_svc records will be replaced. I can be set to a hashref of svcparts and flag values ('Y' or '') to set the -'hidden' field in these records. +'hidden' field in these records. I can be set +to a hashref of svcparts and flag values ('Y' or '') to set the field +in those records. If I is set to the svcpart of the primary service, the appropriate FS::pkg_svc record will be updated. @@ -443,10 +452,12 @@ sub replace { warn " replacing pkg_svc records" if $DEBUG; my $pkg_svc = $options->{'pkg_svc'}; my $hidden_svc = $options->{'hidden_svc'} || {}; + my $provision_hold = $options->{'provision_hold'} || {}; if ( $pkg_svc ) { # if it wasn't passed, don't change existing pkg_svcs foreach my $part_svc ( qsearch('part_svc', {} ) ) { my $quantity = $pkg_svc->{$part_svc->svcpart} || 0; my $hidden = $hidden_svc->{$part_svc->svcpart} || ''; + my $provision_hold = $provision_hold->{$part_svc->svcpart} || ''; my $primary_svc = ( defined($options->{'primary_svc'}) && $options->{'primary_svc'} && $options->{'primary_svc'} == $part_svc->svcpart @@ -462,16 +473,19 @@ sub replace { my $old_quantity = 0; my $old_primary_svc = ''; my $old_hidden = ''; + my $old_provision_hold = ''; if ( $old_pkg_svc ) { $old_quantity = $old_pkg_svc->quantity; $old_primary_svc = $old_pkg_svc->primary_svc if $old_pkg_svc->dbdef_table->column('primary_svc'); # is this needed? $old_hidden = $old_pkg_svc->hidden; + $old_provision_hold = $old_pkg_svc->provision_hold; } next unless $old_quantity != $quantity || $old_primary_svc ne $primary_svc || - $old_hidden ne $hidden; + $old_hidden ne $hidden || + $old_provision_hold ne $provision_hold; my $new_pkg_svc = new FS::pkg_svc( { 'pkgsvcnum' => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ), @@ -480,6 +494,7 @@ sub replace { 'quantity' => $quantity, 'primary_svc' => $primary_svc, 'hidden' => $hidden, + 'provision_hold' => $provision_hold, } ); my $error = $old_pkg_svc ? $new_pkg_svc->replace($old_pkg_svc) @@ -601,14 +616,15 @@ sub check { || $self->ut_textn('comment') || $self->ut_textn('promo_code') || $self->ut_alphan('plan') - || $self->ut_enum('setuptax', [ '', 'Y' ] ) - || $self->ut_enum('recurtax', [ '', 'Y' ] ) + || $self->ut_flag('setuptax') + || $self->ut_flag('recurtax') || $self->ut_textn('taxclass') - || $self->ut_enum('disabled', [ '', 'Y' ] ) - || $self->ut_enum('custom', [ '', 'Y' ] ) - || $self->ut_enum('no_auto', [ '', 'Y' ]) - || $self->ut_enum('recur_show_zero', [ '', 'Y' ]) - || $self->ut_enum('setup_show_zero', [ '', 'Y' ]) + || $self->ut_flag('disabled') + || $self->ut_flag('custom') + || $self->ut_flag('no_auto') + || $self->ut_flag('recur_show_zero') + || $self->ut_flag('setup_show_zero') + || $self->ut_flag('start_on_hold') #|| $self->ut_moneyn('setup_cost') #|| $self->ut_moneyn('recur_cost') || $self->ut_floatn('setup_cost') @@ -1082,7 +1098,10 @@ sub is_free { sub can_discount { 0; } # whether the plan allows changing the start date -sub can_start_date { 1; } +sub can_start_date { + my $self = shift; + $self->start_on_hold ? 0 : 1; +} # the delay start date if present sub delay_start_date { @@ -1248,6 +1267,12 @@ will be suppressed. sub option { my( $self, $opt, $ornull ) = @_; + + #cache: was pulled up in the original part_pkg query + if ( $opt =~ /^(setup|recur)_fee$/ && defined($self->hashref->{"_$opt"}) ) { + return $self->hashref->{"_$opt"}; + } + cluck "$self -> option: searching for $opt" if $DEBUG; my $part_pkg_option = @@ -1256,12 +1281,14 @@ sub option { optionname => $opt, } ); return $part_pkg_option->optionvalue if $part_pkg_option; + my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); } split("\n", $self->get('plandata') ); return $plandata{$opt} if exists $plandata{$opt}; cluck "WARNING: (pkgpart ". $self->pkgpart. ") Package def option $opt ". "not found in options or plandata!\n" unless $ornull; + ''; } @@ -1464,8 +1491,10 @@ package in the location specified by GEOCODE, for usage class CLASS (one of sub tax_rates { my $self = shift; my ($vendor, $geocode, $class) = @_; + # if this part_pkg is overridden into a specific taxclass, get that class my @taxclassnums = map { $_->taxclassnum } $self->part_pkg_taxoverride($class); + # otherwise, get its tax product category if (!@taxclassnums) { my $part_pkg_taxproduct = $self->taxproduct($class); # If this isn't defined, then the class has no taxproduct designation, @@ -1486,7 +1515,8 @@ sub tax_rates { my $extra_sql = "AND taxclassnum IN (". join(',', @taxclassnums) . ")"; my @taxes = qsearch({ 'table' => 'tax_rate', 'hashref' => { 'geocode' => $geocode, - 'data_vendor' => $vendor }, + 'data_vendor' => $vendor, + 'disabled' => '' }, 'extra_sql' => $extra_sql, }); warn "Found taxes ". join(',', map {$_->taxnum} @taxes) ."\n" @@ -1571,7 +1601,7 @@ recur_cost divided by freq (only supported for monthly and longer frequencies) sub recur_cost_permonth { my($self, $cust_pkg) = @_; return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0; - sprintf('%.2f', $self->recur_cost / $self->freq ); + sprintf('%.2f', ($self->recur_cost || 0) / $self->freq ); } =item cust_bill_pkg_recur CUST_PKG @@ -1616,7 +1646,7 @@ unit_setup minus setup_cost sub setup_margin { my $self = shift; - $self->unit_setup(@_) - $self->setup_cost; + $self->unit_setup(@_) - ($self->setup_cost || 0); } =item recur_margin_permonth @@ -1945,8 +1975,8 @@ sub _pkgs_sql { #false laziness w/part_export & cdr my %info; foreach my $INC ( @INC ) { - warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG; - foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) { + warn "globbing $INC/FS/part_pkg/[a-z]*.pm\n" if $DEBUG; + foreach my $file ( glob("$INC/FS/part_pkg/[a-z]*.pm") ) { warn "attempting to load plan info from $file\n" if $DEBUG; $file =~ /\/(\w+)\.pm$/ or do { warn "unrecognized file in $INC/FS/part_pkg/: $file\n";