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_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
117 Creates a new package definition. To add the package definition to
118 the database, see L<"insert">.
122 sub table { 'part_pkg'; }
126 An alternate constructor. Creates a new package definition by duplicating
127 an existing definition. A new pkgpart is assigned and the custom flag is
128 set to Y. To add the package definition to the database, see L<"insert">.
134 my $class = ref($self);
135 my %hash = $self->hash;
136 $hash{'pkgpart'} = '';
137 $hash{'custom'} = 'Y';
138 #new FS::part_pkg ( \%hash ); # ?
139 new $class ( \%hash ); # ?
142 =item insert [ , OPTION => VALUE ... ]
144 Adds this package definition to the database. If there is an error,
145 returns the error, otherwise returns false.
147 Currently available options are: I<pkg_svc>, I<primary_svc>, I<cust_pkg>,
148 I<custnum_ref> and I<options>.
150 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
151 values, appropriate FS::pkg_svc records will be inserted. I<hidden_svc> can
152 be set to a hashref of svcparts and flag values ('Y' or '') to set the
153 'hidden' field in these records.
155 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
156 FS::pkg_svc record will be updated.
158 If I<cust_pkg> is set to a pkgnum of a FS::cust_pkg record (or the FS::cust_pkg
159 record itself), the object will be updated to point to this package definition.
161 In conjunction with I<cust_pkg>, if I<custnum_ref> is set to a scalar reference,
162 the scalar will be updated with the custnum value from the cust_pkg record.
164 If I<tax_overrides> is set to a hashref with usage classes as keys and comma
165 separated tax class numbers as values, appropriate FS::part_pkg_taxoverride
166 records will be inserted.
168 If I<options> is set to a hashref of options, appropriate FS::part_pkg_option
169 records will be inserted.
176 warn "FS::part_pkg::insert called on $self with options ".
177 join(', ', map "$_=>$options{$_}", keys %options)
180 local $SIG{HUP} = 'IGNORE';
181 local $SIG{INT} = 'IGNORE';
182 local $SIG{QUIT} = 'IGNORE';
183 local $SIG{TERM} = 'IGNORE';
184 local $SIG{TSTP} = 'IGNORE';
185 local $SIG{PIPE} = 'IGNORE';
187 my $oldAutoCommit = $FS::UID::AutoCommit;
188 local $FS::UID::AutoCommit = 0;
191 warn " inserting part_pkg record" if $DEBUG;
192 my $error = $self->SUPER::insert( $options{options} );
194 $dbh->rollback if $oldAutoCommit;
198 my $conf = new FS::Conf;
199 if ( $conf->exists('agent_defaultpkg') ) {
200 warn " agent_defaultpkg set; allowing all agents to purchase package"
202 foreach my $agent_type ( qsearch('agent_type', {} ) ) {
203 my $type_pkgs = new FS::type_pkgs({
204 'typenum' => $agent_type->typenum,
205 'pkgpart' => $self->pkgpart,
207 my $error = $type_pkgs->insert;
209 $dbh->rollback if $oldAutoCommit;
215 warn " inserting part_pkg_taxoverride records" if $DEBUG;
216 my %overrides = %{ $options{'tax_overrides'} || {} };
217 foreach my $usage_class ( keys %overrides ) {
219 ( exists($overrides{$usage_class}) && defined($overrides{$usage_class}) )
220 ? $overrides{$usage_class}
222 my @overrides = (grep "$_", split(',', $override) );
223 my $error = $self->process_m2m (
224 'link_table' => 'part_pkg_taxoverride',
225 'target_table' => 'tax_class',
226 'hashref' => { 'usage_class' => $usage_class },
227 'params' => \@overrides,
230 $dbh->rollback if $oldAutoCommit;
235 unless ( $skip_pkg_svc_hack ) {
237 warn " inserting pkg_svc records" if $DEBUG;
238 my $pkg_svc = $options{'pkg_svc'} || {};
239 my $hidden_svc = $options{'hidden_svc'} || {};
240 foreach my $part_svc ( qsearch('part_svc', {} ) ) {
241 my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
243 ( $options{'primary_svc'} && $options{'primary_svc'}==$part_svc->svcpart )
247 my $pkg_svc = new FS::pkg_svc( {
248 'pkgpart' => $self->pkgpart,
249 'svcpart' => $part_svc->svcpart,
250 'quantity' => $quantity,
251 'primary_svc' => $primary_svc,
252 'hidden' => $hidden_svc->{$part_svc->svcpart},
254 my $error = $pkg_svc->insert;
256 $dbh->rollback if $oldAutoCommit;
263 if ( $options{'cust_pkg'} ) {
264 warn " updating cust_pkg record " if $DEBUG;
266 ref($options{'cust_pkg'})
267 ? $options{'cust_pkg'}
268 : qsearchs('cust_pkg', { pkgnum => $options{'cust_pkg'} } );
269 ${ $options{'custnum_ref'} } = $old_cust_pkg->custnum
270 if $options{'custnum_ref'};
271 my %hash = $old_cust_pkg->hash;
272 $hash{'pkgpart'} = $self->pkgpart,
273 my $new_cust_pkg = new FS::cust_pkg \%hash;
274 local($FS::cust_pkg::disable_agentcheck) = 1;
275 my $error = $new_cust_pkg->replace($old_cust_pkg);
277 $dbh->rollback if $oldAutoCommit;
278 return "Error modifying cust_pkg record: $error";
282 if ( $options{'part_pkg_vendor'} ) {
283 while ( my ($exportnum, $vendor_pkg_id) =
284 each %{ $options{part_pkg_vendor} }
287 my $ppv = new FS::part_pkg_vendor( {
288 'pkgpart' => $self->pkgpart,
289 'exportnum' => $exportnum,
290 'vendor_pkg_id' => $vendor_pkg_id,
292 my $error = $ppv->insert;
294 $dbh->rollback if $oldAutoCommit;
295 return "Error inserting part_pkg_vendor record: $error";
300 warn " commiting transaction" if $DEBUG;
301 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
308 Currently unimplemented.
313 return "Can't (yet?) delete package definitions.";
314 # check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
317 =item replace OLD_RECORD [ , OPTION => VALUE ... ]
319 Replaces OLD_RECORD with this one in the database. If there is an error,
320 returns the error, otherwise returns false.
322 Currently available options are: I<pkg_svc>, I<hidden_svc>, I<primary_svc>
325 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
326 values, the appropriate FS::pkg_svc records will be replaced. I<hidden_svc>
327 can be set to a hashref of svcparts and flag values ('Y' or '') to set the
328 'hidden' field in these records.
330 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
331 FS::pkg_svc record will be updated.
333 If I<options> is set to a hashref, the appropriate FS::part_pkg_option records
341 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
346 ( ref($_[0]) eq 'HASH' )
350 $options->{options} = {} unless defined($options->{options});
352 warn "FS::part_pkg::replace called on $new to replace $old with options".
353 join(', ', map "$_ => ". $options->{$_}, keys %$options)
356 local $SIG{HUP} = 'IGNORE';
357 local $SIG{INT} = 'IGNORE';
358 local $SIG{QUIT} = 'IGNORE';
359 local $SIG{TERM} = 'IGNORE';
360 local $SIG{TSTP} = 'IGNORE';
361 local $SIG{PIPE} = 'IGNORE';
363 my $oldAutoCommit = $FS::UID::AutoCommit;
364 local $FS::UID::AutoCommit = 0;
367 #plandata shit stays in replace for upgrades until after 2.0 (or edit
369 warn " saving legacy plandata" if $DEBUG;
370 my $plandata = $new->get('plandata');
371 $new->set('plandata', '');
373 warn " deleting old part_pkg_option records" if $DEBUG;
374 foreach my $part_pkg_option ( $old->part_pkg_option ) {
375 my $error = $part_pkg_option->delete;
377 $dbh->rollback if $oldAutoCommit;
382 warn " replacing part_pkg record" if $DEBUG;
383 my $error = $new->SUPER::replace($old, $options->{options} );
385 $dbh->rollback if $oldAutoCommit;
389 warn " inserting part_pkg_option records for plandata: $plandata|" if $DEBUG;
390 foreach my $part_pkg_option (
391 map { /^(\w+)=(.*)$/ or do { $dbh->rollback if $oldAutoCommit;
392 return "illegal plandata: $plandata";
394 new FS::part_pkg_option {
395 'pkgpart' => $new->pkgpart,
400 split("\n", $plandata)
402 my $error = $part_pkg_option->insert;
404 $dbh->rollback if $oldAutoCommit;
409 warn " replacing pkg_svc records" if $DEBUG;
410 my $pkg_svc = $options->{'pkg_svc'} || {};
411 my $hidden_svc = $options->{'hidden_svc'} || {};
412 foreach my $part_svc ( qsearch('part_svc', {} ) ) {
413 my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
414 my $hidden = $hidden_svc->{$part_svc->svcpart} || '';
416 ( defined($options->{'primary_svc'}) && $options->{'primary_svc'}
417 && $options->{'primary_svc'} == $part_svc->svcpart
422 my $old_pkg_svc = qsearchs('pkg_svc', {
423 'pkgpart' => $old->pkgpart,
424 'svcpart' => $part_svc->svcpart,
427 my $old_quantity = 0;
428 my $old_primary_svc = '';
430 if ( $old_pkg_svc ) {
431 $old_quantity = $old_pkg_svc->quantity;
432 $old_primary_svc = $old_pkg_svc->primary_svc
433 if $old_pkg_svc->dbdef_table->column('primary_svc'); # is this needed?
434 $old_hidden = $old_pkg_svc->hidden;
437 next unless $old_quantity != $quantity ||
438 $old_primary_svc ne $primary_svc ||
439 $old_hidden ne $hidden;
441 my $new_pkg_svc = new FS::pkg_svc( {
442 'pkgsvcnum' => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
443 'pkgpart' => $new->pkgpart,
444 'svcpart' => $part_svc->svcpart,
445 'quantity' => $quantity,
446 'primary_svc' => $primary_svc,
449 my $error = $old_pkg_svc
450 ? $new_pkg_svc->replace($old_pkg_svc)
451 : $new_pkg_svc->insert;
453 $dbh->rollback if $oldAutoCommit;
458 my @part_pkg_vendor = $old->part_pkg_vendor;
459 my @current_exportnum = ();
460 if ( $options->{'part_pkg_vendor'} ) {
461 my($exportnum,$vendor_pkg_id);
462 while ( ($exportnum,$vendor_pkg_id)
463 = each %{$options->{'part_pkg_vendor'}} ) {
465 foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
466 if($exportnum == $part_pkg_vendor->exportnum
467 && $vendor_pkg_id ne $part_pkg_vendor->vendor_pkg_id) {
468 $part_pkg_vendor->vendor_pkg_id($vendor_pkg_id);
469 my $error = $part_pkg_vendor->replace;
471 $dbh->rollback if $oldAutoCommit;
472 return "Error replacing part_pkg_vendor record: $error";
477 elsif($exportnum == $part_pkg_vendor->exportnum
478 && $vendor_pkg_id eq $part_pkg_vendor->vendor_pkg_id) {
483 unless ( $noinsert ) {
484 my $ppv = new FS::part_pkg_vendor( {
485 'pkgpart' => $new->pkgpart,
486 'exportnum' => $exportnum,
487 'vendor_pkg_id' => $vendor_pkg_id,
489 my $error = $ppv->insert;
491 $dbh->rollback if $oldAutoCommit;
492 return "Error inserting part_pkg_vendor record: $error";
495 push @current_exportnum, $exportnum;
498 foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
499 unless ( grep($_ eq $part_pkg_vendor->exportnum, @current_exportnum) ) {
500 my $error = $part_pkg_vendor->delete;
502 $dbh->rollback if $oldAutoCommit;
503 return "Error deleting part_pkg_vendor record: $error";
508 warn " commiting transaction" if $DEBUG;
509 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
515 Checks all fields to make sure this is a valid package definition. If
516 there is an error, returns the error, otherwise returns false. Called by the
517 insert and replace methods.
523 warn "FS::part_pkg::check called on $self" if $DEBUG;
525 for (qw(setup recur plandata)) {
526 #$self->set($_=>0) if $self->get($_) =~ /^\s*$/; }
527 return "Use of $_ field is deprecated; set a plan and options: ".
529 if length($self->get($_));
533 if ( $self->dbdef_table->column('freq')->type =~ /(int)/i ) {
534 my $error = $self->ut_number('freq');
535 return $error if $error;
537 $self->freq =~ /^(\d+[hdw]?)$/
538 or return "Illegal or empty freq: ". $self->freq;
542 my @null_agentnum_right = ( 'Edit global package definitions' );
543 push @null_agentnum_right, 'One-time charge'
544 if $self->freq =~ /^0/;
545 push @null_agentnum_right, 'Customize customer package'
546 if $self->disabled eq 'Y'; #good enough
548 my $error = $self->ut_numbern('pkgpart')
549 || $self->ut_text('pkg')
550 || $self->ut_text('comment')
551 || $self->ut_textn('promo_code')
552 || $self->ut_alphan('plan')
553 || $self->ut_enum('setuptax', [ '', 'Y' ] )
554 || $self->ut_enum('recurtax', [ '', 'Y' ] )
555 || $self->ut_textn('taxclass')
556 || $self->ut_enum('disabled', [ '', 'Y' ] )
557 || $self->ut_enum('custom', [ '', 'Y' ] )
558 || $self->ut_enum('no_auto', [ '', 'Y' ])
559 || $self->ut_enum('recur_show_zero', [ '', 'Y' ])
560 || $self->ut_enum('setup_show_zero', [ '', 'Y' ])
561 #|| $self->ut_moneyn('setup_cost')
562 #|| $self->ut_moneyn('recur_cost')
563 || $self->ut_floatn('setup_cost')
564 || $self->ut_floatn('recur_cost')
565 || $self->ut_floatn('pay_weight')
566 || $self->ut_floatn('credit_weight')
567 || $self->ut_numbern('taxproductnum')
568 || $self->ut_foreign_keyn('classnum', 'pkg_class', 'classnum')
569 || $self->ut_foreign_keyn('addon_classnum', 'pkg_class', 'classnum')
570 || $self->ut_foreign_keyn('taxproductnum',
571 'part_pkg_taxproduct',
575 ? $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
576 : $self->ut_agentnum_acl('agentnum', \@null_agentnum_right)
578 || $self->ut_numbern('fcc_ds0s')
579 || $self->ut_numbern('fcc_voip_class')
580 || $self->SUPER::check
582 return $error if $error;
584 return 'Unknown plan '. $self->plan
585 unless exists($plans{$self->plan});
587 my $conf = new FS::Conf;
588 return 'Taxclass is required'
589 if ! $self->taxclass && $conf->exists('require_taxclasses');
594 =item pkg_comment [ OPTION => VALUE... ]
596 Returns an (internal) string representing this package. Currently,
597 "pkgpart: pkg - comment", is returned. "pkg - comment" may be returned in the
598 future, omitting pkgpart. The comment will have '(CUSTOM) ' prepended if
601 If the option nopkgpart is true then the "pkgpart: ' is omitted.
609 #$self->pkg. ' - '. $self->comment;
610 #$self->pkg. ' ('. $self->comment. ')';
611 my $pre = $opt{nopkgpart} ? '' : $self->pkgpart. ': ';
612 $pre. $self->pkg. ' - '. $self->custom_comment;
615 sub price_info { # safety, in case a part_pkg hasn't defined price_info
621 ( $self->custom ? '(CUSTOM) ' : '' ). $self->comment . ' ' . $self->price_info;
626 Returns the package class, as an FS::pkg_class object, or the empty string
627 if there is no package class.
633 if ( $self->classnum ) {
634 qsearchs('pkg_class', { 'classnum' => $self->classnum } );
640 =item addon_pkg_class
642 Returns the add-on package class, as an FS::pkg_class object, or the empty
643 string if there is no add-on package class.
647 sub addon_pkg_class {
649 if ( $self->addon_classnum ) {
650 qsearchs('pkg_class', { 'classnum' => $self->addon_classnum } );
658 Returns the package category name, or the empty string if there is no package
665 my $pkg_class = $self->pkg_class;
667 ? $pkg_class->categoryname
673 Returns the package class name, or the empty string if there is no package
680 my $pkg_class = $self->pkg_class;
682 ? $pkg_class->classname
686 =item addon_classname
688 Returns the add-on package class name, or the empty string if there is no
689 add-on package class.
693 sub addon_classname {
695 my $pkg_class = $self->addon_pkg_class;
697 ? $pkg_class->classname
703 Returns the associated agent for this event, if any, as an FS::agent object.
709 qsearchs('agent', { 'agentnum' => $self->agentnum } );
712 =item pkg_svc [ HASHREF | OPTION => VALUE ]
714 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
715 definition (with non-zero quantity).
717 One option is available, I<disable_linked>. If set true it will return the
718 services for this package definition alone, omitting services from any add-on
725 Returns all FS::type_pkgs objects (see L<FS::type_pkgs>) for this package
732 qsearch('type_pkgs', { 'pkgpart' => $self->pkgpart } );
738 # #sort { $b->primary cmp $a->primary }
739 # grep { $_->quantity }
740 # qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
742 my $opt = ref($_[0]) ? $_[0] : { @_ };
743 my %pkg_svc = map { $_->svcpart => $_ }
744 grep { $_->quantity }
745 qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
747 unless ( $opt->{disable_linked} ) {
748 foreach my $dst_pkg ( map $_->dst_pkg, $self->svc_part_pkg_link ) {
749 my @pkg_svc = grep { $_->quantity }
750 qsearch( 'pkg_svc', { pkgpart=>$dst_pkg->pkgpart } );
751 foreach my $pkg_svc ( @pkg_svc ) {
752 if ( $pkg_svc{$pkg_svc->svcpart} ) {
753 my $quantity = $pkg_svc{$pkg_svc->svcpart}->quantity;
754 $pkg_svc{$pkg_svc->svcpart}->quantity($quantity + $pkg_svc->quantity);
756 $pkg_svc{$pkg_svc->svcpart} = $pkg_svc;
766 =item svcpart [ SVCDB ]
768 Returns the svcpart of the primary service definition (see L<FS::part_svc>)
769 associated with this package definition (see L<FS::pkg_svc>). Returns
770 false if there not a primary service definition or exactly one service
771 definition with quantity 1, or if SVCDB is specified and does not match the
772 svcdb of the service definition. SVCDB can be specified as a scalar table
773 name, such as 'svc_acct', or as an arrayref of possible table names.
778 my $pkg_svc = shift->_primary_pkg_svc(@_);
779 $pkg_svc ? $pkg_svc->svcpart : '';
782 =item part_svc [ SVCDB ]
784 Like the B<svcpart> method, but returns the FS::part_svc object (see
790 my $pkg_svc = shift->_primary_pkg_svc(@_);
791 $pkg_svc ? $pkg_svc->part_svc : '';
794 sub _primary_pkg_svc {
797 my $svcdb = scalar(@_) ? shift : [];
798 $svcdb = ref($svcdb) ? $svcdb : [ $svcdb ];
799 my %svcdb = map { $_=>1 } @$svcdb;
802 grep { !scalar(@$svcdb) || $svcdb{ $_->part_svc->svcdb } }
805 my @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc;
806 @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
808 return '' if scalar(@pkg_svc) != 1;
812 =item svcpart_unique_svcdb SVCDB
814 Returns the svcpart of a service definition (see L<FS::part_svc>) matching
815 SVCDB associated with this package definition (see L<FS::pkg_svc>). Returns
816 false if there not a primary service definition for SVCDB or there are multiple
817 service definitions for SVCDB.
821 sub svcpart_unique_svcdb {
822 my( $self, $svcdb ) = @_;
823 my @svcdb_pkg_svc = grep { ( $svcdb eq $_->part_svc->svcdb ) } $self->pkg_svc;
824 return '' if scalar(@svcdb_pkg_svc) != 1;
825 $svcdb_pkg_svc[0]->svcpart;
830 Returns a list of the acceptable payment types for this package. Eventually
831 this should come out of a database table and be editable, but currently has the
832 following logic instead:
834 If the package is free, the single item B<BILL> is
835 returned, otherwise, the single item B<CARD> is returned.
837 (CHEK? LEC? Probably shouldn't accept those by default, prone to abuse)
843 if ( $self->is_free ) {
852 Returns true if this package is free.
858 if ( $self->can('is_free_options') ) {
859 not grep { $_ !~ /^\s*0*(\.0*)?\s*$/ }
860 map { $self->option($_) }
861 $self->is_free_options;
863 warn "FS::part_pkg::is_free: FS::part_pkg::". $self->plan. " subclass ".
864 "provides neither is_free_options nor is_free method; returning false";
869 sub can_discount { 0; }
871 sub can_start_date { 1; }
874 # moved to FS::Misc to make this accessible to other packages
876 FS::Misc::pkg_freqs();
881 Returns an english representation of the I<freq> field, such as "monthly",
882 "weekly", "semi-annually", etc.
888 my $freq = $self->freq;
890 #my $freqs_href = $self->freqs_href;
891 my $freqs_href = freqs_href();
893 if ( exists($freqs_href->{$freq}) ) {
894 $freqs_href->{$freq};
896 my $interval = 'month';
897 if ( $freq =~ /^(\d+)([hdw])$/ ) {
898 my %interval = ( 'h' => 'hour', 'd'=>'day', 'w'=>'week' );
899 $interval = $interval{$2};
904 "every $freq ${interval}s";
909 =item add_freq TIMESTAMP [ FREQ ]
911 Adds a billing period of some frequency to the provided timestamp and
912 returns the resulting timestamp, or -1 if the frequency could not be
913 parsed (shouldn't happen). By default, the frequency of this package
914 will be used; to override this, pass a different frequency as a second
920 my( $self, $date, $freq ) = @_;
921 $freq = $self->freq unless $freq;
923 #change this bit to use Date::Manip? CAREFUL with timezones (see
924 # mailing list archive)
925 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($date) )[0,1,2,3,4,5];
927 if ( $freq =~ /^\d+$/ ) {
929 until ( $mon < 12 ) { $mon -= 12; $year++; }
930 } elsif ( $freq =~ /^(\d+)w$/ ) {
933 } elsif ( $freq =~ /^(\d+)d$/ ) {
936 } elsif ( $freq =~ /^(\d+)h$/ ) {
943 timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
948 For backwards compatibility, returns the plandata field as well as all options
949 from FS::part_pkg_option.
955 carp "plandata is deprecated";
957 $self->SUPER::plandata(@_);
959 my $plandata = $self->get('plandata');
960 my %options = $self->options;
961 $plandata .= join('', map { "$_=$options{$_}\n" } keys %options );
966 =item part_pkg_vendor
968 Returns all vendor/external package ids as FS::part_pkg_vendor objects (see
969 L<FS::part_pkg_vendor>).
973 sub part_pkg_vendor {
975 qsearch('part_pkg_vendor', { 'pkgpart' => $self->pkgpart } );
980 Returns a list of vendor/external package ids by exportnum
986 map { $_->exportnum => $_->vendor_pkg_id } $self->part_pkg_vendor;
989 =item part_pkg_option
991 Returns all options as FS::part_pkg_option objects (see
992 L<FS::part_pkg_option>).
996 sub part_pkg_option {
998 qsearch('part_pkg_option', { 'pkgpart' => $self->pkgpart } );
1003 Returns a list of option names and values suitable for assigning to a hash.
1009 map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
1012 =item option OPTIONNAME [ QUIET ]
1014 Returns the option value for the given name, or the empty string. If a true
1015 value is passed as the second argument, warnings about missing the option
1021 my( $self, $opt, $ornull ) = @_;
1022 my $part_pkg_option =
1023 qsearchs('part_pkg_option', {
1024 pkgpart => $self->pkgpart,
1027 return $part_pkg_option->optionvalue if $part_pkg_option;
1028 my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
1029 split("\n", $self->get('plandata') );
1030 return $plandata{$opt} if exists $plandata{$opt};
1031 cluck "WARNING: (pkgpart ". $self->pkgpart. ") Package def option $opt ".
1032 "not found in options or plandata!\n"
1037 =item bill_part_pkg_link
1039 Returns the associated part_pkg_link records (see L<FS::part_pkg_link>).
1043 sub bill_part_pkg_link {
1044 shift->_part_pkg_link('bill', @_);
1047 =item svc_part_pkg_link
1049 Returns the associated part_pkg_link records (see L<FS::part_pkg_link>).
1053 sub svc_part_pkg_link {
1054 shift->_part_pkg_link('svc', @_);
1057 sub _part_pkg_link {
1058 my( $self, $type ) = @_;
1059 qsearch({ table => 'part_pkg_link',
1060 hashref => { 'src_pkgpart' => $self->pkgpart,
1061 'link_type' => $type,
1062 #protection against infinite recursive links
1063 'dst_pkgpart' => { op=>'!=', value=> $self->pkgpart },
1065 order_by => "ORDER BY hidden",
1069 sub self_and_bill_linked {
1070 shift->_self_and_linked('bill', @_);
1073 sub self_and_svc_linked {
1074 shift->_self_and_linked('svc', @_);
1077 sub _self_and_linked {
1078 my( $self, $type, $hidden ) = @_;
1082 foreach ( ( $self, map { $_->dst_pkg->_self_and_linked($type, $_->hidden) }
1083 $self->_part_pkg_link($type) ) )
1085 $_->hidden($hidden) if $hidden;
1092 =item part_pkg_taxoverride [ CLASS ]
1094 Returns all associated FS::part_pkg_taxoverride objects (see
1095 L<FS::part_pkg_taxoverride>). Limits the returned set to those
1096 of class CLASS if defined. Class may be one of 'setup', 'recur',
1097 the empty string (default), or a usage class number (see L<FS::usage_class>).
1098 When a class is specified, the empty string class (default) is returned
1099 if no more specific values exist.
1103 sub part_pkg_taxoverride {
1107 my $hashref = { 'pkgpart' => $self->pkgpart };
1108 $hashref->{'usage_class'} = $class if defined($class);
1109 my @overrides = qsearch('part_pkg_taxoverride', $hashref );
1111 unless ( scalar(@overrides) || !defined($class) || !$class ){
1112 $hashref->{'usage_class'} = '';
1113 @overrides = qsearch('part_pkg_taxoverride', $hashref );
1119 =item has_taxproduct
1121 Returns true if this package has any taxproduct associated with it.
1125 sub has_taxproduct {
1128 $self->taxproductnum ||
1129 scalar( grep { $_ =~/^usage_taxproductnum_/ && $self->option($_) }
1130 keys %{ {$self->options} }
1136 =item taxproduct [ CLASS ]
1138 Returns the associated tax product for this package definition (see
1139 L<FS::part_pkg_taxproduct>). CLASS may be one of 'setup', 'recur' or
1140 the usage classnum (see L<FS::usage_class>). Returns the default
1141 tax product for this record if the more specific CLASS value does
1150 my $part_pkg_taxproduct;
1152 my $taxproductnum = $self->taxproductnum;
1154 my $class_taxproductnum = $self->option("usage_taxproductnum_$class", 1);
1155 $taxproductnum = $class_taxproductnum
1156 if $class_taxproductnum
1159 $part_pkg_taxproduct =
1160 qsearchs( 'part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum } );
1162 unless ($part_pkg_taxproduct || $taxproductnum eq $self->taxproductnum ) {
1163 $taxproductnum = $self->taxproductnum;
1164 $part_pkg_taxproduct =
1165 qsearchs( 'part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum } );
1168 $part_pkg_taxproduct;
1171 =item taxproduct_description [ CLASS ]
1173 Returns the description of the associated tax product for this package
1174 definition (see L<FS::part_pkg_taxproduct>).
1178 sub taxproduct_description {
1180 my $part_pkg_taxproduct = $self->taxproduct(@_);
1181 $part_pkg_taxproduct ? $part_pkg_taxproduct->description : '';
1184 =item part_pkg_taxrate DATA_PROVIDER, GEOCODE, [ CLASS ]
1186 Returns the package to taxrate m2m records for this package in the location
1187 specified by GEOCODE (see L<FS::part_pkg_taxrate>) and usage class CLASS.
1188 CLASS may be one of 'setup', 'recur', or one of the usage classes numbers
1189 (see L<FS::usage_class>).
1193 sub _expand_cch_taxproductnum {
1196 my $part_pkg_taxproduct = $self->taxproduct($class);
1198 my ($a,$b,$c,$d) = ( $part_pkg_taxproduct
1199 ? ( split ':', $part_pkg_taxproduct->taxproduct )
1202 $a = '' unless $a; $b = '' unless $b; $c = '' unless $c; $d = '' unless $d;
1203 my $extra_sql = "AND ( taxproduct = '$a:$b:$c:$d'
1204 OR taxproduct = '$a:$b:$c:'
1205 OR taxproduct = '$a:$b:".":$d'
1206 OR taxproduct = '$a:$b:".":' )";
1207 map { $_->taxproductnum } qsearch( { 'table' => 'part_pkg_taxproduct',
1208 'hashref' => { 'data_vendor'=>'cch' },
1209 'extra_sql' => $extra_sql,
1214 sub part_pkg_taxrate {
1216 my ($data_vendor, $geocode, $class) = @_;
1219 my $extra_sql = 'WHERE part_pkg_taxproduct.data_vendor = '.
1220 dbh->quote($data_vendor);
1222 # CCH oddness in m2m
1223 $extra_sql .= ' AND ('.
1224 join(' OR ', map{ 'geocode = '. $dbh->quote(substr($geocode, 0, $_)) }
1228 # much more CCH oddness in m2m -- this is kludgy
1229 my @tpnums = $self->_expand_cch_taxproductnum($class);
1230 if (scalar(@tpnums)) {
1231 $extra_sql .= ' AND ('.
1232 join(' OR ', map{ "taxproductnum = $_" } @tpnums ).
1235 $extra_sql .= ' AND ( 0 = 1 )';
1238 my $addl_from = 'LEFT JOIN part_pkg_taxproduct USING ( taxproductnum )';
1239 my $order_by = 'ORDER BY taxclassnum, length(geocode) desc, length(taxproduct) desc';
1240 my $select = 'DISTINCT ON(taxclassnum) *, taxproduct';
1242 # should qsearch preface columns with the table to facilitate joins?
1243 qsearch( { 'table' => 'part_pkg_taxrate',
1244 'select' => $select,
1245 'hashref' => { # 'data_vendor' => $data_vendor,
1246 # 'taxproductnum' => $self->taxproductnum,
1248 'addl_from' => $addl_from,
1249 'extra_sql' => $extra_sql,
1250 'order_by' => $order_by,
1254 =item part_pkg_discount
1256 Returns the package to discount m2m records (see L<FS::part_pkg_discount>)
1261 sub part_pkg_discount {
1263 qsearch('part_pkg_discount', { 'pkgpart' => $self->pkgpart });
1268 Reblesses the object into the FS::part_pkg::PLAN class (if available), where
1269 PLAN is the object's I<plan> field. There should be better docs
1270 on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
1276 my $plan = $self->plan;
1278 cluck "no price plan found for pkgpart ". $self->pkgpart. "\n"
1282 return $self if ref($self) =~ /::$plan$/; #already blessed into plan subclass
1283 my $class = ref($self). "::$plan";
1284 warn "reblessing $self into $class" if $DEBUG;
1287 bless($self, $class) unless $@;
1292 sub calc_setup { die 'no calc_setup for '. shift->plan. "\n"; }
1293 sub calc_recur { die 'no calc_recur for '. shift->plan. "\n"; }
1295 #fallback that return 0 for old legacy packages with no plan
1296 sub calc_remain { 0; }
1297 sub calc_units { 0; }
1299 #fallback for everything not based on flat.pm
1300 sub recur_temporality { 'upcoming'; }
1301 sub calc_cancel { 0; }
1303 #fallback for everything except bulk.pm
1304 sub hide_svc_detail { 0; }
1306 #fallback for packages that can't/won't summarize usage
1307 sub sum_usage { 0; }
1309 =item recur_cost_permonth CUST_PKG
1311 recur_cost divided by freq (only supported for monthly and longer frequencies)
1315 sub recur_cost_permonth {
1316 my($self, $cust_pkg) = @_;
1317 return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0;
1318 sprintf('%.2f', $self->recur_cost / $self->freq );
1321 =item cust_bill_pkg_recur CUST_PKG
1323 Actual recurring charge for the specified customer package from customer's most
1328 sub cust_bill_pkg_recur {
1329 my($self, $cust_pkg) = @_;
1330 my $cust_bill_pkg = qsearchs({
1331 'table' => 'cust_bill_pkg',
1332 'addl_from' => 'LEFT JOIN cust_bill USING ( invnum )',
1333 'hashref' => { 'pkgnum' => $cust_pkg->pkgnum,
1334 'recur' => { op=>'>', value=>'0' },
1336 'order_by' => 'ORDER BY cust_bill._date DESC,
1337 cust_bill_pkg.sdate DESC
1340 }) or return 0; #die "use cust_bill_pkg_recur credits with once_perinv condition";
1341 $cust_bill_pkg->recur;
1344 =item format OPTION DATA
1346 Returns data formatted according to the function 'format' described
1347 in the plan info. Returns DATA if no such function exists.
1352 my ($self, $option, $data) = (shift, shift, shift);
1353 if (exists($plans{$self->plan}->{fields}->{$option}{format})) {
1354 &{$plans{$self->plan}->{fields}->{$option}{format}}($data);
1360 =item parse OPTION DATA
1362 Returns data parsed according to the function 'parse' described
1363 in the plan info. Returns DATA if no such function exists.
1368 my ($self, $option, $data) = (shift, shift, shift);
1369 if (exists($plans{$self->plan}->{fields}->{$option}{parse})) {
1370 &{$plans{$self->plan}->{fields}->{$option}{parse}}($data);
1380 =head1 CLASS METHODS
1388 # Used by FS::Upgrade to migrate to a new database.
1390 sub _upgrade_data { # class method
1391 my($class, %opts) = @_;
1393 warn "[FS::part_pkg] upgrading $class\n" if $DEBUG;
1395 my @part_pkg = qsearch({
1396 'table' => 'part_pkg',
1397 'extra_sql' => "WHERE ". join(' OR ',
1398 ( map "($_ IS NOT NULL AND $_ != '' )",
1399 qw( plandata setup recur ) ),
1400 'plan IS NULL', "plan = '' ",
1404 foreach my $part_pkg (@part_pkg) {
1406 unless ( $part_pkg->plan ) {
1407 $part_pkg->plan('flat');
1410 if ( length($part_pkg->option('setup_fee')) == 0
1411 && $part_pkg->setup =~ /^\s*([\d\.]+)\s*$/ ) {
1413 my $opt = new FS::part_pkg_option {
1414 'pkgpart' => $part_pkg->pkgpart,
1415 'optionname' => 'setup_fee',
1416 'optionvalue' => $1,
1418 my $error = $opt->insert;
1419 die $error if $error;
1423 # die "Can't parse part_pkg.setup for fee; convert pkgnum ".
1424 # $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
1426 $part_pkg->setup('');
1428 if ( length($part_pkg->option('recur_fee')) == 0
1429 && $part_pkg->recur =~ /^\s*([\d\.]+)\s*$/ ) {
1431 my $opt = new FS::part_pkg_option {
1432 'pkgpart' => $part_pkg->pkgpart,
1433 'optionname' => 'recur_fee',
1434 'optionvalue' => $1,
1436 my $error = $opt->insert;
1437 die $error if $error;
1441 # die "Can't parse part_pkg.setup for fee; convert pkgnum ".
1442 # $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
1444 $part_pkg->recur('');
1446 $part_pkg->replace; #this should take care of plandata, right?
1450 # now upgrade to the explicit custom flag
1452 @part_pkg = qsearch({
1453 'table' => 'part_pkg',
1454 'hashref' => { disabled => 'Y', custom => '' },
1455 'extra_sql' => "AND comment LIKE '(CUSTOM) %'",
1458 foreach my $part_pkg (@part_pkg) {
1459 my $new = new FS::part_pkg { $part_pkg->hash };
1461 my $comment = $part_pkg->comment;
1462 $comment =~ s/^\(CUSTOM\) //;
1463 $comment = '(none)' unless $comment =~ /\S/;
1464 $new->comment($comment);
1466 my $pkg_svc = { map { $_->svcpart => $_->quantity } $part_pkg->pkg_svc };
1467 my $primary = $part_pkg->svcpart;
1468 my $options = { $part_pkg->options };
1470 my $error = $new->replace( $part_pkg,
1471 'pkg_svc' => $pkg_svc,
1472 'primary_svc' => $primary,
1473 'options' => $options,
1475 die $error if $error;
1478 my @part_pkg_option = qsearch('part_pkg_option',
1479 { 'optionname' => 'unused_credit',
1482 foreach my $old_opt (@part_pkg_option) {
1483 my $pkgpart = $old_opt->pkgpart;
1484 my $error = $old_opt->delete;
1485 die $error if $error;
1487 foreach (qw(unused_credit_cancel unused_credit_change)) {
1488 my $new_opt = new FS::part_pkg_option {
1489 'pkgpart' => $pkgpart,
1493 $error = $new_opt->insert;
1494 die $error if $error;
1498 # migrate use_disposition_taqua and use_disposition to disposition_in
1499 @part_pkg_option = qsearch('part_pkg_option',
1500 { 'optionname' => { op => 'LIKE',
1501 value => 'use_disposition%',
1505 my %newopts = map { $_->pkgpart => $_ }
1506 qsearch('part_pkg_option', { 'optionname' => 'disposition_in', } );
1507 foreach my $old_opt (@part_pkg_option) {
1508 my $pkgpart = $old_opt->pkgpart;
1509 my $newval = $old_opt->optionname eq 'use_disposition_taqua' ? '100'
1511 my $error = $old_opt->delete;
1512 die $error if $error;
1514 if ( exists($newopts{$pkgpart}) ) {
1515 my $opt = $newopts{$pkgpart};
1516 $opt->optionvalue($opt->optionvalue.",$newval");
1517 $error = $opt->replace;
1518 die $error if $error;
1520 my $new_opt = new FS::part_pkg_option {
1521 'pkgpart' => $pkgpart,
1522 'optionname' => 'disposition_in',
1523 'optionvalue' => $newval,
1525 $error = $new_opt->insert;
1526 die $error if $error;
1527 $newopts{$pkgpart} = $new_opt;
1531 # set any package with FCC voice lines to the "VoIP with broadband" category
1532 # for backward compatibility
1534 # recover from a bad upgrade bug
1535 my $upgrade = 'part_pkg_fcc_voip_class_FIX';
1536 if (!FS::upgrade_journal->is_done($upgrade)) {
1537 my $bad_upgrade = qsearchs('upgrade_journal',
1538 { upgrade => 'part_pkg_fcc_voip_class' }
1540 if ( $bad_upgrade ) {
1541 my $where = 'WHERE history_date <= '.$bad_upgrade->_date.
1542 ' AND history_date > '.($bad_upgrade->_date - 3600);
1543 my @h_part_pkg_option = map { FS::part_pkg_option->new($_->hashref) }
1546 'table' => 'h_part_pkg_option',
1548 'extra_sql' => "$where AND history_action = 'delete'",
1549 'order_by' => 'ORDER BY history_date ASC',
1551 my @h_pkg_svc = map { FS::pkg_svc->new($_->hashref) }
1554 'table' => 'h_pkg_svc',
1556 'extra_sql' => "$where AND history_action = 'replace_old'",
1557 'order_by' => 'ORDER BY history_date ASC',
1560 foreach my $deleted (@h_part_pkg_option, @h_pkg_svc) {
1561 my $pkgpart ||= $deleted->pkgpart;
1562 $opt{$pkgpart} ||= {
1568 if ( $deleted->isa('FS::part_pkg_option') ) {
1569 $opt{$pkgpart}{options}{ $deleted->optionname } = $deleted->optionvalue;
1571 my $svcpart = $deleted->svcpart;
1572 $opt{$pkgpart}{pkg_svc}{$svcpart} = $deleted->quantity;
1573 $opt{$pkgpart}{hidden_svc}{$svcpart} ||= $deleted->hidden;
1574 $opt{$pkgpart}{primary_svc} = $svcpart if $deleted->primary_svc;
1577 foreach my $pkgpart (keys %opt) {
1578 my $part_pkg = FS::part_pkg->by_key($pkgpart);
1579 my $error = $part_pkg->replace( $part_pkg->replace_old, $opt{$pkgpart} );
1581 die "error recovering damaged pkgpart $pkgpart:\n$error\n";
1584 } # $bad_upgrade exists
1585 else { # do the original upgrade, but correctly this time
1586 @part_pkg = qsearch('part_pkg', {
1587 fcc_ds0s => { op => '>', value => 0 },
1588 fcc_voip_class => ''
1590 foreach my $part_pkg (@part_pkg) {
1591 $part_pkg->set(fcc_voip_class => 2);
1592 my @pkg_svc = $part_pkg->pkg_svc;
1593 my %quantity = map {$_->svcpart, $_->quantity} @pkg_svc;
1594 my %hidden = map {$_->svcpart, $_->hidden } @pkg_svc;
1595 my $error = $part_pkg->replace(
1596 $part_pkg->replace_old,
1597 options => { $part_pkg->options },
1598 pkg_svc => \%quantity,
1599 hidden_svc => \%hidden,
1600 primary_svc => ($part_pkg->svcpart || ''),
1602 die $error if $error;
1605 FS::upgrade_journal->set_done($upgrade);
1610 =item curuser_pkgs_sql
1612 Returns an SQL fragment for searching for packages the current user can
1613 use, either via part_pkg.agentnum directly, or via agent type (see
1618 sub curuser_pkgs_sql {
1621 $class->_pkgs_sql( $FS::CurrentUser::CurrentUser->agentnums );
1625 =item agent_pkgs_sql AGENT | AGENTNUM, ...
1627 Returns an SQL fragment for searching for packages the provided agent or agents
1628 can use, either via part_pkg.agentnum directly, or via agent type (see
1633 sub agent_pkgs_sql {
1634 my $class = shift; #i'm a class method, not a sub (the question is... why??)
1635 my @agentnums = map { ref($_) ? $_->agentnum : $_ } @_;
1637 $class->_pkgs_sql(@agentnums); #is this why
1642 my( $class, @agentnums ) = @_;
1643 my $agentnums = join(',', @agentnums);
1647 ( agentnum IS NOT NULL AND agentnum IN ($agentnums) )
1648 OR ( agentnum IS NULL
1649 AND EXISTS ( SELECT 1
1651 LEFT JOIN agent_type USING ( typenum )
1652 LEFT JOIN agent AS typeagent USING ( typenum )
1653 WHERE type_pkgs.pkgpart = part_pkg.pkgpart
1654 AND typeagent.agentnum IN ($agentnums)
1672 #false laziness w/part_export & cdr
1674 foreach my $INC ( @INC ) {
1675 warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
1676 foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
1677 warn "attempting to load plan info from $file\n" if $DEBUG;
1678 $file =~ /\/(\w+)\.pm$/ or do {
1679 warn "unrecognized file in $INC/FS/part_pkg/: $file\n";
1683 my $info = eval "use FS::part_pkg::$mod; ".
1684 "\\%FS::part_pkg::$mod\::info;";
1686 die "error using FS::part_pkg::$mod (skipping): $@\n" if $@;
1689 unless ( keys %$info ) {
1690 warn "no %info hash found in FS::part_pkg::$mod, skipping\n";
1693 warn "got plan info from FS::part_pkg::$mod: $info\n" if $DEBUG;
1694 #if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
1695 # warn "skipping disabled plan FS::part_pkg::$mod" if $DEBUG;
1698 $info{$mod} = $info;
1699 $info->{'weight'} ||= 0; # quiet warnings
1703 # copy one level deep to allow replacement of fields and fieldorder
1704 tie %plans, 'Tie::IxHash',
1705 map { my %infohash = %{ $info{$_} };
1707 sort { $info{$a}->{'weight'} <=> $info{$b}->{'weight'} }
1710 # inheritance of plan options
1711 foreach my $name (keys(%info)) {
1712 if (exists($info{$name}->{'disabled'}) and $info{$name}->{'disabled'}) {
1713 warn "skipping disabled plan FS::part_pkg::$name" if $DEBUG;
1714 delete $plans{$name};
1717 my $parents = $info{$name}->{'inherit_fields'} || [];
1718 my (%fields, %field_exists, @fieldorder);
1719 foreach my $parent ($name, @$parents) {
1720 if ( !exists($info{$parent}) ) {
1721 warn "$name tried to inherit from nonexistent '$parent'\n";
1724 %fields = ( # avoid replacing existing fields
1725 %{ $info{$parent}->{'fields'} || {} },
1728 foreach (@{ $info{$parent}->{'fieldorder'} || [] }) {
1730 next if $field_exists{$_};
1731 $field_exists{$_} = 1;
1732 # allow inheritors to remove inherited fields from the fieldorder
1733 push @fieldorder, $_ if !exists($fields{$_}) or
1734 !exists($fields{$_}->{'disabled'});
1737 $plans{$name}->{'fields'} = \%fields;
1738 $plans{$name}->{'fieldorder'} = \@fieldorder;
1748 =head1 NEW PLAN CLASSES
1750 A module should be added in FS/FS/part_pkg/ Eventually, an example may be
1751 found in eg/plan_template.pm. Until then, it is suggested that you use the
1752 other modules in FS/FS/part_pkg/ as a guide.
1756 The delete method is unimplemented.
1758 setup and recur semantics are not yet defined (and are implemented in
1759 FS::cust_bill. hmm.). now they're deprecated and need to go.
1763 part_pkg_taxrate is Pg specific
1765 replace should be smarter about managing the related tables (options, pkg_svc)
1769 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
1770 schema.html from the base documentation.