From: ivan Date: Fri, 30 Jul 2004 04:54:41 +0000 (+0000) Subject: svcpart changes now trigger all necessary export actions, manual svcpart changing... X-Git-Tag: BEFORE_FINAL_MASONIZE~978 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=918bbc9ce36a3dc5943f521e26751ea94a5a5539 svcpart changes now trigger all necessary export actions, manual svcpart changing on svc_acct view, linking changes svcpart if you ask it to, closes: Bug#671, Bug#644 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index c4b214845..bfef62807 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1237,7 +1237,7 @@ httemplate/docs/config.html { 'key' => 'cust_pkg-change_svcpart', 'section' => '', - 'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions. Use with caution! No provision is made for export differences between the old and new service definitions. Probably only should be used when your exports for all service definitions of a given svcdb are identical.", + 'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions.", 'type' => 'checkbox', }, diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index 7ee9b3f40..118ab79d2 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -172,15 +172,9 @@ sub replace { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $new->SUPER::replace($old); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error if $error; - } - if ( $new->svcpart != $old->svcpart ) { my $svc_x = $new->svc_x; - my $new_svc_x = ref($svc_x)->new({$svc_x->hash}); + my $new_svc_x = ref($svc_x)->new({$svc_x->hash, svcpart=>$new->svcpart }); my $error = $new_svc_x->replace($svc_x); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -188,6 +182,12 @@ sub replace { } } + my $error = $new->SUPER::replace($old); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error if $error; + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index a22326696..38e656cd4 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -302,14 +302,52 @@ sub replace { #new-style exports! unless ( $noexport_hack ) { - foreach my $part_export ( $new->cust_svc->part_svc->part_export ) { - my $error = $part_export->export_replace($new,$old); + + #not quite false laziness, but same pattern as FS::svc_acct::replace and + #FS::part_export::sqlradius::_export_replace. List::Compare or something + #would be useful but too much of a pain in the ass to deploy + + my @old_part_export = $old->cust_svc->part_svc->part_export; + my %old_exportnum = map { $_->exportnum => 1 } @old_part_export; + my @new_part_export = + $new->svcpart + ? qsearchs('part_svc', { svcpart=>$new->svcpart } )->part_export + : $new->cust_svc->part_svc->part_export; + my %new_exportnum = map { $_->exportnum => 1 } @new_part_export; + + foreach my $delete_part_export ( + grep { ! $new_exportnum{$_->exportnum} } @old_part_export + ) { + my $error = $delete_part_export->export_delete($old); if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "error exporting to ". $part_export->exporttype. + return "error deleting, export to ". $delete_part_export->exporttype. + " (transaction rolled back): $error"; + } + } + + foreach my $replace_part_export ( + grep { $old_exportnum{$_->exportnum} } @new_part_export + ) { + my $error = $replace_part_export->export_replace($new,$old); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error exporting to ". $replace_part_export->exporttype. " (transaction rolled back): $error"; } } + + foreach my $insert_part_export ( + grep { ! $old_exportnum{$_->exportnum} } @new_part_export + ) { + my $error = $insert_part_export->export_insert($new); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error inserting export to ". $insert_part_export->exporttype. + " (transaction rolled back): $error"; + } + } + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; diff --git a/conf/cust_pkg-change_svcpart b/conf/cust_pkg-change_svcpart new file mode 100644 index 000000000..e69de29bb diff --git a/httemplate/edit/process/cust_svc.cgi b/httemplate/edit/process/cust_svc.cgi new file mode 100644 index 000000000..187ede5e5 --- /dev/null +++ b/httemplate/edit/process/cust_svc.cgi @@ -0,0 +1,30 @@ +<% + +my $svcnum = $cgi->param('svcnum'); + +my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum}) if $svcnum; + +my $new = new FS::cust_svc ( { + map { + $_, scalar($cgi->param($_)); + } fields('cust_svc') +} ); + +my $error; +if ( $svcnum ) { + $error=$new->replace($old); +} else { + $error=$new->insert; + $svcnum=$new->getfield('svcnum'); +} + +if ( $error ) { + #$cgi->param('error', $error); + #print $cgi->redirect(popurl(2). "cust_svc.cgi?". $cgi->query_string ); + eidiot($error); +} else { + my $svcdb = $new->part_svc->svcdb; + print $cgi->redirect(popurl(3). "view/$svcdb.cgi?$svcnum"); +} + + diff --git a/httemplate/misc/process/link.cgi b/httemplate/misc/process/link.cgi index 32a5360d9..acdd1ad03 100755 --- a/httemplate/misc/process/link.cgi +++ b/httemplate/misc/process/link.cgi @@ -16,8 +16,11 @@ unless ( $svcnum ) { if ( $cgi->param('link_field2') =~ /^(\w+)$/ ) { $search{$1} = $cgi->param('link_value2'); } - my $svc_x = ( grep { $_->cust_svc->svcpart == $svcpart } - qsearch( $svcdb, \%search ) + my $svc_x = ( sort { ($b->cust_svc->pkgnum > 0) <=> ($a->cust_svc->pkgnum > 0) + or ($b->cust_svc->svcpart == $svcpart) + <=> ($a->cust_svc->svcpart == $svcpart) + } + qsearch( $svcdb, \%search ) )[0]; eidiot("$link_field not found!") unless $svc_x; $svcnum = $svc_x->svcnum; diff --git a/httemplate/view/svc_acct.cgi b/httemplate/view/svc_acct.cgi index 14d2745a2..be58e4e1d 100755 --- a/httemplate/view/svc_acct.cgi +++ b/httemplate/view/svc_acct.cgi @@ -108,6 +108,48 @@ if ( $part_svc->part_export('sqlradius') #print qq!
Send account information!; +%> + +<% + my @part_svc = (); + if ( $pkgnum ) { + @part_svc = grep { $_->svcdb eq 'svc_acct' + && $_->svcpart != $part_svc->svcpart } + $cust_pkg->available_part_svc; + } else { + @part_svc = qsearch('part_svc', { + svcdb => 'svc_acct', + disabled => '', + svcpart => { op=>'!=', value=>$part_svc->svcpart }, + } ); + } + if ( @part_svc ) { +%> + +
+ + + + +
+<% } %> + +<% + print qq!Edit this information
!. &ntable("#cccccc"). ''. &ntable("#cccccc",2). "Service number".