X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=fa09640c5a90070818f6e077ec31b84fe98fed42;hb=b7c25d5e38e6459efe5d1c2f09f437b79798038e;hp=97354d429899f5f48e502ab9d986efb55c3abf0f;hpb=8861d46820af163c7de7839178b6120c9b32ab2c;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 97354d429..fa09640c5 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -30,6 +30,7 @@ use FS::reg_code; use FS::part_svc; use FS::cust_pkg_reason; use FS::reason; +use FS::cust_pkg_usageprice; use FS::cust_pkg_discount; use FS::discount; use FS::UI::Web; @@ -254,6 +255,12 @@ setting I to an array reference of refnums or a hash reference with refnums as keys. If no I is defined, a default FS::pkg_referral record will be created corresponding to cust_main.refnum. +If the additional field I is defined, it will be treated +as an arrayref of FS::cust_pkg_usageprice objects, which will be inserted. +(Note that this field cannot be set with a usual ->cust_pkg_usageprice method. +It can be set as part of the hash when creating the object, or with the B +method.) + The following options are available: =over 4 @@ -267,10 +274,6 @@ orders. (Currently this includes: intro periods when delay_setup is on.) cust_pkg_option records will be created -=item cust_pkg_usageprice - -Array reference of cust_pkg_usageprice objects, will be inserted - =item ticket_subject a ticket will be added to this customer with this subject @@ -333,13 +336,6 @@ sub insert { # set order date unless it was specified as part of an import $self->order_date(time) unless $import && $self->order_date; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -441,13 +437,6 @@ hide cancelled packages. sub delete { my $self = shift; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -558,13 +547,6 @@ sub replace { local($disable_agentcheck) = 1 if $old->pkgpart == $new->pkgpart; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -798,13 +780,6 @@ sub cancel { join(', ', map { "$_: $options{$_}" } keys %options ). "\n" if $DEBUG; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1001,13 +976,6 @@ sub uncancel { # Transaction-alize ## - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1162,13 +1130,6 @@ sub unexpire { my( $self, %options ) = @_; my $error; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1245,13 +1206,6 @@ sub suspend { return $self->main_pkg->suspend(%options); } - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1488,13 +1442,6 @@ sub unsuspend { return $self->main_pkg->unsuspend(%opt); } - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1671,13 +1618,6 @@ sub unadjourn { my( $self, %options ) = @_; my $error; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1795,13 +1735,6 @@ sub change { my $conf = new FS::Conf; # Transactionize this whole mess - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -1971,6 +1904,22 @@ sub change { } } + # transfer usage pricing add-ons, if we're not changing pkgpart + if ( $same_pkgpart ) { + foreach my $old_cust_pkg_usageprice ($self->cust_pkg_usageprice) { + my $new_cust_pkg_usageprice = new FS::cust_pkg_usageprice { + 'pkgnum' => $cust_pkg->pkgnum, + 'usagepricepart' => $old_cust_pkg_usageprice->usagepricepart, + 'quantity' => $old_cust_pkg_usageprice->quantity, + }; + $error = $new_cust_pkg_usageprice->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "Error transferring usage pricing add-on: $error"; + } + } + } + # transfer discounts, if we're not changing pkgpart if ( $same_pkgpart ) { foreach my $old_discount ($self->cust_pkg_discount_active) { @@ -2412,13 +2361,6 @@ sub process_bulk_cust_pkg { #my $keep_dates = $param->{'keep_dates'} || 0; my $keep_dates = 1; # there is no good reason to turn this off - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -2655,13 +2597,6 @@ If there is an error, returns the error, otherwise returns false. sub set_cust_pkg_detail { my( $self, $detailtype, @details ) = @_; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -3149,7 +3084,7 @@ Returns a label for this package. (Currently "pkgnum: pkg - comment" or sub pkg_label { my $self = shift; - my $label = $self->part_pkg->pkg_comment( 'nopkgpart' => 1 ); + my $label = $self->part_pkg->pkg_comment( cust_pkg=>$self, nopkgpart=>1 ); $label = $self->pkgnum. ": $label" if $FS::CurrentUser::CurrentUser->option('show_pkgnum'); $label; @@ -3615,13 +3550,6 @@ sub grab_svcnums { my $self = shift; my @svcnum = @_; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -3656,13 +3584,6 @@ order_pkgs methods in FS::cust_main for a better way to defer provisioning. sub reexport { my $self = shift; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -3693,13 +3614,6 @@ Calls the "pkg_change" export action for all services attached to this package. sub export_pkg_change { my( $self, $old ) = ( shift, shift ); - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -3871,6 +3785,34 @@ sub recharge { } } +=item apply_usageprice + +=cut + +sub apply_usageprice { + my $self = shift; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = ''; + + foreach my $cust_pkg_usageprice ( $self->cust_pkg_usageprice ) { + $error ||= $cust_pkg_usageprice->apply; + } + + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + die "error applying part_pkg_usageprice add-ons, pkgnum ". $self->pkgnum. + ": $error\n"; + } else { + $dbh->commit if $oldAutoCommit; + } + + +} + =item cust_pkg_discount =item cust_pkg_discount_active @@ -3911,16 +3853,10 @@ sub apply_usage { my $pkgnum = $self->pkgnum; my $custnum = $self->custnum; - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; + my $order = FS::Conf->new->config('cdr-minutes_priority'); my $is_classnum; @@ -4902,13 +4838,6 @@ sub order { my $conf = new FS::Conf; # Transactionize this whole mess - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; @@ -5048,13 +4977,6 @@ sub bulk_change { my ($pkgparts, $remove_pkgnum, $return_cust_pkg) = @_; # Transactionize this whole mess - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh;