4 use vars qw( @ISA %plans $DEBUG $setup_hack $skip_pkg_svc_hack );
5 use Carp qw(carp cluck confess);
6 use Scalar::Util qw( blessed );
7 use Time::Local qw( timelocal timelocal_nocheck );
10 use FS::Record qw( qsearch qsearchs dbh dbdef );
16 use FS::part_pkg_option;
19 use FS::part_pkg_taxrate;
20 use FS::part_pkg_taxoverride;
21 use FS::part_pkg_taxproduct;
22 use FS::part_pkg_link;
23 use FS::part_pkg_discount;
24 use FS::part_pkg_vendor;
26 @ISA = qw( FS::m2m_Common FS::option_Common );
29 $skip_pkg_svc_hack = 0;
33 FS::part_pkg - Object methods for part_pkg objects
39 $record = new FS::part_pkg \%hash
40 $record = new FS::part_pkg { 'column' => 'value' };
42 $custom_record = $template_record->clone;
44 $error = $record->insert;
46 $error = $new_record->replace($old_record);
48 $error = $record->delete;
50 $error = $record->check;
52 @pkg_svc = $record->pkg_svc;
54 $svcnum = $record->svcpart;
55 $svcnum = $record->svcpart( 'svc_acct' );
59 An FS::part_pkg object represents a package definition. FS::part_pkg
60 inherits from FS::Record. The following fields are currently supported:
64 =item pkgpart - primary key (assigned automatically for new package definitions)
66 =item pkg - Text name of this package definition (customer-viewable)
68 =item comment - Text name of this package definition (non-customer-viewable)
70 =item classnum - Optional package class (see L<FS::pkg_class>)
72 =item promo_code - Promotional code
74 =item setup - Setup fee expression (deprecated)
76 =item freq - Frequency of recurring fee
78 =item recur - Recurring fee expression (deprecated)
80 =item setuptax - Setup fee tax exempt flag, empty or `Y'
82 =item recurtax - Recurring fee tax exempt flag, empty or `Y'
84 =item taxclass - Tax class
86 =item plan - Price plan
88 =item plandata - Price plan data (deprecated - see L<FS::part_pkg_option> instead)
90 =item disabled - Disabled flag, empty or `Y'
92 =item custom - Custom flag, empty or `Y'
94 =item setup_cost - for cost tracking
96 =item recur_cost - for cost tracking
98 =item pay_weight - Weight (relative to credit_weight and other package definitions) that controls payment application to specific line items.
100 =item credit_weight - Weight (relative to other package definitions) that controls credit application to specific line items.
102 =item agentnum - Optional agentnum (see L<FS::agent>)
104 =item fcc_ds0s - Optional DS0 equivalency number for FCC form 477
106 =item fcc_voip_class - Which column of FCC form 477 part II.B this package
109 =item delay_start - Number of days to delay package start, by default
119 Creates a new package definition. To add the package definition to
120 the database, see L<"insert">.
124 sub table { 'part_pkg'; }
128 An alternate constructor. Creates a new package definition by duplicating
129 an existing definition. A new pkgpart is assigned and the custom flag is
130 set to Y. To add the package definition to the database, see L<"insert">.
136 my $class = ref($self);
137 my %hash = $self->hash;
138 $hash{'pkgpart'} = '';
139 $hash{'custom'} = 'Y';
140 #new FS::part_pkg ( \%hash ); # ?
141 new $class ( \%hash ); # ?
144 =item insert [ , OPTION => VALUE ... ]
146 Adds this package definition to the database. If there is an error,
147 returns the error, otherwise returns false.
149 Currently available options are: I<pkg_svc>, I<primary_svc>, I<cust_pkg>,
150 I<custnum_ref> and I<options>.
152 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
153 values, appropriate FS::pkg_svc records will be inserted. I<hidden_svc> can
154 be set to a hashref of svcparts and flag values ('Y' or '') to set the
155 'hidden' field in these records.
157 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
158 FS::pkg_svc record will be updated.
160 If I<cust_pkg> is set to a pkgnum of a FS::cust_pkg record (or the FS::cust_pkg
161 record itself), the object will be updated to point to this package definition.
163 In conjunction with I<cust_pkg>, if I<custnum_ref> is set to a scalar reference,
164 the scalar will be updated with the custnum value from the cust_pkg record.
166 If I<tax_overrides> is set to a hashref with usage classes as keys and comma
167 separated tax class numbers as values, appropriate FS::part_pkg_taxoverride
168 records will be inserted.
170 If I<options> is set to a hashref of options, appropriate FS::part_pkg_option
171 records will be inserted.
178 warn "FS::part_pkg::insert called on $self with options ".
179 join(', ', map "$_=>$options{$_}", keys %options)
182 local $SIG{HUP} = 'IGNORE';
183 local $SIG{INT} = 'IGNORE';
184 local $SIG{QUIT} = 'IGNORE';
185 local $SIG{TERM} = 'IGNORE';
186 local $SIG{TSTP} = 'IGNORE';
187 local $SIG{PIPE} = 'IGNORE';
189 my $oldAutoCommit = $FS::UID::AutoCommit;
190 local $FS::UID::AutoCommit = 0;
193 warn " inserting part_pkg record" if $DEBUG;
194 my $error = $self->SUPER::insert( $options{options} );
196 $dbh->rollback if $oldAutoCommit;
200 my $conf = new FS::Conf;
201 if ( $conf->exists('agent_defaultpkg') ) {
202 warn " agent_defaultpkg set; allowing all agents to purchase package"
204 foreach my $agent_type ( qsearch('agent_type', {} ) ) {
205 my $type_pkgs = new FS::type_pkgs({
206 'typenum' => $agent_type->typenum,
207 'pkgpart' => $self->pkgpart,
209 my $error = $type_pkgs->insert;
211 $dbh->rollback if $oldAutoCommit;
217 warn " inserting part_pkg_taxoverride records" if $DEBUG;
218 my %overrides = %{ $options{'tax_overrides'} || {} };
219 foreach my $usage_class ( keys %overrides ) {
221 ( exists($overrides{$usage_class}) && defined($overrides{$usage_class}) )
222 ? $overrides{$usage_class}
224 my @overrides = (grep "$_", split(',', $override) );
225 my $error = $self->process_m2m (
226 'link_table' => 'part_pkg_taxoverride',
227 'target_table' => 'tax_class',
228 'hashref' => { 'usage_class' => $usage_class },
229 'params' => \@overrides,
232 $dbh->rollback if $oldAutoCommit;
237 unless ( $skip_pkg_svc_hack ) {
239 warn " inserting pkg_svc records" if $DEBUG;
240 my $pkg_svc = $options{'pkg_svc'} || {};
241 my $hidden_svc = $options{'hidden_svc'} || {};
242 foreach my $part_svc ( qsearch('part_svc', {} ) ) {
243 my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
245 ( $options{'primary_svc'} && $options{'primary_svc'}==$part_svc->svcpart )
249 my $pkg_svc = new FS::pkg_svc( {
250 'pkgpart' => $self->pkgpart,
251 'svcpart' => $part_svc->svcpart,
252 'quantity' => $quantity,
253 'primary_svc' => $primary_svc,
254 'hidden' => $hidden_svc->{$part_svc->svcpart},
256 my $error = $pkg_svc->insert;
258 $dbh->rollback if $oldAutoCommit;
265 if ( $options{'cust_pkg'} ) {
266 warn " updating cust_pkg record " if $DEBUG;
268 ref($options{'cust_pkg'})
269 ? $options{'cust_pkg'}
270 : qsearchs('cust_pkg', { pkgnum => $options{'cust_pkg'} } );
271 ${ $options{'custnum_ref'} } = $old_cust_pkg->custnum
272 if $options{'custnum_ref'};
273 my %hash = $old_cust_pkg->hash;
274 $hash{'pkgpart'} = $self->pkgpart,
275 my $new_cust_pkg = new FS::cust_pkg \%hash;
276 local($FS::cust_pkg::disable_agentcheck) = 1;
277 my $error = $new_cust_pkg->replace($old_cust_pkg);
279 $dbh->rollback if $oldAutoCommit;
280 return "Error modifying cust_pkg record: $error";
284 if ( $options{'part_pkg_vendor'} ) {
285 while ( my ($exportnum, $vendor_pkg_id) =
286 each %{ $options{part_pkg_vendor} }
289 my $ppv = new FS::part_pkg_vendor( {
290 'pkgpart' => $self->pkgpart,
291 'exportnum' => $exportnum,
292 'vendor_pkg_id' => $vendor_pkg_id,
294 my $error = $ppv->insert;
296 $dbh->rollback if $oldAutoCommit;
297 return "Error inserting part_pkg_vendor record: $error";
302 warn " commiting transaction" if $DEBUG;
303 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
310 Currently unimplemented.
315 return "Can't (yet?) delete package definitions.";
316 # check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
319 =item replace OLD_RECORD [ , OPTION => VALUE ... ]
321 Replaces OLD_RECORD with this one in the database. If there is an error,
322 returns the error, otherwise returns false.
324 Currently available options are: I<pkg_svc>, I<hidden_svc>, I<primary_svc>
327 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
328 values, the appropriate FS::pkg_svc records will be replaced. I<hidden_svc>
329 can be set to a hashref of svcparts and flag values ('Y' or '') to set the
330 'hidden' field in these records.
332 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
333 FS::pkg_svc record will be updated.
335 If I<options> is set to a hashref, the appropriate FS::part_pkg_option records
343 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
348 ( ref($_[0]) eq 'HASH' )
352 $options->{options} = {} unless defined($options->{options});
354 warn "FS::part_pkg::replace called on $new to replace $old with options".
355 join(', ', map "$_ => ". $options->{$_}, keys %$options)
358 local $SIG{HUP} = 'IGNORE';
359 local $SIG{INT} = 'IGNORE';
360 local $SIG{QUIT} = 'IGNORE';
361 local $SIG{TERM} = 'IGNORE';
362 local $SIG{TSTP} = 'IGNORE';
363 local $SIG{PIPE} = 'IGNORE';
365 my $oldAutoCommit = $FS::UID::AutoCommit;
366 local $FS::UID::AutoCommit = 0;
369 #plandata shit stays in replace for upgrades until after 2.0 (or edit
371 warn " saving legacy plandata" if $DEBUG;
372 my $plandata = $new->get('plandata');
373 $new->set('plandata', '');
375 warn " deleting old part_pkg_option records" if $DEBUG;
376 foreach my $part_pkg_option ( $old->part_pkg_option ) {
377 my $error = $part_pkg_option->delete;
379 $dbh->rollback if $oldAutoCommit;
384 warn " replacing part_pkg record" if $DEBUG;
385 my $error = $new->SUPER::replace($old, $options->{options} );
387 $dbh->rollback if $oldAutoCommit;
391 warn " inserting part_pkg_option records for plandata: $plandata|" if $DEBUG;
392 foreach my $part_pkg_option (
393 map { /^(\w+)=(.*)$/ or do { $dbh->rollback if $oldAutoCommit;
394 return "illegal plandata: $plandata";
396 new FS::part_pkg_option {
397 'pkgpart' => $new->pkgpart,
402 split("\n", $plandata)
404 my $error = $part_pkg_option->insert;
406 $dbh->rollback if $oldAutoCommit;
411 warn " replacing pkg_svc records" if $DEBUG;
412 my $pkg_svc = $options->{'pkg_svc'} || {};
413 my $hidden_svc = $options->{'hidden_svc'} || {};
414 foreach my $part_svc ( qsearch('part_svc', {} ) ) {
415 my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
416 my $hidden = $hidden_svc->{$part_svc->svcpart} || '';
418 ( defined($options->{'primary_svc'}) && $options->{'primary_svc'}
419 && $options->{'primary_svc'} == $part_svc->svcpart
424 my $old_pkg_svc = qsearchs('pkg_svc', {
425 'pkgpart' => $old->pkgpart,
426 'svcpart' => $part_svc->svcpart,
429 my $old_quantity = 0;
430 my $old_primary_svc = '';
432 if ( $old_pkg_svc ) {
433 $old_quantity = $old_pkg_svc->quantity;
434 $old_primary_svc = $old_pkg_svc->primary_svc
435 if $old_pkg_svc->dbdef_table->column('primary_svc'); # is this needed?
436 $old_hidden = $old_pkg_svc->hidden;
439 next unless $old_quantity != $quantity ||
440 $old_primary_svc ne $primary_svc ||
441 $old_hidden ne $hidden;
443 my $new_pkg_svc = new FS::pkg_svc( {
444 'pkgsvcnum' => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
445 'pkgpart' => $new->pkgpart,
446 'svcpart' => $part_svc->svcpart,
447 'quantity' => $quantity,
448 'primary_svc' => $primary_svc,
451 my $error = $old_pkg_svc
452 ? $new_pkg_svc->replace($old_pkg_svc)
453 : $new_pkg_svc->insert;
455 $dbh->rollback if $oldAutoCommit;
460 my @part_pkg_vendor = $old->part_pkg_vendor;
461 my @current_exportnum = ();
462 if ( $options->{'part_pkg_vendor'} ) {
463 my($exportnum,$vendor_pkg_id);
464 while ( ($exportnum,$vendor_pkg_id)
465 = each %{$options->{'part_pkg_vendor'}} ) {
467 foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
468 if($exportnum == $part_pkg_vendor->exportnum
469 && $vendor_pkg_id ne $part_pkg_vendor->vendor_pkg_id) {
470 $part_pkg_vendor->vendor_pkg_id($vendor_pkg_id);
471 my $error = $part_pkg_vendor->replace;
473 $dbh->rollback if $oldAutoCommit;
474 return "Error replacing part_pkg_vendor record: $error";
479 elsif($exportnum == $part_pkg_vendor->exportnum
480 && $vendor_pkg_id eq $part_pkg_vendor->vendor_pkg_id) {
485 unless ( $noinsert ) {
486 my $ppv = new FS::part_pkg_vendor( {
487 'pkgpart' => $new->pkgpart,
488 'exportnum' => $exportnum,
489 'vendor_pkg_id' => $vendor_pkg_id,
491 my $error = $ppv->insert;
493 $dbh->rollback if $oldAutoCommit;
494 return "Error inserting part_pkg_vendor record: $error";
497 push @current_exportnum, $exportnum;
500 foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
501 unless ( grep($_ eq $part_pkg_vendor->exportnum, @current_exportnum) ) {
502 my $error = $part_pkg_vendor->delete;
504 $dbh->rollback if $oldAutoCommit;
505 return "Error deleting part_pkg_vendor record: $error";
510 warn " commiting transaction" if $DEBUG;
511 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
517 Checks all fields to make sure this is a valid package definition. If
518 there is an error, returns the error, otherwise returns false. Called by the
519 insert and replace methods.
525 warn "FS::part_pkg::check called on $self" if $DEBUG;
527 for (qw(setup recur plandata)) {
528 #$self->set($_=>0) if $self->get($_) =~ /^\s*$/; }
529 return "Use of $_ field is deprecated; set a plan and options: ".
531 if length($self->get($_));
535 if ( $self->dbdef_table->column('freq')->type =~ /(int)/i ) {
536 my $error = $self->ut_number('freq');
537 return $error if $error;
539 $self->freq =~ /^(\d+[hdw]?)$/
540 or return "Illegal or empty freq: ". $self->freq;
544 my @null_agentnum_right = ( 'Edit global package definitions' );
545 push @null_agentnum_right, 'One-time charge'
546 if $self->freq =~ /^0/;
547 push @null_agentnum_right, 'Customize customer package'
548 if $self->disabled eq 'Y'; #good enough
550 my $error = $self->ut_numbern('pkgpart')
551 || $self->ut_text('pkg')
552 || $self->ut_text('comment')
553 || $self->ut_textn('promo_code')
554 || $self->ut_alphan('plan')
555 || $self->ut_enum('setuptax', [ '', 'Y' ] )
556 || $self->ut_enum('recurtax', [ '', 'Y' ] )
557 || $self->ut_textn('taxclass')
558 || $self->ut_enum('disabled', [ '', 'Y' ] )
559 || $self->ut_enum('custom', [ '', 'Y' ] )
560 || $self->ut_enum('no_auto', [ '', 'Y' ])
561 || $self->ut_enum('recur_show_zero', [ '', 'Y' ])
562 || $self->ut_enum('setup_show_zero', [ '', 'Y' ])
563 #|| $self->ut_moneyn('setup_cost')
564 #|| $self->ut_moneyn('recur_cost')
565 || $self->ut_floatn('setup_cost')
566 || $self->ut_floatn('recur_cost')
567 || $self->ut_floatn('pay_weight')
568 || $self->ut_floatn('credit_weight')
569 || $self->ut_numbern('taxproductnum')
570 || $self->ut_foreign_keyn('classnum', 'pkg_class', 'classnum')
571 || $self->ut_foreign_keyn('addon_classnum', 'pkg_class', 'classnum')
572 || $self->ut_foreign_keyn('taxproductnum',
573 'part_pkg_taxproduct',
577 ? $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
578 : $self->ut_agentnum_acl('agentnum', \@null_agentnum_right)
580 || $self->ut_numbern('fcc_ds0s')
581 || $self->ut_numbern('fcc_voip_class')
582 || $self->ut_numbern('delay_start')
583 || $self->SUPER::check
585 return $error if $error;
587 return 'Unknown plan '. $self->plan
588 unless exists($plans{$self->plan});
590 my $conf = new FS::Conf;
591 return 'Taxclass is required'
592 if ! $self->taxclass && $conf->exists('require_taxclasses');
597 =item pkg_comment [ OPTION => VALUE... ]
599 Returns an (internal) string representing this package. Currently,
600 "pkgpart: pkg - comment", is returned. "pkg - comment" may be returned in the
601 future, omitting pkgpart. The comment will have '(CUSTOM) ' prepended if
604 If the option nopkgpart is true then the "pkgpart: ' is omitted.
612 #$self->pkg. ' - '. $self->comment;
613 #$self->pkg. ' ('. $self->comment. ')';
614 my $pre = $opt{nopkgpart} ? '' : $self->pkgpart. ': ';
615 $pre. $self->pkg. ' - '. $self->custom_comment;
618 sub price_info { # safety, in case a part_pkg hasn't defined price_info
624 ( $self->custom ? '(CUSTOM) ' : '' ). $self->comment . ' ' . $self->price_info;
629 Returns the package class, as an FS::pkg_class object, or the empty string
630 if there is no package class.
636 if ( $self->classnum ) {
637 qsearchs('pkg_class', { 'classnum' => $self->classnum } );
643 =item addon_pkg_class
645 Returns the add-on package class, as an FS::pkg_class object, or the empty
646 string if there is no add-on package class.
650 sub addon_pkg_class {
652 if ( $self->addon_classnum ) {
653 qsearchs('pkg_class', { 'classnum' => $self->addon_classnum } );
661 Returns the package category name, or the empty string if there is no package
668 my $pkg_class = $self->pkg_class;
670 ? $pkg_class->categoryname
676 Returns the package class name, or the empty string if there is no package
683 my $pkg_class = $self->pkg_class;
685 ? $pkg_class->classname
689 =item addon_classname
691 Returns the add-on package class name, or the empty string if there is no
692 add-on package class.
696 sub addon_classname {
698 my $pkg_class = $self->addon_pkg_class;
700 ? $pkg_class->classname
706 Returns the associated agent for this event, if any, as an FS::agent object.
712 qsearchs('agent', { 'agentnum' => $self->agentnum } );
715 =item pkg_svc [ HASHREF | OPTION => VALUE ]
717 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
718 definition (with non-zero quantity).
720 One option is available, I<disable_linked>. If set true it will return the
721 services for this package definition alone, omitting services from any add-on
728 Returns all FS::type_pkgs objects (see L<FS::type_pkgs>) for this package
735 qsearch('type_pkgs', { 'pkgpart' => $self->pkgpart } );
741 # #sort { $b->primary cmp $a->primary }
742 # grep { $_->quantity }
743 # qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
745 my $opt = ref($_[0]) ? $_[0] : { @_ };
746 my %pkg_svc = map { $_->svcpart => $_ }
747 grep { $_->quantity }
748 qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
750 unless ( $opt->{disable_linked} ) {
751 foreach my $dst_pkg ( map $_->dst_pkg, $self->svc_part_pkg_link ) {
752 my @pkg_svc = grep { $_->quantity }
753 qsearch( 'pkg_svc', { pkgpart=>$dst_pkg->pkgpart } );
754 foreach my $pkg_svc ( @pkg_svc ) {
755 if ( $pkg_svc{$pkg_svc->svcpart} ) {
756 my $quantity = $pkg_svc{$pkg_svc->svcpart}->quantity;
757 $pkg_svc{$pkg_svc->svcpart}->quantity($quantity + $pkg_svc->quantity);
759 $pkg_svc{$pkg_svc->svcpart} = $pkg_svc;
769 =item svcpart [ SVCDB ]
771 Returns the svcpart of the primary service definition (see L<FS::part_svc>)
772 associated with this package definition (see L<FS::pkg_svc>). Returns
773 false if there not a primary service definition or exactly one service
774 definition with quantity 1, or if SVCDB is specified and does not match the
775 svcdb of the service definition. SVCDB can be specified as a scalar table
776 name, such as 'svc_acct', or as an arrayref of possible table names.
781 my $pkg_svc = shift->_primary_pkg_svc(@_);
782 $pkg_svc ? $pkg_svc->svcpart : '';
785 =item part_svc [ SVCDB ]
787 Like the B<svcpart> method, but returns the FS::part_svc object (see
793 my $pkg_svc = shift->_primary_pkg_svc(@_);
794 $pkg_svc ? $pkg_svc->part_svc : '';
797 sub _primary_pkg_svc {
800 my $svcdb = scalar(@_) ? shift : [];
801 $svcdb = ref($svcdb) ? $svcdb : [ $svcdb ];
802 my %svcdb = map { $_=>1 } @$svcdb;
805 grep { !scalar(@$svcdb) || $svcdb{ $_->part_svc->svcdb } }
808 my @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc;
809 @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
811 return '' if scalar(@pkg_svc) != 1;
815 =item svcpart_unique_svcdb SVCDB
817 Returns the svcpart of a service definition (see L<FS::part_svc>) matching
818 SVCDB associated with this package definition (see L<FS::pkg_svc>). Returns
819 false if there not a primary service definition for SVCDB or there are multiple
820 service definitions for SVCDB.
824 sub svcpart_unique_svcdb {
825 my( $self, $svcdb ) = @_;
826 my @svcdb_pkg_svc = grep { ( $svcdb eq $_->part_svc->svcdb ) } $self->pkg_svc;
827 return '' if scalar(@svcdb_pkg_svc) != 1;
828 $svcdb_pkg_svc[0]->svcpart;
833 Returns a list of the acceptable payment types for this package. Eventually
834 this should come out of a database table and be editable, but currently has the
835 following logic instead:
837 If the package is free, the single item B<BILL> is
838 returned, otherwise, the single item B<CARD> is returned.
840 (CHEK? LEC? Probably shouldn't accept those by default, prone to abuse)
846 if ( $self->is_free ) {
855 Returns true if this package is free.
861 if ( $self->can('is_free_options') ) {
862 not grep { $_ !~ /^\s*0*(\.0*)?\s*$/ }
863 map { $self->option($_) }
864 $self->is_free_options;
866 warn "FS::part_pkg::is_free: FS::part_pkg::". $self->plan. " subclass ".
867 "provides neither is_free_options nor is_free method; returning false";
872 # whether the plan allows discounts to be applied to this package
873 sub can_discount { 0; }
875 # whether the plan allows changing the start date
876 sub can_start_date { 1; }
878 # the delay start date if present
879 sub delay_start_date {
882 my $delay = $self->delay_start or return '';
884 my ($mday,$mon,$year) = (localtime(time))[3,4,5];
885 timelocal(0,0,0,$mday,$mon,$year) + 86400 * $delay;
890 # moved to FS::Misc to make this accessible to other packages
892 FS::Misc::pkg_freqs();
897 Returns an english representation of the I<freq> field, such as "monthly",
898 "weekly", "semi-annually", etc.
904 my $freq = $self->freq;
906 #my $freqs_href = $self->freqs_href;
907 my $freqs_href = freqs_href();
909 if ( exists($freqs_href->{$freq}) ) {
910 $freqs_href->{$freq};
912 my $interval = 'month';
913 if ( $freq =~ /^(\d+)([hdw])$/ ) {
914 my %interval = ( 'h' => 'hour', 'd'=>'day', 'w'=>'week' );
915 $interval = $interval{$2};
920 "every $freq ${interval}s";
925 =item add_freq TIMESTAMP [ FREQ ]
927 Adds a billing period of some frequency to the provided timestamp and
928 returns the resulting timestamp, or -1 if the frequency could not be
929 parsed (shouldn't happen). By default, the frequency of this package
930 will be used; to override this, pass a different frequency as a second
936 my( $self, $date, $freq ) = @_;
937 $freq = $self->freq unless $freq;
939 #change this bit to use Date::Manip? CAREFUL with timezones (see
940 # mailing list archive)
941 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($date) )[0,1,2,3,4,5];
943 if ( $freq =~ /^\d+$/ ) {
945 until ( $mon < 12 ) { $mon -= 12; $year++; }
947 $mday = 28 if $mday > 28 && FS::Conf->new->exists('anniversary-rollback');
949 } elsif ( $freq =~ /^(\d+)w$/ ) {
952 } elsif ( $freq =~ /^(\d+)d$/ ) {
955 } elsif ( $freq =~ /^(\d+)h$/ ) {
962 timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
967 For backwards compatibility, returns the plandata field as well as all options
968 from FS::part_pkg_option.
974 carp "plandata is deprecated";
976 $self->SUPER::plandata(@_);
978 my $plandata = $self->get('plandata');
979 my %options = $self->options;
980 $plandata .= join('', map { "$_=$options{$_}\n" } keys %options );
985 =item part_pkg_vendor
987 Returns all vendor/external package ids as FS::part_pkg_vendor objects (see
988 L<FS::part_pkg_vendor>).
992 sub part_pkg_vendor {
994 qsearch('part_pkg_vendor', { 'pkgpart' => $self->pkgpart } );
999 Returns a list of vendor/external package ids by exportnum
1003 sub vendor_pkg_ids {
1005 map { $_->exportnum => $_->vendor_pkg_id } $self->part_pkg_vendor;
1008 =item part_pkg_option
1010 Returns all options as FS::part_pkg_option objects (see
1011 L<FS::part_pkg_option>).
1015 sub part_pkg_option {
1017 qsearch('part_pkg_option', { 'pkgpart' => $self->pkgpart } );
1022 Returns a list of option names and values suitable for assigning to a hash.
1028 map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
1031 =item option OPTIONNAME [ QUIET ]
1033 Returns the option value for the given name, or the empty string. If a true
1034 value is passed as the second argument, warnings about missing the option
1040 my( $self, $opt, $ornull ) = @_;
1041 my $part_pkg_option =
1042 qsearchs('part_pkg_option', {
1043 pkgpart => $self->pkgpart,
1046 return $part_pkg_option->optionvalue if $part_pkg_option;
1047 my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
1048 split("\n", $self->get('plandata') );
1049 return $plandata{$opt} if exists $plandata{$opt};
1050 cluck "WARNING: (pkgpart ". $self->pkgpart. ") Package def option $opt ".
1051 "not found in options or plandata!\n"
1056 =item bill_part_pkg_link
1058 Returns the associated part_pkg_link records (see L<FS::part_pkg_link>).
1062 sub bill_part_pkg_link {
1063 shift->_part_pkg_link('bill', @_);
1066 =item svc_part_pkg_link
1068 Returns the associated part_pkg_link records (see L<FS::part_pkg_link>).
1072 sub svc_part_pkg_link {
1073 shift->_part_pkg_link('svc', @_);
1076 sub _part_pkg_link {
1077 my( $self, $type ) = @_;
1078 qsearch({ table => 'part_pkg_link',
1079 hashref => { 'src_pkgpart' => $self->pkgpart,
1080 'link_type' => $type,
1081 #protection against infinite recursive links
1082 'dst_pkgpart' => { op=>'!=', value=> $self->pkgpart },
1084 order_by => "ORDER BY hidden",
1088 sub self_and_bill_linked {
1089 shift->_self_and_linked('bill', @_);
1092 sub self_and_svc_linked {
1093 shift->_self_and_linked('svc', @_);
1096 sub _self_and_linked {
1097 my( $self, $type, $hidden ) = @_;
1101 foreach ( ( $self, map { $_->dst_pkg->_self_and_linked($type, $_->hidden) }
1102 $self->_part_pkg_link($type) ) )
1104 $_->hidden($hidden) if $hidden;
1111 =item part_pkg_taxoverride [ CLASS ]
1113 Returns all associated FS::part_pkg_taxoverride objects (see
1114 L<FS::part_pkg_taxoverride>). Limits the returned set to those
1115 of class CLASS if defined. Class may be one of 'setup', 'recur',
1116 the empty string (default), or a usage class number (see L<FS::usage_class>).
1117 When a class is specified, the empty string class (default) is returned
1118 if no more specific values exist.
1122 sub part_pkg_taxoverride {
1126 my $hashref = { 'pkgpart' => $self->pkgpart };
1127 $hashref->{'usage_class'} = $class if defined($class);
1128 my @overrides = qsearch('part_pkg_taxoverride', $hashref );
1130 unless ( scalar(@overrides) || !defined($class) || !$class ){
1131 $hashref->{'usage_class'} = '';
1132 @overrides = qsearch('part_pkg_taxoverride', $hashref );
1138 =item has_taxproduct
1140 Returns true if this package has any taxproduct associated with it.
1144 sub has_taxproduct {
1147 $self->taxproductnum ||
1148 scalar( grep { $_ =~/^usage_taxproductnum_/ && $self->option($_) }
1149 keys %{ {$self->options} }
1155 =item taxproduct [ CLASS ]
1157 Returns the associated tax product for this package definition (see
1158 L<FS::part_pkg_taxproduct>). CLASS may be one of 'setup', 'recur' or
1159 the usage classnum (see L<FS::usage_class>). Returns the default
1160 tax product for this record if the more specific CLASS value does
1169 my $part_pkg_taxproduct;
1171 my $taxproductnum = $self->taxproductnum;
1173 my $class_taxproductnum = $self->option("usage_taxproductnum_$class", 1);
1174 $taxproductnum = $class_taxproductnum
1175 if $class_taxproductnum
1178 $part_pkg_taxproduct =
1179 qsearchs( 'part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum } );
1181 unless ($part_pkg_taxproduct || $taxproductnum eq $self->taxproductnum ) {
1182 $taxproductnum = $self->taxproductnum;
1183 $part_pkg_taxproduct =
1184 qsearchs( 'part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum } );
1187 $part_pkg_taxproduct;
1190 =item taxproduct_description [ CLASS ]
1192 Returns the description of the associated tax product for this package
1193 definition (see L<FS::part_pkg_taxproduct>).
1197 sub taxproduct_description {
1199 my $part_pkg_taxproduct = $self->taxproduct(@_);
1200 $part_pkg_taxproduct ? $part_pkg_taxproduct->description : '';
1203 =item part_pkg_taxrate DATA_PROVIDER, GEOCODE, [ CLASS ]
1205 Returns the package to taxrate m2m records for this package in the location
1206 specified by GEOCODE (see L<FS::part_pkg_taxrate>) and usage class CLASS.
1207 CLASS may be one of 'setup', 'recur', or one of the usage classes numbers
1208 (see L<FS::usage_class>).
1212 sub _expand_cch_taxproductnum {
1215 my $part_pkg_taxproduct = $self->taxproduct($class);
1217 my ($a,$b,$c,$d) = ( $part_pkg_taxproduct
1218 ? ( split ':', $part_pkg_taxproduct->taxproduct )
1221 $a = '' unless $a; $b = '' unless $b; $c = '' unless $c; $d = '' unless $d;
1222 my $extra_sql = "AND ( taxproduct = '$a:$b:$c:$d'
1223 OR taxproduct = '$a:$b:$c:'
1224 OR taxproduct = '$a:$b:".":$d'
1225 OR taxproduct = '$a:$b:".":' )";
1226 map { $_->taxproductnum } qsearch( { 'table' => 'part_pkg_taxproduct',
1227 'hashref' => { 'data_vendor'=>'cch' },
1228 'extra_sql' => $extra_sql,
1233 sub part_pkg_taxrate {
1235 my ($data_vendor, $geocode, $class) = @_;
1238 my $extra_sql = 'WHERE part_pkg_taxproduct.data_vendor = '.
1239 dbh->quote($data_vendor);
1241 # CCH oddness in m2m
1242 $extra_sql .= ' AND ('.
1243 join(' OR ', map{ 'geocode = '. $dbh->quote(substr($geocode, 0, $_)) }
1247 # much more CCH oddness in m2m -- this is kludgy
1248 my @tpnums = $self->_expand_cch_taxproductnum($class);
1249 if (scalar(@tpnums)) {
1250 $extra_sql .= ' AND ('.
1251 join(' OR ', map{ "taxproductnum = $_" } @tpnums ).
1254 $extra_sql .= ' AND ( 0 = 1 )';
1257 my $addl_from = 'LEFT JOIN part_pkg_taxproduct USING ( taxproductnum )';
1258 my $order_by = 'ORDER BY taxclassnum, length(geocode) desc, length(taxproduct) desc';
1259 my $select = 'DISTINCT ON(taxclassnum) *, taxproduct';
1261 # should qsearch preface columns with the table to facilitate joins?
1262 qsearch( { 'table' => 'part_pkg_taxrate',
1263 'select' => $select,
1264 'hashref' => { # 'data_vendor' => $data_vendor,
1265 # 'taxproductnum' => $self->taxproductnum,
1267 'addl_from' => $addl_from,
1268 'extra_sql' => $extra_sql,
1269 'order_by' => $order_by,
1273 =item part_pkg_discount
1275 Returns the package to discount m2m records (see L<FS::part_pkg_discount>)
1280 sub part_pkg_discount {
1282 qsearch('part_pkg_discount', { 'pkgpart' => $self->pkgpart });
1287 Reblesses the object into the FS::part_pkg::PLAN class (if available), where
1288 PLAN is the object's I<plan> field. There should be better docs
1289 on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
1295 my $plan = $self->plan;
1297 cluck "no price plan found for pkgpart ". $self->pkgpart. "\n"
1301 return $self if ref($self) =~ /::$plan$/; #already blessed into plan subclass
1302 my $class = ref($self). "::$plan";
1303 warn "reblessing $self into $class" if $DEBUG;
1306 bless($self, $class) unless $@;
1311 sub calc_setup { die 'no calc_setup for '. shift->plan. "\n"; }
1312 sub calc_recur { die 'no calc_recur for '. shift->plan. "\n"; }
1314 #fallback that return 0 for old legacy packages with no plan
1315 sub calc_remain { 0; }
1316 sub calc_units { 0; }
1318 #fallback for everything not based on flat.pm
1319 sub recur_temporality { 'upcoming'; }
1320 sub calc_cancel { 0; }
1322 #fallback for everything except bulk.pm
1323 sub hide_svc_detail { 0; }
1325 #fallback for packages that can't/won't summarize usage
1326 sub sum_usage { 0; }
1328 =item recur_cost_permonth CUST_PKG
1330 recur_cost divided by freq (only supported for monthly and longer frequencies)
1334 sub recur_cost_permonth {
1335 my($self, $cust_pkg) = @_;
1336 return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0;
1337 sprintf('%.2f', $self->recur_cost / $self->freq );
1340 =item cust_bill_pkg_recur CUST_PKG
1342 Actual recurring charge for the specified customer package from customer's most
1347 sub cust_bill_pkg_recur {
1348 my($self, $cust_pkg) = @_;
1349 my $cust_bill_pkg = qsearchs({
1350 'table' => 'cust_bill_pkg',
1351 'addl_from' => 'LEFT JOIN cust_bill USING ( invnum )',
1352 'hashref' => { 'pkgnum' => $cust_pkg->pkgnum,
1353 'recur' => { op=>'>', value=>'0' },
1355 'order_by' => 'ORDER BY cust_bill._date DESC,
1356 cust_bill_pkg.sdate DESC
1359 }) or return 0; #die "use cust_bill_pkg_recur credits with once_perinv condition";
1360 $cust_bill_pkg->recur;
1363 =item format OPTION DATA
1365 Returns data formatted according to the function 'format' described
1366 in the plan info. Returns DATA if no such function exists.
1371 my ($self, $option, $data) = (shift, shift, shift);
1372 if (exists($plans{$self->plan}->{fields}->{$option}{format})) {
1373 &{$plans{$self->plan}->{fields}->{$option}{format}}($data);
1379 =item parse OPTION DATA
1381 Returns data parsed according to the function 'parse' described
1382 in the plan info. Returns DATA if no such function exists.
1387 my ($self, $option, $data) = (shift, shift, shift);
1388 if (exists($plans{$self->plan}->{fields}->{$option}{parse})) {
1389 &{$plans{$self->plan}->{fields}->{$option}{parse}}($data);
1399 =head1 CLASS METHODS
1407 # Used by FS::Upgrade to migrate to a new database.
1409 sub _upgrade_data { # class method
1410 my($class, %opts) = @_;
1412 warn "[FS::part_pkg] upgrading $class\n" if $DEBUG;
1414 my @part_pkg = qsearch({
1415 'table' => 'part_pkg',
1416 'extra_sql' => "WHERE ". join(' OR ',
1417 ( map "($_ IS NOT NULL AND $_ != '' )",
1418 qw( plandata setup recur ) ),
1419 'plan IS NULL', "plan = '' ",
1423 foreach my $part_pkg (@part_pkg) {
1425 unless ( $part_pkg->plan ) {
1426 $part_pkg->plan('flat');
1429 if ( length($part_pkg->option('setup_fee')) == 0
1430 && $part_pkg->setup =~ /^\s*([\d\.]+)\s*$/ ) {
1432 my $opt = new FS::part_pkg_option {
1433 'pkgpart' => $part_pkg->pkgpart,
1434 'optionname' => 'setup_fee',
1435 'optionvalue' => $1,
1437 my $error = $opt->insert;
1438 die $error if $error;
1442 # die "Can't parse part_pkg.setup for fee; convert pkgnum ".
1443 # $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
1445 $part_pkg->setup('');
1447 if ( length($part_pkg->option('recur_fee')) == 0
1448 && $part_pkg->recur =~ /^\s*([\d\.]+)\s*$/ ) {
1450 my $opt = new FS::part_pkg_option {
1451 'pkgpart' => $part_pkg->pkgpart,
1452 'optionname' => 'recur_fee',
1453 'optionvalue' => $1,
1455 my $error = $opt->insert;
1456 die $error if $error;
1460 # die "Can't parse part_pkg.setup for fee; convert pkgnum ".
1461 # $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
1463 $part_pkg->recur('');
1465 $part_pkg->replace; #this should take care of plandata, right?
1469 # now upgrade to the explicit custom flag
1471 @part_pkg = qsearch({
1472 'table' => 'part_pkg',
1473 'hashref' => { disabled => 'Y', custom => '' },
1474 'extra_sql' => "AND comment LIKE '(CUSTOM) %'",
1477 foreach my $part_pkg (@part_pkg) {
1478 my $new = new FS::part_pkg { $part_pkg->hash };
1480 my $comment = $part_pkg->comment;
1481 $comment =~ s/^\(CUSTOM\) //;
1482 $comment = '(none)' unless $comment =~ /\S/;
1483 $new->comment($comment);
1485 my $pkg_svc = { map { $_->svcpart => $_->quantity } $part_pkg->pkg_svc };
1486 my $primary = $part_pkg->svcpart;
1487 my $options = { $part_pkg->options };
1489 my $error = $new->replace( $part_pkg,
1490 'pkg_svc' => $pkg_svc,
1491 'primary_svc' => $primary,
1492 'options' => $options,
1494 die $error if $error;
1497 my @part_pkg_option = qsearch('part_pkg_option',
1498 { 'optionname' => 'unused_credit',
1501 foreach my $old_opt (@part_pkg_option) {
1502 my $pkgpart = $old_opt->pkgpart;
1503 my $error = $old_opt->delete;
1504 die $error if $error;
1506 foreach (qw(unused_credit_cancel unused_credit_change)) {
1507 my $new_opt = new FS::part_pkg_option {
1508 'pkgpart' => $pkgpart,
1512 $error = $new_opt->insert;
1513 die $error if $error;
1517 # migrate use_disposition_taqua and use_disposition to disposition_in
1518 @part_pkg_option = qsearch('part_pkg_option',
1519 { 'optionname' => { op => 'LIKE',
1520 value => 'use_disposition%',
1524 my %newopts = map { $_->pkgpart => $_ }
1525 qsearch('part_pkg_option', { 'optionname' => 'disposition_in', } );
1526 foreach my $old_opt (@part_pkg_option) {
1527 my $pkgpart = $old_opt->pkgpart;
1528 my $newval = $old_opt->optionname eq 'use_disposition_taqua' ? '100'
1530 my $error = $old_opt->delete;
1531 die $error if $error;
1533 if ( exists($newopts{$pkgpart}) ) {
1534 my $opt = $newopts{$pkgpart};
1535 $opt->optionvalue($opt->optionvalue.",$newval");
1536 $error = $opt->replace;
1537 die $error if $error;
1539 my $new_opt = new FS::part_pkg_option {
1540 'pkgpart' => $pkgpart,
1541 'optionname' => 'disposition_in',
1542 'optionvalue' => $newval,
1544 $error = $new_opt->insert;
1545 die $error if $error;
1546 $newopts{$pkgpart} = $new_opt;
1550 # set any package with FCC voice lines to the "VoIP with broadband" category
1551 # for backward compatibility
1553 # recover from a bad upgrade bug
1554 my $upgrade = 'part_pkg_fcc_voip_class_FIX';
1555 if (!FS::upgrade_journal->is_done($upgrade)) {
1556 my $bad_upgrade = qsearchs('upgrade_journal',
1557 { upgrade => 'part_pkg_fcc_voip_class' }
1559 if ( $bad_upgrade ) {
1560 my $where = 'WHERE history_date <= '.$bad_upgrade->_date.
1561 ' AND history_date > '.($bad_upgrade->_date - 3600);
1562 my @h_part_pkg_option = map { FS::part_pkg_option->new($_->hashref) }
1565 'table' => 'h_part_pkg_option',
1567 'extra_sql' => "$where AND history_action = 'delete'",
1568 'order_by' => 'ORDER BY history_date ASC',
1570 my @h_pkg_svc = map { FS::pkg_svc->new($_->hashref) }
1573 'table' => 'h_pkg_svc',
1575 'extra_sql' => "$where AND history_action = 'replace_old'",
1576 'order_by' => 'ORDER BY history_date ASC',
1579 foreach my $deleted (@h_part_pkg_option, @h_pkg_svc) {
1580 my $pkgpart ||= $deleted->pkgpart;
1581 $opt{$pkgpart} ||= {
1587 if ( $deleted->isa('FS::part_pkg_option') ) {
1588 $opt{$pkgpart}{options}{ $deleted->optionname } = $deleted->optionvalue;
1590 my $svcpart = $deleted->svcpart;
1591 $opt{$pkgpart}{pkg_svc}{$svcpart} = $deleted->quantity;
1592 $opt{$pkgpart}{hidden_svc}{$svcpart} ||= $deleted->hidden;
1593 $opt{$pkgpart}{primary_svc} = $svcpart if $deleted->primary_svc;
1596 foreach my $pkgpart (keys %opt) {
1597 my $part_pkg = FS::part_pkg->by_key($pkgpart);
1598 my $error = $part_pkg->replace( $part_pkg->replace_old, $opt{$pkgpart} );
1600 die "error recovering damaged pkgpart $pkgpart:\n$error\n";
1603 } # $bad_upgrade exists
1604 else { # do the original upgrade, but correctly this time
1605 @part_pkg = qsearch('part_pkg', {
1606 fcc_ds0s => { op => '>', value => 0 },
1607 fcc_voip_class => ''
1609 foreach my $part_pkg (@part_pkg) {
1610 $part_pkg->set(fcc_voip_class => 2);
1611 my @pkg_svc = $part_pkg->pkg_svc;
1612 my %quantity = map {$_->svcpart, $_->quantity} @pkg_svc;
1613 my %hidden = map {$_->svcpart, $_->hidden } @pkg_svc;
1614 my $error = $part_pkg->replace(
1615 $part_pkg->replace_old,
1616 options => { $part_pkg->options },
1617 pkg_svc => \%quantity,
1618 hidden_svc => \%hidden,
1619 primary_svc => ($part_pkg->svcpart || ''),
1621 die $error if $error;
1624 FS::upgrade_journal->set_done($upgrade);
1629 =item curuser_pkgs_sql
1631 Returns an SQL fragment for searching for packages the current user can
1632 use, either via part_pkg.agentnum directly, or via agent type (see
1637 sub curuser_pkgs_sql {
1640 $class->_pkgs_sql( $FS::CurrentUser::CurrentUser->agentnums );
1644 =item agent_pkgs_sql AGENT | AGENTNUM, ...
1646 Returns an SQL fragment for searching for packages the provided agent or agents
1647 can use, either via part_pkg.agentnum directly, or via agent type (see
1652 sub agent_pkgs_sql {
1653 my $class = shift; #i'm a class method, not a sub (the question is... why??)
1654 my @agentnums = map { ref($_) ? $_->agentnum : $_ } @_;
1656 $class->_pkgs_sql(@agentnums); #is this why
1661 my( $class, @agentnums ) = @_;
1662 my $agentnums = join(',', @agentnums);
1666 ( agentnum IS NOT NULL AND agentnum IN ($agentnums) )
1667 OR ( agentnum IS NULL
1668 AND EXISTS ( SELECT 1
1670 LEFT JOIN agent_type USING ( typenum )
1671 LEFT JOIN agent AS typeagent USING ( typenum )
1672 WHERE type_pkgs.pkgpart = part_pkg.pkgpart
1673 AND typeagent.agentnum IN ($agentnums)
1691 #false laziness w/part_export & cdr
1693 foreach my $INC ( @INC ) {
1694 warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
1695 foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
1696 warn "attempting to load plan info from $file\n" if $DEBUG;
1697 $file =~ /\/(\w+)\.pm$/ or do {
1698 warn "unrecognized file in $INC/FS/part_pkg/: $file\n";
1702 my $info = eval "use FS::part_pkg::$mod; ".
1703 "\\%FS::part_pkg::$mod\::info;";
1705 die "error using FS::part_pkg::$mod (skipping): $@\n" if $@;
1708 unless ( keys %$info ) {
1709 warn "no %info hash found in FS::part_pkg::$mod, skipping\n";
1712 warn "got plan info from FS::part_pkg::$mod: $info\n" if $DEBUG;
1713 #if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
1714 # warn "skipping disabled plan FS::part_pkg::$mod" if $DEBUG;
1717 $info{$mod} = $info;
1718 $info->{'weight'} ||= 0; # quiet warnings
1722 # copy one level deep to allow replacement of fields and fieldorder
1723 tie %plans, 'Tie::IxHash',
1724 map { my %infohash = %{ $info{$_} };
1726 sort { $info{$a}->{'weight'} <=> $info{$b}->{'weight'} }
1729 # inheritance of plan options
1730 foreach my $name (keys(%info)) {
1731 if (exists($info{$name}->{'disabled'}) and $info{$name}->{'disabled'}) {
1732 warn "skipping disabled plan FS::part_pkg::$name" if $DEBUG;
1733 delete $plans{$name};
1736 my $parents = $info{$name}->{'inherit_fields'} || [];
1737 my (%fields, %field_exists, @fieldorder);
1738 foreach my $parent ($name, @$parents) {
1739 if ( !exists($info{$parent}) ) {
1740 warn "$name tried to inherit from nonexistent '$parent'\n";
1743 %fields = ( # avoid replacing existing fields
1744 %{ $info{$parent}->{'fields'} || {} },
1747 foreach (@{ $info{$parent}->{'fieldorder'} || [] }) {
1749 next if $field_exists{$_};
1750 $field_exists{$_} = 1;
1751 # allow inheritors to remove inherited fields from the fieldorder
1752 push @fieldorder, $_ if !exists($fields{$_}) or
1753 !exists($fields{$_}->{'disabled'});
1756 $plans{$name}->{'fields'} = \%fields;
1757 $plans{$name}->{'fieldorder'} = \@fieldorder;
1767 =head1 NEW PLAN CLASSES
1769 A module should be added in FS/FS/part_pkg/ Eventually, an example may be
1770 found in eg/plan_template.pm. Until then, it is suggested that you use the
1771 other modules in FS/FS/part_pkg/ as a guide.
1775 The delete method is unimplemented.
1777 setup and recur semantics are not yet defined (and are implemented in
1778 FS::cust_bill. hmm.). now they're deprecated and need to go.
1782 part_pkg_taxrate is Pg specific
1784 replace should be smarter about managing the related tables (options, pkg_svc)
1788 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
1789 schema.html from the base documentation.