summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authormark <mark>2010-12-29 22:56:47 +0000
committermark <mark>2010-12-29 22:56:47 +0000
commit6fc8a42e503e4e1f12659e1cfef7f5f26577034f (patch)
treefcac659b42217a4013afe04a98ac956f2c650cdb /FS
parent15a9fae1bde88fb279534de4effae20e43fbee27 (diff)
cust_location editing features, RT#10766
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/cust_location.pm69
2 files changed, 70 insertions, 0 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 1a88dd2a9..cd0a4dc2f 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -906,6 +906,7 @@ sub tables_hashref {
'zip', 'varchar', 'NULL', 10, '', '',
'country', 'char', '', 2, '', '',
'geocode', 'varchar', 'NULL', 20, '', '',
+ 'disabled', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'locationnum',
'unique' => [],
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm
index ab80941f9..60c0181a3 100644
--- a/FS/FS/cust_location.pm
+++ b/FS/FS/cust_location.pm
@@ -3,6 +3,7 @@ package FS::cust_location;
use strict;
use base qw( FS::geocode_Mixin FS::Record );
use Locale::Country;
+use FS::UID qw( dbh );
use FS::Record qw( qsearch ); #qsearchs );
use FS::prospect_main;
use FS::cust_main;
@@ -74,6 +75,10 @@ Country (see L<FS::cust_main_county>)
Geocode
+=item disabled
+
+Disabled flag; set to 'Y' to disable the location.
+
=back
=head1 METHODS
@@ -192,6 +197,70 @@ city, county, state, zip, country, geocode.
=cut
+=item move_to HASHREF
+
+Takes a hashref with one or more cust_location fields. Creates a duplicate
+of the existing location with all fields set to the values in the hashref.
+Moves all packages that use the existing location to the new one, then sets
+the "disabled" flag on the old location. Returns nothing on success, an
+error message on error.
+
+=cut
+
+sub move_to {
+ my $old = shift;
+ my $hashref = 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;
+ my $error = '';
+
+ my $new = FS::cust_location->new({
+ $old->location_hash,
+ 'custnum' => $old->custnum,
+ 'prospectnum' => $old->prospectnum,
+ %$hashref
+ });
+ $error = $new->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error creating location: $error";
+ }
+
+ my @pkgs = qsearch('cust_pkg', {
+ 'locationnum' => $old->locationnum,
+ 'cancel' => ''
+ });
+ foreach my $cust_pkg (@pkgs) {
+ $error = $cust_pkg->change(
+ 'locationnum' => $new->locationnum,
+ 'keep_dates' => 1
+ );
+ if ( $error and not ref($error) ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error moving pkgnum ".$cust_pkg->pkgnum.": $error";
+ }
+ }
+
+ $old->disabled('Y');
+ $error = $old->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error disabling old location: $error";
+ }
+
+ $dbh->commit if $oldAutoCommit;
+ return;
+}
+
=back
=head1 BUGS