From f424f11eb366fe64f5f7bb42b21745e22537cab1 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 14 Dec 2010 07:29:13 +0000 Subject: [PATCH] cust_location editing features, RT#10766 --- FS/FS/Conf.pm | 7 ++ FS/FS/Schema.pm | 1 + FS/FS/cust_location.pm | 69 +++++++++++++++++ httemplate/edit/cust_location.cgi | 54 +++++++++++++ httemplate/edit/process/cust_location.cgi | 38 ++++++++++ httemplate/elements/tr-select-cust_location.html | 1 + httemplate/misc/disable-cust_location.cgi | 35 +++++++++ httemplate/view/cust_main/locations.html | 87 +++++++++++++++++++++ httemplate/view/cust_main/packages.html | 96 +++++------------------- httemplate/view/cust_main/packages/location.html | 13 ++++ httemplate/view/cust_main/packages/package.html | 27 ++++++- httemplate/view/cust_main/packages/section.html | 95 +++++++++++++++++++++++ 12 files changed, 445 insertions(+), 78 deletions(-) create mode 100755 httemplate/edit/cust_location.cgi create mode 100644 httemplate/edit/process/cust_location.cgi create mode 100755 httemplate/misc/disable-cust_location.cgi create mode 100755 httemplate/view/cust_main/locations.html create mode 100755 httemplate/view/cust_main/packages/section.html diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index a05ad0358..072982ab4 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2689,6 +2689,13 @@ and customer address. Include units.', }, { + 'key' => 'cust_pkg-group_by_location', + 'section' => 'UI', + 'description' => "Group packages by location.", + 'type' => 'checkbox', + }, + + { 'key' => 'cust_pkg-show_fcc_voice_grade_equivalent', 'section' => 'UI', 'description' => "Show a field on package definitions for assigning a DSO equivalency number suitable for use on FCC form 477.", diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index b48e5af8a..253eb6602 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -909,6 +909,7 @@ sub tables_hashref { 'location_type', 'varchar', 'NULL', 20, '', '', 'location_number', 'varchar', 'NULL', 20, '', '', 'location_kind', 'char', 'NULL', 1, '', '', + '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) 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 diff --git a/httemplate/edit/cust_location.cgi b/httemplate/edit/cust_location.cgi new file mode 100755 index 000000000..80b27c2b3 --- /dev/null +++ b/httemplate/edit/cust_location.cgi @@ -0,0 +1,54 @@ +<% include('/elements/header-popup.html', "Edit Location") %> + +<% include('/elements/error.html') %> + +
+ + +<% ntable('#cccccc') %> +<% include('/elements/location.html', + 'object' => $cust_location, + 'no_asterisks' => 1, + ) %> + + +
+ + + +
+ + + +<%init> + +my $conf = new FS::Conf; + +my $curuser = $FS::CurrentUser::CurrentUser; + +# it's the same access right you'd need to do this by editing packages +die "access denied" + unless $curuser->access_right('Change customer package'); + +my $locationnum = scalar($cgi->param('locationnum')); +my $cust_location = qsearchs({ + 'select' => 'cust_location.*', + 'table' => 'cust_location', + 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'locationnum' => $locationnum }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql, + }) or die "unknown locationnum $locationnum"; + +die "can't edit disabled locationnum $locationnum" if $cust_location->disabled; + +my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_location->custnum }) + or die "can't get cust_main record for custnum ". $cust_location->custnum; + +my @cust_pkgs = qsearch('cust_pkg', { 'locationnum' => $locationnum }); + + diff --git a/httemplate/edit/process/cust_location.cgi b/httemplate/edit/process/cust_location.cgi new file mode 100644 index 000000000..790fc8ea4 --- /dev/null +++ b/httemplate/edit/process/cust_location.cgi @@ -0,0 +1,38 @@ +% if ($error) { +% $cgi->param('error', Dumper($error)); +% $cgi->redirect(popurl(3). 'edit/cust_location.cgi?'. $cgi->query_string ); +% } else { + + <% header("Location changed") %> + + + + +% } +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right('Change customer package'); + +my $locationnum = $cgi->param('locationnum'); +my $cust_location = qsearchs({ + 'select' => 'cust_location.*', + 'table' => 'cust_location', + 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'locationnum' => $locationnum }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql, +}); +die "unknown locationnum $locationnum" unless $cust_location; + +my $new = { + map { $_ => scalar($cgi->param($_)) } + qw( address1 address2 city county state zip country ) +}; + +my $error = $cust_location->move_to($new); + + diff --git a/httemplate/elements/tr-select-cust_location.html b/httemplate/elements/tr-select-cust_location.html index 78252ba1d..fa19405b2 100644 --- a/httemplate/elements/tr-select-cust_location.html +++ b/httemplate/elements/tr-select-cust_location.html @@ -162,6 +162,7 @@ Example: % push @locations, $cust_location % if !$cust_main && $cust_location && $cust_location->locationnum>0; % foreach my $loc ( sort $location_sort @locations ) { +% next if $loc->disabled;