4 use vars qw(@ISA $disable_agentcheck @SVCDB_CANCEL_SEQ $DEBUG);
5 use FS::UID qw( getotaker dbh );
6 use FS::Record qw( qsearch qsearchs );
7 use FS::Misc qw( send_email );
13 use FS::cust_bill_pkg;
15 # need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
17 # because they load configuraion by setting FS::UID::callback (see TODO)
23 # for sending cancel emails in sub cancel
26 @ISA = qw( FS::Record );
30 $disable_agentcheck = 0;
32 # The order in which to unprovision services.
33 @SVCDB_CANCEL_SEQ = qw( svc_external
42 my ( $hashref, $cache ) = @_;
43 #if ( $hashref->{'pkgpart'} ) {
44 if ( $hashref->{'pkg'} ) {
45 # #@{ $self->{'_pkgnum'} } = ();
46 # my $subcache = $cache->subcache('pkgpart', 'part_pkg');
47 # $self->{'_pkgpart'} = $subcache;
48 # #push @{ $self->{'_pkgnum'} },
49 # FS::part_pkg->new_or_cached($hashref, $subcache);
50 $self->{'_pkgpart'} = FS::part_pkg->new($hashref);
52 if ( exists $hashref->{'svcnum'} ) {
53 #@{ $self->{'_pkgnum'} } = ();
54 my $subcache = $cache->subcache('svcnum', 'cust_svc', $hashref->{pkgnum});
55 $self->{'_svcnum'} = $subcache;
56 #push @{ $self->{'_pkgnum'} },
57 FS::cust_svc->new_or_cached($hashref, $subcache) if $hashref->{svcnum};
63 FS::cust_pkg - Object methods for cust_pkg objects
69 $record = new FS::cust_pkg \%hash;
70 $record = new FS::cust_pkg { 'column' => 'value' };
72 $error = $record->insert;
74 $error = $new_record->replace($old_record);
76 $error = $record->delete;
78 $error = $record->check;
80 $error = $record->cancel;
82 $error = $record->suspend;
84 $error = $record->unsuspend;
86 $part_pkg = $record->part_pkg;
88 @labels = $record->labels;
90 $seconds = $record->seconds_since($timestamp);
92 $error = FS::cust_pkg::order( $custnum, \@pkgparts );
93 $error = FS::cust_pkg::order( $custnum, \@pkgparts, \@remove_pkgnums ] );
97 An FS::cust_pkg object represents a customer billing item. FS::cust_pkg
98 inherits from FS::Record. The following fields are currently supported:
102 =item pkgnum - primary key (assigned automatically for new billing items)
104 =item custnum - Customer (see L<FS::cust_main>)
106 =item pkgpart - Billing item definition (see L<FS::part_pkg>)
110 =item bill - date (next bill date)
112 =item last_bill - last bill date
120 =item otaker - order taker (assigned automatically if null, see L<FS::UID>)
122 =item manual_flag - If this field is set to 1, disables the automatic
123 unsuspension of this package when using the B<unsuspendauto> config file.
127 Note: setup, bill, susp, expire and cancel are specified as UNIX timestamps;
128 see L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for
129 conversion functions.
137 Create a new billing item. To add the item to the database, see L<"insert">.
141 sub table { 'cust_pkg'; }
145 Adds this billing item to the database ("Orders" the item). If there is an
146 error, returns the error, otherwise returns false.
148 If the additional field I<promo_code> is defined instead of I<pkgpart>, it
149 will be used to look up the package definition and agent restrictions will be
154 This method now works but you probably shouldn't use it.
156 You don't want to delete billing items, because there would then be no record
157 the customer ever purchased the item. Instead, see the cancel method.
162 # return "Can't delete cust_pkg records!";
165 =item replace OLD_RECORD
167 Replaces the OLD_RECORD with this one in the database. If there is an error,
168 returns the error, otherwise returns false.
170 Currently, custnum, setup, bill, susp, expire, and cancel may be changed.
172 Changing pkgpart may have disasterous effects. See the order subroutine.
174 setup and bill are normally updated by calling the bill method of a customer
175 object (see L<FS::cust_main>).
177 suspend is normally updated by the suspend and unsuspend methods.
179 cancel is normally updated by the cancel method (and also the order subroutine
185 my( $new, $old ) = ( shift, shift );
187 #return "Can't (yet?) change pkgpart!" if $old->pkgpart != $new->pkgpart;
188 return "Can't change otaker!" if $old->otaker ne $new->otaker;
191 #return "Can't change setup once it exists!"
192 # if $old->getfield('setup') &&
193 # $old->getfield('setup') != $new->getfield('setup');
195 #some logic for bill, susp, cancel?
197 $new->SUPER::replace($old);
202 Checks all fields to make sure this is a valid billing item. If there is an
203 error, returns the error, otherwise returns false. Called by the insert and
212 $self->ut_numbern('pkgnum')
213 || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
214 || $self->ut_numbern('pkgpart')
215 || $self->ut_numbern('setup')
216 || $self->ut_numbern('bill')
217 || $self->ut_numbern('susp')
218 || $self->ut_numbern('cancel')
220 return $error if $error;
222 if ( $self->promo_code ) {
225 qsearchs('part_pkg', {
226 'pkgpart' => $self->pkgpart,
227 'promo_code' => { op=>'ILIKE', value=>$self->promo_code },
229 return 'Unknown promotional code' unless $promo_part_pkg;
230 $self->pkgpart($promo_part_pkg->pkgpart);
234 unless ( $disable_agentcheck ) {
236 qsearchs( 'agent', { 'agentnum' => $self->cust_main->agentnum } );
237 my $pkgpart_href = $agent->pkgpart_hashref;
238 return "agent ". $agent->agentnum.
239 " can't purchase pkgpart ". $self->pkgpart
240 unless $pkgpart_href->{ $self->pkgpart };
243 $error = $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart' );
244 return $error if $error;
248 $self->otaker(getotaker) unless $self->otaker;
249 $self->otaker =~ /^([\w\.\-]{0,16})$/ or return "Illegal otaker";
252 if ( $self->dbdef_table->column('manual_flag') ) {
253 $self->manual_flag('') if $self->manual_flag eq ' ';
254 $self->manual_flag =~ /^([01]?)$/
255 or return "Illegal manual_flag ". $self->manual_flag;
256 $self->manual_flag($1);
262 =item cancel [ OPTION => VALUE ... ]
264 Cancels and removes all services (see L<FS::cust_svc> and L<FS::part_svc>)
265 in this package, then cancels the package itself (sets the cancel field to
268 Available options are: I<quiet>
270 I<quiet> can be set true to supress email cancellation notices.
272 If there is an error, returns the error, otherwise returns false.
277 my( $self, %options ) = @_;
280 local $SIG{HUP} = 'IGNORE';
281 local $SIG{INT} = 'IGNORE';
282 local $SIG{QUIT} = 'IGNORE';
283 local $SIG{TERM} = 'IGNORE';
284 local $SIG{TSTP} = 'IGNORE';
285 local $SIG{PIPE} = 'IGNORE';
287 my $oldAutoCommit = $FS::UID::AutoCommit;
288 local $FS::UID::AutoCommit = 0;
292 foreach my $cust_svc (
293 qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
295 push @{ $svc{$cust_svc->part_svc->svcdb} }, $cust_svc;
298 foreach my $svcdb (@SVCDB_CANCEL_SEQ) {
299 foreach my $cust_svc (@{ $svc{$svcdb} }) {
300 my $error = $cust_svc->cancel;
303 $dbh->rollback if $oldAutoCommit;
304 return "Error cancelling cust_svc: $error";
309 unless ( $self->getfield('cancel') ) {
310 my %hash = $self->hash;
311 $hash{'cancel'} = time;
312 my $new = new FS::cust_pkg ( \%hash );
313 $error = $new->replace($self);
315 $dbh->rollback if $oldAutoCommit;
320 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
322 my $conf = new FS::Conf;
323 my @invoicing_list = grep { $_ ne 'POST' } $self->cust_main->invoicing_list;
324 if ( !$options{'quiet'} && $conf->exists('emailcancel') && @invoicing_list ) {
325 my $conf = new FS::Conf;
326 my $error = send_email(
327 'from' => $conf->config('invoice_from'),
328 'to' => \@invoicing_list,
329 'subject' => $conf->config('cancelsubject'),
330 'body' => [ map "$_\n", $conf->config('cancelmessage') ],
332 #should this do something on errors?
341 Suspends all services (see L<FS::cust_svc> and L<FS::part_svc>) in this
342 package, then suspends the package itself (sets the susp field to now).
344 If there is an error, returns the error, otherwise returns false.
352 local $SIG{HUP} = 'IGNORE';
353 local $SIG{INT} = 'IGNORE';
354 local $SIG{QUIT} = 'IGNORE';
355 local $SIG{TERM} = 'IGNORE';
356 local $SIG{TSTP} = 'IGNORE';
357 local $SIG{PIPE} = 'IGNORE';
359 my $oldAutoCommit = $FS::UID::AutoCommit;
360 local $FS::UID::AutoCommit = 0;
363 foreach my $cust_svc (
364 qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
366 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $cust_svc->svcpart } );
368 $part_svc->svcdb =~ /^([\w\-]+)$/ or do {
369 $dbh->rollback if $oldAutoCommit;
370 return "Illegal svcdb value in part_svc!";
373 require "FS/$svcdb.pm";
375 my $svc = qsearchs( $svcdb, { 'svcnum' => $cust_svc->svcnum } );
377 $error = $svc->suspend;
379 $dbh->rollback if $oldAutoCommit;
386 unless ( $self->getfield('susp') ) {
387 my %hash = $self->hash;
388 $hash{'susp'} = time;
389 my $new = new FS::cust_pkg ( \%hash );
390 $error = $new->replace($self);
392 $dbh->rollback if $oldAutoCommit;
397 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
404 Unsuspends all services (see L<FS::cust_svc> and L<FS::part_svc>) in this
405 package, then unsuspends the package itself (clears the susp field).
407 If there is an error, returns the error, otherwise returns false.
415 local $SIG{HUP} = 'IGNORE';
416 local $SIG{INT} = 'IGNORE';
417 local $SIG{QUIT} = 'IGNORE';
418 local $SIG{TERM} = 'IGNORE';
419 local $SIG{TSTP} = 'IGNORE';
420 local $SIG{PIPE} = 'IGNORE';
422 my $oldAutoCommit = $FS::UID::AutoCommit;
423 local $FS::UID::AutoCommit = 0;
426 foreach my $cust_svc (
427 qsearch('cust_svc',{'pkgnum'=> $self->pkgnum } )
429 my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $cust_svc->svcpart } );
431 $part_svc->svcdb =~ /^([\w\-]+)$/ or do {
432 $dbh->rollback if $oldAutoCommit;
433 return "Illegal svcdb value in part_svc!";
436 require "FS/$svcdb.pm";
438 my $svc = qsearchs( $svcdb, { 'svcnum' => $cust_svc->svcnum } );
440 $error = $svc->unsuspend;
442 $dbh->rollback if $oldAutoCommit;
449 unless ( ! $self->getfield('susp') ) {
450 my %hash = $self->hash;
451 my $inactive = time - $hash{'susp'};
453 $hash{'bill'} = ( $hash{'bill'} || $hash{'setup'} ) + $inactive
454 if $inactive > 0 && ( $hash{'bill'} || $hash{'setup'} );
455 my $new = new FS::cust_pkg ( \%hash );
456 $error = $new->replace($self);
458 $dbh->rollback if $oldAutoCommit;
463 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
470 Returns the last bill date, or if there is no last bill date, the setup date.
471 Useful for billing metered services.
477 if ( $self->dbdef_table->column('last_bill') ) {
478 return $self->setfield('last_bill', $_[0]) if @_;
479 return $self->getfield('last_bill') if $self->getfield('last_bill');
481 my $cust_bill_pkg = qsearchs('cust_bill_pkg', { 'pkgnum' => $self->pkgnum,
482 'edate' => $self->bill, } );
483 $cust_bill_pkg ? $cust_bill_pkg->sdate : $self->setup || 0;
488 Returns the definition for this billing item, as an FS::part_pkg object (see
495 #exists( $self->{'_pkgpart'} )
497 ? $self->{'_pkgpart'}
498 : qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
503 Calls the I<calc_setup> of the FS::part_pkg object associated with this billing
510 $self->part_pkg->calc_setup($self, @_);
515 Calls the I<calc_recur> of the FS::part_pkg object associated with this billing
522 $self->part_pkg->calc_recur($self, @_);
525 =item cust_svc [ SVCPART ]
527 Returns the services for this package, as FS::cust_svc objects (see
528 L<FS::cust_svc>). If a svcpart is specified, return only the matching
537 return qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum,
538 'svcpart' => shift, } );
541 #if ( $self->{'_svcnum'} ) {
542 # values %{ $self->{'_svcnum'}->cache };
545 sort { $b->[1] cmp $a->[1] or $a->[2] <=> $b->[2] }
547 my $pkg_svc = qsearchs( 'pkg_svc', { 'pkgpart' => $self->pkgpart,
548 'svcpart' => $_->svcpart } );
550 $pkg_svc ? $pkg_svc->primary_svc : '',
551 $pkg_svc ? $pkg_svc->quantity : 0,
554 qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } );
559 =item num_cust_svc [ SVCPART ]
561 Returns the number of provisioned services for this package. If a svcpart is
562 specified, counts only the matching services.
568 my $sql = 'SELECT COUNT(*) FROM cust_svc WHERE pkgnum = ?';
569 $sql .= ' AND svcpart = ?' if @_;
570 my $sth = dbh->prepare($sql) or die dbh->errstr;
571 $sth->execute($self->pkgnum, @_) or die $sth->errstr;
572 $sth->fetchrow_arrayref->[0];
575 =item available_part_svc
577 Returns a list FS::part_svc objects representing services included in this
578 package but not yet provisioned. Each FS::part_svc object also has an extra
579 field, I<num_avail>, which specifies the number of available services.
583 sub available_part_svc {
585 grep { $_->num_avail > 0 }
587 my $part_svc = $_->part_svc;
588 $part_svc->{'Hash'}{'num_avail'} = #evil encapsulation-breaking
589 $_->quantity - $self->num_cust_svc($_->svcpart);
592 $self->part_pkg->pkg_svc;
597 Returns a list of lists, calling the label method for all services
598 (see L<FS::cust_svc>) of this billing item.
604 map { [ $_->label ] } $self->cust_svc;
609 Returns the parent customer object (see L<FS::cust_main>).
615 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
618 =item seconds_since TIMESTAMP
620 Returns the number of seconds all accounts (see L<FS::svc_acct>) in this
621 package have been online since TIMESTAMP, according to the session monitor.
623 TIMESTAMP is specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
624 L<Time::Local> and L<Date::Parse> for conversion functions.
629 my($self, $since) = @_;
632 foreach my $cust_svc (
633 grep { $_->part_svc->svcdb eq 'svc_acct' } $self->cust_svc
635 $seconds += $cust_svc->seconds_since($since);
642 =item seconds_since_sqlradacct TIMESTAMP_START TIMESTAMP_END
644 Returns the numbers of seconds all accounts (see L<FS::svc_acct>) in this
645 package have been online between TIMESTAMP_START (inclusive) and TIMESTAMP_END
648 TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see
649 L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for conversion
655 sub seconds_since_sqlradacct {
656 my($self, $start, $end) = @_;
660 foreach my $cust_svc (
662 my $part_svc = $_->part_svc;
663 $part_svc->svcdb eq 'svc_acct'
664 && scalar($part_svc->part_export('sqlradius'));
667 $seconds += $cust_svc->seconds_since_sqlradacct($start, $end);
674 =item attribute_since_sqlradacct TIMESTAMP_START TIMESTAMP_END ATTRIBUTE
676 Returns the sum of the given attribute for all accounts (see L<FS::svc_acct>)
677 in this package for sessions ending between TIMESTAMP_START (inclusive) and
681 TIMESTAMP_START and TIMESTAMP_END are specified as UNIX timestamps; see
682 L<perlfunc/"time">. Also see L<Time::Local> and L<Date::Parse> for conversion
687 sub attribute_since_sqlradacct {
688 my($self, $start, $end, $attrib) = @_;
692 foreach my $cust_svc (
694 my $part_svc = $_->part_svc;
695 $part_svc->svcdb eq 'svc_acct'
696 && scalar($part_svc->part_export('sqlradius'));
699 $sum += $cust_svc->attribute_since_sqlradacct($start, $end, $attrib);
706 =item transfer DEST_PKGNUM | DEST_CUST_PKG, [ OPTION => VALUE ... ]
708 Transfers as many services as possible from this package to another package.
710 The destination package can be specified by pkgnum by passing an FS::cust_pkg
711 object. The destination package must already exist.
713 Services are moved only if the destination allows services with the correct
714 I<svcpart> (not svcdb), unless the B<change_svcpart> option is set true. Use
715 this option with caution! No provision is made for export differences
716 between the old and new service definitions. Probably only should be used
717 when your exports for all service definitions of a given svcdb are identical.
718 (attempt a transfer without it first, to move all possible svcpart-matching
721 Any services that can't be moved remain in the original package.
723 Returns an error, if there is one; otherwise, returns the number of services
724 that couldn't be moved.
729 my ($self, $dest_pkgnum, %opt) = @_;
735 if (ref ($dest_pkgnum) eq 'FS::cust_pkg') {
736 $dest = $dest_pkgnum;
737 $dest_pkgnum = $dest->pkgnum;
739 $dest = qsearchs('cust_pkg', { pkgnum => $dest_pkgnum });
742 return ('Package does not exist: '.$dest_pkgnum) unless $dest;
744 foreach my $pkg_svc ( $dest->part_pkg->pkg_svc ) {
745 $target{$pkg_svc->svcpart} = $pkg_svc->quantity;
748 foreach my $cust_svc ($dest->cust_svc) {
749 $target{$cust_svc->svcpart}--;
752 my %svcpart2svcparts = ();
753 if ( exists $opt{'change_svcpart'} && $opt{'change_svcpart'} ) {
754 warn "change_svcpart option received, creating alternates list\n" if $DEBUG;
755 foreach my $svcpart ( map { $_->svcpart } $self->cust_svc ) {
756 next if exists $svcpart2svcparts{$svcpart};
757 my $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } );
758 $svcpart2svcparts{$svcpart} = [
760 sort { $b->[1] cmp $a->[1] or $a->[2] <=> $b->[2] }
762 my $pkg_svc = qsearchs( 'pkg_svc', { 'pkgpart' => $dest->pkgpart,
765 $pkg_svc ? $pkg_svc->primary_svc : '',
766 $pkg_svc ? $pkg_svc->quantity : 0,
770 grep { $_ != $svcpart }
772 qsearch('part_svc', { 'svcdb' => $part_svc->svcdb } )
774 warn "alternates for svcpart $svcpart: ".
775 join(', ', @{$svcpart2svcparts{$svcpart}}). "\n"
780 foreach my $cust_svc ($self->cust_svc) {
781 if($target{$cust_svc->svcpart} > 0) {
782 $target{$cust_svc->svcpart}--;
783 my $new = new FS::cust_svc {
784 svcnum => $cust_svc->svcnum,
785 svcpart => $cust_svc->svcpart,
786 pkgnum => $dest_pkgnum,
788 my $error = $new->replace($cust_svc);
789 return $error if $error;
790 } elsif ( exists $opt{'change_svcpart'} && $opt{'change_svcpart'} ) {
792 warn "looking for alternates for svcpart ". $cust_svc->svcpart. "\n";
793 warn "alternates to consider: ".
794 join(', ', @{$svcpart2svcparts{$cust_svc->svcpart}}). "\n";
796 my @alternate = grep {
797 warn "considering alternate svcpart $_: ".
798 "$target{$_} available in new package\n"
801 } @{$svcpart2svcparts{$cust_svc->svcpart}};
803 warn "alternate(s) found\n" if $DEBUG;
804 my $change_svcpart = $alternate[0];
805 $target{$change_svcpart}--;
806 my $new = new FS::cust_svc {
807 svcnum => $cust_svc->svcnum,
808 svcpart => $change_svcpart,
809 pkgnum => $dest_pkgnum,
811 my $error = $new->replace($cust_svc);
812 return $error if $error;
825 This method is deprecated. See the I<depend_jobnum> option to the insert and
826 order_pkgs methods in FS::cust_main for a better way to defer provisioning.
833 local $SIG{HUP} = 'IGNORE';
834 local $SIG{INT} = 'IGNORE';
835 local $SIG{QUIT} = 'IGNORE';
836 local $SIG{TERM} = 'IGNORE';
837 local $SIG{TSTP} = 'IGNORE';
838 local $SIG{PIPE} = 'IGNORE';
840 my $oldAutoCommit = $FS::UID::AutoCommit;
841 local $FS::UID::AutoCommit = 0;
844 foreach my $cust_svc ( $self->cust_svc ) {
845 #false laziness w/svc_Common::insert
846 my $svc_x = $cust_svc->svc_x;
847 foreach my $part_export ( $cust_svc->part_svc->part_export ) {
848 my $error = $part_export->export_insert($svc_x);
850 $dbh->rollback if $oldAutoCommit;
856 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
867 =item order CUSTNUM, PKGPARTS_ARYREF, [ REMOVE_PKGNUMS_ARYREF [ RETURN_CUST_PKG_ARRAYREF ] ]
869 CUSTNUM is a customer (see L<FS::cust_main>)
871 PKGPARTS is a list of pkgparts specifying the the billing item definitions (see
872 L<FS::part_pkg>) to order for this customer. Duplicates are of course
875 REMOVE_PKGNUMS is an optional list of pkgnums specifying the billing items to
876 remove for this customer. The services (see L<FS::cust_svc>) are moved to the
877 new billing items. An error is returned if this is not possible (see
878 L<FS::pkg_svc>). An empty arrayref is equivalent to not specifying this
881 RETURN_CUST_PKG_ARRAYREF, if specified, will be filled in with the
882 newly-created cust_pkg objects.
887 my ($custnum, $pkgparts, $remove_pkgnum, $return_cust_pkg) = @_;
889 my $conf = new FS::Conf;
891 # Transactionize this whole mess
892 local $SIG{HUP} = 'IGNORE';
893 local $SIG{INT} = 'IGNORE';
894 local $SIG{QUIT} = 'IGNORE';
895 local $SIG{TERM} = 'IGNORE';
896 local $SIG{TSTP} = 'IGNORE';
897 local $SIG{PIPE} = 'IGNORE';
899 my $oldAutoCommit = $FS::UID::AutoCommit;
900 local $FS::UID::AutoCommit = 0;
904 my $cust_main = qsearchs('cust_main', { custnum => $custnum });
905 return "Customer not found: $custnum" unless $cust_main;
907 # Create the new packages.
909 foreach (@$pkgparts) {
910 $cust_pkg = new FS::cust_pkg { custnum => $custnum,
912 $error = $cust_pkg->insert;
914 $dbh->rollback if $oldAutoCommit;
917 push @$return_cust_pkg, $cust_pkg;
919 # $return_cust_pkg now contains refs to all of the newly
922 # Transfer services and cancel old packages.
923 foreach my $old_pkgnum (@$remove_pkgnum) {
924 my $old_pkg = qsearchs ('cust_pkg', { pkgnum => $old_pkgnum });
926 foreach my $new_pkg (@$return_cust_pkg) {
927 $error = $old_pkg->transfer($new_pkg);
928 if ($error and $error == 0) {
929 # $old_pkg->transfer failed.
930 $dbh->rollback if $oldAutoCommit;
935 if ( $error > 0 && $conf->exists('cust_pkg-change_svcpart') ) {
936 warn "trying transfer again with change_svcpart option\n" if $DEBUG;
937 foreach my $new_pkg (@$return_cust_pkg) {
938 $error = $old_pkg->transfer($new_pkg, 'change_svcpart'=>1 );
939 if ($error and $error == 0) {
940 # $old_pkg->transfer failed.
941 $dbh->rollback if $oldAutoCommit;
948 # Transfers were successful, but we went through all of the
949 # new packages and still had services left on the old package.
950 # We can't cancel the package under the circumstances, so abort.
951 $dbh->rollback if $oldAutoCommit;
952 return "Unable to transfer all services from package ".$old_pkg->pkgnum;
954 $error = $old_pkg->cancel;
960 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
968 sub order is not OO. Perhaps it should be moved to FS::cust_main and made so?
970 In sub order, the @pkgparts array (passed by reference) is clobbered.
972 Also in sub order, no money is adjusted. Once FS::part_pkg defines a standard
973 method to pass dates to the recur_prog expression, it should do so.
975 FS::svc_acct, FS::svc_domain, FS::svc_www, FS::svc_ip and FS::svc_forward are
976 loaded via 'use' at compile time, rather than via 'require' in sub { setup,
977 suspend, unsuspend, cancel } because they use %FS::UID::callback to load
978 configuration values. Probably need a subroutine which decides what to do
979 based on whether or not we've fetched the user yet, rather than a hash. See
980 FS::UID and the TODO.
982 Now that things are transactional should the check in the insert method be
987 L<FS::Record>, L<FS::cust_main>, L<FS::part_pkg>, L<FS::cust_svc>,
988 L<FS::pkg_svc>, schema.html from the base documentation