This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / FS / FS / part_pkg.pm
1 package FS::part_pkg;
2
3 use strict;
4 use vars qw( @ISA %freq %plans $DEBUG );
5 use Carp qw(carp cluck confess);
6 use Tie::IxHash;
7 use FS::Conf;
8 use FS::Record qw( qsearch qsearchs dbh dbdef );
9 use FS::pkg_svc;
10 use FS::part_svc;
11 use FS::cust_pkg;
12 use FS::agent_type;
13 use FS::type_pkgs;
14 use FS::part_pkg_option;
15
16 @ISA = qw( FS::Record ); # FS::option_Common ); # this can use option_Common
17                                                 # when all the plandata bs is
18                                                 # gone
19
20 $DEBUG = 0;
21
22 =head1 NAME
23
24 FS::part_pkg - Object methods for part_pkg objects
25
26 =head1 SYNOPSIS
27
28   use FS::part_pkg;
29
30   $record = new FS::part_pkg \%hash
31   $record = new FS::part_pkg { 'column' => 'value' };
32
33   $custom_record = $template_record->clone;
34
35   $error = $record->insert;
36
37   $error = $new_record->replace($old_record);
38
39   $error = $record->delete;
40
41   $error = $record->check;
42
43   @pkg_svc = $record->pkg_svc;
44
45   $svcnum = $record->svcpart;
46   $svcnum = $record->svcpart( 'svc_acct' );
47
48 =head1 DESCRIPTION
49
50 An FS::part_pkg object represents a package definition.  FS::part_pkg
51 inherits from FS::Record.  The following fields are currently supported:
52
53 =over 4
54
55 =item pkgpart - primary key (assigned automatically for new package definitions)
56
57 =item pkg - Text name of this package definition (customer-viewable)
58
59 =item comment - Text name of this package definition (non-customer-viewable)
60
61 =item promo_code - Promotional code
62
63 =item setup - Setup fee expression (deprecated)
64
65 =item freq - Frequency of recurring fee
66
67 =item recur - Recurring fee expression (deprecated)
68
69 =item setuptax - Setup fee tax exempt flag, empty or `Y'
70
71 =item recurtax - Recurring fee tax exempt flag, empty or `Y'
72
73 =item taxclass - Tax class 
74
75 =item plan - Price plan
76
77 =item plandata - Price plan data (deprecated - see L<FS::part_pkg_option> instead)
78
79 =item disabled - Disabled flag, empty or `Y'
80
81 =back
82
83 =head1 METHODS
84
85 =over 4 
86
87 =item new HASHREF
88
89 Creates a new package definition.  To add the package definition to
90 the database, see L<"insert">.
91
92 =cut
93
94 sub table { 'part_pkg'; }
95
96 =item clone
97
98 An alternate constructor.  Creates a new package definition by duplicating
99 an existing definition.  A new pkgpart is assigned and `(CUSTOM) ' is prepended
100 to the comment field.  To add the package definition to the database, see
101 L<"insert">.
102
103 =cut
104
105 sub clone {
106   my $self = shift;
107   my $class = ref($self);
108   my %hash = $self->hash;
109   $hash{'pkgpart'} = '';
110   $hash{'comment'} = "(CUSTOM) ". $hash{'comment'}
111     unless $hash{'comment'} =~ /^\(CUSTOM\) /;
112   #new FS::part_pkg ( \%hash ); # ?
113   new $class ( \%hash ); # ?
114 }
115
116 =item insert [ , OPTION => VALUE ... ]
117
118 Adds this package definition to the database.  If there is an error,
119 returns the error, otherwise returns false.
120
121 Currently available options are: I<pkg_svc>, I<primary_svc>, I<cust_pkg>, 
122 I<custnum_ref> and I<options>.
123
124 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
125 values, appropriate FS::pkg_svc records will be inserted.
126
127 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
128 FS::pkg_svc record will be updated.
129
130 If I<cust_pkg> is set to a pkgnum of a FS::cust_pkg record (or the FS::cust_pkg
131 record itself), the object will be updated to point to this package definition.
132
133 In conjunction with I<cust_pkg>, if I<custnum_ref> is set to a scalar reference,
134 the scalar will be updated with the custnum value from the cust_pkg record.
135
136 If I<options> is set to a hashref of options, appropriate FS::part_pkg_option
137 records will be inserted.
138
139 =cut
140
141 sub insert {
142   my $self = shift;
143   my %options = @_;
144   warn "FS::part_pkg::insert called on $self with options ".
145        join(', ', map "$_=>$options{$_}", keys %options)
146     if $DEBUG;
147
148   local $SIG{HUP} = 'IGNORE';
149   local $SIG{INT} = 'IGNORE';
150   local $SIG{QUIT} = 'IGNORE';
151   local $SIG{TERM} = 'IGNORE';
152   local $SIG{TSTP} = 'IGNORE';
153   local $SIG{PIPE} = 'IGNORE';
154
155   my $oldAutoCommit = $FS::UID::AutoCommit;
156   local $FS::UID::AutoCommit = 0;
157   my $dbh = dbh;
158
159   warn "  saving legacy plandata" if $DEBUG;
160   my $plandata = $self->get('plandata');
161   $self->set('plandata', '');
162
163   warn "  inserting part_pkg record" if $DEBUG;
164   my $error = $self->SUPER::insert;
165   if ( $error ) {
166     $dbh->rollback if $oldAutoCommit;
167     return $error;
168   }
169
170   if ( $plandata ) {
171
172     warn "  inserting part_pkg_option records for plandata" if $DEBUG;
173     foreach my $part_pkg_option ( 
174       map { /^(\w+)=(.*)$/ or do { $dbh->rollback if $oldAutoCommit;
175                                    return "illegal plandata: $plandata";
176                                  };
177             new FS::part_pkg_option {
178               'pkgpart'     => $self->pkgpart,
179               'optionname'  => $1,
180               'optionvalue' => $2,
181             };
182           }
183       split("\n", $plandata)
184     ) {
185       my $error = $part_pkg_option->insert;
186       if ( $error ) {
187         $dbh->rollback if $oldAutoCommit;
188         return $error;
189       }
190     }
191
192   } elsif ( $options{'options'} ) {
193
194     warn "  inserting part_pkg_option records for options hashref" if $DEBUG;
195     foreach my $optionname ( keys %{$options{'options'}} ) {
196
197       my $part_pkg_option =
198         new FS::part_pkg_option {
199           'pkgpart'     => $self->pkgpart,
200           'optionname'  => $optionname,
201           'optionvalue' => $options{'options'}->{$optionname},
202         };
203
204       my $error = $part_pkg_option->insert;
205       if ( $error ) {
206         $dbh->rollback if $oldAutoCommit;
207         return $error;
208       }
209
210     }
211
212   }
213
214   my $conf = new FS::Conf;
215   if ( $conf->exists('agent_defaultpkg') ) {
216     warn "  agent_defaultpkg set; allowing all agents to purchase package"
217       if $DEBUG;
218     foreach my $agent_type ( qsearch('agent_type', {} ) ) {
219       my $type_pkgs = new FS::type_pkgs({
220         'typenum' => $agent_type->typenum,
221         'pkgpart' => $self->pkgpart,
222       });
223       my $error = $type_pkgs->insert;
224       if ( $error ) {
225         $dbh->rollback if $oldAutoCommit;
226         return $error;
227       }
228     }
229   }
230
231   warn "  inserting pkg_svc records" if $DEBUG;
232   my $pkg_svc = $options{'pkg_svc'} || {};
233   foreach my $part_svc ( qsearch('part_svc', {} ) ) {
234     my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
235     my $primary_svc =
236       ( $options{'primary_svc'} && $options{'primary_svc'}==$part_svc->svcpart )
237         ? 'Y'
238         : '';
239
240     my $pkg_svc = new FS::pkg_svc( {
241       'pkgpart'     => $self->pkgpart,
242       'svcpart'     => $part_svc->svcpart,
243       'quantity'    => $quantity, 
244       'primary_svc' => $primary_svc,
245     } );
246     my $error = $pkg_svc->insert;
247     if ( $error ) {
248       $dbh->rollback if $oldAutoCommit;
249       return $error;
250     }
251   }
252
253   if ( $options{'cust_pkg'} ) {
254     warn "  updating cust_pkg record " if $DEBUG;
255     my $old_cust_pkg =
256       ref($options{'cust_pkg'})
257         ? $options{'cust_pkg'}
258         : qsearchs('cust_pkg', { pkgnum => $options{'cust_pkg'} } );
259     ${ $options{'custnum_ref'} } = $old_cust_pkg->custnum
260       if $options{'custnum_ref'};
261     my %hash = $old_cust_pkg->hash;
262     $hash{'pkgpart'} = $self->pkgpart,
263     my $new_cust_pkg = new FS::cust_pkg \%hash;
264     local($FS::cust_pkg::disable_agentcheck) = 1;
265     my $error = $new_cust_pkg->replace($old_cust_pkg);
266     if ( $error ) {
267       $dbh->rollback if $oldAutoCommit;
268       return "Error modifying cust_pkg record: $error";
269     }
270   }
271
272   warn "  commiting transaction" if $DEBUG;
273   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
274
275   '';
276 }
277
278 =item delete
279
280 Currently unimplemented.
281
282 =cut
283
284 sub delete {
285   return "Can't (yet?) delete package definitions.";
286 # check & make sure the pkgpart isn't in cust_pkg or type_pkgs?
287 }
288
289 =item replace OLD_RECORD [ , OPTION => VALUE ... ]
290
291 Replaces OLD_RECORD with this one in the database.  If there is an error,
292 returns the error, otherwise returns false.
293
294 Currently available options are: I<pkg_svc> and I<primary_svc>
295
296 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
297 values, the appropriate FS::pkg_svc records will be replace.
298
299 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
300 FS::pkg_svc record will be updated.
301
302 =cut
303
304 sub replace {
305   my( $new, $old ) = ( shift, shift );
306   my %options = @_;
307   warn "FS::part_pkg::replace called on $new to replace $old ".
308        "with options %options"
309     if $DEBUG;
310
311   local $SIG{HUP} = 'IGNORE';
312   local $SIG{INT} = 'IGNORE';
313   local $SIG{QUIT} = 'IGNORE';
314   local $SIG{TERM} = 'IGNORE';
315   local $SIG{TSTP} = 'IGNORE';
316   local $SIG{PIPE} = 'IGNORE';
317
318   my $oldAutoCommit = $FS::UID::AutoCommit;
319   local $FS::UID::AutoCommit = 0;
320   my $dbh = dbh;
321
322   warn "  saving legacy plandata" if $DEBUG;
323   my $plandata = $new->get('plandata');
324   $new->set('plandata', '');
325
326   warn "  deleting old part_pkg_option records" if $DEBUG;
327   foreach my $part_pkg_option ( $old->part_pkg_option ) {
328     my $error = $part_pkg_option->delete;
329     if ( $error ) {
330       $dbh->rollback if $oldAutoCommit;
331       return $error;
332     }
333   }
334
335   warn "  replacing part_pkg record" if $DEBUG;
336   my $error = $new->SUPER::replace($old);
337   if ( $error ) {
338     $dbh->rollback if $oldAutoCommit;
339     return $error;
340   }
341
342   warn "  inserting part_pkg_option records for plandata" if $DEBUG;
343   foreach my $part_pkg_option ( 
344     map { /^(\w+)=(.*)$/ or do { $dbh->rollback if $oldAutoCommit;
345                                  return "illegal plandata: $plandata";
346                                };
347           new FS::part_pkg_option {
348             'pkgpart'     => $new->pkgpart,
349             'optionname'  => $1,
350             'optionvalue' => $2,
351           };
352         }
353     split("\n", $plandata)
354   ) {
355     my $error = $part_pkg_option->insert;
356     if ( $error ) {
357       $dbh->rollback if $oldAutoCommit;
358       return $error;
359     }
360   }
361
362   warn "  replacing pkg_svc records" if $DEBUG;
363   my $pkg_svc = $options{'pkg_svc'} || {};
364   foreach my $part_svc ( qsearch('part_svc', {} ) ) {
365     my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
366     my $primary_svc = $options{'primary_svc'} == $part_svc->svcpart ? 'Y' : '';
367
368     my $old_pkg_svc = qsearchs('pkg_svc', {
369       'pkgpart' => $old->pkgpart,
370       'svcpart' => $part_svc->svcpart,
371     } );
372     my $old_quantity = $old_pkg_svc ? $old_pkg_svc->quantity : 0;
373     my $old_primary_svc =
374       ( $old_pkg_svc && $old_pkg_svc->dbdef_table->column('primary_svc') )
375         ? $old_pkg_svc->primary_svc
376         : '';
377     next unless $old_quantity != $quantity || $old_primary_svc ne $primary_svc;
378   
379     my $new_pkg_svc = new FS::pkg_svc( {
380       'pkgsvcnum'   => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
381       'pkgpart'     => $new->pkgpart,
382       'svcpart'     => $part_svc->svcpart,
383       'quantity'    => $quantity, 
384       'primary_svc' => $primary_svc,
385     } );
386     my $error = $old_pkg_svc
387                   ? $new_pkg_svc->replace($old_pkg_svc)
388                   : $new_pkg_svc->insert;
389     if ( $error ) {
390       $dbh->rollback if $oldAutoCommit;
391       return $error;
392     }
393   }
394
395   warn "  commiting transaction" if $DEBUG;
396   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
397   '';
398 }
399
400 =item check
401
402 Checks all fields to make sure this is a valid package definition.  If
403 there is an error, returns the error, otherwise returns false.  Called by the
404 insert and replace methods.
405
406 =cut
407
408 sub check {
409   my $self = shift;
410   warn "FS::part_pkg::check called on $self" if $DEBUG;
411
412   for (qw(setup recur plandata)) {
413     #$self->set($_=>0) if $self->get($_) =~ /^\s*$/; }
414     return "Use of $_ field is deprecated; set a plan and options"
415       if length($self->get($_));
416     $self->set($_, '');
417   }
418
419   if ( $self->dbdef_table->column('freq')->type =~ /(int)/i ) {
420     my $error = $self->ut_number('freq');
421     return $error if $error;
422   } else {
423     $self->freq =~ /^(\d+[hdw]?)$/
424       or return "Illegal or empty freq: ". $self->freq;
425     $self->freq($1);
426   }
427
428   my $error = $self->ut_numbern('pkgpart')
429     || $self->ut_text('pkg')
430     || $self->ut_text('comment')
431     || $self->ut_textn('promo_code')
432     || $self->ut_alphan('plan')
433     || $self->ut_enum('setuptax', [ '', 'Y' ] )
434     || $self->ut_enum('recurtax', [ '', 'Y' ] )
435     || $self->ut_textn('taxclass')
436     || $self->ut_enum('disabled', [ '', 'Y' ] )
437     || $self->SUPER::check
438   ;
439   return $error if $error;
440
441   return 'Unknown plan '. $self->plan
442     unless exists($plans{$self->plan});
443
444   my $conf = new FS::Conf;
445   return 'Taxclass is required'
446     if ! $self->taxclass && $conf->exists('require_taxclasses');
447
448   '';
449 }
450
451 =item pkg_svc
452
453 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
454 definition (with non-zero quantity).
455
456 =cut
457
458 sub pkg_svc {
459   my $self = shift;
460   #sort { $b->primary cmp $a->primary } 
461     grep { $_->quantity }
462       qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
463 }
464
465 =item svcpart [ SVCDB ]
466
467 Returns the svcpart of the primary service definition (see L<FS::part_svc>)
468 associated with this package definition (see L<FS::pkg_svc>).  Returns
469 false if there not a primary service definition or exactly one service
470 definition with quantity 1, or if SVCDB is specified and does not match the
471 svcdb of the service definition, 
472
473 =cut
474
475 sub svcpart {
476   my $self = shift;
477   my $svcdb = scalar(@_) ? shift : '';
478   my @svcdb_pkg_svc =
479     grep { ( $svcdb eq $_->part_svc->svcdb || !$svcdb ) } $self->pkg_svc;
480   my @pkg_svc = ();
481   @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc
482     if dbdef->table('pkg_svc')->column('primary_svc');
483   @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
484     unless @pkg_svc;
485   return '' if scalar(@pkg_svc) != 1;
486   $pkg_svc[0]->svcpart;
487 }
488
489 =item payby
490
491 Returns a list of the acceptable payment types for this package.  Eventually
492 this should come out of a database table and be editable, but currently has the
493 following logic instead:
494
495 If the package is free, the single item B<BILL> is
496 returned, otherwise, the single item B<CARD> is returned.
497
498 (CHEK?  LEC?  Probably shouldn't accept those by default, prone to abuse)
499
500 =cut
501
502 sub payby {
503   my $self = shift;
504   if ( $self->is_free ) {
505     ( 'BILL' );
506   } else {
507     ( 'CARD' );
508   }
509 }
510
511 =item is_free
512
513 Returns true if this package is free.  
514
515 =cut
516
517 sub is_free {
518   my $self = shift;
519   unless ( $self->plan ) {
520     $self->setup =~ /^\s*0+(\.0*)?\s*$/
521       && $self->recur =~ /^\s*0+(\.0*)?\s*$/;
522   } elsif ( $self->can('is_free_options') ) {
523     not grep { $_ !~ /^\s*0*(\.0*)?\s*$/ }
524          map { $self->option($_) } 
525              $self->is_free_options;
526   } else {
527     warn "FS::part_pkg::is_free: FS::part_pkg::". $self->plan. " subclass ".
528          "provides neither is_free_options nor is_free method; returning false";
529     0;
530   }
531 }
532
533 =item freq_pretty
534
535 Returns an english representation of the I<freq> field, such as "monthly",
536 "weekly", "semi-annually", etc.
537
538 =cut
539
540 tie %freq, 'Tie::IxHash', 
541   '0'  => '(no recurring fee)',
542   '1h' => 'hourly',
543   '1d' => 'daily',
544   '1w' => 'weekly',
545   '2w' => 'biweekly (every 2 weeks)',
546   '1'  => 'monthly',
547   '2'  => 'bimonthly (every 2 months)',
548   '3'  => 'quarterly (every 3 months)',
549   '6'  => 'semiannually (every 6 months)',
550   '12' => 'annually',
551   '24' => 'biannually (every 2 years)',
552   '36' => 'triannually (every 3 years)',
553   '48' => '(every 4 years)',
554   '60' => '(every 5 years)',
555   '120' => '(every 10 years)',
556 ;
557
558 sub freq_pretty {
559   my $self = shift;
560   my $freq = $self->freq;
561   if ( exists($freq{$freq}) ) {
562     $freq{$freq};
563   } else {
564     my $interval = 'month';
565     if ( $freq =~ /^(\d+)([hdw])$/ ) {
566       my %interval = ( 'h' => 'hour', 'd'=>'day', 'w'=>'week' );
567       $interval = $interval{$2};
568     }
569     if ( $1 == 1 ) {
570       "every $interval";
571     } else {
572       "every $freq ${interval}s";
573     }
574   }
575 }
576
577 =item plandata
578
579 For backwards compatibility, returns the plandata field as well as all options
580 from FS::part_pkg_option.
581
582 =cut
583
584 sub plandata {
585   my $self = shift;
586   carp "plandata is deprecated";
587   if ( @_ ) {
588     $self->SUPER::plandata(@_);
589   } else {
590     my $plandata = $self->get('plandata');
591     my %options = $self->options;
592     $plandata .= join('', map { "$_=$options{$_}\n" } keys %options );
593     $plandata;
594   }
595 }
596
597 =item part_pkg_option
598
599 Returns all options as FS::part_pkg_option objects (see
600 L<FS::part_pkg_option>).
601
602 =cut
603
604 sub part_pkg_option {
605   my $self = shift;
606   qsearch('part_pkg_option', { 'pkgpart' => $self->pkgpart } );
607 }
608
609 =item options 
610
611 Returns a list of option names and values suitable for assigning to a hash.
612
613 =cut
614
615 sub options {
616   my $self = shift;
617   map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
618 }
619
620 =item option OPTIONNAME
621
622 Returns the option value for the given name, or the empty string.
623
624 =cut
625
626 sub option {
627   my( $self, $opt, $ornull ) = @_;
628   my $part_pkg_option =
629     qsearchs('part_pkg_option', {
630       pkgpart    => $self->pkgpart,
631       optionname => $opt,
632   } );
633   return $part_pkg_option->optionvalue if $part_pkg_option;
634   my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
635                      split("\n", $self->get('plandata') );
636   return $plandata{$opt} if exists $plandata{$opt};
637   cluck "Package definition option $opt not found in options or plandata!\n"
638     unless $ornull;
639   '';
640 }
641
642 =item _rebless
643
644 Reblesses the object into the FS::part_pkg::PLAN class (if available), where
645 PLAN is the object's I<plan> field.  There should be better docs
646 on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
647
648 =cut
649
650 sub _rebless {
651   my $self = shift;
652   my $plan = $self->plan;
653   unless ( $plan ) {
654     confess "no price plan found for pkgpart ". $self->pkgpart. "\n"
655       if $DEBUG;
656     return $self;
657   }
658   return $self if ref($self) =~ /::$plan$/; #already blessed into plan subclass
659   my $class = ref($self). "::$plan";
660   warn "reblessing $self into $class" if $DEBUG;
661   eval "use $class;";
662   die $@ if $@;
663   bless($self, $class) unless $@;
664   $self;
665 }
666
667 #fallbacks that eval the setup and recur fields, for backwards compat
668
669 sub calc_setup {
670   my $self = shift;
671   warn 'no price plan class for '. $self->plan. ", eval-ing setup\n";
672   $self->_calc_eval('setup', @_);
673 }
674
675 sub calc_recur {
676   my $self = shift;
677   warn 'no price plan class for '. $self->plan. ", eval-ing recur\n";
678   $self->_calc_eval('recur', @_);
679 }
680
681 use vars qw( $sdate @details );
682 sub _calc_eval {
683   #my( $self, $field, $cust_pkg ) = @_;
684   my( $self, $field, $cust_pkg, $sdateref, $detailsref ) = @_;
685   *sdate = $sdateref;
686   *details = $detailsref;
687   $self->$field() =~ /^(.*)$/
688     or die "Illegal $field (pkgpart ". $self->pkgpart. '): '.
689             $self->$field(). "\n";
690   my $prog = $1;
691   return 0 if $prog =~ /^\s*$/;
692   my $value = eval $prog;
693   die $@ if $@;
694   $value;
695 }
696
697 #fallback that return 0 for old legacy packages with no plan
698
699 sub calc_remain { 0; }
700 sub calc_cancel { 0; }
701
702 =back
703
704 =head1 SUBROUTINES
705
706 =over 4
707
708 =item plan_info
709
710 =cut
711
712 my %info;
713 foreach my $INC ( @INC ) {
714   warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
715   foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
716     warn "attempting to load plan info from $file\n" if $DEBUG;
717     $file =~ /\/(\w+)\.pm$/ or do {
718       warn "unrecognized file in $INC/FS/part_pkg/: $file\n";
719       next;
720     };
721     my $mod = $1;
722     my $info = eval "use FS::part_pkg::$mod; ".
723                     "\\%FS::part_pkg::$mod\::info;";
724     if ( $@ ) {
725       die "error using FS::part_pkg::$mod (skipping): $@\n" if $@;
726       next;
727     }
728     unless ( keys %$info ) {
729       warn "no %info hash found in FS::part_pkg::$mod, skipping\n"
730         unless $mod =~ /^(passwdfile|null)$/; #hack but what the heck
731       next;
732     }
733     warn "got plan info from FS::part_pkg::$mod: $info\n" if $DEBUG;
734     if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
735       warn "skipping disabled plan FS::part_pkg::$mod" if $DEBUG;
736       next;
737     }
738     $info{$mod} = $info;
739   }
740 }
741
742 tie %plans, 'Tie::IxHash',
743   map { $_ => $info{$_} }
744   sort { $info{$a}->{'weight'} <=> $info{$b}->{'weight'} }
745   keys %info;
746
747 sub plan_info {
748   \%plans;
749 }
750
751 =back
752
753 =head1 NEW PLAN CLASSES
754
755 A module should be added in FS/FS/part_pkg/ (an example may be found in
756 eg/plan_template.pm)
757
758 =head1 BUGS
759
760 The delete method is unimplemented.
761
762 setup and recur semantics are not yet defined (and are implemented in
763 FS::cust_bill.  hmm.).
764
765 plandata should go
766
767 =head1 SEE ALSO
768
769 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
770 schema.html from the base documentation.
771
772 =cut
773
774 1;
775