summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-09-16 06:38:11 -0700
committerIvan Kohler <ivan@freeside.biz>2014-09-16 06:38:11 -0700
commitaa59cc83ffa65da2fce9b5be42f483d9b17d91c0 (patch)
treeda16769b602c41da406de4b5726d3c05a94cd164
parent2eb4ef92fbea43f55fd705d604fda5c815f9eb9c (diff)
convert prospects to customers via quotations, RT#20688
-rw-r--r--FS/FS/Schema.pm3
-rw-r--r--FS/FS/cust_main.pm22
2 files changed, 17 insertions, 8 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 1828cba8b..3eedc5cc3 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1300,10 +1300,11 @@ sub tables_hashref {
'add_date', @date_type, '', '',
'disabled', 'char', 'NULL', 1, '', '',
'custnum', 'int', 'NULL', '', '', '',
+ 'refnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'prospectnum',
'unique' => [],
- 'index' => [ [ 'company' ], [ 'agentnum' ], [ 'disabled' ] ],
+ 'index' => [ ['company'], ['agentnum'], ['disabled'], ['refnum'] ],
},
'quotation' => {
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 43d8f0ce7..e1d3caafe 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -402,11 +402,8 @@ sub insert {
# insert locations
foreach my $l (qw(bill_location ship_location)) {
- my $loc = delete $self->hashref->{$l};
- # XXX if we're moving a prospect's locations, do that here
- if ( !$loc ) {
- return "$l not set";
- }
+
+ my $loc = delete $self->hashref->{$l} or return "$l not set";
if ( !$loc->locationnum ) {
# warn the location that we're going to insert it with no custnum
@@ -419,8 +416,19 @@ sub insert {
my $label = $l eq 'ship_location' ? 'service' : 'billing';
return "$error (in $label location)";
}
- }
- elsif ( ($loc->custnum || 0) > 0 or $loc->prospectnum ) {
+
+ } elsif ( $loc->prospectnum ) {
+
+ $loc->prospectnum('');
+ $loc->set(custnum_pending => 1);
+ my $error = $loc->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ my $label = $l eq 'ship_location' ? 'service' : 'billing';
+ return "$error (moving $label location)";
+ }
+
+ } elsif ( ($loc->custnum || 0) > 0 ) {
# then it somehow belongs to another customer--shouldn't happen
$dbh->rollback if $oldAutoCommit;
return "$l belongs to customer ".$loc->custnum;