X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fquotation.pm;h=f828a3920480d8d809fb5b6953495b9291119458;hb=1f1c0ad8798bfaea287c47565f1a565ee7d82e5c;hp=0e6b4e7d09f44a95a84bf7a1af9e80491b65b849;hpb=02b3110eb22945351c1b840a6686b9ad6541be0b;p=freeside.git diff --git a/FS/FS/quotation.pm b/FS/FS/quotation.pm index 0e6b4e7d0..f828a3920 100644 --- a/FS/FS/quotation.pm +++ b/FS/FS/quotation.pm @@ -65,6 +65,13 @@ disabled usernum +=item close_date + +projected date when the quotation will be closed + +=item confidence + +projected confidence (expressed as integer) that quotation will close =back @@ -117,6 +124,8 @@ sub check { || $self->ut_numbern('_date') || $self->ut_enum('disabled', [ '', 'Y' ]) || $self->ut_numbern('usernum') + || $self->ut_numbern('close_date') + || $self->ut_numbern('confidence') ; return $error if $error; @@ -124,6 +133,9 @@ sub check { $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum; + return 'confidence must be an integer between 1 and 100' + if length($self->confidence) && (($self->confidence < 1) || ($self->confidence > 100)); + return 'prospectnum or custnum must be specified' if ! $self->prospectnum && ! $self->custnum; @@ -347,11 +359,13 @@ sub _items_total { my $disable_total = 0; foreach my $quotation_pkg ($self->quotation_pkg) { my $part_pkg = $quotation_pkg->part_pkg; - if ( $part_pkg->plan =~ /^prorate/ - or $part_pkg->plan eq 'agent' - or $part_pkg->plan =~ /^torrus/ - or $part_pkg->option('sync_bill_date') - or $part_pkg->option('recur_method') eq 'prorate' ) { + if ( $part_pkg->plan =~ /^(prorate|torrus|agent$)/ + || $part_pkg->option('recur_method') eq 'prorate' + || ( $part_pkg->option('sync_bill_date') + && $self->custnum + && $self->cust_main->billing_pkgs #num_billing_pkgs when we have it + ) + ) { $disable_total = 1; last; } @@ -419,7 +433,7 @@ sub convert_cust_main { } -=item order +=item order [ HASHREF ] This method is for use with quotations which are already associated with a customer. @@ -427,14 +441,27 @@ Orders this quotation's packages as real packages for the customer. If there is an error, returns an error message, otherwise returns false. +If HASHREF is passed, it will be filled with a hash mapping the +C of each quoted package to the C of the package +as ordered. + =cut sub order { my $self = shift; + my $pkgnum_map = shift || {}; + my $details_map = {}; tie my %all_cust_pkg, 'Tie::RefHash'; foreach my $quotation_pkg ($self->quotation_pkg) { my $cust_pkg = FS::cust_pkg->new; + $pkgnum_map->{ $quotation_pkg->quotationpkgnum } = $cust_pkg; + + # details will be copied below, after package is ordered + $details_map->{ $quotation_pkg->quotationpkgnum } = [ + map { $_->copy_on_order ? $_->detail : () } $quotation_pkg->quotation_pkg_detail + ]; + foreach (qw(pkgpart locationnum start_date contract_end quantity waive_setup)) { $cust_pkg->set( $_, $quotation_pkg->get($_) ); } @@ -448,7 +475,44 @@ sub order { $all_cust_pkg{$cust_pkg} = []; # no services } - $self->cust_main->order_pkgs( \%all_cust_pkg ); + 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 $error = $self->cust_main->order_pkgs( \%all_cust_pkg ); + + unless ($error) { + # copy details (copy_on_order filtering handled above) + foreach my $quotationpkgnum (keys %$details_map) { + next unless @{$details_map->{$quotationpkgnum}}; + $error = $pkgnum_map->{$quotationpkgnum}->set_cust_pkg_detail( + 'I', + @{$details_map->{$quotationpkgnum}} + ); + last if $error; + } + } + + foreach my $quotationpkgnum (keys %$pkgnum_map) { + # convert the objects to just pkgnums + my $cust_pkg = $pkgnum_map->{$quotationpkgnum}; + $pkgnum_map->{$quotationpkgnum} = $cust_pkg->pkgnum; + } + + if ($error) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; #no error }