95bc56a1349dbfbdc869f2cfd5239962292e8132
[freeside.git] / FS / FS / part_pkg.pm
1 package FS::part_pkg;
2
3 use strict;
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 );
8 use Tie::IxHash;
9 use FS::Conf;
10 use FS::Record qw( qsearch qsearchs dbh dbdef );
11 use FS::pkg_svc;
12 use FS::part_svc;
13 use FS::cust_pkg;
14 use FS::agent_type;
15 use FS::type_pkgs;
16 use FS::part_pkg_option;
17 use FS::pkg_class;
18 use FS::agent;
19 use FS::part_pkg_taxoverride;
20 use FS::part_pkg_taxproduct;
21 use FS::part_pkg_link;
22
23 @ISA = qw( FS::m2m_Common FS::option_Common );
24 $DEBUG = 0;
25 $setup_hack = 0;
26 $skip_pkg_svc_hack = 0;
27
28 =head1 NAME
29
30 FS::part_pkg - Object methods for part_pkg objects
31
32 =head1 SYNOPSIS
33
34   use FS::part_pkg;
35
36   $record = new FS::part_pkg \%hash
37   $record = new FS::part_pkg { 'column' => 'value' };
38
39   $custom_record = $template_record->clone;
40
41   $error = $record->insert;
42
43   $error = $new_record->replace($old_record);
44
45   $error = $record->delete;
46
47   $error = $record->check;
48
49   @pkg_svc = $record->pkg_svc;
50
51   $svcnum = $record->svcpart;
52   $svcnum = $record->svcpart( 'svc_acct' );
53
54 =head1 DESCRIPTION
55
56 An FS::part_pkg object represents a package definition.  FS::part_pkg
57 inherits from FS::Record.  The following fields are currently supported:
58
59 =over 4
60
61 =item pkgpart - primary key (assigned automatically for new package definitions)
62
63 =item pkg - Text name of this package definition (customer-viewable)
64
65 =item comment - Text name of this package definition (non-customer-viewable)
66
67 =item classnum - Optional package class (see L<FS::pkg_class>)
68
69 =item promo_code - Promotional code
70
71 =item setup - Setup fee expression (deprecated)
72
73 =item freq - Frequency of recurring fee
74
75 =item recur - Recurring fee expression (deprecated)
76
77 =item setuptax - Setup fee tax exempt flag, empty or `Y'
78
79 =item recurtax - Recurring fee tax exempt flag, empty or `Y'
80
81 =item taxclass - Tax class 
82
83 =item plan - Price plan
84
85 =item plandata - Price plan data (deprecated - see L<FS::part_pkg_option> instead)
86
87 =item disabled - Disabled flag, empty or `Y'
88
89 =item custom - Custom flag, empty or `Y'
90
91 =item setup_cost - for cost tracking
92
93 =item recur_cost - for cost tracking
94
95 =item pay_weight - Weight (relative to credit_weight and other package definitions) that controls payment application to specific line items.
96
97 =item credit_weight - Weight (relative to other package definitions) that controls credit application to specific line items.
98
99 =item agentnum - Optional agentnum (see L<FS::agent>)
100
101 =item fcc_ds0s - Optional DS0 equivalency number for FCC form 477
102
103 =back
104
105 =head1 METHODS
106
107 =over 4 
108
109 =item new HASHREF
110
111 Creates a new package definition.  To add the package definition to
112 the database, see L<"insert">.
113
114 =cut
115
116 sub table { 'part_pkg'; }
117
118 =item clone
119
120 An alternate constructor.  Creates a new package definition by duplicating
121 an existing definition.  A new pkgpart is assigned and the custom flag is
122 set to Y.  To add the package definition to the database, see L<"insert">.
123
124 =cut
125
126 sub clone {
127   my $self = shift;
128   my $class = ref($self);
129   my %hash = $self->hash;
130   $hash{'pkgpart'} = '';
131   $hash{'custom'} = 'Y';
132   #new FS::part_pkg ( \%hash ); # ?
133   new $class ( \%hash ); # ?
134 }
135
136 =item insert [ , OPTION => VALUE ... ]
137
138 Adds this package definition to the database.  If there is an error,
139 returns the error, otherwise returns false.
140
141 Currently available options are: I<pkg_svc>, I<primary_svc>, I<cust_pkg>, 
142 I<custnum_ref> and I<options>.
143
144 If I<pkg_svc> is set to a hashref with svcparts as keys and quantities as
145 values, appropriate FS::pkg_svc records will be inserted.
146
147 If I<primary_svc> is set to the svcpart of the primary service, the appropriate
148 FS::pkg_svc record will be updated.
149
150 If I<cust_pkg> is set to a pkgnum of a FS::cust_pkg record (or the FS::cust_pkg
151 record itself), the object will be updated to point to this package definition.
152
153 In conjunction with I<cust_pkg>, if I<custnum_ref> is set to a scalar reference,
154 the scalar will be updated with the custnum value from the cust_pkg record.
155
156 If I<tax_overrides> is set to a hashref with usage classes as keys and comma
157 separated tax class numbers as values, appropriate FS::part_pkg_taxoverride
158 records will be inserted.
159
160 If I<options> is set to a hashref of options, appropriate FS::part_pkg_option
161 records will be inserted.
162
163 =cut
164
165 sub insert {
166   my $self = shift;
167   my %options = @_;
168   warn "FS::part_pkg::insert called on $self with options ".
169        join(', ', map "$_=>$options{$_}", keys %options)
170     if $DEBUG;
171
172   local $SIG{HUP} = 'IGNORE';
173   local $SIG{INT} = 'IGNORE';
174   local $SIG{QUIT} = 'IGNORE';
175   local $SIG{TERM} = 'IGNORE';
176   local $SIG{TSTP} = 'IGNORE';
177   local $SIG{PIPE} = 'IGNORE';
178
179   my $oldAutoCommit = $FS::UID::AutoCommit;
180   local $FS::UID::AutoCommit = 0;
181   my $dbh = dbh;
182
183   warn "  inserting part_pkg record" if $DEBUG;
184   my $error = $self->SUPER::insert( $options{options} );
185   if ( $error ) {
186     $dbh->rollback if $oldAutoCommit;
187     return $error;
188   }
189
190   my $conf = new FS::Conf;
191   if ( $conf->exists('agent_defaultpkg') ) {
192     warn "  agent_defaultpkg set; allowing all agents to purchase package"
193       if $DEBUG;
194     foreach my $agent_type ( qsearch('agent_type', {} ) ) {
195       my $type_pkgs = new FS::type_pkgs({
196         'typenum' => $agent_type->typenum,
197         'pkgpart' => $self->pkgpart,
198       });
199       my $error = $type_pkgs->insert;
200       if ( $error ) {
201         $dbh->rollback if $oldAutoCommit;
202         return $error;
203       }
204     }
205   }
206
207   warn "  inserting part_pkg_taxoverride records" if $DEBUG;
208   my %overrides = %{ $options{'tax_overrides'} || {} };
209   foreach my $usage_class ( keys %overrides ) {
210     my $override =
211       ( exists($overrides{$usage_class}) && defined($overrides{$usage_class}) )
212         ? $overrides{$usage_class}
213         : '';
214     my @overrides = (grep "$_", split(',', $override) );
215     my $error = $self->process_m2m (
216                   'link_table'   => 'part_pkg_taxoverride',
217                   'target_table' => 'tax_class',
218                   'hashref'      => { 'usage_class' => $usage_class },
219                   'params'       => \@overrides,
220                 );
221     if ( $error ) {
222       $dbh->rollback if $oldAutoCommit;
223       return $error;
224     }
225   }
226
227   unless ( $skip_pkg_svc_hack ) {
228
229     warn "  inserting pkg_svc records" if $DEBUG;
230     my $pkg_svc = $options{'pkg_svc'} || {};
231     foreach my $part_svc ( qsearch('part_svc', {} ) ) {
232       my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
233       my $primary_svc =
234         ( $options{'primary_svc'} && $options{'primary_svc'}==$part_svc->svcpart )
235           ? 'Y'
236           : '';
237
238       my $pkg_svc = new FS::pkg_svc( {
239         'pkgpart'     => $self->pkgpart,
240         'svcpart'     => $part_svc->svcpart,
241         'quantity'    => $quantity, 
242         'primary_svc' => $primary_svc,
243       } );
244       my $error = $pkg_svc->insert;
245       if ( $error ) {
246         $dbh->rollback if $oldAutoCommit;
247         return $error;
248       }
249     }
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>, I<primary_svc> and I<options>
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 replaced.
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 If I<options> is set to a hashref, the appropriate FS::part_pkg_option records
303 will be replaced.
304
305 =cut
306
307 sub replace {
308   my $new = shift;
309
310   my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
311               ? shift
312               : $new->replace_old;
313
314   my $options = 
315     ( ref($_[0]) eq 'HASH' )
316       ? shift
317       : { @_ };
318
319   $options->{options} = {} unless defined($options->{options});
320
321   warn "FS::part_pkg::replace called on $new to replace $old with options".
322        join(', ', map "$_ => ". $options->{$_}, keys %$options)
323     if $DEBUG;
324
325   local $SIG{HUP} = 'IGNORE';
326   local $SIG{INT} = 'IGNORE';
327   local $SIG{QUIT} = 'IGNORE';
328   local $SIG{TERM} = 'IGNORE';
329   local $SIG{TSTP} = 'IGNORE';
330   local $SIG{PIPE} = 'IGNORE';
331
332   my $oldAutoCommit = $FS::UID::AutoCommit;
333   local $FS::UID::AutoCommit = 0;
334   my $dbh = dbh;
335
336   #plandata shit stays in replace for upgrades until after 2.0 (or edit
337   #_upgrade_data)
338   warn "  saving legacy plandata" if $DEBUG;
339   my $plandata = $new->get('plandata');
340   $new->set('plandata', '');
341
342   warn "  deleting old part_pkg_option records" if $DEBUG;
343   foreach my $part_pkg_option ( $old->part_pkg_option ) {
344     my $error = $part_pkg_option->delete;
345     if ( $error ) {
346       $dbh->rollback if $oldAutoCommit;
347       return $error;
348     }
349   }
350
351   warn "  replacing part_pkg record" if $DEBUG;
352   my $error = $new->SUPER::replace($old, $options->{options} );
353   if ( $error ) {
354     $dbh->rollback if $oldAutoCommit;
355     return $error;
356   }
357
358   warn "  inserting part_pkg_option records for plandata: $plandata|" if $DEBUG;
359   foreach my $part_pkg_option ( 
360     map { /^(\w+)=(.*)$/ or do { $dbh->rollback if $oldAutoCommit;
361                                  return "illegal plandata: $plandata";
362                                };
363           new FS::part_pkg_option {
364             'pkgpart'     => $new->pkgpart,
365             'optionname'  => $1,
366             'optionvalue' => $2,
367           };
368         }
369     split("\n", $plandata)
370   ) {
371     my $error = $part_pkg_option->insert;
372     if ( $error ) {
373       $dbh->rollback if $oldAutoCommit;
374       return $error;
375     }
376   }
377
378   warn "  replacing pkg_svc records" if $DEBUG;
379   my $pkg_svc = $options->{'pkg_svc'} || {};
380   foreach my $part_svc ( qsearch('part_svc', {} ) ) {
381     my $quantity = $pkg_svc->{$part_svc->svcpart} || 0;
382     my $primary_svc =
383       ( defined($options->{'primary_svc'}) && $options->{'primary_svc'}
384         && $options->{'primary_svc'} == $part_svc->svcpart
385       )
386         ? 'Y'
387         : '';
388
389
390     my $old_pkg_svc = qsearchs('pkg_svc', {
391       'pkgpart' => $old->pkgpart,
392       'svcpart' => $part_svc->svcpart,
393     } );
394     my $old_quantity = $old_pkg_svc ? $old_pkg_svc->quantity : 0;
395     my $old_primary_svc =
396       ( $old_pkg_svc && $old_pkg_svc->dbdef_table->column('primary_svc') )
397         ? $old_pkg_svc->primary_svc
398         : '';
399     next unless $old_quantity != $quantity || $old_primary_svc ne $primary_svc;
400   
401     my $new_pkg_svc = new FS::pkg_svc( {
402       'pkgsvcnum'   => ( $old_pkg_svc ? $old_pkg_svc->pkgsvcnum : '' ),
403       'pkgpart'     => $new->pkgpart,
404       'svcpart'     => $part_svc->svcpart,
405       'quantity'    => $quantity, 
406       'primary_svc' => $primary_svc,
407     } );
408     my $error = $old_pkg_svc
409                   ? $new_pkg_svc->replace($old_pkg_svc)
410                   : $new_pkg_svc->insert;
411     if ( $error ) {
412       $dbh->rollback if $oldAutoCommit;
413       return $error;
414     }
415   }
416
417   warn "  commiting transaction" if $DEBUG;
418   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
419   '';
420 }
421
422 =item check
423
424 Checks all fields to make sure this is a valid package definition.  If
425 there is an error, returns the error, otherwise returns false.  Called by the
426 insert and replace methods.
427
428 =cut
429
430 sub check {
431   my $self = shift;
432   warn "FS::part_pkg::check called on $self" if $DEBUG;
433
434   for (qw(setup recur plandata)) {
435     #$self->set($_=>0) if $self->get($_) =~ /^\s*$/; }
436     return "Use of $_ field is deprecated; set a plan and options: ".
437            $self->get($_)
438       if length($self->get($_));
439     $self->set($_, '');
440   }
441
442   if ( $self->dbdef_table->column('freq')->type =~ /(int)/i ) {
443     my $error = $self->ut_number('freq');
444     return $error if $error;
445   } else {
446     $self->freq =~ /^(\d+[hdw]?)$/
447       or return "Illegal or empty freq: ". $self->freq;
448     $self->freq($1);
449   }
450
451   my @null_agentnum_right = ( 'Edit global package definitions' );
452   push @null_agentnum_right, 'One-time charge'
453     if $self->freq =~ /^0/;
454   push @null_agentnum_right, 'Customize customer package'
455     if $self->disabled eq 'Y'; #good enough
456
457   my $error = $self->ut_numbern('pkgpart')
458     || $self->ut_text('pkg')
459     || $self->ut_text('comment')
460     || $self->ut_textn('promo_code')
461     || $self->ut_alphan('plan')
462     || $self->ut_enum('setuptax', [ '', 'Y' ] )
463     || $self->ut_enum('recurtax', [ '', 'Y' ] )
464     || $self->ut_textn('taxclass')
465     || $self->ut_enum('disabled', [ '', 'Y' ] )
466     || $self->ut_enum('custom', [ '', 'Y' ] )
467     #|| $self->ut_moneyn('setup_cost')
468     #|| $self->ut_moneyn('recur_cost')
469     || $self->ut_floatn('setup_cost')
470     || $self->ut_floatn('recur_cost')
471     || $self->ut_floatn('pay_weight')
472     || $self->ut_floatn('credit_weight')
473     || $self->ut_numbern('taxproductnum')
474     || $self->ut_foreign_keyn('taxproductnum',
475                               'part_pkg_taxproduct',
476                               'taxproductnum'
477                              )
478     || ( $setup_hack
479            ? $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
480            : $self->ut_agentnum_acl('agentnum', \@null_agentnum_right)
481        )
482     || $self->ut_numbern('fcc_ds0s')
483     || $self->SUPER::check
484   ;
485   return $error if $error;
486
487   if ( $self->classnum !~ /^$/ ) {
488     my $error = $self->ut_foreign_key('classnum', 'pkg_class', 'classnum');
489     return $error if $error;
490   } else {
491     $self->classnum('');
492   }
493
494   return 'Unknown plan '. $self->plan
495     unless exists($plans{$self->plan});
496
497   my $conf = new FS::Conf;
498   return 'Taxclass is required'
499     if ! $self->taxclass && $conf->exists('require_taxclasses');
500
501   '';
502 }
503
504 =item pkg_comment [ OPTION => VALUE... ]
505
506 Returns an (internal) string representing this package.  Currently,
507 "pkgpart: pkg - comment", is returned.  "pkg - comment" may be returned in the
508 future, omitting pkgpart.  The comment will have '(CUSTOM) ' prepended if
509 custom is Y.
510
511 If the option nopkgpart is true then the "pkgpart: ' is omitted.
512
513 =cut
514
515 sub pkg_comment {
516   my $self = shift;
517   my %opt = @_;
518
519   #$self->pkg. ' - '. $self->comment;
520   #$self->pkg. ' ('. $self->comment. ')';
521   my $pre = $opt{nopkgpart} ? '' : $self->pkgpart. ': ';
522   $pre. $self->pkg. ' - '. $self->custom_comment;
523 }
524
525 sub custom_comment {
526   my $self = shift;
527   ( $self->custom ? '(CUSTOM) ' : '' ). $self->comment;
528 }
529
530 =item pkg_class
531
532 Returns the package class, as an FS::pkg_class object, or the empty string
533 if there is no package class.
534
535 =cut
536
537 sub pkg_class {
538   my $self = shift;
539   if ( $self->classnum ) {
540     qsearchs('pkg_class', { 'classnum' => $self->classnum } );
541   } else {
542     return '';
543   }
544 }
545
546 =item categoryname 
547
548 Returns the package category name, or the empty string if there is no package
549 category.
550
551 =cut
552
553 sub categoryname {
554   my $self = shift;
555   my $pkg_class = $self->pkg_class;
556   $pkg_class
557     ? $pkg_class->categoryname
558     : '';
559 }
560
561 =item classname 
562
563 Returns the package class name, or the empty string if there is no package
564 class.
565
566 =cut
567
568 sub classname {
569   my $self = shift;
570   my $pkg_class = $self->pkg_class;
571   $pkg_class
572     ? $pkg_class->classname
573     : '';
574 }
575
576 =item agent 
577
578 Returns the associated agent for this event, if any, as an FS::agent object.
579
580 =cut
581
582 sub agent {
583   my $self = shift;
584   qsearchs('agent', { 'agentnum' => $self->agentnum } );
585 }
586
587 =item pkg_svc [ HASHREF | OPTION => VALUE ]
588
589 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
590 definition (with non-zero quantity).
591
592 One option is available, I<disable_linked>.  If set true it will return the
593 services for this package definition alone, omitting services from any add-on
594 packages.
595
596 =cut
597
598 =item type_pkgs
599
600 Returns all FS::type_pkgs objects (see L<FS::type_pkgs>) for this package
601 definition.
602
603 =cut
604
605 sub type_pkgs {
606   my $self = shift;
607   qsearch('type_pkgs', { 'pkgpart' => $self->pkgpart } );
608 }
609
610 sub pkg_svc {
611   my $self = shift;
612
613 #  #sort { $b->primary cmp $a->primary } 
614 #    grep { $_->quantity }
615 #      qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
616
617   my $opt = ref($_[0]) ? $_[0] : { @_ };
618   my %pkg_svc = map  { $_->svcpart => $_ }
619                 grep { $_->quantity }
620                 qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } );
621
622   unless ( $opt->{disable_linked} ) {
623     foreach my $dst_pkg ( map $_->dst_pkg, $self->svc_part_pkg_link ) {
624       my @pkg_svc = grep { $_->quantity }
625                     qsearch( 'pkg_svc', { pkgpart=>$dst_pkg->pkgpart } );
626       foreach my $pkg_svc ( @pkg_svc ) {
627         if ( $pkg_svc{$pkg_svc->svcpart} ) {
628           my $quantity = $pkg_svc{$pkg_svc->svcpart}->quantity;
629           $pkg_svc{$pkg_svc->svcpart}->quantity($quantity + $pkg_svc->quantity);
630         } else {
631           $pkg_svc{$pkg_svc->svcpart} = $pkg_svc;
632         }
633       }
634     }
635   }
636
637   values(%pkg_svc);
638
639 }
640
641 =item svcpart [ SVCDB ]
642
643 Returns the svcpart of the primary service definition (see L<FS::part_svc>)
644 associated with this package definition (see L<FS::pkg_svc>).  Returns
645 false if there not a primary service definition or exactly one service
646 definition with quantity 1, or if SVCDB is specified and does not match the
647 svcdb of the service definition.  SVCDB can be specified as a scalar table
648 name, such as 'svc_acct', or as an arrayref of possible table names.
649
650 =cut
651
652 sub svcpart {
653   my $pkg_svc = shift->_primary_pkg_svc(@_);
654   $pkg_svc ? $pkg_svc->svcpart : '';
655 }
656
657 =item part_svc [ SVCDB ]
658
659 Like the B<svcpart> method, but returns the FS::part_svc object (see
660 L<FS::part_svc>).
661
662 =cut
663
664 sub part_svc {
665   my $pkg_svc = shift->_primary_pkg_svc(@_);
666   $pkg_svc ? $pkg_svc->part_svc : '';
667 }
668
669 sub _primary_pkg_svc {
670   my $self = shift;
671
672   my $svcdb = scalar(@_) ? shift : [];
673   $svcdb = ref($svcdb) ? $svcdb : [ $svcdb ];
674   my %svcdb = map { $_=>1 } @$svcdb;
675
676   my @svcdb_pkg_svc =
677     grep { !scalar(@$svcdb) || $svcdb{ $_->part_svc->svcdb } }
678          $self->pkg_svc;
679
680   my @pkg_svc = grep { $_->primary_svc =~ /^Y/i } @svcdb_pkg_svc;
681   @pkg_svc = grep {$_->quantity == 1 } @svcdb_pkg_svc
682     unless @pkg_svc;
683   return '' if scalar(@pkg_svc) != 1;
684   $pkg_svc[0];
685 }
686
687 =item svcpart_unique_svcdb SVCDB
688
689 Returns the svcpart of a service definition (see L<FS::part_svc>) matching
690 SVCDB associated with this package definition (see L<FS::pkg_svc>).  Returns
691 false if there not a primary service definition for SVCDB or there are multiple
692 service definitions for SVCDB.
693
694 =cut
695
696 sub svcpart_unique_svcdb {
697   my( $self, $svcdb ) = @_;
698   my @svcdb_pkg_svc = grep { ( $svcdb eq $_->part_svc->svcdb ) } $self->pkg_svc;
699   return '' if scalar(@svcdb_pkg_svc) != 1;
700   $svcdb_pkg_svc[0]->svcpart;
701 }
702
703 =item payby
704
705 Returns a list of the acceptable payment types for this package.  Eventually
706 this should come out of a database table and be editable, but currently has the
707 following logic instead:
708
709 If the package is free, the single item B<BILL> is
710 returned, otherwise, the single item B<CARD> is returned.
711
712 (CHEK?  LEC?  Probably shouldn't accept those by default, prone to abuse)
713
714 =cut
715
716 sub payby {
717   my $self = shift;
718   if ( $self->is_free ) {
719     ( 'BILL' );
720   } else {
721     ( 'CARD' );
722   }
723 }
724
725 =item is_free
726
727 Returns true if this package is free.  
728
729 =cut
730
731 sub is_free {
732   my $self = shift;
733   unless ( $self->plan ) {
734     $self->setup =~ /^\s*0+(\.0*)?\s*$/
735       && $self->recur =~ /^\s*0+(\.0*)?\s*$/;
736   } elsif ( $self->can('is_free_options') ) {
737     not grep { $_ !~ /^\s*0*(\.0*)?\s*$/ }
738          map { $self->option($_) } 
739              $self->is_free_options;
740   } else {
741     warn "FS::part_pkg::is_free: FS::part_pkg::". $self->plan. " subclass ".
742          "provides neither is_free_options nor is_free method; returning false";
743     0;
744   }
745 }
746
747
748 sub freqs_href {
749   #method, class method or sub? #my $self = shift;
750
751   tie my %freq, 'Tie::IxHash', 
752     '0'    => '(no recurring fee)',
753     '1h'   => 'hourly',
754     '1d'   => 'daily',
755     '2d'   => 'every two days',
756     '3d'   => 'every three days',
757     '1w'   => 'weekly',
758     '2w'   => 'biweekly (every 2 weeks)',
759     '1'    => 'monthly',
760     '45d'  => 'every 45 days',
761     '2'    => 'bimonthly (every 2 months)',
762     '3'    => 'quarterly (every 3 months)',
763     '4'    => 'every 4 months',
764     '137d' => 'every 4 1/2 months (137 days)',
765     '6'    => 'semiannually (every 6 months)',
766     '12'   => 'annually',
767     '13'   => 'every 13 months (annually +1 month)',
768     '24'   => 'biannually (every 2 years)',
769     '36'   => 'triannually (every 3 years)',
770     '48'   => '(every 4 years)',
771     '60'   => '(every 5 years)',
772     '120'  => '(every 10 years)',
773   ;
774
775   \%freq;
776
777 }
778
779 =item freq_pretty
780
781 Returns an english representation of the I<freq> field, such as "monthly",
782 "weekly", "semi-annually", etc.
783
784 =cut
785
786 sub freq_pretty {
787   my $self = shift;
788   my $freq = $self->freq;
789
790   #my $freqs_href = $self->freqs_href;
791   my $freqs_href = freqs_href();
792
793   if ( exists($freqs_href->{$freq}) ) {
794     $freqs_href->{$freq};
795   } else {
796     my $interval = 'month';
797     if ( $freq =~ /^(\d+)([hdw])$/ ) {
798       my %interval = ( 'h' => 'hour', 'd'=>'day', 'w'=>'week' );
799       $interval = $interval{$2};
800     }
801     if ( $1 == 1 ) {
802       "every $interval";
803     } else {
804       "every $freq ${interval}s";
805     }
806   }
807 }
808
809 =item add_freq TIMESTAMP
810
811 Adds the frequency of this package to the provided timestamp and returns
812 the resulting timestamp, or -1 if the frequency of this package could not be
813 parsed (shouldn't happen).
814
815 =cut
816
817 sub add_freq {
818   my( $self, $date ) = @_;
819   my $freq = $self->freq;
820
821   #change this bit to use Date::Manip? CAREFUL with timezones (see
822   # mailing list archive)
823   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($date) )[0,1,2,3,4,5];
824
825   if ( $self->freq =~ /^\d+$/ ) {
826     $mon += $self->freq;
827     until ( $mon < 12 ) { $mon -= 12; $year++; }
828   } elsif ( $self->freq =~ /^(\d+)w$/ ) {
829     my $weeks = $1;
830     $mday += $weeks * 7;
831   } elsif ( $self->freq =~ /^(\d+)d$/ ) {
832     my $days = $1;
833     $mday += $days;
834   } elsif ( $self->freq =~ /^(\d+)h$/ ) {
835     my $hours = $1;
836     $hour += $hours;
837   } else {
838     return -1;
839   }
840
841   timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
842 }
843
844 =item plandata
845
846 For backwards compatibility, returns the plandata field as well as all options
847 from FS::part_pkg_option.
848
849 =cut
850
851 sub plandata {
852   my $self = shift;
853   carp "plandata is deprecated";
854   if ( @_ ) {
855     $self->SUPER::plandata(@_);
856   } else {
857     my $plandata = $self->get('plandata');
858     my %options = $self->options;
859     $plandata .= join('', map { "$_=$options{$_}\n" } keys %options );
860     $plandata;
861   }
862 }
863
864 =item part_pkg_option
865
866 Returns all options as FS::part_pkg_option objects (see
867 L<FS::part_pkg_option>).
868
869 =cut
870
871 sub part_pkg_option {
872   my $self = shift;
873   qsearch('part_pkg_option', { 'pkgpart' => $self->pkgpart } );
874 }
875
876 =item options 
877
878 Returns a list of option names and values suitable for assigning to a hash.
879
880 =cut
881
882 sub options {
883   my $self = shift;
884   map { $_->optionname => $_->optionvalue } $self->part_pkg_option;
885 }
886
887 =item option OPTIONNAME
888
889 Returns the option value for the given name, or the empty string.
890
891 =cut
892
893 sub option {
894   my( $self, $opt, $ornull ) = @_;
895   my $part_pkg_option =
896     qsearchs('part_pkg_option', {
897       pkgpart    => $self->pkgpart,
898       optionname => $opt,
899   } );
900   return $part_pkg_option->optionvalue if $part_pkg_option;
901   my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
902                      split("\n", $self->get('plandata') );
903   return $plandata{$opt} if exists $plandata{$opt};
904   cluck "WARNING: (pkgpart ". $self->pkgpart. ") Package def option $opt ".
905         "not found in options or plandata!\n"
906     unless $ornull;
907   '';
908 }
909
910 =item bill_part_pkg_link
911
912 Returns the associated part_pkg_link records (see L<FS::part_pkg_link>).
913
914 =cut
915
916 sub bill_part_pkg_link {
917   shift->_part_pkg_link('bill', @_);
918 }
919
920 =item svc_part_pkg_link
921
922 Returns the associated part_pkg_link records (see L<FS::part_pkg_link>).
923
924 =cut
925
926 sub svc_part_pkg_link {
927   shift->_part_pkg_link('svc', @_);
928 }
929
930 sub _part_pkg_link {
931   my( $self, $type ) = @_;
932   qsearch({ table    => 'part_pkg_link',
933             hashref  => { 'src_pkgpart' => $self->pkgpart,
934                           'link_type'   => $type,
935                         },
936             order_by => "ORDER BY hidden",
937          });
938 }
939
940 sub self_and_bill_linked {
941   shift->_self_and_linked('bill', @_);
942 }
943
944 sub _self_and_linked {
945   my( $self, $type, $hidden ) = @_;
946   $hidden ||= '';
947
948   my @result = ();
949   foreach ( ( $self, map { $_->dst_pkg->_self_and_linked($type, $_->hidden) }
950                      $self->_part_pkg_link($type) ) )
951   {
952     $_->hidden($hidden) if $hidden;
953     push @result, $_;
954   }
955
956   (@result);
957 }
958
959 =item part_pkg_taxoverride [ CLASS ]
960
961 Returns all associated FS::part_pkg_taxoverride objects (see
962 L<FS::part_pkg_taxoverride>).  Limits the returned set to those
963 of class CLASS if defined.  Class may be one of 'setup', 'recur',
964 the empty string (default), or a usage class number (see L<FS::usage_class>).
965 When a class is specified, the empty string class (default) is returned
966 if no more specific values exist.
967
968 =cut
969
970 sub part_pkg_taxoverride {
971   my $self = shift;
972   my $class = shift;
973
974   my $hashref = { 'pkgpart' => $self->pkgpart };
975   $hashref->{'usage_class'} = $class if defined($class);
976   my @overrides = qsearch('part_pkg_taxoverride', $hashref );
977
978   unless ( scalar(@overrides) || !defined($class) || !$class ){
979     $hashref->{'usage_class'} = '';
980     @overrides = qsearch('part_pkg_taxoverride', $hashref );
981   }
982
983   @overrides;
984 }
985
986 =item has_taxproduct
987
988 Returns true if this package has any taxproduct associated with it.  
989
990 =cut
991
992 sub has_taxproduct {
993   my $self = shift;
994
995   $self->taxproductnum ||
996   scalar( grep { $_ =~/^usage_taxproductnum_/ && $self->option($_) } 
997           keys %{ {$self->options} }
998   )
999
1000 }
1001
1002
1003 =item taxproduct [ CLASS ]
1004
1005 Returns the associated tax product for this package definition (see
1006 L<FS::part_pkg_taxproduct>).  CLASS may be one of 'setup', 'recur' or
1007 the usage classnum (see L<FS::usage_class>).  Returns the default
1008 tax product for this record if the more specific CLASS value does
1009 not exist.
1010
1011 =cut
1012
1013 sub taxproduct {
1014   my $self = shift;
1015   my $class = shift;
1016
1017   my $part_pkg_taxproduct;
1018
1019   my $taxproductnum = $self->taxproductnum;
1020   if ($class) { 
1021     my $class_taxproductnum = $self->option("usage_taxproductnum_$class", 1);
1022     $taxproductnum = $class_taxproductnum
1023       if $class_taxproductnum
1024   }
1025   
1026   $part_pkg_taxproduct =
1027     qsearchs( 'part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum } );
1028
1029   unless ($part_pkg_taxproduct || $taxproductnum eq $self->taxproductnum ) {
1030     $taxproductnum = $self->taxproductnum;
1031     $part_pkg_taxproduct =
1032       qsearchs( 'part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum } );
1033   }
1034
1035   $part_pkg_taxproduct;
1036 }
1037
1038 =item taxproduct_description [ CLASS ]
1039
1040 Returns the description of the associated tax product for this package
1041 definition (see L<FS::part_pkg_taxproduct>).
1042
1043 =cut
1044
1045 sub taxproduct_description {
1046   my $self = shift;
1047   my $part_pkg_taxproduct = $self->taxproduct(@_);
1048   $part_pkg_taxproduct ? $part_pkg_taxproduct->description : '';
1049 }
1050
1051 =item part_pkg_taxrate DATA_PROVIDER, GEOCODE, [ CLASS ]
1052
1053 Returns the package to taxrate m2m records for this package in the location
1054 specified by GEOCODE (see L<FS::part_pkg_taxrate>) and usage class CLASS.
1055 CLASS may be one of 'setup', 'recur', or one of the usage classes numbers
1056 (see L<FS::usage_class>).
1057
1058 =cut
1059
1060 sub _expand_cch_taxproductnum {
1061   my $self = shift;
1062   my $class = shift;
1063   my $part_pkg_taxproduct = $self->taxproduct($class);
1064
1065   my ($a,$b,$c,$d) = ( $part_pkg_taxproduct
1066                          ? ( split ':', $part_pkg_taxproduct->taxproduct )
1067                          : ()
1068                      );
1069   $a = '' unless $a; $b = '' unless $b; $c = '' unless $c; $d = '' unless $d;
1070   my $extra_sql = "AND ( taxproduct = '$a:$b:$c:$d'
1071                       OR taxproduct = '$a:$b:$c:'
1072                       OR taxproduct = '$a:$b:".":$d'
1073                       OR taxproduct = '$a:$b:".":' )";
1074   map { $_->taxproductnum } qsearch( { 'table'     => 'part_pkg_taxproduct',
1075                                        'hashref'   => { 'data_vendor'=>'cch' },
1076                                        'extra_sql' => $extra_sql,
1077                                    } );
1078                                      
1079 }
1080
1081 sub part_pkg_taxrate {
1082   my $self = shift;
1083   my ($data_vendor, $geocode, $class) = @_;
1084
1085   my $dbh = dbh;
1086   my $extra_sql = 'WHERE part_pkg_taxproduct.data_vendor = '.
1087                   dbh->quote($data_vendor);
1088   
1089   # CCH oddness in m2m
1090   $extra_sql .= ' AND ('.
1091     join(' OR ', map{ 'geocode = '. $dbh->quote(substr($geocode, 0, $_)) }
1092                  qw(10 5 2)
1093         ).
1094     ')';
1095   # much more CCH oddness in m2m -- this is kludgy
1096   my @tpnums = $self->_expand_cch_taxproductnum($class);
1097   if (scalar(@tpnums)) {
1098     $extra_sql .= ' AND ('.
1099                             join(' OR ', map{ "taxproductnum = $_" } @tpnums ).
1100                        ')';
1101   } else {
1102     $extra_sql .= ' AND ( 0 = 1 )';
1103   }
1104
1105   my $addl_from = 'LEFT JOIN part_pkg_taxproduct USING ( taxproductnum )';
1106   my $order_by = 'ORDER BY taxclassnum, length(geocode) desc, length(taxproduct) desc';
1107   my $select   = 'DISTINCT ON(taxclassnum) *, taxproduct';
1108
1109   # should qsearch preface columns with the table to facilitate joins?
1110   qsearch( { 'table'     => 'part_pkg_taxrate',
1111              'select'    => $select,
1112              'hashref'   => { # 'data_vendor'   => $data_vendor,
1113                               # 'taxproductnum' => $self->taxproductnum,
1114                             },
1115              'addl_from' => $addl_from,
1116              'extra_sql' => $extra_sql,
1117              'order_by'  => $order_by,
1118          } );
1119 }
1120
1121 =item _rebless
1122
1123 Reblesses the object into the FS::part_pkg::PLAN class (if available), where
1124 PLAN is the object's I<plan> field.  There should be better docs
1125 on how to create new price plans, but until then, see L</NEW PLAN CLASSES>.
1126
1127 =cut
1128
1129 sub _rebless {
1130   my $self = shift;
1131   my $plan = $self->plan;
1132   unless ( $plan ) {
1133     cluck "no price plan found for pkgpart ". $self->pkgpart. "\n"
1134       if $DEBUG;
1135     return $self;
1136   }
1137   return $self if ref($self) =~ /::$plan$/; #already blessed into plan subclass
1138   my $class = ref($self). "::$plan";
1139   warn "reblessing $self into $class" if $DEBUG;
1140   eval "use $class;";
1141   die $@ if $@;
1142   bless($self, $class) unless $@;
1143   $self;
1144 }
1145
1146 #fallbacks that eval the setup and recur fields, for backwards compat
1147
1148 sub calc_setup {
1149   my $self = shift;
1150   warn 'no price plan class for '. $self->plan. ", eval-ing setup\n";
1151   $self->_calc_eval('setup', @_);
1152 }
1153
1154 sub calc_recur {
1155   my $self = shift;
1156   warn 'no price plan class for '. $self->plan. ", eval-ing recur\n";
1157   $self->_calc_eval('recur', @_);
1158 }
1159
1160 use vars qw( $sdate @details );
1161 sub _calc_eval {
1162   #my( $self, $field, $cust_pkg ) = @_;
1163   my( $self, $field, $cust_pkg, $sdateref, $detailsref ) = @_;
1164   *sdate = $sdateref;
1165   *details = $detailsref;
1166   $self->$field() =~ /^(.*)$/
1167     or die "Illegal $field (pkgpart ". $self->pkgpart. '): '.
1168             $self->$field(). "\n";
1169   my $prog = $1;
1170   return 0 if $prog =~ /^\s*$/;
1171   my $value = eval $prog;
1172   die $@ if $@;
1173   $value;
1174 }
1175
1176 #fallback that return 0 for old legacy packages with no plan
1177
1178 sub calc_remain { 0; }
1179 sub calc_cancel { 0; }
1180 sub calc_units  { 0; }
1181
1182 #fallback for everything except bulk.pm
1183 sub hide_svc_detail { 0; }
1184
1185 =item recur_cost_permonth CUST_PKG
1186
1187 recur_cost divided by freq (only supported for monthly and longer frequencies)
1188
1189 =cut
1190
1191 sub recur_cost_permonth {
1192   my($self, $cust_pkg) = @_;
1193   return 0 unless $self->freq =~ /^\d+$/ && $self->freq > 0;
1194   sprintf('%.2f', $self->recur_cost / $self->freq );
1195 }
1196
1197 =item format OPTION DATA
1198
1199 Returns data formatted according to the function 'format' described
1200 in the plan info.  Returns DATA if no such function exists.
1201
1202 =cut
1203
1204 sub format {
1205   my ($self, $option, $data) = (shift, shift, shift);
1206   if (exists($plans{$self->plan}->{fields}->{$option}{format})) {
1207     &{$plans{$self->plan}->{fields}->{$option}{format}}($data);
1208   }else{
1209     $data;
1210   }
1211 }
1212
1213 =item parse OPTION DATA
1214
1215 Returns data parsed according to the function 'parse' described
1216 in the plan info.  Returns DATA if no such function exists.
1217
1218 =cut
1219
1220 sub parse {
1221   my ($self, $option, $data) = (shift, shift, shift);
1222   if (exists($plans{$self->plan}->{fields}->{$option}{parse})) {
1223     &{$plans{$self->plan}->{fields}->{$option}{parse}}($data);
1224   }else{
1225     $data;
1226   }
1227 }
1228
1229 =back
1230
1231 =cut
1232
1233 =head1 CLASS METHODS
1234
1235 =over 4
1236
1237 =cut
1238
1239 # _upgrade_data
1240 #
1241 # Used by FS::Upgrade to migrate to a new database.
1242
1243 sub _upgrade_data { # class method
1244   my($class, %opts) = @_;
1245
1246   warn "[FS::part_pkg] upgrading $class\n" if $DEBUG;
1247
1248   my @part_pkg = qsearch({
1249     'table'     => 'part_pkg',
1250     'extra_sql' => "WHERE ". join(' OR ',
1251                      ( map "($_ IS NOT NULL AND $_ != '' )",
1252                            qw( plandata setup recur ) ),
1253                      'plan IS NULL', "plan = '' ",
1254                    ),
1255   });
1256
1257   foreach my $part_pkg (@part_pkg) {
1258
1259     unless ( $part_pkg->plan ) {
1260       $part_pkg->plan('flat');
1261     }
1262
1263     if ( length($part_pkg->option('setup_fee')) == 0 
1264          && $part_pkg->setup =~ /^\s*([\d\.]+)\s*$/ ) {
1265
1266       my $opt = new FS::part_pkg_option {
1267         'pkgpart'     => $part_pkg->pkgpart,
1268         'optionname'  => 'setup_fee',
1269         'optionvalue' => $1,
1270       };
1271       my $error = $opt->insert;
1272       die $error if $error;
1273
1274
1275       #} else {
1276       #  die "Can't parse part_pkg.setup for fee; convert pkgnum ".
1277       #      $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
1278     }
1279     $part_pkg->setup('');
1280
1281     if ( length($part_pkg->option('recur_fee')) == 0
1282          && $part_pkg->recur =~ /^\s*([\d\.]+)\s*$/ ) {
1283
1284         my $opt = new FS::part_pkg_option {
1285           'pkgpart'     => $part_pkg->pkgpart,
1286           'optionname'  => 'recur_fee',
1287           'optionvalue' => $1,
1288         };
1289         my $error = $opt->insert;
1290         die $error if $error;
1291
1292
1293       #} else {
1294       #  die "Can't parse part_pkg.setup for fee; convert pkgnum ".
1295       #      $part_pkg->pkgnum. " manually: ". $part_pkg->setup. "\n";
1296     }
1297     $part_pkg->recur('');
1298
1299     $part_pkg->replace; #this should take care of plandata, right?
1300
1301   }
1302
1303   # now upgrade to the explicit custom flag
1304
1305   @part_pkg = qsearch({
1306     'table'     => 'part_pkg',
1307     'hashref'   => { disabled => 'Y', custom => '' },
1308     'extra_sql' => "AND comment LIKE '(CUSTOM) %'",
1309   });
1310
1311   foreach my $part_pkg (@part_pkg) {
1312     my $new = new FS::part_pkg { $part_pkg->hash };
1313     $new->custom('Y');
1314     my $comment = $part_pkg->comment;
1315     $comment =~ s/^\(CUSTOM\) //;
1316     $comment = '(none)' unless $comment =~ /\S/;
1317     $new->comment($comment);
1318
1319     my $pkg_svc = { map { $_->svcpart => $_->quantity } $part_pkg->pkg_svc };
1320     my $primary = $part_pkg->svcpart;
1321     my $options = { $part_pkg->options };
1322
1323     my $error = $new->replace( $part_pkg,
1324                                'pkg_svc'     => $pkg_svc,
1325                                'primary_svc' => $primary,
1326                                'options'     => $options,
1327                              );
1328     die $error if $error;
1329   }
1330
1331 }
1332
1333 =item curuser_pkgs_sql
1334
1335 Returns an SQL fragment for searching for packages the current user can
1336 use, either via part_pkg.agentnum directly, or via agent type (see
1337 L<FS::type_pkgs>).
1338
1339 =cut
1340
1341 sub curuser_pkgs_sql {
1342   my $class = shift;
1343
1344   $class->_pkgs_sql( $FS::CurrentUser::CurrentUser->agentnums );
1345
1346 }
1347
1348 =item agent_pkgs_sql AGENT | AGENTNUM, ...
1349
1350 Returns an SQL fragment for searching for packages the provided agent or agents
1351 can use, either via part_pkg.agentnum directly, or via agent type (see
1352 L<FS::type_pkgs>).
1353
1354 =cut
1355
1356 sub agent_pkgs_sql {
1357   my $class = shift;  #i'm a class method, not a sub (the question is... why??)
1358   my @agentnums = map { ref($_) ? $_->agentnum : $_ } @_;
1359
1360   $class->_pkgs_sql(@agentnums); #is this why
1361
1362 }
1363
1364 sub _pkgs_sql {
1365   my( $class, @agentnums ) = @_;
1366   my $agentnums = join(',', @agentnums);
1367
1368   "
1369     (
1370       ( agentnum IS NOT NULL AND agentnum IN ($agentnums) )
1371       OR ( agentnum IS NULL
1372            AND EXISTS ( SELECT 1
1373                           FROM type_pkgs
1374                             LEFT JOIN agent_type USING ( typenum )
1375                             LEFT JOIN agent AS typeagent USING ( typenum )
1376                           WHERE type_pkgs.pkgpart = part_pkg.pkgpart
1377                             AND typeagent.agentnum IN ($agentnums)
1378                       )
1379          )
1380     )
1381   ";
1382
1383 }
1384
1385 =back
1386
1387 =head1 SUBROUTINES
1388
1389 =over 4
1390
1391 =item plan_info
1392
1393 =cut
1394
1395 #false laziness w/part_export & cdr
1396 my %info;
1397 foreach my $INC ( @INC ) {
1398   warn "globbing $INC/FS/part_pkg/*.pm\n" if $DEBUG;
1399   foreach my $file ( glob("$INC/FS/part_pkg/*.pm") ) {
1400     warn "attempting to load plan info from $file\n" if $DEBUG;
1401     $file =~ /\/(\w+)\.pm$/ or do {
1402       warn "unrecognized file in $INC/FS/part_pkg/: $file\n";
1403       next;
1404     };
1405     my $mod = $1;
1406     my $info = eval "use FS::part_pkg::$mod; ".
1407                     "\\%FS::part_pkg::$mod\::info;";
1408     if ( $@ ) {
1409       die "error using FS::part_pkg::$mod (skipping): $@\n" if $@;
1410       next;
1411     }
1412     unless ( keys %$info ) {
1413       warn "no %info hash found in FS::part_pkg::$mod, skipping\n";
1414       next;
1415     }
1416     warn "got plan info from FS::part_pkg::$mod: $info\n" if $DEBUG;
1417     if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
1418       warn "skipping disabled plan FS::part_pkg::$mod" if $DEBUG;
1419       next;
1420     }
1421     $info{$mod} = $info;
1422   }
1423 }
1424
1425 tie %plans, 'Tie::IxHash',
1426   map  { $_ => $info{$_} }
1427   sort { $info{$a}->{'weight'} <=> $info{$b}->{'weight'} }
1428   keys %info;
1429
1430 sub plan_info {
1431   \%plans;
1432 }
1433
1434
1435 =back
1436
1437 =head1 NEW PLAN CLASSES
1438
1439 A module should be added in FS/FS/part_pkg/  Eventually, an example may be
1440 found in eg/plan_template.pm.  Until then, it is suggested that you use the
1441 other modules in FS/FS/part_pkg/ as a guide.
1442
1443 =head1 BUGS
1444
1445 The delete method is unimplemented.
1446
1447 setup and recur semantics are not yet defined (and are implemented in
1448 FS::cust_bill.  hmm.).  now they're deprecated and need to go.
1449
1450 plandata should go
1451
1452 part_pkg_taxrate is Pg specific
1453
1454 replace should be smarter about managing the related tables (options, pkg_svc)
1455
1456 =head1 SEE ALSO
1457
1458 L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
1459 schema.html from the base documentation.
1460
1461 =cut
1462
1463 1;
1464