add hourly frequency
[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   '';
445 }
446
447 =item pkg_svc
448
449 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
450 definition (with non-zero quantity).
451
452 =cut
453
454 sub pkg_svc {
455   my $self = shift;
456   #sort { $b->primary cmp $a->primary } 
457     grep { $_->quantity }
458       qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
459 }
460
461 =item svcpart [ SVCDB ]
462
463 Returns the svcpart of the primary service definition (see L<FS::part_svc>)
464 associated with this package definition (see L<FS::pkg_svc>).  Returns
465 false if there not a primary service definition or exactly one service
466 definition with quantity 1, or if SVCDB is specified and does not match the
467 svcdb of the service definition, 
468
469 =cut
470
471 sub svcpart {
472   my $self = shift;
473   my $svcdb = scalar(@_) ? shift : '';
474   my @svcdb_pkg_svc =
475     grep { ( $svcdb eq $_->part_svc->svcdb || !$svcdb ) } $self->pkg_svc;
476   my @pkg_svc = ();
477   @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc
478     if dbdef->table('pkg_svc')->column('primary_svc');
479   @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
480     unless @pkg_svc;
481   return '' if scalar(@pkg_svc) != 1;
482   $pkg_svc[0]->svcpart;
483 }
484
485 =item payby
486
487 Returns a list of the acceptable payment types for this package.  Eventually
488 this should come out of a database table and be editable, but currently has the
489 following logic instead:
490
491 If the package is free, the single item B<BILL> is
492 returned, otherwise, the single item B<CARD> is returned.
493
494 (CHEK?  LEC?  Probably shouldn't accept those by default, prone to abuse)
495
496 =cut
497
498 sub payby {
499   my $self = shift;
500   if ( $self->is_free ) {
501     ( 'BILL' );
502   } else {
503     ( 'CARD' );
504   }
505 }
506
507 =item is_free
508
509 Returns true if this package is free.  
510
511 =cut
512
513 sub is_free {
514   my $self = shift;
515   unless ( $self->plan ) {
516     $self->setup =~ /^\s*0+(\.0*)?\s*$/
517       && $self->recur =~ /^\s*0+(\.0*)?\s*$/;
518   } elsif ( $self->can('is_free_options') ) {
519     not grep { $_ !~ /^\s*0*(\.0*)?\s*$/ }
520          map { $self->option($_) } 
521              $self->is_free_options;
522   } else {
523     warn "FS::part_pkg::is_free: FS::part_pkg::". $self->plan. " subclass ".
524          "provides neither is_free_options nor is_free method; returning false";
525     0;
526   }
527 }
528
529 =item freq_pretty
530
531 Returns an english representation of the I<freq> field, such as "monthly",
532 "weekly", "semi-annually", etc.
533
534 =cut
535
536 tie %freq, 'Tie::IxHash', 
537   '0'  => '(no recurring fee)',
538   '1h' => 'hourly',
539   '1d' => 'daily',
540   '1w' => 'weekly',
541   '2w' => 'biweekly (every 2 weeks)',
542   '1'  => 'monthly',
543   '2'  => 'bimonthly (every 2 months)',
544   '3'  => 'quarterly (every 3 months)',
545   '6'  => 'semiannually (every 6 months)',
546   '12' => 'annually',
547   '24' => 'biannually (every 2 years)',
548   '36' => 'triannually (every 3 years)',
549   '48' => '(every 4 years)',
550   '60' => '(every 5 years)',
551   '120' => '(every 10 years)',
552 ;
553
554 sub freq_pretty {
555   my $self = shift;
556   my $freq = $self->freq;
557   if ( exists($freq{$freq}) ) {
558     $freq{$freq};
559   } else {
560     my $interval = 'month';
561     if ( $freq =~ /^(\d+)([hdw])$/ ) {
562       my %interval = ( 'h' => 'hour', 'd'=>'day', 'w'=>'week' );
563       $interval = $interval{$2};
564     }
565     if ( $1 == 1 ) {
566       "every $interval";
567     } else {
568       "every $freq ${interval}s";
569     }
570   }
571 }
572
573 =item plandata
574
575 For backwards compatibility, returns the plandata field as well as all options
576 from FS::part_pkg_option.
577
578 =cut
579
580 sub plandata {
581   my $self = shift;
582   carp "plandata is deprecated";
583   if ( @_ ) {
584     $self->SUPER::plandata(@_);
585   } else {
586     my $plandata = $self->get('plandata');
587     my %options = $self->options;
588     $plandata .= join('', map { "$_=$options{$_}\n" } keys %options );
589     $plandata;
590   }
591 }
592
593 =item part_pkg_option
594
595 Returns all options as FS::part_pkg_option objects (see
596 L<FS::part_pkg_option>).
597
598 =cut
599
600 sub part_pkg_option {
601   my $self = shift;
602   qsearch('part_pkg_option', { 'pkgpart' => $self->pkgpart } );
603 }
604
605 =item options 
606
607 Returns a list of option names and values suitable for assigning to a hash.
608
609 =cut
610
611 sub options {
612   my $self = shift;
613   map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
614 }
615
616 =item option OPTIONNAME
617
618 Returns the option value for the given name, or the empty string.
619
620 =cut
621
622 sub option {
623   my( $self, $opt, $ornull ) = @_;
624   my $part_pkg_option =
625     qsearchs('part_pkg_option', {
626       pkgpart    => $self->pkgpart,
627       optionname => $opt,
628   } );
629   return $part_pkg_option->optionvalue if $part_pkg_option;
630   my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
631                      split("\n", $self->get('plandata') );
632   return $plandata{$opt} if exists $plandata{$opt};
633   cluck "Package definition option $opt not found in options or plandata!\n"
634     unless $ornull;
635   '';
636 }
637
638 =item _rebless
639
640 Reblesses the object into the FS::part_pkg::PLAN class (if available), where
641 PLAN is the object's I<plan> field.  There should be better docs
642 on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
643
644 =cut
645
646 sub _rebless {
647   my $self = shift;
648   my $plan = $self->plan;
649   unless ( $plan ) {
650     confess "no price plan found for pkgpart ". $self->pkgpart. "\n"
651       if $DEBUG;
652     return $self;
653   }
654   return $self if ref($self) =~ /::$plan$/; #already blessed into plan subclass
655   my $class = ref($self). "::$plan";
656   warn "reblessing $self into $class" if $DEBUG;
657   eval "use $class;";
658   die $@ if $@;
659   bless($self, $class) unless $@;
660   $self;
661 }
662
663 #fallbacks that eval the setup and recur fields, for backwards compat
664
665 sub calc_setup {
666   my $self = shift;
667   warn 'no price plan class for '. $self->plan. ", eval-ing setup\n";
668   $self->_calc_eval('setup', @_);
669 }
670
671 sub calc_recur {
672   my $self = shift;
673   warn 'no price plan class for '. $self->plan. ", eval-ing recur\n";
674   $self->_calc_eval('recur', @_);
675 }
676
677 use vars qw( $sdate @details );
678 sub _calc_eval {
679   #my( $self, $field, $cust_pkg ) = @_;
680   my( $self, $field, $cust_pkg, $sdateref, $detailsref ) = @_;
681   *sdate = $sdateref;
682   *details = $detailsref;
683   $self->$field() =~ /^(.*)$/
684     or die "Illegal $field (pkgpart ". $self->pkgpart. '): '.
685             $self->$field(). "\n";
686   my $prog = $1;
687   return 0 if $prog =~ /^\s*$/;
688   my $value = eval $prog;
689   die $@ if $@;
690   $value;
691 }
692
693 #fallback that return 0 for old legacy packages with no plan
694
695 sub calc_remain { 0; }
696 sub calc_cancel { 0; }
697
698 =back
699
700 =head1 SUBROUTINES
701
702 =over 4
703
704 =item plan_info
705
706 =cut
707
708 my %info;
709 foreach my $INC ( @INC ) {
710   warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
711   foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
712     warn "attempting to load plan info from $file\n" if $DEBUG;
713     $file =~ /\/(\w+)\.pm$/ or do {
714       warn "unrecognized file in $INC/FS/part_pkg/: $file\n";
715       next;
716     };
717     my $mod = $1;
718     my $info = eval "use FS::part_pkg::$mod; ".
719                     "\\%FS::part_pkg::$mod\::info;";
720     if ( $@ ) {
721       die "error using FS::part_pkg::$mod (skipping): $@\n" if $@;
722       next;
723     }
724     unless ( keys %$info ) {
725       warn "no %info hash found in FS::part_pkg::$mod, skipping\n"
726         unless $mod =~ /^(passwdfile|null)$/; #hack but what the heck
727       next;
728     }
729     warn "got plan info from FS::part_pkg::$mod: $info\n" if $DEBUG;
730     if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
731       warn "skipping disabled plan FS::part_pkg::$mod" if $DEBUG;
732       next;
733     }
734     $info{$mod} = $info;
735   }
736 }
737
738 tie %plans, 'Tie::IxHash',
739   map { $_ => $info{$_} }
740   sort { $info{$a}->{'weight'} <=> $info{$b}->{'weight'} }
741   keys %info;
742
743 sub plan_info {
744   \%plans;
745 }
746
747 =back
748
749 =head1 NEW PLAN CLASSES
750
751 A module should be added in FS/FS/part_pkg/ (an example may be found in
752 eg/plan_template.pm)
753
754 =head1 BUGS
755
756 The delete method is unimplemented.
757
758 setup and recur semantics are not yet defined (and are implemented in
759 FS::cust_bill.  hmm.).
760
761 plandata should go
762
763 =head1 SEE ALSO
764
765 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
766 schema.html from the base documentation.
767
768 =cut
769
770 1;
771