4 use vars qw( @ISA %plans $DEBUG );
5 use Carp qw(carp cluck confess);
6 use Scalar::Util qw( blessed );
9 use FS::Record qw( qsearch qsearchs dbh dbdef );
15 use FS::part_pkg_option;
18 use FS::part_pkg_taxoverride;
19 use FS::part_pkg_taxproduct;
20 use FS::part_pkg_link;
22 @ISA = qw( FS::m2m_Common FS::option_Common );
27 FS::part_pkg - Object methods for part_pkg objects
33 $record = new FS::part_pkg \%hash
34 $record = new FS::part_pkg { 'column' => 'value' };
36 $custom_record = $template_record->clone;
38 $error = $record->insert;
40 $error = $new_record->replace($old_record);
42 $error = $record->delete;
44 $error = $record->check;
46 @pkg_svc = $record->pkg_svc;
48 $svcnum = $record->svcpart;
49 $svcnum = $record->svcpart( 'svc_acct' );
53 An FS::part_pkg object represents a package definition. FS::part_pkg
54 inherits from FS::Record. The following fields are currently supported:
58 =item pkgpart - primary key (assigned automatically for new package definitions)
60 =item pkg - Text name of this package definition (customer-viewable)
62 =item comment - Text name of this package definition (non-customer-viewable)
64 =item classnum - Optional package class (see L<FS::pkg_class>)
66 =item promo_code - Promotional code
68 =item setup - Setup fee expression (deprecated)
70 =item freq - Frequency of recurring fee
72 =item recur - Recurring fee expression (deprecated)
74 =item setuptax - Setup fee tax exempt flag, empty or `Y'
76 =item recurtax - Recurring fee tax exempt flag, empty or `Y'
78 =item taxclass - Tax class
80 =item plan - Price plan
82 =item plandata - Price plan data (deprecated - see L<FS::part_pkg_option> instead)
84 =item disabled - Disabled flag, empty or `Y'
86 =item pay_weight - Weight (relative to credit_weight and other package definitions) that controls payment application to specific line items.
88 =item credit_weight - Weight (relative to other package definitions) that controls credit application to specific line items.
90 =item agentnum - Optional agentnum (see L<FS::agent>)
100 Creates a new package definition. To add the package definition to
101 the database, see L<"insert">.
105 sub table { 'part_pkg'; }
109 An alternate constructor. Creates a new package definition by duplicating
110 an existing definition. A new pkgpart is assigned and `(CUSTOM) ' is prepended
111 to the comment field. To add the package definition to the database, see
118 my $class = ref($self);
119 my %hash = $self->hash;
120 $hash{'pkgpart'} = '';
121 $hash{'comment'} = "(CUSTOM) ". $hash{'comment'}
122 unless $hash{'comment'} =~ /^\(CUSTOM\) /;
123 #new FS::part_pkg ( \%hash ); # ?
124 new $class ( \%hash ); # ?
127 =item insert [ , OPTION => VALUE ... ]
129 Adds this package definition to the database. If there is an error,
130 returns the error, otherwise returns false.
132 Currently available options are: I<pkg_svc>, I<primary_svc>, I<cust_pkg>,
133 I<custnum_ref> and I<options>.
135 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
136 values, appropriate FS::pkg_svc records will be inserted.
138 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
139 FS::pkg_svc record will be updated.
141 If I<cust_pkg> is set to a pkgnum of a FS::cust_pkg record (or the FS::cust_pkg
142 record itself), the object will be updated to point to this package definition.
144 In conjunction with I<cust_pkg>, if I<custnum_ref> is set to a scalar reference,
145 the scalar will be updated with the custnum value from the cust_pkg record.
147 If I<options> is set to a hashref of options, appropriate FS::part_pkg_option
148 records will be inserted.
155 warn "FS::part_pkg::insert called on $self with options ".
156 join(', ', map "$_=>$options{$_}", keys %options)
159 local $SIG{HUP} = 'IGNORE';
160 local $SIG{INT} = 'IGNORE';
161 local $SIG{QUIT} = 'IGNORE';
162 local $SIG{TERM} = 'IGNORE';
163 local $SIG{TSTP} = 'IGNORE';
164 local $SIG{PIPE} = 'IGNORE';
166 my $oldAutoCommit = $FS::UID::AutoCommit;
167 local $FS::UID::AutoCommit = 0;
170 warn " inserting part_pkg record" if $DEBUG;
171 my $error = $self->SUPER::insert( $options{options} );
173 $dbh->rollback if $oldAutoCommit;
177 my $conf = new FS::Conf;
178 if ( $conf->exists('agent_defaultpkg') ) {
179 warn " agent_defaultpkg set; allowing all agents to purchase package"
181 foreach my $agent_type ( qsearch('agent_type', {} ) ) {
182 my $type_pkgs = new FS::type_pkgs({
183 'typenum' => $agent_type->typenum,
184 'pkgpart' => $self->pkgpart,
186 my $error = $type_pkgs->insert;
188 $dbh->rollback if $oldAutoCommit;
194 warn " inserting pkg_svc records" if $DEBUG;
195 my $pkg_svc = $options{'pkg_svc'} || {};
196 foreach my $part_svc ( qsearch('part_svc', {} ) ) {
197 my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
199 ( $options{'primary_svc'} && $options{'primary_svc'}==$part_svc->svcpart )
203 my $pkg_svc = new FS::pkg_svc( {
204 'pkgpart' => $self->pkgpart,
205 'svcpart' => $part_svc->svcpart,
206 'quantity' => $quantity,
207 'primary_svc' => $primary_svc,
209 my $error = $pkg_svc->insert;
211 $dbh->rollback if $oldAutoCommit;
216 if ( $options{'cust_pkg'} ) {
217 warn " updating cust_pkg record " if $DEBUG;
219 ref($options{'cust_pkg'})
220 ? $options{'cust_pkg'}
221 : qsearchs('cust_pkg', { pkgnum => $options{'cust_pkg'} } );
222 ${ $options{'custnum_ref'} } = $old_cust_pkg->custnum
223 if $options{'custnum_ref'};
224 my %hash = $old_cust_pkg->hash;
225 $hash{'pkgpart'} = $self->pkgpart,
226 my $new_cust_pkg = new FS::cust_pkg \%hash;
227 local($FS::cust_pkg::disable_agentcheck) = 1;
228 my $error = $new_cust_pkg->replace($old_cust_pkg);
230 $dbh->rollback if $oldAutoCommit;
231 return "Error modifying cust_pkg record: $error";
235 warn " commiting transaction" if $DEBUG;
236 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
243 Currently unimplemented.
248 return "Can't (yet?) delete package definitions.";
249 # check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
252 =item replace OLD_RECORD [ , OPTION => VALUE ... ]
254 Replaces OLD_RECORD with this one in the database. If there is an error,
255 returns the error, otherwise returns false.
257 Currently available options are: I<pkg_svc> and I<primary_svc>
259 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
260 values, the appropriate FS::pkg_svc records will be replace.
262 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
263 FS::pkg_svc record will be updated.
270 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
275 ( ref($_[0]) eq 'HASH' )
279 warn "FS::part_pkg::replace called on $new to replace $old with options".
280 join(', ', map "$_ => ". $options->{$_}, keys %$options)
283 local $SIG{HUP} = 'IGNORE';
284 local $SIG{INT} = 'IGNORE';
285 local $SIG{QUIT} = 'IGNORE';
286 local $SIG{TERM} = 'IGNORE';
287 local $SIG{TSTP} = 'IGNORE';
288 local $SIG{PIPE} = 'IGNORE';
290 my $oldAutoCommit = $FS::UID::AutoCommit;
291 local $FS::UID::AutoCommit = 0;
294 #plandata shit stays in replace for upgrades until after 2.0 (or edit
296 warn " saving legacy plandata" if $DEBUG;
297 my $plandata = $new->get('plandata');
298 $new->set('plandata', '');
300 warn " deleting old part_pkg_option records" if $DEBUG;
301 foreach my $part_pkg_option ( $old->part_pkg_option ) {
302 my $error = $part_pkg_option->delete;
304 $dbh->rollback if $oldAutoCommit;
309 warn " replacing part_pkg record" if $DEBUG;
310 my $error = $new->SUPER::replace($old, $options->{options} );
312 $dbh->rollback if $oldAutoCommit;
316 warn " inserting part_pkg_option records for plandata: $plandata|" if $DEBUG;
317 foreach my $part_pkg_option (
318 map { /^(\w+)=(.*)$/ or do { $dbh->rollback if $oldAutoCommit;
319 return "illegal plandata: $plandata";
321 new FS::part_pkg_option {
322 'pkgpart' => $new->pkgpart,
327 split("\n", $plandata)
329 my $error = $part_pkg_option->insert;
331 $dbh->rollback if $oldAutoCommit;
336 warn " replacing pkg_svc records" if $DEBUG;
337 my $pkg_svc = $options->{'pkg_svc'} || {};
338 foreach my $part_svc ( qsearch('part_svc', {} ) ) {
339 my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
340 my $primary_svc = $options->{'primary_svc'} == $part_svc->svcpart ? 'Y' : '';
342 my $old_pkg_svc = qsearchs('pkg_svc', {
343 'pkgpart' => $old->pkgpart,
344 'svcpart' => $part_svc->svcpart,
346 my $old_quantity = $old_pkg_svc ? $old_pkg_svc->quantity : 0;
347 my $old_primary_svc =
348 ( $old_pkg_svc && $old_pkg_svc->dbdef_table->column('primary_svc') )
349 ? $old_pkg_svc->primary_svc
351 next unless $old_quantity != $quantity || $old_primary_svc ne $primary_svc;
353 my $new_pkg_svc = new FS::pkg_svc( {
354 'pkgsvcnum' => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
355 'pkgpart' => $new->pkgpart,
356 'svcpart' => $part_svc->svcpart,
357 'quantity' => $quantity,
358 'primary_svc' => $primary_svc,
360 my $error = $old_pkg_svc
361 ? $new_pkg_svc->replace($old_pkg_svc)
362 : $new_pkg_svc->insert;
364 $dbh->rollback if $oldAutoCommit;
369 warn " commiting transaction" if $DEBUG;
370 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
376 Checks all fields to make sure this is a valid package definition. If
377 there is an error, returns the error, otherwise returns false. Called by the
378 insert and replace methods.
384 warn "FS::part_pkg::check called on $self" if $DEBUG;
386 for (qw(setup recur plandata)) {
387 #$self->set($_=>0) if $self->get($_) =~ /^\s*$/; }
388 return "Use of $_ field is deprecated; set a plan and options: ".
390 if length($self->get($_));
394 if ( $self->dbdef_table->column('freq')->type =~ /(int)/i ) {
395 my $error = $self->ut_number('freq');
396 return $error if $error;
398 $self->freq =~ /^(\d+[hdw]?)$/
399 or return "Illegal or empty freq: ". $self->freq;
403 my $error = $self->ut_numbern('pkgpart')
404 || $self->ut_text('pkg')
405 || $self->ut_text('comment')
406 || $self->ut_textn('promo_code')
407 || $self->ut_alphan('plan')
408 || $self->ut_enum('setuptax', [ '', 'Y' ] )
409 || $self->ut_enum('recurtax', [ '', 'Y' ] )
410 || $self->ut_textn('taxclass')
411 || $self->ut_enum('disabled', [ '', 'Y' ] )
412 || $self->ut_floatn('pay_weight')
413 || $self->ut_floatn('credit_weight')
414 || $self->ut_agentnum_acl('agentnum', 'Edit global package definitions')
415 || $self->SUPER::check
417 return $error if $error;
419 if ( $self->classnum !~ /^$/ ) {
420 my $error = $self->ut_foreign_key('classnum', 'pkg_class', 'classnum');
421 return $error if $error;
426 return 'Unknown plan '. $self->plan
427 unless exists($plans{$self->plan});
429 my $conf = new FS::Conf;
430 return 'Taxclass is required'
431 if ! $self->taxclass && $conf->exists('require_taxclasses');
438 Returns an (internal) string representing this package. Currently,
439 "pkgpart: pkg - comment", is returned. "pkg - comment" may be returned in the
440 future, omitting pkgpart.
447 #$self->pkg. ' - '. $self->comment;
448 #$self->pkg. ' ('. $self->comment. ')';
449 $self->pkgpart. ': '. $self->pkg. ' - '. $self->comment;
454 Returns the package class, as an FS::pkg_class object, or the empty string
455 if there is no package class.
461 if ( $self->classnum ) {
462 qsearchs('pkg_class', { 'classnum' => $self->classnum } );
470 Returns the package class name, or the empty string if there is no package
477 my $pkg_class = $self->pkg_class;
479 ? $pkg_class->classname
485 Returns the associated agent for this event, if any, as an FS::agent object.
491 qsearchs('agent', { 'agentnum' => $self->agentnum } );
494 =item pkg_svc [ HASHREF | OPTION => VALUE ]
496 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
497 definition (with non-zero quantity).
499 One option is available, I<disable_linked>. If set true it will return the
500 services for this package definition alone, omitting services from any add-on
508 # #sort { $b->primary cmp $a->primary }
509 # grep { $_->quantity }
510 # qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
512 my $opt = ref($_[0]) ? $_[0] : { @_ };
513 my %pkg_svc = map { $_->svcpart => $_ }
514 grep { $_->quantity }
515 qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
517 unless ( $opt->{disable_linked} ) {
518 foreach my $dst_pkg ( map $_->dst_pkg, $self->svc_part_pkg_link ) {
519 my @pkg_svc = grep { $_->quantity }
520 qsearch( 'pkg_svc', { pkgpart=>$dst_pkg->pkgpart } );
521 foreach my $pkg_svc ( @pkg_svc ) {
522 if ( $pkg_svc{$pkg_svc->svcpart} ) {
523 my $quantity = $pkg_svc{$pkg_svc->svcpart}->quantity;
524 $pkg_svc{$pkg_svc->svcpart}->quantity($quantity + $pkg_svc->quantity);
526 $pkg_svc{$pkg_svc->svcpart} = $pkg_svc;
536 =item svcpart [ SVCDB ]
538 Returns the svcpart of the primary service definition (see L<FS::part_svc>)
539 associated with this package definition (see L<FS::pkg_svc>). Returns
540 false if there not a primary service definition or exactly one service
541 definition with quantity 1, or if SVCDB is specified and does not match the
542 svcdb of the service definition,
548 my $svcdb = scalar(@_) ? shift : '';
550 grep { ( $svcdb eq $_->part_svc->svcdb || !$svcdb ) } $self->pkg_svc;
552 @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc
553 if dbdef->table('pkg_svc')->column('primary_svc');
554 @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
556 return '' if scalar(@pkg_svc) != 1;
557 $pkg_svc[0]->svcpart;
562 Returns a list of the acceptable payment types for this package. Eventually
563 this should come out of a database table and be editable, but currently has the
564 following logic instead:
566 If the package is free, the single item B<BILL> is
567 returned, otherwise, the single item B<CARD> is returned.
569 (CHEK? LEC? Probably shouldn't accept those by default, prone to abuse)
575 if ( $self->is_free ) {
584 Returns true if this package is free.
590 unless ( $self->plan ) {
591 $self->setup =~ /^\s*0+(\.0*)?\s*$/
592 && $self->recur =~ /^\s*0+(\.0*)?\s*$/;
593 } elsif ( $self->can('is_free_options') ) {
594 not grep { $_ !~ /^\s*0*(\.0*)?\s*$/ }
595 map { $self->option($_) }
596 $self->is_free_options;
598 warn "FS::part_pkg::is_free: FS::part_pkg::". $self->plan. " subclass ".
599 "provides neither is_free_options nor is_free method; returning false";
606 #method, class method or sub? #my $self = shift;
608 tie my %freq, 'Tie::IxHash',
609 '0' => '(no recurring fee)',
612 '2d' => 'every two days',
613 '3d' => 'every three days',
615 '2w' => 'biweekly (every 2 weeks)',
617 '45d' => 'every 45 days',
618 '2' => 'bimonthly (every 2 months)',
619 '3' => 'quarterly (every 3 months)',
620 '4' => 'every 4 months',
621 '137d' => 'every 4 1/2 months (137 days)',
622 '6' => 'semiannually (every 6 months)',
624 '13' => 'every 13 months (annually +1 month)',
625 '24' => 'biannually (every 2 years)',
626 '36' => 'triannually (every 3 years)',
627 '48' => '(every 4 years)',
628 '60' => '(every 5 years)',
629 '120' => '(every 10 years)',
638 Returns an english representation of the I<freq> field, such as "monthly",
639 "weekly", "semi-annually", etc.
645 my $freq = $self->freq;
647 #my $freqs_href = $self->freqs_href;
648 my $freqs_href = freqs_href();
650 if ( exists($freqs_href->{$freq}) ) {
651 $freqs_href->{$freq};
653 my $interval = 'month';
654 if ( $freq =~ /^(\d+)([hdw])$/ ) {
655 my %interval = ( 'h' => 'hour', 'd'=>'day', 'w'=>'week' );
656 $interval = $interval{$2};
661 "every $freq ${interval}s";
668 For backwards compatibility, returns the plandata field as well as all options
669 from FS::part_pkg_option.
675 carp "plandata is deprecated";
677 $self->SUPER::plandata(@_);
679 my $plandata = $self->get('plandata');
680 my %options = $self->options;
681 $plandata .= join('', map { "$_=$options{$_}\n" } keys %options );
686 =item part_pkg_option
688 Returns all options as FS::part_pkg_option objects (see
689 L<FS::part_pkg_option>).
693 sub part_pkg_option {
695 qsearch('part_pkg_option', { 'pkgpart' => $self->pkgpart } );
700 Returns a list of option names and values suitable for assigning to a hash.
706 map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
709 =item option OPTIONNAME
711 Returns the option value for the given name, or the empty string.
716 my( $self, $opt, $ornull ) = @_;
717 my $part_pkg_option =
718 qsearchs('part_pkg_option', {
719 pkgpart => $self->pkgpart,
722 return $part_pkg_option->optionvalue if $part_pkg_option;
723 my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
724 split("\n", $self->get('plandata') );
725 return $plandata{$opt} if exists $plandata{$opt};
726 cluck "WARNING: (pkgpart ". $self->pkgpart. ") Package def option $opt ".
727 "not found in options or plandata!\n"
732 =item bill_part_pkg_link
734 Returns the associated part_pkg_link records (see L<FS::part_pkg_link).
738 sub bill_part_pkg_link {
739 shift->_part_pkg_link('bill', @_);
742 =item svc_part_pkg_link
746 sub svc_part_pkg_link {
747 shift->_part_pkg_link('svc', @_);
751 my( $self, $type ) = @_;
752 qsearch('part_pkg_link', { 'src_pkgpart' => $self->pkgpart,
753 'link_type' => $type,
758 sub self_and_bill_linked {
759 shift->_self_and_linked('bill', @_);
762 sub _self_and_linked {
763 my( $self, $type ) = @_;
766 map { $_->dst_pkg->_self_and_linked($type) }
767 $self->_part_pkg_link($type)
771 =item part_pkg_taxoverride
773 Returns all associated FS::part_pkg_taxoverride objects (see
774 L<FS::part_pkg_taxoverride>).
778 sub part_pkg_taxoverride {
780 qsearch('part_pkg_taxoverride', { 'pkgpart' => $self->pkgpart } );
783 =item taxproduct_description
785 Returns the description of the associated tax product for this package
786 definition (see L<FS::part_pkg_taxproduct>).
790 sub taxproduct_description {
792 my $part_pkg_taxproduct =
793 qsearchs( 'part_pkg_taxproduct',
794 { 'taxproductnum' => $self->taxproductnum }
796 $part_pkg_taxproduct ? $part_pkg_taxproduct->description : '';
799 =item part_pkg_taxrate DATA_PROVIDER, GEOCODE
801 Returns the package to taxrate m2m records for this package in the location
802 specified by GEOCODE (see L<FS::part_pkg_taxrate> and ).
806 sub part_pkg_taxrate {
808 my ($data_vendor, $geocode) = @_;
812 my $extra_sql = 'AND ('.
813 join(' OR ', map{ 'geocode = '. $dbh->quote(substr($geocode, 0, $_)) }
817 my $order_by = 'ORDER BY taxclassnum, length(geocode) desc';
818 my $select = 'DISTINCT ON(taxclassnum) *';
820 qsearch( { 'table' => 'part_pkg_taxrate',
821 'select' => 'distinct on(taxclassnum) *',
822 'hashref' => { 'data_vendor' => $data_vendor,
823 'taxproductnum' => $self->taxproductnum,
825 'extra_sql' => $extra_sql,
826 'order_by' => $order_by,
832 Reblesses the object into the FS::part_pkg::PLAN class (if available), where
833 PLAN is the object's I<plan> field. There should be better docs
834 on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
840 my $plan = $self->plan;
842 cluck "no price plan found for pkgpart ". $self->pkgpart. "\n"
846 return $self if ref($self) =~ /::$plan$/; #already blessed into plan subclass
847 my $class = ref($self). "::$plan";
848 warn "reblessing $self into $class" if $DEBUG;
851 bless($self, $class) unless $@;
855 #fallbacks that eval the setup and recur fields, for backwards compat
859 warn 'no price plan class for '. $self->plan. ", eval-ing setup\n";
860 $self->_calc_eval('setup', @_);
865 warn 'no price plan class for '. $self->plan. ", eval-ing recur\n";
866 $self->_calc_eval('recur', @_);
869 use vars qw( $sdate @details );
871 #my( $self, $field, $cust_pkg ) = @_;
872 my( $self, $field, $cust_pkg, $sdateref, $detailsref ) = @_;
874 *details = $detailsref;
875 $self->$field() =~ /^(.*)$/
876 or die "Illegal $field (pkgpart ". $self->pkgpart. '): '.
877 $self->$field(). "\n";
879 return 0 if $prog =~ /^\s*$/;
880 my $value = eval $prog;
885 #fallback that return 0 for old legacy packages with no plan
887 sub calc_remain { 0; }
888 sub calc_cancel { 0; }
896 # Used by FS::Upgrade to migrate to a new database.
898 sub _upgrade_data { # class method
899 my($class, %opts) = @_;
901 warn "[FS::part_pkg] upgrading $class\n" if $DEBUG;
903 my @part_pkg = qsearch({
904 'table' => 'part_pkg',
905 'extra_sql' => "WHERE ". join(' OR ',
906 ( map "($_ IS NOT NULL AND $_ != '' )",
907 qw( plandata setup recur ) ),
908 'plan IS NULL', "plan = '' ",
912 foreach my $part_pkg (@part_pkg) {
914 unless ( $part_pkg->plan ) {
916 $part_pkg->plan('flat');
918 if ( $part_pkg->setup =~ /^\s*([\d\.]+)\s*$/ ) {
920 my $opt = new FS::part_pkg_option {
921 'pkgpart' => $part_pkg->pkgpart,
922 'optionname' => 'setup_fee',
925 my $error = $opt->insert;
926 die $error if $error;
928 $part_pkg->setup('');
931 die "Can't parse part_pkg.setup for fee; convert pkgnum ".
932 $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
935 if ( $part_pkg->recur =~ /^\s*([\d\.]+)\s*$/ ) {
937 my $opt = new FS::part_pkg_option {
938 'pkgpart' => $part_pkg->pkgpart,
939 'optionname' => 'recur_fee',
942 my $error = $opt->insert;
943 die $error if $error;
945 $part_pkg->recur('');
948 die "Can't parse part_pkg.setup for fee; convert pkgnum ".
949 $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
954 $part_pkg->replace; #this should take care of plandata, right?
969 foreach my $INC ( @INC ) {
970 warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
971 foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
972 warn "attempting to load plan info from $file\n" if $DEBUG;
973 $file =~ /\/(\w+)\.pm$/ or do {
974 warn "unrecognized file in $INC/FS/part_pkg/: $file\n";
978 my $info = eval "use FS::part_pkg::$mod; ".
979 "\\%FS::part_pkg::$mod\::info;";
981 die "error using FS::part_pkg::$mod (skipping): $@\n" if $@;
984 unless ( keys %$info ) {
985 warn "no %info hash found in FS::part_pkg::$mod, skipping\n"
986 unless $mod =~ /^(passwdfile|null)$/; #hack but what the heck
989 warn "got plan info from FS::part_pkg::$mod: $info\n" if $DEBUG;
990 if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
991 warn "skipping disabled plan FS::part_pkg::$mod" if $DEBUG;
998 tie %plans, 'Tie::IxHash',
999 map { $_ => $info{$_} }
1000 sort { $info{$a}->{'weight'} <=> $info{$b}->{'weight'} }
1007 =item format OPTION DATA
1009 Returns data formatted according to the function 'format' described
1010 in the plan info. Returns DATA if no such function exists.
1015 my ($self, $option, $data) = (shift, shift, shift);
1016 if (exists($plans{$self->plan}->{fields}->{$option}{format})) {
1017 &{$plans{$self->plan}->{fields}->{$option}{format}}($data);
1023 =item parse OPTION DATA
1025 Returns data parsed according to the function 'parse' described
1026 in the plan info. Returns DATA if no such function exists.
1031 my ($self, $option, $data) = (shift, shift, shift);
1032 if (exists($plans{$self->plan}->{fields}->{$option}{parse})) {
1033 &{$plans{$self->plan}->{fields}->{$option}{parse}}($data);
1042 =head1 NEW PLAN CLASSES
1044 A module should be added in FS/FS/part_pkg/ Eventually, an example may be
1045 found in eg/plan_template.pm. Until then, it is suggested that you use the
1046 other modules in FS/FS/part_pkg/ as a guide.
1050 The delete method is unimplemented.
1052 setup and recur semantics are not yet defined (and are implemented in
1053 FS::cust_bill. hmm.). now they're deprecated and need to go.
1059 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
1060 schema.html from the base documentation.