diff options
author | Jonathan Prykop <jonathan@freeside.biz> | 2016-01-29 20:24:46 -0600 |
---|---|---|
committer | Jonathan Prykop <jonathan@freeside.biz> | 2016-01-30 14:48:17 -0600 |
commit | 0ef2dee417147582084f925bc5d62cf13d41801d (patch) | |
tree | d5c3e40b6354886788556957e9beeb9e4355cc37 /FS/FS | |
parent | 98298f640d54b04f93e702a80a58e10525193b1e (diff) |
RT#39831 Quotation extra information for line items
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/quotation.pm | 38 | ||||
-rw-r--r-- | FS/FS/quotation_pkg.pm | 18 | ||||
-rw-r--r-- | FS/FS/quotation_pkg_detail.pm | 5 |
4 files changed, 58 insertions, 4 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 029dbe1..7bc30ef 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1980,6 +1980,7 @@ sub tables_hashref { 'quotationpkgnum', 'int', '', '', '', '', 'format', 'char', 'NULL', 1, '', '', # not used for anything 'detail', 'varchar', '', 255, '', '', + 'copy_on_order', 'char', 'NULL', 1, '', '', # 'Y' to copy when ordering ], 'primary_key' => 'detailnum', 'unique' => [], diff --git a/FS/FS/quotation.pm b/FS/FS/quotation.pm index c400493..cb3d80b 100644 --- a/FS/FS/quotation.pm +++ b/FS/FS/quotation.pm @@ -399,12 +399,18 @@ as ordered. 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($_) ); } @@ -418,15 +424,45 @@ sub order { $all_cust_pkg{$cust_pkg} = []; # no services } + 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; } - $error; + if ($error) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; #no error + } =item charge diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm index e264209..1e5a0da 100644 --- a/FS/FS/quotation_pkg.pm +++ b/FS/FS/quotation_pkg.pm @@ -380,16 +380,27 @@ sub delete_details { } -=item set_details [ DETAIL, DETAIL, ... ] +=item set_details PARAM -Sets quotation details for this package (see L<FS::quotation_pkg_detail>). +Sets new quotation details for this package (see L<FS::quotation_pkg_detail>), +removing existing details. + +Recognizes the following parameters: + +details - arrayref of strings, one for each new detail + +copy_on_order - if true, sets copy_on_order flag on new details If there is an error, returns the error, otherwise returns false. =cut sub set_details { - my( $self, @details ) = @_; + my $self = shift; + my %opt = @_; + + $opt{'details'} ||= []; + my @details = @{$opt{'details'}}; my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; @@ -405,6 +416,7 @@ sub set_details { my $quotation_pkg_detail = new FS::quotation_pkg_detail { 'quotationpkgnum' => $self->quotationpkgnum, 'detail' => $detail, + 'copy_on_order' => $opt{'copy_on_order'} ? 'Y' : '', }; $error = $quotation_pkg_detail->insert; if ( $error ) { diff --git a/FS/FS/quotation_pkg_detail.pm b/FS/FS/quotation_pkg_detail.pm index ce13589..76e2fd1 100644 --- a/FS/FS/quotation_pkg_detail.pm +++ b/FS/FS/quotation_pkg_detail.pm @@ -42,6 +42,10 @@ for the relevant L<FS::quotation_pkg> detail text +=item copy_on_order + +flag, indicates detail should be copied over when ordering + =cut # 'format' field isn't used, there for TemplateItem_Mixin @@ -109,6 +113,7 @@ sub check { $self->ut_numbern('detailnum') || $self->ut_foreign_key('quotationpkgnum', 'quotation_pkg', 'quotationpkgnum') || $self->ut_text('detail') + || $self->ut_flag('copy_on_order') ; return $error if $error; |